@web-ts-toolkit/access-router 0.58.0 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -0
- package/advanced.d.mts +1 -1
- package/advanced.d.ts +1 -1
- package/advanced.js +19 -3
- package/advanced.mjs +19 -3
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.js +1200 -856
- package/index.mjs +1077 -734
- package/package.json +3 -3
- package/{parsers-CngKnVjW.d.mts → parsers-bP4gXehf.d.mts} +38 -0
- package/{parsers-CngKnVjW.d.ts → parsers-bP4gXehf.d.ts} +38 -0
package/index.js
CHANGED
|
@@ -48,7 +48,7 @@ function assertPublicAdmission(input, kind = "envelope") {
|
|
|
48
48
|
for (const key of privateControls) {
|
|
49
49
|
if (key in record3) {
|
|
50
50
|
throw new PublicAdmissionError(
|
|
51
|
-
`Unsupported public control ${path}.${key}; use explicit per-call internal service options for backend authorization`
|
|
51
|
+
key === "unsafeSkipListDocumentSnapshotChecks" || key === "unsafeSkipReadDocumentSnapshotChecks" ? `Unsupported public control ${path}.${key}; this unsafe flag is server model configuration only` : `Unsupported public control ${path}.${key}; use explicit per-call internal service options for backend authorization`
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -149,6 +149,8 @@ var init_public_admission = __esm({
|
|
|
149
149
|
"skipParsing",
|
|
150
150
|
"skipAuthorization",
|
|
151
151
|
"alreadyAuthorized",
|
|
152
|
+
"unsafeSkipListDocumentSnapshotChecks",
|
|
153
|
+
"unsafeSkipReadDocumentSnapshotChecks",
|
|
152
154
|
"operation"
|
|
153
155
|
];
|
|
154
156
|
PublicAdmissionError = class extends import_express_json_router.default.clientErrors.BadRequestError {
|
|
@@ -2842,7 +2844,9 @@ var init_runtime = __esm({
|
|
|
2842
2844
|
queryRouteSegment: "__query",
|
|
2843
2845
|
mutationRouteSegment: "__mutation",
|
|
2844
2846
|
operationAccess: false,
|
|
2845
|
-
modelPermissionPrefix: ""
|
|
2847
|
+
modelPermissionPrefix: "",
|
|
2848
|
+
unsafeSkipListDocumentSnapshotChecks: false,
|
|
2849
|
+
unsafeSkipReadDocumentSnapshotChecks: false
|
|
2846
2850
|
}).build();
|
|
2847
2851
|
this.modelOptions = {};
|
|
2848
2852
|
this.modelJsonSchemas = {};
|
|
@@ -3060,11 +3064,23 @@ var init_runtime = __esm({
|
|
|
3060
3064
|
...defaultModelOptions,
|
|
3061
3065
|
modelName
|
|
3062
3066
|
});
|
|
3067
|
+
const snapshotFlagChanged = (newValue, key, target, oldValue) => {
|
|
3068
|
+
target[key] = newValue === true;
|
|
3069
|
+
if (newValue !== true || oldValue === true) return;
|
|
3070
|
+
const operation = key === "unsafeSkipReadDocumentSnapshotChecks" ? "read" : "list";
|
|
3071
|
+
try {
|
|
3072
|
+
this.getGlobalOption("logger")?.warn?.(
|
|
3073
|
+
`UNSAFE: ${operation} document snapshot checks disabled; source mutation can leave stale authorization decisions. Restore ${key}=false after the temporary workaround.`,
|
|
3074
|
+
{ modelName }
|
|
3075
|
+
);
|
|
3076
|
+
} catch {
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3063
3079
|
manager.onchange("permissionSchema", function(_newval, _key, target) {
|
|
3064
3080
|
refreshPermissionMetadata(target);
|
|
3065
3081
|
}).onchange("modelPermissionPrefix", function(_newval, _key, target) {
|
|
3066
3082
|
refreshPermissionMetadata(target);
|
|
3067
|
-
}).onchange("basePath", function(newval, key, target) {
|
|
3083
|
+
}).onchange("unsafeSkipListDocumentSnapshotChecks", snapshotFlagChanged).onchange("unsafeSkipReadDocumentSnapshotChecks", snapshotFlagChanged).onchange("basePath", function(newval, key, target) {
|
|
3068
3084
|
target[key] = normalizeBasePath(
|
|
3069
3085
|
modelName,
|
|
3070
3086
|
(0, import_utils17.isString)(newval) || (0, import_utils17.isNil)(newval) ? newval : void 0
|
|
@@ -3733,6 +3749,9 @@ function resolveServiceAuthorization(input) {
|
|
|
3733
3749
|
);
|
|
3734
3750
|
for (const value of Object.values(permissions)) if (value && typeof value === "object") Object.freeze(value);
|
|
3735
3751
|
Object.freeze(permissions);
|
|
3752
|
+
const readAccess = outputAccess.rowAccess;
|
|
3753
|
+
const readResponse = input.readResponse === true && (input.applicability ?? "service") === "service" && scopePath.length === 0 && outputAccess.operation === "read" && (readAccess === "read" || readAccess === "list") && outputAccess.outputAccess === readAccess && outputAccess.virtualAccess === readAccess && outputAccess.docPermissionsAccess === readAccess && (input.parent === void 0 || callRecord(input.parent).readResponse);
|
|
3754
|
+
if (readResponse && input.parent) assertAuthorizationBinding(input.parent, input.binding);
|
|
3736
3755
|
const call = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
3737
3756
|
calls.set(call, {
|
|
3738
3757
|
binding: Object.freeze({ ...input.binding, scopePath: Object.freeze(scopePath) }),
|
|
@@ -3743,7 +3762,9 @@ function resolveServiceAuthorization(input) {
|
|
|
3743
3762
|
// normalizeFields constructs only mode strings and validated string paths.
|
|
3744
3763
|
output: Object.freeze({ access: outputAccess, catalog, outputFields: policy.outputFields }),
|
|
3745
3764
|
permissions,
|
|
3746
|
-
provenance: input.parent ? callRecord(input.parent).provenance : call
|
|
3765
|
+
provenance: input.parent ? callRecord(input.parent).provenance : call,
|
|
3766
|
+
readResponse,
|
|
3767
|
+
validateDocumentSnapshots: !(input.listResponse === true && input.parent === void 0 && (input.applicability ?? "service") === "service" && outputAccess.operation === "list" && outputAccess.rowAccess === "list" && outputAccess.outputAccess === "list" && scopePath.length === 0 && configuration.unsafeSkipListDocumentSnapshotChecks === true || readResponse && configuration.unsafeSkipReadDocumentSnapshotChecks === true)
|
|
3747
3768
|
});
|
|
3748
3769
|
return call;
|
|
3749
3770
|
}
|
|
@@ -3764,6 +3785,10 @@ function readServiceAuthorizationAccess(call, binding) {
|
|
|
3764
3785
|
assertAuthorizationBinding(call, binding);
|
|
3765
3786
|
return callRecord(call).output.access;
|
|
3766
3787
|
}
|
|
3788
|
+
function requiresDocumentSnapshotChecks(call, binding) {
|
|
3789
|
+
assertAuthorizationBinding(call, binding);
|
|
3790
|
+
return callRecord(call).validateDocumentSnapshots;
|
|
3791
|
+
}
|
|
3767
3792
|
function readServiceAuthorizationHydration(call, binding) {
|
|
3768
3793
|
assertAuthorizationBinding(call, binding);
|
|
3769
3794
|
return copyAuthorizationValue({ hydration: callRecord(call).configuration.hydration }, true);
|
|
@@ -3810,11 +3835,10 @@ function readServiceOutputPolicy(call, binding) {
|
|
|
3810
3835
|
function readServiceOutputFieldAuthorization(call, binding) {
|
|
3811
3836
|
assertAuthorizationBinding(call, binding);
|
|
3812
3837
|
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");
|
|
3838
|
+
const reusable = reusableOutputFieldConfiguration(record3);
|
|
3816
3839
|
return Object.freeze({
|
|
3817
3840
|
access: record3.output.access,
|
|
3841
|
+
catalog: record3.output.catalog,
|
|
3818
3842
|
outputFields: record3.output.outputFields,
|
|
3819
3843
|
reusable,
|
|
3820
3844
|
...copyAuthorizationValue(
|
|
@@ -3826,6 +3850,16 @@ function readServiceOutputFieldAuthorization(call, binding) {
|
|
|
3826
3850
|
)
|
|
3827
3851
|
});
|
|
3828
3852
|
}
|
|
3853
|
+
function reusableOutputFieldConfiguration(record3) {
|
|
3854
|
+
return record3.reusableFieldConfiguration ??= hasStableConfigurationCopies(record3.configuration.permissionSchema) && // Coercion methods can observe an object's identity even without native
|
|
3855
|
+
// leaves. Keep those receivers local to the original resolution boundary.
|
|
3856
|
+
(record3.configuration.modelPermissionPrefix === null || typeof record3.configuration.modelPermissionPrefix !== "object");
|
|
3857
|
+
}
|
|
3858
|
+
function canPrepareStaticOutputPolicy(call, binding) {
|
|
3859
|
+
assertAuthorizationBinding(call, binding);
|
|
3860
|
+
const record3 = callRecord(call);
|
|
3861
|
+
return reusableOutputFieldConfiguration(record3) && typeof (record3.configuration.modelPermissionPrefix ?? "") === "string";
|
|
3862
|
+
}
|
|
3829
3863
|
function getAuthorizationPermissions(call, binding) {
|
|
3830
3864
|
assertAuthorizationBinding(call, binding);
|
|
3831
3865
|
return callRecord(call).permissions;
|
|
@@ -3844,430 +3878,93 @@ var init_service_authorization = __esm({
|
|
|
3844
3878
|
}
|
|
3845
3879
|
});
|
|
3846
3880
|
|
|
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
|
-
});
|
|
3881
|
+
// src/acl/field-authorization.ts
|
|
3882
|
+
function extractScopedOutputRule(schema, field, access) {
|
|
3883
|
+
if (!schema || !Object.prototype.hasOwnProperty.call(schema, field)) return void 0;
|
|
3884
|
+
const raw = schema[field];
|
|
3885
|
+
return raw && typeof raw === "object" && !Array.isArray(raw) && Object.prototype.hasOwnProperty.call(raw, access) ? raw[access] : raw;
|
|
3888
3886
|
}
|
|
3889
|
-
function
|
|
3890
|
-
|
|
3891
|
-
if (!record3) authorizationError("invalid document stage");
|
|
3892
|
-
if (!matchesAuthorizationSnapshot(record3.input, record3.snapshot)) authorizationError("changed document snapshot");
|
|
3893
|
-
return record3;
|
|
3887
|
+
function extractOutputFieldRules(schema, path, access) {
|
|
3888
|
+
return extractOutputFieldRuleEntries(schema, path, access).map((entry) => entry.rule);
|
|
3894
3889
|
}
|
|
3895
|
-
function
|
|
3896
|
-
|
|
3897
|
-
if (
|
|
3898
|
-
|
|
3899
|
-
|
|
3890
|
+
function extractOutputFieldRuleEntries(schema, path, access, prefix = "") {
|
|
3891
|
+
if (!schema) return [{ path: `${prefix}${path}`, rule: void 0 }];
|
|
3892
|
+
if (Object.prototype.hasOwnProperty.call(schema, path))
|
|
3893
|
+
return [{ path: `${prefix}${path}`, rule: extractScopedOutputRule(schema, path, access) }];
|
|
3894
|
+
const [head, ...rest] = path.split(".");
|
|
3895
|
+
const rule = extractScopedOutputRule(schema, head, access);
|
|
3896
|
+
const raw = schema[head];
|
|
3897
|
+
const entry = { path: `${prefix}${head}`, rule };
|
|
3898
|
+
if (!rest.length || !raw?.sub) return [entry];
|
|
3899
|
+
return [entry, ...extractOutputFieldRuleEntries(raw.sub, rest.join("."), access, `${prefix}${head}.`)];
|
|
3900
3900
|
}
|
|
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;
|
|
3901
|
+
function hasExplicitFieldGrant(policy, path) {
|
|
3902
|
+
return policy?.mode === "unrestricted" || policy?.mode === "grant" && policy.paths.some((grant) => path === grant || path.startsWith(`${grant}.`));
|
|
3912
3903
|
}
|
|
3913
|
-
function
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3904
|
+
function classifyRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
3905
|
+
if (typeof rule === "boolean") return rule ? "granted" : "denied";
|
|
3906
|
+
if (typeof rule === "function") return "deferred";
|
|
3907
|
+
const validator = createValidator((key) => permissions.has(key));
|
|
3908
|
+
if (typeof rule !== "string" && !Array.isArray(rule)) return "denied";
|
|
3909
|
+
if (typeof rule === "string" ? validator.stringHandler(rule) : validator.arrayHandler(rule)) return "granted";
|
|
3910
|
+
const possible = createValidator(
|
|
3911
|
+
(key) => permissions.has(key) || !modelPermissionPrefix || key.startsWith(modelPermissionPrefix)
|
|
3912
|
+
);
|
|
3913
|
+
return (typeof rule === "string" ? possible.stringHandler(rule) : possible.arrayHandler(rule)) ? "deferred" : "denied";
|
|
3919
3914
|
}
|
|
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;
|
|
3915
|
+
function prepareRequestFieldRule(rule, permissions, modelPermissionPrefix = "") {
|
|
3916
|
+
const state = classifyRequestFieldRule(rule, permissions, modelPermissionPrefix);
|
|
3917
|
+
const invariant = state === "denied" && modelPermissionPrefix ? classifyRequestFieldRule(rule, permissions) : state;
|
|
3918
|
+
return Object.freeze({ state, decision: invariant === "deferred" ? void 0 : invariant === "granted" });
|
|
3939
3919
|
}
|
|
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
|
-
});
|
|
3920
|
+
function combineFieldAuthorizationStates(states2) {
|
|
3921
|
+
return states2.includes("denied") ? "denied" : states2.includes("deferred") ? "deferred" : "granted";
|
|
3950
3922
|
}
|
|
3951
|
-
function
|
|
3952
|
-
|
|
3953
|
-
const
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
...readServiceAuthorizationAccess(stage.call, binding)
|
|
3958
|
-
});
|
|
3923
|
+
function classifyEffectiveFieldAuthorization(args) {
|
|
3924
|
+
if (hasExplicitFieldGrant(args.outputFields, args.path)) return "granted";
|
|
3925
|
+
const states2 = args.rules.map(
|
|
3926
|
+
(rule) => classifyRequestFieldRule(rule, args.globalPermissions, args.modelPermissionPrefix)
|
|
3927
|
+
);
|
|
3928
|
+
return combineFieldAuthorizationStates(states2);
|
|
3959
3929
|
}
|
|
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);
|
|
3930
|
+
async function evaluateScopedAccessRule(args) {
|
|
3931
|
+
const { req, rule, globalPermissions, docPermissions, modelPermissionPrefix } = args;
|
|
3932
|
+
if (typeof rule === "boolean") return rule;
|
|
3933
|
+
const validator = createValidator((key) => {
|
|
3934
|
+
try {
|
|
3935
|
+
if (globalPermissions?.has(key)) return true;
|
|
3936
|
+
} catch {
|
|
3937
|
+
}
|
|
3938
|
+
try {
|
|
3939
|
+
return Boolean((docPermissions ?? {})[stripModelPermissionPrefix(key, modelPermissionPrefix)]);
|
|
3940
|
+
} catch {
|
|
3941
|
+
return false;
|
|
3942
|
+
}
|
|
3943
|
+
});
|
|
3944
|
+
if (typeof rule === "string") return validator.stringHandler(rule);
|
|
3945
|
+
if (Array.isArray(rule)) return validator.arrayHandler(rule);
|
|
3946
|
+
if (typeof rule === "function") {
|
|
3947
|
+
try {
|
|
3948
|
+
return Boolean(await rule.call(req, globalPermissions, docPermissions));
|
|
3949
|
+
} catch {
|
|
3950
|
+
return false;
|
|
3951
|
+
}
|
|
3986
3952
|
}
|
|
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]);
|
|
3953
|
+
return false;
|
|
3993
3954
|
}
|
|
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");
|
|
3955
|
+
async function evaluateEffectiveFieldAuthorization(args) {
|
|
3956
|
+
if (hasExplicitFieldGrant(args.outputFields, args.path)) return true;
|
|
3957
|
+
for (const [index, rule] of args.rules.entries()) {
|
|
3958
|
+
if (!await (args.evaluateRule ? args.evaluateRule(rule, index) : evaluateScopedAccessRule({ ...args, rule })))
|
|
3959
|
+
return false;
|
|
4004
3960
|
}
|
|
3961
|
+
return true;
|
|
4005
3962
|
}
|
|
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;
|
|
3963
|
+
var stripModelPermissionPrefix;
|
|
3964
|
+
var init_field_authorization = __esm({
|
|
3965
|
+
"src/acl/field-authorization.ts"() {
|
|
3966
|
+
init_helpers();
|
|
3967
|
+
stripModelPermissionPrefix = (key, prefix) => prefix && key.startsWith(prefix) ? key.slice(prefix.length) : key;
|
|
4271
3968
|
}
|
|
4272
3969
|
});
|
|
4273
3970
|
|
|
@@ -4495,10 +4192,10 @@ function planVirtualProjection(args) {
|
|
|
4495
4192
|
relatedPlans
|
|
4496
4193
|
};
|
|
4497
4194
|
}
|
|
4498
|
-
var
|
|
4195
|
+
var import_utils19, getScopedPermissionSchema, resolveAlwaysSelectForAccess, stripVirtualsFromNormalizedSelect, snapshotVirtualPaths, stripLeadingDash, dbPrefixForScope, toDbPath;
|
|
4499
4196
|
var init_virtual_projection = __esm({
|
|
4500
4197
|
"src/acl/virtual-projection.ts"() {
|
|
4501
|
-
|
|
4198
|
+
import_utils19 = require("@web-ts-toolkit/utils");
|
|
4502
4199
|
init_query();
|
|
4503
4200
|
init_field_authorization();
|
|
4504
4201
|
init_output_projection();
|
|
@@ -4506,20 +4203,20 @@ var init_virtual_projection = __esm({
|
|
|
4506
4203
|
init_virtual_populate_dependencies();
|
|
4507
4204
|
init_virtual_descriptor();
|
|
4508
4205
|
getScopedPermissionSchema = (root, scopePath) => {
|
|
4509
|
-
if (!root || !(0,
|
|
4206
|
+
if (!root || !(0, import_utils19.isPlainObject)(root)) return null;
|
|
4510
4207
|
if (scopePath.length === 0) return root;
|
|
4511
|
-
const scoped = (0,
|
|
4512
|
-
return (0,
|
|
4208
|
+
const scoped = (0, import_utils19.get)(root, scopePath.join("."));
|
|
4209
|
+
return (0, import_utils19.isPlainObject)(scoped) ? scoped : null;
|
|
4513
4210
|
};
|
|
4514
4211
|
resolveAlwaysSelectForAccess = (raw, access) => {
|
|
4515
4212
|
if (!raw) return [];
|
|
4516
|
-
if ((0,
|
|
4517
|
-
if ((0,
|
|
4213
|
+
if ((0, import_utils19.isArray)(raw)) return [...raw];
|
|
4214
|
+
if ((0, import_utils19.isPlainObject)(raw)) {
|
|
4518
4215
|
const record3 = raw;
|
|
4519
4216
|
const exact = record3[access];
|
|
4520
|
-
if ((0,
|
|
4217
|
+
if ((0, import_utils19.isArray)(exact)) return [...exact];
|
|
4521
4218
|
const def = record3.default;
|
|
4522
|
-
if ((0,
|
|
4219
|
+
if ((0, import_utils19.isArray)(def)) return [...def];
|
|
4523
4220
|
return [];
|
|
4524
4221
|
}
|
|
4525
4222
|
return [];
|
|
@@ -4544,6 +4241,34 @@ var init_virtual_projection = __esm({
|
|
|
4544
4241
|
});
|
|
4545
4242
|
|
|
4546
4243
|
// src/acl/output-projection.ts
|
|
4244
|
+
function copyOutputDecisionFields(value) {
|
|
4245
|
+
if (!Array.isArray(value) || import_node_util4.types.isProxy(value) || Object.getPrototypeOf(value) !== Array.prototype) return;
|
|
4246
|
+
const length = Object.getOwnPropertyDescriptor(value, "length").value;
|
|
4247
|
+
if (length > 2e4) return;
|
|
4248
|
+
const fields = [];
|
|
4249
|
+
for (let index = 0; index < length; index++) {
|
|
4250
|
+
const slot = Object.getOwnPropertyDescriptor(value, String(index));
|
|
4251
|
+
if (!slot || !("value" in slot) || typeof slot.value !== "string") return;
|
|
4252
|
+
fields.push(slot.value);
|
|
4253
|
+
}
|
|
4254
|
+
return Object.freeze(fields);
|
|
4255
|
+
}
|
|
4256
|
+
function readStaticOutputPlanFields(plan, authorization) {
|
|
4257
|
+
const record3 = staticPlanFields.get(plan);
|
|
4258
|
+
if (!record3 || record3.authorization !== authorization || import_node_util4.types.isProxy(plan)) return;
|
|
4259
|
+
const ownValue2 = (key) => {
|
|
4260
|
+
const slot = Object.getOwnPropertyDescriptor(plan, key);
|
|
4261
|
+
return slot && "value" in slot ? slot.value : void 0;
|
|
4262
|
+
};
|
|
4263
|
+
if (ownValue2("authorization") !== authorization || ownValue2("authorizationBinding") !== record3.binding) return;
|
|
4264
|
+
const children = ownValue2("childPlans");
|
|
4265
|
+
if (children !== record3.children || import_node_util4.types.isProxy(children) || Reflect.ownKeys(children).length) return;
|
|
4266
|
+
const persisted = copyOutputDecisionFields(ownValue2("outputPersistedFields"));
|
|
4267
|
+
const virtuals = copyOutputDecisionFields(ownValue2("outputVirtualNames"));
|
|
4268
|
+
const same = (a, b) => a?.length === b.length && a.every((field, index) => field === b[index]);
|
|
4269
|
+
if (!same(persisted, record3.persisted) || !same(virtuals, record3.virtuals)) return;
|
|
4270
|
+
return Object.freeze([.../* @__PURE__ */ new Set([...record3.persisted, ...record3.virtuals])]);
|
|
4271
|
+
}
|
|
4547
4272
|
function compactPersistedProjection(paths) {
|
|
4548
4273
|
const unique = [...new Set(paths.filter((p) => p && !p.startsWith("-")))];
|
|
4549
4274
|
return unique.filter((path) => !unique.some((parent) => parent !== path && path.startsWith(`${parent}.`)));
|
|
@@ -4572,6 +4297,13 @@ function planAuthorizedModelProjection(args) {
|
|
|
4572
4297
|
);
|
|
4573
4298
|
plan.authorization = args.authorization;
|
|
4574
4299
|
plan.authorizationBinding = Object.freeze({ ...args.binding, scopePath: Object.freeze(scope2) });
|
|
4300
|
+
staticPlanFields.set(plan, {
|
|
4301
|
+
authorization: args.authorization,
|
|
4302
|
+
binding: plan.authorizationBinding,
|
|
4303
|
+
persisted: Object.freeze([...plan.outputPersistedFields]),
|
|
4304
|
+
virtuals: Object.freeze([...plan.outputVirtualNames]),
|
|
4305
|
+
children: plan.childPlans
|
|
4306
|
+
});
|
|
4575
4307
|
return plan;
|
|
4576
4308
|
}
|
|
4577
4309
|
function planCatalogProjection(args, outputFields = { mode: "request" }) {
|
|
@@ -4770,22 +4502,664 @@ function planCatalogProjection(args, outputFields = { mode: "request" }) {
|
|
|
4770
4502
|
)
|
|
4771
4503
|
};
|
|
4772
4504
|
}
|
|
4773
|
-
var
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4505
|
+
var import_node_util4, staticPlanFields;
|
|
4506
|
+
var init_output_projection = __esm({
|
|
4507
|
+
"src/acl/output-projection.ts"() {
|
|
4508
|
+
import_node_util4 = require("util");
|
|
4509
|
+
init_query();
|
|
4510
|
+
init_authorization_snapshot();
|
|
4511
|
+
init_field_catalog();
|
|
4512
|
+
init_field_authorization();
|
|
4513
|
+
init_virtual_populate_dependencies();
|
|
4514
|
+
init_service_authorization();
|
|
4515
|
+
init_virtual_projection();
|
|
4516
|
+
staticPlanFields = /* @__PURE__ */ new WeakMap();
|
|
4517
|
+
}
|
|
4518
|
+
});
|
|
4519
|
+
|
|
4520
|
+
// src/acl/output-field-policy.ts
|
|
4521
|
+
function callFieldPolicy(authorization, binding) {
|
|
4522
|
+
assertAuthorizationBinding(authorization, binding);
|
|
4523
|
+
let policy = fieldPolicies.get(authorization);
|
|
4524
|
+
if (!policy) {
|
|
4525
|
+
const view = readServiceOutputFieldAuthorization(authorization, binding);
|
|
4526
|
+
policy = {
|
|
4527
|
+
schema: view.permissionSchema,
|
|
4528
|
+
requestPaths: view.permissionSchema == null || (0, import_utils20.isPlainObject)(view.permissionSchema) && Object.isFrozen(view.permissionSchema) ? Object.freeze(Object.keys(view.permissionSchema ?? {})) : void 0,
|
|
4529
|
+
prefix: view.modelPermissionPrefix ?? "",
|
|
4530
|
+
outputFields: view.outputFields,
|
|
4531
|
+
catalog: view.catalog,
|
|
4532
|
+
reusable: view.reusable,
|
|
4533
|
+
accesses: /* @__PURE__ */ new Map()
|
|
4534
|
+
};
|
|
4535
|
+
if (view.reusable) fieldPolicies.set(authorization, policy);
|
|
4536
|
+
}
|
|
4537
|
+
return policy;
|
|
4538
|
+
}
|
|
4539
|
+
function requestRuleClassification(entry, authorization, permissions, prefix) {
|
|
4540
|
+
if (typeof prefix !== "string") return void 0;
|
|
4541
|
+
let classification = entry.classifications.get(authorization);
|
|
4542
|
+
if (!classification) {
|
|
4543
|
+
classification = prepareRequestFieldRule(entry.rule, permissions, prefix);
|
|
4544
|
+
entry.classifications.set(authorization, classification);
|
|
4545
|
+
}
|
|
4546
|
+
return classification;
|
|
4547
|
+
}
|
|
4548
|
+
function invariantRuleLookup(schema, path) {
|
|
4549
|
+
if (schema == null) return true;
|
|
4550
|
+
if (!(0, import_utils20.isPlainObject)(schema) || !Object.isFrozen(schema)) return false;
|
|
4551
|
+
const exact = Object.getOwnPropertyDescriptor(schema, path);
|
|
4552
|
+
if (exact) {
|
|
4553
|
+
const raw2 = exact.value;
|
|
4554
|
+
return !raw2 || typeof raw2 !== "object" || Array.isArray(raw2) || (0, import_utils20.isPlainObject)(raw2) && Object.isFrozen(raw2);
|
|
4555
|
+
}
|
|
4556
|
+
const [head, ...rest] = path.split(".");
|
|
4557
|
+
const raw = Object.getOwnPropertyDescriptor(schema, head)?.value;
|
|
4558
|
+
if (raw == null) return true;
|
|
4559
|
+
if (!(0, import_utils20.isPlainObject)(raw) || !Object.isFrozen(raw)) return false;
|
|
4560
|
+
const sub = Object.getOwnPropertyDescriptor(raw, "sub");
|
|
4561
|
+
return !rest.length || !sub || invariantRuleLookup(sub.value, rest.join("."));
|
|
4562
|
+
}
|
|
4563
|
+
function prepareOutputPath(policy, authorization, binding, path, access) {
|
|
4564
|
+
let cache = policy.accesses.get(access);
|
|
4565
|
+
if (!cache) {
|
|
4566
|
+
cache = /* @__PURE__ */ new Map();
|
|
4567
|
+
policy.accesses.set(access, cache);
|
|
4568
|
+
}
|
|
4569
|
+
let prepared = cache.get(path);
|
|
4570
|
+
if (!prepared) {
|
|
4571
|
+
const invariant = invariantRuleLookup(policy.schema, path);
|
|
4572
|
+
const permissions = getAuthorizationPermissions(authorization, binding);
|
|
4573
|
+
const entries = extractOutputFieldRuleEntries(policy.schema, path, access).map((entry) => ({
|
|
4574
|
+
...entry,
|
|
4575
|
+
classifications: /* @__PURE__ */ new WeakMap()
|
|
4576
|
+
}));
|
|
4577
|
+
const classifications = entries.map(
|
|
4578
|
+
(entry) => requestRuleClassification(entry, authorization, permissions, policy.prefix)
|
|
4579
|
+
);
|
|
4580
|
+
const backendGrant = hasExplicitFieldGrant(policy.outputFields, path);
|
|
4581
|
+
prepared = {
|
|
4582
|
+
entries,
|
|
4583
|
+
backendGrant,
|
|
4584
|
+
state: backendGrant ? "granted" : classifications.every((value) => value !== void 0) ? combineFieldAuthorizationStates(classifications.map((value) => value.state)) : void 0
|
|
4585
|
+
};
|
|
4586
|
+
if (invariant) cache.set(path, prepared);
|
|
4587
|
+
}
|
|
4588
|
+
return prepared;
|
|
4589
|
+
}
|
|
4590
|
+
function ordinaryContainer(value) {
|
|
4591
|
+
return value !== null && typeof value === "object" && !import_node_util5.types.isProxy(value) && Object.getPrototypeOf(value) === Object.prototype && Object.isFrozen(value);
|
|
4592
|
+
}
|
|
4593
|
+
function booleanRuleLookup(schema, path, access) {
|
|
4594
|
+
if (schema == null) return true;
|
|
4595
|
+
if (!ordinaryContainer(schema)) return false;
|
|
4596
|
+
const booleanRule = (raw) => {
|
|
4597
|
+
if (typeof raw === "boolean" || raw === void 0) return true;
|
|
4598
|
+
if (!ordinaryContainer(raw)) return false;
|
|
4599
|
+
const slot2 = Object.getOwnPropertyDescriptor(raw, access);
|
|
4600
|
+
return !!slot2 && "value" in slot2 && (typeof slot2.value === "boolean" || slot2.value === void 0);
|
|
4601
|
+
};
|
|
4602
|
+
const exact = Object.getOwnPropertyDescriptor(schema, path);
|
|
4603
|
+
if (exact) return "value" in exact && booleanRule(exact.value);
|
|
4604
|
+
const [head, ...rest] = path.split(".");
|
|
4605
|
+
const slot = Object.getOwnPropertyDescriptor(schema, head);
|
|
4606
|
+
if (!slot) return !(head in schema);
|
|
4607
|
+
if (!("value" in slot) || !booleanRule(slot.value)) return false;
|
|
4608
|
+
if (!rest.length || slot.value == null) return true;
|
|
4609
|
+
if (!ordinaryContainer(slot.value)) return false;
|
|
4610
|
+
const sub = Object.getOwnPropertyDescriptor(slot.value, "sub");
|
|
4611
|
+
if (!sub) return !("sub" in slot.value);
|
|
4612
|
+
if (!("value" in sub)) return false;
|
|
4613
|
+
return !sub.value || booleanRuleLookup(sub.value, rest.join("."), access);
|
|
4614
|
+
}
|
|
4615
|
+
function staticFieldPolicy(authorization, binding) {
|
|
4616
|
+
return canPrepareStaticOutputPolicy(authorization, binding) ? callFieldPolicy(authorization, binding) : void 0;
|
|
4617
|
+
}
|
|
4618
|
+
function prepareStaticOutputPaths(authorization, binding, paths, access, requestOnly = false) {
|
|
4619
|
+
const policy = staticFieldPolicy(authorization, binding);
|
|
4620
|
+
if (!policy?.reusable || typeof policy.prefix !== "string") return void 0;
|
|
4621
|
+
const { catalog } = policy;
|
|
4622
|
+
if (paths.some(
|
|
4623
|
+
(path) => !requestOnly && !isCatalogOutputPath(catalog, path) || !booleanRuleLookup(policy.schema, path, access)
|
|
4624
|
+
))
|
|
4625
|
+
return void 0;
|
|
4626
|
+
return paths.map((path) => {
|
|
4627
|
+
const prepared = prepareOutputPath(policy, authorization, binding, path, access);
|
|
4628
|
+
return {
|
|
4629
|
+
path,
|
|
4630
|
+
backendGrant: !requestOnly && prepared.backendGrant,
|
|
4631
|
+
granted: prepared.backendGrant || prepared.entries.every((entry) => entry.rule === true),
|
|
4632
|
+
entries: prepared.entries.map((entry) => ({
|
|
4633
|
+
key: `request:${access}:${entry.path}`,
|
|
4634
|
+
allowed: entry.rule === true
|
|
4635
|
+
}))
|
|
4636
|
+
};
|
|
4637
|
+
});
|
|
4638
|
+
}
|
|
4639
|
+
var import_node_util5, import_utils20, fieldPolicies;
|
|
4640
|
+
var init_output_field_policy = __esm({
|
|
4641
|
+
"src/acl/output-field-policy.ts"() {
|
|
4642
|
+
import_node_util5 = require("util");
|
|
4643
|
+
import_utils20 = require("@web-ts-toolkit/utils");
|
|
4644
|
+
init_service_authorization();
|
|
4645
|
+
init_field_authorization();
|
|
4646
|
+
init_field_catalog();
|
|
4647
|
+
fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
4648
|
+
}
|
|
4649
|
+
});
|
|
4650
|
+
|
|
4651
|
+
// src/acl/document-authorization.ts
|
|
4652
|
+
function bindOutputDocumentOwner(handle, knownOutput, owner, binding) {
|
|
4653
|
+
lookupDocumentOwner(handle);
|
|
4654
|
+
if (knownOutput || owner && unresolvedDocuments.has(owner)) unresolvedDocuments.add(handle);
|
|
4655
|
+
if (owner) {
|
|
4656
|
+
lookupDocumentOwner(owner);
|
|
4657
|
+
owningDocuments.set(handle, { handle: owner, binding });
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
function readOutputDocumentOwner(handle) {
|
|
4661
|
+
return owningDocuments.get(handle);
|
|
4662
|
+
}
|
|
4663
|
+
function isUnresolvedOutputDocument(handle) {
|
|
4664
|
+
return unresolvedDocuments.has(handle);
|
|
4665
|
+
}
|
|
4666
|
+
function normalizeOutputAuthorizationOptions(input, options, purpose) {
|
|
4667
|
+
const value = authorizationRecord(options, "output options");
|
|
4668
|
+
for (const key of Reflect.ownKeys(value)) {
|
|
4669
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
4670
|
+
if (typeof key !== "string" || !("value" in descriptor) || !descriptor.enumerable) {
|
|
4671
|
+
authorizationError("invalid output option property");
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
assertAuthorizationKeys(
|
|
4675
|
+
value,
|
|
4676
|
+
["authorization", "scopePath", "documentAuthorization", ...purpose ? ["purpose"] : []],
|
|
4677
|
+
"output options"
|
|
4678
|
+
);
|
|
4679
|
+
if (purpose && value.purpose !== purpose) authorizationError("genAllowedFields requires purpose: output");
|
|
4680
|
+
if (Object.prototype.hasOwnProperty.call(value, "documentAuthorization")) {
|
|
4681
|
+
if (Object.prototype.hasOwnProperty.call(value, "authorization") || Object.prototype.hasOwnProperty.call(value, "scopePath")) {
|
|
4682
|
+
authorizationError("document handle cannot be mixed with raw policy/scope");
|
|
4683
|
+
}
|
|
4684
|
+
const handle = value.documentAuthorization;
|
|
4685
|
+
const { stage } = validateDocumentOwner(handle);
|
|
4686
|
+
const binding = Object.freeze({ ...input.binding, scopePath: stage.binding.scopePath });
|
|
4687
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4688
|
+
const access = readServiceAuthorizationAccess(stage.call, binding);
|
|
4689
|
+
if (input.access.outputAccess !== access.outputAccess) authorizationError("document access mismatch");
|
|
4690
|
+
return Object.freeze({ kind: "document", documentAuthorization: handle, binding });
|
|
4691
|
+
}
|
|
4692
|
+
if (value.scopePath !== void 0 && !Array.isArray(value.scopePath))
|
|
4693
|
+
authorizationError("scopePath must be an array");
|
|
4694
|
+
return Object.freeze({
|
|
4695
|
+
kind: "policy",
|
|
4696
|
+
authorization: resolveServiceAuthorization({
|
|
4697
|
+
...input,
|
|
4698
|
+
binding: {
|
|
4699
|
+
...input.binding,
|
|
4700
|
+
scopePath: copyAuthorizationValue(value.scopePath)
|
|
4701
|
+
},
|
|
4702
|
+
authorization: value.authorization,
|
|
4703
|
+
applicability: "output"
|
|
4704
|
+
})
|
|
4705
|
+
});
|
|
4706
|
+
}
|
|
4707
|
+
function lookupStageOwner(stage) {
|
|
4708
|
+
const record3 = stages.get(stage);
|
|
4709
|
+
if (!record3) authorizationError("invalid document stage");
|
|
4710
|
+
return record3;
|
|
4711
|
+
}
|
|
4712
|
+
function lookupDocumentOwner(handle) {
|
|
4713
|
+
const record3 = documents.get(handle);
|
|
4714
|
+
if (!record3) authorizationError("invalid document handle");
|
|
4715
|
+
return record3;
|
|
4716
|
+
}
|
|
4717
|
+
function validateStageOwner(record3) {
|
|
4718
|
+
if (!record3.validateSnapshot) return;
|
|
4719
|
+
if (!matchesAuthorizationSnapshot(record3.input, record3.snapshot)) authorizationError("changed document snapshot");
|
|
4720
|
+
}
|
|
4721
|
+
function validateDocumentOwner(handle) {
|
|
4722
|
+
const document = lookupDocumentOwner(handle);
|
|
4723
|
+
const stage = lookupStageOwner(document.stage);
|
|
4724
|
+
validateStageOwner(stage);
|
|
4725
|
+
validateStageOwner(stage);
|
|
4726
|
+
return { document, stage };
|
|
4727
|
+
}
|
|
4728
|
+
function createDocumentAuthorizationStage(call, binding, projectedSnapshot) {
|
|
4729
|
+
assertAuthorizationBinding(call, binding);
|
|
4730
|
+
authorizationRecord(projectedSnapshot, "projected document snapshot");
|
|
4731
|
+
const stage = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
4732
|
+
const ownedBinding = Object.freeze({ ...binding, scopePath: Object.freeze([...binding.scopePath ?? []]) });
|
|
4733
|
+
const snapshot = copyAuthorizationValue(projectedSnapshot, "document");
|
|
4734
|
+
stages.set(stage, {
|
|
4735
|
+
call,
|
|
4736
|
+
binding: ownedBinding,
|
|
4737
|
+
input: projectedSnapshot,
|
|
4738
|
+
snapshot,
|
|
4739
|
+
validateSnapshot: requiresDocumentSnapshotChecks(call, binding)
|
|
4740
|
+
});
|
|
4741
|
+
return stage;
|
|
4742
|
+
}
|
|
4743
|
+
function assertDocumentAuthorizationStage(stage, call, binding, projectedSnapshot) {
|
|
4744
|
+
const record3 = lookupStageOwner(stage);
|
|
4745
|
+
validateStageOwner(record3);
|
|
4746
|
+
assertAuthorizationBinding(record3.call, binding);
|
|
4747
|
+
if (record3.call !== call || record3.input !== projectedSnapshot || record3.validateSnapshot && !matchesAuthorizationSnapshot(projectedSnapshot, record3.snapshot)) {
|
|
4748
|
+
authorizationError("document call/stage/snapshot mismatch");
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
function resolveDocumentAuthorization(stage, resolveGrants) {
|
|
4752
|
+
const record3 = lookupStageOwner(stage);
|
|
4753
|
+
validateStageOwner(record3);
|
|
4754
|
+
if (!record3.result) {
|
|
4755
|
+
record3.result = Promise.resolve().then(async () => {
|
|
4756
|
+
validateStageOwner(record3);
|
|
4757
|
+
const result2 = resolveGrants.call(
|
|
4758
|
+
record3.binding.request,
|
|
4759
|
+
copyAuthorizationValue(record3.snapshot, "document"),
|
|
4760
|
+
getAuthorizationPermissions(record3.call, record3.binding)
|
|
4761
|
+
);
|
|
4762
|
+
const grants = result2 && typeof result2.then === "function" ? await result2 : result2;
|
|
4763
|
+
validateStageOwner(record3);
|
|
4764
|
+
const ownedGrants = copyAuthorizationValue(authorizationRecord(grants, "document grants"));
|
|
4765
|
+
const handle = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
4766
|
+
documents.set(handle, { stage, grants: ownedGrants, decisions: /* @__PURE__ */ new Map() });
|
|
4767
|
+
return handle;
|
|
4768
|
+
});
|
|
4769
|
+
}
|
|
4770
|
+
return record3.result;
|
|
4771
|
+
}
|
|
4772
|
+
function readDocumentAuthorization(handle, binding) {
|
|
4773
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4774
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4775
|
+
return Object.freeze({
|
|
4776
|
+
authorization: stage.call,
|
|
4777
|
+
stage: record3.stage,
|
|
4778
|
+
grants: copyAuthorizationValue(record3.grants),
|
|
4779
|
+
...readServiceAuthorizationAccess(stage.call, binding)
|
|
4780
|
+
});
|
|
4781
|
+
}
|
|
4782
|
+
function readDocumentAuthorizationAccess(handle, binding) {
|
|
4783
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4784
|
+
return Object.freeze({
|
|
4785
|
+
authorization: stage.call,
|
|
4786
|
+
stage: record3.stage,
|
|
4787
|
+
...readServiceAuthorizationAccess(stage.call, binding)
|
|
4788
|
+
});
|
|
4789
|
+
}
|
|
4790
|
+
function memoizeDocumentFieldDecision(handle, binding, field, evaluate) {
|
|
4791
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4792
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4793
|
+
let decision = record3.decisions.get(field);
|
|
4794
|
+
if (decision) {
|
|
4795
|
+
return decision.promise.then((result2) => {
|
|
4796
|
+
validateStageOwner(stage);
|
|
4797
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4798
|
+
return result2;
|
|
4799
|
+
});
|
|
4800
|
+
} else {
|
|
4801
|
+
const created = {
|
|
4802
|
+
state: "pending",
|
|
4803
|
+
promise: Promise.resolve().then(async () => {
|
|
4804
|
+
validateStageOwner(stage);
|
|
4805
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4806
|
+
const result2 = await evaluate.call(
|
|
4807
|
+
stage.binding.request,
|
|
4808
|
+
getAuthorizationPermissions(stage.call, binding),
|
|
4809
|
+
copyAuthorizationValue(record3.grants)
|
|
4810
|
+
);
|
|
4811
|
+
validateStageOwner(stage);
|
|
4812
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4813
|
+
if (typeof result2 !== "boolean") authorizationError("field decision must be boolean");
|
|
4814
|
+
return result2;
|
|
4815
|
+
})
|
|
4816
|
+
};
|
|
4817
|
+
void created.promise.then(
|
|
4818
|
+
(value) => {
|
|
4819
|
+
created.value = value;
|
|
4820
|
+
created.state = "fulfilled";
|
|
4821
|
+
},
|
|
4822
|
+
() => {
|
|
4823
|
+
created.state = "rejected";
|
|
4824
|
+
}
|
|
4825
|
+
);
|
|
4826
|
+
decision = created;
|
|
4827
|
+
record3.decisions.set(field, decision);
|
|
4828
|
+
}
|
|
4829
|
+
return decision.promise;
|
|
4830
|
+
}
|
|
4831
|
+
function ordinaryDecisionBinding(binding) {
|
|
4832
|
+
if (import_node_util6.types.isProxy(binding) || Object.getPrototypeOf(binding) !== Object.prototype) return false;
|
|
4833
|
+
for (const key of ["request", "runtime", "model", "modelName", "scopePath"]) {
|
|
4834
|
+
const slot = Object.getOwnPropertyDescriptor(binding, key);
|
|
4835
|
+
if (slot && !("value" in slot)) return false;
|
|
4836
|
+
if (!slot && key !== "scopePath") return false;
|
|
4837
|
+
if (!slot && key in binding) return false;
|
|
4838
|
+
}
|
|
4839
|
+
const scope2 = Object.getOwnPropertyDescriptor(binding, "scopePath")?.value;
|
|
4840
|
+
return scope2 === void 0 || copyOutputDecisionFields(scope2) !== void 0;
|
|
4841
|
+
}
|
|
4842
|
+
function settleStaticFieldBatch(handle, binding, paths) {
|
|
4843
|
+
const { document, stage } = validateDocumentOwner(handle);
|
|
4844
|
+
if (!ordinaryDecisionBinding(binding)) {
|
|
4845
|
+
validateDocumentOwner(handle);
|
|
4846
|
+
return;
|
|
4847
|
+
}
|
|
4848
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4849
|
+
const expected = /* @__PURE__ */ new Map();
|
|
4850
|
+
const journal = /* @__PURE__ */ new Map();
|
|
4851
|
+
const result2 = /* @__PURE__ */ new Map();
|
|
4852
|
+
const unresolved = unresolvedDocuments.has(handle);
|
|
4853
|
+
let available = !owningDocuments.has(handle);
|
|
4854
|
+
const read = (key) => {
|
|
4855
|
+
const memo = document.decisions.get(key);
|
|
4856
|
+
expected.set(key, memo);
|
|
4857
|
+
if (memo) {
|
|
4858
|
+
if (memo.state !== "fulfilled") available = false;
|
|
4859
|
+
return memo.value;
|
|
4860
|
+
}
|
|
4861
|
+
return journal.get(key);
|
|
4862
|
+
};
|
|
4863
|
+
for (const path of paths) {
|
|
4864
|
+
if (!available) break;
|
|
4865
|
+
let allowed = path.outputKey ? read(path.outputKey) : void 0;
|
|
4866
|
+
if (!available) break;
|
|
4867
|
+
if (allowed === void 0) {
|
|
4868
|
+
const policy = path.policy;
|
|
4869
|
+
if (!policy) {
|
|
4870
|
+
available = false;
|
|
4871
|
+
break;
|
|
4872
|
+
}
|
|
4873
|
+
if (path.outputKey && unresolved && !policy.granted) allowed = false;
|
|
4874
|
+
else if (path.outputKey && policy.backendGrant) allowed = true;
|
|
4875
|
+
else {
|
|
4876
|
+
allowed = true;
|
|
4877
|
+
for (const entry of policy.entries) {
|
|
4878
|
+
let decision = read(entry.key);
|
|
4879
|
+
if (!available) break;
|
|
4880
|
+
if (decision === void 0) {
|
|
4881
|
+
decision = entry.allowed;
|
|
4882
|
+
journal.set(entry.key, decision);
|
|
4883
|
+
}
|
|
4884
|
+
if (!decision) {
|
|
4885
|
+
allowed = false;
|
|
4886
|
+
break;
|
|
4887
|
+
}
|
|
4888
|
+
}
|
|
4889
|
+
}
|
|
4890
|
+
if (!available) break;
|
|
4891
|
+
if (path.outputKey) journal.set(path.outputKey, allowed);
|
|
4892
|
+
}
|
|
4893
|
+
result2.set(path.field, allowed);
|
|
4894
|
+
}
|
|
4895
|
+
validateDocumentOwner(handle);
|
|
4896
|
+
if (!ordinaryDecisionBinding(binding)) return;
|
|
4897
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4898
|
+
if (!available || owningDocuments.has(handle) || unresolvedDocuments.has(handle) !== unresolved || [...expected].some(([key, memo]) => document.decisions.get(key) !== memo))
|
|
4899
|
+
return;
|
|
4900
|
+
for (const [key, value] of journal) {
|
|
4901
|
+
document.decisions.set(key, { promise: Promise.resolve(value), state: "fulfilled", value });
|
|
4902
|
+
}
|
|
4903
|
+
return result2;
|
|
4904
|
+
}
|
|
4905
|
+
function tryStaticOutputFieldDecisions(handle, binding, plan, fields) {
|
|
4906
|
+
const document = lookupDocumentOwner(handle);
|
|
4907
|
+
const stage = lookupStageOwner(document.stage);
|
|
4908
|
+
if (!ordinaryDecisionBinding(binding) || owningDocuments.has(handle)) return;
|
|
4909
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4910
|
+
const canonical = readStaticOutputPlanFields(plan, stage.call);
|
|
4911
|
+
const ownedFields = copyOutputDecisionFields(fields);
|
|
4912
|
+
if (!canonical || !ownedFields) return;
|
|
4913
|
+
let index = 0;
|
|
4914
|
+
for (const field of ownedFields) {
|
|
4915
|
+
const next = canonical.indexOf(field, index);
|
|
4916
|
+
if (next < 0) return;
|
|
4917
|
+
index = next + 1;
|
|
4918
|
+
}
|
|
4919
|
+
const prefix = (binding.scopePath ?? []).join(".");
|
|
4920
|
+
const paths = ownedFields.map((field) => {
|
|
4921
|
+
const path = prefix ? `${prefix}.${field}` : field;
|
|
4922
|
+
return { field, path, outputKey: `output:${path}` };
|
|
4923
|
+
});
|
|
4924
|
+
const missing = [];
|
|
4925
|
+
for (const path of paths) {
|
|
4926
|
+
const memo = document.decisions.get(path.outputKey);
|
|
4927
|
+
if (memo && memo.state !== "fulfilled") return;
|
|
4928
|
+
if (!memo) missing.push(path.path);
|
|
4929
|
+
}
|
|
4930
|
+
const access = readServiceAuthorizationAccess(stage.call, binding).outputAccess;
|
|
4931
|
+
const prepared = missing.length ? prepareStaticOutputPaths(stage.call, binding, missing, access) : [];
|
|
4932
|
+
if (!prepared) return;
|
|
4933
|
+
const policies = new Map(prepared.map((policy) => [policy.path, policy]));
|
|
4934
|
+
const decisions = settleStaticFieldBatch(
|
|
4935
|
+
handle,
|
|
4936
|
+
binding,
|
|
4937
|
+
paths.map((path) => ({ ...path, policy: policies.get(path.path) }))
|
|
4938
|
+
);
|
|
4939
|
+
if (decisions && !readStaticOutputPlanFields(plan, stage.call)) authorizationError("changed static output plan");
|
|
4940
|
+
return decisions;
|
|
4941
|
+
}
|
|
4942
|
+
function tryStaticRequestFieldPaths(handle, binding, access) {
|
|
4943
|
+
const document = lookupDocumentOwner(handle);
|
|
4944
|
+
const stage = lookupStageOwner(document.stage);
|
|
4945
|
+
if (!ordinaryDecisionBinding(binding) || owningDocuments.has(handle) || typeof access !== "string") return;
|
|
4946
|
+
const policy = staticFieldPolicy(stage.call, binding);
|
|
4947
|
+
if (!policy?.reusable || !policy.requestPaths) return;
|
|
4948
|
+
const prepared = prepareStaticOutputPaths(stage.call, binding, policy.requestPaths, access, true);
|
|
4949
|
+
if (!prepared) return;
|
|
4950
|
+
const decisions = settleStaticFieldBatch(
|
|
4951
|
+
handle,
|
|
4952
|
+
binding,
|
|
4953
|
+
prepared.map((policy2) => ({ field: policy2.path, policy: policy2 }))
|
|
4954
|
+
);
|
|
4955
|
+
return decisions && [...decisions].filter(([, allowed]) => allowed).map(([field]) => field);
|
|
4956
|
+
}
|
|
4957
|
+
function unchangedOutput(output, record3) {
|
|
4958
|
+
if (!matchesAuthorizationSnapshot(output, record3.snapshot)) return false;
|
|
4959
|
+
const identities = outputIdentities(output);
|
|
4960
|
+
return identities.length === record3.identities.length && identities.every((identity, i) => identity === record3.identities[i]);
|
|
4961
|
+
}
|
|
4962
|
+
function assertDocumentAuthorization(handle, use) {
|
|
4963
|
+
const { document: record3, stage } = validateDocumentOwner(handle);
|
|
4964
|
+
assertAuthorizationBinding(stage.call, use.binding);
|
|
4965
|
+
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) {
|
|
4966
|
+
authorizationError("document call/access/stage mismatch");
|
|
4967
|
+
}
|
|
4968
|
+
const association = outputs.get(use.output);
|
|
4969
|
+
if (!association || association.handle !== handle || !unchangedOutput(use.output, association)) {
|
|
4970
|
+
authorizationError("unknown, replaced or mutated authorized output");
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
function associateDocumentAuthorization(handle, binding, output) {
|
|
4974
|
+
const { stage } = validateDocumentOwner(handle);
|
|
4975
|
+
assertAuthorizationBinding(stage.call, binding);
|
|
4976
|
+
if (!output || typeof output !== "object") authorizationError("output must be an object");
|
|
4977
|
+
if (outputs.has(output)) {
|
|
4978
|
+
const previous = outputs.get(output);
|
|
4979
|
+
if (previous.handle !== handle || !unchangedOutput(output, previous))
|
|
4980
|
+
authorizationError("output already associated");
|
|
4981
|
+
return;
|
|
4982
|
+
}
|
|
4983
|
+
outputs.set(output, {
|
|
4984
|
+
handle,
|
|
4985
|
+
snapshot: copyAuthorizationValue(output, "document"),
|
|
4986
|
+
identities: outputIdentities(output)
|
|
4987
|
+
});
|
|
4988
|
+
}
|
|
4989
|
+
function transferDocumentAuthorization(handle, use, copy) {
|
|
4990
|
+
assertDocumentAuthorization(handle, use);
|
|
4991
|
+
associateDocumentAuthorization(handle, use.binding, copy);
|
|
4992
|
+
}
|
|
4993
|
+
function isKnownAuthorizationOutput(output) {
|
|
4994
|
+
return outputs.has(output);
|
|
4995
|
+
}
|
|
4996
|
+
function getAssociatedDocumentAuthorization(output, call) {
|
|
4997
|
+
const record3 = outputs.get(output);
|
|
4998
|
+
if (!record3 || !unchangedOutput(output, record3)) return void 0;
|
|
4999
|
+
const { stage } = validateDocumentOwner(record3.handle);
|
|
5000
|
+
if (call && getAuthorizationProvenance(stage.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
5001
|
+
return record3.handle;
|
|
5002
|
+
}
|
|
5003
|
+
function transferDocumentAuthorizationGraph(source, copy, copyOrigins) {
|
|
5004
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
5005
|
+
const visit = (source2, copy2) => {
|
|
5006
|
+
if (!copy2 || typeof copy2 !== "object" || seen.has(copy2)) return;
|
|
5007
|
+
seen.add(copy2);
|
|
5008
|
+
source2 = copyOrigins?.get(copy2) ?? source2;
|
|
5009
|
+
if (source2 instanceof import_mongoose5.Document) source2 = source2._doc;
|
|
5010
|
+
const original = source2 && typeof source2 === "object" ? source2 : void 0;
|
|
5011
|
+
if (!original && !copyOrigins) return;
|
|
5012
|
+
const association = original && outputs.get(original);
|
|
5013
|
+
if (association) {
|
|
5014
|
+
const { document, stage } = validateDocumentOwner(association.handle);
|
|
5015
|
+
const outputAccess = readServiceAuthorizationAccess(stage.call, stage.binding).outputAccess;
|
|
5016
|
+
validateStageOwner(stage);
|
|
5017
|
+
transferDocumentAuthorization(
|
|
5018
|
+
association.handle,
|
|
5019
|
+
{
|
|
5020
|
+
binding: stage.binding,
|
|
5021
|
+
output: original,
|
|
5022
|
+
outputAccess,
|
|
5023
|
+
authorization: stage.call,
|
|
5024
|
+
stage: document.stage
|
|
5025
|
+
},
|
|
5026
|
+
copy2
|
|
5027
|
+
);
|
|
5028
|
+
}
|
|
5029
|
+
for (const key of Object.keys(copy2)) {
|
|
5030
|
+
const descriptor = original && Object.getOwnPropertyDescriptor(original, key);
|
|
5031
|
+
if (descriptor && "value" in descriptor) {
|
|
5032
|
+
visit(descriptor.value, copy2[key]);
|
|
5033
|
+
} else if (copyOrigins) {
|
|
5034
|
+
visit(void 0, copy2[key]);
|
|
5035
|
+
}
|
|
5036
|
+
}
|
|
5037
|
+
};
|
|
5038
|
+
visit(source, copy);
|
|
5039
|
+
}
|
|
5040
|
+
function createServiceOutputContext(diagnostic, handle, use) {
|
|
5041
|
+
assertDocumentAuthorization(handle, use);
|
|
5042
|
+
const rootOutput = use.output;
|
|
5043
|
+
const root = outputs.get(rootOutput);
|
|
5044
|
+
const graph = new Set(root.identities);
|
|
5045
|
+
const { stage } = validateDocumentOwner(handle);
|
|
5046
|
+
const call = stage.call;
|
|
5047
|
+
const context = { ...diagnostic };
|
|
5048
|
+
Object.defineProperties(context, {
|
|
5049
|
+
documentAuthorization: { value: handle, enumerable: false, writable: false, configurable: false },
|
|
5050
|
+
getDocumentAuthorization: {
|
|
5051
|
+
enumerable: false,
|
|
5052
|
+
writable: false,
|
|
5053
|
+
configurable: false,
|
|
5054
|
+
value(output) {
|
|
5055
|
+
if (!graph.has(output) || !unchangedOutput(rootOutput, root)) return void 0;
|
|
5056
|
+
const association = outputs.get(output);
|
|
5057
|
+
if (!association || !unchangedOutput(output, association)) return void 0;
|
|
5058
|
+
try {
|
|
5059
|
+
validateStageOwner(lookupStageOwner(lookupDocumentOwner(handle).stage));
|
|
5060
|
+
const { stage: child } = validateDocumentOwner(association.handle);
|
|
5061
|
+
if (getAuthorizationProvenance(child.call) !== getAuthorizationProvenance(call)) return void 0;
|
|
5062
|
+
return association.handle;
|
|
5063
|
+
} catch {
|
|
5064
|
+
return void 0;
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
}
|
|
5068
|
+
});
|
|
5069
|
+
return context;
|
|
5070
|
+
}
|
|
5071
|
+
var import_node_util6, import_mongoose5, stages, documents, outputs, unresolvedDocuments, owningDocuments;
|
|
5072
|
+
var init_document_authorization = __esm({
|
|
5073
|
+
"src/acl/document-authorization.ts"() {
|
|
5074
|
+
import_node_util6 = require("util");
|
|
5075
|
+
import_mongoose5 = require("mongoose");
|
|
4780
5076
|
init_service_authorization();
|
|
4781
|
-
|
|
5077
|
+
init_authorization_snapshot();
|
|
5078
|
+
init_output_projection();
|
|
5079
|
+
init_output_field_policy();
|
|
5080
|
+
stages = /* @__PURE__ */ new WeakMap();
|
|
5081
|
+
documents = /* @__PURE__ */ new WeakMap();
|
|
5082
|
+
outputs = /* @__PURE__ */ new WeakMap();
|
|
5083
|
+
unresolvedDocuments = /* @__PURE__ */ new WeakSet();
|
|
5084
|
+
owningDocuments = /* @__PURE__ */ new WeakMap();
|
|
5085
|
+
}
|
|
5086
|
+
});
|
|
5087
|
+
|
|
5088
|
+
// src/output/include-output.ts
|
|
5089
|
+
function prepareIncludeOutput(doc) {
|
|
5090
|
+
if (stateFor(doc)) return doc;
|
|
5091
|
+
const source = isolateDocForOutput(doc);
|
|
5092
|
+
transferDocumentAuthorizationGraph(doc, source);
|
|
5093
|
+
const working = deepIsolateValue(source);
|
|
5094
|
+
outputs2.set(working, { original: doc, source, attachments: [] });
|
|
5095
|
+
return working;
|
|
5096
|
+
}
|
|
5097
|
+
function attachIncludeOutput(doc, path, value) {
|
|
5098
|
+
const state = stateFor(doc);
|
|
5099
|
+
if (!state) throw new Error("Include attachment requires a prepared output row");
|
|
5100
|
+
state.attachments.push({ path, value });
|
|
5101
|
+
(0, import_utils21.set)(doc, path, deepIsolateValue(value));
|
|
5102
|
+
}
|
|
5103
|
+
function getIncludeSource(doc) {
|
|
5104
|
+
return stateFor(doc)?.source ?? doc;
|
|
5105
|
+
}
|
|
5106
|
+
function getIncludeOriginal(doc) {
|
|
5107
|
+
return stateFor(doc)?.original ?? doc;
|
|
5108
|
+
}
|
|
5109
|
+
function restoreIncludeOutput(doc, output) {
|
|
5110
|
+
const attachments = stateFor(doc)?.attachments;
|
|
5111
|
+
if (!attachments?.length) return void 0;
|
|
5112
|
+
const origins = /* @__PURE__ */ new WeakMap();
|
|
5113
|
+
for (const { path, value } of attachments) {
|
|
5114
|
+
const copy = deepIsolateValue(value);
|
|
5115
|
+
if (copy !== null && typeof copy === "object") origins.set(copy, value);
|
|
5116
|
+
(0, import_utils21.set)(output, path, copy);
|
|
5117
|
+
}
|
|
5118
|
+
return origins;
|
|
5119
|
+
}
|
|
5120
|
+
var import_utils21, outputs2, stateFor;
|
|
5121
|
+
var init_include_output = __esm({
|
|
5122
|
+
"src/output/include-output.ts"() {
|
|
5123
|
+
import_utils21 = require("@web-ts-toolkit/utils");
|
|
5124
|
+
init_document_authorization();
|
|
5125
|
+
init_document();
|
|
5126
|
+
outputs2 = /* @__PURE__ */ new WeakMap();
|
|
5127
|
+
stateFor = (doc) => doc !== null && typeof doc === "object" ? outputs2.get(doc) : void 0;
|
|
5128
|
+
}
|
|
5129
|
+
});
|
|
5130
|
+
|
|
5131
|
+
// src/helpers/request-work.ts
|
|
5132
|
+
function getRequestWorkState(req, runtime) {
|
|
5133
|
+
let owners = states.get(req);
|
|
5134
|
+
if (!owners) {
|
|
5135
|
+
owners = /* @__PURE__ */ new WeakMap();
|
|
5136
|
+
states.set(req, owners);
|
|
5137
|
+
}
|
|
5138
|
+
let state = owners.get(runtime);
|
|
5139
|
+
if (!state) {
|
|
5140
|
+
const limits = resolveRequestComplexity(runtime.getGlobalOption("requestComplexity"));
|
|
5141
|
+
state = {
|
|
5142
|
+
totalQueries: 0,
|
|
5143
|
+
scheduler: new RequestConcurrencyScheduler(limits.maxBulkConcurrency),
|
|
5144
|
+
hookGate: new SharedHookGate(limits.maxHookConcurrency)
|
|
5145
|
+
};
|
|
5146
|
+
owners.set(runtime, state);
|
|
5147
|
+
}
|
|
5148
|
+
return state;
|
|
5149
|
+
}
|
|
5150
|
+
var states;
|
|
5151
|
+
var init_request_work = __esm({
|
|
5152
|
+
"src/helpers/request-work.ts"() {
|
|
5153
|
+
init_request_complexity();
|
|
5154
|
+
init_concurrency();
|
|
5155
|
+
states = /* @__PURE__ */ new WeakMap();
|
|
4782
5156
|
}
|
|
4783
5157
|
});
|
|
4784
5158
|
|
|
4785
5159
|
// src/acl/model-output-planning.ts
|
|
4786
5160
|
function getCapturedAuthorizationOption(configuration, key) {
|
|
4787
|
-
const defaultValue = key.startsWith("operationAccess.") ? (0,
|
|
4788
|
-
return resolveNestedOption((path, fallback) => (0,
|
|
5161
|
+
const defaultValue = key.startsWith("operationAccess.") ? (0, import_utils23.get)(configuration.operationAccessDefaults, key.slice("operationAccess.".length)) : void 0;
|
|
5162
|
+
return resolveNestedOption((path, fallback) => (0, import_utils23.get)(configuration, path, fallback), key, defaultValue);
|
|
4789
5163
|
}
|
|
4790
5164
|
function captureModelAuthorizationConfiguration(runtime, modelName, options = runtime.getModelOptions(modelName), globalOptions = runtime.getGlobalOptions()) {
|
|
4791
5165
|
const model = runtime.getModelInstance(modelName);
|
|
@@ -4812,6 +5186,8 @@ function captureModelAuthorizationConfiguration(runtime, modelName, options = ru
|
|
|
4812
5186
|
exposedDocPermissionKeys: options.exposedDocPermissionKeys,
|
|
4813
5187
|
stripPermissionsField: options.stripPermissionsField,
|
|
4814
5188
|
disableFieldPermissions: options.disableFieldPermissions,
|
|
5189
|
+
unsafeSkipListDocumentSnapshotChecks: options.unsafeSkipListDocumentSnapshotChecks === true,
|
|
5190
|
+
unsafeSkipReadDocumentSnapshotChecks: options.unsafeSkipReadDocumentSnapshotChecks === true,
|
|
4815
5191
|
overrideFilter: options.overrideFilter,
|
|
4816
5192
|
baseFilter: options.baseFilter,
|
|
4817
5193
|
idField: options.idField,
|
|
@@ -4848,10 +5224,10 @@ function planModelOutputForHelper(args) {
|
|
|
4848
5224
|
requestedSelect: args.select
|
|
4849
5225
|
});
|
|
4850
5226
|
}
|
|
4851
|
-
var
|
|
5227
|
+
var import_utils23;
|
|
4852
5228
|
var init_model_output_planning = __esm({
|
|
4853
5229
|
"src/acl/model-output-planning.ts"() {
|
|
4854
|
-
|
|
5230
|
+
import_utils23 = require("@web-ts-toolkit/utils");
|
|
4855
5231
|
init_manager();
|
|
4856
5232
|
init_field_catalog();
|
|
4857
5233
|
init_authorization_snapshot();
|
|
@@ -4863,10 +5239,10 @@ var init_model_output_planning = __esm({
|
|
|
4863
5239
|
|
|
4864
5240
|
// src/core-shared.ts
|
|
4865
5241
|
function isAndFilter(filter2) {
|
|
4866
|
-
return !!filter2 && (0,
|
|
5242
|
+
return !!filter2 && (0, import_utils24.isPlainObject)(filter2) && Object.keys(filter2).length === 1 && (0, import_utils24.isArray)(filter2.$and);
|
|
4867
5243
|
}
|
|
4868
5244
|
function isMergeableClause(filter2) {
|
|
4869
|
-
return !!filter2 && (0,
|
|
5245
|
+
return !!filter2 && (0, import_utils24.isPlainObject)(filter2) && Object.keys(filter2).every((key) => !key.startsWith("$"));
|
|
4870
5246
|
}
|
|
4871
5247
|
function optimizeAndFilter(clausesInput) {
|
|
4872
5248
|
const clauses = [];
|
|
@@ -4883,11 +5259,11 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4883
5259
|
const dedupeKey = (value) => {
|
|
4884
5260
|
if (value instanceof RegExp) return `regexp:${JSON.stringify([value.source, value.flags])}`;
|
|
4885
5261
|
if (value instanceof Date) return `date:${value.getTime()}`;
|
|
4886
|
-
if ((0,
|
|
5262
|
+
if ((0, import_utils24.isArray)(value)) {
|
|
4887
5263
|
const entries = Array.from(value, dedupeKey);
|
|
4888
5264
|
return entries.every((entry) => entry !== void 0) ? `array:${JSON.stringify(entries)}` : void 0;
|
|
4889
5265
|
}
|
|
4890
|
-
if ((0,
|
|
5266
|
+
if ((0, import_utils24.isPlainObject)(value)) {
|
|
4891
5267
|
const entries = Object.keys(value).sort().map((key) => [key, dedupeKey(value[key])]);
|
|
4892
5268
|
return entries.every(([, entry]) => entry !== void 0) ? `object:${JSON.stringify(entries)}` : void 0;
|
|
4893
5269
|
}
|
|
@@ -4917,7 +5293,7 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4917
5293
|
}
|
|
4918
5294
|
let canMerge = true;
|
|
4919
5295
|
for (const [key, value] of Object.entries(clause)) {
|
|
4920
|
-
if ((0,
|
|
5296
|
+
if ((0, import_utils24.hasOwn)(mergedClause, key) && !(0, import_node_util7.isDeepStrictEqual)(mergedClause[key], value)) {
|
|
4921
5297
|
canMerge = false;
|
|
4922
5298
|
break;
|
|
4923
5299
|
}
|
|
@@ -4928,24 +5304,24 @@ function optimizeAndFilter(clausesInput) {
|
|
|
4928
5304
|
}
|
|
4929
5305
|
Object.assign(mergedClause, clause);
|
|
4930
5306
|
}
|
|
4931
|
-
const finalClauses = (0,
|
|
5307
|
+
const finalClauses = (0, import_utils24.isEmpty)(mergedClause) ? remainingClauses : [mergedClause, ...remainingClauses];
|
|
4932
5308
|
if (finalClauses.length === 0) return null;
|
|
4933
5309
|
if (finalClauses.length === 1) return finalClauses[0];
|
|
4934
5310
|
return { $and: finalClauses };
|
|
4935
5311
|
}
|
|
4936
5312
|
function normalizeFilter(filter2) {
|
|
4937
5313
|
if (filter2 === false) return false;
|
|
4938
|
-
if (!filter2 || !(0,
|
|
5314
|
+
if (!filter2 || !(0, import_utils24.isPlainObject)(filter2) || (0, import_utils24.isEmpty)(filter2)) return null;
|
|
4939
5315
|
if (!isAndFilter(filter2)) {
|
|
4940
5316
|
return filter2;
|
|
4941
5317
|
}
|
|
4942
5318
|
return optimizeAndFilter(filter2.$and);
|
|
4943
5319
|
}
|
|
4944
5320
|
async function resolveIdentifierFilter(req, idField, resolveIdFilter, id) {
|
|
4945
|
-
if ((0,
|
|
5321
|
+
if ((0, import_utils24.isFunction)(resolveIdFilter)) {
|
|
4946
5322
|
return await resolveIdFilter.call(req, id);
|
|
4947
5323
|
}
|
|
4948
|
-
if ((0,
|
|
5324
|
+
if ((0, import_utils24.isString)(idField)) {
|
|
4949
5325
|
return { [idField]: id };
|
|
4950
5326
|
}
|
|
4951
5327
|
return { _id: id };
|
|
@@ -4969,7 +5345,7 @@ async function resolveAccessFilterParts({
|
|
|
4969
5345
|
}
|
|
4970
5346
|
const overrideFilterFn = getOption(`overrideFilter.${access}`, null);
|
|
4971
5347
|
const baseFilterFn = rows2.mode === "request" ? getOption(`baseFilter.${access}`, null) : null;
|
|
4972
|
-
if (nextFilter !== false && (0,
|
|
5348
|
+
if (nextFilter !== false && (0, import_utils24.isFunction)(overrideFilterFn)) {
|
|
4973
5349
|
nextFilter = normalizeFilter(await overrideFilterFn.call(req, nextFilter, permissions));
|
|
4974
5350
|
}
|
|
4975
5351
|
if (nextFilter === false) return { transformed: false, scope: {}, filter: false };
|
|
@@ -4977,7 +5353,7 @@ async function resolveAccessFilterParts({
|
|
|
4977
5353
|
const scope2 = rows2.mode === "scope" ? rows2.filter : {};
|
|
4978
5354
|
return { transformed: nextFilter ?? {}, scope: scope2, filter: intersectFilters(nextFilter, scope2) };
|
|
4979
5355
|
}
|
|
4980
|
-
if (!(0,
|
|
5356
|
+
if (!(0, import_utils24.isFunction)(baseFilterFn)) return { transformed: nextFilter ?? {}, scope: {}, filter: nextFilter ?? {} };
|
|
4981
5357
|
const cached = cache.get(cacheKey);
|
|
4982
5358
|
const reusable = cached?.resolver === baseFilterFn;
|
|
4983
5359
|
const baseFilter = normalizeFilter(
|
|
@@ -5012,34 +5388,34 @@ async function setRequestPermissions(req) {
|
|
|
5012
5388
|
if (owner === activeRuntime) return;
|
|
5013
5389
|
if (hasFieldValue && owner === void 0) return;
|
|
5014
5390
|
const globalPermissions = getGlobalOption("globalPermissions");
|
|
5015
|
-
const permissions = (0,
|
|
5016
|
-
if ((0,
|
|
5017
|
-
else if ((0,
|
|
5018
|
-
else if ((0,
|
|
5391
|
+
const permissions = (0, import_utils24.isFunction)(globalPermissions) ? await globalPermissions.call(req, req) : void 0;
|
|
5392
|
+
if ((0, import_utils24.isPlainObject)(permissions)) req[requestPermissionField] = permissions;
|
|
5393
|
+
else if ((0, import_utils24.isArray)(permissions)) req[requestPermissionField] = (0, import_utils24.arrayToRecord)(permissions);
|
|
5394
|
+
else if ((0, import_utils24.isString)(permissions)) req[requestPermissionField] = { [permissions]: true };
|
|
5019
5395
|
else req[requestPermissionField] = {};
|
|
5020
5396
|
owners.set(requestPermissionField, activeRuntime);
|
|
5021
5397
|
}
|
|
5022
5398
|
async function evaluateRouteGuard(req, permissions, routeGuard) {
|
|
5023
5399
|
const phas = (key) => permissions.has(key);
|
|
5024
5400
|
const { stringHandler, arrayHandler } = createValidator(phas);
|
|
5025
|
-
if ((0,
|
|
5401
|
+
if ((0, import_utils24.isBoolean)(routeGuard)) {
|
|
5026
5402
|
return routeGuard === true;
|
|
5027
5403
|
}
|
|
5028
|
-
if ((0,
|
|
5404
|
+
if ((0, import_utils24.isString)(routeGuard)) {
|
|
5029
5405
|
return stringHandler(routeGuard);
|
|
5030
5406
|
}
|
|
5031
|
-
if ((0,
|
|
5407
|
+
if ((0, import_utils24.isArray)(routeGuard)) {
|
|
5032
5408
|
return arrayHandler(routeGuard);
|
|
5033
5409
|
}
|
|
5034
|
-
if ((0,
|
|
5410
|
+
if ((0, import_utils24.isFunction)(routeGuard)) {
|
|
5035
5411
|
return routeGuard.call(req, permissions);
|
|
5036
5412
|
}
|
|
5037
5413
|
return false;
|
|
5038
5414
|
}
|
|
5039
5415
|
async function callHookChain(req, hook, doc, permissions, context) {
|
|
5040
|
-
const hooks = (0,
|
|
5416
|
+
const hooks = (0, import_utils24.castArray)(hook);
|
|
5041
5417
|
for (let x = 0; x < hooks.length; x++) {
|
|
5042
|
-
if ((0,
|
|
5418
|
+
if ((0, import_utils24.isFunction)(hooks[x])) {
|
|
5043
5419
|
doc = await hooks[x].call(req, doc, permissions, context);
|
|
5044
5420
|
}
|
|
5045
5421
|
}
|
|
@@ -5059,23 +5435,23 @@ async function collectSchemaFields({
|
|
|
5059
5435
|
for (let x = 0; x < keys2.length; x++) {
|
|
5060
5436
|
const key = keys2[x];
|
|
5061
5437
|
const value = extractScopedOutputRule(permissionSchema, key, access);
|
|
5062
|
-
if ((0,
|
|
5438
|
+
if ((0, import_utils24.isBoolean)(value)) {
|
|
5063
5439
|
if (value) fields.push(key);
|
|
5064
|
-
} else if ((0,
|
|
5440
|
+
} else if ((0, import_utils24.isString)(value)) {
|
|
5065
5441
|
if (stringHandler(value)) fields.push(key);
|
|
5066
|
-
} else if ((0,
|
|
5442
|
+
} else if ((0, import_utils24.isArray)(value)) {
|
|
5067
5443
|
if (arrayHandler(value)) fields.push(key);
|
|
5068
|
-
} else if ((0,
|
|
5444
|
+
} else if ((0, import_utils24.isFunction)(value)) {
|
|
5069
5445
|
if (await value.call(req, ...functionArgs)) fields.push(key);
|
|
5070
5446
|
}
|
|
5071
5447
|
}
|
|
5072
5448
|
return fields;
|
|
5073
5449
|
}
|
|
5074
|
-
var
|
|
5450
|
+
var import_utils24, import_node_util7, permissionFieldOwners;
|
|
5075
5451
|
var init_core_shared = __esm({
|
|
5076
5452
|
"src/core-shared.ts"() {
|
|
5077
|
-
|
|
5078
|
-
|
|
5453
|
+
import_utils24 = require("@web-ts-toolkit/utils");
|
|
5454
|
+
import_node_util7 = require("util");
|
|
5079
5455
|
init_helpers();
|
|
5080
5456
|
init_options();
|
|
5081
5457
|
init_runtime_context();
|
|
@@ -5443,8 +5819,8 @@ function equivalentVirtualPopulatePredicate(left, right) {
|
|
|
5443
5819
|
}
|
|
5444
5820
|
if (Array.isArray(left) || Array.isArray(right))
|
|
5445
5821
|
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,
|
|
5822
|
+
if ((0, import_utils28.isPlainObject)(left) || (0, import_utils28.isPlainObject)(right)) {
|
|
5823
|
+
if (!(0, import_utils28.isPlainObject)(left) || !(0, import_utils28.isPlainObject)(right)) return false;
|
|
5448
5824
|
const a = Object.keys(left), b = Object.keys(right);
|
|
5449
5825
|
return a.length === b.length && a.every(
|
|
5450
5826
|
(key, index) => key === b[index] && equivalentVirtualPopulatePredicate(
|
|
@@ -5453,7 +5829,7 @@ function equivalentVirtualPopulatePredicate(left, right) {
|
|
|
5453
5829
|
)
|
|
5454
5830
|
);
|
|
5455
5831
|
}
|
|
5456
|
-
return (0,
|
|
5832
|
+
return (0, import_node_util8.isDeepStrictEqual)(left, right);
|
|
5457
5833
|
}
|
|
5458
5834
|
function createVirtualPopulateBatch(owner) {
|
|
5459
5835
|
const batch = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
@@ -5828,12 +6204,12 @@ async function loadVirtualPopulateOutputRows(owner, inputs, plan, publicPopulate
|
|
|
5828
6204
|
}
|
|
5829
6205
|
return output;
|
|
5830
6206
|
}
|
|
5831
|
-
var import_mongoose7,
|
|
6207
|
+
var import_mongoose7, import_node_util8, import_utils28, batches, rows, outputRows, fetchedPublicIdentities, publicViewIdentities, familyRawFetches, addressKey, storage, originalRef, copyOriginalValue, readPolicy, compatible, idKey, logUnavailable;
|
|
5832
6208
|
var init_virtual_populate_execution = __esm({
|
|
5833
6209
|
"src/acl/virtual-populate-execution.ts"() {
|
|
5834
6210
|
import_mongoose7 = require("mongoose");
|
|
5835
|
-
|
|
5836
|
-
|
|
6211
|
+
import_node_util8 = require("util");
|
|
6212
|
+
import_utils28 = require("@web-ts-toolkit/utils");
|
|
5837
6213
|
init_cache();
|
|
5838
6214
|
init_core_shared();
|
|
5839
6215
|
init_document();
|
|
@@ -5850,7 +6226,7 @@ var init_virtual_populate_execution = __esm({
|
|
|
5850
6226
|
publicViewIdentities = /* @__PURE__ */ new WeakMap();
|
|
5851
6227
|
familyRawFetches = /* @__PURE__ */ new WeakMap();
|
|
5852
6228
|
addressKey = (address) => JSON.stringify(address);
|
|
5853
|
-
storage = (value) => value instanceof import_mongoose7.Document ? value._doc : (0,
|
|
6229
|
+
storage = (value) => value instanceof import_mongoose7.Document ? value._doc : (0, import_utils28.isPlainObject)(value) ? value : void 0;
|
|
5854
6230
|
originalRef = (source, key) => {
|
|
5855
6231
|
const record3 = storage(source);
|
|
5856
6232
|
return {
|
|
@@ -5877,75 +6253,8 @@ var init_virtual_populate_execution = __esm({
|
|
|
5877
6253
|
});
|
|
5878
6254
|
|
|
5879
6255
|
// 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
6256
|
function assertOwningOutputDocuments(handle) {
|
|
5948
|
-
const owner =
|
|
6257
|
+
const owner = readOutputDocumentOwner(handle);
|
|
5949
6258
|
if (owner) {
|
|
5950
6259
|
readDocumentAuthorizationAccess(owner.handle, owner.binding);
|
|
5951
6260
|
assertOwningOutputDocuments(owner.handle);
|
|
@@ -5955,7 +6264,7 @@ function prepareOutputDocumentAuthorization(authorization, binding, configuratio
|
|
|
5955
6264
|
const access = readServiceAuthorizationAccess(authorization, binding);
|
|
5956
6265
|
const key = `docPermissions.${access.docPermissionsAccess}`;
|
|
5957
6266
|
const docPermissions = configuration.docPermissions;
|
|
5958
|
-
const invariant = /^[A-Za-z0-9_-]+$/.test(access.docPermissionsAccess) && (docPermissions == null || (0,
|
|
6267
|
+
const invariant = /^[A-Za-z0-9_-]+$/.test(access.docPermissionsAccess) && (docPermissions == null || (0, import_utils29.isPlainObject)(docPermissions));
|
|
5959
6268
|
const option = invariant ? getCapturedAuthorizationOption(configuration, key) : void 0;
|
|
5960
6269
|
const hook = typeof option === "function" ? option : void 0;
|
|
5961
6270
|
const resolveHook = invariant ? () => hook : () => {
|
|
@@ -5985,7 +6294,7 @@ async function resolveOutputDocumentAuthorizationWithHook(args, access, resolveH
|
|
|
5985
6294
|
try {
|
|
5986
6295
|
const run = () => hook.call(this, doc, permissions, args.context);
|
|
5987
6296
|
const grants = await getRequestWorkState(binding.request, binding.runtime).hookGate.run(run);
|
|
5988
|
-
return (0,
|
|
6297
|
+
return (0, import_utils29.isPlainObject)(grants) ? grants : {};
|
|
5989
6298
|
} catch (error2) {
|
|
5990
6299
|
warn("docPermissions hook failed; applying empty document permissions", {
|
|
5991
6300
|
modelName: binding.modelName,
|
|
@@ -5996,14 +6305,12 @@ async function resolveOutputDocumentAuthorizationWithHook(args, access, resolveH
|
|
|
5996
6305
|
return {};
|
|
5997
6306
|
}
|
|
5998
6307
|
});
|
|
5999
|
-
|
|
6000
|
-
unresolvedDocuments.add(handle);
|
|
6001
|
-
if (args.owningDocument) owningDocuments.set(handle, { handle: args.owningDocument, binding: args.owningBinding });
|
|
6308
|
+
bindOutputDocumentOwner(handle, args.knownOutput, args.owningDocument, args.owningBinding);
|
|
6002
6309
|
return handle;
|
|
6003
6310
|
}
|
|
6004
6311
|
function evaluateRequestRule(handle, binding, entry, prefix, access) {
|
|
6005
6312
|
assertOwningOutputDocuments(handle);
|
|
6006
|
-
const owner =
|
|
6313
|
+
const owner = readOutputDocumentOwner(handle);
|
|
6007
6314
|
if (owner && !entry.path.startsWith(`${(binding.scopePath ?? []).join(".")}.`)) {
|
|
6008
6315
|
return evaluateRequestRule(owner.handle, owner.binding, entry, prefix, access);
|
|
6009
6316
|
}
|
|
@@ -6037,7 +6344,7 @@ function evaluateAuthorizedOutputField(handle, binding, field) {
|
|
|
6037
6344
|
const policy = callFieldPolicy(authorization, binding);
|
|
6038
6345
|
const { outputAccess } = readDocumentAuthorizationAccess(handle, binding);
|
|
6039
6346
|
const prepared = prepareOutputPath(policy, authorization, binding, path, outputAccess);
|
|
6040
|
-
const unresolved =
|
|
6347
|
+
const unresolved = isUnresolvedOutputDocument(handle);
|
|
6041
6348
|
const state = unresolved ? prepared.state ?? classifyEffectiveFieldAuthorization({
|
|
6042
6349
|
path,
|
|
6043
6350
|
rules: prepared.entries.map((entry) => entry.rule),
|
|
@@ -6060,12 +6367,18 @@ function evaluateAuthorizedOutputField(handle, binding, field) {
|
|
|
6060
6367
|
assertOwningOutputDocuments(handle);
|
|
6061
6368
|
return allowed;
|
|
6062
6369
|
});
|
|
6063
|
-
return
|
|
6370
|
+
return readOutputDocumentOwner(handle) ? decision.then((allowed) => {
|
|
6064
6371
|
assertOwningOutputDocuments(handle);
|
|
6065
6372
|
return allowed;
|
|
6066
6373
|
}) : decision;
|
|
6067
6374
|
}
|
|
6068
6375
|
async function requestOutputFieldPaths(handle, binding, access) {
|
|
6376
|
+
const staticFields = tryStaticRequestFieldPaths(handle, binding, access);
|
|
6377
|
+
if (staticFields) {
|
|
6378
|
+
await Promise.resolve();
|
|
6379
|
+
readDocumentAuthorizationAccess(handle, binding);
|
|
6380
|
+
return staticFields;
|
|
6381
|
+
}
|
|
6069
6382
|
const { authorization } = readDocumentAuthorizationAccess(handle, binding);
|
|
6070
6383
|
assertOwningOutputDocuments(handle);
|
|
6071
6384
|
const policy = callFieldPolicy(authorization, binding);
|
|
@@ -6114,7 +6427,7 @@ function copyOutputValue(value, plan, path) {
|
|
|
6114
6427
|
const visit = (input, current) => {
|
|
6115
6428
|
if (Array.isArray(input)) return input.map((entry) => visit(entry, current));
|
|
6116
6429
|
if (input instanceof Map) return visit(Object.fromEntries(input), current);
|
|
6117
|
-
if (!(0,
|
|
6430
|
+
if (!(0, import_utils29.isPlainObject)(input)) return deepIsolateValue(input);
|
|
6118
6431
|
const output = {};
|
|
6119
6432
|
for (const [key, entry] of Object.entries(input)) {
|
|
6120
6433
|
const child = `${current}.${key}`;
|
|
@@ -6130,7 +6443,7 @@ function copyOutputValue(value, plan, path) {
|
|
|
6130
6443
|
}
|
|
6131
6444
|
function copyAuthorizedReference(value, plan, path) {
|
|
6132
6445
|
if (Array.isArray(value)) return value.map((entry) => copyAuthorizedReference(entry, plan, path));
|
|
6133
|
-
if (!(0,
|
|
6446
|
+
if (!(0, import_utils29.isPlainObject)(value)) return deepIsolateValue(value);
|
|
6134
6447
|
const handle = getAssociatedDocumentAuthorization(value, plan.authorization);
|
|
6135
6448
|
if (handle) {
|
|
6136
6449
|
const copy = deepIsolateValue(value);
|
|
@@ -6143,8 +6456,8 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6143
6456
|
if (scope2.length || configuration.stripPermissionsField) return;
|
|
6144
6457
|
const parts = (configuration.documentPermissionField ?? "_permissions").split(".");
|
|
6145
6458
|
let value = source;
|
|
6146
|
-
for (const part of parts) value = (0,
|
|
6147
|
-
if (!(0,
|
|
6459
|
+
for (const part of parts) value = (0, import_utils29.isPlainObject)(value) ? value[part] : void 0;
|
|
6460
|
+
if (!(0, import_utils29.isPlainObject)(value)) return;
|
|
6148
6461
|
const keys2 = configuration.exposedDocPermissionKeys;
|
|
6149
6462
|
const metadata = Object.fromEntries(
|
|
6150
6463
|
Object.entries(value).filter(
|
|
@@ -6154,7 +6467,7 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6154
6467
|
const copy = { ...output };
|
|
6155
6468
|
let target = copy;
|
|
6156
6469
|
for (const part of parts.slice(0, -1)) {
|
|
6157
|
-
target[part] = (0,
|
|
6470
|
+
target[part] = (0, import_utils29.isPlainObject)(target[part]) ? { ...target[part] } : {};
|
|
6158
6471
|
target = target[part];
|
|
6159
6472
|
}
|
|
6160
6473
|
target[parts[parts.length - 1]] = deepIsolateValue(metadata);
|
|
@@ -6163,27 +6476,37 @@ function retainOutputMetadata(output, source, configuration, scope2) {
|
|
|
6163
6476
|
attachPermissionsAlias(output, parts.join("."));
|
|
6164
6477
|
}
|
|
6165
6478
|
function helperPlan(authorization, binding) {
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6479
|
+
return planAuthorizedModelProjection({ authorization, binding, effectiveSelect: [] });
|
|
6480
|
+
}
|
|
6481
|
+
function primitiveHelperFields(source, plan) {
|
|
6482
|
+
if (import_node_util9.types.isProxy(source)) return;
|
|
6483
|
+
const canonical = readStaticOutputPlanFields(plan, plan.authorization);
|
|
6484
|
+
if (!canonical) return;
|
|
6485
|
+
const fields = [];
|
|
6486
|
+
for (const field of canonical) {
|
|
6487
|
+
const slot = Object.getOwnPropertyDescriptor(source, field);
|
|
6488
|
+
if (!slot) continue;
|
|
6489
|
+
if (!("value" in slot)) return;
|
|
6490
|
+
const value = slot.value;
|
|
6491
|
+
if (value !== null && typeof value === "object" || typeof value === "function" || typeof value === "symbol")
|
|
6492
|
+
return;
|
|
6493
|
+
if (value !== void 0) fields.push(field);
|
|
6494
|
+
}
|
|
6495
|
+
return fields;
|
|
6181
6496
|
}
|
|
6182
6497
|
async function filterExistingOutput(source, plan, handle, associated) {
|
|
6183
6498
|
const binding = plan.authorizationBinding;
|
|
6184
6499
|
const { configuration } = readServiceAuthorization(plan.authorization, binding);
|
|
6185
6500
|
const output = {};
|
|
6186
6501
|
const fields = [];
|
|
6502
|
+
const primitiveFields = primitiveHelperFields(source, plan);
|
|
6503
|
+
const staticDecisions = primitiveFields && tryStaticOutputFieldDecisions(handle, binding, plan, primitiveFields);
|
|
6504
|
+
if (staticDecisions) {
|
|
6505
|
+
await Promise.resolve();
|
|
6506
|
+
if (associated) assertDocumentAuthorization(handle, { binding, output: source, outputAccess: plan.outputAccess });
|
|
6507
|
+
else readDocumentAuthorizationAccess(handle, binding);
|
|
6508
|
+
if (!readStaticOutputPlanFields(plan, plan.authorization)) authorizationError("changed static output plan");
|
|
6509
|
+
}
|
|
6187
6510
|
for (const field of /* @__PURE__ */ new Set([...plan.outputPersistedFields, ...plan.outputVirtualNames])) {
|
|
6188
6511
|
if (!Object.prototype.hasOwnProperty.call(source, field) || source[field] === void 0) continue;
|
|
6189
6512
|
const childPlan = plan.childPlans[field];
|
|
@@ -6196,7 +6519,7 @@ async function filterExistingOutput(source, plan, handle, associated) {
|
|
|
6196
6519
|
for (const entry of value2) values.push(await one(entry) ?? null);
|
|
6197
6520
|
return values;
|
|
6198
6521
|
}
|
|
6199
|
-
if (!(0,
|
|
6522
|
+
if (!(0, import_utils29.isPlainObject)(value2)) return value2 === null ? null : void 0;
|
|
6200
6523
|
const childHandle = associated ? getAssociatedDocumentAuthorization(value2) : void 0;
|
|
6201
6524
|
let child = scoped;
|
|
6202
6525
|
if (childHandle) {
|
|
@@ -6224,7 +6547,7 @@ async function filterExistingOutput(source, plan, handle, associated) {
|
|
|
6224
6547
|
const value = await one(source[field]);
|
|
6225
6548
|
if (value !== void 0) output[field] = value;
|
|
6226
6549
|
fields.push(...childFields);
|
|
6227
|
-
} else if (await evaluateAuthorizedOutputField(handle, binding, field)) {
|
|
6550
|
+
} else if (staticDecisions ? staticDecisions.get(field) === true : await evaluateAuthorizedOutputField(handle, binding, field)) {
|
|
6228
6551
|
const path = [...binding.scopePath ?? [], field].join(".");
|
|
6229
6552
|
output[field] = configuration.catalog.referencePaths?.some((p) => matchesCatalogPattern(p, path)) ? copyAuthorizedReference(source[field], plan, path) : copyOutputValue(source[field], plan, path);
|
|
6230
6553
|
if (associated) transferDocumentAuthorizationGraph(source[field], output[field]);
|
|
@@ -6276,7 +6599,7 @@ async function filterModelOutputForHelper(args) {
|
|
|
6276
6599
|
const plan = helperPlan(normalized.authorization, binding);
|
|
6277
6600
|
if (args.doc == null) return { output: args.doc, fields: [] };
|
|
6278
6601
|
const source = isolateDocForOutput(args.doc);
|
|
6279
|
-
if (!(0,
|
|
6602
|
+
if (!(0, import_utils29.isPlainObject)(source)) return authorizationError("output helper requires one plain or hydrated document");
|
|
6280
6603
|
const knownOutput = !!args.doc && typeof args.doc === "object" && isKnownAuthorizationOutput(args.doc);
|
|
6281
6604
|
const handle = await resolveOutputDocumentAuthorization({
|
|
6282
6605
|
authorization: normalized.authorization,
|
|
@@ -6287,10 +6610,11 @@ async function filterModelOutputForHelper(args) {
|
|
|
6287
6610
|
});
|
|
6288
6611
|
return filterExistingOutput(source, plan, handle, false);
|
|
6289
6612
|
}
|
|
6290
|
-
var
|
|
6613
|
+
var import_node_util9, import_utils29;
|
|
6291
6614
|
var init_output_field_filter = __esm({
|
|
6292
6615
|
"src/acl/output-field-filter.ts"() {
|
|
6293
|
-
|
|
6616
|
+
import_node_util9 = require("util");
|
|
6617
|
+
import_utils29 = require("@web-ts-toolkit/utils");
|
|
6294
6618
|
init_permissions_alias();
|
|
6295
6619
|
init_document();
|
|
6296
6620
|
init_request_work();
|
|
@@ -6302,9 +6626,7 @@ var init_output_field_filter = __esm({
|
|
|
6302
6626
|
init_field_authorization();
|
|
6303
6627
|
init_field_catalog();
|
|
6304
6628
|
init_output_projection();
|
|
6305
|
-
|
|
6306
|
-
owningDocuments = /* @__PURE__ */ new WeakMap();
|
|
6307
|
-
fieldPolicies = /* @__PURE__ */ new WeakMap();
|
|
6629
|
+
init_output_field_policy();
|
|
6308
6630
|
}
|
|
6309
6631
|
});
|
|
6310
6632
|
|
|
@@ -6414,8 +6736,8 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6414
6736
|
const privateRow = args.virtualPopulateRow ?? (original && typeof original === "object" ? getVirtualPopulateRow(original) : void 0);
|
|
6415
6737
|
const privateAddress = args.virtualPopulateAddress ?? [];
|
|
6416
6738
|
const isolated = isolateDocForOutput(input);
|
|
6417
|
-
const output = (0,
|
|
6418
|
-
if (captured && (0,
|
|
6739
|
+
const output = (0, import_utils30.isPlainObject)(isolated) ? isolated : {};
|
|
6740
|
+
if (captured && (0, import_utils30.isPlainObject)(input))
|
|
6419
6741
|
for (const key of Object.keys(output)) {
|
|
6420
6742
|
transferDocumentAuthorizationGraph(input[key], output[key]);
|
|
6421
6743
|
}
|
|
@@ -6467,7 +6789,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6467
6789
|
);
|
|
6468
6790
|
continue;
|
|
6469
6791
|
}
|
|
6470
|
-
if (captured && !(0,
|
|
6792
|
+
if (captured && !(0, import_utils30.isPlainObject)(rawContainer) && !Array.isArray(rawContainer)) {
|
|
6471
6793
|
delete output[containerName];
|
|
6472
6794
|
continue;
|
|
6473
6795
|
}
|
|
@@ -6493,7 +6815,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6493
6815
|
const finalizeOneChild = async (rawChild, address) => {
|
|
6494
6816
|
if (captured && Array.isArray(rawChild))
|
|
6495
6817
|
return mapWithConcurrencyLimit(rawChild, limit, (entry, index) => finalizeOneChild(entry, [...address, index]));
|
|
6496
|
-
if (!(0,
|
|
6818
|
+
if (!(0, import_utils30.isPlainObject)(rawChild) && !Array.isArray(rawChild)) return captured ? null : deepIsolateValue(rawChild);
|
|
6497
6819
|
if (args.traversal?.finalizeEmbeddedChildren) {
|
|
6498
6820
|
return args.traversal.finalizeEmbeddedChildren({
|
|
6499
6821
|
containerName,
|
|
@@ -6526,7 +6848,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6526
6848
|
(entry, index) => finalizeOneChild(entry, [...privateAddress, containerName, index])
|
|
6527
6849
|
);
|
|
6528
6850
|
output[containerName] = finalized;
|
|
6529
|
-
} else if ((0,
|
|
6851
|
+
} else if ((0, import_utils30.isPlainObject)(rawContainer)) {
|
|
6530
6852
|
output[containerName] = await finalizeOneChild(rawContainer, [
|
|
6531
6853
|
...privateAddress,
|
|
6532
6854
|
containerName
|
|
@@ -6538,8 +6860,8 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6538
6860
|
let rawRelated;
|
|
6539
6861
|
let originalRelated;
|
|
6540
6862
|
try {
|
|
6541
|
-
rawRelated = target.path.includes(".") ? (0,
|
|
6542
|
-
originalRelated = (0,
|
|
6863
|
+
rawRelated = target.path.includes(".") ? (0, import_utils30.get)(output, target.path) : output[target.path];
|
|
6864
|
+
originalRelated = (0, import_utils30.get)(original, target.path);
|
|
6543
6865
|
} catch {
|
|
6544
6866
|
continue;
|
|
6545
6867
|
}
|
|
@@ -6571,7 +6893,7 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6571
6893
|
};
|
|
6572
6894
|
let relatedPreparation;
|
|
6573
6895
|
const finalizeOneRelated = async (rawChild, originalChild = rawChild) => {
|
|
6574
|
-
if (!(0,
|
|
6896
|
+
if (!(0, import_utils30.isPlainObject)(rawChild) && !Array.isArray(rawChild)) return rawChild;
|
|
6575
6897
|
if (typeof rawChild?._bsontype === "string") return rawChild;
|
|
6576
6898
|
const childOriginal = getIncludeOriginal(originalChild);
|
|
6577
6899
|
const childRow = childOriginal && typeof childOriginal === "object" ? getVirtualPopulateRow(childOriginal) : void 0;
|
|
@@ -6596,13 +6918,13 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6596
6918
|
limit,
|
|
6597
6919
|
(entry, index) => finalizeOneRelated(entry, Array.isArray(originalRelated) ? originalRelated[index] : void 0)
|
|
6598
6920
|
);
|
|
6599
|
-
} else if ((0,
|
|
6921
|
+
} else if ((0, import_utils30.isPlainObject)(rawRelated)) {
|
|
6600
6922
|
finalized = await finalizeOneRelated(rawRelated, originalRelated);
|
|
6601
6923
|
} else {
|
|
6602
6924
|
continue;
|
|
6603
6925
|
}
|
|
6604
6926
|
try {
|
|
6605
|
-
if (target.path.includes(".")) (0,
|
|
6927
|
+
if (target.path.includes(".")) (0, import_utils30.set)(output, target.path, finalized);
|
|
6606
6928
|
else output[target.path] = finalized;
|
|
6607
6929
|
} catch {
|
|
6608
6930
|
}
|
|
@@ -6681,10 +7003,17 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6681
7003
|
}
|
|
6682
7004
|
const eligiblePersisted = new Set(plan.outputPersistedFields ?? []);
|
|
6683
7005
|
const eligibleVirtuals = new Set(plan.outputVirtualNames ?? []);
|
|
7006
|
+
const staticDecisions = documentAuthorization ? tryStaticOutputFieldDecisions(documentAuthorization, binding, plan, [...eligiblePersisted]) : void 0;
|
|
7007
|
+
if (staticDecisions) {
|
|
7008
|
+
await Promise.resolve();
|
|
7009
|
+
assertFinalizerCall(args, prepared);
|
|
7010
|
+
readDocumentAuthorizationAccess(documentAuthorization, binding);
|
|
7011
|
+
if (!readStaticOutputPlanFields(plan, prepared.authorization)) authorizationError("changed static output plan");
|
|
7012
|
+
}
|
|
6684
7013
|
const allowedPersisted = [];
|
|
6685
7014
|
for (const field of eligiblePersisted) {
|
|
6686
7015
|
if (documentAuthorization) {
|
|
6687
|
-
if (plan.childPlans[field] || await evaluateAuthorizedOutputField(documentAuthorization, binding, field))
|
|
7016
|
+
if (plan.childPlans[field] || (staticDecisions ? staticDecisions.get(field) === true : await evaluateAuthorizedOutputField(documentAuthorization, binding, field)))
|
|
6688
7017
|
allowedPersisted.push(field);
|
|
6689
7018
|
continue;
|
|
6690
7019
|
}
|
|
@@ -6762,6 +7091,10 @@ async function finalizeSingleDoc(args, input, prepared) {
|
|
|
6762
7091
|
stage: readDocumentAuthorizationAccess(documentAuthorization, binding).stage
|
|
6763
7092
|
})
|
|
6764
7093
|
);
|
|
7094
|
+
if (staticDecisions) {
|
|
7095
|
+
assertFinalizerCall(args, prepared);
|
|
7096
|
+
readDocumentAuthorizationAccess(documentAuthorization, binding);
|
|
7097
|
+
}
|
|
6765
7098
|
}
|
|
6766
7099
|
void getRetainedAssociations;
|
|
6767
7100
|
return trimmed;
|
|
@@ -6809,10 +7142,10 @@ async function finalizeModelOutputs(args) {
|
|
|
6809
7142
|
);
|
|
6810
7143
|
});
|
|
6811
7144
|
}
|
|
6812
|
-
var
|
|
7145
|
+
var import_utils30, isVirtualContainerValue3, getScopeVirtualsObject2, getScopeVirtualNames, getScopedPermissionSchema2, resolveGlobalPermissions, resolveDocPermissions, isAbsentDependency, __finalizeInternals;
|
|
6813
7146
|
var init_finalize_model_output = __esm({
|
|
6814
7147
|
"src/output/finalize-model-output.ts"() {
|
|
6815
|
-
|
|
7148
|
+
import_utils30 = require("@web-ts-toolkit/utils");
|
|
6816
7149
|
init_document();
|
|
6817
7150
|
init_concurrency();
|
|
6818
7151
|
init_request_work();
|
|
@@ -6823,22 +7156,23 @@ var init_finalize_model_output = __esm({
|
|
|
6823
7156
|
init_output_field_filter();
|
|
6824
7157
|
init_field_authorization();
|
|
6825
7158
|
init_field_catalog();
|
|
7159
|
+
init_output_projection();
|
|
6826
7160
|
init_virtual_populate_execution();
|
|
6827
7161
|
init_include_output();
|
|
6828
|
-
isVirtualContainerValue3 = (value) => (0,
|
|
7162
|
+
isVirtualContainerValue3 = (value) => (0, import_utils30.isPlainObject)(value) && "sub" in value;
|
|
6829
7163
|
getScopeVirtualsObject2 = (rootVirtuals, scopePath) => {
|
|
6830
|
-
if (!rootVirtuals || !(0,
|
|
7164
|
+
if (!rootVirtuals || !(0, import_utils30.isPlainObject)(rootVirtuals)) return null;
|
|
6831
7165
|
if (scopePath.length === 0) return rootVirtuals;
|
|
6832
7166
|
let current = rootVirtuals;
|
|
6833
7167
|
for (let i = 0; i < scopePath.length; i += 2) {
|
|
6834
7168
|
const field = scopePath[i];
|
|
6835
7169
|
const subMarker = scopePath[i + 1];
|
|
6836
7170
|
if (!field || subMarker !== "sub") return null;
|
|
6837
|
-
if (!(0,
|
|
7171
|
+
if (!(0, import_utils30.isPlainObject)(current)) return null;
|
|
6838
7172
|
const container = current[field];
|
|
6839
7173
|
if (!isVirtualContainerValue3(container)) return null;
|
|
6840
7174
|
current = container.sub;
|
|
6841
|
-
if (!(0,
|
|
7175
|
+
if (!(0, import_utils30.isPlainObject)(current)) return null;
|
|
6842
7176
|
}
|
|
6843
7177
|
return current;
|
|
6844
7178
|
};
|
|
@@ -6851,11 +7185,11 @@ var init_finalize_model_output = __esm({
|
|
|
6851
7185
|
return Object.entries(scopeVirtuals).filter(([, v]) => v !== void 0 && !isVirtualContainerValue3(v)).map(([k]) => k);
|
|
6852
7186
|
};
|
|
6853
7187
|
getScopedPermissionSchema2 = (root, scopePath) => {
|
|
6854
|
-
if (!root || !(0,
|
|
7188
|
+
if (!root || !(0, import_utils30.isPlainObject)(root)) return null;
|
|
6855
7189
|
if (scopePath.length === 0) return root;
|
|
6856
7190
|
try {
|
|
6857
|
-
const scoped = (0,
|
|
6858
|
-
return (0,
|
|
7191
|
+
const scoped = (0, import_utils30.get)(root, scopePath.join("."));
|
|
7192
|
+
return (0, import_utils30.isPlainObject)(scoped) ? scoped : null;
|
|
6859
7193
|
} catch {
|
|
6860
7194
|
return null;
|
|
6861
7195
|
}
|
|
@@ -6914,7 +7248,7 @@ var init_finalize_model_output = __esm({
|
|
|
6914
7248
|
const grants = await args.sharedGate.run(
|
|
6915
7249
|
() => hook.call(args.request, isolatedForHook, globalPerms, scopeContext)
|
|
6916
7250
|
);
|
|
6917
|
-
const normalized = (0,
|
|
7251
|
+
const normalized = (0, import_utils30.isPlainObject)(grants) ? grants : {};
|
|
6918
7252
|
scopeContext.docPermissions = normalized;
|
|
6919
7253
|
return normalized;
|
|
6920
7254
|
}
|
|
@@ -6986,20 +7320,20 @@ __export(index_exports, {
|
|
|
6986
7320
|
setModelOptions: () => setModelOptions
|
|
6987
7321
|
});
|
|
6988
7322
|
module.exports = __toCommonJS(index_exports);
|
|
6989
|
-
var
|
|
7323
|
+
var import_utils48 = require("@web-ts-toolkit/utils");
|
|
6990
7324
|
|
|
6991
7325
|
// src/middleware.ts
|
|
6992
7326
|
var import_express_json_router5 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
6993
|
-
var
|
|
7327
|
+
var import_utils41 = require("@web-ts-toolkit/utils");
|
|
6994
7328
|
|
|
6995
7329
|
// src/core.ts
|
|
6996
7330
|
init_public_admission();
|
|
6997
|
-
var
|
|
7331
|
+
var import_utils40 = require("@web-ts-toolkit/utils");
|
|
6998
7332
|
init_options();
|
|
6999
7333
|
init_permission();
|
|
7000
7334
|
|
|
7001
7335
|
// src/services/base.ts
|
|
7002
|
-
var
|
|
7336
|
+
var import_utils25 = require("@web-ts-toolkit/utils");
|
|
7003
7337
|
init_options();
|
|
7004
7338
|
init_helpers();
|
|
7005
7339
|
init_document();
|
|
@@ -7125,7 +7459,7 @@ function requestFieldScope(options) {
|
|
|
7125
7459
|
init_public_admission();
|
|
7126
7460
|
|
|
7127
7461
|
// src/correlated-includes.ts
|
|
7128
|
-
var
|
|
7462
|
+
var import_utils22 = require("@web-ts-toolkit/utils");
|
|
7129
7463
|
init_request_complexity();
|
|
7130
7464
|
init_sort_policy();
|
|
7131
7465
|
var PARENT_MARKER_KEY = "$parent";
|
|
@@ -7138,10 +7472,10 @@ var FIELD_SEGMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
|
7138
7472
|
var ARRAY_INDEX_SEGMENT_PATTERN = /^(0|[1-9]\d*)$/;
|
|
7139
7473
|
var ownKeys = (value) => Object.keys(value);
|
|
7140
7474
|
function isParentRefMarker(value) {
|
|
7141
|
-
return (0,
|
|
7475
|
+
return (0, import_utils22.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === PARENT_MARKER_KEY;
|
|
7142
7476
|
}
|
|
7143
7477
|
function isEscapedParentRef(value) {
|
|
7144
|
-
return (0,
|
|
7478
|
+
return (0, import_utils22.isPlainObject)(value) && ownKeys(value).length === 1 && ownKeys(value)[0] === ESCAPE_WRAPPER_KEY;
|
|
7145
7479
|
}
|
|
7146
7480
|
function hasMarkerKey(value) {
|
|
7147
7481
|
return ownKeys(value).includes(PARENT_MARKER_KEY) || ownKeys(value).includes(ESCAPE_WRAPPER_KEY);
|
|
@@ -7160,12 +7494,12 @@ function containsParentMarkerShape(value) {
|
|
|
7160
7494
|
const seen = /* @__PURE__ */ new Set();
|
|
7161
7495
|
const visit = (current) => {
|
|
7162
7496
|
if (isParentRefMarker(current) || isEscapedParentRef(current)) return true;
|
|
7163
|
-
if ((0,
|
|
7497
|
+
if ((0, import_utils22.isArray)(current)) {
|
|
7164
7498
|
if (seen.has(current)) return false;
|
|
7165
7499
|
seen.add(current);
|
|
7166
7500
|
return current.some(visit);
|
|
7167
7501
|
}
|
|
7168
|
-
if ((0,
|
|
7502
|
+
if ((0, import_utils22.isPlainObject)(current)) {
|
|
7169
7503
|
if (seen.has(current)) return false;
|
|
7170
7504
|
seen.add(current);
|
|
7171
7505
|
if (hasMarkerKey(current)) return true;
|
|
@@ -7195,7 +7529,7 @@ function scanTemplateValueNode(value, path, issues) {
|
|
|
7195
7529
|
}
|
|
7196
7530
|
return;
|
|
7197
7531
|
}
|
|
7198
|
-
if ((0,
|
|
7532
|
+
if ((0, import_utils22.isPlainObject)(value)) {
|
|
7199
7533
|
if (hasMarkerKey(value)) {
|
|
7200
7534
|
issues.push({
|
|
7201
7535
|
message: 'Malformed $parent reference: objects carrying $parent must be exactly { "$parent": "<field>" }',
|
|
@@ -7206,7 +7540,7 @@ function scanTemplateValueNode(value, path, issues) {
|
|
|
7206
7540
|
scanTemplateObjectEntries(value, path, issues);
|
|
7207
7541
|
return;
|
|
7208
7542
|
}
|
|
7209
|
-
if ((0,
|
|
7543
|
+
if ((0, import_utils22.isArray)(value)) {
|
|
7210
7544
|
value.forEach((item, index) => scanTemplateValueNode(item, [...path, index], issues));
|
|
7211
7545
|
}
|
|
7212
7546
|
}
|
|
@@ -7247,7 +7581,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7247
7581
|
continue;
|
|
7248
7582
|
}
|
|
7249
7583
|
if (LOGICAL_CLAUSE_KEYS.has(key)) {
|
|
7250
|
-
if (!(0,
|
|
7584
|
+
if (!(0, import_utils22.isArray)(child)) {
|
|
7251
7585
|
scanTemplateValueNode(child, childPath, issues);
|
|
7252
7586
|
continue;
|
|
7253
7587
|
}
|
|
@@ -7260,7 +7594,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7260
7594
|
});
|
|
7261
7595
|
return;
|
|
7262
7596
|
}
|
|
7263
|
-
if ((0,
|
|
7597
|
+
if ((0, import_utils22.isPlainObject)(clause)) {
|
|
7264
7598
|
scanTemplateObjectEntries(clause, clausePath, issues);
|
|
7265
7599
|
}
|
|
7266
7600
|
});
|
|
@@ -7271,7 +7605,7 @@ function scanTemplateObjectEntries(obj, basePath, issues) {
|
|
|
7271
7605
|
}
|
|
7272
7606
|
function validateCorrelatedFilterTemplate(filter2) {
|
|
7273
7607
|
const issues = [];
|
|
7274
|
-
if (!(0,
|
|
7608
|
+
if (!(0, import_utils22.isPlainObject)(filter2)) {
|
|
7275
7609
|
issues.push({ message: "Correlated include filter must be an object", path: [] });
|
|
7276
7610
|
return issues;
|
|
7277
7611
|
}
|
|
@@ -7314,13 +7648,13 @@ function collectFilterReferencePaths(filter2) {
|
|
|
7314
7648
|
return;
|
|
7315
7649
|
}
|
|
7316
7650
|
if (isEscapedParentRef(value)) return;
|
|
7317
|
-
if ((0,
|
|
7651
|
+
if ((0, import_utils22.isArray)(value)) {
|
|
7318
7652
|
if (seen.has(value)) return;
|
|
7319
7653
|
seen.add(value);
|
|
7320
7654
|
value.forEach(visitValue);
|
|
7321
7655
|
return;
|
|
7322
7656
|
}
|
|
7323
|
-
if ((0,
|
|
7657
|
+
if ((0, import_utils22.isPlainObject)(value)) {
|
|
7324
7658
|
if (seen.has(value)) return;
|
|
7325
7659
|
seen.add(value);
|
|
7326
7660
|
for (const [key, child] of Object.entries(value)) {
|
|
@@ -7366,7 +7700,7 @@ function getOwnPathValue(parent, path) {
|
|
|
7366
7700
|
return current;
|
|
7367
7701
|
}
|
|
7368
7702
|
function cloneSubstitutedValue(value) {
|
|
7369
|
-
if ((0,
|
|
7703
|
+
if ((0, import_utils22.isPlainObject)(value) || (0, import_utils22.isArray)(value)) return (0, import_utils22.cloneDeep)(value);
|
|
7370
7704
|
return value;
|
|
7371
7705
|
}
|
|
7372
7706
|
function literalParentRefObject(path) {
|
|
@@ -7407,7 +7741,7 @@ function resolveObjectEntries(obj, parent) {
|
|
|
7407
7741
|
continue;
|
|
7408
7742
|
}
|
|
7409
7743
|
if (LOGICAL_CLAUSE_KEYS.has(key)) {
|
|
7410
|
-
if (!(0,
|
|
7744
|
+
if (!(0, import_utils22.isArray)(child)) {
|
|
7411
7745
|
out[key] = resolveValueNode(child, parent, false);
|
|
7412
7746
|
continue;
|
|
7413
7747
|
}
|
|
@@ -7415,7 +7749,7 @@ function resolveObjectEntries(obj, parent) {
|
|
|
7415
7749
|
if (isParentRefMarker(clause) || isEscapedParentRef(clause)) {
|
|
7416
7750
|
throw new CorrelatedReferenceError(`Unsupported $parent reference as a direct ${key} clause`);
|
|
7417
7751
|
}
|
|
7418
|
-
if (!(0,
|
|
7752
|
+
if (!(0, import_utils22.isPlainObject)(clause)) return cloneSubstitutedValue(clause);
|
|
7419
7753
|
return resolveObjectEntries(clause, parent);
|
|
7420
7754
|
});
|
|
7421
7755
|
continue;
|
|
@@ -7444,10 +7778,10 @@ function resolveValueNode(template, parent, bare) {
|
|
|
7444
7778
|
}
|
|
7445
7779
|
const value = getOwnPathValue(parent, path);
|
|
7446
7780
|
if (value === void 0 || value === null) throw UNRESOLVABLE;
|
|
7447
|
-
if (bare && (0,
|
|
7781
|
+
if (bare && (0, import_utils22.isPlainObject)(value)) return { $eq: (0, import_utils22.cloneDeep)(value) };
|
|
7448
7782
|
return cloneSubstitutedValue(value);
|
|
7449
7783
|
}
|
|
7450
|
-
if ((0,
|
|
7784
|
+
if ((0, import_utils22.isPlainObject)(template)) {
|
|
7451
7785
|
if (hasMarkerKey(template)) {
|
|
7452
7786
|
throw new CorrelatedReferenceError(
|
|
7453
7787
|
'Malformed $parent reference: objects carrying $parent must be exactly { "$parent": "<field>" }'
|
|
@@ -7455,7 +7789,7 @@ function resolveValueNode(template, parent, bare) {
|
|
|
7455
7789
|
}
|
|
7456
7790
|
return resolveObjectEntries(template, parent);
|
|
7457
7791
|
}
|
|
7458
|
-
if ((0,
|
|
7792
|
+
if ((0, import_utils22.isArray)(template)) {
|
|
7459
7793
|
return template.map((item) => resolveValueNode(item, parent, false));
|
|
7460
7794
|
}
|
|
7461
7795
|
return template;
|
|
@@ -7489,7 +7823,7 @@ function resolveCorrelatedIdTemplate(id, parent) {
|
|
|
7489
7823
|
}
|
|
7490
7824
|
function resolveCorrelatedFilterTemplate(filter2, parent) {
|
|
7491
7825
|
try {
|
|
7492
|
-
if (!(0,
|
|
7826
|
+
if (!(0, import_utils22.isPlainObject)(filter2) || isParentRefMarker(filter2) || isEscapedParentRef(filter2)) {
|
|
7493
7827
|
throw new CorrelatedReferenceError("Correlated include filter must be an object");
|
|
7494
7828
|
}
|
|
7495
7829
|
return { status: "resolved", filter: resolveObjectEntries(filter2, parent) };
|
|
@@ -7504,7 +7838,7 @@ function validateExpandedCorrelatedOperands(expanded, limits) {
|
|
|
7504
7838
|
var MAX_NESTED_INCLUDE_DEPTH = 10;
|
|
7505
7839
|
function validateCorrelatedArgsShape(args, op, depth) {
|
|
7506
7840
|
if (args === void 0) return [];
|
|
7507
|
-
if (!(0,
|
|
7841
|
+
if (!(0, import_utils22.isPlainObject)(args)) return ["Correlated include args must be an object"];
|
|
7508
7842
|
const record3 = args;
|
|
7509
7843
|
const allowed = op === "list" ? /* @__PURE__ */ new Set(["select", "sort", "skip", "limit", "page", "pageSize", "include"]) : /* @__PURE__ */ new Set(["select", "sort", "include"]);
|
|
7510
7844
|
for (const key of Object.keys(record3)) {
|
|
@@ -7526,7 +7860,7 @@ function validateCorrelatedArgsShape(args, op, depth) {
|
|
|
7526
7860
|
return [];
|
|
7527
7861
|
}
|
|
7528
7862
|
function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
7529
|
-
if (!(0,
|
|
7863
|
+
if (!(0, import_utils22.isPlainObject)(entry)) return ["Correlated include must be an object"];
|
|
7530
7864
|
const record3 = entry;
|
|
7531
7865
|
if (record3.mode !== "correlated") return ['Correlated include mode must be "correlated"'];
|
|
7532
7866
|
if (typeof record3.model !== "string" || record3.model.length === 0)
|
|
@@ -7539,7 +7873,7 @@ function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
|
7539
7873
|
if ("localField" in record3 || "foreignField" in record3) {
|
|
7540
7874
|
return ["Correlated includes must not carry localField or foreignField"];
|
|
7541
7875
|
}
|
|
7542
|
-
if (record3.options !== void 0 && !((0,
|
|
7876
|
+
if (record3.options !== void 0 && !((0, import_utils22.isPlainObject)(record3.options) && Object.keys(record3.options).length === 0)) {
|
|
7543
7877
|
return ["Correlated include options must be absent or empty"];
|
|
7544
7878
|
}
|
|
7545
7879
|
const hasId = record3.id !== void 0;
|
|
@@ -7561,7 +7895,7 @@ function validateCorrelatedIncludeShape(entry, depth = 0) {
|
|
|
7561
7895
|
return validateCorrelatedArgsShape(record3.args, record3.op, depth);
|
|
7562
7896
|
}
|
|
7563
7897
|
function isCorrelatedInclude(value) {
|
|
7564
|
-
return (0,
|
|
7898
|
+
return (0, import_utils22.isPlainObject)(value) && value.mode === "correlated";
|
|
7565
7899
|
}
|
|
7566
7900
|
|
|
7567
7901
|
// src/services/base.ts
|
|
@@ -7838,7 +8172,9 @@ function createServiceExecution(receiver, access, authorization, applicability =
|
|
|
7838
8172
|
relatedTargets,
|
|
7839
8173
|
parent,
|
|
7840
8174
|
configuration: configuration ?? registered.configuration(),
|
|
7841
|
-
requestPermissions: requestPermissions ?? registered.permissions()
|
|
8175
|
+
requestPermissions: requestPermissions ?? registered.permissions(),
|
|
8176
|
+
listResponse: access.operation === "list" && parent === void 0,
|
|
8177
|
+
readResponse: access.operation === "read" && parent === void 0
|
|
7842
8178
|
});
|
|
7843
8179
|
const execution = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
7844
8180
|
executions.set(
|
|
@@ -7892,7 +8228,10 @@ function deriveServiceExecution(receiver, parent, access, applicability = "servi
|
|
|
7892
8228
|
relatedTargets: captured.relatedTargets,
|
|
7893
8229
|
configuration: captured.configuration,
|
|
7894
8230
|
requestPermissions: getAuthorizationPermissions(record3.authorization, record3.binding),
|
|
7895
|
-
parent: record3.authorization
|
|
8231
|
+
parent: record3.authorization,
|
|
8232
|
+
// The resolver authenticates root-read provenance and the unchanged owner tuple.
|
|
8233
|
+
// Effective list access is still a read; write branches cannot inherit this marker.
|
|
8234
|
+
readResponse: record3.access.operation === "read" && access.operation === "read"
|
|
7896
8235
|
});
|
|
7897
8236
|
const execution = Object.freeze(/* @__PURE__ */ Object.create(null));
|
|
7898
8237
|
executions.set(
|
|
@@ -8298,20 +8637,20 @@ var copyAuthorizedOutput = (value) => {
|
|
|
8298
8637
|
transferDocumentAuthorizationGraph(value, copy);
|
|
8299
8638
|
return copy;
|
|
8300
8639
|
};
|
|
8301
|
-
var isVirtualContainerValueForGuard = (value) => (0,
|
|
8640
|
+
var isVirtualContainerValueForGuard = (value) => (0, import_utils25.isPlainObject)(value) && "sub" in value;
|
|
8302
8641
|
var getScopeVirtualsForGuard = (rootVirtuals, scopePath) => {
|
|
8303
|
-
if (!rootVirtuals || !(0,
|
|
8642
|
+
if (!rootVirtuals || !(0, import_utils25.isPlainObject)(rootVirtuals)) return null;
|
|
8304
8643
|
if (scopePath.length === 0) return rootVirtuals;
|
|
8305
8644
|
let current = rootVirtuals;
|
|
8306
8645
|
for (let i = 0; i < scopePath.length; i += 2) {
|
|
8307
8646
|
const field = scopePath[i];
|
|
8308
8647
|
const subMarker = scopePath[i + 1];
|
|
8309
8648
|
if (!field || subMarker !== "sub") return null;
|
|
8310
|
-
if (!(0,
|
|
8649
|
+
if (!(0, import_utils25.isPlainObject)(current)) return null;
|
|
8311
8650
|
const container = current[field];
|
|
8312
8651
|
if (!isVirtualContainerValueForGuard(container)) return null;
|
|
8313
8652
|
current = container.sub;
|
|
8314
|
-
if (!(0,
|
|
8653
|
+
if (!(0, import_utils25.isPlainObject)(current)) return null;
|
|
8315
8654
|
}
|
|
8316
8655
|
return current;
|
|
8317
8656
|
};
|
|
@@ -8377,7 +8716,7 @@ var sanitizeSubScopeVirtualKeys = (data, snapshot, sub) => {
|
|
|
8377
8716
|
for (const entry of value) stripScope(entry, currentScope);
|
|
8378
8717
|
return;
|
|
8379
8718
|
}
|
|
8380
|
-
if (!(0,
|
|
8719
|
+
if (!(0, import_utils25.isPlainObject)(value)) return;
|
|
8381
8720
|
const record3 = value;
|
|
8382
8721
|
const leaves = getScopeVirtualLeafNames(snapshot, currentScope);
|
|
8383
8722
|
for (const leaf of leaves) {
|
|
@@ -8390,7 +8729,7 @@ var sanitizeSubScopeVirtualKeys = (data, snapshot, sub) => {
|
|
|
8390
8729
|
for (const key of Object.keys(record3)) {
|
|
8391
8730
|
if (leaves.has(key) || containers.has(key)) continue;
|
|
8392
8731
|
const child = record3[key];
|
|
8393
|
-
if (Array.isArray(child) || (0,
|
|
8732
|
+
if (Array.isArray(child) || (0, import_utils25.isPlainObject)(child)) {
|
|
8394
8733
|
stripScope(child, currentScope);
|
|
8395
8734
|
}
|
|
8396
8735
|
}
|
|
@@ -8402,7 +8741,7 @@ var LOGICAL_FILTER_KEYS = /* @__PURE__ */ new Set(["$and", "$or", "$nor"]);
|
|
|
8402
8741
|
var isOperatorKey = (key) => key.startsWith("$");
|
|
8403
8742
|
var REMOVED_VIRTUAL_FILTER = /* @__PURE__ */ Symbol("removed virtual filter clause");
|
|
8404
8743
|
var rewriteFilterObject = (value, visit) => {
|
|
8405
|
-
if (!(0,
|
|
8744
|
+
if (!(0, import_utils25.isPlainObject)(value)) return value;
|
|
8406
8745
|
let changed = false;
|
|
8407
8746
|
const entries = [];
|
|
8408
8747
|
for (const [key, child] of Object.entries(value)) {
|
|
@@ -8433,7 +8772,7 @@ var resolveVirtualFilterField = (path, scope2) => {
|
|
|
8433
8772
|
if (!Object.hasOwn(scope2, segment) || scope2[segment] === void 0) return null;
|
|
8434
8773
|
const definition = scope2[segment];
|
|
8435
8774
|
if (!isVirtualContainerValueForGuard(definition)) return REMOVED_VIRTUAL_FILTER;
|
|
8436
|
-
scope2 = (0,
|
|
8775
|
+
scope2 = (0, import_utils25.isPlainObject)(definition.sub) ? definition.sub : null;
|
|
8437
8776
|
inContainer = true;
|
|
8438
8777
|
}
|
|
8439
8778
|
return scope2;
|
|
@@ -8445,7 +8784,7 @@ var stripVirtualFilterOperator = (key, value, scope2) => {
|
|
|
8445
8784
|
}
|
|
8446
8785
|
if (key === "$all") {
|
|
8447
8786
|
return rewriteFilterClauses(value, (entry) => {
|
|
8448
|
-
if (!(0,
|
|
8787
|
+
if (!(0, import_utils25.isPlainObject)(entry) || Object.keys(entry).length !== 1 || !Object.hasOwn(entry, "$elemMatch")) return entry;
|
|
8449
8788
|
return rewriteFilterObject(entry, (operator, operand) => stripVirtualFilterOperator(operator, operand, scope2));
|
|
8450
8789
|
});
|
|
8451
8790
|
}
|
|
@@ -8460,7 +8799,7 @@ var stripVirtualFilterQuery = (value, scope2, element = false) => {
|
|
|
8460
8799
|
if (isOperatorKey(key)) return element ? stripVirtualFilterOperator(key, child, scope2) : child;
|
|
8461
8800
|
const fieldScope = resolveVirtualFilterField(key, scope2);
|
|
8462
8801
|
if (fieldScope === REMOVED_VIRTUAL_FILTER) return REMOVED_VIRTUAL_FILTER;
|
|
8463
|
-
if (!fieldScope || !(0,
|
|
8802
|
+
if (!fieldScope || !(0, import_utils25.isPlainObject)(child)) return child;
|
|
8464
8803
|
if (Object.keys(child).some(isOperatorKey)) {
|
|
8465
8804
|
return rewriteFilterObject(
|
|
8466
8805
|
child,
|
|
@@ -8482,9 +8821,9 @@ var stripSubVirtualKeysFromFilter = (filter2, snapshot, sub) => {
|
|
|
8482
8821
|
function getCorrelatedTemplateDepth(includes) {
|
|
8483
8822
|
let max = 0;
|
|
8484
8823
|
const visit = (entries, depth) => {
|
|
8485
|
-
const list = (0,
|
|
8824
|
+
const list = (0, import_utils25.castArray)(entries).filter(Boolean);
|
|
8486
8825
|
for (const entry of list) {
|
|
8487
|
-
if (!(0,
|
|
8826
|
+
if (!(0, import_utils25.isPlainObject)(entry)) continue;
|
|
8488
8827
|
max = Math.max(max, depth);
|
|
8489
8828
|
const nested = entry.args?.include;
|
|
8490
8829
|
if (nested !== void 0) {
|
|
@@ -8509,11 +8848,11 @@ function validateClientFilter(filter2) {
|
|
|
8509
8848
|
}
|
|
8510
8849
|
const blockedOperators = /* @__PURE__ */ new Set(["$where", "$expr", "$function", "$accumulator"]);
|
|
8511
8850
|
const visit = (value, path) => {
|
|
8512
|
-
if ((0,
|
|
8851
|
+
if ((0, import_utils25.isArray)(value)) {
|
|
8513
8852
|
value.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
8514
8853
|
return;
|
|
8515
8854
|
}
|
|
8516
|
-
if (!(0,
|
|
8855
|
+
if (!(0, import_utils25.isPlainObject)(value)) return;
|
|
8517
8856
|
Object.entries(value).forEach(([key, child]) => {
|
|
8518
8857
|
const nextPath = path ? `${path}.${key}` : key;
|
|
8519
8858
|
if (blockedOperators.has(key)) {
|
|
@@ -8718,7 +9057,7 @@ var Base = class {
|
|
|
8718
9057
|
}
|
|
8719
9058
|
processInclude(include, authorization) {
|
|
8720
9059
|
assertPublicAdmission(include, "include");
|
|
8721
|
-
const items = (0,
|
|
9060
|
+
const items = (0, import_utils25.compact)((0, import_utils25.castArray)(include));
|
|
8722
9061
|
const legacy = [];
|
|
8723
9062
|
const correlated = [];
|
|
8724
9063
|
const correlatedReferenceFields = [];
|
|
@@ -8754,23 +9093,23 @@ var Base = class {
|
|
|
8754
9093
|
else this.assertIncludeOutputPaths([...legacy, ...correlated]);
|
|
8755
9094
|
let includeLocalFields = [];
|
|
8756
9095
|
let includePaths = [];
|
|
8757
|
-
(0,
|
|
9096
|
+
(0, import_utils25.forEach)(legacy, (inc) => {
|
|
8758
9097
|
includeLocalFields.push(inc.localField);
|
|
8759
9098
|
includePaths.push(inc.path);
|
|
8760
9099
|
});
|
|
8761
|
-
includeLocalFields = (0,
|
|
8762
|
-
includePaths = (0,
|
|
9100
|
+
includeLocalFields = (0, import_utils25.uniq)((0, import_utils25.compact)(includeLocalFields));
|
|
9101
|
+
includePaths = (0, import_utils25.uniq)((0, import_utils25.compact)(includePaths));
|
|
8763
9102
|
return {
|
|
8764
9103
|
includes: legacy,
|
|
8765
9104
|
correlatedIncludes: correlated,
|
|
8766
9105
|
includeLocalFields,
|
|
8767
9106
|
includePaths,
|
|
8768
|
-
correlatedReferenceFields: (0,
|
|
9107
|
+
correlatedReferenceFields: (0, import_utils25.uniq)((0, import_utils25.compact)(correlatedReferenceFields))
|
|
8769
9108
|
};
|
|
8770
9109
|
}
|
|
8771
9110
|
validateIncludeOutputPath(path, modelName, configuration) {
|
|
8772
9111
|
const permissionField = configuration ? configuration.documentPermissionField ?? "_permissions" : getModelOption(modelName, "documentPermissionField");
|
|
8773
|
-
if ((0,
|
|
9112
|
+
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
9113
|
this.throwClientRequestError(
|
|
8775
9114
|
"bad_request" /* BadRequest */,
|
|
8776
9115
|
`Include output path ${path} overlaps document permission field ${permissionField} on model ${modelName}`
|
|
@@ -8795,9 +9134,9 @@ var Base = class {
|
|
|
8795
9134
|
const walk = (node, prefix) => {
|
|
8796
9135
|
for (const [key, value] of Object.entries(node)) {
|
|
8797
9136
|
if (value === void 0) continue;
|
|
8798
|
-
if ((0,
|
|
9137
|
+
if ((0, import_utils25.isPlainObject)(value) && "sub" in value) {
|
|
8799
9138
|
const sub = value.sub;
|
|
8800
|
-
if ((0,
|
|
9139
|
+
if ((0, import_utils25.isPlainObject)(sub)) walk(sub, prefix ? `${prefix}.${key}` : key);
|
|
8801
9140
|
continue;
|
|
8802
9141
|
}
|
|
8803
9142
|
out.push(prefix ? `${prefix}.${key}` : key);
|
|
@@ -8850,7 +9189,7 @@ var Base = class {
|
|
|
8850
9189
|
this.throwClientRequestError("bad_request" /* BadRequest */, `Model ${modelName} not found`);
|
|
8851
9190
|
}
|
|
8852
9191
|
for (const entry of entries) {
|
|
8853
|
-
if (!(0,
|
|
9192
|
+
if (!(0, import_utils25.isPlainObject)(entry)) continue;
|
|
8854
9193
|
const models = visited.get(entry) ?? /* @__PURE__ */ new Set();
|
|
8855
9194
|
if (models.has(modelName)) continue;
|
|
8856
9195
|
models.add(modelName);
|
|
@@ -8863,7 +9202,7 @@ var Base = class {
|
|
|
8863
9202
|
const target = targets?.find((target2) => target2.path === entry.path);
|
|
8864
9203
|
if (nested)
|
|
8865
9204
|
pending.push({
|
|
8866
|
-
entries: (0,
|
|
9205
|
+
entries: (0, import_utils25.compact)((0, import_utils25.castArray)(nested)),
|
|
8867
9206
|
modelName: entry.model,
|
|
8868
9207
|
configuration: target?.configuration,
|
|
8869
9208
|
targets: target?.relatedTargets
|
|
@@ -8873,7 +9212,7 @@ var Base = class {
|
|
|
8873
9212
|
}
|
|
8874
9213
|
}
|
|
8875
9214
|
getForeignKeyValues(value) {
|
|
8876
|
-
return (0,
|
|
9215
|
+
return (0, import_utils25.flatten)((0, import_utils25.castArray)(value));
|
|
8877
9216
|
}
|
|
8878
9217
|
getForeignKey(value) {
|
|
8879
9218
|
return String(value);
|
|
@@ -8881,7 +9220,7 @@ var Base = class {
|
|
|
8881
9220
|
buildForeignKeyIndex(rows2, foreignField) {
|
|
8882
9221
|
const index = /* @__PURE__ */ new Map();
|
|
8883
9222
|
for (const row of rows2) {
|
|
8884
|
-
for (const value of this.getForeignKeyValues((0,
|
|
9223
|
+
for (const value of this.getForeignKeyValues((0, import_utils25.get)(row, foreignField))) {
|
|
8885
9224
|
const key = this.getForeignKey(value);
|
|
8886
9225
|
const values = index.get(key);
|
|
8887
9226
|
if (values) values.push(row);
|
|
@@ -8917,9 +9256,9 @@ var Base = class {
|
|
|
8917
9256
|
async includeDocs(docs, include, parentAuthorization) {
|
|
8918
9257
|
assertPublicAdmission(include, "include");
|
|
8919
9258
|
if (!include) return docs;
|
|
8920
|
-
const includes = (0,
|
|
9259
|
+
const includes = (0, import_utils25.compact)((0, import_utils25.castArray)(include));
|
|
8921
9260
|
if (includes.length === 0) return docs;
|
|
8922
|
-
const isSingle = !(0,
|
|
9261
|
+
const isSingle = !(0, import_utils25.isArray)(docs);
|
|
8923
9262
|
let docList = (isSingle ? [docs] : docs).map(prepareIncludeOutput);
|
|
8924
9263
|
for (let x = 0; x < includes.length; x++) {
|
|
8925
9264
|
const include2 = includes[x];
|
|
@@ -8949,7 +9288,7 @@ var Base = class {
|
|
|
8949
9288
|
const svc = await this.getAuthorizedTargetService(model, "read", path, parentAuthorization);
|
|
8950
9289
|
for (let y = 0; y < docs.length; y++) {
|
|
8951
9290
|
const doc = docs[y];
|
|
8952
|
-
const localValue = (0,
|
|
9291
|
+
const localValue = (0, import_utils25.get)(doc, localField);
|
|
8953
9292
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
8954
9293
|
const prepared = await prepareModelQuery(
|
|
8955
9294
|
svc,
|
|
@@ -8984,15 +9323,15 @@ var Base = class {
|
|
|
8984
9323
|
const { model, op, path, localField, foreignField, filter: _filters, args = {}, options = {} } = include;
|
|
8985
9324
|
const svc = await this.getAuthorizedTargetService(model, op, path, parentAuthorization);
|
|
8986
9325
|
const includeLocalValues = [];
|
|
8987
|
-
(0,
|
|
8988
|
-
includeLocalValues.push(...this.getForeignKeyValues((0,
|
|
9326
|
+
(0, import_utils25.forEach)(docs, (doc) => {
|
|
9327
|
+
includeLocalValues.push(...this.getForeignKeyValues((0, import_utils25.get)(doc, localField)));
|
|
8989
9328
|
});
|
|
8990
9329
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
8991
9330
|
const prepared = await prepareModelQuery(
|
|
8992
9331
|
svc,
|
|
8993
9332
|
execution,
|
|
8994
9333
|
{ kind: "client-read", filter: _filters ?? {} },
|
|
8995
|
-
{ [foreignField]: { $in: (0,
|
|
9334
|
+
{ [foreignField]: { $in: (0, import_utils25.flatten)(includeLocalValues) } },
|
|
8996
9335
|
true
|
|
8997
9336
|
);
|
|
8998
9337
|
const trustedArgs = this.sanitizeIncludeArgs(args, "list");
|
|
@@ -9035,7 +9374,7 @@ var Base = class {
|
|
|
9035
9374
|
}
|
|
9036
9375
|
for (let y = 0; y < docs.length; y++) {
|
|
9037
9376
|
const doc = docs[y];
|
|
9038
|
-
const matches = this.getIndexedMatches(index, (0,
|
|
9377
|
+
const matches = this.getIndexedMatches(index, (0, import_utils25.get)(doc, localField));
|
|
9039
9378
|
const isolated = matches.map((m) => copyAuthorizedOutput(m));
|
|
9040
9379
|
attachIncludeOutput(doc, path, op === "list" ? isolated : isolated[0]);
|
|
9041
9380
|
}
|
|
@@ -9044,7 +9383,7 @@ var Base = class {
|
|
|
9044
9383
|
async includeDocsCount(docs, include, parentAuthorization) {
|
|
9045
9384
|
const { model, path, localField, foreignField, filter: _filters } = include;
|
|
9046
9385
|
const svc = await this.getAuthorizedTargetService(model, "count", path, parentAuthorization);
|
|
9047
|
-
const groups = prepareCountGroups(docs, (doc) => (0,
|
|
9386
|
+
const groups = prepareCountGroups(docs, (doc) => (0, import_utils25.get)(doc, localField));
|
|
9048
9387
|
const execution = this.relatedExecution(svc, include, parentAuthorization);
|
|
9049
9388
|
const prepared = await prepareModelQuery(
|
|
9050
9389
|
svc,
|
|
@@ -9098,7 +9437,7 @@ var Base = class {
|
|
|
9098
9437
|
}
|
|
9099
9438
|
const state = this.getCorrelatedExecState();
|
|
9100
9439
|
docs = docs.map(prepareIncludeOutput);
|
|
9101
|
-
const resolvedSnapshots = snapshots2 ?? docs.map((doc) => (0,
|
|
9440
|
+
const resolvedSnapshots = snapshots2 ?? docs.map((doc) => (0, import_utils25.cloneDeep)(toObject(getIncludeSource(doc))));
|
|
9102
9441
|
for (const include of correlatedIncludes) {
|
|
9103
9442
|
switch (include.op) {
|
|
9104
9443
|
case "read":
|
|
@@ -9447,10 +9786,10 @@ var Base = class {
|
|
|
9447
9786
|
}
|
|
9448
9787
|
let ret = result2.data;
|
|
9449
9788
|
if (sqOptions.path) {
|
|
9450
|
-
ret = (0,
|
|
9789
|
+
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
9790
|
}
|
|
9452
9791
|
if (sqOptions.compact) {
|
|
9453
|
-
ret = (0,
|
|
9792
|
+
ret = (0, import_utils25.compact)((0, import_utils25.castArray)(ret));
|
|
9454
9793
|
}
|
|
9455
9794
|
return ret;
|
|
9456
9795
|
}
|
|
@@ -9462,11 +9801,11 @@ var Base = class {
|
|
|
9462
9801
|
};
|
|
9463
9802
|
|
|
9464
9803
|
// src/services/service.ts
|
|
9465
|
-
var
|
|
9804
|
+
var import_utils36 = require("@web-ts-toolkit/utils");
|
|
9466
9805
|
var import_just_diff = require("just-diff");
|
|
9467
9806
|
|
|
9468
9807
|
// src/model.ts
|
|
9469
|
-
var
|
|
9808
|
+
var import_utils26 = require("@web-ts-toolkit/utils");
|
|
9470
9809
|
init_runtime_context();
|
|
9471
9810
|
init_runtime();
|
|
9472
9811
|
function admitModelPersistence(adapter, scheduler) {
|
|
@@ -9542,7 +9881,7 @@ var Model = class {
|
|
|
9542
9881
|
}
|
|
9543
9882
|
/** Cast a copy using this model's query schema/setters, without executing query middleware or persistence. */
|
|
9544
9883
|
castFilter(filter2) {
|
|
9545
|
-
const query = this.mongooseModel.countDocuments((0,
|
|
9884
|
+
const query = this.mongooseModel.countDocuments((0, import_utils26.cloneDeep)(filter2));
|
|
9546
9885
|
return query.cast(this.mongooseModel);
|
|
9547
9886
|
}
|
|
9548
9887
|
// see https://mongoosejs.com/docs/api.html#model_Model.distinct
|
|
@@ -9556,7 +9895,7 @@ var Model = class {
|
|
|
9556
9895
|
var model_default = Model;
|
|
9557
9896
|
|
|
9558
9897
|
// src/acl/distinct-field-authorization.ts
|
|
9559
|
-
var
|
|
9898
|
+
var import_utils27 = require("@web-ts-toolkit/utils");
|
|
9560
9899
|
init_field_authorization();
|
|
9561
9900
|
init_field_catalog();
|
|
9562
9901
|
var schemaVariants = (schema) => Object.values(schema.discriminators ?? {});
|
|
@@ -9638,8 +9977,8 @@ function isDistinctFieldAuthorized(args) {
|
|
|
9638
9977
|
if (path !== field && !path.startsWith(`${field}.`) && !field.startsWith(`${path}.`)) continue;
|
|
9639
9978
|
if (path.startsWith(`${field}.`) && (!eligible(path) || !schemaShape(schema, path) || !granted(path)))
|
|
9640
9979
|
return false;
|
|
9641
|
-
if ((0,
|
|
9642
|
-
if (!(0,
|
|
9980
|
+
if ((0, import_utils27.isPlainObject)(raw) && raw.sub !== void 0) {
|
|
9981
|
+
if (!(0, import_utils27.isPlainObject)(raw.sub) || !declaredRulesSafe(raw.sub, path, next)) return false;
|
|
9643
9982
|
}
|
|
9644
9983
|
}
|
|
9645
9984
|
return true;
|
|
@@ -9816,7 +10155,7 @@ init_document();
|
|
|
9816
10155
|
init_populate_target();
|
|
9817
10156
|
|
|
9818
10157
|
// src/helpers/apply-update.ts
|
|
9819
|
-
var
|
|
10158
|
+
var import_utils31 = require("@web-ts-toolkit/utils");
|
|
9820
10159
|
init_lib();
|
|
9821
10160
|
function applyUpdate(target, data, allowedFields) {
|
|
9822
10161
|
const wholeFields = /* @__PURE__ */ new Set();
|
|
@@ -9832,17 +10171,17 @@ function applyUpdate(target, data, allowedFields) {
|
|
|
9832
10171
|
}
|
|
9833
10172
|
};
|
|
9834
10173
|
for (const field of allowedFields) {
|
|
9835
|
-
collectBoundary((0,
|
|
10174
|
+
collectBoundary((0, import_utils31.set)({}, field, true));
|
|
9836
10175
|
}
|
|
9837
10176
|
const apply = (values, prefix = "") => {
|
|
9838
10177
|
for (const [key, value] of Object.entries(values)) {
|
|
9839
10178
|
const path = prefix ? `${prefix}.${key}` : key;
|
|
9840
|
-
if (partialContainers.has(path) && !wholeFields.has(path) && ((0,
|
|
10179
|
+
if (partialContainers.has(path) && !wholeFields.has(path) && ((0, import_utils31.isPlainObject)(value) || Array.isArray(value))) {
|
|
9841
10180
|
apply(value, path);
|
|
9842
10181
|
} else if (isDocument2(target)) {
|
|
9843
10182
|
target.set(path, value);
|
|
9844
10183
|
} else {
|
|
9845
|
-
(0,
|
|
10184
|
+
(0, import_utils31.set)(target, path, value);
|
|
9846
10185
|
}
|
|
9847
10186
|
}
|
|
9848
10187
|
};
|
|
@@ -9850,7 +10189,7 @@ function applyUpdate(target, data, allowedFields) {
|
|
|
9850
10189
|
}
|
|
9851
10190
|
|
|
9852
10191
|
// src/acl/model-input-admission.ts
|
|
9853
|
-
var
|
|
10192
|
+
var import_utils33 = require("@web-ts-toolkit/utils");
|
|
9854
10193
|
var import_mongoose8 = require("mongoose");
|
|
9855
10194
|
init_document();
|
|
9856
10195
|
init_request_work();
|
|
@@ -9858,7 +10197,7 @@ init_logger_helpers();
|
|
|
9858
10197
|
init_request_complexity();
|
|
9859
10198
|
|
|
9860
10199
|
// src/acl/select-resolution.ts
|
|
9861
|
-
var
|
|
10200
|
+
var import_utils32 = require("@web-ts-toolkit/utils");
|
|
9862
10201
|
init_core_shared();
|
|
9863
10202
|
init_helpers();
|
|
9864
10203
|
async function collectAllowedFieldsForRequest({
|
|
@@ -9932,15 +10271,15 @@ async function resolveSelectForRequest({
|
|
|
9932
10271
|
const excludeall = normalizedSelect.every((v) => v.startsWith("-"));
|
|
9933
10272
|
if (excludeall) {
|
|
9934
10273
|
normalizedSelect = normalizedSelect.map((v) => v.substring(1));
|
|
9935
|
-
fields = (0,
|
|
10274
|
+
fields = (0, import_utils32.difference)(fields, normalizedSelect);
|
|
9936
10275
|
if (excludeid) fields.push("-_id");
|
|
9937
10276
|
} else {
|
|
9938
|
-
fields = (0,
|
|
10277
|
+
fields = (0, import_utils32.intersection)(normalizedSelect, fields.concat(excludeid ? "-_id" : "_id"));
|
|
9939
10278
|
}
|
|
9940
10279
|
}
|
|
9941
10280
|
return fields.concat(strippedAlways);
|
|
9942
10281
|
}
|
|
9943
|
-
return (0,
|
|
10282
|
+
return (0, import_utils32.intersection)(normalizedSelect, fields);
|
|
9944
10283
|
}
|
|
9945
10284
|
function stripVirtuals(fields, virtualNames) {
|
|
9946
10285
|
const set13 = virtualNames instanceof Set ? virtualNames : new Set(virtualNames ?? []);
|
|
@@ -9971,7 +10310,7 @@ init_field_catalog();
|
|
|
9971
10310
|
init_service_authorization();
|
|
9972
10311
|
var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
9973
10312
|
var inside = (path, root) => path === root || path.startsWith(`${root}.`);
|
|
9974
|
-
var record2 = (value) => (0,
|
|
10313
|
+
var record2 = (value) => (0, import_utils33.isPlainObject)(value);
|
|
9975
10314
|
function inputValue(value) {
|
|
9976
10315
|
if (typeof value === "function" || typeof value === "symbol") {
|
|
9977
10316
|
authorizationError("input values must be persisted data, not functions or symbols");
|
|
@@ -10040,7 +10379,7 @@ function requestBoundaries(fields) {
|
|
|
10040
10379
|
else visit(value, path);
|
|
10041
10380
|
}
|
|
10042
10381
|
};
|
|
10043
|
-
for (const field of fields) visit((0,
|
|
10382
|
+
for (const field of fields) visit((0, import_utils33.set)({}, field, true));
|
|
10044
10383
|
return [...new Set(result2)];
|
|
10045
10384
|
}
|
|
10046
10385
|
function ownValue(data, parts) {
|
|
@@ -10170,7 +10509,7 @@ function admitModelInput(args) {
|
|
|
10170
10509
|
if (forbidden(catalog, path, requested)) continue;
|
|
10171
10510
|
const supplied = ownValue(data, parts);
|
|
10172
10511
|
if (!supplied) continue;
|
|
10173
|
-
(0,
|
|
10512
|
+
(0, import_utils33.set)(allowedData, field, copyInputValue(supplied.value, path, catalog, scopedRequests, logicalPath(field)));
|
|
10174
10513
|
selected.push(field);
|
|
10175
10514
|
}
|
|
10176
10515
|
return { allowedData, allowedFields };
|
|
@@ -10182,7 +10521,7 @@ async function requestInputFields(args) {
|
|
|
10182
10521
|
const prefix = configuration.modelPermissionPrefix ?? "";
|
|
10183
10522
|
return collectModelRequestFields({
|
|
10184
10523
|
req: args.binding.request,
|
|
10185
|
-
permissionSchema: args.scopePath ? (0,
|
|
10524
|
+
permissionSchema: args.scopePath ? (0, import_utils33.get)(configuration.permissionSchema, [args.scopePath, "sub"]) : configuration.permissionSchema,
|
|
10186
10525
|
access: args.access,
|
|
10187
10526
|
permissions,
|
|
10188
10527
|
grants,
|
|
@@ -10226,13 +10565,13 @@ init_logger_helpers();
|
|
|
10226
10565
|
init_lib();
|
|
10227
10566
|
|
|
10228
10567
|
// src/services/model-subdocument-service.ts
|
|
10229
|
-
var
|
|
10568
|
+
var import_utils35 = require("@web-ts-toolkit/utils");
|
|
10230
10569
|
init_helpers();
|
|
10231
10570
|
init_document();
|
|
10232
10571
|
init_public_admission();
|
|
10233
10572
|
|
|
10234
10573
|
// src/acl/subdocument-authorization.ts
|
|
10235
|
-
var
|
|
10574
|
+
var import_utils34 = require("@web-ts-toolkit/utils");
|
|
10236
10575
|
init_helpers();
|
|
10237
10576
|
init_document();
|
|
10238
10577
|
init_core_shared();
|
|
@@ -10421,8 +10760,8 @@ async function subdocumentGateAllowed(service, gate) {
|
|
|
10421
10760
|
let guard2;
|
|
10422
10761
|
if (access.startsWith("subs.")) {
|
|
10423
10762
|
const [, sub, op] = access.split(".");
|
|
10424
|
-
guard2 = (0,
|
|
10425
|
-
if (guard2 === void 0) guard2 = (0,
|
|
10763
|
+
guard2 = (0, import_utils34.get)(configuration, `operationAccess.${access}`);
|
|
10764
|
+
if (guard2 === void 0) guard2 = (0, import_utils34.get)(configuration, `operationAccess.subs.${sub}`);
|
|
10426
10765
|
if (guard2 === void 0) guard2 = getCapturedAuthorizationOption(configuration, `operationAccess.${op}`);
|
|
10427
10766
|
} else guard2 = getCapturedAuthorizationOption(configuration, `operationAccess.${access}`);
|
|
10428
10767
|
return evaluateRouteGuard(
|
|
@@ -10553,7 +10892,7 @@ async function visibleMutationRows(service, call, parentId, rows2) {
|
|
|
10553
10892
|
const read = await subdocumentRows(service, visibility.child, selected, selected, call.sub);
|
|
10554
10893
|
const list = visibility.list ? await subdocumentRows(service, visibility.list, {}, {}, call.sub) : {};
|
|
10555
10894
|
if (read === false || list === false) return [];
|
|
10556
|
-
const visible = filterCollection((0,
|
|
10895
|
+
const visible = filterCollection((0, import_utils35.get)(parent, call.sub), intersectFilters(read, list));
|
|
10557
10896
|
return await finalizeSubdocumentRows(service, call.output, parent, visible);
|
|
10558
10897
|
} catch {
|
|
10559
10898
|
return [];
|
|
@@ -10578,7 +10917,7 @@ async function listSub(service, id, sub, options) {
|
|
|
10578
10917
|
populate: []
|
|
10579
10918
|
});
|
|
10580
10919
|
if (!parent) return denied2("not_found" /* NotFound */);
|
|
10581
|
-
const rows2 = filterCollection((0,
|
|
10920
|
+
const rows2 = filterCollection((0, import_utils35.get)(parent, sub), childFilter);
|
|
10582
10921
|
const data = await finalizeSubdocumentRows(service, call.output, parent, rows2);
|
|
10583
10922
|
return { success: true, kind: "list", code: "success" /* Success */, data, count: data.length };
|
|
10584
10923
|
});
|
|
@@ -10602,7 +10941,7 @@ async function readSub(service, id, sub, subId, options) {
|
|
|
10602
10941
|
});
|
|
10603
10942
|
if (!parent) return denied2("not_found" /* NotFound */);
|
|
10604
10943
|
const row = findElement(
|
|
10605
|
-
(0,
|
|
10944
|
+
(0, import_utils35.get)(capture ? parent : copySubdocumentParent(parent), sub),
|
|
10606
10945
|
childFilter
|
|
10607
10946
|
);
|
|
10608
10947
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
@@ -10623,7 +10962,7 @@ async function updateSub(service, persist, id, sub, subId, data, options) {
|
|
|
10623
10962
|
const identity = { _id: subId };
|
|
10624
10963
|
const filter2 = await subdocumentRows(service, call.child, identity, identity, sub);
|
|
10625
10964
|
if (filter2 === false) return denied2();
|
|
10626
|
-
const row = findElement((0,
|
|
10965
|
+
const row = findElement((0, import_utils35.get)(parent, sub), filter2);
|
|
10627
10966
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
10628
10967
|
const original = isolateDocForOutput(row);
|
|
10629
10968
|
const admit = await inputAdmission(service, call, parent);
|
|
@@ -10650,7 +10989,7 @@ async function bulkUpdateSub(service, persist, id, sub, data, options) {
|
|
|
10650
10989
|
const selected = { _id: { $in: data.map((row) => row._id) } };
|
|
10651
10990
|
const filter2 = await subdocumentRows(service, call.child, selected, selected, sub);
|
|
10652
10991
|
if (filter2 === false) return denied2();
|
|
10653
|
-
const rows2 = filterCollection((0,
|
|
10992
|
+
const rows2 = filterCollection((0, import_utils35.get)(parent, sub), filter2);
|
|
10654
10993
|
const originals = rows2.map((row) => isolateDocForOutput(row));
|
|
10655
10994
|
const admit = await inputAdmission(service, call, parent);
|
|
10656
10995
|
for (const [index, row] of rows2.entries()) {
|
|
@@ -10679,7 +11018,7 @@ async function createSub(service, persist, id, sub, data, options) {
|
|
|
10679
11018
|
const lookup = await mutationParent(service, id, call);
|
|
10680
11019
|
if ("error" in lookup) return lookup.error;
|
|
10681
11020
|
const { parent } = lookup;
|
|
10682
|
-
const rows2 = (0,
|
|
11021
|
+
const rows2 = (0, import_utils35.get)(parent, sub);
|
|
10683
11022
|
const admit = await inputAdmission(service, call, parent);
|
|
10684
11023
|
const allowed = (Array.isArray(data) ? data : [data]).map((row) => admit(row).allowedData);
|
|
10685
11024
|
if (addFirst) rows2.unshift(...allowed);
|
|
@@ -10700,7 +11039,7 @@ async function deleteSub(service, persist, id, sub, subId, options) {
|
|
|
10700
11039
|
const identity = { _id: subId };
|
|
10701
11040
|
const filter2 = await subdocumentRows(service, call.child, identity, identity, sub);
|
|
10702
11041
|
if (filter2 === false) return denied2();
|
|
10703
|
-
const row = findElement((0,
|
|
11042
|
+
const row = findElement((0, import_utils35.get)(parent, sub), filter2);
|
|
10704
11043
|
if (!row) return denied2("not_found" /* NotFound */);
|
|
10705
11044
|
await ("deleteOne" in row ? row.deleteOne?.() : row.remove?.());
|
|
10706
11045
|
await persist(() => parent.save());
|
|
@@ -10869,6 +11208,11 @@ var Service = class extends Base {
|
|
|
10869
11208
|
["args", args],
|
|
10870
11209
|
["options", options]
|
|
10871
11210
|
]) {
|
|
11211
|
+
if (value !== null && (typeof value === "object" || typeof value === "function")) {
|
|
11212
|
+
for (const key of ["unsafeSkipListDocumentSnapshotChecks", "unsafeSkipReadDocumentSnapshotChecks"]) {
|
|
11213
|
+
if (key in value) authorizationError(`${slot}.${key} is server model configuration only`);
|
|
11214
|
+
}
|
|
11215
|
+
}
|
|
10872
11216
|
if (value !== null && (typeof value === "object" || typeof value === "function") && "authorization" in value && (slot === "args" || !authorizationOptions)) {
|
|
10873
11217
|
authorizationError(`${slot}.authorization is unsupported here; inputFields requires model mutation options`);
|
|
10874
11218
|
}
|
|
@@ -11015,20 +11359,20 @@ var Service = class extends Base {
|
|
|
11015
11359
|
const field = configuration.documentPermissionField ?? "_permissions";
|
|
11016
11360
|
unsetDocPath(output, field);
|
|
11017
11361
|
if (!configuration.stripPermissionsField) {
|
|
11018
|
-
(0,
|
|
11362
|
+
(0, import_utils36.set)(output, field, args.includePermissions || args.includeFieldPermissions ? deepIsolateValue(grants) : {});
|
|
11019
11363
|
if (args.includeFieldPermissions && !configuration.disableFieldPermissions) {
|
|
11020
11364
|
const rowAccess = this.asServiceHookContext(context).fieldPermissionAccess ?? await this.getFieldPermissionAccess([snapshot._id]);
|
|
11021
11365
|
const id = String(snapshot._id);
|
|
11022
11366
|
const views = rowAccess.readIds?.has(id) ? await requestOutputFieldPaths(handle, binding, "read") : [];
|
|
11023
11367
|
const edits = rowAccess.updateIds?.has(id) ? await requestOutputFieldPaths(handle, binding, "update") : [];
|
|
11024
11368
|
const map2 = (paths) => paths.length ? Object.fromEntries(paths.map((path) => [path, true])) : { $: "_" };
|
|
11025
|
-
(0,
|
|
11026
|
-
(0,
|
|
11027
|
-
} else if (!args.includePermissions) (0,
|
|
11369
|
+
(0, import_utils36.set)(output, `${field}._view`, map2(views));
|
|
11370
|
+
(0, import_utils36.set)(output, `${field}._edit`, map2(edits));
|
|
11371
|
+
} else if (!args.includePermissions) (0, import_utils36.set)(output, field, { _view: { $: "_" }, _edit: { $: "_" } });
|
|
11028
11372
|
const exposed = configuration.exposedDocPermissionKeys;
|
|
11029
11373
|
if (exposed) {
|
|
11030
|
-
const metadata = (0,
|
|
11031
|
-
(0,
|
|
11374
|
+
const metadata = (0, import_utils36.get)(output, field);
|
|
11375
|
+
(0, import_utils36.set)(
|
|
11032
11376
|
output,
|
|
11033
11377
|
field,
|
|
11034
11378
|
Object.fromEntries(
|
|
@@ -11289,7 +11633,7 @@ var Service = class extends Base {
|
|
|
11289
11633
|
return docs.map((doc) => {
|
|
11290
11634
|
try {
|
|
11291
11635
|
const plain = toObject(doc);
|
|
11292
|
-
const val = (0,
|
|
11636
|
+
const val = (0, import_utils36.get)(plain, associationField);
|
|
11293
11637
|
return deepIsolateValue(val);
|
|
11294
11638
|
} catch {
|
|
11295
11639
|
return void 0;
|
|
@@ -11398,7 +11742,7 @@ var Service = class extends Base {
|
|
|
11398
11742
|
if (this.isScalarPopulateValue(rawTarget)) return rawTarget;
|
|
11399
11743
|
const isDoc = (() => {
|
|
11400
11744
|
try {
|
|
11401
|
-
if ((0,
|
|
11745
|
+
if ((0, import_utils36.isPlainObject)(rawTarget)) return true;
|
|
11402
11746
|
const maybe = rawTarget;
|
|
11403
11747
|
if (maybe && typeof maybe === "object" && "_doc" in maybe) return true;
|
|
11404
11748
|
if (maybe && typeof maybe.toObject === "function") return true;
|
|
@@ -11486,7 +11830,7 @@ var Service = class extends Base {
|
|
|
11486
11830
|
child = getDocValue(current, key);
|
|
11487
11831
|
if (child === void 0) {
|
|
11488
11832
|
try {
|
|
11489
|
-
child = (0,
|
|
11833
|
+
child = (0, import_utils36.get)(current, key);
|
|
11490
11834
|
} catch {
|
|
11491
11835
|
return;
|
|
11492
11836
|
}
|
|
@@ -11721,7 +12065,7 @@ var Service = class extends Base {
|
|
|
11721
12065
|
originalDocumentSnapshot: toObject(doc),
|
|
11722
12066
|
resolvedQuery: query
|
|
11723
12067
|
};
|
|
11724
|
-
const correlatedSnapshots = [(0,
|
|
12068
|
+
const correlatedSnapshots = [(0, import_utils36.cloneDeep)(toObject(doc))];
|
|
11725
12069
|
try {
|
|
11726
12070
|
doc = await this.includeDocs(doc, includes, state.authorization);
|
|
11727
12071
|
if (correlatedIncludes.length > 0) {
|
|
@@ -11903,7 +12247,7 @@ var Service = class extends Base {
|
|
|
11903
12247
|
const findAssociationField = this.getAssociationFieldFromOptions(options);
|
|
11904
12248
|
const withAssocSelect = findAssociationField && !finalSelect.includes(findAssociationField) ? [...finalSelect, findAssociationField] : finalSelect;
|
|
11905
12249
|
const dbSelect = this.buildDbSelectForAssociation(withAssocSelect, findAssociationField);
|
|
11906
|
-
const filteredPopulate = (0,
|
|
12250
|
+
const filteredPopulate = (0, import_utils36.isArray)(withAssocSelect) && (0, import_utils36.isArray)(_populate) ? _populate.filter(
|
|
11907
12251
|
(p) => [
|
|
11908
12252
|
...virtualPlan.publicPersistedFetchSelection,
|
|
11909
12253
|
...findAssociationField ? [findAssociationField] : []
|
|
@@ -11963,7 +12307,7 @@ var Service = class extends Base {
|
|
|
11963
12307
|
findAssociationField ? [findAssociationField] : []
|
|
11964
12308
|
);
|
|
11965
12309
|
const capturedAssociation = findAssociationField ? this.captureAssociationValues(docs, findAssociationField) : void 0;
|
|
11966
|
-
const correlatedSnapshots = docs.map((doc) => (0,
|
|
12310
|
+
const correlatedSnapshots = docs.map((doc) => (0, import_utils36.cloneDeep)(toObject(doc)));
|
|
11967
12311
|
try {
|
|
11968
12312
|
docs = await this.includeDocs(docs, includes, state.authorization);
|
|
11969
12313
|
if (correlatedIncludes.length > 0) {
|
|
@@ -12162,12 +12506,12 @@ var Service = class extends Base {
|
|
|
12162
12506
|
context.allowedFields = allowedFields;
|
|
12163
12507
|
context.allowedData = allowedData;
|
|
12164
12508
|
const validated = await this.validate(allowedData, "create", context);
|
|
12165
|
-
if ((0,
|
|
12509
|
+
if ((0, import_utils36.isBoolean)(validated)) {
|
|
12166
12510
|
if (!validated) {
|
|
12167
12511
|
validationErrors.push({ index, errors: [] });
|
|
12168
12512
|
return void 0;
|
|
12169
12513
|
}
|
|
12170
|
-
} else if ((0,
|
|
12514
|
+
} else if ((0, import_utils36.isArray)(validated)) {
|
|
12171
12515
|
if (validated.length > 0) {
|
|
12172
12516
|
validationErrors.push({
|
|
12173
12517
|
index,
|
|
@@ -12378,7 +12722,7 @@ var Service = class extends Base {
|
|
|
12378
12722
|
}
|
|
12379
12723
|
let doc = await this.model.findOne({
|
|
12380
12724
|
filter: _filter,
|
|
12381
|
-
select: (0,
|
|
12725
|
+
select: (0, import_utils36.uniq)([...updatePlan.persistedFetchSelection, ...inputFetchPaths(captured.configuration.catalog)]).map(
|
|
12382
12726
|
(path) => `+${path}`
|
|
12383
12727
|
)
|
|
12384
12728
|
});
|
|
@@ -12417,12 +12761,12 @@ var Service = class extends Base {
|
|
|
12417
12761
|
context.allowedFields = allowedFields;
|
|
12418
12762
|
context.allowedData = allowedData;
|
|
12419
12763
|
const validated = await this.validate(allowedData, "update", context);
|
|
12420
|
-
if ((0,
|
|
12764
|
+
if ((0, import_utils36.isBoolean)(validated)) {
|
|
12421
12765
|
if (!validated) {
|
|
12422
12766
|
this.completeOp("updateOne", startedAt, "bad_request" /* BadRequest */, _filter);
|
|
12423
12767
|
return { success: false, kind: "error", code: "bad_request" /* BadRequest */ };
|
|
12424
12768
|
}
|
|
12425
|
-
} else if ((0,
|
|
12769
|
+
} else if ((0, import_utils36.isArray)(validated)) {
|
|
12426
12770
|
if (validated.length > 0) {
|
|
12427
12771
|
this.completeOp("updateOne", startedAt, "bad_request" /* BadRequest */, _filter);
|
|
12428
12772
|
return { success: false, kind: "error", code: "bad_request" /* BadRequest */, errors: validated };
|
|
@@ -12442,10 +12786,10 @@ var Service = class extends Base {
|
|
|
12442
12786
|
const diffExcludeFields = [this.options.documentPermissionField, "__v"];
|
|
12443
12787
|
this.asServiceHookContext(context).diff = (d) => {
|
|
12444
12788
|
context.changes = (0, import_just_diff.diff)(
|
|
12445
|
-
(0,
|
|
12446
|
-
(0,
|
|
12789
|
+
(0, import_utils36.omit)(context.originalDocumentSnapshot, diffExcludeFields),
|
|
12790
|
+
(0, import_utils36.omit)(d.toObject({ virtuals: false }), diffExcludeFields)
|
|
12447
12791
|
) || [];
|
|
12448
|
-
context.modifiedPaths = (0,
|
|
12792
|
+
context.modifiedPaths = (0, import_utils36.uniq)(context.changes.map((di) => di.path.length > 0 ? String(di.path[0]) : ""));
|
|
12449
12793
|
};
|
|
12450
12794
|
doc = assertModelDocument(await this.afterPersist(doc, "update", context), this.modelName, "afterPersist");
|
|
12451
12795
|
context.currentDocument = doc;
|
|
@@ -12533,7 +12877,7 @@ var Service = class extends Base {
|
|
|
12533
12877
|
const upsertOptions = this.resolveUpsertOptions(options);
|
|
12534
12878
|
const updateIntent = captureModelServiceIntent(this, "updateOne", upsertArgs, upsertOptions);
|
|
12535
12879
|
const createIntent = captureModelServiceIntent(this, "create", upsertArgs, upsertOptions);
|
|
12536
|
-
const related = (0,
|
|
12880
|
+
const related = (0, import_utils36.uniqBy)(
|
|
12537
12881
|
[...this.captureRelated(updateIntent.args), ...this.captureRelated(createIntent.args)],
|
|
12538
12882
|
(target) => target.path
|
|
12539
12883
|
);
|
|
@@ -12974,7 +13318,7 @@ var Service = class extends Base {
|
|
|
12974
13318
|
return resolveExistsOptions(this, options);
|
|
12975
13319
|
}
|
|
12976
13320
|
async getFieldPermissionAccess(ids) {
|
|
12977
|
-
const uniqueIds = (0,
|
|
13321
|
+
const uniqueIds = (0, import_utils36.compact)((0, import_utils36.uniqBy)(ids, (id) => String(id)).map((id) => String(id)));
|
|
12978
13322
|
if (uniqueIds.length === 0) {
|
|
12979
13323
|
return {
|
|
12980
13324
|
readIds: /* @__PURE__ */ new Set(),
|
|
@@ -13020,7 +13364,7 @@ var Service = class extends Base {
|
|
|
13020
13364
|
* (direct/root-entry 200); count measures visible rows, not all updated rows.
|
|
13021
13365
|
*/
|
|
13022
13366
|
async bulkUpdateSub(id, sub, data, options) {
|
|
13023
|
-
return bulkUpdateSub(this, this.persist, id, sub, (0,
|
|
13367
|
+
return bulkUpdateSub(this, this.persist, id, sub, (0, import_utils36.castArray)(data), options);
|
|
13024
13368
|
}
|
|
13025
13369
|
/**
|
|
13026
13370
|
* Append/prepend admitted rows, then return the visible full array (including when
|
|
@@ -13044,7 +13388,7 @@ var Service = class extends Base {
|
|
|
13044
13388
|
};
|
|
13045
13389
|
|
|
13046
13390
|
// src/services/public-service.ts
|
|
13047
|
-
var
|
|
13391
|
+
var import_utils37 = require("@web-ts-toolkit/utils");
|
|
13048
13392
|
init_helpers();
|
|
13049
13393
|
init_permissions_alias();
|
|
13050
13394
|
init_document();
|
|
@@ -13170,7 +13514,7 @@ var PublicService = class extends Service {
|
|
|
13170
13514
|
let d = toObject(doc);
|
|
13171
13515
|
d = await this.decorate(d, "create", context);
|
|
13172
13516
|
d = this.runTasks(d, tasks);
|
|
13173
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13517
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13174
13518
|
return d;
|
|
13175
13519
|
}
|
|
13176
13520
|
);
|
|
@@ -13389,8 +13733,8 @@ var PublicService = class extends Service {
|
|
|
13389
13733
|
let d = toObject(doc);
|
|
13390
13734
|
d = await this.decorate(d, "update", context);
|
|
13391
13735
|
d = this.runTasks(d, tasks);
|
|
13392
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13393
|
-
else if (!returningAll) d = copyPermissionsAlias(d, (0,
|
|
13736
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13737
|
+
else if (!returningAll) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, returningKeys));
|
|
13394
13738
|
return d;
|
|
13395
13739
|
}
|
|
13396
13740
|
);
|
|
@@ -13473,8 +13817,8 @@ var PublicService = class extends Service {
|
|
|
13473
13817
|
let d = toObject(doc);
|
|
13474
13818
|
d = await this.decorate(d, "update", context);
|
|
13475
13819
|
d = this.runTasks(d, tasks2);
|
|
13476
|
-
if (select) d = copyPermissionsAlias(d, (0,
|
|
13477
|
-
else if (!returningAll) d = copyPermissionsAlias(d, (0,
|
|
13820
|
+
if (select) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(select), ...this.baseFieldsExt]));
|
|
13821
|
+
else if (!returningAll) d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, returningKeys));
|
|
13478
13822
|
return d;
|
|
13479
13823
|
}
|
|
13480
13824
|
);
|
|
@@ -13499,7 +13843,7 @@ var PublicService = class extends Service {
|
|
|
13499
13843
|
d = await this.decorate(d, "create", context);
|
|
13500
13844
|
d = this.runTasks(d, tasks);
|
|
13501
13845
|
if (createSelect)
|
|
13502
|
-
d = copyPermissionsAlias(d, (0,
|
|
13846
|
+
d = copyPermissionsAlias(d, (0, import_utils37.pick)(d, [...normalizeSelect(createSelect), ...this.baseFieldsExt]));
|
|
13503
13847
|
return d;
|
|
13504
13848
|
}
|
|
13505
13849
|
);
|
|
@@ -13644,7 +13988,7 @@ var PublicService = class extends Service {
|
|
|
13644
13988
|
init_options();
|
|
13645
13989
|
init_data_values();
|
|
13646
13990
|
init_helpers();
|
|
13647
|
-
var
|
|
13991
|
+
var import_utils38 = require("@web-ts-toolkit/utils");
|
|
13648
13992
|
init_request_complexity();
|
|
13649
13993
|
init_runtime_context();
|
|
13650
13994
|
init_runtime();
|
|
@@ -13673,7 +14017,7 @@ var DataService = class {
|
|
|
13673
14017
|
let doc = await findElement(this.data, _filter);
|
|
13674
14018
|
if (!doc) return { success: false, kind: "error", code: "not_found" /* NotFound */, query };
|
|
13675
14019
|
doc = await this.trimOutputFields(doc, access);
|
|
13676
|
-
if (_select.length > 0) doc = (0,
|
|
14020
|
+
if (_select.length > 0) doc = (0, import_utils38.pick)(doc, _select);
|
|
13677
14021
|
return {
|
|
13678
14022
|
success: true,
|
|
13679
14023
|
kind: "single",
|
|
@@ -13719,13 +14063,13 @@ var DataService = class {
|
|
|
13719
14063
|
const totalCount = docs.length;
|
|
13720
14064
|
if (sort) {
|
|
13721
14065
|
const normalizedSort = normalizeSortForOrderBy(sort);
|
|
13722
|
-
docs = (0,
|
|
14066
|
+
docs = (0, import_utils38.orderBy)(docs, normalizedSort.fields, normalizedSort.orders);
|
|
13723
14067
|
}
|
|
13724
14068
|
const pagedDocs = docs.slice(query.skip, query.limit && query.skip + query.limit);
|
|
13725
14069
|
const { maxHookConcurrency } = this.getRequestComplexity();
|
|
13726
14070
|
const trimmed = await mapWithConcurrencyLimit(pagedDocs, maxHookConcurrency, async (doc) => {
|
|
13727
14071
|
doc = await this.trimOutputFields(doc, "list");
|
|
13728
|
-
if (_select.length > 0) doc = (0,
|
|
14072
|
+
if (_select.length > 0) doc = (0, import_utils38.pick)(doc, _select);
|
|
13729
14073
|
return copyDataValue(doc);
|
|
13730
14074
|
});
|
|
13731
14075
|
if (!hasExplicitLimit && trimmed.length === totalCount) {
|
|
@@ -13800,10 +14144,10 @@ var DataService = class {
|
|
|
13800
14144
|
init_helpers();
|
|
13801
14145
|
|
|
13802
14146
|
// src/processors.ts
|
|
13803
|
-
var
|
|
14147
|
+
var import_utils39 = require("@web-ts-toolkit/utils");
|
|
13804
14148
|
init_permissions_alias();
|
|
13805
14149
|
function cloneProcessorValue(value) {
|
|
13806
|
-
const copy = (0,
|
|
14150
|
+
const copy = (0, import_utils39.cloneDeep)(value);
|
|
13807
14151
|
copyPermissionsAliasGraph(value, copy);
|
|
13808
14152
|
return copy;
|
|
13809
14153
|
}
|
|
@@ -13841,10 +14185,10 @@ function resolveLeafParents(obj, src) {
|
|
|
13841
14185
|
for (let ind = 0; ind < segs.length - 1; ind += 1) {
|
|
13842
14186
|
const seg = segs[ind];
|
|
13843
14187
|
targets = targets.reduce((ret, target) => {
|
|
13844
|
-
if (!(0,
|
|
14188
|
+
if (!(0, import_utils39.isPlainObject)(target)) return ret;
|
|
13845
14189
|
const targetObject = target;
|
|
13846
14190
|
const next = targetObject[seg];
|
|
13847
|
-
if ((0,
|
|
14191
|
+
if ((0, import_utils39.isArray)(next)) {
|
|
13848
14192
|
for (const item of next) {
|
|
13849
14193
|
ret.push(item);
|
|
13850
14194
|
}
|
|
@@ -13854,8 +14198,8 @@ function resolveLeafParents(obj, src) {
|
|
|
13854
14198
|
}
|
|
13855
14199
|
const leaf = segs[segs.length - 1];
|
|
13856
14200
|
const pairs = [];
|
|
13857
|
-
(0,
|
|
13858
|
-
if (!(0,
|
|
14201
|
+
(0, import_utils39.forEach)(targets, (target) => {
|
|
14202
|
+
if (!(0, import_utils39.isPlainObject)(target)) return;
|
|
13859
14203
|
pairs.push({ parent: target, leaf });
|
|
13860
14204
|
});
|
|
13861
14205
|
return pairs;
|
|
@@ -13864,7 +14208,7 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13864
14208
|
const mutable = options.mutable !== false;
|
|
13865
14209
|
const idField = options.idField ?? "_id";
|
|
13866
14210
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13867
|
-
(0,
|
|
14211
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13868
14212
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13869
14213
|
const src = op.src;
|
|
13870
14214
|
const dest = op.dest;
|
|
@@ -13873,19 +14217,19 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13873
14217
|
assertSafePath(dest);
|
|
13874
14218
|
let targets = [obj];
|
|
13875
14219
|
const segs = src.split(".");
|
|
13876
|
-
(0,
|
|
14220
|
+
(0, import_utils39.forEach)(segs, (seg, ind) => {
|
|
13877
14221
|
if (segs.length === ind + 1) {
|
|
13878
|
-
(0,
|
|
13879
|
-
if (!(0,
|
|
14222
|
+
(0, import_utils39.forEach)(targets, (target) => {
|
|
14223
|
+
if (!(0, import_utils39.isPlainObject)(target)) return;
|
|
13880
14224
|
const targetObject = target;
|
|
13881
14225
|
const leaf = targetObject[seg];
|
|
13882
14226
|
const sourceForDest = leaf;
|
|
13883
14227
|
let depopulated;
|
|
13884
|
-
if ((0,
|
|
14228
|
+
if ((0, import_utils39.isArray)(leaf)) {
|
|
13885
14229
|
if (leaf.length === 0) {
|
|
13886
14230
|
depopulated = [];
|
|
13887
|
-
} else if (leaf.every((item) => (0,
|
|
13888
|
-
depopulated = (0,
|
|
14231
|
+
} else if (leaf.every((item) => (0, import_utils39.isPlainObject)(item))) {
|
|
14232
|
+
depopulated = (0, import_utils39.map)(leaf, idField).map((id, i) => {
|
|
13889
14233
|
if (id === void 0) {
|
|
13890
14234
|
failMissingId(`${src}[${i}]`);
|
|
13891
14235
|
}
|
|
@@ -13894,8 +14238,8 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13894
14238
|
} else {
|
|
13895
14239
|
return;
|
|
13896
14240
|
}
|
|
13897
|
-
} else if ((0,
|
|
13898
|
-
const id = (0,
|
|
14241
|
+
} else if ((0, import_utils39.isPlainObject)(leaf)) {
|
|
14242
|
+
const id = (0, import_utils39.get)(leaf, idField);
|
|
13899
14243
|
if (id === void 0) {
|
|
13900
14244
|
failMissingId(src);
|
|
13901
14245
|
}
|
|
@@ -13903,15 +14247,15 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13903
14247
|
} else {
|
|
13904
14248
|
return;
|
|
13905
14249
|
}
|
|
13906
|
-
(0,
|
|
13907
|
-
(0,
|
|
14250
|
+
(0, import_utils39.set)(targetObject, dest, sourceForDest);
|
|
14251
|
+
(0, import_utils39.set)(targetObject, seg, depopulated);
|
|
13908
14252
|
});
|
|
13909
14253
|
} else {
|
|
13910
14254
|
targets = targets.reduce((ret, target) => {
|
|
13911
|
-
if (!(0,
|
|
14255
|
+
if (!(0, import_utils39.isPlainObject)(target)) return ret;
|
|
13912
14256
|
const targetObject = target;
|
|
13913
14257
|
const next = targetObject[seg];
|
|
13914
|
-
if ((0,
|
|
14258
|
+
if ((0, import_utils39.isArray)(next)) {
|
|
13915
14259
|
for (const item of next) {
|
|
13916
14260
|
ret.push(item);
|
|
13917
14261
|
}
|
|
@@ -13926,7 +14270,7 @@ var copyAndDepopulate = (docObject, operations, options = { mutable: true, idFie
|
|
|
13926
14270
|
var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
13927
14271
|
const mutable = options.mutable !== false;
|
|
13928
14272
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13929
|
-
(0,
|
|
14273
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13930
14274
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13931
14275
|
const src = op.src;
|
|
13932
14276
|
const dest = op.dest;
|
|
@@ -13934,9 +14278,9 @@ var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13934
14278
|
assertSafePath(src, "copyPaths");
|
|
13935
14279
|
assertSafePath(dest, "copyPaths");
|
|
13936
14280
|
if (src === dest) return;
|
|
13937
|
-
(0,
|
|
13938
|
-
if (!(0,
|
|
13939
|
-
(0,
|
|
14281
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14282
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14283
|
+
(0, import_utils39.set)(parent, dest, cloneProcessorValue(parent[leaf]));
|
|
13940
14284
|
});
|
|
13941
14285
|
});
|
|
13942
14286
|
return obj;
|
|
@@ -13944,7 +14288,7 @@ var copyPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13944
14288
|
var movePaths = (docObject, operations, options = { mutable: true }) => {
|
|
13945
14289
|
const mutable = options.mutable !== false;
|
|
13946
14290
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13947
|
-
(0,
|
|
14291
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13948
14292
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
13949
14293
|
const src = op.src;
|
|
13950
14294
|
const dest = op.dest;
|
|
@@ -13952,10 +14296,10 @@ var movePaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
13952
14296
|
assertSafePath(src, "movePaths");
|
|
13953
14297
|
assertSafePath(dest, "movePaths");
|
|
13954
14298
|
if (src === dest) return;
|
|
13955
|
-
(0,
|
|
13956
|
-
if (!(0,
|
|
14299
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14300
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
13957
14301
|
const value = cloneProcessorValue(parent[leaf]);
|
|
13958
|
-
(0,
|
|
14302
|
+
(0, import_utils39.set)(parent, dest, value);
|
|
13959
14303
|
if (dest === leaf || dest.startsWith(`${leaf}.`)) return;
|
|
13960
14304
|
delete parent[leaf];
|
|
13961
14305
|
});
|
|
@@ -13967,7 +14311,7 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
13967
14311
|
const maxSlice = options.maxSlice ?? DEFAULT_MAX_SLICE;
|
|
13968
14312
|
assertNonNegativeSafeInteger(maxSlice, "maxSlice", "sliceArrays");
|
|
13969
14313
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
13970
|
-
(0,
|
|
14314
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
13971
14315
|
if (!op || typeof op.src !== "string") return;
|
|
13972
14316
|
const src = op.src;
|
|
13973
14317
|
if (src.length === 0) return;
|
|
@@ -13984,15 +14328,15 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
13984
14328
|
assertNonNegativeSafeInteger(op.limit, "limit", "sliceArrays");
|
|
13985
14329
|
limit = Math.min(op.limit, maxSlice);
|
|
13986
14330
|
}
|
|
13987
|
-
(0,
|
|
14331
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
13988
14332
|
const leafValue = parent[leaf];
|
|
13989
|
-
if (!(0,
|
|
14333
|
+
if (!(0, import_utils39.isArray)(leafValue)) return;
|
|
13990
14334
|
const end = typeof limit === "undefined" ? void 0 : skip + limit;
|
|
13991
14335
|
const window = leafValue.slice(skip, end);
|
|
13992
14336
|
if (typeof rawDest === "undefined") {
|
|
13993
|
-
(0,
|
|
14337
|
+
(0, import_utils39.set)(parent, leaf, window);
|
|
13994
14338
|
} else {
|
|
13995
|
-
(0,
|
|
14339
|
+
(0, import_utils39.set)(parent, rawDest, window);
|
|
13996
14340
|
}
|
|
13997
14341
|
});
|
|
13998
14342
|
});
|
|
@@ -14001,27 +14345,27 @@ var sliceArrays = (docObject, operations, options = { mutable: true, maxSlice: D
|
|
|
14001
14345
|
var countPaths = (docObject, operations, options = { mutable: true }) => {
|
|
14002
14346
|
const mutable = options.mutable !== false;
|
|
14003
14347
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
14004
|
-
(0,
|
|
14348
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
14005
14349
|
if (!op || typeof op.src !== "string" || typeof op.dest !== "string") return;
|
|
14006
14350
|
const src = op.src;
|
|
14007
14351
|
const dest = op.dest;
|
|
14008
14352
|
if (src.length === 0 || dest.length === 0) return;
|
|
14009
14353
|
assertSafePath(src, "countPaths");
|
|
14010
14354
|
assertSafePath(dest, "countPaths");
|
|
14011
|
-
(0,
|
|
14012
|
-
if (!(0,
|
|
14355
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14356
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14013
14357
|
const leafValue = parent[leaf];
|
|
14014
14358
|
let count;
|
|
14015
|
-
if ((0,
|
|
14359
|
+
if ((0, import_utils39.isArray)(leafValue)) {
|
|
14016
14360
|
count = leafValue.length;
|
|
14017
|
-
} else if ((0,
|
|
14361
|
+
} else if ((0, import_utils39.isPlainObject)(leafValue)) {
|
|
14018
14362
|
count = Object.keys(leafValue).length;
|
|
14019
14363
|
} else if (leafValue === null || typeof leafValue === "undefined") {
|
|
14020
14364
|
count = 0;
|
|
14021
14365
|
} else {
|
|
14022
14366
|
count = 1;
|
|
14023
14367
|
}
|
|
14024
|
-
(0,
|
|
14368
|
+
(0, import_utils39.set)(parent, dest, count);
|
|
14025
14369
|
});
|
|
14026
14370
|
});
|
|
14027
14371
|
return obj;
|
|
@@ -14029,15 +14373,15 @@ var countPaths = (docObject, operations, options = { mutable: true }) => {
|
|
|
14029
14373
|
var maskPaths = (docObject, operations, options = { mutable: true }) => {
|
|
14030
14374
|
const mutable = options.mutable !== false;
|
|
14031
14375
|
const obj = mutable ? docObject : cloneProcessorValue(docObject);
|
|
14032
|
-
(0,
|
|
14376
|
+
(0, import_utils39.forEach)(Array.isArray(operations) ? operations : [], (op) => {
|
|
14033
14377
|
if (!op || typeof op.src !== "string") return;
|
|
14034
14378
|
const src = op.src;
|
|
14035
14379
|
if (src.length === 0) return;
|
|
14036
14380
|
assertSafePath(src, "maskPaths");
|
|
14037
14381
|
const replacement = Object.prototype.hasOwnProperty.call(op, "replacement") ? op.replacement : DEFAULT_MASK_REPLACEMENT;
|
|
14038
|
-
(0,
|
|
14039
|
-
if (!(0,
|
|
14040
|
-
(0,
|
|
14382
|
+
(0, import_utils39.forEach)(resolveLeafParents(obj, src), ({ parent, leaf }) => {
|
|
14383
|
+
if (!(0, import_utils39.hasOwn)(parent, leaf)) return;
|
|
14384
|
+
(0, import_utils39.set)(parent, leaf, replacement);
|
|
14041
14385
|
});
|
|
14042
14386
|
});
|
|
14043
14387
|
return obj;
|
|
@@ -14111,10 +14455,10 @@ var Core = class {
|
|
|
14111
14455
|
getIdentifier(modelName) {
|
|
14112
14456
|
const resolveIdFilter = getModelOption(modelName, "resolveIdFilter");
|
|
14113
14457
|
const idField = getModelOption(modelName, "idField");
|
|
14114
|
-
if ((0,
|
|
14458
|
+
if ((0, import_utils40.isFunction)(resolveIdFilter)) {
|
|
14115
14459
|
return null;
|
|
14116
14460
|
}
|
|
14117
|
-
if ((0,
|
|
14461
|
+
if ((0, import_utils40.isString)(idField)) {
|
|
14118
14462
|
return idField;
|
|
14119
14463
|
}
|
|
14120
14464
|
return "_id";
|
|
@@ -14206,7 +14550,7 @@ var Core = class {
|
|
|
14206
14550
|
/** Persisted request-only populate admission; fetch planning is not field authority. */
|
|
14207
14551
|
async requestPopulateSelect(configuration, permissions, access, targetFields = null, scopePath = []) {
|
|
14208
14552
|
const subPaths = scopePath.flatMap((part) => [part, "sub"]);
|
|
14209
|
-
const permissionSchema = (0,
|
|
14553
|
+
const permissionSchema = (0, import_utils40.get)(configuration, ["permissionSchema", ...subPaths]);
|
|
14210
14554
|
const prefix = scopePath.length ? `${scopePath.join(".")}.` : "";
|
|
14211
14555
|
const virtualNames = (configuration.catalog.virtualPaths ?? []).filter((path) => path.startsWith(prefix)).map((path) => path.slice(prefix.length)).filter((path) => !path.includes("."));
|
|
14212
14556
|
return resolveSelectForRequest({
|
|
@@ -14229,7 +14573,7 @@ var Core = class {
|
|
|
14229
14573
|
if (!_populate) return [];
|
|
14230
14574
|
const descriptors = copyAuthorizationValue(Array.isArray(_populate) ? _populate : [_populate], true);
|
|
14231
14575
|
for (const p of descriptors) {
|
|
14232
|
-
if (!(0,
|
|
14576
|
+
if (!(0, import_utils40.isString)(p)) assertPopulateAccess(p.access);
|
|
14233
14577
|
}
|
|
14234
14578
|
const runtime = this.requestRuntime;
|
|
14235
14579
|
const globalOptions = modelServiceGlobalOptions(this, runtime);
|
|
@@ -14239,13 +14583,13 @@ var Core = class {
|
|
|
14239
14583
|
const permissions = new permission_default(
|
|
14240
14584
|
Object.fromEntries(originalPermissions.keys.map((key) => [key, originalPermissions.has(key)]))
|
|
14241
14585
|
);
|
|
14242
|
-
const populate = (0,
|
|
14586
|
+
const populate = (0, import_utils40.compact)(
|
|
14243
14587
|
await Promise.all(
|
|
14244
14588
|
descriptors.map(async (p) => {
|
|
14245
|
-
const populateAccess = !(0,
|
|
14589
|
+
const populateAccess = !(0, import_utils40.isString)(p) && p.access ? p.access : access;
|
|
14246
14590
|
assertPopulateAccess(populateAccess);
|
|
14247
|
-
const originalSelect = (0,
|
|
14248
|
-
const ret = (0,
|
|
14591
|
+
const originalSelect = (0, import_utils40.isString)(p) ? void 0 : p.select;
|
|
14592
|
+
const ret = (0, import_utils40.isString)(p) ? { path: p } : {
|
|
14249
14593
|
path: p.path,
|
|
14250
14594
|
select: normalizeSelect(p.select)
|
|
14251
14595
|
};
|
|
@@ -14284,11 +14628,11 @@ var Core = class {
|
|
|
14284
14628
|
targetConfiguration.alwaysSelectFields,
|
|
14285
14629
|
populateAccess
|
|
14286
14630
|
);
|
|
14287
|
-
ret.select = (0,
|
|
14631
|
+
ret.select = (0, import_utils40.uniq)([
|
|
14288
14632
|
...ret.select,
|
|
14289
14633
|
...stripVirtuals(hookInputs, [...targetConfiguration.catalog.virtualPaths ?? []])
|
|
14290
14634
|
]);
|
|
14291
|
-
const match = (0,
|
|
14635
|
+
const match = (0, import_utils40.isString)(p) ? {} : p.match ?? {};
|
|
14292
14636
|
const filter2 = await resolveAccessFilterForRequest({
|
|
14293
14637
|
req: this.req,
|
|
14294
14638
|
permissions,
|
|
@@ -14319,7 +14663,7 @@ var Core = class {
|
|
|
14319
14663
|
internalFetch: { baseFields: ["_id"] },
|
|
14320
14664
|
globalPermissions: permissions
|
|
14321
14665
|
});
|
|
14322
|
-
const merged = (0,
|
|
14666
|
+
const merged = (0, import_utils40.uniq)([...normalizeSelect(ret.select), ...targetPlan.virtualOnlyDeps ?? []]).filter(
|
|
14323
14667
|
(t) => t !== "-_id" && !t.includes(".sub.")
|
|
14324
14668
|
);
|
|
14325
14669
|
if (!merged.includes("_id")) merged.push("_id");
|
|
@@ -14341,10 +14685,10 @@ var Core = class {
|
|
|
14341
14685
|
}
|
|
14342
14686
|
async validate(modelName, allowedData, access, context) {
|
|
14343
14687
|
const validate = getModelOption(modelName, `validate.${access}`, null);
|
|
14344
|
-
if ((0,
|
|
14688
|
+
if ((0, import_utils40.isFunction)(validate)) {
|
|
14345
14689
|
const permissions = this.getGlobalPermissions();
|
|
14346
14690
|
return validate.call(this.req, allowedData, permissions, context);
|
|
14347
|
-
} else if ((0,
|
|
14691
|
+
} else if ((0, import_utils40.isBoolean)(validate) || (0, import_utils40.isArray)(validate)) {
|
|
14348
14692
|
return validate;
|
|
14349
14693
|
} else {
|
|
14350
14694
|
return true;
|
|
@@ -14369,7 +14713,7 @@ var Core = class {
|
|
|
14369
14713
|
const changeOptions = getModelOption(modelName, `onChange`, {});
|
|
14370
14714
|
for (let x = 0; x < context.modifiedPaths.length; x++) {
|
|
14371
14715
|
const mpath = context.modifiedPaths[x];
|
|
14372
|
-
if ((0,
|
|
14716
|
+
if ((0, import_utils40.isFunction)(changeOptions[mpath])) {
|
|
14373
14717
|
await changeOptions[mpath].call(
|
|
14374
14718
|
this.req,
|
|
14375
14719
|
context.originalDocumentSnapshot[mpath],
|
|
@@ -14393,7 +14737,7 @@ var Core = class {
|
|
|
14393
14737
|
async genDocPermissions(modelName, doc, access, context) {
|
|
14394
14738
|
const docPermissionsFn = getModelOption(modelName, `docPermissions.${access}`, null);
|
|
14395
14739
|
let docPermissions = {};
|
|
14396
|
-
if ((0,
|
|
14740
|
+
if ((0, import_utils40.isFunction)(docPermissionsFn)) {
|
|
14397
14741
|
const permissions = this.getGlobalPermissions();
|
|
14398
14742
|
try {
|
|
14399
14743
|
docPermissions = await getRequestWorkState(this.req, this.requestRuntime).hookGate.run(
|
|
@@ -14477,7 +14821,7 @@ var Core = class {
|
|
|
14477
14821
|
readExists ? requestFields("read") : [],
|
|
14478
14822
|
updateExists ? requestFields("update") : []
|
|
14479
14823
|
]);
|
|
14480
|
-
const viewObj = (0,
|
|
14824
|
+
const viewObj = (0, import_utils40.reduce)(
|
|
14481
14825
|
views,
|
|
14482
14826
|
(ret, view) => {
|
|
14483
14827
|
ret[view] = true;
|
|
@@ -14485,7 +14829,7 @@ var Core = class {
|
|
|
14485
14829
|
},
|
|
14486
14830
|
{}
|
|
14487
14831
|
);
|
|
14488
|
-
const editObj = (0,
|
|
14832
|
+
const editObj = (0, import_utils40.reduce)(
|
|
14489
14833
|
edits,
|
|
14490
14834
|
(ret, view) => {
|
|
14491
14835
|
ret[view] = true;
|
|
@@ -14516,9 +14860,9 @@ var Core = class {
|
|
|
14516
14860
|
});
|
|
14517
14861
|
}
|
|
14518
14862
|
runTasks(modelName, docObject, task) {
|
|
14519
|
-
const tasks = (0,
|
|
14863
|
+
const tasks = (0, import_utils40.compact)((0, import_utils40.castArray)(task));
|
|
14520
14864
|
if (tasks.length === 0) return docObject;
|
|
14521
|
-
(0,
|
|
14865
|
+
(0, import_utils40.forEach)(tasks, (task2) => {
|
|
14522
14866
|
const { type, args, options } = task2;
|
|
14523
14867
|
switch (type) {
|
|
14524
14868
|
case "COPY_AND_DEPOPULATE":
|
|
@@ -14588,9 +14932,9 @@ var Core = class {
|
|
|
14588
14932
|
}
|
|
14589
14933
|
const [, field, op] = keys2;
|
|
14590
14934
|
const subOption = getExactModelOption(modelName, `operationAccess.${access}`);
|
|
14591
|
-
if ((0,
|
|
14935
|
+
if ((0, import_utils40.isUndefined)(subOption)) {
|
|
14592
14936
|
const subFieldOption = getExactModelOption(modelName, `operationAccess.subs.${field}`);
|
|
14593
|
-
if ((0,
|
|
14937
|
+
if ((0, import_utils40.isUndefined)(subFieldOption)) {
|
|
14594
14938
|
const opOption = getModelOption(modelName, `operationAccess.${op}`);
|
|
14595
14939
|
return this.canActivate(opOption);
|
|
14596
14940
|
}
|
|
@@ -14656,25 +15000,25 @@ function guard(condition) {
|
|
|
14656
15000
|
const permissions = req[PERMISSIONS];
|
|
14657
15001
|
let cond = condition;
|
|
14658
15002
|
let phas = (key) => permissions.has(key);
|
|
14659
|
-
if ((0,
|
|
15003
|
+
if ((0, import_utils41.isPlainObject)(condition)) {
|
|
14660
15004
|
const { modelName, id, condition: _cond } = condition;
|
|
14661
15005
|
const svc = req.macl.getPublicService(modelName);
|
|
14662
15006
|
const select = getModelOption(modelName, `alwaysSelectFields.read`, void 0);
|
|
14663
|
-
let _id = (0,
|
|
14664
|
-
if ((0,
|
|
15007
|
+
let _id = (0, import_utils41.isString)(id) ? id : null;
|
|
15008
|
+
if ((0, import_utils41.isPlainObject)(id)) {
|
|
14665
15009
|
const { type = "param", key } = id;
|
|
14666
15010
|
if (type === "param") {
|
|
14667
15011
|
const paramValue = req.params[key];
|
|
14668
|
-
_id = (0,
|
|
15012
|
+
_id = (0, import_utils41.isArray)(paramValue) ? paramValue[0] ?? null : paramValue ?? null;
|
|
14669
15013
|
} else if (type === "query") {
|
|
14670
15014
|
const _qval = req.query[key];
|
|
14671
|
-
if ((0,
|
|
15015
|
+
if ((0, import_utils41.isArray)(_qval)) _id = _qval.length > 0 ? _qval[0] : null;
|
|
14672
15016
|
else _id = _qval;
|
|
14673
15017
|
} else {
|
|
14674
15018
|
_id = null;
|
|
14675
15019
|
}
|
|
14676
15020
|
}
|
|
14677
|
-
if (!(0,
|
|
15021
|
+
if (!(0, import_utils41.isString)(_id) || !_id) {
|
|
14678
15022
|
return next(new import_express_json_router5.default.clientErrors.BadRequestError());
|
|
14679
15023
|
}
|
|
14680
15024
|
const result2 = await svc._read(_id, { select });
|
|
@@ -14686,11 +15030,11 @@ function guard(condition) {
|
|
|
14686
15030
|
cond = _cond;
|
|
14687
15031
|
}
|
|
14688
15032
|
const { stringHandler, arrayHandler } = createValidator(phas);
|
|
14689
|
-
if ((0,
|
|
15033
|
+
if ((0, import_utils41.isString)(cond)) {
|
|
14690
15034
|
if (stringHandler(cond)) return next();
|
|
14691
|
-
} else if ((0,
|
|
15035
|
+
} else if ((0, import_utils41.isArray)(cond)) {
|
|
14692
15036
|
if (arrayHandler(cond)) return next();
|
|
14693
|
-
} else if ((0,
|
|
15037
|
+
} else if ((0, import_utils41.isFunction)(cond)) {
|
|
14694
15038
|
const result2 = await cond.call(req, permissions);
|
|
14695
15039
|
if (!!result2) return next();
|
|
14696
15040
|
}
|
|
@@ -14703,7 +15047,7 @@ var import_express2 = __toESM(require("express"));
|
|
|
14703
15047
|
|
|
14704
15048
|
// src/routers/model-router.ts
|
|
14705
15049
|
var import_express_json_router8 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
14706
|
-
var
|
|
15050
|
+
var import_utils45 = require("@web-ts-toolkit/utils");
|
|
14707
15051
|
init_logger_helpers();
|
|
14708
15052
|
init_runtime();
|
|
14709
15053
|
init_runtime_context();
|
|
@@ -14837,7 +15181,7 @@ init_request_complexity();
|
|
|
14837
15181
|
|
|
14838
15182
|
// src/validation/common.ts
|
|
14839
15183
|
var import_zod2 = require("zod");
|
|
14840
|
-
var
|
|
15184
|
+
var import_utils42 = require("@web-ts-toolkit/utils");
|
|
14841
15185
|
|
|
14842
15186
|
// src/validation/public-admission-schema.ts
|
|
14843
15187
|
init_public_admission();
|
|
@@ -14966,7 +15310,7 @@ var correlatedFilterSchema = import_zod2.z.record(import_zod2.z.string(), import
|
|
|
14966
15310
|
}
|
|
14967
15311
|
});
|
|
14968
15312
|
var correlatedEmptyOptionsSchema = import_zod2.z.unknown().refine(
|
|
14969
|
-
(value) => value === void 0 || (0,
|
|
15313
|
+
(value) => value === void 0 || (0, import_utils42.isPlainObject)(value) && Object.keys(value).length === 0,
|
|
14970
15314
|
"Correlated include options must be absent or empty"
|
|
14971
15315
|
).optional();
|
|
14972
15316
|
var correlatedPathSchema = import_zod2.z.string().min(1).superRefine((path, ctx) => {
|
|
@@ -15003,7 +15347,7 @@ var correlatedListArgsSchema = import_zod2.z.object({
|
|
|
15003
15347
|
include: import_zod2.z.lazy(() => correlatedNestedIncludeSchema).optional()
|
|
15004
15348
|
}).strict().superRefine((args, ctx) => checkArgsMarkers(args.select, args.sort, ctx));
|
|
15005
15349
|
var correlatedCountArgsSchema = import_zod2.z.unknown().refine(
|
|
15006
|
-
(value) => value === void 0 || (0,
|
|
15350
|
+
(value) => value === void 0 || (0, import_utils42.isPlainObject)(value) && Object.keys(value).length === 0,
|
|
15007
15351
|
"Count includes accept no args"
|
|
15008
15352
|
).optional();
|
|
15009
15353
|
var correlatedReadByIdSchema = import_zod2.z.object({
|
|
@@ -15056,7 +15400,7 @@ var correlatedNestedIncludeSchema = import_zod2.z.union([includeItemSchema, impo
|
|
|
15056
15400
|
var rejectDuplicateCorrelatedPaths = (items, ctx) => {
|
|
15057
15401
|
const seen = /* @__PURE__ */ new Set();
|
|
15058
15402
|
items.forEach((item, index) => {
|
|
15059
|
-
if ((0,
|
|
15403
|
+
if ((0, import_utils42.isPlainObject)(item) && item.mode === "correlated" && typeof item.path === "string") {
|
|
15060
15404
|
if (seen.has(item.path)) {
|
|
15061
15405
|
ctx.addIssue({
|
|
15062
15406
|
code: import_zod2.z.ZodIssueCode.custom,
|
|
@@ -16029,7 +16373,7 @@ var rootQuerySchema = publicBoundarySchema(
|
|
|
16029
16373
|
init_helpers();
|
|
16030
16374
|
|
|
16031
16375
|
// src/routers/shared.ts
|
|
16032
|
-
var
|
|
16376
|
+
var import_utils43 = require("@web-ts-toolkit/utils");
|
|
16033
16377
|
|
|
16034
16378
|
// src/routers/model-router-collection-routes.ts
|
|
16035
16379
|
init_schemas();
|
|
@@ -16060,15 +16404,15 @@ function setModelCollectionRoutes(context) {
|
|
|
16060
16404
|
sort
|
|
16061
16405
|
} = parseQuery(requestSchemas.listQuery, req.query);
|
|
16062
16406
|
const svc = context.getPublicService(req);
|
|
16063
|
-
const includeCount = (0,
|
|
16064
|
-
const includeExtraHeaders = (0,
|
|
16407
|
+
const includeCount = (0, import_utils43.parseBooleanString)(include_count);
|
|
16408
|
+
const includeExtraHeaders = (0, import_utils43.parseBooleanString)(include_extra_headers);
|
|
16065
16409
|
const result2 = await svc._list(
|
|
16066
16410
|
{},
|
|
16067
16411
|
{ select: parseSelectParam(select), sort, skip, limit, page, pageSize: page_size },
|
|
16068
16412
|
{
|
|
16069
|
-
skim: (0,
|
|
16070
|
-
includePermissions: (0,
|
|
16071
|
-
includeFieldPermissions: (0,
|
|
16413
|
+
skim: (0, import_utils43.parseBooleanString)(skim),
|
|
16414
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16415
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16072
16416
|
includeCount
|
|
16073
16417
|
}
|
|
16074
16418
|
);
|
|
@@ -16128,8 +16472,8 @@ function setModelCollectionRoutes(context) {
|
|
|
16128
16472
|
data,
|
|
16129
16473
|
{},
|
|
16130
16474
|
{
|
|
16131
|
-
includePermissions: (0,
|
|
16132
|
-
includeFieldPermissions: (0,
|
|
16475
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16476
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16133
16477
|
}
|
|
16134
16478
|
);
|
|
16135
16479
|
handleResultError(result2);
|
|
@@ -16167,8 +16511,8 @@ function setModelCollectionRoutes(context) {
|
|
|
16167
16511
|
finalData,
|
|
16168
16512
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16169
16513
|
{
|
|
16170
|
-
includePermissions: includePermissions ?? (0,
|
|
16171
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16514
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16515
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16172
16516
|
populateAccess
|
|
16173
16517
|
}
|
|
16174
16518
|
);
|
|
@@ -16265,9 +16609,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16265
16609
|
id,
|
|
16266
16610
|
{ select: parseSelectParam(select) },
|
|
16267
16611
|
{
|
|
16268
|
-
includePermissions: (0,
|
|
16269
|
-
includeFieldPermissions: (0,
|
|
16270
|
-
tryList: (0,
|
|
16612
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16613
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16614
|
+
tryList: (0, import_utils43.parseBooleanString)(try_list)
|
|
16271
16615
|
}
|
|
16272
16616
|
);
|
|
16273
16617
|
handleResultError(result2);
|
|
@@ -16367,9 +16711,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16367
16711
|
data,
|
|
16368
16712
|
{ select: parseSelectParam(select) },
|
|
16369
16713
|
{
|
|
16370
|
-
returningAll: (0,
|
|
16371
|
-
includePermissions: (0,
|
|
16372
|
-
includeFieldPermissions: (0,
|
|
16714
|
+
returningAll: (0, import_utils43.parseBooleanString)(returning_all),
|
|
16715
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16716
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16373
16717
|
}
|
|
16374
16718
|
);
|
|
16375
16719
|
handleResultError(result2);
|
|
@@ -16418,9 +16762,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16418
16762
|
finalData,
|
|
16419
16763
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16420
16764
|
{
|
|
16421
|
-
returningAll: returningAll ?? (0,
|
|
16422
|
-
includePermissions: includePermissions ?? (0,
|
|
16423
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16765
|
+
returningAll: returningAll ?? (0, import_utils43.parseBooleanString)(returning_all),
|
|
16766
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16767
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16424
16768
|
populateAccess
|
|
16425
16769
|
}
|
|
16426
16770
|
);
|
|
@@ -16451,9 +16795,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16451
16795
|
body,
|
|
16452
16796
|
{},
|
|
16453
16797
|
{
|
|
16454
|
-
returningAll: (0,
|
|
16455
|
-
includePermissions: (0,
|
|
16456
|
-
includeFieldPermissions: (0,
|
|
16798
|
+
returningAll: (0, import_utils43.parseBooleanString)(returning_all),
|
|
16799
|
+
includePermissions: (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16800
|
+
includeFieldPermissions: (0, import_utils43.parseBooleanString)(include_field_permissions)
|
|
16457
16801
|
}
|
|
16458
16802
|
);
|
|
16459
16803
|
handleResultError(result2);
|
|
@@ -16500,9 +16844,9 @@ function setModelDocumentRoutes(context) {
|
|
|
16500
16844
|
finalData,
|
|
16501
16845
|
{ select: finalSelect, populate: finalPopulate, tasks: finalTasks },
|
|
16502
16846
|
{
|
|
16503
|
-
returningAll: returningAll ?? (0,
|
|
16504
|
-
includePermissions: includePermissions ?? (0,
|
|
16505
|
-
includeFieldPermissions: includeFieldPermissions ?? (0,
|
|
16847
|
+
returningAll: returningAll ?? (0, import_utils43.parseBooleanString)(returning_all),
|
|
16848
|
+
includePermissions: includePermissions ?? (0, import_utils43.parseBooleanString)(include_permissions),
|
|
16849
|
+
includeFieldPermissions: includeFieldPermissions ?? (0, import_utils43.parseBooleanString)(include_field_permissions),
|
|
16506
16850
|
populateAccess
|
|
16507
16851
|
}
|
|
16508
16852
|
);
|
|
@@ -16742,11 +17086,11 @@ function setModelSubDocumentRoutes(context) {
|
|
|
16742
17086
|
}
|
|
16743
17087
|
|
|
16744
17088
|
// src/openapi/route-registration.ts
|
|
16745
|
-
var
|
|
17089
|
+
var import_utils44 = require("@web-ts-toolkit/utils");
|
|
16746
17090
|
function registerOpenApiRoute(runtime, basePath, defaultTag, route) {
|
|
16747
17091
|
runtime.registerOpenApiRoute({
|
|
16748
17092
|
...route,
|
|
16749
|
-
path: (0,
|
|
17093
|
+
path: (0, import_utils44.normalizeUrlPath)(basePath + route.path),
|
|
16750
17094
|
tags: route.tags ?? [defaultTag]
|
|
16751
17095
|
});
|
|
16752
17096
|
}
|
|
@@ -16754,8 +17098,8 @@ function registerOpenApiRoute(runtime, basePath, defaultTag, route) {
|
|
|
16754
17098
|
// src/routers/model-router.ts
|
|
16755
17099
|
var clientErrors2 = import_express_json_router8.default.clientErrors;
|
|
16756
17100
|
function setOption(parentKey, optionKey, option) {
|
|
16757
|
-
const key = (0,
|
|
16758
|
-
const value = (0,
|
|
17101
|
+
const key = (0, import_utils45.isUndefined)(option) ? parentKey : `${parentKey}.${optionKey}`;
|
|
17102
|
+
const value = (0, import_utils45.isUndefined)(option) ? optionKey : option;
|
|
16759
17103
|
assertMutableRouterOption("model", key);
|
|
16760
17104
|
this.runtime.setModelOption(
|
|
16761
17105
|
this.modelName,
|
|
@@ -16957,7 +17301,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
16957
17301
|
this.runtime = runtime;
|
|
16958
17302
|
this.runtime.setModelOptions(modelName, initialOptions);
|
|
16959
17303
|
this.options = this.runtime.getModelOptions(modelName);
|
|
16960
|
-
this.fullBasePath = (0,
|
|
17304
|
+
this.fullBasePath = (0, import_utils45.normalizeUrlPath)(this.options.parentPath + this.options.basePath);
|
|
16961
17305
|
this.modelName = modelName;
|
|
16962
17306
|
this.router = new import_express_json_router8.default(this.options.basePath, createSetCore(this.runtime), accessRouterResponseHandler);
|
|
16963
17307
|
this.model = new model_default(modelName, this.runtime);
|
|
@@ -17043,13 +17387,13 @@ var ModelRouter = class _ModelRouter {
|
|
|
17043
17387
|
}
|
|
17044
17388
|
logEndpoints() {
|
|
17045
17389
|
runWithRuntime(this.runtime, () => {
|
|
17046
|
-
(0,
|
|
17047
|
-
logInfoMessage(`${(0,
|
|
17390
|
+
(0, import_utils45.forEach)(this.router.getEndpoints(), ({ method, path }) => {
|
|
17391
|
+
logInfoMessage(`${(0, import_utils45.padEnd)(method, 6)} ${(0, import_utils45.normalizeUrlPath)(this.options.parentPath + path)}`);
|
|
17048
17392
|
});
|
|
17049
17393
|
});
|
|
17050
17394
|
}
|
|
17051
17395
|
set(keyOrOptions, value) {
|
|
17052
|
-
if (arguments.length === 2 && (0,
|
|
17396
|
+
if (arguments.length === 2 && (0, import_utils45.isString)(keyOrOptions)) {
|
|
17053
17397
|
assertMutableRouterOption("model", keyOrOptions);
|
|
17054
17398
|
this.runtime.setModelOption(
|
|
17055
17399
|
this.modelName,
|
|
@@ -17057,7 +17401,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
17057
17401
|
value
|
|
17058
17402
|
);
|
|
17059
17403
|
}
|
|
17060
|
-
if (arguments.length === 1 && (0,
|
|
17404
|
+
if (arguments.length === 1 && (0, import_utils45.isPlainObject)(keyOrOptions)) {
|
|
17061
17405
|
assertMutableRouterOptions("model", keyOrOptions);
|
|
17062
17406
|
this.runtime.setModelOptions(
|
|
17063
17407
|
this.modelName,
|
|
@@ -17085,7 +17429,7 @@ var ModelRouter = class _ModelRouter {
|
|
|
17085
17429
|
|
|
17086
17430
|
// src/routers/root-router.ts
|
|
17087
17431
|
var import_express_json_router9 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
17088
|
-
var
|
|
17432
|
+
var import_utils46 = require("@web-ts-toolkit/utils");
|
|
17089
17433
|
|
|
17090
17434
|
// src/core-data.ts
|
|
17091
17435
|
init_options();
|
|
@@ -17393,7 +17737,7 @@ var RootRouter = class {
|
|
|
17393
17737
|
this.setRoutes();
|
|
17394
17738
|
}
|
|
17395
17739
|
registerOpenApiRoute(route) {
|
|
17396
|
-
registerOpenApiRoute(this.runtime, (0,
|
|
17740
|
+
registerOpenApiRoute(this.runtime, (0, import_utils46.normalizeUrlPath)(this.basename), "root", route);
|
|
17397
17741
|
}
|
|
17398
17742
|
wrapResult(index, item, result2) {
|
|
17399
17743
|
return {
|
|
@@ -17502,7 +17846,7 @@ var RootRouter = class {
|
|
|
17502
17846
|
groupItemsByOrder(items) {
|
|
17503
17847
|
const groups = /* @__PURE__ */ new Map();
|
|
17504
17848
|
items.forEach((item, index) => {
|
|
17505
|
-
const order = (0,
|
|
17849
|
+
const order = (0, import_utils46.isNumber)(item.order) ? item.order : 0;
|
|
17506
17850
|
const group = groups.get(order);
|
|
17507
17851
|
if (group) {
|
|
17508
17852
|
group.push({ index, item });
|
|
@@ -17573,7 +17917,7 @@ var RootRouter = class {
|
|
|
17573
17917
|
const arrResult = await this.runGroup(req, groupedItems[x]);
|
|
17574
17918
|
results.push(...arrResult);
|
|
17575
17919
|
}
|
|
17576
|
-
return (0,
|
|
17920
|
+
return (0, import_utils46.orderBy)(results, ["index"], ["asc"]);
|
|
17577
17921
|
});
|
|
17578
17922
|
this.registerOpenApiRoute({
|
|
17579
17923
|
method: "post",
|
|
@@ -17591,14 +17935,14 @@ var RootRouter = class {
|
|
|
17591
17935
|
|
|
17592
17936
|
// src/routers/data-router.ts
|
|
17593
17937
|
var import_express_json_router10 = __toESM(require("@web-ts-toolkit/express-json-router"));
|
|
17594
|
-
var
|
|
17938
|
+
var import_utils47 = require("@web-ts-toolkit/utils");
|
|
17595
17939
|
init_runtime();
|
|
17596
17940
|
init_helpers();
|
|
17597
17941
|
init_schemas();
|
|
17598
17942
|
var clientErrors4 = import_express_json_router10.default.clientErrors;
|
|
17599
17943
|
function setOption2(parentKey, optionKey, option) {
|
|
17600
|
-
const key = (0,
|
|
17601
|
-
const value = (0,
|
|
17944
|
+
const key = (0, import_utils47.isUndefined)(option) ? parentKey : `${parentKey}.${optionKey}`;
|
|
17945
|
+
const value = (0, import_utils47.isUndefined)(option) ? optionKey : option;
|
|
17602
17946
|
assertMutableRouterOption("data", key);
|
|
17603
17947
|
this.runtime.setDataOption(this.dataName, key, value);
|
|
17604
17948
|
return this;
|
|
@@ -17647,7 +17991,7 @@ var DataRouter = class {
|
|
|
17647
17991
|
this.runtime = runtime;
|
|
17648
17992
|
this.runtime.setDataOptions(dataName, initialOptions);
|
|
17649
17993
|
this.options = this.runtime.getDataOptions(dataName);
|
|
17650
|
-
this.fullBasePath = (0,
|
|
17994
|
+
this.fullBasePath = (0, import_utils47.normalizeUrlPath)(this.options.parentPath + this.options.basePath);
|
|
17651
17995
|
this.dataName = dataName;
|
|
17652
17996
|
this.router = new import_express_json_router10.default(this.options.basePath, createSetDataCore(this.runtime), accessRouterResponseHandler);
|
|
17653
17997
|
this.setCollectionRoutes();
|
|
@@ -17680,8 +18024,8 @@ var DataRouter = class {
|
|
|
17680
18024
|
req.query
|
|
17681
18025
|
);
|
|
17682
18026
|
const svc = this.getService(req);
|
|
17683
|
-
const includeCount = (0,
|
|
17684
|
-
const includeExtraHeaders = (0,
|
|
18027
|
+
const includeCount = (0, import_utils43.parseBooleanString)(include_count);
|
|
18028
|
+
const includeExtraHeaders = (0, import_utils43.parseBooleanString)(include_extra_headers);
|
|
17685
18029
|
const result2 = await svc.find(
|
|
17686
18030
|
{},
|
|
17687
18031
|
{ select: parseSelectParam(select), sort, skip, limit, page, pageSize: page_size },
|
|
@@ -17799,7 +18143,7 @@ var DataRouter = class {
|
|
|
17799
18143
|
});
|
|
17800
18144
|
}
|
|
17801
18145
|
set(keyOrOptions, value) {
|
|
17802
|
-
if (arguments.length === 2 && (0,
|
|
18146
|
+
if (arguments.length === 2 && (0, import_utils47.isString)(keyOrOptions)) {
|
|
17803
18147
|
assertMutableRouterOption("data", keyOrOptions);
|
|
17804
18148
|
this.runtime.setDataOption(
|
|
17805
18149
|
this.dataName,
|
|
@@ -17807,7 +18151,7 @@ var DataRouter = class {
|
|
|
17807
18151
|
value
|
|
17808
18152
|
);
|
|
17809
18153
|
}
|
|
17810
|
-
if (arguments.length === 1 && (0,
|
|
18154
|
+
if (arguments.length === 1 && (0, import_utils47.isPlainObject)(keyOrOptions)) {
|
|
17811
18155
|
assertMutableRouterOptions("data", keyOrOptions);
|
|
17812
18156
|
this.runtime.setDataOptions(this.dataName, keyOrOptions);
|
|
17813
18157
|
}
|
|
@@ -17942,7 +18286,7 @@ function createRuntimeApi(runtime) {
|
|
|
17942
18286
|
const wtt2 = runtimeMiddleware;
|
|
17943
18287
|
wtt2.runtime = runtime;
|
|
17944
18288
|
wtt2.createRouter = function(modelName, options) {
|
|
17945
|
-
if ((0,
|
|
18289
|
+
if ((0, import_utils48.isUndefined)(options)) {
|
|
17946
18290
|
return new RootRouter(modelName, runtime);
|
|
17947
18291
|
}
|
|
17948
18292
|
if (typeof modelName === "string") {
|
|
@@ -17963,10 +18307,10 @@ function createRuntimeApi(runtime) {
|
|
|
17963
18307
|
};
|
|
17964
18308
|
wtt2.combineRoutes = combineRoutes;
|
|
17965
18309
|
wtt2.set = function(keyOrOptions, value) {
|
|
17966
|
-
if (arguments.length === 2 && (0,
|
|
18310
|
+
if (arguments.length === 2 && (0, import_utils48.isString)(keyOrOptions)) {
|
|
17967
18311
|
return runtime.setGlobalOption(keyOrOptions, value);
|
|
17968
18312
|
}
|
|
17969
|
-
if (arguments.length === 1 && (0,
|
|
18313
|
+
if (arguments.length === 1 && (0, import_utils48.isPlainObject)(keyOrOptions)) {
|
|
17970
18314
|
return runtime.setGlobalOptions(keyOrOptions);
|
|
17971
18315
|
}
|
|
17972
18316
|
};
|