@web-ts-toolkit/access-router 0.58.0 → 0.59.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/index.js +1155 -850
- package/index.mjs +1032 -728
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -3810,11 +3810,10 @@ function readServiceOutputPolicy(call, binding) {
|
|
|
3810
3810
|
function readServiceOutputFieldAuthorization(call, binding) {
|
|
3811
3811
|
assertAuthorizationBinding(call, binding);
|
|
3812
3812
|
const record3 = callRecord(call);
|
|
3813
|
-
const reusable =
|
|
3814
|
-
// leaves. Keep those receivers local to the original resolution boundary.
|
|
3815
|
-
(record3.configuration.modelPermissionPrefix === null || typeof record3.configuration.modelPermissionPrefix !== "object");
|
|
3813
|
+
const reusable = reusableOutputFieldConfiguration(record3);
|
|
3816
3814
|
return Object.freeze({
|
|
3817
3815
|
access: record3.output.access,
|
|
3816
|
+
catalog: record3.output.catalog,
|
|
3818
3817
|
outputFields: record3.output.outputFields,
|
|
3819
3818
|
reusable,
|
|
3820
3819
|
...copyAuthorizationValue(
|
|
@@ -3826,6 +3825,16 @@ function readServiceOutputFieldAuthorization(call, binding) {
|
|
|
3826
3825
|
)
|
|
3827
3826
|
});
|
|
3828
3827
|
}
|
|
3828
|
+
function reusableOutputFieldConfiguration(record3) {
|
|
3829
|
+
return record3.reusableFieldConfiguration ??= hasStableConfigurationCopies(record3.configuration.permissionSchema) && // Coercion methods can observe an object's identity even without native
|
|
3830
|
+
// leaves. Keep those receivers local to the original resolution boundary.
|
|
3831
|
+
(record3.configuration.modelPermissionPrefix === null || typeof record3.configuration.modelPermissionPrefix !== "object");
|
|
3832
|
+
}
|
|
3833
|
+
function canPrepareStaticOutputPolicy(call, binding) {
|
|
3834
|
+
assertAuthorizationBinding(call, binding);
|
|
3835
|
+
const record3 = callRecord(call);
|
|
3836
|
+
return reusableOutputFieldConfiguration(record3) && typeof (record3.configuration.modelPermissionPrefix ?? "") === "string";
|
|
3837
|
+
}
|
|
3829
3838
|
function getAuthorizationPermissions(call, binding) {
|
|
3830
3839
|
assertAuthorizationBinding(call, binding);
|
|
3831
3840
|
return callRecord(call).permissions;
|
|
@@ -3844,430 +3853,93 @@ var init_service_authorization = __esm({
|
|
|
3844
3853
|
}
|
|
3845
3854
|
});
|
|
3846
3855
|
|
|
3847
|
-
// src/acl/
|
|
3848
|
-
function
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3852
|
-
if (typeof key !== "string" || !("value" in descriptor) || !descriptor.enumerable) {
|
|
3853
|
-
authorizationError("invalid output option property");
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
assertAuthorizationKeys(
|
|
3857
|
-
value,
|
|
3858
|
-
["authorization", "scopePath", "documentAuthorization", ...purpose ? ["purpose"] : []],
|
|
3859
|
-
"output options"
|
|
3860
|
-
);
|
|
3861
|
-
if (purpose && value.purpose !== purpose) authorizationError("genAllowedFields requires purpose: output");
|
|
3862
|
-
if (Object.prototype.hasOwnProperty.call(value, "documentAuthorization")) {
|
|
3863
|
-
if (Object.prototype.hasOwnProperty.call(value, "authorization") || Object.prototype.hasOwnProperty.call(value, "scopePath")) {
|
|
3864
|
-
authorizationError("document handle cannot be mixed with raw policy/scope");
|
|
3865
|
-
}
|
|
3866
|
-
const handle = value.documentAuthorization;
|
|
3867
|
-
const stage = stageRecord(documentRecord(handle).stage);
|
|
3868
|
-
const binding = Object.freeze({ ...input.binding, scopePath: stage.binding.scopePath });
|
|
3869
|
-
assertAuthorizationBinding(stage.call, binding);
|
|
3870
|
-
const access = readServiceAuthorizationAccess(stage.call, binding);
|
|
3871
|
-
if (input.access.outputAccess !== access.outputAccess) authorizationError("document access mismatch");
|
|
3872
|
-
return Object.freeze({ kind: "document", documentAuthorization: handle, binding });
|
|
3873
|
-
}
|
|
3874
|
-
if (value.scopePath !== void 0 && !Array.isArray(value.scopePath))
|
|
3875
|
-
authorizationError("scopePath must be an array");
|
|
3876
|
-
return Object.freeze({
|
|
3877
|
-
kind: "policy",
|
|
3878
|
-
authorization: resolveServiceAuthorization({
|
|
3879
|
-
...input,
|
|
3880
|
-
binding: {
|
|
3881
|
-
...input.binding,
|
|
3882
|
-
scopePath: copyAuthorizationValue(value.scopePath)
|
|
3883
|
-
},
|
|
3884
|
-
authorization: value.authorization,
|
|
3885
|
-
applicability: "output"
|
|
3886
|
-
})
|
|
3887
|
-
});
|
|
3856
|
+
// src/acl/field-authorization.ts
|
|
3857
|
+
function extractScopedOutputRule(schema, field, access) {
|
|
3858
|
+
if (!schema || !Object.prototype.hasOwnProperty.call(schema, field)) return void 0;
|
|
3859
|
+
const raw = schema[field];
|
|
3860
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) && Object.prototype.hasOwnProperty.call(raw, access) ? raw[access] : raw;
|
|
3888
3861
|
}
|
|
3889
|
-
function
|
|
3890
|
-
|
|
3891
|
-
if (!record3) authorizationError("invalid document stage");
|
|
3892
|
-
if (!matchesAuthorizationSnapshot(record3.input, record3.snapshot)) authorizationError("changed document snapshot");
|
|
3893
|
-
return record3;
|
|
3862
|
+
function extractOutputFieldRules(schema, path, access) {
|
|
3863
|
+
return extractOutputFieldRuleEntries(schema, path, access).map((entry) => entry.rule);
|
|
3894
3864
|
}
|
|
3895
|
-
function
|
|
3896
|
-
|
|
3897
|
-
if (
|
|
3898
|
-
|
|
3899
|
-
|
|
3865
|
+
function extractOutputFieldRuleEntries(schema, path, access, prefix = "") {
|
|
3866
|
+
if (!schema) return [{ path: `${prefix}${path}`, rule: void 0 }];
|
|
3867
|
+
if (Object.prototype.hasOwnProperty.call(schema, path))
|
|
3868
|
+
return [{ path: `${prefix}${path}`, rule: extractScopedOutputRule(schema, path, access) }];
|
|
3869
|
+
const [head, ...rest] = path.split(".");
|
|
3870
|
+
const rule = extractScopedOutputRule(schema, head, access);
|
|
3871
|
+
const raw = schema[head];
|
|
3872
|
+
const entry = { path: `${prefix}${head}`, rule };
|
|
3873
|
+
if (!rest.length || !raw?.sub) return [entry];
|
|
3874
|
+
return [entry, ...extractOutputFieldRuleEntries(raw.sub, rest.join("."), access, `${prefix}${head}.`)];
|
|
3900
3875
|
}
|
|
3901
|
-
function
|
|
3902
|
-
|
|
3903
|
-
authorizationRecord(projectedSnapshot, "projected document snapshot");
|
|
3904
|
-
const stage = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
3905
|
-
stages.set(stage, {
|
|
3906
|
-
call,
|
|
3907
|
-
binding: Object.freeze({ ...binding, scopePath: Object.freeze([...binding.scopePath ?? []]) }),
|
|
3908
|
-
input: projectedSnapshot,
|
|
3909
|
-
snapshot: copyAuthorizationValue(projectedSnapshot, "document")
|
|
3910
|
-
});
|
|
3911
|
-
return stage;
|
|
3876
|
+
function hasExplicitFieldGrant(policy, path) {
|
|
3877
|
+
return policy?.mode === "unrestricted" || policy?.mode === "grant" && policy.paths.some((grant) => path === grant || path.startsWith(`${grant}.`));
|
|
3912
3878
|
}
|
|
3913
|
-
function
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3879
|
+
function classifyRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
3880
|
+
if (typeof rule === "boolean") return rule ? "granted" : "denied";
|
|
3881
|
+
if (typeof rule === "function") return "deferred";
|
|
3882
|
+
const validator = createValidator((key) => permissions.has(key));
|
|
3883
|
+
if (typeof rule !== "string" && !Array.isArray(rule)) return "denied";
|
|
3884
|
+
if (typeof rule === "string" ? validator.stringHandler(rule) : validator.arrayHandler(rule)) return "granted";
|
|
3885
|
+
const possible = createValidator(
|
|
3886
|
+
(key) => permissions.has(key) || !modelPermissionPrefix || key.startsWith(modelPermissionPrefix)
|
|
3887
|
+
);
|
|
3888
|
+
return (typeof rule === "string" ? possible.stringHandler(rule) : possible.arrayHandler(rule)) ? "deferred" : "denied";
|
|
3919
3889
|
}
|
|
3920
|
-
function
|
|
3921
|
-
const
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
stageRecord(stage);
|
|
3925
|
-
const result2 = resolveGrants.call(
|
|
3926
|
-
record3.binding.request,
|
|
3927
|
-
copyAuthorizationValue(record3.snapshot, "document"),
|
|
3928
|
-
getAuthorizationPermissions(record3.call, record3.binding)
|
|
3929
|
-
);
|
|
3930
|
-
const grants = result2 && typeof result2.then === "function" ? await result2 : result2;
|
|
3931
|
-
stageRecord(stage);
|
|
3932
|
-
const ownedGrants = copyAuthorizationValue(authorizationRecord(grants, "document grants"));
|
|
3933
|
-
const handle = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
3934
|
-
documents.set(handle, { stage, grants: ownedGrants, decisions: /* @__PURE__ */ new Map() });
|
|
3935
|
-
return handle;
|
|
3936
|
-
});
|
|
3937
|
-
}
|
|
3938
|
-
return record3.result;
|
|
3890
|
+
function prepareRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
3891
|
+
const state = classifyRequestFieldRule(rule, permissions, modelPermissionPrefix);
|
|
3892
|
+
const invariant = state === "denied" && modelPermissionPrefix ? classifyRequestFieldRule(rule, permissions) : state;
|
|
3893
|
+
return Object.freeze({ state, decision: invariant === "deferred" ? void 0 : invariant === "granted" });
|
|
3939
3894
|
}
|
|
3940
|
-
function
|
|
3941
|
-
|
|
3942
|
-
const stage = stageRecord(record3.stage);
|
|
3943
|
-
assertAuthorizationBinding(stage.call, binding);
|
|
3944
|
-
return Object.freeze({
|
|
3945
|
-
authorization: stage.call,
|
|
3946
|
-
stage: record3.stage,
|
|
3947
|
-
grants: copyAuthorizationValue(record3.grants),
|
|
3948
|
-
...readServiceAuthorizationAccess(stage.call, binding)
|
|
3949
|
-
});
|
|
3895
|
+
function combineFieldAuthorizationStates(states2) {
|
|
3896
|
+
return states2.includes("denied") ? "denied" : states2.includes("deferred") ? "deferred" : "granted";
|
|
3950
3897
|
}
|
|
3951
|
-
function
|
|
3952
|
-
|
|
3953
|
-
const
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
...readServiceAuthorizationAccess(stage.call, binding)
|
|
3958
|
-
});
|
|
3898
|
+
function classifyEffectiveFieldAuthorization(args) {
|
|
3899
|
+
if (hasExplicitFieldGrant(args.outputFields, args.path)) return "granted";
|
|
3900
|
+
const states2 = args.rules.map(
|
|
3901
|
+
(rule) => classifyRequestFieldRule(rule, args.globalPermissions, args.modelPermissionPrefix)
|
|
3902
|
+
);
|
|
3903
|
+
return combineFieldAuthorizationStates(states2);
|
|
3959
3904
|
}
|
|
3960
|
-
function
|
|
3961
|
-
const
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
return
|
|
3970
|
-
}
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
if (typeof result2 !== "boolean") authorizationError("field decision must be boolean");
|
|
3983
|
-
return result2;
|
|
3984
|
-
});
|
|
3985
|
-
record3.decisions.set(field, decision);
|
|
3905
|
+
async function evaluateScopedAccessRule(args) {
|
|
3906
|
+
const { req, rule, globalPermissions, docPermissions, modelPermissionPrefix } = args;
|
|
3907
|
+
if (typeof rule === "boolean") return rule;
|
|
3908
|
+
const validator = createValidator((key) => {
|
|
3909
|
+
try {
|
|
3910
|
+
if (globalPermissions?.has(key)) return true;
|
|
3911
|
+
} catch {
|
|
3912
|
+
}
|
|
3913
|
+
try {
|
|
3914
|
+
return Boolean((docPermissions ?? {})[stripModelPermissionPrefix(key, modelPermissionPrefix)]);
|
|
3915
|
+
} catch {
|
|
3916
|
+
return false;
|
|
3917
|
+
}
|
|
3918
|
+
});
|
|
3919
|
+
if (typeof rule === "string") return validator.stringHandler(rule);
|
|
3920
|
+
if (Array.isArray(rule)) return validator.arrayHandler(rule);
|
|
3921
|
+
if (typeof rule === "function") {
|
|
3922
|
+
try {
|
|
3923
|
+
return Boolean(await rule.call(req, globalPermissions, docPermissions));
|
|
3924
|
+
} catch {
|
|
3925
|
+
return false;
|
|
3926
|
+
}
|
|
3986
3927
|
}
|
|
3987
|
-
return
|
|
3988
|
-
}
|
|
3989
|
-
function unchangedOutput(output, record3) {
|
|
3990
|
-
if (!matchesAuthorizationSnapshot(output, record3.snapshot)) return false;
|
|
3991
|
-
const identities = outputIdentities(output);
|
|
3992
|
-
return identities.length === record3.identities.length && identities.every((identity, i) => identity === record3.identities[i]);
|
|
3928
|
+
return false;
|
|
3993
3929
|
}
|
|
3994
|
-
function
|
|
3995
|
-
|
|
3996
|
-
const
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
authorizationError("document call/access/stage mismatch");
|
|
4000
|
-
}
|
|
4001
|
-
const association = outputs.get(use.output);
|
|
4002
|
-
if (!association || association.handle !== handle || !unchangedOutput(use.output, association)) {
|
|
4003
|
-
authorizationError("unknown, replaced or mutated authorized output");
|
|
3930
|
+
async function evaluateEffectiveFieldAuthorization(args) {
|
|
3931
|
+
if (hasExplicitFieldGrant(args.outputFields, args.path)) return true;
|
|
3932
|
+
for (const [index, rule] of args.rules.entries()) {
|
|
3933
|
+
if (!await (args.evaluateRule ? args.evaluateRule(rule, index) : evaluateScopedAccessRule({ ...args, rule })))
|
|
3934
|
+
return false;
|
|
4004
3935
|
}
|
|
3936
|
+
return true;
|
|
4005
3937
|
}
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
const previous = outputs.get(output);
|
|
4012
|
-
if (previous.handle !== handle || !unchangedOutput(output, previous))
|
|
4013
|
-
authorizationError("output already associated");
|
|
4014
|
-
return;
|
|
4015
|
-
}
|
|
4016
|
-
outputs.set(output, {
|
|
4017
|
-
handle,
|
|
4018
|
-
snapshot: copyAuthorizationValue(output, "document"),
|
|
4019
|
-
identities: outputIdentities(output)
|
|
4020
|
-
});
|
|
4021
|
-
}
|
|
4022
|
-
function transferDocumentAuthorization(handle, use, copy) {
|
|
4023
|
-
assertDocumentAuthorization(handle, use);
|
|
4024
|
-
associateDocumentAuthorization(handle, use.binding, copy);
|
|
4025
|
-
}
|
|
4026
|
-
function isKnownAuthorizationOutput(output) {
|
|
4027
|
-
return outputs.has(output);
|
|
4028
|
-
}
|
|
4029
|
-
function getAssociatedDocumentAuthorization(output, call) {
|
|
4030
|
-
const record3 = outputs.get(output);
|
|
4031
|
-
if (!record3 || !unchangedOutput(output, record3)) return void 0;
|
|
4032
|
-
const stage = stageRecord(documentRecord(record3.handle).stage);
|
|
4033
|
-
if (call && getAuthorizationProvenance(stage.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
4034
|
-
return record3.handle;
|
|
4035
|
-
}
|
|
4036
|
-
function transferDocumentAuthorizationGraph(source, copy, copyOrigins) {
|
|
4037
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
4038
|
-
const visit = (source2, copy2) => {
|
|
4039
|
-
if (!copy2 || typeof copy2 !== "object" || seen.has(copy2)) return;
|
|
4040
|
-
seen.add(copy2);
|
|
4041
|
-
source2 = copyOrigins?.get(copy2) ?? source2;
|
|
4042
|
-
if (source2 instanceof import_mongoose5.Document) source2 = source2._doc;
|
|
4043
|
-
const original = source2 && typeof source2 === "object" ? source2 : void 0;
|
|
4044
|
-
if (!original && !copyOrigins) return;
|
|
4045
|
-
const association = original && outputs.get(original);
|
|
4046
|
-
if (association) {
|
|
4047
|
-
const stage = stageRecord(documentRecord(association.handle).stage);
|
|
4048
|
-
transferDocumentAuthorization(
|
|
4049
|
-
association.handle,
|
|
4050
|
-
{
|
|
4051
|
-
binding: stage.binding,
|
|
4052
|
-
output: original,
|
|
4053
|
-
outputAccess: readServiceAuthorizationAccess(stage.call, stage.binding).outputAccess,
|
|
4054
|
-
authorization: stage.call,
|
|
4055
|
-
stage: documentRecord(association.handle).stage
|
|
4056
|
-
},
|
|
4057
|
-
copy2
|
|
4058
|
-
);
|
|
4059
|
-
}
|
|
4060
|
-
for (const key of Object.keys(copy2)) {
|
|
4061
|
-
const descriptor = original && Object.getOwnPropertyDescriptor(original, key);
|
|
4062
|
-
if (descriptor && "value" in descriptor) {
|
|
4063
|
-
visit(descriptor.value, copy2[key]);
|
|
4064
|
-
} else if (copyOrigins) {
|
|
4065
|
-
visit(void 0, copy2[key]);
|
|
4066
|
-
}
|
|
4067
|
-
}
|
|
4068
|
-
};
|
|
4069
|
-
visit(source, copy);
|
|
4070
|
-
}
|
|
4071
|
-
function createServiceOutputContext(diagnostic, handle, use) {
|
|
4072
|
-
assertDocumentAuthorization(handle, use);
|
|
4073
|
-
const rootOutput = use.output;
|
|
4074
|
-
const root = outputs.get(rootOutput);
|
|
4075
|
-
const graph = new Set(root.identities);
|
|
4076
|
-
const call = stageRecord(documentRecord(handle).stage).call;
|
|
4077
|
-
const context = { ...diagnostic };
|
|
4078
|
-
Object.defineProperties(context, {
|
|
4079
|
-
documentAuthorization: { value: handle, enumerable: false, writable: false, configurable: false },
|
|
4080
|
-
getDocumentAuthorization: {
|
|
4081
|
-
enumerable: false,
|
|
4082
|
-
writable: false,
|
|
4083
|
-
configurable: false,
|
|
4084
|
-
value(output) {
|
|
4085
|
-
if (!graph.has(output) || !unchangedOutput(rootOutput, root)) return void 0;
|
|
4086
|
-
const association = outputs.get(output);
|
|
4087
|
-
if (!association || !unchangedOutput(output, association)) return void 0;
|
|
4088
|
-
try {
|
|
4089
|
-
documentRecord(handle);
|
|
4090
|
-
const child = stageRecord(documentRecord(association.handle).stage);
|
|
4091
|
-
if (getAuthorizationProvenance(child.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
4092
|
-
return association.handle;
|
|
4093
|
-
} catch {
|
|
4094
|
-
return void 0;
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
}
|
|
4098
|
-
});
|
|
4099
|
-
return context;
|
|
4100
|
-
}
|
|
4101
|
-
var import_mongoose5, stages, documents, outputs;
|
|
4102
|
-
var init_document_authorization = __esm({
|
|
4103
|
-
"src/acl/document-authorization.ts"() {
|
|
4104
|
-
import_mongoose5 = require("mongoose");
|
|
4105
|
-
init_service_authorization();
|
|
4106
|
-
init_authorization_snapshot();
|
|
4107
|
-
stages = /* @__PURE__ */ new WeakMap();
|
|
4108
|
-
documents = /* @__PURE__ */ new WeakMap();
|
|
4109
|
-
outputs = /* @__PURE__ */ new WeakMap();
|
|
4110
|
-
}
|
|
4111
|
-
});
|
|
4112
|
-
|
|
4113
|
-
// src/output/include-output.ts
|
|
4114
|
-
function prepareIncludeOutput(doc) {
|
|
4115
|
-
if (stateFor(doc)) return doc;
|
|
4116
|
-
const source = isolateDocForOutput(doc);
|
|
4117
|
-
transferDocumentAuthorizationGraph(doc, source);
|
|
4118
|
-
const working = deepIsolateValue(source);
|
|
4119
|
-
outputs2.set(working, { original: doc, source, attachments: [] });
|
|
4120
|
-
return working;
|
|
4121
|
-
}
|
|
4122
|
-
function attachIncludeOutput(doc, path, value) {
|
|
4123
|
-
const state = stateFor(doc);
|
|
4124
|
-
if (!state) throw new Error("Include attachment requires a prepared output row");
|
|
4125
|
-
state.attachments.push({ path, value });
|
|
4126
|
-
(0, import_utils19.set)(doc, path, deepIsolateValue(value));
|
|
4127
|
-
}
|
|
4128
|
-
function getIncludeSource(doc) {
|
|
4129
|
-
return stateFor(doc)?.source ?? doc;
|
|
4130
|
-
}
|
|
4131
|
-
function getIncludeOriginal(doc) {
|
|
4132
|
-
return stateFor(doc)?.original ?? doc;
|
|
4133
|
-
}
|
|
4134
|
-
function restoreIncludeOutput(doc, output) {
|
|
4135
|
-
const attachments = stateFor(doc)?.attachments;
|
|
4136
|
-
if (!attachments?.length) return void 0;
|
|
4137
|
-
const origins = /* @__PURE__ */ new WeakMap();
|
|
4138
|
-
for (const { path, value } of attachments) {
|
|
4139
|
-
const copy = deepIsolateValue(value);
|
|
4140
|
-
if (copy !== null && typeof copy === "object") origins.set(copy, value);
|
|
4141
|
-
(0, import_utils19.set)(output, path, copy);
|
|
4142
|
-
}
|
|
4143
|
-
return origins;
|
|
4144
|
-
}
|
|
4145
|
-
var import_utils19, outputs2, stateFor;
|
|
4146
|
-
var init_include_output = __esm({
|
|
4147
|
-
"src/output/include-output.ts"() {
|
|
4148
|
-
import_utils19 = require("@web-ts-toolkit/utils");
|
|
4149
|
-
init_document_authorization();
|
|
4150
|
-
init_document();
|
|
4151
|
-
outputs2 = /* @__PURE__ */ new WeakMap();
|
|
4152
|
-
stateFor = (doc) => doc !== null && typeof doc === "object" ? outputs2.get(doc) : void 0;
|
|
4153
|
-
}
|
|
4154
|
-
});
|
|
4155
|
-
|
|
4156
|
-
// src/helpers/request-work.ts
|
|
4157
|
-
function getRequestWorkState(req, runtime) {
|
|
4158
|
-
let owners = states.get(req);
|
|
4159
|
-
if (!owners) {
|
|
4160
|
-
owners = /* @__PURE__ */ new WeakMap();
|
|
4161
|
-
states.set(req, owners);
|
|
4162
|
-
}
|
|
4163
|
-
let state = owners.get(runtime);
|
|
4164
|
-
if (!state) {
|
|
4165
|
-
const limits = resolveRequestComplexity(runtime.getGlobalOption("requestComplexity"));
|
|
4166
|
-
state = {
|
|
4167
|
-
totalQueries: 0,
|
|
4168
|
-
scheduler: new RequestConcurrencyScheduler(limits.maxBulkConcurrency),
|
|
4169
|
-
hookGate: new SharedHookGate(limits.maxHookConcurrency)
|
|
4170
|
-
};
|
|
4171
|
-
owners.set(runtime, state);
|
|
4172
|
-
}
|
|
4173
|
-
return state;
|
|
4174
|
-
}
|
|
4175
|
-
var states;
|
|
4176
|
-
var init_request_work = __esm({
|
|
4177
|
-
"src/helpers/request-work.ts"() {
|
|
4178
|
-
init_request_complexity();
|
|
4179
|
-
init_concurrency();
|
|
4180
|
-
states = /* @__PURE__ */ new WeakMap();
|
|
4181
|
-
}
|
|
4182
|
-
});
|
|
4183
|
-
|
|
4184
|
-
// src/acl/field-authorization.ts
|
|
4185
|
-
function extractScopedOutputRule(schema, field, access) {
|
|
4186
|
-
if (!schema || !Object.prototype.hasOwnProperty.call(schema, field)) return void 0;
|
|
4187
|
-
const raw = schema[field];
|
|
4188
|
-
return raw && typeof raw === "object" && !Array.isArray(raw) && Object.prototype.hasOwnProperty.call(raw, access) ? raw[access] : raw;
|
|
4189
|
-
}
|
|
4190
|
-
function extractOutputFieldRules(schema, path, access) {
|
|
4191
|
-
return extractOutputFieldRuleEntries(schema, path, access).map((entry) => entry.rule);
|
|
4192
|
-
}
|
|
4193
|
-
function extractOutputFieldRuleEntries(schema, path, access, prefix = "") {
|
|
4194
|
-
if (!schema) return [{ path: `${prefix}${path}`, rule: void 0 }];
|
|
4195
|
-
if (Object.prototype.hasOwnProperty.call(schema, path))
|
|
4196
|
-
return [{ path: `${prefix}${path}`, rule: extractScopedOutputRule(schema, path, access) }];
|
|
4197
|
-
const [head, ...rest] = path.split(".");
|
|
4198
|
-
const rule = extractScopedOutputRule(schema, head, access);
|
|
4199
|
-
const raw = schema[head];
|
|
4200
|
-
const entry = { path: `${prefix}${head}`, rule };
|
|
4201
|
-
if (!rest.length || !raw?.sub) return [entry];
|
|
4202
|
-
return [entry, ...extractOutputFieldRuleEntries(raw.sub, rest.join("."), access, `${prefix}${head}.`)];
|
|
4203
|
-
}
|
|
4204
|
-
function hasExplicitFieldGrant(policy, path) {
|
|
4205
|
-
return policy?.mode === "unrestricted" || policy?.mode === "grant" && policy.paths.some((grant) => path === grant || path.startsWith(`${grant}.`));
|
|
4206
|
-
}
|
|
4207
|
-
function classifyRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
4208
|
-
if (typeof rule === "boolean") return rule ? "granted" : "denied";
|
|
4209
|
-
if (typeof rule === "function") return "deferred";
|
|
4210
|
-
const validator = createValidator((key) => permissions.has(key));
|
|
4211
|
-
if (typeof rule !== "string" && !Array.isArray(rule)) return "denied";
|
|
4212
|
-
if (typeof rule === "string" ? validator.stringHandler(rule) : validator.arrayHandler(rule)) return "granted";
|
|
4213
|
-
const possible = createValidator(
|
|
4214
|
-
(key) => permissions.has(key) || !modelPermissionPrefix || key.startsWith(modelPermissionPrefix)
|
|
4215
|
-
);
|
|
4216
|
-
return (typeof rule === "string" ? possible.stringHandler(rule) : possible.arrayHandler(rule)) ? "deferred" : "denied";
|
|
4217
|
-
}
|
|
4218
|
-
function prepareRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
4219
|
-
const state = classifyRequestFieldRule(rule, permissions, modelPermissionPrefix);
|
|
4220
|
-
const invariant = state === "denied" && modelPermissionPrefix ? classifyRequestFieldRule(rule, permissions) : state;
|
|
4221
|
-
return Object.freeze({ state, decision: invariant === "deferred" ? void 0 : invariant === "granted" });
|
|
4222
|
-
}
|
|
4223
|
-
function combineFieldAuthorizationStates(states2) {
|
|
4224
|
-
return states2.includes("denied") ? "denied" : states2.includes("deferred") ? "deferred" : "granted";
|
|
4225
|
-
}
|
|
4226
|
-
function classifyEffectiveFieldAuthorization(args) {
|
|
4227
|
-
if (hasExplicitFieldGrant(args.outputFields, args.path)) return "granted";
|
|
4228
|
-
const states2 = args.rules.map(
|
|
4229
|
-
(rule) => classifyRequestFieldRule(rule, args.globalPermissions, args.modelPermissionPrefix)
|
|
4230
|
-
);
|
|
4231
|
-
return combineFieldAuthorizationStates(states2);
|
|
4232
|
-
}
|
|
4233
|
-
async function evaluateScopedAccessRule(args) {
|
|
4234
|
-
const { req, rule, globalPermissions, docPermissions, modelPermissionPrefix } = args;
|
|
4235
|
-
if (typeof rule === "boolean") return rule;
|
|
4236
|
-
const validator = createValidator((key) => {
|
|
4237
|
-
try {
|
|
4238
|
-
if (globalPermissions?.has(key)) return true;
|
|
4239
|
-
} catch {
|
|
4240
|
-
}
|
|
4241
|
-
try {
|
|
4242
|
-
return Boolean((docPermissions ?? {})[stripModelPermissionPrefix(key, modelPermissionPrefix)]);
|
|
4243
|
-
} catch {
|
|
4244
|
-
return false;
|
|
4245
|
-
}
|
|
4246
|
-
});
|
|
4247
|
-
if (typeof rule === "string") return validator.stringHandler(rule);
|
|
4248
|
-
if (Array.isArray(rule)) return validator.arrayHandler(rule);
|
|
4249
|
-
if (typeof rule === "function") {
|
|
4250
|
-
try {
|
|
4251
|
-
return Boolean(await rule.call(req, globalPermissions, docPermissions));
|
|
4252
|
-
} catch {
|
|
4253
|
-
return false;
|
|
4254
|
-
}
|
|
4255
|
-
}
|
|
4256
|
-
return false;
|
|
4257
|
-
}
|
|
4258
|
-
async function evaluateEffectiveFieldAuthorization(args) {
|
|
4259
|
-
if (hasExplicitFieldGrant(args.outputFields, args.path)) return true;
|
|
4260
|
-
for (const [index, rule] of args.rules.entries()) {
|
|
4261
|
-
if (!await (args.evaluateRule ? args.evaluateRule(rule, index) : evaluateScopedAccessRule({ ...args, rule })))
|
|
4262
|
-
return false;
|
|
4263
|
-
}
|
|
4264
|
-
return true;
|
|
4265
|
-
}
|
|
4266
|
-
var stripModelPermissionPrefix;
|
|
4267
|
-
var init_field_authorization = __esm({
|
|
4268
|
-
"src/acl/field-authorization.ts"() {
|
|
4269
|
-
init_helpers();
|
|
4270
|
-
stripModelPermissionPrefix = (key, prefix) => prefix && key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
3938
|
+
var stripModelPermissionPrefix;
|
|
3939
|
+
var init_field_authorization = __esm({
|
|
3940
|
+
"src/acl/field-authorization.ts"() {
|
|
3941
|
+
init_helpers();
|
|
3942
|
+
stripModelPermissionPrefix = (key, prefix) => prefix && key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
4271
3943
|
}
|
|
4272
3944
|
});
|
|
4273
3945
|
|
|
@@ -4495,10 +4167,10 @@ function planVirtualProjection(args) {
|
|
|
4495
4167
|
relatedPlans
|
|
4496
4168
|
};
|
|
4497
4169
|
}
|
|
4498
|
-
var
|
|
4170
|
+
var import_utils19, getScopedPermissionSchema, resolveAlwaysSelectForAccess, stripVirtualsFromNormalizedSelect, snapshotVirtualPaths, stripLeadingDash, dbPrefixForScope, toDbPath;
|
|
4499
4171
|
var init_virtual_projection = __esm({
|
|
4500
4172
|
"src/acl/virtual-projection.ts"() {
|
|
4501
|
-
|
|
4173
|
+
import_utils19 = require("@web-ts-toolkit/utils");
|
|
4502
4174
|
init_query();
|
|
4503
4175
|
init_field_authorization();
|
|
4504
4176
|
init_output_projection();
|
|
@@ -4506,20 +4178,20 @@ var init_virtual_projection = __esm({
|
|
|
4506
4178
|
init_virtual_populate_dependencies();
|
|
4507
4179
|
init_virtual_descriptor();
|
|
4508
4180
|
getScopedPermissionSchema = (root, scopePath) => {
|
|
4509
|
-
if (!root || !(0,
|
|
4181
|
+
if (!root || !(0, import_utils19.isPlainObject)(root)) return null;
|
|
4510
4182
|
if (scopePath.length === 0) return root;
|
|
4511
|
-
const scoped = (0,
|
|
4512
|
-
return (0,
|
|
4183
|
+
const scoped = (0, import_utils19.get)(root, scopePath.join("."));
|
|
4184
|
+
return (0, import_utils19.isPlainObject)(scoped) ? scoped : null;
|
|
4513
4185
|
};
|
|
4514
4186
|
resolveAlwaysSelectForAccess = (raw, access) => {
|
|
4515
4187
|
if (!raw) return [];
|
|
4516
|
-
if ((0,
|
|
4517
|
-
if ((0,
|
|
4188
|
+
if ((0, import_utils19.isArray)(raw)) return [...raw];
|
|
4189
|
+
if ((0, import_utils19.isPlainObject)(raw)) {
|
|
4518
4190
|
const record3 = raw;
|
|
4519
4191
|
const exact = record3[access];
|
|
4520
|
-
if ((0,
|
|
4192
|
+
if ((0, import_utils19.isArray)(exact)) return [...exact];
|
|
4521
4193
|
const def = record3.default;
|
|
4522
|
-
if ((0,
|
|
4194
|
+
if ((0, import_utils19.isArray)(def)) return [...def];
|
|
4523
4195
|
return [];
|
|
4524
4196
|
}
|
|
4525
4197
|
return [];
|
|
@@ -4544,6 +4216,34 @@ var init_virtual_projection = __esm({
|
|
|
4544
4216
|
});
|
|
4545
4217
|
|
|
4546
4218
|
// src/acl/output-projection.ts
|
|
4219
|
+
function copyOutputDecisionFields(value) {
|
|
4220
|
+
if (!Array.isArray(value) || import_node_util4.types.isProxy(value) || Object.getPrototypeOf(value) !== Array.prototype) return;
|
|
4221
|
+
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
4222
|
+
if (length > 2e4) return;
|
|
4223
|
+
const fields = [];
|
|
4224
|
+
for (let index = 0; index < length; index++) {
|
|
4225
|
+
const slot = Object.getOwnPropertyDescriptor(value, String(index));
|
|
4226
|
+
if (!slot || !("value" in slot) || typeof slot.value !== "string") return;
|
|
4227
|
+
fields.push(slot.value);
|
|
4228
|
+
}
|
|
4229
|
+
return Object.freeze(fields);
|
|
4230
|
+
}
|
|
4231
|
+
function readStaticOutputPlanFields(plan, authorization) {
|
|
4232
|
+
const record3 = staticPlanFields.get(plan);
|
|
4233
|
+
if (!record3 || record3.authorization !== authorization || import_node_util4.types.isProxy(plan)) return;
|
|
4234
|
+
const ownValue2 = (key) => {
|
|
4235
|
+
const slot = Object.getOwnPropertyDescriptor(plan, key);
|
|
4236
|
+
return slot && "value" in slot ? slot.value : void 0;
|
|
4237
|
+
};
|
|
4238
|
+
if (ownValue2("authorization") !== authorization || ownValue2("authorizationBinding") !== record3.binding) return;
|
|
4239
|
+
const children = ownValue2("childPlans");
|
|
4240
|
+
if (children !== record3.children || import_node_util4.types.isProxy(children) || Reflect.ownKeys(children).length) return;
|
|
4241
|
+
const persisted = copyOutputDecisionFields(ownValue2("outputPersistedFields"));
|
|
4242
|
+
const virtuals = copyOutputDecisionFields(ownValue2("outputVirtualNames"));
|
|
4243
|
+
const same = (a, b) => a?.length === b.length && a.every((field, index) => field === b[index]);
|
|
4244
|
+
if (!same(persisted, record3.persisted) || !same(virtuals, record3.virtuals)) return;
|
|
4245
|
+
return Object.freeze([.../* @__PURE__ */ new Set([...record3.persisted, ...record3.virtuals])]);
|
|
4246
|
+
}
|
|
4547
4247
|
function compactPersistedProjection(paths) {
|
|
4548
4248
|
const unique = [...new Set(paths.filter((p) => p && !p.startsWith("-")))];
|
|
4549
4249
|
return unique.filter((path) => !unique.some((parent) => parent !== path && path.startsWith(`${parent}.`)));
|
|
@@ -4572,6 +4272,13 @@ function planAuthorizedModelProjection(args) {
|
|
|
4572
4272
|
);
|
|
4573
4273
|
plan.authorization = args.authorization;
|
|
4574
4274
|
plan.authorizationBinding = Object.freeze({ ...args.binding, scopePath: Object.freeze(scope2) });
|
|
4275
|
+
staticPlanFields.set(plan, {
|
|
4276
|
+
authorization: args.authorization,
|
|
4277
|
+
binding: plan.authorizationBinding,
|
|
4278
|
+
persisted: Object.freeze([...plan.outputPersistedFields]),
|
|
4279
|
+
virtuals: Object.freeze([...plan.outputVirtualNames]),
|
|
4280
|
+
children: plan.childPlans
|
|
4281
|
+
});
|
|
4575
4282
|
return plan;
|
|
4576
4283
|
}
|
|
4577
4284
|
function planCatalogProjection(args, outputFields = { mode: "request" }) {
|
|
@@ -4770,22 +4477,662 @@ function planCatalogProjection(args, outputFields = { mode: "request" }) {
|
|
|
4770
4477
|
)
|
|
4771
4478
|
};
|
|
4772
4479
|
}
|
|
4773
|
-
var
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4480
|
+
var import_node_util4, staticPlanFields;
|
|
4481
|
+
var init_output_projection = __esm({
|
|
4482
|
+
"src/acl/output-projection.ts"() {
|
|
4483
|
+
import_node_util4 = require("util");
|
|
4484
|
+
init_query();
|
|
4485
|
+
init_authorization_snapshot();
|
|
4486
|
+
init_field_catalog();
|
|
4487
|
+
init_field_authorization();
|
|
4488
|
+
init_virtual_populate_dependencies();
|
|
4489
|
+
init_service_authorization();
|
|
4490
|
+
init_virtual_projection();
|
|
4491
|
+
staticPlanFields = /* @__PURE__ */ new WeakMap();
|
|
4492
|
+
}
|
|
4493
|
+
});
|
|
4494
|
+
|
|
4495
|
+
// src/acl/output-field-policy.ts
|
|
4496
|
+
function callFieldPolicy(authorization, binding) {
|
|
4497
|
+
assertAuthorizationBinding(authorization, binding);
|
|
4498
|
+
let policy = fieldPolicies.get(authorization);
|
|
4499
|
+
if (!policy) {
|
|
4500
|
+
const view = readServiceOutputFieldAuthorization(authorization, binding);
|
|
4501
|
+
policy = {
|
|
4502
|
+
schema: view.permissionSchema,
|
|
4503
|
+
requestPaths: view.permissionSchema == null || (0, import_utils20.isPlainObject)(view.permissionSchema) && Object.isFrozen(view.permissionSchema) ? Object.freeze(Object.keys(view.permissionSchema ?? {})) : void 0,
|
|
4504
|
+
prefix: view.modelPermissionPrefix ?? "",
|
|
4505
|
+
outputFields: view.outputFields,
|
|
4506
|
+
catalog: view.catalog,
|
|
4507
|
+
reusable: view.reusable,
|
|
4508
|
+
accesses: /* @__PURE__ */ new Map()
|
|
4509
|
+
};
|
|
4510
|
+
if (view.reusable) fieldPolicies.set(authorization, policy);
|
|
4511
|
+
}
|
|
4512
|
+
return policy;
|
|
4513
|
+
}
|
|
4514
|
+
function requestRuleClassification(entry, authorization, permissions, prefix) {
|
|
4515
|
+
if (typeof prefix !== "string") return void 0;
|
|
4516
|
+
let classification = entry.classifications.get(authorization);
|
|
4517
|
+
if (!classification) {
|
|
4518
|
+
classification = prepareRequestFieldRule(entry.rule, permissions, prefix);
|
|
4519
|
+
entry.classifications.set(authorization, classification);
|
|
4520
|
+
}
|
|
4521
|
+
return classification;
|
|
4522
|
+
}
|
|
4523
|
+
function invariantRuleLookup(schema, path) {
|
|
4524
|
+
if (schema == null) return true;
|
|
4525
|
+
if (!(0, import_utils20.isPlainObject)(schema) || !Object.isFrozen(schema)) return false;
|
|
4526
|
+
const exact = Object.getOwnPropertyDescriptor(schema, path);
|
|
4527
|
+
if (exact) {
|
|
4528
|
+
const raw2 = exact.value;
|
|
4529
|
+
return !raw2 || typeof raw2 !== "object" || Array.isArray(raw2) || (0, import_utils20.isPlainObject)(raw2) && Object.isFrozen(raw2);
|
|
4530
|
+
}
|
|
4531
|
+
const [head, ...rest] = path.split(".");
|
|
4532
|
+
const raw = Object.getOwnPropertyDescriptor(schema, head)?.value;
|
|
4533
|
+
if (raw == null) return true;
|
|
4534
|
+
if (!(0, import_utils20.isPlainObject)(raw) || !Object.isFrozen(raw)) return false;
|
|
4535
|
+
const sub = Object.getOwnPropertyDescriptor(raw, "sub");
|
|
4536
|
+
return !rest.length || !sub || invariantRuleLookup(sub.value, rest.join("."));
|
|
4537
|
+
}
|
|
4538
|
+
function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
4539
|
+
let cache = policy.accesses.get(access);
|
|
4540
|
+
if (!cache) {
|
|
4541
|
+
cache = /* @__PURE__ */ new Map();
|
|
4542
|
+
policy.accesses.set(access, cache);
|
|
4543
|
+
}
|
|
4544
|
+
let prepared = cache.get(path);
|
|
4545
|
+
if (!prepared) {
|
|
4546
|
+
const invariant = invariantRuleLookup(policy.schema, path);
|
|
4547
|
+
const permissions = getAuthorizationPermissions(authorization, binding);
|
|
4548
|
+
const entries = extractOutputFieldRuleEntries(policy.schema, path, access).map((entry) => ({
|
|
4549
|
+
...entry,
|
|
4550
|
+
classifications: /* @__PURE__ */ new WeakMap()
|
|
4551
|
+
}));
|
|
4552
|
+
const classifications = entries.map(
|
|
4553
|
+
(entry) => requestRuleClassification(entry, authorization, permissions, policy.prefix)
|
|
4554
|
+
);
|
|
4555
|
+
const backendGrant = hasExplicitFieldGrant(policy.outputFields, path);
|
|
4556
|
+
prepared = {
|
|
4557
|
+
entries,
|
|
4558
|
+
backendGrant,
|
|
4559
|
+
state: backendGrant ? "granted" : classifications.every((value) => value !== void 0) ? combineFieldAuthorizationStates(classifications.map((value) => value.state)) : void 0
|
|
4560
|
+
};
|
|
4561
|
+
if (invariant) cache.set(path, prepared);
|
|
4562
|
+
}
|
|
4563
|
+
return prepared;
|
|
4564
|
+
}
|
|
4565
|
+
function ordinaryContainer(value) {
|
|
4566
|
+
return value !== null && typeof value === "object" && !import_node_util5.types.isProxy(value) && Object.getPrototypeOf(value) === Object.prototype && Object.isFrozen(value);
|
|
4567
|
+
}
|
|
4568
|
+
function booleanRuleLookup(schema, path, access) {
|
|
4569
|
+
if (schema == null) return true;
|
|
4570
|
+
if (!ordinaryContainer(schema)) return false;
|
|
4571
|
+
const booleanRule = (raw) => {
|
|
4572
|
+
if (typeof raw === "boolean" || raw === void 0) return true;
|
|
4573
|
+
if (!ordinaryContainer(raw)) return false;
|
|
4574
|
+
const slot2 = Object.getOwnPropertyDescriptor(raw, access);
|
|
4575
|
+
return !!slot2 && "value" in slot2 && (typeof slot2.value === "boolean" || slot2.value === void 0);
|
|
4576
|
+
};
|
|
4577
|
+
const exact = Object.getOwnPropertyDescriptor(schema, path);
|
|
4578
|
+
if (exact) return "value" in exact && booleanRule(exact.value);
|
|
4579
|
+
const [head, ...rest] = path.split(".");
|
|
4580
|
+
const slot = Object.getOwnPropertyDescriptor(schema, head);
|
|
4581
|
+
if (!slot) return !(head in schema);
|
|
4582
|
+
if (!("value" in slot) || !booleanRule(slot.value)) return false;
|
|
4583
|
+
if (!rest.length || slot.value == null) return true;
|
|
4584
|
+
if (!ordinaryContainer(slot.value)) return false;
|
|
4585
|
+
const sub = Object.getOwnPropertyDescriptor(slot.value, "sub");
|
|
4586
|
+
if (!sub) return !("sub" in slot.value);
|
|
4587
|
+
if (!("value" in sub)) return false;
|
|
4588
|
+
return !sub.value || booleanRuleLookup(sub.value, rest.join("."), access);
|
|
4589
|
+
}
|
|
4590
|
+
function staticFieldPolicy(authorization, binding) {
|
|
4591
|
+
return canPrepareStaticOutputPolicy(authorization, binding) ? callFieldPolicy(authorization, binding) : void 0;
|
|
4592
|
+
}
|
|
4593
|
+
function prepareStaticOutputPaths(authorization, binding, paths, access, requestOnly = false) {
|
|
4594
|
+
const policy = staticFieldPolicy(authorization, binding);
|
|
4595
|
+
if (!policy?.reusable || typeof policy.prefix !== "string") return void 0;
|
|
4596
|
+
const { catalog } = policy;
|
|
4597
|
+
if (paths.some(
|
|
4598
|
+
(path) => !requestOnly && !isCatalogOutputPath(catalog, path) || !booleanRuleLookup(policy.schema, path, access)
|
|
4599
|
+
))
|
|
4600
|
+
return void 0;
|
|
4601
|
+
return paths.map((path) => {
|
|
4602
|
+
const prepared = prepareOutputPath(policy, authorization, binding, path, access);
|
|
4603
|
+
return {
|
|
4604
|
+
path,
|
|
4605
|
+
backendGrant: !requestOnly && prepared.backendGrant,
|
|
4606
|
+
granted: prepared.backendGrant || prepared.entries.every((entry) => entry.rule === true),
|
|
4607
|
+
entries: prepared.entries.map((entry) => ({
|
|
4608
|
+
key: `request:${access}:${entry.path}`,
|
|
4609
|
+
allowed: entry.rule === true
|
|
4610
|
+
}))
|
|
4611
|
+
};
|
|
4612
|
+
});
|
|
4613
|
+
}
|
|
4614
|
+
var import_node_util5, import_utils20, fieldPolicies;
|
|
4615
|
+
var init_output_field_policy = __esm({
|
|
4616
|
+
"src/acl/output-field-policy.ts"() {
|
|
4617
|
+
import_node_util5 = require("util");
|
|
4618
|
+
import_utils20 = require("@web-ts-toolkit/utils");
|
|
4619
|
+
init_service_authorization();
|
|
4620
|
+
init_field_authorization();
|
|
4621
|
+
init_field_catalog();
|
|
4622
|
+
fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
4623
|
+
}
|
|
4624
|
+
});
|
|
4625
|
+
|
|
4626
|
+
// src/acl/document-authorization.ts
|
|
4627
|
+
function bindOutputDocumentOwner(handle, knownOutput, owner, binding) {
|
|
4628
|
+
lookupDocumentOwner(handle);
|
|
4629
|
+
if (knownOutput || owner && unresolvedDocuments.has(owner)) unresolvedDocuments.add(handle);
|
|
4630
|
+
if (owner) {
|
|
4631
|
+
lookupDocumentOwner(owner);
|
|
4632
|
+
owningDocuments.set(handle, { handle: owner, binding });
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
function readOutputDocumentOwner(handle) {
|
|
4636
|
+
return owningDocuments.get(handle);
|
|
4637
|
+
}
|
|
4638
|
+
function isUnresolvedOutputDocument(handle) {
|
|
4639
|
+
return unresolvedDocuments.has(handle);
|
|
4640
|
+
}
|
|
4641
|
+
function normalizeOutputAuthorizationOptions(input, options, purpose) {
|
|
4642
|
+
const value = authorizationRecord(options, "output options");
|
|
4643
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
4644
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
4645
|
+
if (typeof key !== "string" || !("value" in descriptor) || !descriptor.enumerable) {
|
|
4646
|
+
authorizationError("invalid output option property");
|
|
4647
|
+
}
|
|
4648
|
+
}
|
|
4649
|
+
assertAuthorizationKeys(
|
|
4650
|
+
value,
|
|
4651
|
+
["authorization", "scopePath", "documentAuthorization", ...purpose ? ["purpose"] : []],
|
|
4652
|
+
"output options"
|
|
4653
|
+
);
|
|
4654
|
+
if (purpose && value.purpose !== purpose) authorizationError("genAllowedFields requires purpose: output");
|
|
4655
|
+
if (Object.prototype.hasOwnProperty.call(value, "documentAuthorization")) {
|
|
4656
|
+
if (Object.prototype.hasOwnProperty.call(value, "authorization") || Object.prototype.hasOwnProperty.call(value, "scopePath")) {
|
|
4657
|
+
authorizationError("document handle cannot be mixed with raw policy/scope");
|
|
4658
|
+
}
|
|
4659
|
+
const handle = value.documentAuthorization;
|
|
4660
|
+
const { stage } = validateDocumentOwner(handle);
|
|
4661
|
+
const binding = Object.freeze({ ...input.binding, scopePath: stage.binding.scopePath });
|
|
4662
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4663
|
+
const access = readServiceAuthorizationAccess(stage.call, binding);
|
|
4664
|
+
if (input.access.outputAccess !== access.outputAccess) authorizationError("document access mismatch");
|
|
4665
|
+
return Object.freeze({ kind: "document", documentAuthorization: handle, binding });
|
|
4666
|
+
}
|
|
4667
|
+
if (value.scopePath !== void 0 && !Array.isArray(value.scopePath))
|
|
4668
|
+
authorizationError("scopePath must be an array");
|
|
4669
|
+
return Object.freeze({
|
|
4670
|
+
kind: "policy",
|
|
4671
|
+
authorization: resolveServiceAuthorization({
|
|
4672
|
+
...input,
|
|
4673
|
+
binding: {
|
|
4674
|
+
...input.binding,
|
|
4675
|
+
scopePath: copyAuthorizationValue(value.scopePath)
|
|
4676
|
+
},
|
|
4677
|
+
authorization: value.authorization,
|
|
4678
|
+
applicability: "output"
|
|
4679
|
+
})
|
|
4680
|
+
});
|
|
4681
|
+
}
|
|
4682
|
+
function lookupStageOwner(stage) {
|
|
4683
|
+
const record3 = stages.get(stage);
|
|
4684
|
+
if (!record3) authorizationError("invalid document stage");
|
|
4685
|
+
return record3;
|
|
4686
|
+
}
|
|
4687
|
+
function lookupDocumentOwner(handle) {
|
|
4688
|
+
const record3 = documents.get(handle);
|
|
4689
|
+
if (!record3) authorizationError("invalid document handle");
|
|
4690
|
+
return record3;
|
|
4691
|
+
}
|
|
4692
|
+
function validateStageOwner(record3) {
|
|
4693
|
+
if (!matchesAuthorizationSnapshot(record3.input, record3.snapshot)) authorizationError("changed document snapshot");
|
|
4694
|
+
}
|
|
4695
|
+
function validateDocumentOwner(handle) {
|
|
4696
|
+
const document = lookupDocumentOwner(handle);
|
|
4697
|
+
const stage = lookupStageOwner(document.stage);
|
|
4698
|
+
validateStageOwner(stage);
|
|
4699
|
+
validateStageOwner(stage);
|
|
4700
|
+
return { document, stage };
|
|
4701
|
+
}
|
|
4702
|
+
function createDocumentAuthorizationStage(call, binding, projectedSnapshot) {
|
|
4703
|
+
assertAuthorizationBinding(call, binding);
|
|
4704
|
+
authorizationRecord(projectedSnapshot, "projected document snapshot");
|
|
4705
|
+
const stage = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
4706
|
+
const ownedBinding = Object.freeze({ ...binding, scopePath: Object.freeze([...binding.scopePath ?? []]) });
|
|
4707
|
+
const snapshot = copyAuthorizationValue(projectedSnapshot, "document");
|
|
4708
|
+
stages.set(stage, {
|
|
4709
|
+
call,
|
|
4710
|
+
binding: ownedBinding,
|
|
4711
|
+
input: projectedSnapshot,
|
|
4712
|
+
snapshot
|
|
4713
|
+
});
|
|
4714
|
+
return stage;
|
|
4715
|
+
}
|
|
4716
|
+
function assertDocumentAuthorizationStage(stage, call, binding, projectedSnapshot) {
|
|
4717
|
+
const record3 = lookupStageOwner(stage);
|
|
4718
|
+
validateStageOwner(record3);
|
|
4719
|
+
assertAuthorizationBinding(record3.call, binding);
|
|
4720
|
+
if (record3.call !== call || record3.input !== projectedSnapshot || !matchesAuthorizationSnapshot(projectedSnapshot, record3.snapshot)) {
|
|
4721
|
+
authorizationError("document call/stage/snapshot mismatch");
|
|
4722
|
+
}
|
|
4723
|
+
}
|
|
4724
|
+
function resolveDocumentAuthorization(stage, resolveGrants) {
|
|
4725
|
+
const record3 = lookupStageOwner(stage);
|
|
4726
|
+
validateStageOwner(record3);
|
|
4727
|
+
if (!record3.result) {
|
|
4728
|
+
record3.result = Promise.resolve().then(async () => {
|
|
4729
|
+
validateStageOwner(record3);
|
|
4730
|
+
const result2 = resolveGrants.call(
|
|
4731
|
+
record3.binding.request,
|
|
4732
|
+
copyAuthorizationValue(record3.snapshot, "document"),
|
|
4733
|
+
getAuthorizationPermissions(record3.call, record3.binding)
|
|
4734
|
+
);
|
|
4735
|
+
const grants = result2 && typeof result2.then === "function" ? await result2 : result2;
|
|
4736
|
+
validateStageOwner(record3);
|
|
4737
|
+
const ownedGrants = copyAuthorizationValue(authorizationRecord(grants, "document grants"));
|
|
4738
|
+
const handle = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
4739
|
+
documents.set(handle, { stage, grants: ownedGrants, decisions: /* @__PURE__ */ new Map() });
|
|
4740
|
+
return handle;
|
|
4741
|
+
});
|
|
4742
|
+
}
|
|
4743
|
+
return record3.result;
|
|
4744
|
+
}
|
|
4745
|
+
function readDocumentAuthorization(handle, binding) {
|
|
4746
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4747
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4748
|
+
return Object.freeze({
|
|
4749
|
+
authorization: stage.call,
|
|
4750
|
+
stage: record3.stage,
|
|
4751
|
+
grants: copyAuthorizationValue(record3.grants),
|
|
4752
|
+
...readServiceAuthorizationAccess(stage.call, binding)
|
|
4753
|
+
});
|
|
4754
|
+
}
|
|
4755
|
+
function readDocumentAuthorizationAccess(handle, binding) {
|
|
4756
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4757
|
+
return Object.freeze({
|
|
4758
|
+
authorization: stage.call,
|
|
4759
|
+
stage: record3.stage,
|
|
4760
|
+
...readServiceAuthorizationAccess(stage.call, binding)
|
|
4761
|
+
});
|
|
4762
|
+
}
|
|
4763
|
+
function memoizeDocumentFieldDecision(handle, binding, field, evaluate) {
|
|
4764
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4765
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4766
|
+
let decision = record3.decisions.get(field);
|
|
4767
|
+
if (decision) {
|
|
4768
|
+
return decision.promise.then((result2) => {
|
|
4769
|
+
validateStageOwner(stage);
|
|
4770
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4771
|
+
return result2;
|
|
4772
|
+
});
|
|
4773
|
+
} else {
|
|
4774
|
+
const created = {
|
|
4775
|
+
state: "pending",
|
|
4776
|
+
promise: Promise.resolve().then(async () => {
|
|
4777
|
+
validateStageOwner(stage);
|
|
4778
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4779
|
+
const result2 = await evaluate.call(
|
|
4780
|
+
stage.binding.request,
|
|
4781
|
+
getAuthorizationPermissions(stage.call, binding),
|
|
4782
|
+
copyAuthorizationValue(record3.grants)
|
|
4783
|
+
);
|
|
4784
|
+
validateStageOwner(stage);
|
|
4785
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4786
|
+
if (typeof result2 !== "boolean") authorizationError("field decision must be boolean");
|
|
4787
|
+
return result2;
|
|
4788
|
+
})
|
|
4789
|
+
};
|
|
4790
|
+
void created.promise.then(
|
|
4791
|
+
(value) => {
|
|
4792
|
+
created.value = value;
|
|
4793
|
+
created.state = "fulfilled";
|
|
4794
|
+
},
|
|
4795
|
+
() => {
|
|
4796
|
+
created.state = "rejected";
|
|
4797
|
+
}
|
|
4798
|
+
);
|
|
4799
|
+
decision = created;
|
|
4800
|
+
record3.decisions.set(field, decision);
|
|
4801
|
+
}
|
|
4802
|
+
return decision.promise;
|
|
4803
|
+
}
|
|
4804
|
+
function ordinaryDecisionBinding(binding) {
|
|
4805
|
+
if (import_node_util6.types.isProxy(binding) || Object.getPrototypeOf(binding) !== Object.prototype) return false;
|
|
4806
|
+
for (const key of ["request", "runtime", "model", "modelName", "scopePath"]) {
|
|
4807
|
+
const slot = Object.getOwnPropertyDescriptor(binding, key);
|
|
4808
|
+
if (slot && !("value" in slot)) return false;
|
|
4809
|
+
if (!slot && key !== "scopePath") return false;
|
|
4810
|
+
if (!slot && key in binding) return false;
|
|
4811
|
+
}
|
|
4812
|
+
const scope2 = Object.getOwnPropertyDescriptor(binding, "scopePath")?.value;
|
|
4813
|
+
return scope2 === void 0 || copyOutputDecisionFields(scope2) !== void 0;
|
|
4814
|
+
}
|
|
4815
|
+
function settleStaticFieldBatch(handle, binding, paths) {
|
|
4816
|
+
const { document, stage } = validateDocumentOwner(handle);
|
|
4817
|
+
if (!ordinaryDecisionBinding(binding)) {
|
|
4818
|
+
validateDocumentOwner(handle);
|
|
4819
|
+
return;
|
|
4820
|
+
}
|
|
4821
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4822
|
+
const expected = /* @__PURE__ */ new Map();
|
|
4823
|
+
const journal = /* @__PURE__ */ new Map();
|
|
4824
|
+
const result2 = /* @__PURE__ */ new Map();
|
|
4825
|
+
const unresolved = unresolvedDocuments.has(handle);
|
|
4826
|
+
let available = !owningDocuments.has(handle);
|
|
4827
|
+
const read = (key) => {
|
|
4828
|
+
const memo = document.decisions.get(key);
|
|
4829
|
+
expected.set(key, memo);
|
|
4830
|
+
if (memo) {
|
|
4831
|
+
if (memo.state !== "fulfilled") available = false;
|
|
4832
|
+
return memo.value;
|
|
4833
|
+
}
|
|
4834
|
+
return journal.get(key);
|
|
4835
|
+
};
|
|
4836
|
+
for (const path of paths) {
|
|
4837
|
+
if (!available) break;
|
|
4838
|
+
let allowed = path.outputKey ? read(path.outputKey) : void 0;
|
|
4839
|
+
if (!available) break;
|
|
4840
|
+
if (allowed === void 0) {
|
|
4841
|
+
const policy = path.policy;
|
|
4842
|
+
if (!policy) {
|
|
4843
|
+
available = false;
|
|
4844
|
+
break;
|
|
4845
|
+
}
|
|
4846
|
+
if (path.outputKey && unresolved && !policy.granted) allowed = false;
|
|
4847
|
+
else if (path.outputKey && policy.backendGrant) allowed = true;
|
|
4848
|
+
else {
|
|
4849
|
+
allowed = true;
|
|
4850
|
+
for (const entry of policy.entries) {
|
|
4851
|
+
let decision = read(entry.key);
|
|
4852
|
+
if (!available) break;
|
|
4853
|
+
if (decision === void 0) {
|
|
4854
|
+
decision = entry.allowed;
|
|
4855
|
+
journal.set(entry.key, decision);
|
|
4856
|
+
}
|
|
4857
|
+
if (!decision) {
|
|
4858
|
+
allowed = false;
|
|
4859
|
+
break;
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
}
|
|
4863
|
+
if (!available) break;
|
|
4864
|
+
if (path.outputKey) journal.set(path.outputKey, allowed);
|
|
4865
|
+
}
|
|
4866
|
+
result2.set(path.field, allowed);
|
|
4867
|
+
}
|
|
4868
|
+
validateDocumentOwner(handle);
|
|
4869
|
+
if (!ordinaryDecisionBinding(binding)) return;
|
|
4870
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4871
|
+
if (!available || owningDocuments.has(handle) || unresolvedDocuments.has(handle) !== unresolved || [...expected].some(([key, memo]) => document.decisions.get(key) !== memo))
|
|
4872
|
+
return;
|
|
4873
|
+
for (const [key, value] of journal) {
|
|
4874
|
+
document.decisions.set(key, { promise: Promise.resolve(value), state: "fulfilled", value });
|
|
4875
|
+
}
|
|
4876
|
+
return result2;
|
|
4877
|
+
}
|
|
4878
|
+
function tryStaticOutputFieldDecisions(handle, binding, plan, fields) {
|
|
4879
|
+
const document = lookupDocumentOwner(handle);
|
|
4880
|
+
const stage = lookupStageOwner(document.stage);
|
|
4881
|
+
if (!ordinaryDecisionBinding(binding) || owningDocuments.has(handle)) return;
|
|
4882
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4883
|
+
const canonical = readStaticOutputPlanFields(plan, stage.call);
|
|
4884
|
+
const ownedFields = copyOutputDecisionFields(fields);
|
|
4885
|
+
if (!canonical || !ownedFields) return;
|
|
4886
|
+
let index = 0;
|
|
4887
|
+
for (const field of ownedFields) {
|
|
4888
|
+
const next = canonical.indexOf(field, index);
|
|
4889
|
+
if (next < 0) return;
|
|
4890
|
+
index = next + 1;
|
|
4891
|
+
}
|
|
4892
|
+
const prefix = (binding.scopePath ?? []).join(".");
|
|
4893
|
+
const paths = ownedFields.map((field) => {
|
|
4894
|
+
const path = prefix ? `${prefix}.${field}` : field;
|
|
4895
|
+
return { field, path, outputKey: `output:${path}` };
|
|
4896
|
+
});
|
|
4897
|
+
const missing = [];
|
|
4898
|
+
for (const path of paths) {
|
|
4899
|
+
const memo = document.decisions.get(path.outputKey);
|
|
4900
|
+
if (memo && memo.state !== "fulfilled") return;
|
|
4901
|
+
if (!memo) missing.push(path.path);
|
|
4902
|
+
}
|
|
4903
|
+
const access = readServiceAuthorizationAccess(stage.call, binding).outputAccess;
|
|
4904
|
+
const prepared = missing.length ? prepareStaticOutputPaths(stage.call, binding, missing, access) : [];
|
|
4905
|
+
if (!prepared) return;
|
|
4906
|
+
const policies = new Map(prepared.map((policy) => [policy.path, policy]));
|
|
4907
|
+
const decisions = settleStaticFieldBatch(
|
|
4908
|
+
handle,
|
|
4909
|
+
binding,
|
|
4910
|
+
paths.map((path) => ({ ...path, policy: policies.get(path.path) }))
|
|
4911
|
+
);
|
|
4912
|
+
if (decisions && !readStaticOutputPlanFields(plan, stage.call)) authorizationError("changed static output plan");
|
|
4913
|
+
return decisions;
|
|
4914
|
+
}
|
|
4915
|
+
function tryStaticRequestFieldPaths(handle, binding, access) {
|
|
4916
|
+
const document = lookupDocumentOwner(handle);
|
|
4917
|
+
const stage = lookupStageOwner(document.stage);
|
|
4918
|
+
if (!ordinaryDecisionBinding(binding) || owningDocuments.has(handle) || typeof access !== "string") return;
|
|
4919
|
+
const policy = staticFieldPolicy(stage.call, binding);
|
|
4920
|
+
if (!policy?.reusable || !policy.requestPaths) return;
|
|
4921
|
+
const prepared = prepareStaticOutputPaths(stage.call, binding, policy.requestPaths, access, true);
|
|
4922
|
+
if (!prepared) return;
|
|
4923
|
+
const decisions = settleStaticFieldBatch(
|
|
4924
|
+
handle,
|
|
4925
|
+
binding,
|
|
4926
|
+
prepared.map((policy2) => ({ field: policy2.path, policy: policy2 }))
|
|
4927
|
+
);
|
|
4928
|
+
return decisions && [...decisions].filter(([, allowed]) => allowed).map(([field]) => field);
|
|
4929
|
+
}
|
|
4930
|
+
function unchangedOutput(output, record3) {
|
|
4931
|
+
if (!matchesAuthorizationSnapshot(output, record3.snapshot)) return false;
|
|
4932
|
+
const identities = outputIdentities(output);
|
|
4933
|
+
return identities.length === record3.identities.length && identities.every((identity, i) => identity === record3.identities[i]);
|
|
4934
|
+
}
|
|
4935
|
+
function assertDocumentAuthorization(handle, use) {
|
|
4936
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4937
|
+
assertAuthorizationBinding(stage.call, use.binding);
|
|
4938
|
+
if (use.authorization !== void 0 && stage.call !== use.authorization || use.stage !== void 0 && record3.stage !== use.stage || readServiceAuthorizationAccess(stage.call, use.binding).outputAccess !== use.outputAccess) {
|
|
4939
|
+
authorizationError("document call/access/stage mismatch");
|
|
4940
|
+
}
|
|
4941
|
+
const association = outputs.get(use.output);
|
|
4942
|
+
if (!association || association.handle !== handle || !unchangedOutput(use.output, association)) {
|
|
4943
|
+
authorizationError("unknown, replaced or mutated authorized output");
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
function associateDocumentAuthorization(handle, binding, output) {
|
|
4947
|
+
const { stage } = validateDocumentOwner(handle);
|
|
4948
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4949
|
+
if (!output || typeof output !== "object") authorizationError("output must be an object");
|
|
4950
|
+
if (outputs.has(output)) {
|
|
4951
|
+
const previous = outputs.get(output);
|
|
4952
|
+
if (previous.handle !== handle || !unchangedOutput(output, previous))
|
|
4953
|
+
authorizationError("output already associated");
|
|
4954
|
+
return;
|
|
4955
|
+
}
|
|
4956
|
+
outputs.set(output, {
|
|
4957
|
+
handle,
|
|
4958
|
+
snapshot: copyAuthorizationValue(output, "document"),
|
|
4959
|
+
identities: outputIdentities(output)
|
|
4960
|
+
});
|
|
4961
|
+
}
|
|
4962
|
+
function transferDocumentAuthorization(handle, use, copy) {
|
|
4963
|
+
assertDocumentAuthorization(handle, use);
|
|
4964
|
+
associateDocumentAuthorization(handle, use.binding, copy);
|
|
4965
|
+
}
|
|
4966
|
+
function isKnownAuthorizationOutput(output) {
|
|
4967
|
+
return outputs.has(output);
|
|
4968
|
+
}
|
|
4969
|
+
function getAssociatedDocumentAuthorization(output, call) {
|
|
4970
|
+
const record3 = outputs.get(output);
|
|
4971
|
+
if (!record3 || !unchangedOutput(output, record3)) return void 0;
|
|
4972
|
+
const { stage } = validateDocumentOwner(record3.handle);
|
|
4973
|
+
if (call && getAuthorizationProvenance(stage.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
4974
|
+
return record3.handle;
|
|
4975
|
+
}
|
|
4976
|
+
function transferDocumentAuthorizationGraph(source, copy, copyOrigins) {
|
|
4977
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
4978
|
+
const visit = (source2, copy2) => {
|
|
4979
|
+
if (!copy2 || typeof copy2 !== "object" || seen.has(copy2)) return;
|
|
4980
|
+
seen.add(copy2);
|
|
4981
|
+
source2 = copyOrigins?.get(copy2) ?? source2;
|
|
4982
|
+
if (source2 instanceof import_mongoose5.Document) source2 = source2._doc;
|
|
4983
|
+
const original = source2 && typeof source2 === "object" ? source2 : void 0;
|
|
4984
|
+
if (!original && !copyOrigins) return;
|
|
4985
|
+
const association = original && outputs.get(original);
|
|
4986
|
+
if (association) {
|
|
4987
|
+
const { document, stage } = validateDocumentOwner(association.handle);
|
|
4988
|
+
const outputAccess = readServiceAuthorizationAccess(stage.call, stage.binding).outputAccess;
|
|
4989
|
+
validateStageOwner(stage);
|
|
4990
|
+
transferDocumentAuthorization(
|
|
4991
|
+
association.handle,
|
|
4992
|
+
{
|
|
4993
|
+
binding: stage.binding,
|
|
4994
|
+
output: original,
|
|
4995
|
+
outputAccess,
|
|
4996
|
+
authorization: stage.call,
|
|
4997
|
+
stage: document.stage
|
|
4998
|
+
},
|
|
4999
|
+
copy2
|
|
5000
|
+
);
|
|
5001
|
+
}
|
|
5002
|
+
for (const key of Object.keys(copy2)) {
|
|
5003
|
+
const descriptor = original && Object.getOwnPropertyDescriptor(original, key);
|
|
5004
|
+
if (descriptor && "value" in descriptor) {
|
|
5005
|
+
visit(descriptor.value, copy2[key]);
|
|
5006
|
+
} else if (copyOrigins) {
|
|
5007
|
+
visit(void 0, copy2[key]);
|
|
5008
|
+
}
|
|
5009
|
+
}
|
|
5010
|
+
};
|
|
5011
|
+
visit(source, copy);
|
|
5012
|
+
}
|
|
5013
|
+
function createServiceOutputContext(diagnostic, handle, use) {
|
|
5014
|
+
assertDocumentAuthorization(handle, use);
|
|
5015
|
+
const rootOutput = use.output;
|
|
5016
|
+
const root = outputs.get(rootOutput);
|
|
5017
|
+
const graph = new Set(root.identities);
|
|
5018
|
+
const { stage } = validateDocumentOwner(handle);
|
|
5019
|
+
const call = stage.call;
|
|
5020
|
+
const context = { ...diagnostic };
|
|
5021
|
+
Object.defineProperties(context, {
|
|
5022
|
+
documentAuthorization: { value: handle, enumerable: false, writable: false, configurable: false },
|
|
5023
|
+
getDocumentAuthorization: {
|
|
5024
|
+
enumerable: false,
|
|
5025
|
+
writable: false,
|
|
5026
|
+
configurable: false,
|
|
5027
|
+
value(output) {
|
|
5028
|
+
if (!graph.has(output) || !unchangedOutput(rootOutput, root)) return void 0;
|
|
5029
|
+
const association = outputs.get(output);
|
|
5030
|
+
if (!association || !unchangedOutput(output, association)) return void 0;
|
|
5031
|
+
try {
|
|
5032
|
+
validateStageOwner(lookupStageOwner(lookupDocumentOwner(handle).stage));
|
|
5033
|
+
const { stage: child } = validateDocumentOwner(association.handle);
|
|
5034
|
+
if (getAuthorizationProvenance(child.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
5035
|
+
return association.handle;
|
|
5036
|
+
} catch {
|
|
5037
|
+
return void 0;
|
|
5038
|
+
}
|
|
5039
|
+
}
|
|
5040
|
+
}
|
|
5041
|
+
});
|
|
5042
|
+
return context;
|
|
5043
|
+
}
|
|
5044
|
+
var import_node_util6, import_mongoose5, stages, documents, outputs, unresolvedDocuments, owningDocuments;
|
|
5045
|
+
var init_document_authorization = __esm({
|
|
5046
|
+
"src/acl/document-authorization.ts"() {
|
|
5047
|
+
import_node_util6 = require("util");
|
|
5048
|
+
import_mongoose5 = require("mongoose");
|
|
4780
5049
|
init_service_authorization();
|
|
4781
|
-
|
|
5050
|
+
init_authorization_snapshot();
|
|
5051
|
+
init_output_projection();
|
|
5052
|
+
init_output_field_policy();
|
|
5053
|
+
stages = /* @__PURE__ */ new WeakMap();
|
|
5054
|
+
documents = /* @__PURE__ */ new WeakMap();
|
|
5055
|
+
outputs = /* @__PURE__ */ new WeakMap();
|
|
5056
|
+
unresolvedDocuments = /* @__PURE__ */ new WeakSet();
|
|
5057
|
+
owningDocuments = /* @__PURE__ */ new WeakMap();
|
|
5058
|
+
}
|
|
5059
|
+
});
|
|
5060
|
+
|
|
5061
|
+
// src/output/include-output.ts
|
|
5062
|
+
function prepareIncludeOutput(doc) {
|
|
5063
|
+
if (stateFor(doc)) return doc;
|
|
5064
|
+
const source = isolateDocForOutput(doc);
|
|
5065
|
+
transferDocumentAuthorizationGraph(doc, source);
|
|
5066
|
+
const working = deepIsolateValue(source);
|
|
5067
|
+
outputs2.set(working, { original: doc, source, attachments: [] });
|
|
5068
|
+
return working;
|
|
5069
|
+
}
|
|
5070
|
+
function attachIncludeOutput(doc, path, value) {
|
|
5071
|
+
const state = stateFor(doc);
|
|
5072
|
+
if (!state) throw new Error("Include attachment requires a prepared output row");
|
|
5073
|
+
state.attachments.push({ path, value });
|
|
5074
|
+
(0, import_utils21.set)(doc, path, deepIsolateValue(value));
|
|
5075
|
+
}
|
|
5076
|
+
function getIncludeSource(doc) {
|
|
5077
|
+
return stateFor(doc)?.source ?? doc;
|
|
5078
|
+
}
|
|
5079
|
+
function getIncludeOriginal(doc) {
|
|
5080
|
+
return stateFor(doc)?.original ?? doc;
|
|
5081
|
+
}
|
|
5082
|
+
function restoreIncludeOutput(doc, output) {
|
|
5083
|
+
const attachments = stateFor(doc)?.attachments;
|
|
5084
|
+
if (!attachments?.length) return void 0;
|
|
5085
|
+
const origins = /* @__PURE__ */ new WeakMap();
|
|
5086
|
+
for (const { path, value } of attachments) {
|
|
5087
|
+
const copy = deepIsolateValue(value);
|
|
5088
|
+
if (copy !== null && typeof copy === "object") origins.set(copy, value);
|
|
5089
|
+
(0, import_utils21.set)(output, path, copy);
|
|
5090
|
+
}
|
|
5091
|
+
return origins;
|
|
5092
|
+
}
|
|
5093
|
+
var import_utils21, outputs2, stateFor;
|
|
5094
|
+
var init_include_output = __esm({
|
|
5095
|
+
"src/output/include-output.ts"() {
|
|
5096
|
+
import_utils21 = require("@web-ts-toolkit/utils");
|
|
5097
|
+
init_document_authorization();
|
|
5098
|
+
init_document();
|
|
5099
|
+
outputs2 = /* @__PURE__ */ new WeakMap();
|
|
5100
|
+
stateFor = (doc) => doc !== null && typeof doc === "object" ? outputs2.get(doc) : void 0;
|
|
5101
|
+
}
|
|
5102
|
+
});
|
|
5103
|
+
|
|
5104
|
+
// src/helpers/request-work.ts
|
|
5105
|
+
function getRequestWorkState(req, runtime) {
|
|
5106
|
+
let owners = states.get(req);
|
|
5107
|
+
if (!owners) {
|
|
5108
|
+
owners = /* @__PURE__ */ new WeakMap();
|
|
5109
|
+
states.set(req, owners);
|
|
5110
|
+
}
|
|
5111
|
+
let state = owners.get(runtime);
|
|
5112
|
+
if (!state) {
|
|
5113
|
+
const limits = resolveRequestComplexity(runtime.getGlobalOption("requestComplexity"));
|
|
5114
|
+
state = {
|
|
5115
|
+
totalQueries: 0,
|
|
5116
|
+
scheduler: new RequestConcurrencyScheduler(limits.maxBulkConcurrency),
|
|
5117
|
+
hookGate: new SharedHookGate(limits.maxHookConcurrency)
|
|
5118
|
+
};
|
|
5119
|
+
owners.set(runtime, state);
|
|
5120
|
+
}
|
|
5121
|
+
return state;
|
|
5122
|
+
}
|
|
5123
|
+
var states;
|
|
5124
|
+
var init_request_work = __esm({
|
|
5125
|
+
"src/helpers/request-work.ts"() {
|
|
5126
|
+
init_request_complexity();
|
|
5127
|
+
init_concurrency();
|
|
5128
|
+
states = /* @__PURE__ */ new WeakMap();
|
|
4782
5129
|
}
|
|
4783
5130
|
});
|
|
4784
5131
|
|
|
4785
5132
|
// src/acl/model-output-planning.ts
|
|
4786
5133
|
function getCapturedAuthorizationOption(configuration, key) {
|
|
4787
|
-
const defaultValue = key.startsWith("operationAccess.") ? (0,
|
|
4788
|
-
return resolveNestedOption((path, fallback) => (0,
|
|
5134
|
+
const defaultValue = key.startsWith("operationAccess.") ? (0, import_utils23.get)(configuration.operationAccessDefaults, key.slice("operationAccess.".length)) : void 0;
|
|
5135
|
+
return resolveNestedOption((path, fallback) => (0, import_utils23.get)(configuration, path, fallback), key, defaultValue);
|
|
4789
5136
|
}
|
|
4790
5137
|
function captureModelAuthorizationConfiguration(runtime, modelName, options = runtime.getModelOptions(modelName), globalOptions = runtime.getGlobalOptions()) {
|
|
4791
5138
|
const model = runtime.getModelInstance(modelName);
|
|
@@ -4848,10 +5195,10 @@ function planModelOutputForHelper(args) {
|
|
|
4848
5195
|
requestedSelect: args.select
|
|
4849
5196
|
});
|
|
4850
5197
|
}
|
|
4851
|
-
var
|
|
5198
|
+
var import_utils23;
|
|
4852
5199
|
var init_model_output_planning = __esm({
|
|
4853
5200
|
"src/acl/model-output-planning.ts"() {
|
|
4854
|
-
|
|
5201
|
+
import_utils23 = require("@web-ts-toolkit/utils");
|
|
4855
5202
|
init_manager();
|
|
4856
5203
|
init_field_catalog();
|
|
4857
5204
|
init_authorization_snapshot();
|
|
@@ -4863,10 +5210,10 @@ var init_model_output_planning = __esm({
|
|
|
4863
5210
|
|
|
4864
5211
|
// src/core-shared.ts
|
|
4865
5212
|
function isAndFilter(filter2) {
|
|
4866
|
-
return !!filter2 && (0,
|
|
5213
|
+
return !!filter2 && (0, import_utils24.isPlainObject)(filter2) && Object.keys(filter2).length === 1 && (0, import_utils24.isArray)(filter2.$and);
|
|
4867
5214
|
}
|
|
4868
5215
|
function isMergeableClause(filter2) {
|
|
4869
|
-
return !!filter2 && (0,
|
|
5216
|
+
return !!filter2 && (0, import_utils24.isPlainObject)(filter2) && Object.keys(filter2).every((key) => !key.startsWith("$"));
|
|
4870
5217
|
}
|
|
4871
5218
|
function optimizeAndFilter(clausesInput) {
|
|
4872
5219
|
const clauses = [];
|
|
@@ -4883,11 +5230,11 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4883
5230
|
const dedupeKey = (value) => {
|
|
4884
5231
|
if (value instanceof RegExp) return `regexp:${JSON.stringify([value.source, value.flags])}`;
|
|
4885
5232
|
if (value instanceof Date) return `date:${value.getTime()}`;
|
|
4886
|
-
if ((0,
|
|
5233
|
+
if ((0, import_utils24.isArray)(value)) {
|
|
4887
5234
|
const entries = Array.from(value, dedupeKey);
|
|
4888
5235
|
return entries.every((entry) => entry !== void 0) ? `array:${JSON.stringify(entries)}` : void 0;
|
|
4889
5236
|
}
|
|
4890
|
-
if ((0,
|
|
5237
|
+
if ((0, import_utils24.isPlainObject)(value)) {
|
|
4891
5238
|
const entries = Object.keys(value).sort().map((key) => [key, dedupeKey(value[key])]);
|
|
4892
5239
|
return entries.every(([, entry]) => entry !== void 0) ? `object:${JSON.stringify(entries)}` : void 0;
|
|
4893
5240
|
}
|
|
@@ -4917,7 +5264,7 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4917
5264
|
}
|
|
4918
5265
|
let canMerge = true;
|
|
4919
5266
|
for (const [key, value] of Object.entries(clause)) {
|
|
4920
|
-
if ((0,
|
|
5267
|
+
if ((0, import_utils24.hasOwn)(mergedClause, key) && !(0, import_node_util7.isDeepStrictEqual)(mergedClause[key], value)) {
|
|
4921
5268
|
canMerge = false;
|
|
4922
5269
|
break;
|
|
4923
5270
|
}
|
|
@@ -4928,24 +5275,24 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4928
5275
|
}
|
|
4929
5276
|
Object.assign(mergedClause, clause);
|
|
4930
5277
|
}
|
|
4931
|
-
const finalClauses = (0,
|
|
5278
|
+
const finalClauses = (0, import_utils24.isEmpty)(mergedClause) ? remainingClauses : [mergedClause, ...remainingClauses];
|
|
4932
5279
|
if (finalClauses.length === 0) return null;
|
|
4933
5280
|
if (finalClauses.length === 1) return finalClauses[0];
|
|
4934
5281
|
return { $and: finalClauses };
|
|
4935
5282
|
}
|
|
4936
5283
|
function normalizeFilter(filter2) {
|
|
4937
5284
|
if (filter2 === false) return false;
|
|
4938
|
-
if (!filter2 || !(0,
|
|
5285
|
+
if (!filter2 || !(0, import_utils24.isPlainObject)(filter2) || (0, import_utils24.isEmpty)(filter2)) return null;
|
|
4939
5286
|
if (!isAndFilter(filter2)) {
|
|
4940
5287
|
return filter2;
|
|
4941
5288
|
}
|
|
4942
5289
|
return optimizeAndFilter(filter2.$and);
|
|
4943
5290
|
}
|
|
4944
5291
|
async function resolveIdentifierFilter(req, idField, resolveIdFilter, id) {
|
|
4945
|
-
if ((0,
|
|
5292
|
+
if ((0, import_utils24.isFunction)(resolveIdFilter)) {
|
|
4946
5293
|
return await resolveIdFilter.call(req, id);
|
|
4947
5294
|
}
|
|
4948
|
-
if ((0,
|
|
5295
|
+
if ((0, import_utils24.isString)(idField)) {
|
|
4949
5296
|
return { [idField]: id };
|
|
4950
5297
|
}
|
|
4951
5298
|
return { _id: id };
|
|
@@ -4969,7 +5316,7 @@ async function resolveAccessFilterParts({
|
|
|
4969
5316
|
}
|
|
4970
5317
|
const overrideFilterFn = getOption(`overrideFilter.${access}`, null);
|
|
4971
5318
|
const baseFilterFn = rows2.mode === "request" ? getOption(`baseFilter.${access}`, null) : null;
|
|
4972
|
-
if (nextFilter !== false && (0,
|
|
5319
|
+
if (nextFilter !== false && (0, import_utils24.isFunction)(overrideFilterFn)) {
|
|
4973
5320
|
nextFilter = normalizeFilter(await overrideFilterFn.call(req, nextFilter, permissions));
|
|
4974
5321
|
}
|
|
4975
5322
|
if (nextFilter === false) return { transformed: false, scope: {}, filter: false };
|
|
@@ -4977,7 +5324,7 @@ async function resolveAccessFilterParts({
|
|
|
4977
5324
|
const scope2 = rows2.mode === "scope" ? rows2.filter : {};
|
|
4978
5325
|
return { transformed: nextFilter ?? {}, scope: scope2, filter: intersectFilters(nextFilter, scope2) };
|
|
4979
5326
|
}
|
|
4980
|
-
if (!(0,
|
|
5327
|
+
if (!(0, import_utils24.isFunction)(baseFilterFn)) return { transformed: nextFilter ?? {}, scope: {}, filter: nextFilter ?? {} };
|
|
4981
5328
|
const cached = cache.get(cacheKey);
|
|
4982
5329
|
const reusable = cached?.resolver === baseFilterFn;
|
|
4983
5330
|
const baseFilter = normalizeFilter(
|
|
@@ -5012,34 +5359,34 @@ async function setRequestPermissions(req) {
|
|
|
5012
5359
|
if (owner === activeRuntime) return;
|
|
5013
5360
|
if (hasFieldValue && owner === void 0) return;
|
|
5014
5361
|
const globalPermissions = getGlobalOption("globalPermissions");
|
|
5015
|
-
const permissions = (0,
|
|
5016
|
-
if ((0,
|
|
5017
|
-
else if ((0,
|
|
5018
|
-
else if ((0,
|
|
5362
|
+
const permissions = (0, import_utils24.isFunction)(globalPermissions) ? await globalPermissions.call(req, req) : void 0;
|
|
5363
|
+
if ((0, import_utils24.isPlainObject)(permissions)) req[requestPermissionField] = permissions;
|
|
5364
|
+
else if ((0, import_utils24.isArray)(permissions)) req[requestPermissionField] = (0, import_utils24.arrayToRecord)(permissions);
|
|
5365
|
+
else if ((0, import_utils24.isString)(permissions)) req[requestPermissionField] = { [permissions]: true };
|
|
5019
5366
|
else req[requestPermissionField] = {};
|
|
5020
5367
|
owners.set(requestPermissionField, activeRuntime);
|
|
5021
5368
|
}
|
|
5022
5369
|
async function evaluateRouteGuard(req, permissions, routeGuard) {
|
|
5023
5370
|
const phas = (key) => permissions.has(key);
|
|
5024
5371
|
const { stringHandler, arrayHandler } = createValidator(phas);
|
|
5025
|
-
if ((0,
|
|
5372
|
+
if ((0, import_utils24.isBoolean)(routeGuard)) {
|
|
5026
5373
|
return routeGuard === true;
|
|
5027
5374
|
}
|
|
5028
|
-
if ((0,
|
|
5375
|
+
if ((0, import_utils24.isString)(routeGuard)) {
|
|
5029
5376
|
return stringHandler(routeGuard);
|
|
5030
5377
|
}
|
|
5031
|
-
if ((0,
|
|
5378
|
+
if ((0, import_utils24.isArray)(routeGuard)) {
|
|
5032
5379
|
return arrayHandler(routeGuard);
|
|
5033
5380
|
}
|
|
5034
|
-
if ((0,
|
|
5381
|
+
if ((0, import_utils24.isFunction)(routeGuard)) {
|
|
5035
5382
|
return routeGuard.call(req, permissions);
|
|
5036
5383
|
}
|
|
5037
5384
|
return false;
|
|
5038
5385
|
}
|
|
5039
5386
|
async function callHookChain(req, hook, doc, permissions, context) {
|
|
5040
|
-
const hooks = (0,
|
|
5387
|
+
const hooks = (0, import_utils24.castArray)(hook);
|
|
5041
5388
|
for (let x = 0; x < hooks.length; x++) {
|
|
5042
|
-
if ((0,
|
|
5389
|
+
if ((0, import_utils24.isFunction)(hooks[x])) {
|
|
5043
5390
|
doc = await hooks[x].call(req, doc, permissions, context);
|
|
5044
5391
|
}
|
|
5045
5392
|
}
|
|
@@ -5059,23 +5406,23 @@ async function collectSchemaFields({
|
|
|
5059
5406
|
for (let x = 0; x < keys2.length; x++) {
|
|
5060
5407
|
const key = keys2[x];
|
|
5061
5408
|
const value = extractScopedOutputRule(permissionSchema, key, access);
|
|
5062
|
-
if ((0,
|
|
5409
|
+
if ((0, import_utils24.isBoolean)(value)) {
|
|
5063
5410
|
if (value) fields.push(key);
|
|
5064
|
-
} else if ((0,
|
|
5411
|
+
} else if ((0, import_utils24.isString)(value)) {
|
|
5065
5412
|
if (stringHandler(value)) fields.push(key);
|
|
5066
|
-
} else if ((0,
|
|
5413
|
+
} else if ((0, import_utils24.isArray)(value)) {
|
|
5067
5414
|
if (arrayHandler(value)) fields.push(key);
|
|
5068
|
-
} else if ((0,
|
|
5415
|
+
} else if ((0, import_utils24.isFunction)(value)) {
|
|
5069
5416
|
if (await value.call(req, ...functionArgs)) fields.push(key);
|
|
5070
5417
|
}
|
|
5071
5418
|
}
|
|
5072
5419
|
return fields;
|
|
5073
5420
|
}
|
|
5074
|
-
var
|
|
5421
|
+
var import_utils24, import_node_util7, permissionFieldOwners;
|
|
5075
5422
|
var init_core_shared = __esm({
|
|
5076
5423
|
"src/core-shared.ts"() {
|
|
5077
|
-
|
|
5078
|
-
|
|
5424
|
+
import_utils24 = require("@web-ts-toolkit/utils");
|
|
5425
|
+
import_node_util7 = require("util");
|
|
5079
5426
|
init_helpers();
|
|
5080
5427
|
init_options();
|
|
5081
5428
|
init_runtime_context();
|
|
@@ -5443,8 +5790,8 @@ function equivalentVirtualPopulatePredicate(left, right) {
|
|
|
5443
5790
|
}
|
|
5444
5791
|
if (Array.isArray(left) || Array.isArray(right))
|
|
5445
5792
|
return Array.isArray(left) && Array.isArray(right) && left.length === right.length && left.every((entry, index) => equivalentVirtualPopulatePredicate(entry, right[index]));
|
|
5446
|
-
if ((0,
|
|
5447
|
-
if (!(0,
|
|
5793
|
+
if ((0, import_utils28.isPlainObject)(left) || (0, import_utils28.isPlainObject)(right)) {
|
|
5794
|
+
if (!(0, import_utils28.isPlainObject)(left) || !(0, import_utils28.isPlainObject)(right)) return false;
|
|
5448
5795
|
const a = Object.keys(left), b = Object.keys(right);
|
|
5449
5796
|
return a.length === b.length && a.every(
|
|
5450
5797
|
(key, index) => key === b[index] && equivalentVirtualPopulatePredicate(
|
|
@@ -5453,7 +5800,7 @@ function equivalentVirtualPopulatePredicate(left, right) {
|
|
|
5453
5800
|
)
|
|
5454
5801
|
);
|
|
5455
5802
|
}
|
|
5456
|
-
return (0,
|
|
5803
|
+
return (0, import_node_util8.isDeepStrictEqual)(left, right);
|
|
5457
5804
|
}
|
|
5458
5805
|
function createVirtualPopulateBatch(owner) {
|
|
5459
5806
|
const batch = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
@@ -5828,12 +6175,12 @@ async function loadVirtualPopulateOutputRows(owner, inputs, plan, publicPopulate
|
|
|
5828
6175
|
}
|
|
5829
6176
|
return output;
|
|
5830
6177
|
}
|
|
5831
|
-
var import_mongoose7,
|
|
6178
|
+
var import_mongoose7, import_node_util8, import_utils28, batches, rows, outputRows, fetchedPublicIdentities, publicViewIdentities, familyRawFetches, addressKey, storage, originalRef, copyOriginalValue, readPolicy, compatible, idKey, logUnavailable;
|
|
5832
6179
|
var init_virtual_populate_execution = __esm({
|
|
5833
6180
|
"src/acl/virtual-populate-execution.ts"() {
|
|
5834
6181
|
import_mongoose7 = require("mongoose");
|
|
5835
|
-
|
|
5836
|
-
|
|
6182
|
+
import_node_util8 = require("util");
|
|
6183
|
+
import_utils28 = require("@web-ts-toolkit/utils");
|
|
5837
6184
|
init_cache();
|
|
5838
6185
|
init_core_shared();
|
|
5839
6186
|
init_document();
|
|
@@ -5850,7 +6197,7 @@ var init_virtual_populate_execution = __esm({
|
|
|
5850
6197
|
publicViewIdentities = /* @__PURE__ */ new WeakMap();
|
|
5851
6198
|
familyRawFetches = /* @__PURE__ */ new WeakMap();
|
|
5852
6199
|
addressKey = (address) => JSON.stringify(address);
|
|
5853
|
-
storage = (value) => value instanceof import_mongoose7.Document ? value._doc : (0,
|
|
6200
|
+
storage = (value) => value instanceof import_mongoose7.Document ? value._doc : (0, import_utils28.isPlainObject)(value) ? value : void 0;
|
|
5854
6201
|
originalRef = (source, key) => {
|
|
5855
6202
|
const record3 = storage(source);
|
|
5856
6203
|
return {
|
|
@@ -5877,75 +6224,8 @@ var init_virtual_populate_execution = __esm({
|
|
|
5877
6224
|
});
|
|
5878
6225
|
|
|
5879
6226
|
// src/acl/output-field-filter.ts
|
|
5880
|
-
function callFieldPolicy(authorization, binding) {
|
|
5881
|
-
assertAuthorizationBinding(authorization, binding);
|
|
5882
|
-
let policy = fieldPolicies.get(authorization);
|
|
5883
|
-
if (!policy) {
|
|
5884
|
-
const view = readServiceOutputFieldAuthorization(authorization, binding);
|
|
5885
|
-
policy = {
|
|
5886
|
-
schema: view.permissionSchema,
|
|
5887
|
-
requestPaths: view.permissionSchema == null || (0, import_utils28.isPlainObject)(view.permissionSchema) && Object.isFrozen(view.permissionSchema) ? Object.freeze(Object.keys(view.permissionSchema ?? {})) : void 0,
|
|
5888
|
-
prefix: view.modelPermissionPrefix ?? "",
|
|
5889
|
-
outputFields: view.outputFields,
|
|
5890
|
-
accesses: /* @__PURE__ */ new Map()
|
|
5891
|
-
};
|
|
5892
|
-
if (view.reusable) fieldPolicies.set(authorization, policy);
|
|
5893
|
-
}
|
|
5894
|
-
return policy;
|
|
5895
|
-
}
|
|
5896
|
-
function requestRuleClassification(entry, authorization, permissions, prefix) {
|
|
5897
|
-
if (typeof prefix !== "string") return void 0;
|
|
5898
|
-
let classification = entry.classifications.get(authorization);
|
|
5899
|
-
if (!classification) {
|
|
5900
|
-
classification = prepareRequestFieldRule(entry.rule, permissions, prefix);
|
|
5901
|
-
entry.classifications.set(authorization, classification);
|
|
5902
|
-
}
|
|
5903
|
-
return classification;
|
|
5904
|
-
}
|
|
5905
|
-
function invariantRuleLookup(schema, path) {
|
|
5906
|
-
if (schema == null) return true;
|
|
5907
|
-
if (!(0, import_utils28.isPlainObject)(schema) || !Object.isFrozen(schema)) return false;
|
|
5908
|
-
const exact = Object.getOwnPropertyDescriptor(schema, path);
|
|
5909
|
-
if (exact) {
|
|
5910
|
-
const raw2 = exact.value;
|
|
5911
|
-
return !raw2 || typeof raw2 !== "object" || Array.isArray(raw2) || (0, import_utils28.isPlainObject)(raw2) && Object.isFrozen(raw2);
|
|
5912
|
-
}
|
|
5913
|
-
const [head, ...rest] = path.split(".");
|
|
5914
|
-
const raw = Object.getOwnPropertyDescriptor(schema, head)?.value;
|
|
5915
|
-
if (raw == null) return true;
|
|
5916
|
-
if (!(0, import_utils28.isPlainObject)(raw) || !Object.isFrozen(raw)) return false;
|
|
5917
|
-
const sub = Object.getOwnPropertyDescriptor(raw, "sub");
|
|
5918
|
-
return !rest.length || !sub || invariantRuleLookup(sub.value, rest.join("."));
|
|
5919
|
-
}
|
|
5920
|
-
function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
5921
|
-
let cache = policy.accesses.get(access);
|
|
5922
|
-
if (!cache) {
|
|
5923
|
-
cache = /* @__PURE__ */ new Map();
|
|
5924
|
-
policy.accesses.set(access, cache);
|
|
5925
|
-
}
|
|
5926
|
-
let prepared = cache.get(path);
|
|
5927
|
-
if (!prepared) {
|
|
5928
|
-
const invariant = invariantRuleLookup(policy.schema, path);
|
|
5929
|
-
const permissions = getAuthorizationPermissions(authorization, binding);
|
|
5930
|
-
const entries = extractOutputFieldRuleEntries(policy.schema, path, access).map((entry) => ({
|
|
5931
|
-
...entry,
|
|
5932
|
-
classifications: /* @__PURE__ */ new WeakMap()
|
|
5933
|
-
}));
|
|
5934
|
-
const classifications = entries.map(
|
|
5935
|
-
(entry) => requestRuleClassification(entry, authorization, permissions, policy.prefix)
|
|
5936
|
-
);
|
|
5937
|
-
const backendGrant = hasExplicitFieldGrant(policy.outputFields, path);
|
|
5938
|
-
prepared = {
|
|
5939
|
-
entries,
|
|
5940
|
-
backendGrant,
|
|
5941
|
-
state: backendGrant ? "granted" : classifications.every((value) => value !== void 0) ? combineFieldAuthorizationStates(classifications.map((value) => value.state)) : void 0
|
|
5942
|
-
};
|
|
5943
|
-
if (invariant) cache.set(path, prepared);
|
|
5944
|
-
}
|
|
5945
|
-
return prepared;
|
|
5946
|
-
}
|
|
5947
6227
|
function assertOwningOutputDocuments(handle) {
|
|
5948
|
-
const owner =
|
|
6228
|
+
const owner = readOutputDocumentOwner(handle);
|
|
5949
6229
|
if (owner) {
|
|
5950
6230
|
readDocumentAuthorizationAccess(owner.handle, owner.binding);
|
|
5951
6231
|
assertOwningOutputDocuments(owner.handle);
|
|
@@ -5955,7 +6235,7 @@ function prepareOutputDocumentAuthorization(authorization, binding, configuratio
|
|
|
5955
6235
|
const access = readServiceAuthorizationAccess(authorization, binding);
|
|
5956
6236
|
const key = `docPermissions.${access.docPermissionsAccess}`;
|
|
5957
6237
|
const docPermissions = configuration.docPermissions;
|
|
5958
|
-
const invariant = /^[A-Za-z0-9_-]+$/.test(access.docPermissionsAccess) && (docPermissions == null || (0,
|
|
6238
|
+
const invariant = /^[A-Za-z0-9_-]+$/.test(access.docPermissionsAccess) && (docPermissions == null || (0, import_utils29.isPlainObject)(docPermissions));
|
|
5959
6239
|
const option = invariant ? getCapturedAuthorizationOption(configuration, key) : void 0;
|
|
5960
6240
|
const hook = typeof option === "function" ? option : void 0;
|
|
5961
6241
|
const resolveHook = invariant ? () => hook : () => {
|
|
@@ -5985,7 +6265,7 @@ async function resolveOutputDocumentAuthorizationWithHook(args, access, resolveH
|
|
|
5985
6265
|
try {
|
|
5986
6266
|
const run = () => hook.call(this, doc, permissions, args.context);
|
|
5987
6267
|
const grants = await getRequestWorkState(binding.request, binding.runtime).hookGate.run(run);
|
|
5988
|
-
return (0,
|
|
6268
|
+
return (0, import_utils29.isPlainObject)(grants) ? grants : {};
|
|
5989
6269
|
} catch (error2) {
|
|
5990
6270
|
warn("docPermissions hook failed; applying empty document permissions", {
|
|
5991
6271
|
modelName: binding.modelName,
|
|
@@ -5996,14 +6276,12 @@ async function resolveOutputDocumentAuthorizationWithHook(args, access, resolveH
|
|
|
5996
6276
|
return {};
|
|
5997
6277
|
}
|
|
5998
6278
|
});
|
|
5999
|
-
|
|
6000
|
-
unresolvedDocuments.add(handle);
|
|
6001
|
-
if (args.owningDocument) owningDocuments.set(handle, { handle: args.owningDocument, binding: args.owningBinding });
|
|
6279
|
+
bindOutputDocumentOwner(handle, args.knownOutput, args.owningDocument, args.owningBinding);
|
|
6002
6280
|
return handle;
|
|
6003
6281
|
}
|
|
6004
6282
|
function evaluateRequestRule(handle, binding, entry, prefix, access) {
|
|
6005
6283
|
assertOwningOutputDocuments(handle);
|
|
6006
|
-
const owner =
|
|
6284
|
+
const owner = readOutputDocumentOwner(handle);
|
|
6007
6285
|
if (owner && !entry.path.startsWith(`${(binding.scopePath ?? []).join(".")}.`)) {
|
|
6008
6286
|
return evaluateRequestRule(owner.handle, owner.binding, entry, prefix, access);
|
|
6009
6287
|
}
|
|
@@ -6037,7 +6315,7 @@ function evaluateAuthorizedOutputField(handle, binding, field) {
|
|
|
6037
6315
|
const policy = callFieldPolicy(authorization, binding);
|
|
6038
6316
|
const { outputAccess } = readDocumentAuthorizationAccess(handle, binding);
|
|
6039
6317
|
const prepared = prepareOutputPath(policy, authorization, binding, path, outputAccess);
|
|
6040
|
-
const unresolved =
|
|
6318
|
+
const unresolved = isUnresolvedOutputDocument(handle);
|
|
6041
6319
|
const state = unresolved ? prepared.state ?? classifyEffectiveFieldAuthorization({
|
|
6042
6320
|
path,
|
|
6043
6321
|
rules: prepared.entries.map((entry) => entry.rule),
|
|
@@ -6060,12 +6338,18 @@ function evaluateAuthorizedOutputField(handle, binding, field) {
|
|
|
6060
6338
|
assertOwningOutputDocuments(handle);
|
|
6061
6339
|
return allowed;
|
|
6062
6340
|
});
|
|
6063
|
-
return
|
|
6341
|
+
return readOutputDocumentOwner(handle) ? decision.then((allowed) => {
|
|
6064
6342
|
assertOwningOutputDocuments(handle);
|
|
6065
6343
|
return allowed;
|
|
6066
6344
|
}) : decision;
|
|
6067
6345
|
}
|
|
6068
6346
|
async function requestOutputFieldPaths(handle, binding, access) {
|
|
6347
|
+
const staticFields = tryStaticRequestFieldPaths(handle, binding, access);
|
|
6348
|
+
if (staticFields) {
|
|
6349
|
+
await Promise.resolve();
|
|
6350
|
+
readDocumentAuthorizationAccess(handle, binding);
|
|
6351
|
+
return staticFields;
|
|
6352
|
+
}
|
|
6069
6353
|
const { authorization } = readDocumentAuthorizationAccess(handle, binding);
|
|
6070
6354
|
assertOwningOutputDocuments(handle);
|
|
6071
6355
|
const policy = callFieldPolicy(authorization, binding);
|
|
@@ -6114,7 +6398,7 @@ function copyOutputValue(value, plan, path) {
|
|
|
6114
6398
|
const visit = (input, current) => {
|
|
6115
6399
|
if (Array.isArray(input)) return input.map((entry) => visit(entry, current));
|
|
6116
6400
|
if (input instanceof Map) return visit(Object.fromEntries(input), current);
|
|
6117
|
-
if (!(0,
|
|
6401
|
+
if (!(0, import_utils29.isPlainObject)(input)) return deepIsolateValue(input);
|
|
6118
6402
|
const output = {};
|
|
6119
6403
|
for (const [key, entry] of Object.entries(input)) {
|
|
6120
6404
|
const child = `${current}.${key}`;
|
|
@@ -6130,7 +6414,7 @@ function copyOutputValue(value, plan, path) {
|
|
|
6130
6414
|
}
|
|
6131
6415
|
function copyAuthorizedReference(value, plan, path) {
|
|
6132
6416
|
if (Array.isArray(value)) return value.map((entry) => copyAuthorizedReference(entry, plan, path));
|
|
6133
|
-
if (!(0,
|
|
6417
|
+
if (!(0, import_utils29.isPlainObject)(value)) return deepIsolateValue(value);
|
|
6134
6418
|
const handle = getAssociatedDocumentAuthorization(value, plan.authorization);
|
|
6135
6419
|
if (handle) {
|
|
6136
6420
|
const copy = deepIsolateValue(value);
|
|
@@ -6143,8 +6427,8 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6143
6427
|
if (scope2.length || configuration.stripPermissionsField) return;
|
|
6144
6428
|
const parts = (configuration.documentPermissionField ?? "_permissions").split(".");
|
|
6145
6429
|
let value = source;
|
|
6146
|
-
for (const part of parts) value = (0,
|
|
6147
|
-
if (!(0,
|
|
6430
|
+
for (const part of parts) value = (0, import_utils29.isPlainObject)(value) ? value[part] : void 0;
|
|
6431
|
+
if (!(0, import_utils29.isPlainObject)(value)) return;
|
|
6148
6432
|
const keys2 = configuration.exposedDocPermissionKeys;
|
|
6149
6433
|
const metadata = Object.fromEntries(
|
|
6150
6434
|
Object.entries(value).filter(
|
|
@@ -6154,7 +6438,7 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6154
6438
|
const copy = { ...output };
|
|
6155
6439
|
let target = copy;
|
|
6156
6440
|
for (const part of parts.slice(0, -1)) {
|
|
6157
|
-
target[part] = (0,
|
|
6441
|
+
target[part] = (0, import_utils29.isPlainObject)(target[part]) ? { ...target[part] } : {};
|
|
6158
6442
|
target = target[part];
|
|
6159
6443
|
}
|
|
6160
6444
|
target[parts[parts.length - 1]] = deepIsolateValue(metadata);
|
|
@@ -6163,27 +6447,37 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6163
6447
|
attachPermissionsAlias(output, parts.join("."));
|
|
6164
6448
|
}
|
|
6165
6449
|
function helperPlan(authorization, binding) {
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6450
|
+
return planAuthorizedModelProjection({ authorization, binding, effectiveSelect: [] });
|
|
6451
|
+
}
|
|
6452
|
+
function primitiveHelperFields(source, plan) {
|
|
6453
|
+
if (import_node_util9.types.isProxy(source)) return;
|
|
6454
|
+
const canonical = readStaticOutputPlanFields(plan, plan.authorization);
|
|
6455
|
+
if (!canonical) return;
|
|
6456
|
+
const fields = [];
|
|
6457
|
+
for (const field of canonical) {
|
|
6458
|
+
const slot = Object.getOwnPropertyDescriptor(source, field);
|
|
6459
|
+
if (!slot) continue;
|
|
6460
|
+
if (!("value" in slot)) return;
|
|
6461
|
+
const value = slot.value;
|
|
6462
|
+
if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol")
|
|
6463
|
+
return;
|
|
6464
|
+
if (value !== void 0) fields.push(field);
|
|
6465
|
+
}
|
|
6466
|
+
return fields;
|
|
6181
6467
|
}
|
|
6182
6468
|
async function filterExistingOutput(source, plan, handle, associated) {
|
|
6183
6469
|
const binding = plan.authorizationBinding;
|
|
6184
6470
|
const { configuration } = readServiceAuthorization(plan.authorization, binding);
|
|
6185
6471
|
const output = {};
|
|
6186
6472
|
const fields = [];
|
|
6473
|
+
const primitiveFields = primitiveHelperFields(source, plan);
|
|
6474
|
+
const staticDecisions = primitiveFields && tryStaticOutputFieldDecisions(handle, binding, plan, primitiveFields);
|
|
6475
|
+
if (staticDecisions) {
|
|
6476
|
+
await Promise.resolve();
|
|
6477
|
+
if (associated) assertDocumentAuthorization(handle, { binding, output: source, outputAccess: plan.outputAccess });
|
|
6478
|
+
else readDocumentAuthorizationAccess(handle, binding);
|
|
6479
|
+
if (!readStaticOutputPlanFields(plan, plan.authorization)) authorizationError("changed static output plan");
|
|
6480
|
+
}
|
|
6187
6481
|
for (const field of /* @__PURE__ */ new Set([...plan.outputPersistedFields, ...plan.outputVirtualNames])) {
|
|
6188
6482
|
if (!Object.prototype.hasOwnProperty.call(source, field) || source[field] === void 0) continue;
|
|
6189
6483
|
const childPlan = plan.childPlans[field];
|
|
@@ -6196,7 +6490,7 @@ async function filterExistingOutput(source, plan, handle, associated) {
|
|
|
6196
6490
|
for (const entry of value2) values.push(await one(entry) ?? null);
|
|
6197
6491
|
return values;
|
|
6198
6492
|
}
|
|
6199
|
-
if (!(0,
|
|
6493
|
+
if (!(0, import_utils29.isPlainObject)(value2)) return value2 === null ? null : void 0;
|
|
6200
6494
|
const childHandle = associated ? getAssociatedDocumentAuthorization(value2) : void 0;
|
|
6201
6495
|
let child = scoped;
|
|
6202
6496
|
if (childHandle) {
|
|
@@ -6224,7 +6518,7 @@ async function filterExistingOutput(source, plan, handle, associated) {
|
|
|
6224
6518
|
const value = await one(source[field]);
|
|
6225
6519
|
if (value !== void 0) output[field] = value;
|
|
6226
6520
|
fields.push(...childFields);
|
|
6227
|
-
} else if (await evaluateAuthorizedOutputField(handle, binding, field)) {
|
|
6521
|
+
} else if (staticDecisions ? staticDecisions.get(field) === true : await evaluateAuthorizedOutputField(handle, binding, field)) {
|
|
6228
6522
|
const path = [...binding.scopePath ?? [], field].join(".");
|
|
6229
6523
|
output[field] = configuration.catalog.referencePaths?.some((p) => matchesCatalogPattern(p, path)) ? copyAuthorizedReference(source[field], plan, path) : copyOutputValue(source[field], plan, path);
|
|
6230
6524
|
if (associated) transferDocumentAuthorizationGraph(source[field], output[field]);
|
|
@@ -6276,7 +6570,7 @@ async function filterModelOutputForHelper(args) {
|
|
|
6276
6570
|
const plan = helperPlan(normalized.authorization, binding);
|
|
6277
6571
|
if (args.doc == null) return { output: args.doc, fields: [] };
|
|
6278
6572
|
const source = isolateDocForOutput(args.doc);
|
|
6279
|
-
if (!(0,
|
|
6573
|
+
if (!(0, import_utils29.isPlainObject)(source)) return authorizationError("output helper requires one plain or hydrated document");
|
|
6280
6574
|
const knownOutput = !!args.doc && typeof args.doc === "object" && isKnownAuthorizationOutput(args.doc);
|
|
6281
6575
|
const handle = await resolveOutputDocumentAuthorization({
|
|
6282
6576
|
authorization: normalized.authorization,
|
|
@@ -6287,10 +6581,11 @@ async function filterModelOutputForHelper(args) {
|
|
|
6287
6581
|
});
|
|
6288
6582
|
return filterExistingOutput(source, plan, handle, false);
|
|
6289
6583
|
}
|
|
6290
|
-
var
|
|
6584
|
+
var import_node_util9, import_utils29;
|
|
6291
6585
|
var init_output_field_filter = __esm({
|
|
6292
6586
|
"src/acl/output-field-filter.ts"() {
|
|
6293
|
-
|
|
6587
|
+
import_node_util9 = require("util");
|
|
6588
|
+
import_utils29 = require("@web-ts-toolkit/utils");
|
|
6294
6589
|
init_permissions_alias();
|
|
6295
6590
|
init_document();
|
|
6296
6591
|
init_request_work();
|
|
@@ -6302,9 +6597,7 @@ var init_output_field_filter = __esm({
|
|
|
6302
6597
|
init_field_authorization();
|
|
6303
6598
|
init_field_catalog();
|
|
6304
6599
|
init_output_projection();
|
|
6305
|
-
|
|
6306
|
-
owningDocuments = /* @__PURE__ */ new WeakMap();
|
|
6307
|
-
fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
6600
|
+
init_output_field_policy();
|
|
6308
6601
|
}
|
|
6309
6602
|
});
|
|
6310
6603
|
|
|
@@ -6414,8 +6707,8 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6414
6707
|
const privateRow = args.virtualPopulateRow ?? (original && typeof original === "object" ? getVirtualPopulateRow(original) : void 0);
|
|
6415
6708
|
const privateAddress = args.virtualPopulateAddress ?? [];
|
|
6416
6709
|
const isolated = isolateDocForOutput(input);
|
|
6417
|
-
const output = (0,
|
|
6418
|
-
if (captured && (0,
|
|
6710
|
+
const output = (0, import_utils30.isPlainObject)(isolated) ? isolated : {};
|
|
6711
|
+
if (captured && (0, import_utils30.isPlainObject)(input))
|
|
6419
6712
|
for (const key of Object.keys(output)) {
|
|
6420
6713
|
transferDocumentAuthorizationGraph(input[key], output[key]);
|
|
6421
6714
|
}
|
|
@@ -6467,7 +6760,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6467
6760
|
);
|
|
6468
6761
|
continue;
|
|
6469
6762
|
}
|
|
6470
|
-
if (captured && !(0,
|
|
6763
|
+
if (captured && !(0, import_utils30.isPlainObject)(rawContainer) && !Array.isArray(rawContainer)) {
|
|
6471
6764
|
delete output[containerName];
|
|
6472
6765
|
continue;
|
|
6473
6766
|
}
|
|
@@ -6493,7 +6786,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6493
6786
|
const finalizeOneChild = async (rawChild, address) => {
|
|
6494
6787
|
if (captured && Array.isArray(rawChild))
|
|
6495
6788
|
return mapWithConcurrencyLimit(rawChild, limit, (entry, index) => finalizeOneChild(entry, [...address, index]));
|
|
6496
|
-
if (!(0,
|
|
6789
|
+
if (!(0, import_utils30.isPlainObject)(rawChild) && !Array.isArray(rawChild)) return captured ? null : deepIsolateValue(rawChild);
|
|
6497
6790
|
if (args.traversal?.finalizeEmbeddedChildren) {
|
|
6498
6791
|
return args.traversal.finalizeEmbeddedChildren({
|
|
6499
6792
|
containerName,
|
|
@@ -6526,7 +6819,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6526
6819
|
(entry, index) => finalizeOneChild(entry, [...privateAddress, containerName, index])
|
|
6527
6820
|
);
|
|
6528
6821
|
output[containerName] = finalized;
|
|
6529
|
-
} else if ((0,
|
|
6822
|
+
} else if ((0, import_utils30.isPlainObject)(rawContainer)) {
|
|
6530
6823
|
output[containerName] = await finalizeOneChild(rawContainer, [
|
|
6531
6824
|
...privateAddress,
|
|
6532
6825
|
containerName
|
|
@@ -6538,8 +6831,8 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6538
6831
|
let rawRelated;
|
|
6539
6832
|
let originalRelated;
|
|
6540
6833
|
try {
|
|
6541
|
-
rawRelated = target.path.includes(".") ? (0,
|
|
6542
|
-
originalRelated = (0,
|
|
6834
|
+
rawRelated = target.path.includes(".") ? (0, import_utils30.get)(output, target.path) : output[target.path];
|
|
6835
|
+
originalRelated = (0, import_utils30.get)(original, target.path);
|
|
6543
6836
|
} catch {
|
|
6544
6837
|
continue;
|
|
6545
6838
|
}
|
|
@@ -6571,7 +6864,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6571
6864
|
};
|
|
6572
6865
|
let relatedPreparation;
|
|
6573
6866
|
const finalizeOneRelated = async (rawChild, originalChild = rawChild) => {
|
|
6574
|
-
if (!(0,
|
|
6867
|
+
if (!(0, import_utils30.isPlainObject)(rawChild) && !Array.isArray(rawChild)) return rawChild;
|
|
6575
6868
|
if (typeof rawChild?._bsontype === "string") return rawChild;
|
|
6576
6869
|
const childOriginal = getIncludeOriginal(originalChild);
|
|
6577
6870
|
const childRow = childOriginal && typeof childOriginal === "object" ? getVirtualPopulateRow(childOriginal) : void 0;
|
|
@@ -6596,13 +6889,13 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6596
6889
|
limit,
|
|
6597
6890
|
(entry, index) => finalizeOneRelated(entry, Array.isArray(originalRelated) ? originalRelated[index] : void 0)
|
|
6598
6891
|
);
|
|
6599
|
-
} else if ((0,
|
|
6892
|
+
} else if ((0, import_utils30.isPlainObject)(rawRelated)) {
|
|
6600
6893
|
finalized = await finalizeOneRelated(rawRelated, originalRelated);
|
|
6601
6894
|
} else {
|
|
6602
6895
|
continue;
|
|
6603
6896
|
}
|
|
6604
6897
|
try {
|
|
6605
|
-
if (target.path.includes(".")) (0,
|
|
6898
|
+
if (target.path.includes(".")) (0, import_utils30.set)(output, target.path, finalized);
|
|
6606
6899
|
else output[target.path] = finalized;
|
|
6607
6900
|
} catch {
|
|
6608
6901
|
}
|
|
@@ -6681,10 +6974,17 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6681
6974
|
}
|
|
6682
6975
|
const eligiblePersisted = new Set(plan.outputPersistedFields ?? []);
|
|
6683
6976
|
const eligibleVirtuals = new Set(plan.outputVirtualNames ?? []);
|
|
6977
|
+
const staticDecisions = documentAuthorization ? tryStaticOutputFieldDecisions(documentAuthorization, binding, plan, [...eligiblePersisted]) : void 0;
|
|
6978
|
+
if (staticDecisions) {
|
|
6979
|
+
await Promise.resolve();
|
|
6980
|
+
assertFinalizerCall(args, prepared);
|
|
6981
|
+
readDocumentAuthorizationAccess(documentAuthorization, binding);
|
|
6982
|
+
if (!readStaticOutputPlanFields(plan, prepared.authorization)) authorizationError("changed static output plan");
|
|
6983
|
+
}
|
|
6684
6984
|
const allowedPersisted = [];
|
|
6685
6985
|
for (const field of eligiblePersisted) {
|
|
6686
6986
|
if (documentAuthorization) {
|
|
6687
|
-
if (plan.childPlans[field] || await evaluateAuthorizedOutputField(documentAuthorization, binding, field))
|
|
6987
|
+
if (plan.childPlans[field] || (staticDecisions ? staticDecisions.get(field) === true : await evaluateAuthorizedOutputField(documentAuthorization, binding, field)))
|
|
6688
6988
|
allowedPersisted.push(field);
|
|
6689
6989
|
continue;
|
|
6690
6990
|
}
|
|
@@ -6762,6 +7062,10 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6762
7062
|
stage: readDocumentAuthorizationAccess(documentAuthorization, binding).stage
|
|
6763
7063
|
})
|
|
6764
7064
|
);
|
|
7065
|
+
if (staticDecisions) {
|
|
7066
|
+
assertFinalizerCall(args, prepared);
|
|
7067
|
+
readDocumentAuthorizationAccess(documentAuthorization, binding);
|
|
7068
|
+
}
|
|
6765
7069
|
}
|
|
6766
7070
|
void getRetainedAssociations;
|
|
6767
7071
|
return trimmed;
|
|
@@ -6809,10 +7113,10 @@ async function finalizeModelOutputs(args) {
|
|
|
6809
7113
|
);
|
|
6810
7114
|
});
|
|
6811
7115
|
}
|
|
6812
|
-
var
|
|
7116
|
+
var import_utils30, isVirtualContainerValue3, getScopeVirtualsObject2, getScopeVirtualNames, getScopedPermissionSchema2, resolveGlobalPermissions, resolveDocPermissions, isAbsentDependency, __finalizeInternals;
|
|
6813
7117
|
var init_finalize_model_output = __esm({
|
|
6814
7118
|
"src/output/finalize-model-output.ts"() {
|
|
6815
|
-
|
|
7119
|
+
import_utils30 = require("@web-ts-toolkit/utils");
|
|
6816
7120
|
init_document();
|
|
6817
7121
|
init_concurrency();
|
|
6818
7122
|
init_request_work();
|
|
@@ -6823,22 +7127,23 @@ var init_finalize_model_output = __esm({
|
|
|
6823
7127
|
init_output_field_filter();
|
|
6824
7128
|
init_field_authorization();
|
|
6825
7129
|
init_field_catalog();
|
|
7130
|
+
init_output_projection();
|
|
6826
7131
|
init_virtual_populate_execution();
|
|
6827
7132
|
init_include_output();
|
|
6828
|
-
isVirtualContainerValue3 = (value) => (0,
|
|
7133
|
+
isVirtualContainerValue3 = (value) => (0, import_utils30.isPlainObject)(value) && "sub" in value;
|
|
6829
7134
|
getScopeVirtualsObject2 = (rootVirtuals, scopePath) => {
|
|
6830
|
-
if (!rootVirtuals || !(0,
|
|
7135
|
+
if (!rootVirtuals || !(0, import_utils30.isPlainObject)(rootVirtuals)) return null;
|
|
6831
7136
|
if (scopePath.length === 0) return rootVirtuals;
|
|
6832
7137
|
let current = rootVirtuals;
|
|
6833
7138
|
for (let i = 0; i < scopePath.length; i += 2) {
|
|
6834
7139
|
const field = scopePath[i];
|
|
6835
7140
|
const subMarker = scopePath[i + 1];
|
|
6836
7141
|
if (!field || subMarker !== "sub") return null;
|
|
6837
|
-
if (!(0,
|
|
7142
|
+
if (!(0, import_utils30.isPlainObject)(current)) return null;
|
|
6838
7143
|
const container = current[field];
|
|
6839
7144
|
if (!isVirtualContainerValue3(container)) return null;
|
|
6840
7145
|
current = container.sub;
|
|
6841
|
-
if (!(0,
|
|
7146
|
+
if (!(0, import_utils30.isPlainObject)(current)) return null;
|
|
6842
7147
|
}
|
|
6843
7148
|
return current;
|
|
6844
7149
|
};
|
|
@@ -6851,11 +7156,11 @@ var init_finalize_model_output = __esm({
|
|
|
6851
7156
|
return Object.entries(scopeVirtuals).filter(([, v]) => v !== void 0 && !isVirtualContainerValue3(v)).map(([k]) => k);
|
|
6852
7157
|
};
|
|
6853
7158
|
getScopedPermissionSchema2 = (root, scopePath) => {
|
|
6854
|
-
if (!root || !(0,
|
|
7159
|
+
if (!root || !(0, import_utils30.isPlainObject)(root)) return null;
|
|
6855
7160
|
if (scopePath.length === 0) return root;
|
|
6856
7161
|
try {
|
|
6857
|
-
const scoped = (0,
|
|
6858
|
-
return (0,
|
|
7162
|
+
const scoped = (0, import_utils30.get)(root, scopePath.join("."));
|
|
7163
|
+
return (0, import_utils30.isPlainObject)(scoped) ? scoped : null;
|
|
6859
7164
|
} catch {
|
|
6860
7165
|
return null;
|
|
6861
7166
|
}
|
|
@@ -6914,7 +7219,7 @@ var init_finalize_model_output = __esm({
|
|
|
6914
7219
|
const grants = await args.sharedGate.run(
|
|
6915
7220
|
() => hook.call(args.request, isolatedForHook, globalPerms, scopeContext)
|
|
6916
7221
|
);
|
|
6917
|
-
const normalized = (0,
|
|
7222
|
+
const normalized = (0, import_utils30.isPlainObject)(grants) ? grants : {};
|
|
6918
7223
|
scopeContext.docPermissions = normalized;
|
|
6919
7224
|
return normalized;
|
|
6920
7225
|
}
|
|
@@ -6986,20 +7291,20 @@ __export(index_exports, {
|
|
|
6986
7291
|
setModelOptions: () => setModelOptions
|
|
6987
7292
|
});
|
|
6988
7293
|
module.exports = __toCommonJS(index_exports);
|
|
6989
|
-
var
|
|
7294
|
+
var import_utils48 = require("@web-ts-toolkit/utils");
|
|
6990
7295
|
|
|
6991
7296
|
// src/middleware.ts
|
|
6992
7297
|
var import_express_json_router5 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
6993
|
-
var
|
|
7298
|
+
var import_utils41 = require("@web-ts-toolkit/utils");
|
|
6994
7299
|
|
|
6995
7300
|
// src/core.ts
|
|
6996
7301
|
init_public_admission();
|
|
6997
|
-
var
|
|
7302
|
+
var import_utils40 = require("@web-ts-toolkit/utils");
|
|
6998
7303
|
init_options();
|
|
6999
7304
|
init_permission();
|
|
7000
7305
|
|
|
7001
7306
|
// src/services/base.ts
|
|
7002
|
-
var
|
|
7307
|
+
var import_utils25 = require("@web-ts-toolkit/utils");
|
|
7003
7308
|
init_options();
|
|
7004
7309
|
init_helpers();
|
|
7005
7310
|
init_document();
|
|
@@ -7125,7 +7430,7 @@ function requestFieldScope(options) {
|
|
|
7125
7430
|
init_public_admission();
|
|
7126
7431
|
|
|
7127
7432
|
// src/correlated-includes.ts
|
|
7128
|
-
var
|
|
7433
|
+
var import_utils22 = require("@web-ts-toolkit/utils");
|
|
7129
7434
|
init_request_complexity();
|
|
7130
7435
|
init_sort_policy();
|
|
7131
7436
|
var PARENT_MARKER_KEY = "$parent";
|
|
@@ -7138,10 +7443,10 @@ var FIELD_SEGMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
|
7138
7443
|
var ARRAY_INDEX_SEGMENT_PATTERN = /^(0|[1-9]\d*)$/;
|
|
7139
7444
|
var ownKeys = (value) => Object.keys(value);
|
|
7140
7445
|
function isParentRefMarker(value) {
|
|
7141
|
-
return (0,
|
|
7446
|
+
return (0, import_utils22.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === PARENT_MARKER_KEY;
|
|
7142
7447
|
}
|
|
7143
7448
|
function isEscapedParentRef(value) {
|
|
7144
|
-
return (0,
|
|
7449
|
+
return (0, import_utils22.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === ESCAPE_WRAPPER_KEY;
|
|
7145
7450
|
}
|
|
7146
7451
|
function hasMarkerKey(value) {
|
|
7147
7452
|
return ownKeys(value).includes(PARENT_MARKER_KEY) || ownKeys(value).includes(ESCAPE_WRAPPER_KEY);
|
|
@@ -7160,12 +7465,12 @@ function containsParentMarkerShape(value) {
|
|
|
7160
7465
|
const seen = /* @__PURE__ */ new Set();
|
|
7161
7466
|
const visit = (current) => {
|
|
7162
7467
|
if (isParentRefMarker(current) || isEscapedParentRef(current)) return true;
|
|
7163
|
-
if ((0,
|
|
7468
|
+
if ((0, import_utils22.isArray)(current)) {
|
|
7164
7469
|
if (seen.has(current)) return false;
|
|
7165
7470
|
seen.add(current);
|
|
7166
7471
|
return current.some(visit);
|
|
7167
7472
|
}
|
|
7168
|
-
if ((0,
|
|
7473
|
+
if ((0, import_utils22.isPlainObject)(current)) {
|
|
7169
7474
|
if (seen.has(current)) return false;
|
|
7170
7475
|
seen.add(current);
|
|
7171
7476
|
if (hasMarkerKey(current)) return true;
|
|
@@ -7195,7 +7500,7 @@ function scanTemplateValueNode(value, path, issues) {
|
|
|
7195
7500
|
}
|
|
7196
7501
|
return;
|
|
7197
7502
|
}
|
|
7198
|
-
if ((0,
|
|
7503
|
+
if ((0, import_utils22.isPlainObject)(value)) {
|
|
7199
7504
|
if (hasMarkerKey(value)) {
|
|
7200
7505
|
issues.push({
|
|
7201
7506
|
message: 'Malformed $parent reference: objects carrying $parent must be exactly { "$parent": "<field>" }',
|
|
@@ -7206,7 +7511,7 @@ function scanTemplateValueNode(value, path, issues) {
|
|
|
7206
7511
|
scanTemplateObjectEntries(value, path, issues);
|
|
7207
7512
|
return;
|
|
7208
7513
|
}
|
|
7209
|
-
if ((0,
|
|
7514
|
+
if ((0, import_utils22.isArray)(value)) {
|
|
7210
7515
|
value.forEach((item, index) => scanTemplateValueNode(item, [...path, index], issues));
|
|
7211
7516
|
}
|
|
7212
7517
|
}
|
|
@@ -7247,7 +7552,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7247
7552
|
continue;
|
|
7248
7553
|
}
|
|
7249
7554
|
if (LOGICAL_CLAUSE_KEYS.has(key)) {
|
|
7250
|
-
if (!(0,
|
|
7555
|
+
if (!(0, import_utils22.isArray)(child)) {
|
|
7251
7556
|
scanTemplateValueNode(child, childPath, issues);
|
|
7252
7557
|
continue;
|
|
7253
7558
|
}
|
|
@@ -7260,7 +7565,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7260
7565
|
});
|
|
7261
7566
|
return;
|
|
7262
7567
|
}
|
|
7263
|
-
if ((0,
|
|
7568
|
+
if ((0, import_utils22.isPlainObject)(clause)) {
|
|
7264
7569
|
scanTemplateObjectEntries(clause, clausePath, issues);
|
|
7265
7570
|
}
|
|
7266
7571
|
});
|
|
@@ -7271,7 +7576,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7271
7576
|
}
|
|
7272
7577
|
function validateCorrelatedFilterTemplate(filter2) {
|
|
7273
7578
|
const issues = [];
|
|
7274
|
-
if (!(0,
|
|
7579
|
+
if (!(0, import_utils22.isPlainObject)(filter2)) {
|
|
7275
7580
|
issues.push({ message: "Correlated include filter must be an object", path: [] });
|
|
7276
7581
|
return issues;
|
|
7277
7582
|
}
|
|
@@ -7314,13 +7619,13 @@ function collectFilterReferencePaths(filter2) {
|
|
|
7314
7619
|
return;
|
|
7315
7620
|
}
|
|
7316
7621
|
if (isEscapedParentRef(value)) return;
|
|
7317
|
-
if ((0,
|
|
7622
|
+
if ((0, import_utils22.isArray)(value)) {
|
|
7318
7623
|
if (seen.has(value)) return;
|
|
7319
7624
|
seen.add(value);
|
|
7320
7625
|
value.forEach(visitValue);
|
|
7321
7626
|
return;
|
|
7322
7627
|
}
|
|
7323
|
-
if ((0,
|
|
7628
|
+
if ((0, import_utils22.isPlainObject)(value)) {
|
|
7324
7629
|
if (seen.has(value)) return;
|
|
7325
7630
|
seen.add(value);
|
|
7326
7631
|
for (const [key, child] of Object.entries(value)) {
|
|
@@ -7366,7 +7671,7 @@ function getOwnPathValue(parent, path) {
|
|
|
7366
7671
|
return current;
|
|
7367
7672
|
}
|
|
7368
7673
|
function cloneSubstitutedValue(value) {
|
|
7369
|
-
if ((0,
|
|
7674
|
+
if ((0, import_utils22.isPlainObject)(value) || (0, import_utils22.isArray)(value)) return (0, import_utils22.cloneDeep)(value);
|
|
7370
7675
|
return value;
|
|
7371
7676
|
}
|
|
7372
7677
|
function literalParentRefObject(path) {
|
|
@@ -7407,7 +7712,7 @@ function resolveObjectEntries(obj, parent) {
|
|
|
7407
7712
|
continue;
|
|
7408
7713
|
}
|
|
7409
7714
|
if (LOGICAL_CLAUSE_KEYS.has(key)) {
|
|
7410
|
-
if (!(0,
|
|
7715
|
+
if (!(0, import_utils22.isArray)(child)) {
|
|
7411
7716
|
out[key] = resolveValueNode(child, parent, false);
|
|
7412
7717
|
continue;
|
|
7413
7718
|
}
|
|
@@ -7415,7 +7720,7 @@ function resolveObjectEntries(obj, parent) {
|
|
|
7415
7720
|
if (isParentRefMarker(clause) || isEscapedParentRef(clause)) {
|
|
7416
7721
|
throw new CorrelatedReferenceError(`Unsupported $parent reference as a direct ${key} clause`);
|
|
7417
7722
|
}
|
|
7418
|
-
if (!(0,
|
|
7723
|
+
if (!(0, import_utils22.isPlainObject)(clause)) return cloneSubstitutedValue(clause);
|
|
7419
7724
|
return resolveObjectEntries(clause, parent);
|
|
7420
7725
|
});
|
|
7421
7726
|
continue;
|
|
@@ -7444,10 +7749,10 @@ function resolveValueNode(template, parent, bare) {
|
|
|
7444
7749
|
}
|
|
7445
7750
|
const value = getOwnPathValue(parent, path);
|
|
7446
7751
|
if (value === void 0 || value === null) throw UNRESOLVABLE;
|
|
7447
|
-
if (bare && (0,
|
|
7752
|
+
if (bare && (0, import_utils22.isPlainObject)(value)) return { $eq: (0, import_utils22.cloneDeep)(value) };
|
|
7448
7753
|
return cloneSubstitutedValue(value);
|
|
7449
7754
|
}
|
|
7450
|
-
if ((0,
|
|
7755
|
+
if ((0, import_utils22.isPlainObject)(template)) {
|
|
7451
7756
|
if (hasMarkerKey(template)) {
|
|
7452
7757
|
throw new CorrelatedReferenceError(
|
|
7453
7758
|
'Malformed $parent reference: objects carrying $parent must be exactly { "$parent": "<field>" }'
|
|
@@ -7455,7 +7760,7 @@ function resolveValueNode(template, parent, bare) {
|
|
|
7455
7760
|
}
|
|
7456
7761
|
return resolveObjectEntries(template, parent);
|
|
7457
7762
|
}
|
|
7458
|
-
if ((0,
|
|
7763
|
+
if ((0, import_utils22.isArray)(template)) {
|
|
7459
7764
|
return template.map((item) => resolveValueNode(item, parent, false));
|
|
7460
7765
|
}
|
|
7461
7766
|
return template;
|
|
@@ -7489,7 +7794,7 @@ function resolveCorrelatedIdTemplate(id, parent) {
|
|
|
7489
7794
|
}
|
|
7490
7795
|
function resolveCorrelatedFilterTemplate(filter2, parent) {
|
|
7491
7796
|
try {
|
|
7492
|
-
if (!(0,
|
|
7797
|
+
if (!(0, import_utils22.isPlainObject)(filter2) || isParentRefMarker(filter2) || isEscapedParentRef(filter2)) {
|
|
7493
7798
|
throw new CorrelatedReferenceError("Correlated include filter must be an object");
|
|
7494
7799
|
}
|
|
7495
7800
|
return { status: "resolved", filter: resolveObjectEntries(filter2, parent) };
|
|
@@ -7504,7 +7809,7 @@ function validateExpandedCorrelatedOperands(expanded, limits) {
|
|
|
7504
7809
|
var MAX_NESTED_INCLUDE_DEPTH = 10;
|
|
7505
7810
|
function validateCorrelatedArgsShape(args, op, depth) {
|
|
7506
7811
|
if (args === void 0) return [];
|
|
7507
|
-
if (!(0,
|
|
7812
|
+
if (!(0, import_utils22.isPlainObject)(args)) return ["Correlated include args must be an object"];
|
|
7508
7813
|
const record3 = args;
|
|
7509
7814
|
const allowed = op === "list" ? /* @__PURE__ */ new Set(["select", "sort", "skip", "limit", "page", "pageSize", "include"]) : /* @__PURE__ */ new Set(["select", "sort", "include"]);
|
|
7510
7815
|
for (const key of Object.keys(record3)) {
|
|
@@ -7526,7 +7831,7 @@ function validateCorrelatedArgsShape(args, op, depth) {
|
|
|
7526
7831
|
return [];
|
|
7527
7832
|
}
|
|
7528
7833
|
function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
7529
|
-
if (!(0,
|
|
7834
|
+
if (!(0, import_utils22.isPlainObject)(entry)) return ["Correlated include must be an object"];
|
|
7530
7835
|
const record3 = entry;
|
|
7531
7836
|
if (record3.mode !== "correlated") return ['Correlated include mode must be "correlated"'];
|
|
7532
7837
|
if (typeof record3.model !== "string" || record3.model.length === 0)
|
|
@@ -7539,7 +7844,7 @@ function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
|
7539
7844
|
if ("localField" in record3 || "foreignField" in record3) {
|
|
7540
7845
|
return ["Correlated includes must not carry localField or foreignField"];
|
|
7541
7846
|
}
|
|
7542
|
-
if (record3.options !== void 0 && !((0,
|
|
7847
|
+
if (record3.options !== void 0 && !((0, import_utils22.isPlainObject)(record3.options) && Object.keys(record3.options).length === 0)) {
|
|
7543
7848
|
return ["Correlated include options must be absent or empty"];
|
|
7544
7849
|
}
|
|
7545
7850
|
const hasId = record3.id !== void 0;
|
|
@@ -7561,7 +7866,7 @@ function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
|
7561
7866
|
return validateCorrelatedArgsShape(record3.args, record3.op, depth);
|
|
7562
7867
|
}
|
|
7563
7868
|
function isCorrelatedInclude(value) {
|
|
7564
|
-
return (0,
|
|
7869
|
+
return (0, import_utils22.isPlainObject)(value) && value.mode === "correlated";
|
|
7565
7870
|
}
|
|
7566
7871
|
|
|
7567
7872
|
// src/services/base.ts
|
|
@@ -8298,20 +8603,20 @@ var copyAuthorizedOutput = (value) => {
|
|
|
8298
8603
|
transferDocumentAuthorizationGraph(value, copy);
|
|
8299
8604
|
return copy;
|
|
8300
8605
|
};
|
|
8301
|
-
var isVirtualContainerValueForGuard = (value) => (0,
|
|
8606
|
+
var isVirtualContainerValueForGuard = (value) => (0, import_utils25.isPlainObject)(value) && "sub" in value;
|
|
8302
8607
|
var getScopeVirtualsForGuard = (rootVirtuals, scopePath) => {
|
|
8303
|
-
if (!rootVirtuals || !(0,
|
|
8608
|
+
if (!rootVirtuals || !(0, import_utils25.isPlainObject)(rootVirtuals)) return null;
|
|
8304
8609
|
if (scopePath.length === 0) return rootVirtuals;
|
|
8305
8610
|
let current = rootVirtuals;
|
|
8306
8611
|
for (let i = 0; i < scopePath.length; i += 2) {
|
|
8307
8612
|
const field = scopePath[i];
|
|
8308
8613
|
const subMarker = scopePath[i + 1];
|
|
8309
8614
|
if (!field || subMarker !== "sub") return null;
|
|
8310
|
-
if (!(0,
|
|
8615
|
+
if (!(0, import_utils25.isPlainObject)(current)) return null;
|
|
8311
8616
|
const container = current[field];
|
|
8312
8617
|
if (!isVirtualContainerValueForGuard(container)) return null;
|
|
8313
8618
|
current = container.sub;
|
|
8314
|
-
if (!(0,
|
|
8619
|
+
if (!(0, import_utils25.isPlainObject)(current)) return null;
|
|
8315
8620
|
}
|
|
8316
8621
|
return current;
|
|
8317
8622
|
};
|
|
@@ -8377,7 +8682,7 @@ var sanitizeSubScopeVirtualKeys = (data, snapshot, sub) => {
|
|
|
8377
8682
|
for (const entry of value) stripScope(entry, currentScope);
|
|
8378
8683
|
return;
|
|
8379
8684
|
}
|
|
8380
|
-
if (!(0,
|
|
8685
|
+
if (!(0, import_utils25.isPlainObject)(value)) return;
|
|
8381
8686
|
const record3 = value;
|
|
8382
8687
|
const leaves = getScopeVirtualLeafNames(snapshot, currentScope);
|
|
8383
8688
|
for (const leaf of leaves) {
|
|
@@ -8390,7 +8695,7 @@ var sanitizeSubScopeVirtualKeys = (data, snapshot, sub) => {
|
|
|
8390
8695
|
for (const key of Object.keys(record3)) {
|
|
8391
8696
|
if (leaves.has(key) || containers.has(key)) continue;
|
|
8392
8697
|
const child = record3[key];
|
|
8393
|
-
if (Array.isArray(child) || (0,
|
|
8698
|
+
if (Array.isArray(child) || (0, import_utils25.isPlainObject)(child)) {
|
|
8394
8699
|
stripScope(child, currentScope);
|
|
8395
8700
|
}
|
|
8396
8701
|
}
|
|
@@ -8402,7 +8707,7 @@ var LOGICAL_FILTER_KEYS = /* @__PURE__ */ new Set(["$and", "$or", "$nor"]);
|
|
|
8402
8707
|
var isOperatorKey = (key) => key.startsWith("$");
|
|
8403
8708
|
var REMOVED_VIRTUAL_FILTER = /* @__PURE__ */ Symbol("removed virtual filter clause");
|
|
8404
8709
|
var rewriteFilterObject = (value, visit) => {
|
|
8405
|
-
if (!(0,
|
|
8710
|
+
if (!(0, import_utils25.isPlainObject)(value)) return value;
|
|
8406
8711
|
let changed = false;
|
|
8407
8712
|
const entries = [];
|
|
8408
8713
|
for (const [key, child] of Object.entries(value)) {
|
|
@@ -8433,7 +8738,7 @@ var resolveVirtualFilterField = (path, scope2) => {
|
|
|
8433
8738
|
if (!Object.hasOwn(scope2, segment) || scope2[segment] === void 0) return null;
|
|
8434
8739
|
const definition = scope2[segment];
|
|
8435
8740
|
if (!isVirtualContainerValueForGuard(definition)) return REMOVED_VIRTUAL_FILTER;
|
|
8436
|
-
scope2 = (0,
|
|
8741
|
+
scope2 = (0, import_utils25.isPlainObject)(definition.sub) ? definition.sub : null;
|
|
8437
8742
|
inContainer = true;
|
|
8438
8743
|
}
|
|
8439
8744
|
return scope2;
|
|
@@ -8445,7 +8750,7 @@ var stripVirtualFilterOperator = (key, value, scope2) => {
|
|
|
8445
8750
|
}
|
|
8446
8751
|
if (key === "$all") {
|
|
8447
8752
|
return rewriteFilterClauses(value, (entry) => {
|
|
8448
|
-
if (!(0,
|
|
8753
|
+
if (!(0, import_utils25.isPlainObject)(entry) || Object.keys(entry).length !== 1 || !Object.hasOwn(entry, "$elemMatch")) return entry;
|
|
8449
8754
|
return rewriteFilterObject(entry, (operator, operand) => stripVirtualFilterOperator(operator, operand, scope2));
|
|
8450
8755
|
});
|
|
8451
8756
|
}
|
|
@@ -8460,7 +8765,7 @@ var stripVirtualFilterQuery = (value, scope2, element = false) => {
|
|
|
8460
8765
|
if (isOperatorKey(key)) return element ? stripVirtualFilterOperator(key, child, scope2) : child;
|
|
8461
8766
|
const fieldScope = resolveVirtualFilterField(key, scope2);
|
|
8462
8767
|
if (fieldScope === REMOVED_VIRTUAL_FILTER) return REMOVED_VIRTUAL_FILTER;
|
|
8463
|
-
if (!fieldScope || !(0,
|
|
8768
|
+
if (!fieldScope || !(0, import_utils25.isPlainObject)(child)) return child;
|
|
8464
8769
|
if (Object.keys(child).some(isOperatorKey)) {
|
|
8465
8770
|
return rewriteFilterObject(
|
|
8466
8771
|
child,
|
|
@@ -8482,9 +8787,9 @@ var stripSubVirtualKeysFromFilter = (filter2, snapshot, sub) => {
|
|
|
8482
8787
|
function getCorrelatedTemplateDepth(includes) {
|
|
8483
8788
|
let max = 0;
|
|
8484
8789
|
const visit = (entries, depth) => {
|
|
8485
|
-
const list = (0,
|
|
8790
|
+
const list = (0, import_utils25.castArray)(entries).filter(Boolean);
|
|
8486
8791
|
for (const entry of list) {
|
|
8487
|
-
if (!(0,
|
|
8792
|
+
if (!(0, import_utils25.isPlainObject)(entry)) continue;
|
|
8488
8793
|
max = Math.max(max, depth);
|
|
8489
8794
|
const nested = entry.args?.include;
|
|
8490
8795
|
if (nested !== void 0) {
|
|
@@ -8509,11 +8814,11 @@ function validateClientFilter(filter2) {
|
|
|
8509
8814
|
}
|
|
8510
8815
|
const blockedOperators = /* @__PURE__ */ new Set(["$where", "$expr", "$function", "$accumulator"]);
|
|
8511
8816
|
const visit = (value, path) => {
|
|
8512
|
-
if ((0,
|
|
8817
|
+
if ((0, import_utils25.isArray)(value)) {
|
|
8513
8818
|
value.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
8514
8819
|
return;
|
|
8515
8820
|
}
|
|
8516
|
-
if (!(0,
|
|
8821
|
+
if (!(0, import_utils25.isPlainObject)(value)) return;
|
|
8517
8822
|
Object.entries(value).forEach(([key, child]) => {
|
|
8518
8823
|
const nextPath = path ? `${path}.${key}` : key;
|
|
8519
8824
|
if (blockedOperators.has(key)) {
|
|
@@ -8718,7 +9023,7 @@ var Base = class {
|
|
|
8718
9023
|
}
|
|
8719
9024
|
processInclude(include, authorization) {
|
|
8720
9025
|
assertPublicAdmission(include, "include");
|
|
8721
|
-
const items = (0,
|
|
9026
|
+
const items = (0, import_utils25.compact)((0, import_utils25.castArray)(include));
|
|
8722
9027
|
const legacy = [];
|
|
8723
9028
|
const correlated = [];
|
|
8724
9029
|
const correlatedReferenceFields = [];
|
|
@@ -8754,23 +9059,23 @@ var Base = class {
|
|
|
8754
9059
|
else this.assertIncludeOutputPaths([...legacy, ...correlated]);
|
|
8755
9060
|
let includeLocalFields = [];
|
|
8756
9061
|
let includePaths = [];
|
|
8757
|
-
(0,
|
|
9062
|
+
(0, import_utils25.forEach)(legacy, (inc) => {
|
|
8758
9063
|
includeLocalFields.push(inc.localField);
|
|
8759
9064
|
includePaths.push(inc.path);
|
|
8760
9065
|
});
|
|
8761
|
-
includeLocalFields = (0,
|
|
8762
|
-
includePaths = (0,
|
|
9066
|
+
includeLocalFields = (0, import_utils25.uniq)((0, import_utils25.compact)(includeLocalFields));
|
|
9067
|
+
includePaths = (0, import_utils25.uniq)((0, import_utils25.compact)(includePaths));
|
|
8763
9068
|
return {
|
|
8764
9069
|
includes: legacy,
|
|
8765
9070
|
correlatedIncludes: correlated,
|
|
8766
9071
|
includeLocalFields,
|
|
8767
9072
|
includePaths,
|
|
8768
|
-
correlatedReferenceFields: (0,
|
|
9073
|
+
correlatedReferenceFields: (0, import_utils25.uniq)((0, import_utils25.compact)(correlatedReferenceFields))
|
|
8769
9074
|
};
|
|
8770
9075
|
}
|
|
8771
9076
|
validateIncludeOutputPath(path, modelName, configuration) {
|
|
8772
9077
|
const permissionField = configuration ? configuration.documentPermissionField ?? "_permissions" : getModelOption(modelName, "documentPermissionField");
|
|
8773
|
-
if ((0,
|
|
9078
|
+
if ((0, import_utils25.get)((0, import_utils25.set)({}, path, true), permissionField) !== void 0 || (0, import_utils25.get)((0, import_utils25.set)({}, permissionField, true), path) !== void 0) {
|
|
8774
9079
|
this.throwClientRequestError(
|
|
8775
9080
|
"bad_request" /* BadRequest */,
|
|
8776
9081
|
`Include output path ${path} overlaps document permission field ${permissionField} on model ${modelName}`
|
|
@@ -8795,9 +9100,9 @@ var Base = class {
|
|
|
8795
9100
|
const walk = (node, prefix) => {
|
|
8796
9101
|
for (const [key, value] of Object.entries(node)) {
|
|
8797
9102
|
if (value === void 0) continue;
|
|
8798
|
-
if ((0,
|
|
9103
|
+
if ((0, import_utils25.isPlainObject)(value) && "sub" in value) {
|
|
8799
9104
|
const sub = value.sub;
|
|
8800
|
-
if ((0,
|
|
9105
|
+
if ((0, import_utils25.isPlainObject)(sub)) walk(sub, prefix ? `${prefix}.${key}` : key);
|
|
8801
9106
|
continue;
|
|
8802
9107
|
}
|
|
8803
9108
|
out.push(prefix ? `${prefix}.${key}` : key);
|
|
@@ -8850,7 +9155,7 @@ var Base = class {
|
|
|
8850
9155
|
this.throwClientRequestError("bad_request" /* BadRequest */, `Model ${modelName} not found`);
|
|
8851
9156
|
}
|
|
8852
9157
|
for (const entry of entries) {
|
|
8853
|
-
if (!(0,
|
|
9158
|
+
if (!(0, import_utils25.isPlainObject)(entry)) continue;
|
|
8854
9159
|
const models = visited.get(entry) ?? /* @__PURE__ */ new Set();
|
|
8855
9160
|
if (models.has(modelName)) continue;
|
|
8856
9161
|
models.add(modelName);
|
|
@@ -8863,7 +9168,7 @@ var Base = class {
|
|
|
8863
9168
|
const target = targets?.find((target2) => target2.path === entry.path);
|
|
8864
9169
|
if (nested)
|
|
8865
9170
|
pending.push({
|
|
8866
|
-
entries: (0,
|
|
9171
|
+
entries: (0, import_utils25.compact)((0, import_utils25.castArray)(nested)),
|
|
8867
9172
|
modelName: entry.model,
|
|
8868
9173
|
configuration: target?.configuration,
|
|
8869
9174
|
targets: target?.relatedTargets
|
|
@@ -8873,7 +9178,7 @@ var Base = class {
|
|
|
8873
9178
|
}
|
|
8874
9179
|
}
|
|
8875
9180
|
getForeignKeyValues(value) {
|
|
8876
|
-
return (0,
|
|
9181
|
+
return (0, import_utils25.flatten)((0, import_utils25.castArray)(value));
|
|
8877
9182
|
}
|
|
8878
9183
|
getForeignKey(value) {
|
|
8879
9184
|
return String(value);
|
|
@@ -8881,7 +9186,7 @@ var Base = class {
|
|
|
8881
9186
|
buildForeignKeyIndex(rows2, foreignField) {
|
|
8882
9187
|
const index = /* @__PURE__ */ new Map();
|
|
8883
9188
|
for (const row of rows2) {
|
|
8884
|
-
for (const value of this.getForeignKeyValues((0,
|
|
9189
|
+
for (const value of this.getForeignKeyValues((0, import_utils25.get)(row, foreignField))) {
|
|
8885
9190
|
const key = this.getForeignKey(value);
|
|
8886
9191
|
const values = index.get(key);
|
|
8887
9192
|
if (values) values.push(row);
|
|
@@ -8917,9 +9222,9 @@ var Base = class {
|
|
|
8917
9222
|
async includeDocs(docs, include, parentAuthorization) {
|
|
8918
9223
|
assertPublicAdmission(include, "include");
|
|
8919
9224
|
if (!include) return docs;
|
|
8920
|
-
const includes = (0,
|
|
9225
|
+
const includes = (0, import_utils25.compact)((0, import_utils25.castArray)(include));
|
|
8921
9226
|
if (includes.length === 0) return docs;
|
|
8922
|
-
const isSingle = !(0,
|
|
9227
|
+
const isSingle = !(0, import_utils25.isArray)(docs);
|
|
8923
9228
|
let docList = (isSingle ? [docs] : docs).map(prepareIncludeOutput);
|
|
8924
9229
|
for (let x = 0; x < includes.length; x++) {
|
|
8925
9230
|
const include2 = includes[x];
|
|
@@ -8949,7 +9254,7 @@ var Base = class {
|
|
|
8949
9254
|
const svc = await this.getAuthorizedTargetService(model, "read", path, parentAuthorization);
|
|
8950
9255
|
for (let y = 0; y < docs.length; y++) {
|
|
8951
9256
|
const doc = docs[y];
|
|
8952
|
-
const localValue = (0,
|
|
9257
|
+
const localValue = (0, import_utils25.get)(doc, localField);
|
|
8953
9258
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
8954
9259
|
const prepared = await prepareModelQuery(
|
|
8955
9260
|
svc,
|
|
@@ -8984,15 +9289,15 @@ var Base = class {
|
|
|
8984
9289
|
const { model, op, path, localField, foreignField, filter: _filters, args = {}, options = {} } = include;
|
|
8985
9290
|
const svc = await this.getAuthorizedTargetService(model, op, path, parentAuthorization);
|
|
8986
9291
|
const includeLocalValues = [];
|
|
8987
|
-
(0,
|
|
8988
|
-
includeLocalValues.push(...this.getForeignKeyValues((0,
|
|
9292
|
+
(0, import_utils25.forEach)(docs, (doc) => {
|
|
9293
|
+
includeLocalValues.push(...this.getForeignKeyValues((0, import_utils25.get)(doc, localField)));
|
|
8989
9294
|
});
|
|
8990
9295
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
8991
9296
|
const prepared = await prepareModelQuery(
|
|
8992
9297
|
svc,
|
|
8993
9298
|
execution,
|
|
8994
9299
|
{ kind: "client-read", filter: _filters ?? {} },
|
|
8995
|
-
{ [foreignField]: { $in: (0,
|
|
9300
|
+
{ [foreignField]: { $in: (0, import_utils25.flatten)(includeLocalValues) } },
|
|
8996
9301
|
true
|
|
8997
9302
|
);
|
|
8998
9303
|
const trustedArgs = this.sanitizeIncludeArgs(args, "list");
|
|
@@ -9035,7 +9340,7 @@ var Base = class {
|
|
|
9035
9340
|
}
|
|
9036
9341
|
for (let y = 0; y < docs.length; y++) {
|
|
9037
9342
|
const doc = docs[y];
|
|
9038
|
-
const matches = this.getIndexedMatches(index, (0,
|
|
9343
|
+
const matches = this.getIndexedMatches(index, (0, import_utils25.get)(doc, localField));
|
|
9039
9344
|
const isolated = matches.map((m) => copyAuthorizedOutput(m));
|
|
9040
9345
|
attachIncludeOutput(doc, path, op === "list" ? isolated : isolated[0]);
|
|
9041
9346
|
}
|
|
@@ -9044,7 +9349,7 @@ var Base = class {
|
|
|
9044
9349
|
async includeDocsCount(docs, include, parentAuthorization) {
|
|
9045
9350
|
const { model, path, localField, foreignField, filter: _filters } = include;
|
|
9046
9351
|
const svc = await this.getAuthorizedTargetService(model, "count", path, parentAuthorization);
|
|
9047
|
-
const groups = prepareCountGroups(docs, (doc) => (0,
|
|
9352
|
+
const groups = prepareCountGroups(docs, (doc) => (0, import_utils25.get)(doc, localField));
|
|
9048
9353
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
9049
9354
|
const prepared = await prepareModelQuery(
|
|
9050
9355
|
svc,
|
|
@@ -9098,7 +9403,7 @@ var Base = class {
|
|
|
9098
9403
|
}
|
|
9099
9404
|
const state = this.getCorrelatedExecState();
|
|
9100
9405
|
docs = docs.map(prepareIncludeOutput);
|
|
9101
|
-
const resolvedSnapshots = snapshots2 ?? docs.map((doc) => (0,
|
|
9406
|
+
const resolvedSnapshots = snapshots2 ?? docs.map((doc) => (0, import_utils25.cloneDeep)(toObject(getIncludeSource(doc))));
|
|
9102
9407
|
for (const include of correlatedIncludes) {
|
|
9103
9408
|
switch (include.op) {
|
|
9104
9409
|
case "read":
|
|
@@ -9447,10 +9752,10 @@ var Base = class {
|
|
|
9447
9752
|
}
|
|
9448
9753
|
let ret = result2.data;
|
|
9449
9754
|
if (sqOptions.path) {
|
|
9450
|
-
ret = (0,
|
|
9755
|
+
ret = (0, import_utils25.isArray)(ret) ? (0, import_utils25.flatten)(ret.map((v) => (0, import_utils25.get)(v, sqOptions.path))) : (0, import_utils25.get)(ret, sqOptions.path);
|
|
9451
9756
|
}
|
|
9452
9757
|
if (sqOptions.compact) {
|
|
9453
|
-
ret = (0,
|
|
9758
|
+
ret = (0, import_utils25.compact)((0, import_utils25.castArray)(ret));
|
|
9454
9759
|
}
|
|
9455
9760
|
return ret;
|
|
9456
9761
|
}
|
|
@@ -9462,11 +9767,11 @@ var Base = class {
|
|
|
9462
9767
|
};
|
|
9463
9768
|
|
|
9464
9769
|
// src/services/service.ts
|
|
9465
|
-
var
|
|
9770
|
+
var import_utils36 = require("@web-ts-toolkit/utils");
|
|
9466
9771
|
var import_just_diff = require("just-diff");
|
|
9467
9772
|
|
|
9468
9773
|
// src/model.ts
|
|
9469
|
-
var
|
|
9774
|
+
var import_utils26 = require("@web-ts-toolkit/utils");
|
|
9470
9775
|
init_runtime_context();
|
|
9471
9776
|
init_runtime();
|
|
9472
9777
|
function admitModelPersistence(adapter, scheduler) {
|
|
@@ -9542,7 +9847,7 @@ var Model = class {
|
|
|
9542
9847
|
}
|
|
9543
9848
|
/** Cast a copy using this model's query schema/setters, without executing query middleware or persistence. */
|
|
9544
9849
|
castFilter(filter2) {
|
|
9545
|
-
const query = this.mongooseModel.countDocuments((0,
|
|
9850
|
+
const query = this.mongooseModel.countDocuments((0, import_utils26.cloneDeep)(filter2));
|
|
9546
9851
|
return query.cast(this.mongooseModel);
|
|
9547
9852
|
}
|
|
9548
9853
|
// see https://mongoosejs.com/docs/api.html#model_Model.distinct
|
|
@@ -9556,7 +9861,7 @@ var Model = class {
|
|
|
9556
9861
|
var model_default = Model;
|
|
9557
9862
|
|
|
9558
9863
|
// src/acl/distinct-field-authorization.ts
|
|
9559
|
-
var
|
|
9864
|
+
var import_utils27 = require("@web-ts-toolkit/utils");
|
|
9560
9865
|
init_field_authorization();
|
|
9561
9866
|
init_field_catalog();
|
|
9562
9867
|
var schemaVariants = (schema) => Object.values(schema.discriminators ?? {});
|
|
@@ -9638,8 +9943,8 @@ function isDistinctFieldAuthorized(args) {
|
|
|
9638
9943
|
if (path !== field && !path.startsWith(`${field}.`) && !field.startsWith(`${path}.`)) continue;
|
|
9639
9944
|
if (path.startsWith(`${field}.`) && (!eligible(path) || !schemaShape(schema, path) || !granted(path)))
|
|
9640
9945
|
return false;
|
|
9641
|
-
if ((0,
|
|
9642
|
-
if (!(0,
|
|
9946
|
+
if ((0, import_utils27.isPlainObject)(raw) && raw.sub !== void 0) {
|
|
9947
|
+
if (!(0, import_utils27.isPlainObject)(raw.sub) || !declaredRulesSafe(raw.sub, path, next)) return false;
|
|
9643
9948
|
}
|
|
9644
9949
|
}
|
|
9645
9950
|
return true;
|
|
@@ -9816,7 +10121,7 @@ init_document();
|
|
|
9816
10121
|
init_populate_target();
|
|
9817
10122
|
|
|
9818
10123
|
// src/helpers/apply-update.ts
|
|
9819
|
-
var
|
|
10124
|
+
var import_utils31 = require("@web-ts-toolkit/utils");
|
|
9820
10125
|
init_lib();
|
|
9821
10126
|
function applyUpdate(target, data, allowedFields) {
|
|
9822
10127
|
const wholeFields = /* @__PURE__ */ new Set();
|
|
@@ -9832,17 +10137,17 @@ function applyUpdate(target, data, allowedFields) {
|
|
|
9832
10137
|
}
|
|
9833
10138
|
};
|
|
9834
10139
|
for (const field of allowedFields) {
|
|
9835
|
-
collectBoundary((0,
|
|
10140
|
+
collectBoundary((0, import_utils31.set)({}, field, true));
|
|
9836
10141
|
}
|
|
9837
10142
|
const apply = (values, prefix = "") => {
|
|
9838
10143
|
for (const [key, value] of Object.entries(values)) {
|
|
9839
10144
|
const path = prefix ? `${prefix}.${key}` : key;
|
|
9840
|
-
if (partialContainers.has(path) && !wholeFields.has(path) && ((0,
|
|
10145
|
+
if (partialContainers.has(path) && !wholeFields.has(path) && ((0, import_utils31.isPlainObject)(value) || Array.isArray(value))) {
|
|
9841
10146
|
apply(value, path);
|
|
9842
10147
|
} else if (isDocument2(target)) {
|
|
9843
10148
|
target.set(path, value);
|
|
9844
10149
|
} else {
|
|
9845
|
-
(0,
|
|
10150
|
+
(0, import_utils31.set)(target, path, value);
|
|
9846
10151
|
}
|
|
9847
10152
|
}
|
|
9848
10153
|
};
|
|
@@ -9850,7 +10155,7 @@ function applyUpdate(target, data, allowedFields) {
|
|
|
9850
10155
|
}
|
|
9851
10156
|
|
|
9852
10157
|
// src/acl/model-input-admission.ts
|
|
9853
|
-
var
|
|
10158
|
+
var import_utils33 = require("@web-ts-toolkit/utils");
|
|
9854
10159
|
var import_mongoose8 = require("mongoose");
|
|
9855
10160
|
init_document();
|
|
9856
10161
|
init_request_work();
|
|
@@ -9858,7 +10163,7 @@ init_logger_helpers();
|
|
|
9858
10163
|
init_request_complexity();
|
|
9859
10164
|
|
|
9860
10165
|
// src/acl/select-resolution.ts
|
|
9861
|
-
var
|
|
10166
|
+
var import_utils32 = require("@web-ts-toolkit/utils");
|
|
9862
10167
|
init_core_shared();
|
|
9863
10168
|
init_helpers();
|
|
9864
10169
|
async function collectAllowedFieldsForRequest({
|
|
@@ -9932,15 +10237,15 @@ async function resolveSelectForRequest({
|
|
|
9932
10237
|
const excludeall = normalizedSelect.every((v) => v.startsWith("-"));
|
|
9933
10238
|
if (excludeall) {
|
|
9934
10239
|
normalizedSelect = normalizedSelect.map((v) => v.substring(1));
|
|
9935
|
-
fields = (0,
|
|
10240
|
+
fields = (0, import_utils32.difference)(fields, normalizedSelect);
|
|
9936
10241
|
if (excludeid) fields.push("-_id");
|
|
9937
10242
|
} else {
|
|
9938
|
-
fields = (0,
|
|
10243
|
+
fields = (0, import_utils32.intersection)(normalizedSelect, fields.concat(excludeid ? "-_id" : "_id"));
|
|
9939
10244
|
}
|
|
9940
10245
|
}
|
|
9941
10246
|
return fields.concat(strippedAlways);
|
|
9942
10247
|
}
|
|
9943
|
-
return (0,
|
|
10248
|
+
return (0, import_utils32.intersection)(normalizedSelect, fields);
|
|
9944
10249
|
}
|
|
9945
10250
|
function stripVirtuals(fields, virtualNames) {
|
|
9946
10251
|
const set13 = virtualNames instanceof Set ? virtualNames : new Set(virtualNames ?? []);
|
|
@@ -9971,7 +10276,7 @@ init_field_catalog();
|
|
|
9971
10276
|
init_service_authorization();
|
|
9972
10277
|
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
9973
10278
|
var inside = (path, root) => path === root || path.startsWith(`${root}.`);
|
|
9974
|
-
var record2 = (value) => (0,
|
|
10279
|
+
var record2 = (value) => (0, import_utils33.isPlainObject)(value);
|
|
9975
10280
|
function inputValue(value) {
|
|
9976
10281
|
if (typeof value === "function" || typeof value === "symbol") {
|
|
9977
10282
|
authorizationError("input values must be persisted data, not functions or symbols");
|
|
@@ -10040,7 +10345,7 @@ function requestBoundaries(fields) {
|
|
|
10040
10345
|
else visit(value, path);
|
|
10041
10346
|
}
|
|
10042
10347
|
};
|
|
10043
|
-
for (const field of fields) visit((0,
|
|
10348
|
+
for (const field of fields) visit((0, import_utils33.set)({}, field, true));
|
|
10044
10349
|
return [...new Set(result2)];
|
|
10045
10350
|
}
|
|
10046
10351
|
function ownValue(data, parts) {
|
|
@@ -10170,7 +10475,7 @@ function admitModelInput(args) {
|
|
|
10170
10475
|
if (forbidden(catalog, path, requested)) continue;
|
|
10171
10476
|
const supplied = ownValue(data, parts);
|
|
10172
10477
|
if (!supplied) continue;
|
|
10173
|
-
(0,
|
|
10478
|
+
(0, import_utils33.set)(allowedData, field, copyInputValue(supplied.value, path, catalog, scopedRequests, logicalPath(field)));
|
|
10174
10479
|
selected.push(field);
|
|
10175
10480
|
}
|
|
10176
10481
|
return { allowedData, allowedFields };
|
|
@@ -10182,7 +10487,7 @@ async function requestInputFields(args) {
|
|
|
10182
10487
|
const prefix = configuration.modelPermissionPrefix ?? "";
|
|
10183
10488
|
return collectModelRequestFields({
|
|
10184
10489
|
req: args.binding.request,
|
|
10185
|
-
permissionSchema: args.scopePath ? (0,
|
|
10490
|
+
permissionSchema: args.scopePath ? (0, import_utils33.get)(configuration.permissionSchema, [args.scopePath, "sub"]) : configuration.permissionSchema,
|
|
10186
10491
|
access: args.access,
|
|
10187
10492
|
permissions,
|
|
10188
10493
|
grants,
|
|
@@ -10226,13 +10531,13 @@ init_logger_helpers();
|
|
|
10226
10531
|
init_lib();
|
|
10227
10532
|
|
|
10228
10533
|
// src/services/model-subdocument-service.ts
|
|
10229
|
-
var
|
|
10534
|
+
var import_utils35 = require("@web-ts-toolkit/utils");
|
|
10230
10535
|
init_helpers();
|
|
10231
10536
|
init_document();
|
|
10232
10537
|
init_public_admission();
|
|
10233
10538
|
|
|
10234
10539
|
// src/acl/subdocument-authorization.ts
|
|
10235
|
-
var
|
|
10540
|
+
var import_utils34 = require("@web-ts-toolkit/utils");
|
|
10236
10541
|
init_helpers();
|
|
10237
10542
|
init_document();
|
|
10238
10543
|
init_core_shared();
|
|
@@ -10421,8 +10726,8 @@ async function subdocumentGateAllowed(service, gate) {
|
|
|
10421
10726
|
let guard2;
|
|
10422
10727
|
if (access.startsWith("subs.")) {
|
|
10423
10728
|
const [, sub, op] = access.split(".");
|
|
10424
|
-
guard2 = (0,
|
|
10425
|
-
if (guard2 === void 0) guard2 = (0,
|
|
10729
|
+
guard2 = (0, import_utils34.get)(configuration, `operationAccess.${access}`);
|
|
10730
|
+
if (guard2 === void 0) guard2 = (0, import_utils34.get)(configuration, `operationAccess.subs.${sub}`);
|
|
10426
10731
|
if (guard2 === void 0) guard2 = getCapturedAuthorizationOption(configuration, `operationAccess.${op}`);
|
|
10427
10732
|
} else guard2 = getCapturedAuthorizationOption(configuration, `operationAccess.${access}`);
|
|
10428
10733
|
return evaluateRouteGuard(
|
|
@@ -10553,7 +10858,7 @@ async function visibleMutationRows(service, call, parentId, rows2) {
|
|
|
10553
10858
|
const read = await subdocumentRows(service, visibility.child, selected, selected, call.sub);
|
|
10554
10859
|
const list = visibility.list ? await subdocumentRows(service, visibility.list, {}, {}, call.sub) : {};
|
|
10555
10860
|
if (read === false || list === false) return [];
|
|
10556
|
-
const visible = filterCollection((0,
|
|
10861
|
+
const visible = filterCollection((0, import_utils35.get)(parent, call.sub), intersectFilters(read, list));
|
|
10557
10862
|
return await finalizeSubdocumentRows(service, call.output, parent, visible);
|
|
10558
10863
|
} catch {
|
|
10559
10864
|
return [];
|
|
@@ -10578,7 +10883,7 @@ async function listSub(service, id, sub, options) {
|
|
|
10578
10883
|
populate: []
|
|
10579
10884
|
});
|
|
10580
10885
|
if (!parent) return denied2("not_found" /* NotFound */);
|
|
10581
|
-
const rows2 = filterCollection((0,
|
|
10886
|
+
const rows2 = filterCollection((0, import_utils35.get)(parent, sub), childFilter);
|
|
10582
10887
|
const data = await finalizeSubdocumentRows(service, call.output, parent, rows2);
|
|
10583
10888
|
return { success: true, kind: "list", code: "success" /* Success */, data, count: data.length };
|
|
10584
10889
|
});
|
|
@@ -10602,7 +10907,7 @@ async function readSub(service, id, sub, subId, options) {
|
|
|
10602
10907
|
});
|
|
10603
10908
|
if (!parent) return denied2("not_found" /* NotFound */);
|
|
10604
10909
|
const row = findElement(
|
|
10605
|
-
(0,
|
|
10910
|
+
(0, import_utils35.get)(capture ? parent : copySubdocumentParent(parent), sub),
|
|
10606
10911
|
childFilter
|
|
10607
10912
|
);
|
|
10608
10913
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
@@ -10623,7 +10928,7 @@ async function updateSub(service, persist, id, sub, subId, data, options) {
|
|
|
10623
10928
|
const identity = { _id: subId };
|
|
10624
10929
|
const filter2 = await subdocumentRows(service, call.child, identity, identity, sub);
|
|
10625
10930
|
if (filter2 === false) return denied2();
|
|
10626
|
-
const row = findElement((0,
|
|
10931
|
+
const row = findElement((0, import_utils35.get)(parent, sub), filter2);
|
|
10627
10932
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
10628
10933
|
const original = isolateDocForOutput(row);
|
|
10629
10934
|
const admit = await inputAdmission(service, call, parent);
|
|
@@ -10650,7 +10955,7 @@ async function bulkUpdateSub(service, persist, id, sub, data, options) {
|
|
|
10650
10955
|
const selected = { _id: { $in: data.map((row) => row._id) } };
|
|
10651
10956
|
const filter2 = await subdocumentRows(service, call.child, selected, selected, sub);
|
|
10652
10957
|
if (filter2 === false) return denied2();
|
|
10653
|
-
const rows2 = filterCollection((0,
|
|
10958
|
+
const rows2 = filterCollection((0, import_utils35.get)(parent, sub), filter2);
|
|
10654
10959
|
const originals = rows2.map((row) => isolateDocForOutput(row));
|
|
10655
10960
|
const admit = await inputAdmission(service, call, parent);
|
|
10656
10961
|
for (const [index, row] of rows2.entries()) {
|
|
@@ -10679,7 +10984,7 @@ async function createSub(service, persist, id, sub, data, options) {
|
|
|
10679
10984
|
const lookup = await mutationParent(service, id, call);
|
|
10680
10985
|
if ("error" in lookup) return lookup.error;
|
|
10681
10986
|
const { parent } = lookup;
|
|
10682
|
-
const rows2 = (0,
|
|
10987
|
+
const rows2 = (0, import_utils35.get)(parent, sub);
|
|
10683
10988
|
const admit = await inputAdmission(service, call, parent);
|
|
10684
10989
|
const allowed = (Array.isArray(data) ? data : [data]).map((row) => admit(row).allowedData);
|
|
10685
10990
|
if (addFirst) rows2.unshift(...allowed);
|
|
@@ -10700,7 +11005,7 @@ async function deleteSub(service, persist, id, sub, subId, options) {
|
|
|
10700
11005
|
const identity = { _id: subId };
|
|
10701
11006
|
const filter2 = await subdocumentRows(service, call.child, identity, identity, sub);
|
|
10702
11007
|
if (filter2 === false) return denied2();
|
|
10703
|
-
const row = findElement((0,
|
|
11008
|
+
const row = findElement((0, import_utils35.get)(parent, sub), filter2);
|
|
10704
11009
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
10705
11010
|
await ("deleteOne" in row ? row.deleteOne?.() : row.remove?.());
|
|
10706
11011
|
await persist(() => parent.save());
|
|
@@ -11015,20 +11320,20 @@ var Service = class extends Base {
|
|
|
11015
11320
|
const field = configuration.documentPermissionField ?? "_permissions";
|
|
11016
11321
|
unsetDocPath(output, field);
|
|
11017
11322
|
if (!configuration.stripPermissionsField) {
|
|
11018
|
-
(0,
|
|
11323
|
+
(0, import_utils36.set)(output, field, args.includePermissions || args.includeFieldPermissions ? deepIsolateValue(grants) : {});
|
|
11019
11324
|
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
11020
11325
|
const rowAccess = this.asServiceHookContext(context).fieldPermissionAccess ?? await this.getFieldPermissionAccess([snapshot._id]);
|
|
11021
11326
|
const id = String(snapshot._id);
|
|
11022
11327
|
const views = rowAccess.readIds?.has(id) ? await requestOutputFieldPaths(handle, binding, "read") : [];
|
|
11023
11328
|
const edits = rowAccess.updateIds?.has(id) ? await requestOutputFieldPaths(handle, binding, "update") : [];
|
|
11024
11329
|
const map2 = (paths) => paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
11025
|
-
(0,
|
|
11026
|
-
(0,
|
|
11027
|
-
} else if (!args.includePermissions) (0,
|
|
11330
|
+
(0, import_utils36.set)(output, `${field}._view`, map2(views));
|
|
11331
|
+
(0, import_utils36.set)(output, `${field}._edit`, map2(edits));
|
|
11332
|
+
} else if (!args.includePermissions) (0, import_utils36.set)(output, field, { _view: { $: "_" }, _edit: { $: "_" } });
|
|
11028
11333
|
const exposed = configuration.exposedDocPermissionKeys;
|
|
11029
11334
|
if (exposed) {
|
|
11030
|
-
const metadata = (0,
|
|
11031
|
-
(0,
|
|
11335
|
+
const metadata = (0, import_utils36.get)(output, field);
|
|
11336
|
+
(0, import_utils36.set)(
|
|
11032
11337
|
output,
|
|
11033
11338
|
field,
|
|
11034
11339
|
Object.fromEntries(
|
|
@@ -11289,7 +11594,7 @@ var Service = class extends Base {
|
|
|
11289
11594
|
return docs.map((doc) => {
|
|
11290
11595
|
try {
|
|
11291
11596
|
const plain = toObject(doc);
|
|
11292
|
-
const val = (0,
|
|
11597
|
+
const val = (0, import_utils36.get)(plain, associationField);
|
|
11293
11598
|
return deepIsolateValue(val);
|
|
11294
11599
|
} catch {
|
|
11295
11600
|
return void 0;
|
|
@@ -11398,7 +11703,7 @@ var Service = class extends Base {
|
|
|
11398
11703
|
if (this.isScalarPopulateValue(rawTarget)) return rawTarget;
|
|
11399
11704
|
const isDoc = (() => {
|
|
11400
11705
|
try {
|
|
11401
|
-
if ((0,
|
|
11706
|
+
if ((0, import_utils36.isPlainObject)(rawTarget)) return true;
|
|
11402
11707
|
const maybe = rawTarget;
|
|
11403
11708
|
if (maybe && typeof maybe === "object" && "_doc" in maybe) return true;
|
|
11404
11709
|
if (maybe && typeof maybe.toObject === "function") return true;
|
|
@@ -11486,7 +11791,7 @@ var Service = class extends Base {
|
|
|
11486
11791
|
child = getDocValue(current, key);
|
|
11487
11792
|
if (child === void 0) {
|
|
11488
11793
|
try {
|
|
11489
|
-
child = (0,
|
|
11794
|
+
child = (0, import_utils36.get)(current, key);
|
|
11490
11795
|
} catch {
|
|
11491
11796
|
return;
|
|
11492
11797
|
}
|
|
@@ -11721,7 +12026,7 @@ var Service = class extends Base {
|
|
|
11721
12026
|
originalDocumentSnapshot: toObject(doc),
|
|
11722
12027
|
resolvedQuery: query
|
|
11723
12028
|
};
|
|
11724
|
-
const correlatedSnapshots = [(0,
|
|
12029
|
+
const correlatedSnapshots = [(0, import_utils36.cloneDeep)(toObject(doc))];
|
|
11725
12030
|
try {
|
|
11726
12031
|
doc = await this.includeDocs(doc, includes, state.authorization);
|
|
11727
12032
|
if (correlatedIncludes.length > 0) {
|
|
@@ -11903,7 +12208,7 @@ var Service = class extends Base {
|
|
|
11903
12208
|
const findAssociationField = this.getAssociationFieldFromOptions(options);
|
|
11904
12209
|
const withAssocSelect = findAssociationField && !finalSelect.includes(findAssociationField) ? [...finalSelect, findAssociationField] : finalSelect;
|
|
11905
12210
|
const dbSelect = this.buildDbSelectForAssociation(withAssocSelect, findAssociationField);
|
|
11906
|
-
const filteredPopulate = (0,
|
|
12211
|
+
const filteredPopulate = (0, import_utils36.isArray)(withAssocSelect) && (0, import_utils36.isArray)(_populate) ? _populate.filter(
|
|
11907
12212
|
(p) => [
|
|
11908
12213
|
...virtualPlan.publicPersistedFetchSelection,
|
|
11909
12214
|
...findAssociationField ? [findAssociationField] : []
|
|
@@ -11963,7 +12268,7 @@ var Service = class extends Base {
|
|
|
11963
12268
|
findAssociationField ? [findAssociationField] : []
|
|
11964
12269
|
);
|
|
11965
12270
|
const capturedAssociation = findAssociationField ? this.captureAssociationValues(docs, findAssociationField) : void 0;
|
|
11966
|
-
const correlatedSnapshots = docs.map((doc) => (0,
|
|
12271
|
+
const correlatedSnapshots = docs.map((doc) => (0, import_utils36.cloneDeep)(toObject(doc)));
|
|
11967
12272
|
try {
|
|
11968
12273
|
docs = await this.includeDocs(docs, includes, state.authorization);
|
|
11969
12274
|
if (correlatedIncludes.length > 0) {
|
|
@@ -12162,12 +12467,12 @@ var Service = class extends Base {
|
|
|
12162
12467
|
context.allowedFields = allowedFields;
|
|
12163
12468
|
context.allowedData = allowedData;
|
|
12164
12469
|
const validated = await this.validate(allowedData, "create", context);
|
|
12165
|
-
if ((0,
|
|
12470
|
+
if ((0, import_utils36.isBoolean)(validated)) {
|
|
12166
12471
|
if (!validated) {
|
|
12167
12472
|
validationErrors.push({ index, errors: [] });
|
|
12168
12473
|
return void 0;
|
|
12169
12474
|
}
|
|
12170
|
-
} else if ((0,
|
|
12475
|
+
} else if ((0, import_utils36.isArray)(validated)) {
|
|
12171
12476
|
if (validated.length > 0) {
|
|
12172
12477
|
validationErrors.push({
|
|
12173
12478
|
index,
|
|
@@ -12378,7 +12683,7 @@ var Service = class extends Base {
|
|
|
12378
12683
|
}
|
|
12379
12684
|
let doc = await this.model.findOne({
|
|
12380
12685
|
filter: _filter,
|
|
12381
|
-
select: (0,
|
|
12686
|
+
select: (0, import_utils36.uniq)([...updatePlan.persistedFetchSelection, ...inputFetchPaths(captured.configuration.catalog)]).map(
|
|
12382
12687
|
(path) => `+${path}`
|
|
12383
12688
|
)
|
|
12384
12689
|
});
|
|
@@ -12417,12 +12722,12 @@ var Service = class extends Base {
|
|
|
12417
12722
|
context.allowedFields = allowedFields;
|
|
12418
12723
|
context.allowedData = allowedData;
|
|
12419
12724
|
const validated = await this.validate(allowedData, "update", context);
|
|
12420
|
-
if ((0,
|
|
12725
|
+
if ((0, import_utils36.isBoolean)(validated)) {
|
|
12421
12726
|
if (!validated) {
|
|
12422
12727
|
this.completeOp("updateOne", startedAt, "bad_request" /* BadRequest */, _filter);
|
|
12423
12728
|
return { success: false, kind: "error", code: "bad_request" /* BadRequest */ };
|
|
12424
12729
|
}
|
|
12425
|
-
} else if ((0,
|
|
12730
|
+
} else if ((0, import_utils36.isArray)(validated)) {
|
|
12426
12731
|
if (validated.length > 0) {
|
|
12427
12732
|
this.completeOp("updateOne", startedAt, "bad_request" /* BadRequest */, _filter);
|
|
12428
12733
|
return { success: false, kind: "error", code: "bad_request" /* BadRequest */, errors: validated };
|
|
@@ -12442,10 +12747,10 @@ var Service = class extends Base {
|
|
|
12442
12747
|
const diffExcludeFields = [this.options.documentPermissionField, "__v"];
|
|
12443
12748
|
this.asServiceHookContext(context).diff = (d) => {
|
|
12444
12749
|
context.changes = (0, import_just_diff.diff)(
|
|
12445
|
-
(0,
|
|
12446
|
-
(0,
|
|
12750
|
+
(0, import_utils36.omit)(context.originalDocumentSnapshot, diffExcludeFields),
|
|
12751
|
+
(0, import_utils36.omit)(d.toObject({ virtuals: false }), diffExcludeFields)
|
|
12447
12752
|
) || [];
|
|
12448
|
-
context.modifiedPaths = (0,
|
|
12753
|
+
context.modifiedPaths = (0, import_utils36.uniq)(context.changes.map((di) => di.path.length > 0 ? String(di.path[0]) : ""));
|
|
12449
12754
|
};
|
|
12450
12755
|
doc = assertModelDocument(await this.afterPersist(doc, "update", context), this.modelName, "afterPersist");
|
|
12451
12756
|
context.currentDocument = doc;
|
|
@@ -12533,7 +12838,7 @@ var Service = class extends Base {
|
|
|
12533
12838
|
const upsertOptions = this.resolveUpsertOptions(options);
|
|
12534
12839
|
const updateIntent = captureModelServiceIntent(this, "updateOne", upsertArgs, upsertOptions);
|
|
12535
12840
|
const createIntent = captureModelServiceIntent(this, "create", upsertArgs, upsertOptions);
|
|
12536
|
-
const related = (0,
|
|
12841
|
+
const related = (0, import_utils36.uniqBy)(
|
|
12537
12842
|
[...this.captureRelated(updateIntent.args), ...this.captureRelated(createIntent.args)],
|
|
12538
12843
|
(target) => target.path
|
|
12539
12844
|
);
|
|
@@ -12974,7 +13279,7 @@ var Service = class extends Base {
|
|
|
12974
13279
|
return resolveExistsOptions(this, options);
|
|
12975
13280
|
}
|
|
12976
13281
|
async getFieldPermissionAccess(ids) {
|
|
12977
|
-
const uniqueIds = (0,
|
|
13282
|
+
const uniqueIds = (0, import_utils36.compact)((0, import_utils36.uniqBy)(ids, (id) => String(id)).map((id) => String(id)));
|
|
12978
13283
|
if (uniqueIds.length === 0) {
|
|
12979
13284
|
return {
|
|
12980
13285
|
readIds: /* @__PURE__ */ new Set(),
|
|
@@ -13020,7 +13325,7 @@ var Service = class extends Base {
|
|
|
13020
13325
|
* (direct/root-entry 200); count measures visible rows, not all updated rows.
|
|
13021
13326
|
*/
|
|
13022
13327
|
async bulkUpdateSub(id, sub, data, options) {
|
|
13023
|
-
return bulkUpdateSub(this, this.persist, id, sub, (0,
|
|
13328
|
+
return bulkUpdateSub(this, this.persist, id, sub, (0, import_utils36.castArray)(data), options);
|
|
13024
13329
|
}
|
|
13025
13330
|
/**
|
|
13026
13331
|
* Append/prepend admitted rows, then return the visible full array (including when
|
|
@@ -13044,7 +13349,7 @@ var Service = class extends Base {
|
|
|
13044
13349
|
};
|
|
13045
13350
|
|
|
13046
13351
|
// src/services/public-service.ts
|
|
13047
|
-
var
|
|
13352
|
+
var import_utils37 = require("@web-ts-toolkit/utils");
|
|
13048
13353
|
init_helpers();
|
|
13049
13354
|
init_permissions_alias();
|
|
13050
13355
|
init_document();
|
|
@@ -13170,7 +13475,7 @@ var PublicService = class extends Service {
|
|
|
13170
13475
|
let d = toObject(doc);
|
|
13171
13476
|
d = await this.decorate(d, "create", context);
|
|
13172
13477
|
d = this.runTasks(d, tasks);
|
|
13173
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13478
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13174
13479
|
return d;
|
|
13175
13480
|
}
|
|
13176
13481
|
);
|
|
@@ -13389,8 +13694,8 @@ var PublicService = class extends Service {
|
|
|
13389
13694
|
let d = toObject(doc);
|
|
13390
13695
|
d = await this.decorate(d, "update", context);
|
|
13391
13696
|
d = this.runTasks(d, tasks);
|
|
13392
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13393
|
-
else if (!returningAll) d = copyPermissionsAlias(d, (0,
|
|
13697
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13698
|
+
else if (!returningAll) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, returningKeys));
|
|
13394
13699
|
return d;
|
|
13395
13700
|
}
|
|
13396
13701
|
);
|
|
@@ -13473,8 +13778,8 @@ var PublicService = class extends Service {
|
|
|
13473
13778
|
let d = toObject(doc);
|
|
13474
13779
|
d = await this.decorate(d, "update", context);
|
|
13475
13780
|
d = this.runTasks(d, tasks2);
|
|
13476
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13477
|
-
else if (!returningAll) d = copyPermissionsAlias(d, (0,
|
|
13781
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13782
|
+
else if (!returningAll) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, returningKeys));
|
|
13478
13783
|
return d;
|
|
13479
13784
|
}
|
|
13480
13785
|
);
|
|
@@ -13499,7 +13804,7 @@ var PublicService = class extends Service {
|
|
|
13499
13804
|
d = await this.decorate(d, "create", context);
|
|
13500
13805
|
d = this.runTasks(d, tasks);
|
|
13501
13806
|
if (createSelect)
|
|
13502
|
-
d = copyPermissionsAlias(d, (0,
|
|
13807
|
+
d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(createSelect), ...this.baseFieldsExt]));
|
|
13503
13808
|
return d;
|
|
13504
13809
|
}
|
|
13505
13810
|
);
|
|
@@ -13644,7 +13949,7 @@ var PublicService = class extends Service {
|
|
|
13644
13949
|
init_options();
|
|
13645
13950
|
init_data_values();
|
|
13646
13951
|
init_helpers();
|
|
13647
|
-
var
|
|
13952
|
+
var import_utils38 = require("@web-ts-toolkit/utils");
|
|
13648
13953
|
init_request_complexity();
|
|
13649
13954
|
init_runtime_context();
|
|
13650
13955
|
init_runtime();
|
|
@@ -13673,7 +13978,7 @@ var DataService = class {
|
|
|
13673
13978
|
let doc = await findElement(this.data, _filter);
|
|
13674
13979
|
if (!doc) return { success: false, kind: "error", code: "not_found" /* NotFound */, query };
|
|
13675
13980
|
doc = await this.trimOutputFields(doc, access);
|
|
13676
|
-
if (_select.length > 0) doc = (0,
|
|
13981
|
+
if (_select.length > 0) doc = (0, import_utils38.pick)(doc, _select);
|
|
13677
13982
|
return {
|
|
13678
13983
|
success: true,
|
|
13679
13984
|
kind: "single",
|
|
@@ -13719,13 +14024,13 @@ var DataService = class {
|
|
|
13719
14024
|
const totalCount = docs.length;
|
|
13720
14025
|
if (sort) {
|
|
13721
14026
|
const normalizedSort = normalizeSortForOrderBy(sort);
|
|
13722
|
-
docs = (0,
|
|
14027
|
+
docs = (0, import_utils38.orderBy)(docs, normalizedSort.fields, normalizedSort.orders);
|
|
13723
14028
|
}
|
|
13724
14029
|
const pagedDocs = docs.slice(query.skip, query.limit && query.skip + query.limit);
|
|
13725
14030
|
const { maxHookConcurrency } = this.getRequestComplexity();
|
|
13726
14031
|
const trimmed = await mapWithConcurrencyLimit(pagedDocs, maxHookConcurrency, async (doc) => {
|
|
13727
14032
|
doc = await this.trimOutputFields(doc, "list");
|
|
13728
|
-
if (_select.length > 0) doc = (0,
|
|
14033
|
+
if (_select.length > 0) doc = (0, import_utils38.pick)(doc, _select);
|
|
13729
14034
|
return copyDataValue(doc);
|
|
13730
14035
|
});
|
|
13731
14036
|
if (!hasExplicitLimit && trimmed.length === totalCount) {
|
|
@@ -13800,10 +14105,10 @@ var DataService = class {
|
|
|
13800
14105
|
init_helpers();
|
|
13801
14106
|
|
|
13802
14107
|
// src/processors.ts
|
|
13803
|
-
var
|
|
14108
|
+
var import_utils39 = require("@web-ts-toolkit/utils");
|
|
13804
14109
|
init_permissions_alias();
|
|
13805
14110
|
function cloneProcessorValue(value) {
|
|
13806
|
-
const copy = (0,
|
|
14111
|
+
const copy = (0, import_utils39.cloneDeep)(value);
|
|
13807
14112
|
copyPermissionsAliasGraph(value, copy);
|
|
13808
14113
|
return copy;
|
|
13809
14114
|
}
|
|
@@ -13841,10 +14146,10 @@ function resolveLeafParents(obj, src) {
|
|
|
13841
14146
|
for (let ind = 0; ind < segs.length - 1; ind += 1) {
|
|
13842
14147
|
const seg = segs[ind];
|
|
13843
14148
|
targets = targets.reduce((ret, target) => {
|
|
13844
|
-
if (!(0,
|
|
14149
|
+
if (!(0, import_utils39.isPlainObject)(target)) return ret;
|
|
13845
14150
|
const targetObject = target;
|
|
13846
14151
|
const next = targetObject[seg];
|
|
13847
|
-
if ((0,
|
|
14152
|
+
if ((0, import_utils39.isArray)(next)) {
|
|
13848
14153
|
for (const item of next) {
|
|
13849
14154
|
ret.push(item);
|
|
13850
14155
|
}
|
|
@@ -13854,8 +14159,8 @@ function resolveLeafParents(obj, src) {
|
|
|
13854
14159
|
}
|
|
13855
14160
|
const leaf = segs[segs.length - 1];
|
|
13856
14161
|
const pairs = [];
|
|
13857
|
-
(0,
|
|
13858
|
-
if (!(0,
|
|
14162
|
+
(0, import_utils39.forEach)(targets, (target) => {
|
|
14163
|
+
if (!(0, import_utils39.isPlainObject)(target)) return;
|
|
13859
14164
|
pairs.push({ parent: target, leaf });
|
|
13860
14165
|
});
|
|
13861
14166
|
return pairs;
|
|
@@ -13864,7 +14169,7 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13864
14169
|
const mutable = options.mutable !== false;
|
|
13865
14170
|
const idField = options.idField ?? "_id";
|
|
13866
14171
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13867
|
-
(0,
|
|
14172
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13868
14173
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13869
14174
|
const src = op.src;
|
|
13870
14175
|
const dest = op.dest;
|
|
@@ -13873,19 +14178,19 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13873
14178
|
assertSafePath(dest);
|
|
13874
14179
|
let targets = [obj];
|
|
13875
14180
|
const segs = src.split(".");
|
|
13876
|
-
(0,
|
|
14181
|
+
(0, import_utils39.forEach)(segs, (seg, ind) => {
|
|
13877
14182
|
if (segs.length === ind + 1) {
|
|
13878
|
-
(0,
|
|
13879
|
-
if (!(0,
|
|
14183
|
+
(0, import_utils39.forEach)(targets, (target) => {
|
|
14184
|
+
if (!(0, import_utils39.isPlainObject)(target)) return;
|
|
13880
14185
|
const targetObject = target;
|
|
13881
14186
|
const leaf = targetObject[seg];
|
|
13882
14187
|
const sourceForDest = leaf;
|
|
13883
14188
|
let depopulated;
|
|
13884
|
-
if ((0,
|
|
14189
|
+
if ((0, import_utils39.isArray)(leaf)) {
|
|
13885
14190
|
if (leaf.length === 0) {
|
|
13886
14191
|
depopulated = [];
|
|
13887
|
-
} else if (leaf.every((item) => (0,
|
|
13888
|
-
depopulated = (0,
|
|
14192
|
+
} else if (leaf.every((item) => (0, import_utils39.isPlainObject)(item))) {
|
|
14193
|
+
depopulated = (0, import_utils39.map)(leaf, idField).map((id, i) => {
|
|
13889
14194
|
if (id === void 0) {
|
|
13890
14195
|
failMissingId(`${src}[${i}]`);
|
|
13891
14196
|
}
|
|
@@ -13894,8 +14199,8 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13894
14199
|
} else {
|
|
13895
14200
|
return;
|
|
13896
14201
|
}
|
|
13897
|
-
} else if ((0,
|
|
13898
|
-
const id = (0,
|
|
14202
|
+
} else if ((0, import_utils39.isPlainObject)(leaf)) {
|
|
14203
|
+
const id = (0, import_utils39.get)(leaf, idField);
|
|
13899
14204
|
if (id === void 0) {
|
|
13900
14205
|
failMissingId(src);
|
|
13901
14206
|
}
|
|
@@ -13903,15 +14208,15 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13903
14208
|
} else {
|
|
13904
14209
|
return;
|
|
13905
14210
|
}
|
|
13906
|
-
(0,
|
|
13907
|
-
(0,
|
|
14211
|
+
(0, import_utils39.set)(targetObject, dest, sourceForDest);
|
|
14212
|
+
(0, import_utils39.set)(targetObject, seg, depopulated);
|
|
13908
14213
|
});
|
|
13909
14214
|
} else {
|
|
13910
14215
|
targets = targets.reduce((ret, target) => {
|
|
13911
|
-
if (!(0,
|
|
14216
|
+
if (!(0, import_utils39.isPlainObject)(target)) return ret;
|
|
13912
14217
|
const targetObject = target;
|
|
13913
14218
|
const next = targetObject[seg];
|
|
13914
|
-
if ((0,
|
|
14219
|
+
if ((0, import_utils39.isArray)(next)) {
|
|
13915
14220
|
for (const item of next) {
|
|
13916
14221
|
ret.push(item);
|
|
13917
14222
|
}
|
|
@@ -13926,7 +14231,7 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13926
14231
|
var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
13927
14232
|
const mutable = options.mutable !== false;
|
|
13928
14233
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13929
|
-
(0,
|
|
14234
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13930
14235
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13931
14236
|
const src = op.src;
|
|
13932
14237
|
const dest = op.dest;
|
|
@@ -13934,9 +14239,9 @@ var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13934
14239
|
assertSafePath(src, "copyPaths");
|
|
13935
14240
|
assertSafePath(dest, "copyPaths");
|
|
13936
14241
|
if (src === dest) return;
|
|
13937
|
-
(0,
|
|
13938
|
-
if (!(0,
|
|
13939
|
-
(0,
|
|
14242
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14243
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14244
|
+
(0, import_utils39.set)(parent, dest, cloneProcessorValue(parent[leaf]));
|
|
13940
14245
|
});
|
|
13941
14246
|
});
|
|
13942
14247
|
return obj;
|
|
@@ -13944,7 +14249,7 @@ var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13944
14249
|
var movePaths = (docObject, operations, options = { mutable: true }) => {
|
|
13945
14250
|
const mutable = options.mutable !== false;
|
|
13946
14251
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13947
|
-
(0,
|
|
14252
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13948
14253
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13949
14254
|
const src = op.src;
|
|
13950
14255
|
const dest = op.dest;
|
|
@@ -13952,10 +14257,10 @@ var movePaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13952
14257
|
assertSafePath(src, "movePaths");
|
|
13953
14258
|
assertSafePath(dest, "movePaths");
|
|
13954
14259
|
if (src === dest) return;
|
|
13955
|
-
(0,
|
|
13956
|
-
if (!(0,
|
|
14260
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14261
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
13957
14262
|
const value = cloneProcessorValue(parent[leaf]);
|
|
13958
|
-
(0,
|
|
14263
|
+
(0, import_utils39.set)(parent, dest, value);
|
|
13959
14264
|
if (dest === leaf || dest.startsWith(`${leaf}.`)) return;
|
|
13960
14265
|
delete parent[leaf];
|
|
13961
14266
|
});
|
|
@@ -13967,7 +14272,7 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
13967
14272
|
const maxSlice = options.maxSlice ?? DEFAULT_MAX_SLICE;
|
|
13968
14273
|
assertNonNegativeSafeInteger(maxSlice, "maxSlice", "sliceArrays");
|
|
13969
14274
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13970
|
-
(0,
|
|
14275
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13971
14276
|
if (!op || typeof op.src !== "string") return;
|
|
13972
14277
|
const src = op.src;
|
|
13973
14278
|
if (src.length === 0) return;
|
|
@@ -13984,15 +14289,15 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
13984
14289
|
assertNonNegativeSafeInteger(op.limit, "limit", "sliceArrays");
|
|
13985
14290
|
limit = Math.min(op.limit, maxSlice);
|
|
13986
14291
|
}
|
|
13987
|
-
(0,
|
|
14292
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
13988
14293
|
const leafValue = parent[leaf];
|
|
13989
|
-
if (!(0,
|
|
14294
|
+
if (!(0, import_utils39.isArray)(leafValue)) return;
|
|
13990
14295
|
const end = typeof limit === "undefined" ? void 0 : skip + limit;
|
|
13991
14296
|
const window = leafValue.slice(skip, end);
|
|
13992
14297
|
if (typeof rawDest === "undefined") {
|
|
13993
|
-
(0,
|
|
14298
|
+
(0, import_utils39.set)(parent, leaf, window);
|
|
13994
14299
|
} else {
|
|
13995
|
-
(0,
|
|
14300
|
+
(0, import_utils39.set)(parent, rawDest, window);
|
|
13996
14301
|
}
|
|
13997
14302
|
});
|
|
13998
14303
|
});
|
|
@@ -14001,27 +14306,27 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
14001
14306
|
var countPaths = (docObject, operations, options = { mutable: true }) => {
|
|
14002
14307
|
const mutable = options.mutable !== false;
|
|
14003
14308
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
14004
|
-
(0,
|
|
14309
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
14005
14310
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
14006
14311
|
const src = op.src;
|
|
14007
14312
|
const dest = op.dest;
|
|
14008
14313
|
if (src.length === 0 || dest.length === 0) return;
|
|
14009
14314
|
assertSafePath(src, "countPaths");
|
|
14010
14315
|
assertSafePath(dest, "countPaths");
|
|
14011
|
-
(0,
|
|
14012
|
-
if (!(0,
|
|
14316
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14317
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14013
14318
|
const leafValue = parent[leaf];
|
|
14014
14319
|
let count;
|
|
14015
|
-
if ((0,
|
|
14320
|
+
if ((0, import_utils39.isArray)(leafValue)) {
|
|
14016
14321
|
count = leafValue.length;
|
|
14017
|
-
} else if ((0,
|
|
14322
|
+
} else if ((0, import_utils39.isPlainObject)(leafValue)) {
|
|
14018
14323
|
count = Object.keys(leafValue).length;
|
|
14019
14324
|
} else if (leafValue === null || typeof leafValue === "undefined") {
|
|
14020
14325
|
count = 0;
|
|
14021
14326
|
} else {
|
|
14022
14327
|
count = 1;
|
|
14023
14328
|
}
|
|
14024
|
-
(0,
|
|
14329
|
+
(0, import_utils39.set)(parent, dest, count);
|
|
14025
14330
|
});
|
|
14026
14331
|
});
|
|
14027
14332
|
return obj;
|
|
@@ -14029,15 +14334,15 @@ var countPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
14029
14334
|
var maskPaths = (docObject, operations, options = { mutable: true }) => {
|
|
14030
14335
|
const mutable = options.mutable !== false;
|
|
14031
14336
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
14032
|
-
(0,
|
|
14337
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
14033
14338
|
if (!op || typeof op.src !== "string") return;
|
|
14034
14339
|
const src = op.src;
|
|
14035
14340
|
if (src.length === 0) return;
|
|
14036
14341
|
assertSafePath(src, "maskPaths");
|
|
14037
14342
|
const replacement = Object.prototype.hasOwnProperty.call(op, "replacement") ? op.replacement : DEFAULT_MASK_REPLACEMENT;
|
|
14038
|
-
(0,
|
|
14039
|
-
if (!(0,
|
|
14040
|
-
(0,
|
|
14343
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14344
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14345
|
+
(0, import_utils39.set)(parent, leaf, replacement);
|
|
14041
14346
|
});
|
|
14042
14347
|
});
|
|
14043
14348
|
return obj;
|
|
@@ -14111,10 +14416,10 @@ var Core = class {
|
|
|
14111
14416
|
getIdentifier(modelName) {
|
|
14112
14417
|
const resolveIdFilter = getModelOption(modelName, "resolveIdFilter");
|
|
14113
14418
|
const idField = getModelOption(modelName, "idField");
|
|
14114
|
-
if ((0,
|
|
14419
|
+
if ((0, import_utils40.isFunction)(resolveIdFilter)) {
|
|
14115
14420
|
return null;
|
|
14116
14421
|
}
|
|
14117
|
-
if ((0,
|
|
14422
|
+
if ((0, import_utils40.isString)(idField)) {
|
|
14118
14423
|
return idField;
|
|
14119
14424
|
}
|
|
14120
14425
|
return "_id";
|
|
@@ -14206,7 +14511,7 @@ var Core = class {
|
|
|
14206
14511
|
/** Persisted request-only populate admission; fetch planning is not field authority. */
|
|
14207
14512
|
async requestPopulateSelect(configuration, permissions, access, targetFields = null, scopePath = []) {
|
|
14208
14513
|
const subPaths = scopePath.flatMap((part) => [part, "sub"]);
|
|
14209
|
-
const permissionSchema = (0,
|
|
14514
|
+
const permissionSchema = (0, import_utils40.get)(configuration, ["permissionSchema", ...subPaths]);
|
|
14210
14515
|
const prefix = scopePath.length ? `${scopePath.join(".")}.` : "";
|
|
14211
14516
|
const virtualNames = (configuration.catalog.virtualPaths ?? []).filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)).filter((path) => !path.includes("."));
|
|
14212
14517
|
return resolveSelectForRequest({
|
|
@@ -14229,7 +14534,7 @@ var Core = class {
|
|
|
14229
14534
|
if (!_populate) return [];
|
|
14230
14535
|
const descriptors = copyAuthorizationValue(Array.isArray(_populate) ? _populate : [_populate], true);
|
|
14231
14536
|
for (const p of descriptors) {
|
|
14232
|
-
if (!(0,
|
|
14537
|
+
if (!(0, import_utils40.isString)(p)) assertPopulateAccess(p.access);
|
|
14233
14538
|
}
|
|
14234
14539
|
const runtime = this.requestRuntime;
|
|
14235
14540
|
const globalOptions = modelServiceGlobalOptions(this, runtime);
|
|
@@ -14239,13 +14544,13 @@ var Core = class {
|
|
|
14239
14544
|
const permissions = new permission_default(
|
|
14240
14545
|
Object.fromEntries(originalPermissions.keys.map((key) => [key, originalPermissions.has(key)]))
|
|
14241
14546
|
);
|
|
14242
|
-
const populate = (0,
|
|
14547
|
+
const populate = (0, import_utils40.compact)(
|
|
14243
14548
|
await Promise.all(
|
|
14244
14549
|
descriptors.map(async (p) => {
|
|
14245
|
-
const populateAccess = !(0,
|
|
14550
|
+
const populateAccess = !(0, import_utils40.isString)(p) && p.access ? p.access : access;
|
|
14246
14551
|
assertPopulateAccess(populateAccess);
|
|
14247
|
-
const originalSelect = (0,
|
|
14248
|
-
const ret = (0,
|
|
14552
|
+
const originalSelect = (0, import_utils40.isString)(p) ? void 0 : p.select;
|
|
14553
|
+
const ret = (0, import_utils40.isString)(p) ? { path: p } : {
|
|
14249
14554
|
path: p.path,
|
|
14250
14555
|
select: normalizeSelect(p.select)
|
|
14251
14556
|
};
|
|
@@ -14284,11 +14589,11 @@ var Core = class {
|
|
|
14284
14589
|
targetConfiguration.alwaysSelectFields,
|
|
14285
14590
|
populateAccess
|
|
14286
14591
|
);
|
|
14287
|
-
ret.select = (0,
|
|
14592
|
+
ret.select = (0, import_utils40.uniq)([
|
|
14288
14593
|
...ret.select,
|
|
14289
14594
|
...stripVirtuals(hookInputs, [...targetConfiguration.catalog.virtualPaths ?? []])
|
|
14290
14595
|
]);
|
|
14291
|
-
const match = (0,
|
|
14596
|
+
const match = (0, import_utils40.isString)(p) ? {} : p.match ?? {};
|
|
14292
14597
|
const filter2 = await resolveAccessFilterForRequest({
|
|
14293
14598
|
req: this.req,
|
|
14294
14599
|
permissions,
|
|
@@ -14319,7 +14624,7 @@ var Core = class {
|
|
|
14319
14624
|
internalFetch: { baseFields: ["_id"] },
|
|
14320
14625
|
globalPermissions: permissions
|
|
14321
14626
|
});
|
|
14322
|
-
const merged = (0,
|
|
14627
|
+
const merged = (0, import_utils40.uniq)([...normalizeSelect(ret.select), ...targetPlan.virtualOnlyDeps ?? []]).filter(
|
|
14323
14628
|
(t) => t !== "-_id" && !t.includes(".sub.")
|
|
14324
14629
|
);
|
|
14325
14630
|
if (!merged.includes("_id")) merged.push("_id");
|
|
@@ -14341,10 +14646,10 @@ var Core = class {
|
|
|
14341
14646
|
}
|
|
14342
14647
|
async validate(modelName, allowedData, access, context) {
|
|
14343
14648
|
const validate = getModelOption(modelName, `validate.${access}`, null);
|
|
14344
|
-
if ((0,
|
|
14649
|
+
if ((0, import_utils40.isFunction)(validate)) {
|
|
14345
14650
|
const permissions = this.getGlobalPermissions();
|
|
14346
14651
|
return validate.call(this.req, allowedData, permissions, context);
|
|
14347
|
-
} else if ((0,
|
|
14652
|
+
} else if ((0, import_utils40.isBoolean)(validate) || (0, import_utils40.isArray)(validate)) {
|
|
14348
14653
|
return validate;
|
|
14349
14654
|
} else {
|
|
14350
14655
|
return true;
|
|
@@ -14369,7 +14674,7 @@ var Core = class {
|
|
|
14369
14674
|
const changeOptions = getModelOption(modelName, `onChange`, {});
|
|
14370
14675
|
for (let x = 0; x < context.modifiedPaths.length; x++) {
|
|
14371
14676
|
const mpath = context.modifiedPaths[x];
|
|
14372
|
-
if ((0,
|
|
14677
|
+
if ((0, import_utils40.isFunction)(changeOptions[mpath])) {
|
|
14373
14678
|
await changeOptions[mpath].call(
|
|
14374
14679
|
this.req,
|
|
14375
14680
|
context.originalDocumentSnapshot[mpath],
|
|
@@ -14393,7 +14698,7 @@ var Core = class {
|
|
|
14393
14698
|
async genDocPermissions(modelName, doc, access, context) {
|
|
14394
14699
|
const docPermissionsFn = getModelOption(modelName, `docPermissions.${access}`, null);
|
|
14395
14700
|
let docPermissions = {};
|
|
14396
|
-
if ((0,
|
|
14701
|
+
if ((0, import_utils40.isFunction)(docPermissionsFn)) {
|
|
14397
14702
|
const permissions = this.getGlobalPermissions();
|
|
14398
14703
|
try {
|
|
14399
14704
|
docPermissions = await getRequestWorkState(this.req, this.requestRuntime).hookGate.run(
|
|
@@ -14477,7 +14782,7 @@ var Core = class {
|
|
|
14477
14782
|
readExists ? requestFields("read") : [],
|
|
14478
14783
|
updateExists ? requestFields("update") : []
|
|
14479
14784
|
]);
|
|
14480
|
-
const viewObj = (0,
|
|
14785
|
+
const viewObj = (0, import_utils40.reduce)(
|
|
14481
14786
|
views,
|
|
14482
14787
|
(ret, view) => {
|
|
14483
14788
|
ret[view] = true;
|
|
@@ -14485,7 +14790,7 @@ var Core = class {
|
|
|
14485
14790
|
},
|
|
14486
14791
|
{}
|
|
14487
14792
|
);
|
|
14488
|
-
const editObj = (0,
|
|
14793
|
+
const editObj = (0, import_utils40.reduce)(
|
|
14489
14794
|
edits,
|
|
14490
14795
|
(ret, view) => {
|
|
14491
14796
|
ret[view] = true;
|
|
@@ -14516,9 +14821,9 @@ var Core = class {
|
|
|
14516
14821
|
});
|
|
14517
14822
|
}
|
|
14518
14823
|
runTasks(modelName, docObject, task) {
|
|
14519
|
-
const tasks = (0,
|
|
14824
|
+
const tasks = (0, import_utils40.compact)((0, import_utils40.castArray)(task));
|
|
14520
14825
|
if (tasks.length === 0) return docObject;
|
|
14521
|
-
(0,
|
|
14826
|
+
(0, import_utils40.forEach)(tasks, (task2) => {
|
|
14522
14827
|
const { type, args, options } = task2;
|
|
14523
14828
|
switch (type) {
|
|
14524
14829
|
case "COPY_AND_DEPOPULATE":
|
|
@@ -14588,9 +14893,9 @@ var Core = class {
|
|
|
14588
14893
|
}
|
|
14589
14894
|
const [, field, op] = keys2;
|
|
14590
14895
|
const subOption = getExactModelOption(modelName, `operationAccess.${access}`);
|
|
14591
|
-
if ((0,
|
|
14896
|
+
if ((0, import_utils40.isUndefined)(subOption)) {
|
|
14592
14897
|
const subFieldOption = getExactModelOption(modelName, `operationAccess.subs.${field}`);
|
|
14593
|
-
if ((0,
|
|
14898
|
+
if ((0, import_utils40.isUndefined)(subFieldOption)) {
|
|
14594
14899
|
const opOption = getModelOption(modelName, `operationAccess.${op}`);
|
|
14595
14900
|
return this.canActivate(opOption);
|
|
14596
14901
|
}
|
|
@@ -14656,25 +14961,25 @@ function guard(condition) {
|
|
|
14656
14961
|
const permissions = req[PERMISSIONS];
|
|
14657
14962
|
let cond = condition;
|
|
14658
14963
|
let phas = (key) => permissions.has(key);
|
|
14659
|
-
if ((0,
|
|
14964
|
+
if ((0, import_utils41.isPlainObject)(condition)) {
|
|
14660
14965
|
const { modelName, id, condition: _cond } = condition;
|
|
14661
14966
|
const svc = req.macl.getPublicService(modelName);
|
|
14662
14967
|
const select = getModelOption(modelName, `alwaysSelectFields.read`, void 0);
|
|
14663
|
-
let _id = (0,
|
|
14664
|
-
if ((0,
|
|
14968
|
+
let _id = (0, import_utils41.isString)(id) ? id : null;
|
|
14969
|
+
if ((0, import_utils41.isPlainObject)(id)) {
|
|
14665
14970
|
const { type = "param", key } = id;
|
|
14666
14971
|
if (type === "param") {
|
|
14667
14972
|
const paramValue = req.params[key];
|
|
14668
|
-
_id = (0,
|
|
14973
|
+
_id = (0, import_utils41.isArray)(paramValue) ? paramValue[0] ?? null : paramValue ?? null;
|
|
14669
14974
|
} else if (type === "query") {
|
|
14670
14975
|
const _qval = req.query[key];
|
|
14671
|
-
if ((0,
|
|
14976
|
+
if ((0, import_utils41.isArray)(_qval)) _id = _qval.length > 0 ? _qval[0] : null;
|
|
14672
14977
|
else _id = _qval;
|
|
14673
14978
|
} else {
|
|
14674
14979
|
_id = null;
|
|
14675
14980
|
}
|
|
14676
14981
|
}
|
|
14677
|
-
if (!(0,
|
|
14982
|
+
if (!(0, import_utils41.isString)(_id) || !_id) {
|
|
14678
14983
|
return next(new import_express_json_router5.default.clientErrors.BadRequestError());
|
|
14679
14984
|
}
|
|
14680
14985
|
const result2 = await svc._read(_id, { select });
|
|
@@ -14686,11 +14991,11 @@ function guard(condition) {
|
|
|
14686
14991
|
cond = _cond;
|
|
14687
14992
|
}
|
|
14688
14993
|
const { stringHandler, arrayHandler } = createValidator(phas);
|
|
14689
|
-
if ((0,
|
|
14994
|
+
if ((0, import_utils41.isString)(cond)) {
|
|
14690
14995
|
if (stringHandler(cond)) return next();
|
|
14691
|
-
} else if ((0,
|
|
14996
|
+
} else if ((0, import_utils41.isArray)(cond)) {
|
|
14692
14997
|
if (arrayHandler(cond)) return next();
|
|
14693
|
-
} else if ((0,
|
|
14998
|
+
} else if ((0, import_utils41.isFunction)(cond)) {
|
|
14694
14999
|
const result2 = await cond.call(req, permissions);
|
|
14695
15000
|
if (!!result2) return next();
|
|
14696
15001
|
}
|
|
@@ -14703,7 +15008,7 @@ var import_express2 = __toESM(require("express"));
|
|
|
14703
15008
|
|
|
14704
15009
|
// src/routers/model-router.ts
|
|
14705
15010
|
var import_express_json_router8 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
14706
|
-
var
|
|
15011
|
+
var import_utils45 = require("@web-ts-toolkit/utils");
|
|
14707
15012
|
init_logger_helpers();
|
|
14708
15013
|
init_runtime();
|
|
14709
15014
|
init_runtime_context();
|
|
@@ -14837,7 +15142,7 @@ init_request_complexity();
|
|
|
14837
15142
|
|
|
14838
15143
|
// src/validation/common.ts
|
|
14839
15144
|
var import_zod2 = require("zod");
|
|
14840
|
-
var
|
|
15145
|
+
var import_utils42 = require("@web-ts-toolkit/utils");
|
|
14841
15146
|
|
|
14842
15147
|
// src/validation/public-admission-schema.ts
|
|
14843
15148
|
init_public_admission();
|
|
@@ -14966,7 +15271,7 @@ var correlatedFilterSchema = import_zod2.z.record(import_zod2.z.string(), import
|
|
|
14966
15271
|
}
|
|
14967
15272
|
});
|
|
14968
15273
|
var correlatedEmptyOptionsSchema = import_zod2.z.unknown().refine(
|
|
14969
|
-
(value) => value === void 0 || (0,
|
|
15274
|
+
(value) => value === void 0 || (0, import_utils42.isPlainObject)(value) && Object.keys(value).length === 0,
|
|
14970
15275
|
"Correlated include options must be absent or empty"
|
|
14971
15276
|
).optional();
|
|
14972
15277
|
var correlatedPathSchema = import_zod2.z.string().min(1).superRefine((path, ctx) => {
|
|
@@ -15003,7 +15308,7 @@ var correlatedListArgsSchema = import_zod2.z.object({
|
|
|
15003
15308
|
include: import_zod2.z.lazy(() => correlatedNestedIncludeSchema).optional()
|
|
15004
15309
|
}).strict().superRefine((args, ctx) => checkArgsMarkers(args.select, args.sort, ctx));
|
|
15005
15310
|
var correlatedCountArgsSchema = import_zod2.z.unknown().refine(
|
|
15006
|
-
(value) => value === void 0 || (0,
|
|
15311
|
+
(value) => value === void 0 || (0, import_utils42.isPlainObject)(value) && Object.keys(value).length === 0,
|
|
15007
15312
|
"Count includes accept no args"
|
|
15008
15313
|
).optional();
|
|
15009
15314
|
var correlatedReadByIdSchema = import_zod2.z.object({
|
|
@@ -15056,7 +15361,7 @@ var correlatedNestedIncludeSchema = import_zod2.z.union([includeItemSchema, impo
|
|
|
15056
15361
|
var rejectDuplicateCorrelatedPaths = (items, ctx) => {
|
|
15057
15362
|
const seen = /* @__PURE__ */ new Set();
|
|
15058
15363
|
items.forEach((item, index) => {
|
|
15059
|
-
if ((0,
|
|
15364
|
+
if ((0, import_utils42.isPlainObject)(item) && item.mode === "correlated" && typeof item.path === "string") {
|
|
15060
15365
|
if (seen.has(item.path)) {
|
|
15061
15366
|
ctx.addIssue({
|
|
15062
15367
|
code: import_zod2.z.ZodIssueCode.custom,
|
|
@@ -16029,7 +16334,7 @@ var rootQuerySchema = publicBoundarySchema(
|
|
|
16029
16334
|
init_helpers();
|
|
16030
16335
|
|
|
16031
16336
|
// src/routers/shared.ts
|
|
16032
|
-
var
|
|
16337
|
+
var import_utils43 = require("@web-ts-toolkit/utils");
|
|
16033
16338
|
|
|
16034
16339
|
// src/routers/model-router-collection-routes.ts
|
|
16035
16340
|
init_schemas();
|
|
@@ -16060,15 +16365,15 @@ function setModelCollectionRoutes(context) {
|
|
|
16060
16365
|
sort
|
|
16061
16366
|
} = parseQuery(requestSchemas.listQuery, req.query);
|
|
16062
16367
|
const svc = context.getPublicService(req);
|
|
16063
|
-
const includeCount = (0,
|
|
16064
|
-
const includeExtraHeaders = (0,
|
|
16368
|
+
const includeCount = (0, import_utils43.parseBooleanString)(include_count);
|
|
16369
|
+
const includeExtraHeaders = (0, import_utils43.parseBooleanString)(include_extra_headers);
|
|
16065
16370
|
const result2 = await svc._list(
|
|
16066
16371
|
{},
|
|
16067
16372
|
{ select: parseSelectParam(select), sort, skip, limit, page, pageSize: page_size },
|
|
16068
16373
|
{
|
|
16069
|
-
skim: (0,
|
|
16070
|
-
includePermissions: (0,
|
|
16071
|
-
includeFieldPermissions: (0,
|
|
16374
|
+
skim: (0, import_utils43.parseBooleanString)(skim),
|
|
16375
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16376
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16072
16377
|
includeCount
|
|
16073
16378
|
}
|
|
16074
16379
|
);
|
|
@@ -16128,8 +16433,8 @@ function setModelCollectionRoutes(context) {
|
|
|
16128
16433
|
data,
|
|
16129
16434
|
{},
|
|
16130
16435
|
{
|
|
16131
|
-
includePermissions: (0,
|
|
16132
|
-
includeFieldPermissions: (0,
|
|
16436
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16437
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16133
16438
|
}
|
|
16134
16439
|
);
|
|
16135
16440
|
handleResultError(result2);
|
|
@@ -16167,8 +16472,8 @@ function setModelCollectionRoutes(context) {
|
|
|
16167
16472
|
finalData,
|
|
16168
16473
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16169
16474
|
{
|
|
16170
|
-
includePermissions: includePermissions ?? (0,
|
|
16171
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16475
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16476
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16172
16477
|
populateAccess
|
|
16173
16478
|
}
|
|
16174
16479
|
);
|
|
@@ -16265,9 +16570,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16265
16570
|
id,
|
|
16266
16571
|
{ select: parseSelectParam(select) },
|
|
16267
16572
|
{
|
|
16268
|
-
includePermissions: (0,
|
|
16269
|
-
includeFieldPermissions: (0,
|
|
16270
|
-
tryList: (0,
|
|
16573
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16574
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16575
|
+
tryList: (0, import_utils43.parseBooleanString)(try_list)
|
|
16271
16576
|
}
|
|
16272
16577
|
);
|
|
16273
16578
|
handleResultError(result2);
|
|
@@ -16367,9 +16672,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16367
16672
|
data,
|
|
16368
16673
|
{ select: parseSelectParam(select) },
|
|
16369
16674
|
{
|
|
16370
|
-
returningAll: (0,
|
|
16371
|
-
includePermissions: (0,
|
|
16372
|
-
includeFieldPermissions: (0,
|
|
16675
|
+
returningAll: (0, import_utils43.parseBooleanString)(returning_all),
|
|
16676
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16677
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16373
16678
|
}
|
|
16374
16679
|
);
|
|
16375
16680
|
handleResultError(result2);
|
|
@@ -16418,9 +16723,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16418
16723
|
finalData,
|
|
16419
16724
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16420
16725
|
{
|
|
16421
|
-
returningAll: returningAll ?? (0,
|
|
16422
|
-
includePermissions: includePermissions ?? (0,
|
|
16423
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16726
|
+
returningAll: returningAll ?? (0, import_utils43.parseBooleanString)(returning_all),
|
|
16727
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16728
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16424
16729
|
populateAccess
|
|
16425
16730
|
}
|
|
16426
16731
|
);
|
|
@@ -16451,9 +16756,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16451
16756
|
body,
|
|
16452
16757
|
{},
|
|
16453
16758
|
{
|
|
16454
|
-
returningAll: (0,
|
|
16455
|
-
includePermissions: (0,
|
|
16456
|
-
includeFieldPermissions: (0,
|
|
16759
|
+
returningAll: (0, import_utils43.parseBooleanString)(returning_all),
|
|
16760
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16761
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16457
16762
|
}
|
|
16458
16763
|
);
|
|
16459
16764
|
handleResultError(result2);
|
|
@@ -16500,9 +16805,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16500
16805
|
finalData,
|
|
16501
16806
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16502
16807
|
{
|
|
16503
|
-
returningAll: returningAll ?? (0,
|
|
16504
|
-
includePermissions: includePermissions ?? (0,
|
|
16505
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16808
|
+
returningAll: returningAll ?? (0, import_utils43.parseBooleanString)(returning_all),
|
|
16809
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16810
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16506
16811
|
populateAccess
|
|
16507
16812
|
}
|
|
16508
16813
|
);
|
|
@@ -16742,11 +17047,11 @@ function setModelSubDocumentRoutes(context) {
|
|
|
16742
17047
|
}
|
|
16743
17048
|
|
|
16744
17049
|
// src/openapi/route-registration.ts
|
|
16745
|
-
var
|
|
17050
|
+
var import_utils44 = require("@web-ts-toolkit/utils");
|
|
16746
17051
|
function registerOpenApiRoute(runtime, basePath, defaultTag, route) {
|
|
16747
17052
|
runtime.registerOpenApiRoute({
|
|
16748
17053
|
...route,
|
|
16749
|
-
path: (0,
|
|
17054
|
+
path: (0, import_utils44.normalizeUrlPath)(basePath + route.path),
|
|
16750
17055
|
tags: route.tags ?? [defaultTag]
|
|
16751
17056
|
});
|
|
16752
17057
|
}
|
|
@@ -16754,8 +17059,8 @@ function registerOpenApiRoute(runtime, basePath, defaultTag, route) {
|
|
|
16754
17059
|
// src/routers/model-router.ts
|
|
16755
17060
|
var clientErrors2 = import_express_json_router8.default.clientErrors;
|
|
16756
17061
|
function setOption(parentKey, optionKey, option) {
|
|
16757
|
-
const key = (0,
|
|
16758
|
-
const value = (0,
|
|
17062
|
+
const key = (0, import_utils45.isUndefined)(option) ? parentKey : `${parentKey}.${optionKey}`;
|
|
17063
|
+
const value = (0, import_utils45.isUndefined)(option) ? optionKey : option;
|
|
16759
17064
|
assertMutableRouterOption("model", key);
|
|
16760
17065
|
this.runtime.setModelOption(
|
|
16761
17066
|
this.modelName,
|
|
@@ -16957,7 +17262,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
16957
17262
|
this.runtime = runtime;
|
|
16958
17263
|
this.runtime.setModelOptions(modelName, initialOptions);
|
|
16959
17264
|
this.options = this.runtime.getModelOptions(modelName);
|
|
16960
|
-
this.fullBasePath = (0,
|
|
17265
|
+
this.fullBasePath = (0, import_utils45.normalizeUrlPath)(this.options.parentPath + this.options.basePath);
|
|
16961
17266
|
this.modelName = modelName;
|
|
16962
17267
|
this.router = new import_express_json_router8.default(this.options.basePath, createSetCore(this.runtime), accessRouterResponseHandler);
|
|
16963
17268
|
this.model = new model_default(modelName, this.runtime);
|
|
@@ -17043,13 +17348,13 @@ var ModelRouter = class _ModelRouter {
|
|
|
17043
17348
|
}
|
|
17044
17349
|
logEndpoints() {
|
|
17045
17350
|
runWithRuntime(this.runtime, () => {
|
|
17046
|
-
(0,
|
|
17047
|
-
logInfoMessage(`${(0,
|
|
17351
|
+
(0, import_utils45.forEach)(this.router.getEndpoints(), ({ method, path }) => {
|
|
17352
|
+
logInfoMessage(`${(0, import_utils45.padEnd)(method, 6)} ${(0, import_utils45.normalizeUrlPath)(this.options.parentPath + path)}`);
|
|
17048
17353
|
});
|
|
17049
17354
|
});
|
|
17050
17355
|
}
|
|
17051
17356
|
set(keyOrOptions, value) {
|
|
17052
|
-
if (arguments.length === 2 && (0,
|
|
17357
|
+
if (arguments.length === 2 && (0, import_utils45.isString)(keyOrOptions)) {
|
|
17053
17358
|
assertMutableRouterOption("model", keyOrOptions);
|
|
17054
17359
|
this.runtime.setModelOption(
|
|
17055
17360
|
this.modelName,
|
|
@@ -17057,7 +17362,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
17057
17362
|
value
|
|
17058
17363
|
);
|
|
17059
17364
|
}
|
|
17060
|
-
if (arguments.length === 1 && (0,
|
|
17365
|
+
if (arguments.length === 1 && (0, import_utils45.isPlainObject)(keyOrOptions)) {
|
|
17061
17366
|
assertMutableRouterOptions("model", keyOrOptions);
|
|
17062
17367
|
this.runtime.setModelOptions(
|
|
17063
17368
|
this.modelName,
|
|
@@ -17085,7 +17390,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
17085
17390
|
|
|
17086
17391
|
// src/routers/root-router.ts
|
|
17087
17392
|
var import_express_json_router9 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
17088
|
-
var
|
|
17393
|
+
var import_utils46 = require("@web-ts-toolkit/utils");
|
|
17089
17394
|
|
|
17090
17395
|
// src/core-data.ts
|
|
17091
17396
|
init_options();
|
|
@@ -17393,7 +17698,7 @@ var RootRouter = class {
|
|
|
17393
17698
|
this.setRoutes();
|
|
17394
17699
|
}
|
|
17395
17700
|
registerOpenApiRoute(route) {
|
|
17396
|
-
registerOpenApiRoute(this.runtime, (0,
|
|
17701
|
+
registerOpenApiRoute(this.runtime, (0, import_utils46.normalizeUrlPath)(this.basename), "root", route);
|
|
17397
17702
|
}
|
|
17398
17703
|
wrapResult(index, item, result2) {
|
|
17399
17704
|
return {
|
|
@@ -17502,7 +17807,7 @@ var RootRouter = class {
|
|
|
17502
17807
|
groupItemsByOrder(items) {
|
|
17503
17808
|
const groups = /* @__PURE__ */ new Map();
|
|
17504
17809
|
items.forEach((item, index) => {
|
|
17505
|
-
const order = (0,
|
|
17810
|
+
const order = (0, import_utils46.isNumber)(item.order) ? item.order : 0;
|
|
17506
17811
|
const group = groups.get(order);
|
|
17507
17812
|
if (group) {
|
|
17508
17813
|
group.push({ index, item });
|
|
@@ -17573,7 +17878,7 @@ var RootRouter = class {
|
|
|
17573
17878
|
const arrResult = await this.runGroup(req, groupedItems[x]);
|
|
17574
17879
|
results.push(...arrResult);
|
|
17575
17880
|
}
|
|
17576
|
-
return (0,
|
|
17881
|
+
return (0, import_utils46.orderBy)(results, ["index"], ["asc"]);
|
|
17577
17882
|
});
|
|
17578
17883
|
this.registerOpenApiRoute({
|
|
17579
17884
|
method: "post",
|
|
@@ -17591,14 +17896,14 @@ var RootRouter = class {
|
|
|
17591
17896
|
|
|
17592
17897
|
// src/routers/data-router.ts
|
|
17593
17898
|
var import_express_json_router10 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
17594
|
-
var
|
|
17899
|
+
var import_utils47 = require("@web-ts-toolkit/utils");
|
|
17595
17900
|
init_runtime();
|
|
17596
17901
|
init_helpers();
|
|
17597
17902
|
init_schemas();
|
|
17598
17903
|
var clientErrors4 = import_express_json_router10.default.clientErrors;
|
|
17599
17904
|
function setOption2(parentKey, optionKey, option) {
|
|
17600
|
-
const key = (0,
|
|
17601
|
-
const value = (0,
|
|
17905
|
+
const key = (0, import_utils47.isUndefined)(option) ? parentKey : `${parentKey}.${optionKey}`;
|
|
17906
|
+
const value = (0, import_utils47.isUndefined)(option) ? optionKey : option;
|
|
17602
17907
|
assertMutableRouterOption("data", key);
|
|
17603
17908
|
this.runtime.setDataOption(this.dataName, key, value);
|
|
17604
17909
|
return this;
|
|
@@ -17647,7 +17952,7 @@ var DataRouter = class {
|
|
|
17647
17952
|
this.runtime = runtime;
|
|
17648
17953
|
this.runtime.setDataOptions(dataName, initialOptions);
|
|
17649
17954
|
this.options = this.runtime.getDataOptions(dataName);
|
|
17650
|
-
this.fullBasePath = (0,
|
|
17955
|
+
this.fullBasePath = (0, import_utils47.normalizeUrlPath)(this.options.parentPath + this.options.basePath);
|
|
17651
17956
|
this.dataName = dataName;
|
|
17652
17957
|
this.router = new import_express_json_router10.default(this.options.basePath, createSetDataCore(this.runtime), accessRouterResponseHandler);
|
|
17653
17958
|
this.setCollectionRoutes();
|
|
@@ -17680,8 +17985,8 @@ var DataRouter = class {
|
|
|
17680
17985
|
req.query
|
|
17681
17986
|
);
|
|
17682
17987
|
const svc = this.getService(req);
|
|
17683
|
-
const includeCount = (0,
|
|
17684
|
-
const includeExtraHeaders = (0,
|
|
17988
|
+
const includeCount = (0, import_utils43.parseBooleanString)(include_count);
|
|
17989
|
+
const includeExtraHeaders = (0, import_utils43.parseBooleanString)(include_extra_headers);
|
|
17685
17990
|
const result2 = await svc.find(
|
|
17686
17991
|
{},
|
|
17687
17992
|
{ select: parseSelectParam(select), sort, skip, limit, page, pageSize: page_size },
|
|
@@ -17799,7 +18104,7 @@ var DataRouter = class {
|
|
|
17799
18104
|
});
|
|
17800
18105
|
}
|
|
17801
18106
|
set(keyOrOptions, value) {
|
|
17802
|
-
if (arguments.length === 2 && (0,
|
|
18107
|
+
if (arguments.length === 2 && (0, import_utils47.isString)(keyOrOptions)) {
|
|
17803
18108
|
assertMutableRouterOption("data", keyOrOptions);
|
|
17804
18109
|
this.runtime.setDataOption(
|
|
17805
18110
|
this.dataName,
|
|
@@ -17807,7 +18112,7 @@ var DataRouter = class {
|
|
|
17807
18112
|
value
|
|
17808
18113
|
);
|
|
17809
18114
|
}
|
|
17810
|
-
if (arguments.length === 1 && (0,
|
|
18115
|
+
if (arguments.length === 1 && (0, import_utils47.isPlainObject)(keyOrOptions)) {
|
|
17811
18116
|
assertMutableRouterOptions("data", keyOrOptions);
|
|
17812
18117
|
this.runtime.setDataOptions(this.dataName, keyOrOptions);
|
|
17813
18118
|
}
|
|
@@ -17942,7 +18247,7 @@ function createRuntimeApi(runtime) {
|
|
|
17942
18247
|
const wtt2 = runtimeMiddleware;
|
|
17943
18248
|
wtt2.runtime = runtime;
|
|
17944
18249
|
wtt2.createRouter = function(modelName, options) {
|
|
17945
|
-
if ((0,
|
|
18250
|
+
if ((0, import_utils48.isUndefined)(options)) {
|
|
17946
18251
|
return new RootRouter(modelName, runtime);
|
|
17947
18252
|
}
|
|
17948
18253
|
if (typeof modelName === "string") {
|
|
@@ -17963,10 +18268,10 @@ function createRuntimeApi(runtime) {
|
|
|
17963
18268
|
};
|
|
17964
18269
|
wtt2.combineRoutes = combineRoutes;
|
|
17965
18270
|
wtt2.set = function(keyOrOptions, value) {
|
|
17966
|
-
if (arguments.length === 2 && (0,
|
|
18271
|
+
if (arguments.length === 2 && (0, import_utils48.isString)(keyOrOptions)) {
|
|
17967
18272
|
return runtime.setGlobalOption(keyOrOptions, value);
|
|
17968
18273
|
}
|
|
17969
|
-
if (arguments.length === 1 && (0,
|
|
18274
|
+
if (arguments.length === 1 && (0, import_utils48.isPlainObject)(keyOrOptions)) {
|
|
17970
18275
|
return runtime.setGlobalOptions(keyOrOptions);
|
|
17971
18276
|
}
|
|
17972
18277
|
};
|