Skip to content

Commit b7f2ece

Browse files
authored
Merge pull request #1125 from constructive-io/feat/check-constraint-node-types
feat: add Check constraint node types (CheckOneOf, CheckGreaterThan, CheckLessThan, CheckNotEqual)
2 parents facd581 + b8aa14e commit b7f2ece

6 files changed

Lines changed: 121 additions & 1 deletion

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { NodeTypeDefinition } from '../types';
2+
3+
export const CheckGreaterThan: NodeTypeDefinition = {
4+
name: 'CheckGreaterThan',
5+
slug: 'check_greater_than',
6+
category: 'check',
7+
display_name: 'Check Greater Than',
8+
description:
9+
'Adds a CHECK constraint that validates a column value is greater than a threshold (single-column: column > value) or that one column is greater than another (cross-column: columns[0] > columns[1]). Compiled via AST helpers.',
10+
parameter_schema: {
11+
type: 'object',
12+
properties: {
13+
column: {
14+
type: 'string',
15+
format: 'column-ref',
16+
description: 'Single column to compare against value (mutually exclusive with columns)',
17+
},
18+
value: {
19+
type: 'number',
20+
description: 'Threshold value for single-column comparison (column > value)',
21+
default: 0,
22+
},
23+
columns: {
24+
type: 'array',
25+
items: { type: 'string', format: 'column-ref' },
26+
description: 'Two columns for cross-column comparison (columns[0] > columns[1])',
27+
minItems: 2,
28+
maxItems: 2,
29+
},
30+
},
31+
},
32+
tags: ['check', 'constraint', 'validation', 'comparison'],
33+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { NodeTypeDefinition } from '../types';
2+
3+
export const CheckLessThan: NodeTypeDefinition = {
4+
name: 'CheckLessThan',
5+
slug: 'check_less_than',
6+
category: 'check',
7+
display_name: 'Check Less Than',
8+
description:
9+
'Adds a CHECK constraint that validates a column value is less than a threshold (single-column: column < value) or that one column is less than another (cross-column: columns[0] < columns[1]). Compiled via AST helpers.',
10+
parameter_schema: {
11+
type: 'object',
12+
properties: {
13+
column: {
14+
type: 'string',
15+
format: 'column-ref',
16+
description: 'Single column to compare against value (mutually exclusive with columns)',
17+
},
18+
value: {
19+
type: 'number',
20+
description: 'Threshold value for single-column comparison (column < value)',
21+
},
22+
columns: {
23+
type: 'array',
24+
items: { type: 'string', format: 'column-ref' },
25+
description: 'Two columns for cross-column comparison (columns[0] < columns[1])',
26+
minItems: 2,
27+
maxItems: 2,
28+
},
29+
},
30+
},
31+
tags: ['check', 'constraint', 'validation', 'comparison'],
32+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { NodeTypeDefinition } from '../types';
2+
3+
export const CheckNotEqual: NodeTypeDefinition = {
4+
name: 'CheckNotEqual',
5+
slug: 'check_not_equal',
6+
category: 'check',
7+
display_name: 'Check Not Equal',
8+
description:
9+
'Adds a CHECK constraint that validates two columns are not equal (columns[0] != columns[1]). Useful for preventing self-referencing rows. Compiled via AST helpers.',
10+
parameter_schema: {
11+
type: 'object',
12+
properties: {
13+
columns: {
14+
type: 'array',
15+
items: { type: 'string', format: 'column-ref' },
16+
description: 'Two columns that must not be equal',
17+
minItems: 2,
18+
maxItems: 2,
19+
},
20+
},
21+
required: ['columns'],
22+
},
23+
tags: ['check', 'constraint', 'validation', 'inequality'],
24+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { NodeTypeDefinition } from '../types';
2+
3+
export const CheckOneOf: NodeTypeDefinition = {
4+
name: 'CheckOneOf',
5+
slug: 'check_one_of',
6+
category: 'check',
7+
display_name: 'Check One Of',
8+
description:
9+
'Adds a CHECK constraint that validates a column value is one of an allowed set (e.g. tier IN (\'free\', \'paid\', \'custom\')). Compiled to column = ANY(ARRAY[...]) via AST helpers.',
10+
parameter_schema: {
11+
type: 'object',
12+
properties: {
13+
column: {
14+
type: 'string',
15+
format: 'column-ref',
16+
description: 'Column to validate against the allowed values',
17+
},
18+
values: {
19+
type: 'array',
20+
items: { type: 'string' },
21+
description: 'Array of allowed values for the column',
22+
},
23+
},
24+
required: ['column', 'values'],
25+
},
26+
tags: ['check', 'constraint', 'validation', 'enum'],
27+
};

packages/node-type-registry/src/data/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
export { CheckGreaterThan } from './check-greater-than';
2+
export { CheckLessThan } from './check-less-than';
3+
export { CheckNotEqual } from './check-not-equal';
4+
export { CheckOneOf } from './check-one-of';
15
export { DataAggregateLimitCounter } from './data-aggregate-limit-counter';
26
export { DataBillingMeter } from './data-billing-meter';
37
export { DataChunks } from './data-chunks';

packages/node-type-registry/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface NodeTypeDefinition {
4343
name: string;
4444
/** snake_case slug, e.g. 'authz_direct_owner' */
4545
slug: string;
46-
/** Category: authz | data | field | relation | view */
46+
/** Category: authz | check | data | field | relation | search | view */
4747
category: string;
4848
/** Human-readable display name, e.g. 'Direct Ownership' */
4949
display_name: string;

0 commit comments

Comments
 (0)