Skip to content

Commit 3449126

Browse files
committed
refactor(config): move zod schemas from .d.ts to .ts implementation file
Replace config.d.ts with config.ts, moving detailed zod schema definitions and exports out of the type declaration file for better separation of concerns and clearer runtime imports.
1 parent 6530e58 commit 3449126

File tree

3 files changed

+169
-114
lines changed

3 files changed

+169
-114
lines changed

plugins/catalog-backend-module-openchoreo-incremental/src/config.d.ts

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -23,127 +23,17 @@ import { z } from 'zod';
2323
/**
2424
* Configuration options for the OpenChoreo API connection.
2525
*/
26-
export const openchoreoApiConfigSchema = z.object({
27-
/**
28-
* Base URL for the OpenChoreo API.
29-
*/
30-
baseUrl: z.string().url().describe('OpenChoreo API base URL'),
31-
32-
/**
33-
* Optional authentication token for API access.
34-
*/
35-
token: z.string().optional().describe('OpenChoreo API authentication token'),
36-
});
26+
export declare const openchoreoApiConfigSchema: import('zod').ZodTypeAny;
3727

3828
/**
3929
* Configuration options for incremental ingestion behavior.
4030
*/
41-
export const openchoreoIncrementalConfigSchema = z.object({
42-
/**
43-
* Duration of each ingestion burst in seconds. Must be between 1 and 300.
44-
* @default 10
45-
*/
46-
burstLength: z
47-
.number()
48-
.min(1)
49-
.max(300)
50-
.default(10)
51-
.describe('Duration of ingestion bursts in seconds'),
52-
53-
/**
54-
* Interval between ingestion bursts in seconds. Must be between 5 and 300.
55-
* @default 30
56-
*/
57-
burstInterval: z
58-
.number()
59-
.min(5)
60-
.max(300)
61-
.default(30)
62-
.describe('Interval between ingestion bursts in seconds'),
63-
64-
/**
65-
* Rest period after successful ingestion in minutes. Must be between 1 and 1440.
66-
* @default 30
67-
*/
68-
restLength: z
69-
.number()
70-
.min(1)
71-
.max(1440)
72-
.default(30)
73-
.describe('Rest period after ingestion in minutes'),
74-
75-
/**
76-
* Number of entities to process in each batch. Must be between 1 and 1000.
77-
* @default 50
78-
*/
79-
chunkSize: z
80-
.number()
81-
.min(1)
82-
.max(1000)
83-
.default(50)
84-
.describe('Number of entities per batch'),
85-
86-
/**
87-
* Backoff strategy for failed ingestion attempts in seconds.
88-
*/
89-
backoff: z
90-
.array(z.number().positive())
91-
.optional()
92-
.describe('Backoff durations in seconds'),
93-
94-
/**
95-
* Percentage threshold above which entity removals will be rejected (0-100).
96-
*/
97-
rejectRemovalsAbovePercentage: z
98-
.number()
99-
.min(0)
100-
.max(100)
101-
.optional()
102-
.describe('Removal rejection threshold percentage'),
103-
104-
/**
105-
* Whether to reject removals when source collections are empty.
106-
* @default false
107-
*/
108-
rejectEmptySourceCollections: z
109-
.boolean()
110-
.default(false)
111-
.describe('Reject removals from empty collections'),
112-
113-
/**
114-
* Maximum number of concurrent API requests during batch processing.
115-
* Must be between 1 and 50.
116-
* @default 5
117-
*/
118-
maxConcurrentRequests: z
119-
.number()
120-
.min(1)
121-
.max(50)
122-
.default(5)
123-
.describe('Maximum concurrent API requests during batch processing'),
124-
125-
/**
126-
* Delay in milliseconds between batch processing requests.
127-
* Must be between 0 and 10000.
128-
* @default 100
129-
*/
130-
batchDelayMs: z
131-
.number()
132-
.min(0)
133-
.max(10000)
134-
.default(100)
135-
.describe('Delay in milliseconds between batch processing requests'),
136-
});
31+
export declare const openchoreoIncrementalConfigSchema: import('zod').ZodTypeAny;
13732

13833
/**
13934
* Complete configuration schema for OpenChoreo incremental plugin.
14035
*/
141-
export const openchoreoIncrementalConfigValidation = z.object({
142-
openchoreo: z.object({
143-
api: openchoreoApiConfigSchema.optional(),
144-
incremental: openchoreoIncrementalConfigSchema.optional(),
145-
}),
146-
});
36+
export declare const openchoreoIncrementalConfigValidation: import('zod').ZodTypeAny;
14737

14838
/**
14939
* TypeScript interface for the complete OpenChoreo configuration.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
* Copyright 2022 The Backstage Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { z } from 'zod';
18+
19+
/**
20+
* Configuration options for the OpenChoreo API connection.
21+
*/
22+
export const openchoreoApiConfigSchema = z.object({
23+
/**
24+
* Base URL for the OpenChoreo API.
25+
*/
26+
baseUrl: z.string().url().describe('OpenChoreo API base URL'),
27+
28+
/**
29+
* Optional authentication token for API access.
30+
*/
31+
token: z.string().optional().describe('OpenChoreo API authentication token'),
32+
});
33+
34+
/**
35+
* Configuration options for incremental ingestion behavior.
36+
*/
37+
export const openchoreoIncrementalConfigSchema = z.object({
38+
/**
39+
* Duration of each ingestion burst in seconds. Must be between 1 and 300.
40+
* @default 10
41+
*/
42+
burstLength: z
43+
.number()
44+
.min(1)
45+
.max(300)
46+
.default(10)
47+
.describe('Duration of ingestion bursts in seconds'),
48+
49+
/**
50+
* Interval between ingestion bursts in seconds. Must be between 5 and 300.
51+
* @default 30
52+
*/
53+
burstInterval: z
54+
.number()
55+
.min(5)
56+
.max(300)
57+
.default(30)
58+
.describe('Interval between ingestion bursts in seconds'),
59+
60+
/**
61+
* Rest period after successful ingestion in minutes. Must be between 1 and 1440.
62+
* @default 30
63+
*/
64+
restLength: z
65+
.number()
66+
.min(1)
67+
.max(1440)
68+
.default(30)
69+
.describe('Rest period after ingestion in minutes'),
70+
71+
/**
72+
* Number of entities to process in each batch. Must be between 1 and 1000.
73+
* @default 50
74+
*/
75+
chunkSize: z
76+
.number()
77+
.min(1)
78+
.max(1000)
79+
.default(50)
80+
.describe('Number of entities per batch'),
81+
82+
/**
83+
* Backoff strategy for failed ingestion attempts in seconds.
84+
*/
85+
backoff: z
86+
.array(z.number().positive())
87+
.optional()
88+
.describe('Backoff durations in seconds'),
89+
90+
/**
91+
* Percentage threshold above which entity removals will be rejected (0-100).
92+
*/
93+
rejectRemovalsAbovePercentage: z
94+
.number()
95+
.min(0)
96+
.max(100)
97+
.optional()
98+
.describe('Removal rejection threshold percentage'),
99+
100+
/**
101+
* Whether to reject removals when source collections are empty.
102+
* @default false
103+
*/
104+
rejectEmptySourceCollections: z
105+
.boolean()
106+
.default(false)
107+
.describe('Reject removals from empty collections'),
108+
109+
/**
110+
* Maximum number of concurrent API requests during batch processing.
111+
* Must be between 1 and 50.
112+
* @default 5
113+
*/
114+
maxConcurrentRequests: z
115+
.number()
116+
.min(1)
117+
.max(50)
118+
.default(5)
119+
.describe('Maximum concurrent API requests during batch processing'),
120+
121+
/**
122+
* Delay in milliseconds between batch processing requests.
123+
* Must be between 0 and 10000.
124+
* @default 100
125+
*/
126+
batchDelayMs: z
127+
.number()
128+
.min(0)
129+
.max(10000)
130+
.default(100)
131+
.describe('Delay in milliseconds between batch processing requests'),
132+
});
133+
134+
/**
135+
* Complete configuration schema for OpenChoreo incremental plugin.
136+
*/
137+
export const openchoreoIncrementalConfigValidation = z.object({
138+
openchoreo: z.object({
139+
api: openchoreoApiConfigSchema.optional(),
140+
incremental: openchoreoIncrementalConfigSchema.optional(),
141+
}),
142+
});
143+
144+
/**
145+
* TypeScript interface for the complete OpenChoreo configuration.
146+
*/
147+
export interface OpenChoreoIncrementalConfig {
148+
openchoreo: {
149+
api?: {
150+
baseUrl: string;
151+
token?: string;
152+
};
153+
incremental?: {
154+
burstLength: number;
155+
burstInterval: number;
156+
restLength: number;
157+
chunkSize: number;
158+
backoff?: number[];
159+
rejectRemovalsAbovePercentage?: number;
160+
rejectEmptySourceCollections: boolean;
161+
maxConcurrentRequests: number;
162+
batchDelayMs: number;
163+
};
164+
};
165+
}

plugins/catalog-backend-module-openchoreo-incremental/src/utils/ConfigValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { LoggerService } from '@backstage/backend-plugin-api';
1919
import {
2020
openchoreoIncrementalConfigValidation,
2121
OpenChoreoIncrementalConfig,
22-
} from '../config.d';
22+
} from '../config';
2323
import { OpenChoreoIncrementalIngestionError } from '../database/errors';
2424

2525
/**

0 commit comments

Comments
 (0)