Rename schema to paramsSchema
Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -31,7 +31,7 @@ const testIntegration = () =>
|
||||
name: 'testRule1',
|
||||
description: 'Test rule 1',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
bar: z.number(),
|
||||
}),
|
||||
@@ -45,7 +45,7 @@ const testIntegration = () =>
|
||||
name: 'testRule2',
|
||||
description: 'Test rule 2',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
}),
|
||||
apply: (_resource: any) => false,
|
||||
|
||||
@@ -23,7 +23,7 @@ describe('createConditionFactory', () => {
|
||||
name: 'test-rule',
|
||||
description: 'test-description',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
}),
|
||||
apply: (_resource, _params) => true,
|
||||
|
||||
@@ -27,7 +27,7 @@ const transformConditions = createConditionTransformer([
|
||||
name: 'test-rule-1',
|
||||
description: 'Test rule 1',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
bar: z.number(),
|
||||
}),
|
||||
@@ -38,7 +38,7 @@ const transformConditions = createConditionTransformer([
|
||||
name: 'test-rule-2',
|
||||
description: 'Test rule 2',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
}),
|
||||
apply: jest.fn(),
|
||||
|
||||
@@ -47,9 +47,9 @@ const mapConditions = <TQuery>(
|
||||
}
|
||||
|
||||
const rule = getRule(criteria.rule);
|
||||
const result = rule.schema.safeParse(criteria.params);
|
||||
const result = rule.paramsSchema.safeParse(criteria.params);
|
||||
|
||||
if (rule.schema && !result.success) {
|
||||
if (rule.paramsSchema && !result.success) {
|
||||
throw new InputError(`Parameters to rule are invalid`, result.error);
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ const testRule1 = createPermissionRule({
|
||||
name: 'test-rule-1',
|
||||
description: 'Test rule 1',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string(),
|
||||
bar: z.number().describe('bar'),
|
||||
}),
|
||||
@@ -52,7 +52,7 @@ const testRule2 = createPermissionRule({
|
||||
name: 'test-rule-2',
|
||||
description: 'Test rule 2',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({
|
||||
paramsSchema: z.object({
|
||||
foo: z.string().describe('foo'),
|
||||
}),
|
||||
apply: (_resource: any, _foo) => false,
|
||||
@@ -603,7 +603,7 @@ describe('createPermissionIntegrationRouter', () => {
|
||||
name: testRule1.name,
|
||||
description: testRule1.description,
|
||||
resourceType: testRule1.resourceType,
|
||||
schema: {
|
||||
paramsSchema: {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
@@ -623,7 +623,7 @@ describe('createPermissionIntegrationRouter', () => {
|
||||
name: testRule2.name,
|
||||
description: testRule2.description,
|
||||
resourceType: testRule2.resourceType,
|
||||
schema: {
|
||||
paramsSchema: {
|
||||
$schema: 'http://json-schema.org/draft-07/schema#',
|
||||
additionalProperties: false,
|
||||
properties: {
|
||||
|
||||
@@ -127,9 +127,9 @@ const applyConditions = <TResourceType extends string, TResource>(
|
||||
}
|
||||
|
||||
const rule = getRule(criteria.rule);
|
||||
const result = rule.schema.safeParse(criteria.params);
|
||||
const result = rule.paramsSchema.safeParse(criteria.params);
|
||||
|
||||
if (rule.schema && !result.success) {
|
||||
if (rule.paramsSchema && !result.success) {
|
||||
throw new InputError(`Parameters to rule are invalid`, result.error);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ export const createPermissionIntegrationRouter = <
|
||||
name: rule.name,
|
||||
description: rule.description,
|
||||
resourceType: rule.resourceType,
|
||||
schema: zodToJsonSchema(rule.schema),
|
||||
paramsSchema: zodToJsonSchema(rule.paramsSchema),
|
||||
}));
|
||||
|
||||
return res.json({ permissions, rules: serializableRules });
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('permission integration utils', () => {
|
||||
name: 'test-rule-1',
|
||||
description: 'Test rule 1',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({}),
|
||||
paramsSchema: z.object({}),
|
||||
apply: jest.fn(),
|
||||
toQuery: jest.fn(),
|
||||
});
|
||||
@@ -40,7 +40,7 @@ describe('permission integration utils', () => {
|
||||
name: 'test-rule-2',
|
||||
description: 'Test rule 2',
|
||||
resourceType: 'test-resource',
|
||||
schema: z.object({}),
|
||||
paramsSchema: z.object({}),
|
||||
apply: jest.fn(),
|
||||
toQuery: jest.fn(),
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ export type PermissionRule<
|
||||
/**
|
||||
* A ZodSchema that documents the parameters that this rule accepts.
|
||||
*/
|
||||
schema: PermissionRuleSchema<TParams>;
|
||||
paramsSchema: PermissionRuleSchema<TParams>;
|
||||
|
||||
/**
|
||||
* Apply this rule to a resource already loaded from a backing data source. The params are
|
||||
|
||||
Reference in New Issue
Block a user