Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Kysely] Migration of condition result types off sequelize (#350)

authored by

Juan Mrad and committed by
GitHub
2edd495e d31dbc87

+114 -117
+3 -3
codegen.yaml
··· 114 114 # `buildGraphqlRuleParent` casts to it at the boundary. 115 115 Rule: ../models/rules/RuleModel.js#Rule 116 116 Condition: ../services/moderationConfigService/index.js#Condition 117 - ConditionWithResult: ../models/rules/RuleModel.js#ConditionWithResult 117 + ConditionWithResult: ../services/moderationConfigService/index.js#ConditionWithResult 118 118 ConditionSet: ../services/moderationConfigService/index.js#ConditionSet 119 - ConditionSetWithResult: ../models/rules/RuleModel.js#ConditionSetWithResult 119 + ConditionSetWithResult: ../services/moderationConfigService/index.js#ConditionSetWithResult 120 120 LeafCondition: ../services/moderationConfigService/index.js#LeafCondition 121 - LeafConditionWithResult: ../models/rules/RuleModel.js#LeafConditionWithResult 121 + LeafConditionWithResult: ../services/moderationConfigService/index.js#LeafConditionWithResult 122 122 UserRule: ../models/rules/RuleModel.js#Rule 123 123 ContentRule: ../models/rules/RuleModel.js#Rule 124 124 RuleInsights: ../models/rules/RuleModel.js#Rule
+2 -4
server/condition_evaluator/condition.ts
··· 16 16 import _ from 'lodash'; 17 17 import { type ReadonlyDeep } from 'type-fest'; 18 18 19 + import { getFieldDerivationCost } from '../services/derivedFieldsService/index.js'; 19 20 import { 21 + type Condition, 20 22 ConditionCompletionOutcome, 21 23 ConditionFailureOutcome, 22 24 type ConditionOutcome, 23 - } from '../models/rules/RuleModel.js'; 24 - import { getFieldDerivationCost } from '../services/derivedFieldsService/index.js'; 25 - import { 26 - type Condition, 27 25 type ConditionSet, 28 26 } from '../services/moderationConfigService/index.js'; 29 27 import { type SignalId } from '../services/signalsService/index.js';
+1 -1
server/condition_evaluator/conditionSet.test.ts
··· 1 1 import fc from 'fast-check'; 2 2 import _ from 'lodash'; 3 3 4 - import { ConditionCompletionOutcome } from '../models/rules/RuleModel.js'; 5 4 import { 5 + ConditionCompletionOutcome, 6 6 ConditionConjunction, 7 7 type LeafCondition, 8 8 } from '../services/moderationConfigService/index.js';
+5 -7
server/condition_evaluator/conditionSet.ts
··· 1 1 import _ from 'lodash'; 2 2 import { type ReadonlyDeep } from 'type-fest'; 3 3 4 + import { type RuleEvaluationContext } from '../rule_engine/RuleEvaluator.js'; 5 + import { type AggregationClause } from '../services/aggregationsService/index.js'; 4 6 import { 5 7 ConditionCompletionOutcome, 8 + ConditionConjunction, 6 9 ConditionFailureOutcome, 7 10 type ConditionOutcome, 11 + type ConditionSet, 8 12 type ConditionSetWithResult, 9 13 type ConditionWithResult, 10 - type LeafConditionWithResult, 11 - } from '../models/rules/RuleModel.js'; 12 - import { type RuleEvaluationContext } from '../rule_engine/RuleEvaluator.js'; 13 - import { type AggregationClause } from '../services/aggregationsService/index.js'; 14 - import { 15 - ConditionConjunction, 16 - type ConditionSet, 17 14 type LeafCondition, 15 + type LeafConditionWithResult, 18 16 } from '../services/moderationConfigService/index.js'; 19 17 import { equalLengthZip } from '../utils/fp-helpers.js'; 20 18 import { assertUnreachable } from '../utils/misc.js';
+1 -1
server/condition_evaluator/leafCondition.test.ts
··· 1 1 import fc from 'fast-check'; 2 2 3 - import { ConditionCompletionOutcome } from '../models/rules/RuleModel.js'; 4 3 import type { RuleEvaluationContext } from '../rule_engine/RuleEvaluator.js'; 4 + import { ConditionCompletionOutcome } from '../services/moderationConfigService/index.js'; 5 5 import { SignalType } from '../services/signalsService/index.js'; 6 6 import { 7 7 LeafConditionArbitrary,
+4 -6
server/condition_evaluator/leafCondition.ts
··· 12 12 type TaggedItemData, 13 13 } from '../models/rules/item-type-fields.js'; 14 14 import { 15 - ConditionCompletionOutcome, 16 - ConditionFailureOutcome, 17 - type ConditionResult, 18 - } from '../models/rules/RuleModel.js'; 19 - import { 20 15 getUserFromRuleInput, 21 16 isFullSubmission, 22 17 type RuleEvaluationContext, ··· 31 26 } from '../services/itemProcessingService/index.js'; 32 27 import { 33 28 CoopInput, 34 - ValueComparator, 29 + ConditionCompletionOutcome, 30 + ConditionFailureOutcome, 35 31 type ConditionInput, 32 + type ConditionResult, 36 33 type ConditionSignalInfo, 37 34 type LeafCondition, 35 + ValueComparator, 38 36 } from '../services/moderationConfigService/index.js'; 39 37 import { 40 38 isSignalErrorResult,
+4 -6
server/graphql/generated.ts
··· 20 20 import type { HashBank } from '../models/HashBankModel.js'; 21 21 import type { Backtest } from '../models/rules/BacktestModel.js'; 22 22 import type { ItemType } from '../models/rules/ItemTypeModel.js'; 23 - import type { 24 - ConditionSetWithResult, 25 - ConditionWithResult, 26 - LeafConditionWithResult, 27 - Rule, 28 - } from '../models/rules/RuleModel.js'; 23 + import type { Rule } from '../models/rules/RuleModel.js'; 29 24 import type { User } from '../models/UserModel.js'; 30 25 import type { SignalWithScore } from '../services/analyticsQueries/RuleActionInsights.js'; 31 26 import type { DerivedFieldSpecSource } from '../services/derivedFieldsService/helpers.js'; ··· 46 41 import type { 47 42 Condition, 48 43 ConditionSet, 44 + ConditionSetWithResult, 45 + ConditionWithResult, 49 46 LeafCondition, 47 + LeafConditionWithResult, 50 48 } from '../services/moderationConfigService/index.js'; 51 49 import type { 52 50 CustomAction,
+1 -1
server/graphql/modules/investigation.ts
··· 3 3 4 4 import _ from 'lodash'; 5 5 6 - import { type ConditionSetWithResult } from '../../models/rules/RuleModel.js'; 6 + import { type ConditionSetWithResult } from '../../services/moderationConfigService/index.js'; 7 7 import { 8 8 getFieldValueForRole, 9 9 type ItemSubmission,
-12
server/models/rules/RuleModel.ts
··· 22 22 import { type SequelizeAction } from './ActionModel.js'; 23 23 import { type RuleLatestVersion } from './RuleLatestVersionModel.js'; 24 24 25 - export { 26 - ConditionCompletionOutcome, 27 - ConditionFailureOutcome, 28 - type ConditionOutcome, 29 - type ConditionCompletionMetadata, 30 - type ConditionFailureMetadata, 31 - type ConditionResult, 32 - type ConditionWithResult, 33 - type ConditionSetWithResult, 34 - type LeafConditionWithResult, 35 - } from './ruleTypes.js'; 36 - 37 25 const { Model, Op } = sequelize; 38 26 const { without } = _; 39 27
-62
server/models/rules/ruleTypes.ts
··· 1 - import { type ScalarType, type TaggedScalar } from '@roostorg/types'; 2 - 3 1 import { 4 2 type RuleAlarmStatus, 5 3 RuleStatus, 6 4 type RuleType, 7 5 type ConditionSet, 8 - type LeafCondition, 9 6 type Action, 10 7 type Policy, 11 8 } from '../../services/moderationConfigService/index.js'; 12 - import { type SerializableError } from '../../utils/errors.js'; 13 - import { 14 - type NonEmptyArray, 15 - type WithUndefined, 16 - } from '../../utils/typescript-types.js'; 17 9 import { type User } from '../UserModel.js'; 18 - import { type TaggedItemData } from './item-type-fields.js'; 19 - 20 - export enum ConditionCompletionOutcome { 21 - PASSED = 'PASSED', 22 - FAILED = 'FAILED', 23 - INAPPLICABLE = 'INAPPLICABLE', 24 - } 25 - 26 - export enum ConditionFailureOutcome { 27 - ERRORED = 'ERRORED', 28 - } 29 - 30 - export type ConditionOutcome = 31 - | ConditionCompletionOutcome 32 - | ConditionFailureOutcome; 33 - 34 - export type ConditionCompletionMetadata = { 35 - score?: string; 36 - matchedValue?: string; 37 - }; 38 - 39 - export type ConditionFailureMetadata = { 40 - error?: SerializableError; 41 - }; 42 - 43 - type ConditionResultCommonMetadata = { 44 - signalInputValues?: (TaggedScalar<ScalarType> | TaggedItemData)[]; 45 - }; 46 - 47 - // prettier-ignore 48 - export type ConditionResult = 49 - | ({ outcome: ConditionCompletionOutcome } 50 - & ConditionCompletionMetadata 51 - & Partial<Pick<ConditionFailureMetadata, 'error'>> 52 - & ConditionResultCommonMetadata) 53 - | ({ outcome: ConditionFailureOutcome; } 54 - & ConditionFailureMetadata 55 - & WithUndefined<ConditionCompletionMetadata> 56 - & ConditionResultCommonMetadata) 57 - 58 - export type ConditionWithResult = 59 - | LeafConditionWithResult 60 - | ConditionSetWithResult; 61 - 62 - export type ConditionSetWithResult = Omit<ConditionSet, 'conditions'> & { 63 - conditions: 64 - | NonEmptyArray<LeafConditionWithResult> 65 - | NonEmptyArray<ConditionSetWithResult>; 66 - result?: ConditionResult; 67 - }; 68 - 69 - export type LeafConditionWithResult = LeafCondition & { 70 - result?: ConditionResult; 71 - }; 72 10 73 11 export type RuleLatestVersionRow = { 74 12 ruleId: string;
+2 -2
server/rule_engine/RuleEngine.ts
··· 7 7 } from '../condition_evaluator/conditionSet.js'; 8 8 import { type Dependencies } from '../iocContainer/index.js'; 9 9 import { inject } from '../iocContainer/utils.js'; 10 - import { ConditionCompletionOutcome } from '../models/rules/RuleModel.js'; 11 10 import { type PlainRuleWithLatestVersion } from '../models/rules/ruleTypes.js'; 12 11 import { evaluateAggregationRuntimeArgsForItem } from '../services/aggregationsService/index.js'; 13 12 import { type ItemSubmission } from '../services/itemProcessingService/index.js'; 14 13 import { 15 - RuleStatus, 16 14 type Action, 15 + ConditionCompletionOutcome, 17 16 type ConditionSet, 17 + RuleStatus, 18 18 } from '../services/moderationConfigService/index.js'; 19 19 import { type RuleExecutionCorrelationId } from '../services/analyticsLoggers/index.js'; 20 20 import {
+1 -1
server/rule_engine/RuleEvaluator.ts
··· 6 6 import makeGetDerivedFieldValueWithCache from '../condition_evaluator/getDerivedFieldValue.js'; 7 7 import { type Dependencies } from '../iocContainer/index.js'; 8 8 import { inject } from '../iocContainer/utils.js'; 9 - import { type ConditionSetWithResult } from '../models/rules/RuleModel.js'; 10 9 import { 11 10 type DerivedFieldSpec, 12 11 type DerivedFieldValue, ··· 14 13 import { type ItemSubmission } from '../services/itemProcessingService/index.js'; 15 14 import { 16 15 type ConditionSet, 16 + type ConditionSetWithResult, 17 17 type ItemType, 18 18 } from '../services/moderationConfigService/index.js'; 19 19 import { type TransientRunSignalWithCache } from '../services/orgAwareSignalExecutionService/index.js';
+1 -1
server/services/analyticsLoggers/ReportingRuleExecutionLogger.ts
··· 3 3 4 4 import { type Dependencies } from '../../iocContainer/index.js'; 5 5 import { inject } from '../../iocContainer/utils.js'; 6 - import { type ConditionSetWithResult } from '../../models/rules/RuleModel.js'; 7 6 import { type RuleEnvironment } from '../../rule_engine/RuleEngine.js'; 8 7 import { type ItemSubmission } from '../../services/itemProcessingService/index.js'; 8 + import { type ConditionSetWithResult } from '../../services/moderationConfigService/index.js'; 9 9 import { type ReportingRuleExecutionCorrelationId } from '../../services/reportingService/index.js'; 10 10 import { fromCorrelationId } from '../../utils/correlationIds.js'; 11 11 import { jsonStringify } from '../../utils/encoding.js';
+1 -1
server/services/analyticsLoggers/RoutingRuleExecutionLogger.ts
··· 3 3 4 4 import { type Dependencies } from '../../iocContainer/index.js'; 5 5 import { inject } from '../../iocContainer/utils.js'; 6 - import { type ConditionSetWithResult } from '../../models/rules/RuleModel.js'; 7 6 import { 8 7 isFullSubmission, 9 8 type RuleInput, 10 9 } from '../../rule_engine/RuleEvaluator.js'; 11 10 import { type ManualReviewJobKind } from '../../services/manualReviewToolService/index.js'; 11 + import { type ConditionSetWithResult } from '../../services/moderationConfigService/index.js'; 12 12 import { fromCorrelationId } from '../../utils/correlationIds.js'; 13 13 import { jsonStringifyUnstable } from '../../utils/encoding.js'; 14 14 import { getUtcDateOnlyString } from '../../utils/time.js';
+1 -1
server/services/analyticsLoggers/RuleExecutionLogger.ts
··· 3 3 4 4 import { type Dependencies } from '../../iocContainer/index.js'; 5 5 import { inject } from '../../iocContainer/utils.js'; 6 - import { type ConditionSetWithResult } from '../../models/rules/RuleModel.js'; 7 6 import { type RuleEnvironment } from '../../rule_engine/RuleEngine.js'; 7 + import { type ConditionSetWithResult } from '../../services/moderationConfigService/index.js'; 8 8 import { fromCorrelationId } from '../../utils/correlationIds.js'; 9 9 import { jsonStringifyUnstable } from '../../utils/encoding.js'; 10 10
+4 -4
server/services/analyticsLoggers/ruleExecutionLoggingUtils.ts
··· 1 1 import { type ReadonlyDeep } from 'type-fest'; 2 2 3 3 import { isConditionSet } from '../../condition_evaluator/condition.js'; 4 + import { type LocationArea } from '../../models/types/locationArea.js'; 5 + import { type DerivedFieldSpec } from '../../services/derivedFieldsService/index.js'; 4 6 import { 5 7 type ConditionResult, 6 8 type ConditionSetWithResult, 9 + type CoopInput, 7 10 type LeafConditionWithResult, 8 - } from '../../models/rules/RuleModel.js'; 9 - import { type LocationArea } from '../../models/types/locationArea.js'; 10 - import { type DerivedFieldSpec } from '../../services/derivedFieldsService/index.js'; 11 - import { type CoopInput } from '../../services/moderationConfigService/index.js'; 11 + } from '../../services/moderationConfigService/index.js'; 12 12 import { isSignalId } from '../../services/signalsService/index.js'; 13 13 import { type CorrelationId } from '../../utils/correlationIds.js'; 14 14 import { jsonParse, tryJsonParse, type JsonOf } from '../../utils/encoding.js';
+1 -1
server/services/analyticsQueries/RuleActionInsights.ts
··· 5 5 import { formatClickhouseQuery } from '../../plugins/warehouse/utils/clickhouseSql.js'; 6 6 import { type Dependencies } from '../../iocContainer/index.js'; 7 7 import { inject } from '../../iocContainer/utils.js'; 8 - import type { ConditionWithResult } from '../../models/rules/RuleModel.js'; 9 8 import { type RuleEnvironment } from '../../rule_engine/RuleEngine.js'; 10 9 import { type NormalizedItemData } from '../../services/itemProcessingService/index.js'; 10 + import { type ConditionWithResult } from '../../services/moderationConfigService/index.js'; 11 11 import { 12 12 BuiltInThirdPartySignalType, 13 13 SignalType,
+12
server/services/moderationConfigService/index.ts
··· 30 30 } from './types/rules.js'; 31 31 32 32 export { 33 + ConditionCompletionOutcome, 34 + ConditionFailureOutcome, 35 + ConditionOutcome, 36 + ConditionCompletionMetadata, 37 + ConditionFailureMetadata, 38 + ConditionResult, 39 + ConditionWithResult, 40 + ConditionSetWithResult, 41 + LeafConditionWithResult, 42 + } from './types/conditionResults.js'; 43 + 44 + export { 33 45 Action, 34 46 ActionType, 35 47 CustomAction,
+69
server/services/moderationConfigService/types/conditionResults.ts
··· 1 + import { type ScalarType, type TaggedScalar } from '@roostorg/types'; 2 + 3 + import { type TaggedItemData } from '../../../models/rules/item-type-fields.js'; 4 + import { type SerializableError } from '../../../utils/errors.js'; 5 + import { 6 + type NonEmptyArray, 7 + type WithUndefined, 8 + } from '../../../utils/typescript-types.js'; 9 + import { type ConditionSet, type LeafCondition } from './rules.js'; 10 + 11 + /** 12 + * Outcome + result types for condition evaluation. Lived on 13 + * `models/rules/RuleModel.ts` (via `ruleTypes.ts`) for historical reasons but 14 + * they don't depend on Sequelize — moving them here keeps them importable from 15 + * Sequelize-free code paths once the `models/*Model.ts` files are deleted. 16 + */ 17 + 18 + export enum ConditionCompletionOutcome { 19 + PASSED = 'PASSED', 20 + FAILED = 'FAILED', 21 + INAPPLICABLE = 'INAPPLICABLE', 22 + } 23 + 24 + export enum ConditionFailureOutcome { 25 + ERRORED = 'ERRORED', 26 + } 27 + 28 + export type ConditionOutcome = 29 + | ConditionCompletionOutcome 30 + | ConditionFailureOutcome; 31 + 32 + export type ConditionCompletionMetadata = { 33 + score?: string; 34 + matchedValue?: string; 35 + }; 36 + 37 + export type ConditionFailureMetadata = { 38 + error?: SerializableError; 39 + }; 40 + 41 + type ConditionResultCommonMetadata = { 42 + signalInputValues?: (TaggedScalar<ScalarType> | TaggedItemData)[]; 43 + }; 44 + 45 + // prettier-ignore 46 + export type ConditionResult = 47 + | ({ outcome: ConditionCompletionOutcome } 48 + & ConditionCompletionMetadata 49 + & Partial<Pick<ConditionFailureMetadata, 'error'>> 50 + & ConditionResultCommonMetadata) 51 + | ({ outcome: ConditionFailureOutcome; } 52 + & ConditionFailureMetadata 53 + & WithUndefined<ConditionCompletionMetadata> 54 + & ConditionResultCommonMetadata) 55 + 56 + export type ConditionWithResult = 57 + | LeafConditionWithResult 58 + | ConditionSetWithResult; 59 + 60 + export type ConditionSetWithResult = Omit<ConditionSet, 'conditions'> & { 61 + conditions: 62 + | NonEmptyArray<LeafConditionWithResult> 63 + | NonEmptyArray<ConditionSetWithResult>; 64 + result?: ConditionResult; 65 + }; 66 + 67 + export type LeafConditionWithResult = LeafCondition & { 68 + result?: ConditionResult; 69 + };
+1 -3
server/test/arbitraries/Condition.ts
··· 3 3 import { outcomeToNullableBool } from '../../condition_evaluator/condition.js'; 4 4 import { 5 5 ConditionCompletionOutcome, 6 - ConditionFailureOutcome, 7 - } from '../../models/rules/RuleModel.js'; 8 - import { 9 6 ConditionConjunction, 7 + ConditionFailureOutcome, 10 8 ValueComparator, 11 9 type ConditionInput, 12 10 type ConditionSet,