From 5352cdd71bc5cd5209be3c73bcae73e7a531a2bb Mon Sep 17 00:00:00 2001 From: Aditya Choudhari Date: Wed, 13 Nov 2024 15:09:14 -0800 Subject: [PATCH] fix: Rename condition stuff --- .../(targets)/target-providers/page.tsx | 8 +-- .../(targets)/targets/TargetPageContent.tsx | 4 +- .../_components/environment-drawer/Filter.tsx | 12 ++--- .../JobTargetConditionRender.tsx | 16 +++--- .../ComparisonConditionRender.tsx | 53 ++++++++++--------- .../target-condition/TargetConditionBadge.tsx | 20 +++---- .../TargetConditionDialog.tsx | 8 +-- .../TargetConditionRender.tsx | 4 +- .../target-condition/TargetViewForm.tsx | 4 +- .../target-condition-props.ts | 4 +- .../target-condition/useTargetFilter.ts | 6 +-- .../systems/SystemActionsDropdown.tsx | 12 ++--- .../_components/variables/ConfigFields.tsx | 4 +- .../_components/variables/VariableInputs.tsx | 28 +++++----- .../deployments/[deploymentSlug]/page.tsx | 24 ++++----- .../variables/VariableValueDropdown.tsx | 4 +- .../[deploymentSlug]/variables/page.tsx | 24 ++++----- .../api/src/router/deployment-variable.ts | 12 ++--- packages/api/src/router/target.ts | 4 +- .../db/src/schema/deployment-variables.ts | 8 +-- packages/db/src/schema/environment.ts | 8 +-- packages/db/src/schema/target.ts | 25 ++++----- .../events/src/triggers/deployment-deleted.ts | 8 +-- .../src/triggers/environment-deleted.ts | 8 +-- .../events/src/triggers/target-deleted.ts | 8 +-- .../src/job-variables-deployment/utils.ts | 4 +- .../targets/conditions/target-condition.ts | 48 +++++++++-------- packages/validators/src/variables/index.ts | 4 +- 28 files changed, 189 insertions(+), 183 deletions(-) diff --git a/apps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/page.tsx b/apps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/page.tsx index bb54d0be..fad7d880 100644 --- a/apps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/page.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/(targets)/target-providers/page.tsx @@ -1,4 +1,4 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; @@ -21,7 +21,7 @@ import { TooltipProvider, TooltipTrigger, } from "@ctrlplane/ui/tooltip"; -import { TargetFilterType } from "@ctrlplane/validators/targets"; +import { ResourceFilterType } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/server"; import { ProviderActionsDropdown } from "./ProviderActionsDropdown"; @@ -45,8 +45,8 @@ export default async function TargetProvidersPage({ if (targetProviders.length === 0) return ; const providers = targetProviders.map((provider) => { - const filter: TargetCondition = { - type: TargetFilterType.Provider, + const filter: ResourceCondition = { + type: ResourceFilterType.Provider, value: provider.id, operator: "equals", }; diff --git a/apps/webservice/src/app/[workspaceSlug]/(targets)/targets/TargetPageContent.tsx b/apps/webservice/src/app/[workspaceSlug]/(targets)/targets/TargetPageContent.tsx index 11dad66a..56a5dc6f 100644 --- a/apps/webservice/src/app/[workspaceSlug]/(targets)/targets/TargetPageContent.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/(targets)/targets/TargetPageContent.tsx @@ -1,7 +1,7 @@ "use client"; import type * as schema from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import React from "react"; import { IconDots, IconFilter, IconLoader2 } from "@tabler/icons-react"; import range from "lodash/range"; @@ -42,7 +42,7 @@ export const TargetPageContent: React.FC<{ { placeholderData: (prev) => prev }, ); - const onFilterChange = (condition: TargetCondition | undefined) => { + const onFilterChange = (condition: ResourceCondition | undefined) => { const cond = condition ?? defaultCondition; if (isEmptyCondition(cond)) setFilter(undefined); if (!isEmptyCondition(cond)) setFilter(cond); diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/environment-drawer/Filter.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/environment-drawer/Filter.tsx index 919e8527..49edbbdc 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/environment-drawer/Filter.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/environment-drawer/Filter.tsx @@ -1,5 +1,5 @@ import type * as SCHEMA from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; @@ -37,7 +37,7 @@ import { import { defaultCondition, isComparisonCondition, - targetCondition, + resourceCondition, } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/react"; @@ -46,7 +46,7 @@ import { TargetIcon } from "../TargetIcon"; const TargetViewsCombobox: React.FC<{ workspaceId: string; - onChange: (targetCondition: TargetCondition) => void; + onChange: (targetCondition: ResourceCondition) => void; }> = ({ workspaceId, onChange }) => { const targetViewsQ = api.target.view.list.useQuery(workspaceId, { enabled: workspaceId !== "", @@ -99,12 +99,12 @@ const TargetViewsCombobox: React.FC<{ }; const filterForm = z.object({ - targetFilter: targetCondition.optional(), + targetFilter: resourceCondition.optional(), }); const getFilter = ( - targetFilter: TargetCondition | null, -): TargetCondition | undefined => { + targetFilter: ResourceCondition | null, +): ResourceCondition | undefined => { if (targetFilter == null) return undefined; if (!isComparisonCondition(targetFilter)) return { diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobTargetConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobTargetConditionRender.tsx index 20d7311d..07411c55 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobTargetConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/job-condition/JobTargetConditionRender.tsx @@ -1,5 +1,5 @@ import type { JobTargetCondition } from "@ctrlplane/validators/jobs"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { useState } from "react"; import { useParams } from "next/navigation"; import { IconLoader2, IconSelector } from "@tabler/icons-react"; @@ -21,8 +21,8 @@ import { FilterType, } from "@ctrlplane/validators/conditions"; import { - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import type { JobConditionRenderProps } from "./job-condition-props"; @@ -47,9 +47,9 @@ export const JobTargetConditionRender: React.FC< const workspaceQ = api.workspace.bySlug.useQuery(workspaceSlug); const workspace = workspaceQ.data; - const searchFilter: TargetCondition = { - type: TargetFilterType.Name, - operator: TargetOperator.Like, + const searchFilter: ResourceCondition = { + type: ResourceFilterType.Name, + operator: ResourceOperator.Like, value: `%${searchDebounced}%`, }; @@ -62,13 +62,13 @@ export const JobTargetConditionRender: React.FC< system?.environments.map((env) => env.resourceFilter).filter(isPresent) ?? []; - const systemFilter: TargetCondition = { + const systemFilter: ResourceCondition = { type: FilterType.Comparison, operator: ComparisonOperator.Or, conditions: envFilters, }; - const systemTargetsFilter: TargetCondition | undefined = + const systemTargetsFilter: ResourceCondition | undefined = system != null ? { type: FilterType.Comparison, diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx index a0b723aa..553fb107 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/ComparisonConditionRender.tsx @@ -1,6 +1,6 @@ import type { ComparisonCondition, - TargetCondition, + ResourceCondition, } from "@ctrlplane/validators/targets"; import { IconChevronDown, @@ -34,8 +34,8 @@ import { ColumnOperator } from "@ctrlplane/validators/conditions"; import { doesConvertingToComparisonRespectMaxDepth, isComparisonCondition, - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import type { TargetConditionRenderProps } from "./target-condition-props"; @@ -44,10 +44,13 @@ import { TargetConditionRender } from "./TargetConditionRender"; export const ComparisonConditionRender: React.FC< TargetConditionRenderProps > = ({ condition, onChange, depth = 0, className }) => { - const setOperator = (operator: TargetOperator.And | TargetOperator.Or) => + const setOperator = (operator: ResourceOperator.And | ResourceOperator.Or) => onChange({ ...condition, operator }); - const updateCondition = (index: number, changedCondition: TargetCondition) => + const updateCondition = ( + index: number, + changedCondition: ResourceCondition, + ) => onChange({ ...condition, conditions: condition.conditions.map((c, i) => @@ -55,7 +58,7 @@ export const ComparisonConditionRender: React.FC< ), }); - const addCondition = (changedCondition: TargetCondition) => + const addCondition = (changedCondition: ResourceCondition) => onChange({ ...condition, conditions: [...condition.conditions, changedCondition], @@ -72,8 +75,8 @@ export const ComparisonConditionRender: React.FC< if (!cond) return; const newComparisonCondition: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [cond], }; @@ -107,8 +110,8 @@ export const ComparisonConditionRender: React.FC< } const newNotComparisonCondition: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, not: true, conditions: [cond], }; @@ -165,8 +168,8 @@ export const ComparisonConditionRender: React.FC< - And - Or + And + Or @@ -261,8 +264,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Metadata, - operator: TargetOperator.Equals, + type: ResourceFilterType.Metadata, + operator: ResourceOperator.Equals, key: "", value: "", }) @@ -273,8 +276,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Kind, - operator: TargetOperator.Equals, + type: ResourceFilterType.Kind, + operator: ResourceOperator.Equals, value: "", }) } @@ -284,8 +287,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Name, - operator: TargetOperator.Like, + type: ResourceFilterType.Name, + operator: ResourceOperator.Like, value: "", }) } @@ -295,7 +298,7 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Identifier, + type: ResourceFilterType.Identifier, operator: ColumnOperator.Like, value: "", }) @@ -306,8 +309,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Provider, - operator: TargetOperator.Equals, + type: ResourceFilterType.Provider, + operator: ResourceOperator.Equals, value: "", }) } @@ -318,8 +321,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [], not: false, }) @@ -332,8 +335,8 @@ export const ComparisonConditionRender: React.FC< addCondition({ - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, not: true, conditions: [], }) diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx index f6a81817..21567d9b 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionBadge.tsx @@ -5,7 +5,7 @@ import type { KindCondition, NameCondition, ProviderCondition, - TargetCondition, + ResourceCondition, } from "@ctrlplane/validators/targets"; import React from "react"; import _ from "lodash"; @@ -24,22 +24,22 @@ import { isMetadataCondition, isNameCondition, isProviderCondition, - TargetOperator, + ResourceOperator, } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/react"; const operatorVerbs = { - [TargetOperator.And]: "and", - [TargetOperator.Or]: "or", - [TargetOperator.Equals]: "is", - [TargetOperator.Null]: ( + [ResourceOperator.And]: "and", + [ResourceOperator.Or]: "or", + [ResourceOperator.Equals]: "is", + [ResourceOperator.Null]: ( is null ), - [TargetOperator.Regex]: "matches", - [TargetOperator.Like]: "contains", + [ResourceOperator.Regex]: "matches", + [ResourceOperator.Like]: "contains", }; const ConditionBadge: React.FC<{ @@ -205,7 +205,7 @@ const StringifiedProviderCondition: React.FC<{ }; const StringifiedTargetCondition: React.FC<{ - condition: TargetCondition; + condition: ResourceCondition; depth?: number; truncate?: boolean; tabbed?: boolean; @@ -241,7 +241,7 @@ const StringifiedTargetCondition: React.FC<{ }; export const TargetConditionBadge: React.FC<{ - condition: TargetCondition; + condition: ResourceCondition; tabbed?: boolean; }> = ({ condition, tabbed = false }) => ( diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionDialog.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionDialog.tsx index 9bef3060..beaeb96e 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionDialog.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionDialog.tsx @@ -1,5 +1,5 @@ import type * as schema from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import React, { useState } from "react"; import { useRouter } from "next/navigation"; @@ -26,8 +26,8 @@ import { TargetConditionRender } from "./TargetConditionRender"; import { TargetViewForm, targetViewFormSchema } from "./TargetViewForm"; type TargetConditionDialogProps = { - condition?: TargetCondition; - onChange: (condition: TargetCondition | undefined) => void; + condition?: ResourceCondition; + onChange: (condition: ResourceCondition | undefined) => void; children: React.ReactNode; }; @@ -94,7 +94,7 @@ export const TargetConditionDialog: React.FC = ({ type CreateTargetViewDialogProps = { workspaceId: string; - filter?: TargetCondition; + filter?: ResourceCondition; onSubmit?: (view: schema.ResourceView) => void; children: React.ReactNode; }; diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx index de605272..fd5780e5 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetConditionRender.tsx @@ -1,4 +1,4 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import React from "react"; import { @@ -23,7 +23,7 @@ import { TargetMetadataConditionRender } from "./TargetMetadataConditionRender"; * to render this component properly. */ export const TargetConditionRender: React.FC< - TargetConditionRenderProps + TargetConditionRenderProps > = ({ condition, onChange, depth = 0, className }) => { if (isComparisonCondition(condition)) return ( diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetViewForm.tsx b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetViewForm.tsx index 0e03db7f..e24e2df5 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetViewForm.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/TargetViewForm.tsx @@ -15,14 +15,14 @@ import { Textarea } from "@ctrlplane/ui/textarea"; import { defaultCondition, isValidTargetCondition, - targetCondition, + resourceCondition, } from "@ctrlplane/validators/targets"; import { TargetConditionRender } from "./TargetConditionRender"; export const targetViewFormSchema = z.object({ name: z.string().min(1), - filter: targetCondition.refine((data) => isValidTargetCondition(data), { + filter: resourceCondition.refine((data) => isValidTargetCondition(data), { message: "Invalid target condition", }), description: z.string().optional(), diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts index a60a2170..e69135ba 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/target-condition-props.ts @@ -1,6 +1,6 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; -export type TargetConditionRenderProps = { +export type TargetConditionRenderProps = { condition: T; onChange: (condition: T) => void; depth?: number; diff --git a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/useTargetFilter.ts b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/useTargetFilter.ts index fe3b8025..e0e90791 100644 --- a/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/useTargetFilter.ts +++ b/apps/webservice/src/app/[workspaceSlug]/_components/target-condition/useTargetFilter.ts @@ -1,5 +1,5 @@ import type * as schema from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { useCallback, useMemo } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import LZString from "lz-string"; @@ -8,7 +8,7 @@ export const useTargetFilter = () => { const urlParams = useSearchParams(); const router = useRouter(); - const filter = useMemo(() => { + const filter = useMemo(() => { const filterJson = urlParams.get("filter"); if (filterJson == null) return undefined; try { @@ -19,7 +19,7 @@ export const useTargetFilter = () => { }, [urlParams]); const setFilter = useCallback( - (filter: TargetCondition | undefined) => { + (filter: ResourceCondition | undefined) => { if (filter == null) { const query = new URLSearchParams(window.location.search); query.delete("filter"); diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/SystemActionsDropdown.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/SystemActionsDropdown.tsx index 2e663319..26f93fb7 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/SystemActionsDropdown.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/SystemActionsDropdown.tsx @@ -1,7 +1,7 @@ "use client"; import type * as schema from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import React from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; @@ -17,8 +17,8 @@ import { DropdownMenuTrigger, } from "@ctrlplane/ui/dropdown-menu"; import { - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import { DeleteSystemDialog } from "./[systemSlug]/_components/DeleteSystemDialog"; @@ -37,9 +37,9 @@ export const SystemActionsDropdown: React.FC = ({ const envFilters = system.environments .map((env) => env.resourceFilter) .filter(isPresent); - const filter: TargetCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + const filter: ResourceCondition = { + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, conditions: envFilters, }; const hash = LZString.compressToEncodedURIComponent(JSON.stringify(filter)); diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/ConfigFields.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/ConfigFields.tsx index 89a6586c..bfff7c23 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/ConfigFields.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/ConfigFields.tsx @@ -1,6 +1,6 @@ "use client"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import type { BooleanVariableConfigType, ChoiceVariableConfigType, @@ -272,7 +272,7 @@ type RunbookConfigFieldsFC = React.FC<{ export const TargetConfigFields: RunbookConfigFieldsFC< TargetVariableConfigType > = ({ config, updateConfig }) => { - const onFilterChange = (condition: TargetCondition | undefined) => { + const onFilterChange = (condition: ResourceCondition | undefined) => { const cond = condition ?? defaultCondition; if (isEmptyCondition(cond)) updateConfig({ ...config, filter: undefined }); if (!isEmptyCondition(cond)) updateConfig({ ...config, filter: cond }); diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/VariableInputs.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/VariableInputs.tsx index db04d7c3..698bc4a3 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/VariableInputs.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/_components/variables/VariableInputs.tsx @@ -1,4 +1,4 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import type { ChoiceVariableConfigType, StringVariableConfigType, @@ -26,8 +26,8 @@ import { } from "@ctrlplane/ui/select"; import { Textarea } from "@ctrlplane/ui/textarea"; import { - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/react"; @@ -129,17 +129,17 @@ export const VariableTargetInput: React.FC< .filter((e) => e.resourceFilter != null) .map((e) => e.resourceFilter!); - const tFilterConditions: TargetCondition[] = [ + const tFilterConditions: ResourceCondition[] = [ { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, conditions: envConditions, }, ]; if (filter != null) tFilterConditions.push(filter); - const tFilter: TargetCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + const tFilter: ResourceCondition = { + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: tFilterConditions, }; const allTargetsQ = api.target.byWorkspaceId.list.useQuery( @@ -151,14 +151,14 @@ export const VariableTargetInput: React.FC< const tFilterConditionsWithSearch = tFilterConditions.concat([ { - type: TargetFilterType.Name, - operator: TargetOperator.Like, + type: ResourceFilterType.Name, + operator: ResourceOperator.Like, value: `%${search}%`, }, ]); - const tFilterWithSearch: TargetCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + const tFilterWithSearch: ResourceCondition = { + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: tFilterConditionsWithSearch, }; const targetsQ = api.target.byWorkspaceId.list.useQuery( diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/page.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/page.tsx index a5fbba5a..fcb2f3b0 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/page.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/page.tsx @@ -1,7 +1,7 @@ import type { Deployment } from "@ctrlplane/db/schema"; import type { ComparisonCondition, - TargetCondition, + ResourceCondition, } from "@ctrlplane/validators/targets"; import React from "react"; import { notFound } from "next/navigation"; @@ -10,8 +10,8 @@ import { isPresent } from "ts-is-present"; import { Card } from "@ctrlplane/ui/card"; import { - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/server"; @@ -29,8 +29,8 @@ const Variables: React.FC<{ ); const systemTargetsFilter: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, conditions: await api.environment .bySystemId(deployment.systemId) .then((envs) => envs.map((e) => e.resourceFilter).filter(isPresent)), @@ -56,8 +56,8 @@ const Variables: React.FC<{ ); const filter: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [systemTargetsFilter, v.resourceFilter], }; @@ -80,17 +80,17 @@ const Variables: React.FC<{ if (defaultValue != null) { const restFilters = rest.map((v) => v.resourceFilter).filter(isPresent); - const filter: TargetCondition = + const filter: ResourceCondition = restFilters.length === 0 ? systemTargetsFilter : { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [ systemTargetsFilter, { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, not: true, conditions: restFilters, }, diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/VariableValueDropdown.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/VariableValueDropdown.tsx index fdd6bfc7..3c2cc35c 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/VariableValueDropdown.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/VariableValueDropdown.tsx @@ -44,7 +44,7 @@ import { Switch } from "@ctrlplane/ui/switch"; import { defaultCondition, isValidTargetCondition, - targetCondition, + resourceCondition, } from "@ctrlplane/validators/targets"; import type { VariableValue } from "./variable-data"; @@ -58,7 +58,7 @@ import { api } from "~/trpc/react"; const editVariableValueFormSchema = z.object({ value: z.union([z.string(), z.number(), z.boolean()]), - targetFilter: targetCondition + targetFilter: resourceCondition .nullish() .refine((data) => data == null || isValidTargetCondition(data), { message: "Invalid target condition", diff --git a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/page.tsx b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/page.tsx index e68b51ee..d1ed78e2 100644 --- a/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/page.tsx +++ b/apps/webservice/src/app/[workspaceSlug]/systems/[systemSlug]/deployments/[deploymentSlug]/variables/page.tsx @@ -1,14 +1,14 @@ import type { ComparisonCondition, - TargetCondition, + ResourceCondition, } from "@ctrlplane/validators/targets"; import { notFound } from "next/navigation"; import LZString from "lz-string"; import { isPresent } from "ts-is-present"; import { - TargetFilterType, - TargetOperator, + ResourceFilterType, + ResourceOperator, } from "@ctrlplane/validators/targets"; import { api } from "~/trpc/server"; @@ -27,8 +27,8 @@ export default async function VariablesPage({ ); const systemTargetsFilter: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, conditions: await api.environment .bySystemId(deployment.systemId) .then((envs) => envs.map((e) => e.resourceFilter).filter(isPresent)), @@ -54,8 +54,8 @@ export default async function VariablesPage({ ); const filter: ComparisonCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [systemTargetsFilter, v.resourceFilter], }; @@ -78,17 +78,17 @@ export default async function VariablesPage({ if (defaultValue != null) { const restFilters = rest.map((v) => v.resourceFilter).filter(isPresent); - const filter: TargetCondition = + const filter: ResourceCondition = restFilters.length === 0 ? systemTargetsFilter : { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, conditions: [ systemTargetsFilter, { - type: TargetFilterType.Comparison, - operator: TargetOperator.Or, + type: ResourceFilterType.Comparison, + operator: ResourceOperator.Or, not: true, conditions: restFilters, }, diff --git a/packages/api/src/router/deployment-variable.ts b/packages/api/src/router/deployment-variable.ts index 8187e3c4..aa1735b9 100644 --- a/packages/api/src/router/deployment-variable.ts +++ b/packages/api/src/router/deployment-variable.ts @@ -1,5 +1,5 @@ import type { DeploymentVariableValue } from "@ctrlplane/db/schema"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import _ from "lodash"; import { isPresent } from "ts-is-present"; import { z } from "zod"; @@ -125,7 +125,7 @@ const valueRouter = createTRPCRouter({ }) .then((d) => d?.system.environments ?? []); - const systemCondition: TargetCondition = { + const systemCondition: ResourceCondition = { type: FilterType.Comparison, operator: ComparisonOperator.Or, conditions: dep.map((e) => e.resourceFilter).filter(isPresent), @@ -175,7 +175,7 @@ const valueRouter = createTRPCRouter({ ), ); - const getOldTargetFilter = (): TargetCondition | null => { + const getOldTargetFilter = (): ResourceCondition | null => { if (value.id !== variable.defaultValueId) return value.resourceFilter; const conditions = otherValues .map((v) => v.resourceFilter) @@ -188,7 +188,7 @@ const valueRouter = createTRPCRouter({ }; }; - const getNewTargetFilter = (): TargetCondition | null => { + const getNewTargetFilter = (): ResourceCondition | null => { if (updatedValue.id !== newDefaultValueId) return updatedValue.resourceFilter; const conditions = otherValues @@ -202,12 +202,12 @@ const valueRouter = createTRPCRouter({ }; }; - const oldTargetFilter: TargetCondition = { + const oldTargetFilter: ResourceCondition = { type: FilterType.Comparison, operator: ComparisonOperator.And, conditions: [systemCondition, getOldTargetFilter()].filter(isPresent), }; - const newTargetFilter: TargetCondition = { + const newTargetFilter: ResourceCondition = { type: FilterType.Comparison, operator: ComparisonOperator.And, conditions: [systemCondition, getNewTargetFilter()].filter(isPresent), diff --git a/packages/api/src/router/target.ts b/packages/api/src/router/target.ts index f0ed2237..ad5aa2b2 100644 --- a/packages/api/src/router/target.ts +++ b/packages/api/src/router/target.ts @@ -27,7 +27,7 @@ import { } from "@ctrlplane/job-dispatch"; import { variablesAES256 } from "@ctrlplane/secrets"; import { Permission } from "@ctrlplane/validators/auth"; -import { targetCondition } from "@ctrlplane/validators/targets"; +import { resourceCondition } from "@ctrlplane/validators/targets"; import { createTRPCRouter, protectedProcedure } from "../trpc"; import { targetMetadataGroupRouter } from "./target-metadata-group"; @@ -343,7 +343,7 @@ export const targetRouter = createTRPCRouter({ .input( z.object({ workspaceId: z.string().uuid(), - filter: targetCondition.optional(), + filter: resourceCondition.optional(), limit: z.number().int().nonnegative().max(1000).default(200), offset: z.number().int().nonnegative().default(0), }), diff --git a/packages/db/src/schema/deployment-variables.ts b/packages/db/src/schema/deployment-variables.ts index 6f417df4..ad03f4b7 100644 --- a/packages/db/src/schema/deployment-variables.ts +++ b/packages/db/src/schema/deployment-variables.ts @@ -1,4 +1,4 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import type { VariableConfigType } from "@ctrlplane/validators/variables"; import type { InferInsertModel, InferSelectModel } from "drizzle-orm"; import type { AnyPgColumn, ColumnsWithTable } from "drizzle-orm/pg-core"; @@ -14,7 +14,7 @@ import { import { createInsertSchema } from "drizzle-zod"; import { z } from "zod"; -import { targetCondition } from "@ctrlplane/validators/targets"; +import { resourceCondition } from "@ctrlplane/validators/targets"; import { VariableConfig } from "@ctrlplane/validators/variables"; import { deployment } from "./deployment.js"; @@ -61,7 +61,7 @@ export const deploymentVariableValue = pgTable( variableId: uuid("variable_id").notNull(), value: jsonb("value").$type().notNull(), resourceFilter: jsonb("resource_filter") - .$type() + .$type() .default(sql`NULL`), }, (t) => ({ @@ -79,7 +79,7 @@ export type DeploymentVariableValue = InferSelectModel< >; export const createDeploymentVariableValue = createInsertSchema( deploymentVariableValue, - { resourceFilter: targetCondition }, + { resourceFilter: resourceCondition }, ) .omit({ id: true, diff --git a/packages/db/src/schema/environment.ts b/packages/db/src/schema/environment.ts index 4c34ccbb..0d4a4a43 100644 --- a/packages/db/src/schema/environment.ts +++ b/packages/db/src/schema/environment.ts @@ -1,4 +1,4 @@ -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import type { InferSelectModel } from "drizzle-orm"; import { relations, sql } from "drizzle-orm"; import { @@ -17,7 +17,7 @@ import { z } from "zod"; import { isValidTargetCondition, - targetCondition, + resourceCondition, } from "@ctrlplane/validators/targets"; import { user } from "./auth.js"; @@ -39,7 +39,7 @@ export const environment = pgTable( onDelete: "set null", }), resourceFilter: jsonb("resource_filter") - .$type() + .$type() .default(sql`NULL`), createdAt: timestamp("created_at", { withTimezone: true }) .notNull() @@ -54,7 +54,7 @@ export const environment = pgTable( export type Environment = InferSelectModel; export const createEnvironment = createInsertSchema(environment, { - resourceFilter: targetCondition + resourceFilter: resourceCondition .optional() .refine((filter) => filter == null || isValidTargetCondition(filter)), }) diff --git a/packages/db/src/schema/target.ts b/packages/db/src/schema/target.ts index 955426e6..32bda470 100644 --- a/packages/db/src/schema/target.ts +++ b/packages/db/src/schema/target.ts @@ -1,7 +1,7 @@ import type { MetadataCondition } from "@ctrlplane/validators/conditions"; import type { IdentifierCondition, - TargetCondition, + ResourceCondition, } from "@ctrlplane/validators/targets"; import type { InferInsertModel, InferSelectModel, SQL } from "drizzle-orm"; import { exists, like, not, notExists, or, relations, sql } from "drizzle-orm"; @@ -26,8 +26,8 @@ import { MetadataOperator, } from "@ctrlplane/validators/conditions"; import { - targetCondition, - TargetFilterType, + resourceCondition, + ResourceFilterType, } from "@ctrlplane/validators/targets"; import type { Tx } from "../common.js"; @@ -104,13 +104,13 @@ export const resourceView = pgTable("resource_view", { .references(() => workspace.id, { onDelete: "cascade" }), name: text("name").notNull(), description: text("description").default(""), - filter: jsonb("filter").notNull().$type(), + filter: jsonb("filter").notNull().$type(), }); export type ResourceView = InferSelectModel; export const createResourceView = createInsertSchema(resourceView, { - filter: targetCondition, + filter: resourceCondition, }).omit({ id: true }); export const updateResourceView = createResourceView.partial(); @@ -205,15 +205,16 @@ const buildIdentifierCondition = (tx: Tx, cond: IdentifierCondition): SQL => { return sql`${resource.identifier} ~ ${cond.value}`; }; -const buildCondition = (tx: Tx, cond: TargetCondition): SQL => { - if (cond.type === TargetFilterType.Metadata) +const buildCondition = (tx: Tx, cond: ResourceCondition): SQL => { + if (cond.type === ResourceFilterType.Metadata) return buildMetadataCondition(tx, cond); - if (cond.type === TargetFilterType.Kind) return eq(resource.kind, cond.value); - if (cond.type === TargetFilterType.Name) + if (cond.type === ResourceFilterType.Kind) + return eq(resource.kind, cond.value); + if (cond.type === ResourceFilterType.Name) return like(resource.name, cond.value); - if (cond.type === TargetFilterType.Provider) + if (cond.type === ResourceFilterType.Provider) return eq(resource.providerId, cond.value); - if (cond.type === TargetFilterType.Identifier) + if (cond.type === ResourceFilterType.Identifier) return buildIdentifierCondition(tx, cond); if (cond.conditions.length === 0) return sql`FALSE`; @@ -226,7 +227,7 @@ const buildCondition = (tx: Tx, cond: TargetCondition): SQL => { export function resourceMatchesMetadata( tx: Tx, - metadata?: TargetCondition | null, + metadata?: ResourceCondition | null, ): SQL | undefined { return metadata == null || Object.keys(metadata).length === 0 ? undefined diff --git a/packages/events/src/triggers/deployment-deleted.ts b/packages/events/src/triggers/deployment-deleted.ts index 82b2d660..11abbe52 100644 --- a/packages/events/src/triggers/deployment-deleted.ts +++ b/packages/events/src/triggers/deployment-deleted.ts @@ -1,12 +1,12 @@ import type { HookEvent } from "@ctrlplane/validators/events"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { isPresent } from "ts-is-present"; import { eq, isNotNull } from "@ctrlplane/db"; import { db } from "@ctrlplane/db/client"; import * as SCHEMA from "@ctrlplane/db/schema"; import { ComparisonOperator } from "@ctrlplane/validators/conditions"; -import { TargetFilterType } from "@ctrlplane/validators/targets"; +import { ResourceFilterType } from "@ctrlplane/validators/targets"; export const getEventsForDeploymentDeleted = async ( deployment: SCHEMA.Deployment, @@ -24,8 +24,8 @@ export const getEventsForDeploymentDeleted = async ( .filter(isPresent); if (envFilters.length === 0) return []; - const systemFilter: TargetCondition = { - type: TargetFilterType.Comparison, + const systemFilter: ResourceCondition = { + type: ResourceFilterType.Comparison, operator: ComparisonOperator.Or, conditions: envFilters, }; diff --git a/packages/events/src/triggers/environment-deleted.ts b/packages/events/src/triggers/environment-deleted.ts index 1fb25bbe..b76efaed 100644 --- a/packages/events/src/triggers/environment-deleted.ts +++ b/packages/events/src/triggers/environment-deleted.ts @@ -1,12 +1,12 @@ import type { HookEvent } from "@ctrlplane/validators/events"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { isPresent } from "ts-is-present"; import { and, eq, inArray, isNotNull, ne } from "@ctrlplane/db"; import { db } from "@ctrlplane/db/client"; import * as SCHEMA from "@ctrlplane/db/schema"; import { ComparisonOperator } from "@ctrlplane/validators/conditions"; -import { TargetFilterType } from "@ctrlplane/validators/targets"; +import { ResourceFilterType } from "@ctrlplane/validators/targets"; export const getEventsForEnvironmentDeleted = async ( environment: SCHEMA.Environment, @@ -32,8 +32,8 @@ export const getEventsForEnvironmentDeleted = async ( .map((e) => e.resourceFilter) .filter(isPresent); - const removedFromSystemFilter: TargetCondition = { - type: TargetFilterType.Comparison, + const removedFromSystemFilter: ResourceCondition = { + type: ResourceFilterType.Comparison, operator: ComparisonOperator.Or, not: true, conditions: envFilters, diff --git a/packages/events/src/triggers/target-deleted.ts b/packages/events/src/triggers/target-deleted.ts index f6b2cf98..49f4cdbf 100644 --- a/packages/events/src/triggers/target-deleted.ts +++ b/packages/events/src/triggers/target-deleted.ts @@ -1,12 +1,12 @@ import type { HookEvent } from "@ctrlplane/validators/events"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { isPresent } from "ts-is-present"; import { eq, isNotNull } from "@ctrlplane/db"; import { db } from "@ctrlplane/db/client"; import * as SCHEMA from "@ctrlplane/db/schema"; import { ComparisonOperator } from "@ctrlplane/validators/conditions"; -import { TargetFilterType } from "@ctrlplane/validators/targets"; +import { ResourceFilterType } from "@ctrlplane/validators/targets"; /** * Get events for a target that has been deleted. @@ -30,8 +30,8 @@ export const getEventsForTargetDeleted = async ( .map((e) => e.resourceFilter) .filter(isPresent); - const systemFilter: TargetCondition = { - type: TargetFilterType.Comparison, + const systemFilter: ResourceCondition = { + type: ResourceFilterType.Comparison, operator: ComparisonOperator.Or, conditions: filters, }; diff --git a/packages/job-dispatch/src/job-variables-deployment/utils.ts b/packages/job-dispatch/src/job-variables-deployment/utils.ts index 205d664b..b4cf8ddb 100644 --- a/packages/job-dispatch/src/job-variables-deployment/utils.ts +++ b/packages/job-dispatch/src/job-variables-deployment/utils.ts @@ -1,5 +1,5 @@ import type { Tx } from "@ctrlplane/db"; -import type { TargetCondition } from "@ctrlplane/validators/targets"; +import type { ResourceCondition } from "@ctrlplane/validators/targets"; import { isPresent } from "ts-is-present"; import { and, eq, takeFirstOrNull } from "@ctrlplane/db"; @@ -63,7 +63,7 @@ export const getVariableValues = (tx: Tx, variableId: string) => export const getMatchedTarget = ( tx: Tx, targetId: string, - targetFilter: TargetCondition | null, + targetFilter: ResourceCondition | null, ) => tx .select() diff --git a/packages/validators/src/targets/conditions/target-condition.ts b/packages/validators/src/targets/conditions/target-condition.ts index 15b40808..71ee1799 100644 --- a/packages/validators/src/targets/conditions/target-condition.ts +++ b/packages/validators/src/targets/conditions/target-condition.ts @@ -13,7 +13,7 @@ import { kindCondition } from "./kind-condition.js"; import { nameCondition } from "./name-condition.js"; import { providerCondition } from "./provider-condition.js"; -export type TargetCondition = +export type ResourceCondition = | ComparisonCondition | MetadataCondition | KindCondition @@ -21,7 +21,7 @@ export type TargetCondition = | ProviderCondition | IdentifierCondition; -export const targetCondition = z.union([ +export const resourceCondition = z.union([ comparisonCondition, metadataCondition, kindCondition, @@ -30,7 +30,7 @@ export const targetCondition = z.union([ identifierCondition, ]); -export enum TargetOperator { +export enum ResourceOperator { Equals = "equals", Like = "like", Regex = "regex", @@ -39,7 +39,7 @@ export enum TargetOperator { Or = "or", } -export enum TargetFilterType { +export enum ResourceFilterType { Metadata = "metadata", Kind = "kind", Name = "name", @@ -48,17 +48,17 @@ export enum TargetFilterType { Comparison = "comparison", } -export const defaultCondition: TargetCondition = { - type: TargetFilterType.Comparison, - operator: TargetOperator.And, +export const defaultCondition: ResourceCondition = { + type: ResourceFilterType.Comparison, + operator: ResourceOperator.And, not: false, conditions: [], }; export const isComparisonCondition = ( - condition: TargetCondition, + condition: ResourceCondition, ): condition is ComparisonCondition => - condition.type === TargetFilterType.Comparison; + condition.type === ResourceFilterType.Comparison; export const MAX_DEPTH_ALLOWED = 2; // 0 indexed @@ -66,7 +66,7 @@ export const MAX_DEPTH_ALLOWED = 2; // 0 indexed // including any nested conditions export const doesConvertingToComparisonRespectMaxDepth = ( depth: number, - condition: TargetCondition, + condition: ResourceCondition, ): boolean => { if (depth > MAX_DEPTH_ALLOWED) return false; if (isComparisonCondition(condition)) { @@ -78,37 +78,39 @@ export const doesConvertingToComparisonRespectMaxDepth = ( return true; }; -export const isEmptyCondition = (condition: TargetCondition): boolean => +export const isEmptyCondition = (condition: ResourceCondition): boolean => isComparisonCondition(condition) && condition.conditions.length === 0; export const isMetadataCondition = ( - condition: TargetCondition, + condition: ResourceCondition, ): condition is MetadataCondition => - condition.type === TargetFilterType.Metadata; + condition.type === ResourceFilterType.Metadata; export const isKindCondition = ( - condition: TargetCondition, -): condition is KindCondition => condition.type === TargetFilterType.Kind; + condition: ResourceCondition, +): condition is KindCondition => condition.type === ResourceFilterType.Kind; export const isNameCondition = ( - condition: TargetCondition, -): condition is NameCondition => condition.type === TargetFilterType.Name; + condition: ResourceCondition, +): condition is NameCondition => condition.type === ResourceFilterType.Name; export const isProviderCondition = ( - condition: TargetCondition, + condition: ResourceCondition, ): condition is ProviderCondition => - condition.type === TargetFilterType.Provider; + condition.type === ResourceFilterType.Provider; export const isIdentifierCondition = ( - condition: TargetCondition, + condition: ResourceCondition, ): condition is IdentifierCondition => - condition.type === TargetFilterType.Identifier; + condition.type === ResourceFilterType.Identifier; -export const isValidTargetCondition = (condition: TargetCondition): boolean => { +export const isValidTargetCondition = ( + condition: ResourceCondition, +): boolean => { if (isComparisonCondition(condition)) return condition.conditions.every((c) => isValidTargetCondition(c)); if (isMetadataCondition(condition)) { - if (condition.operator === TargetOperator.Null) + if (condition.operator === ResourceOperator.Null) return condition.value == null && condition.key.length > 0; return condition.value.length > 0 && condition.key.length > 0; } diff --git a/packages/validators/src/variables/index.ts b/packages/validators/src/variables/index.ts index 0e5db42c..1b0ff372 100644 --- a/packages/validators/src/variables/index.ts +++ b/packages/validators/src/variables/index.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -import { targetCondition } from "../targets/index.js"; +import { resourceCondition } from "../targets/index.js"; export const ChoiceVariableConfig = z.object({ type: z.literal("choice"), @@ -34,7 +34,7 @@ export type BooleanVariableConfigType = z.infer; export const TargetVariableConfig = z.object({ type: z.literal("target"), - filter: targetCondition.optional(), + filter: resourceCondition.optional(), }); export type TargetVariableConfigType = z.infer;