@safeapi/safeapi
Version:
SafeAPI: Secure, deterministic, and tamper-resistant API policy engine for Node and browser.
45 lines (44 loc) • 1.22 kB
JavaScript
/**
* @internal
* SafeAPI benchmarking helpers for performance and stress tests.
*/
import { deepFreeze } from "../shared";
export function generateLargePolicy(guardCount, conditionCount) {
const guards = [];
for (let i = 0; i < guardCount; i++) {
const conditions = [];
for (let j = 0; j < conditionCount; j++) {
conditions.push({
field: `field${j}`,
operator: "equals",
value: `${i}-${j}`,
});
}
guards.push({
guardId: `g${i}`,
conditions: deepFreeze(conditions),
effect: i % 2 === 0 ? "allow" : "deny",
});
}
const policy = deepFreeze({
policyId: "bench-policy",
policyVersion: "v1",
ruleSetId: "bench-rs",
version: "v1",
policyKind: "auth",
rules: [],
guards: deepFreeze(guards),
});
return policy;
}
export function generateSafeApiContext(seed) {
const context = deepFreeze({
clientId: `client-${seed}`,
environment: "dev",
metadata: Object.freeze({
value: seed,
extra: `meta-${seed}`,
}),
});
return context;
}