Skip to content

Commit da8c625

Browse files
committed
Update schema (move some types to shared.validation.ts)
1 parent f9bf01b commit da8c625

File tree

5 files changed

+194
-19
lines changed

5 files changed

+194
-19
lines changed

docs/assets/api/schemas.json

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,15 @@
10491049
},
10501050
"value": {
10511051
"type": "string"
1052+
},
1053+
"cohortValues": {
1054+
"type": "object",
1055+
"patternProperties": {
1056+
"^(.*)$": {
1057+
"type": "string"
1058+
}
1059+
},
1060+
"title": "CohortValues"
10521061
}
10531062
},
10541063
"required": ["id", "type", "scope", "definition", "value"]
@@ -2197,6 +2206,131 @@
21972206
},
21982207
"timeoutSeconds": {
21992208
"type": "number"
2209+
},
2210+
"autoTransferConfig": {
2211+
"anyOf": [
2212+
{
2213+
"anyOf": [
2214+
{
2215+
"additionalProperties": false,
2216+
"type": "object",
2217+
"properties": {
2218+
"type": {
2219+
"const": "default",
2220+
"type": "string"
2221+
},
2222+
"autoCohortParticipantConfig": {
2223+
"$ref": "#/$defs/CohortParticipantConfig"
2224+
},
2225+
"minParticipants": {
2226+
"minimum": 1,
2227+
"type": "number"
2228+
},
2229+
"maxParticipants": {
2230+
"minimum": 1,
2231+
"type": "number"
2232+
}
2233+
},
2234+
"required": [
2235+
"type",
2236+
"autoCohortParticipantConfig",
2237+
"minParticipants",
2238+
"maxParticipants"
2239+
],
2240+
"title": "DefaultStageConfig"
2241+
},
2242+
{
2243+
"$ref": "#/$defs/SurveyStageConfig"
2244+
},
2245+
{
2246+
"additionalProperties": false,
2247+
"type": "object",
2248+
"properties": {
2249+
"type": {
2250+
"const": "condition",
2251+
"type": "string"
2252+
},
2253+
"autoCohortParticipantConfig": {
2254+
"$ref": "#/$defs/CohortParticipantConfig"
2255+
},
2256+
"transferGroups": {
2257+
"minItems": 1,
2258+
"type": "array",
2259+
"items": {
2260+
"additionalProperties": false,
2261+
"type": "object",
2262+
"properties": {
2263+
"id": {
2264+
"minLength": 1,
2265+
"type": "string"
2266+
},
2267+
"name": {
2268+
"minLength": 1,
2269+
"type": "string"
2270+
},
2271+
"composition": {
2272+
"minItems": 1,
2273+
"type": "array",
2274+
"items": {
2275+
"additionalProperties": false,
2276+
"type": "object",
2277+
"properties": {
2278+
"id": {
2279+
"minLength": 1,
2280+
"type": "string"
2281+
},
2282+
"condition": {
2283+
"title": "Condition",
2284+
"anyOf": [
2285+
{
2286+
"$ref": "#/$defs/ComparisonCondition"
2287+
},
2288+
{
2289+
"$ref": "#/$defs/ConditionGroup"
2290+
}
2291+
]
2292+
},
2293+
"minCount": {
2294+
"minimum": 1,
2295+
"type": "number"
2296+
},
2297+
"maxCount": {
2298+
"minimum": 1,
2299+
"type": "number"
2300+
}
2301+
},
2302+
"required": [
2303+
"id",
2304+
"condition",
2305+
"minCount",
2306+
"maxCount"
2307+
],
2308+
"title": "Composition"
2309+
}
2310+
},
2311+
"targetCohortAlias": {
2312+
"minLength": 1,
2313+
"type": "string"
2314+
}
2315+
},
2316+
"required": ["id", "name", "composition"],
2317+
"title": "TransferGroup"
2318+
}
2319+
}
2320+
},
2321+
"required": [
2322+
"type",
2323+
"autoCohortParticipantConfig",
2324+
"transferGroups"
2325+
],
2326+
"title": "ConditionStageConfig"
2327+
}
2328+
]
2329+
},
2330+
{
2331+
"type": "null"
2332+
}
2333+
]
22002334
}
22012335
},
22022336
"required": [
@@ -2206,7 +2340,8 @@
22062340
"descriptions",
22072341
"progress",
22082342
"enableTimeout",
2209-
"timeoutSeconds"
2343+
"timeoutSeconds",
2344+
"autoTransferConfig"
22102345
],
22112346
"title": "TransferStageConfig"
22122347
}
@@ -2427,6 +2562,35 @@
24272562
}
24282563
},
24292564
"title": "VariableMap"
2565+
},
2566+
"cohortDefinitions": {
2567+
"type": "array",
2568+
"items": {
2569+
"additionalProperties": false,
2570+
"type": "object",
2571+
"properties": {
2572+
"id": {
2573+
"minLength": 1,
2574+
"type": "string"
2575+
},
2576+
"alias": {
2577+
"minLength": 1,
2578+
"type": "string"
2579+
},
2580+
"name": {
2581+
"minLength": 1,
2582+
"type": "string"
2583+
},
2584+
"description": {
2585+
"type": "string"
2586+
},
2587+
"generatedCohortId": {
2588+
"type": "string"
2589+
}
2590+
},
2591+
"required": ["id", "alias", "name"],
2592+
"title": "CohortDefinition"
2593+
}
24302594
}
24312595
},
24322596
"required": [
@@ -2554,6 +2718,9 @@
25542718
"id": {
25552719
"type": "string"
25562720
},
2721+
"alias": {
2722+
"type": "string"
2723+
},
25572724
"metadata": {
25582725
"type": "object",
25592726
"properties": {

utils/src/cohort.validation.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {Type, type Static} from '@sinclair/typebox';
2-
import {MetadataConfigSchema} from './shared.validation';
3-
import {CohortParticipantConfigSchema} from './experiment.validation';
2+
import {
3+
MetadataConfigSchema,
4+
CohortParticipantConfigSchema,
5+
} from './shared.validation';
46
import {StageConfigData} from './stages/stage.validation';
57

68
/** Shorthand for strict TypeBox object validation */

utils/src/experiment.validation.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import {Type, type Static} from '@sinclair/typebox';
22
import {
33
MetadataConfigSchema,
44
PermissionsConfigSchema,
5+
CohortParticipantConfigSchema,
56
} from './shared.validation';
7+
8+
// Re-export for backwards compatibility
9+
export {CohortParticipantConfigSchema};
610
import {StageConfigData} from './stages/stage.validation';
711
import {
812
AgentDataObjectData,
@@ -52,21 +56,6 @@ export type ExperimentDeletionData = Static<typeof ExperimentDeletionData>;
5256
// ************************************************************************* //
5357
// writeExperiment endpoint //
5458
// ************************************************************************* //
55-
export const CohortParticipantConfigSchema = Type.Object(
56-
{
57-
minParticipantsPerCohort: Type.Union([
58-
Type.Null(),
59-
Type.Number({minimum: 0}),
60-
]),
61-
maxParticipantsPerCohort: Type.Union([
62-
Type.Null(),
63-
Type.Number({minimum: 1}),
64-
]),
65-
includeAllParticipantsInCohortCount: Type.Boolean(),
66-
botProtection: Type.Boolean(),
67-
},
68-
{$id: 'CohortParticipantConfig'},
69-
);
7059

7160
export const ProlificConfigSchema = Type.Object({
7261
enableProlificIntegration: Type.Boolean(),

utils/src/shared.validation.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,20 @@ export const PermissionsConfigSchema = Type.Object({
2727
]),
2828
readers: Type.Array(Type.String()),
2929
});
30+
31+
/** CohortParticipantConfig input validation. */
32+
export const CohortParticipantConfigSchema = Type.Object(
33+
{
34+
minParticipantsPerCohort: Type.Union([
35+
Type.Null(),
36+
Type.Number({minimum: 0}),
37+
]),
38+
maxParticipantsPerCohort: Type.Union([
39+
Type.Null(),
40+
Type.Number({minimum: 1}),
41+
]),
42+
includeAllParticipantsInCohortCount: Type.Boolean(),
43+
botProtection: Type.Boolean(),
44+
},
45+
{$id: 'CohortParticipantConfig'},
46+
);

utils/src/stages/transfer_stage.validation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
StageProgressConfigSchema,
66
StageTextConfigSchema,
77
} from './stage.validation';
8-
import {CohortParticipantConfigSchema} from '../experiment.validation';
8+
import {CohortParticipantConfigSchema} from '../shared.validation';
99
import {ConditionSchema} from '../utils/condition.validation';
1010

1111
/** Shorthand for strict TypeBox object validation */

0 commit comments

Comments
 (0)