Skip to content

Commit 3935c1e

Browse files
committed
Refine JSON Schema typing across packages
The changes introduce stricter typing for JSON Schema-related definitions, specifically replacing vague types with more precise ones, such as using `z.record(z.unknown())` instead of `z.any()` and `Record<string, unknown>` in place of `any`. This is part of an effort to better align with common practices and improve type safety in the packages. - Updated the `payloadSchema` in several files to use `z.record(z.unknown())`, enhancing the type strictness and consistency with JSON Schema Draft 7 recommendations. - Added `@types/json-schema` as a dependency, utilizing its definitions for improved type clarity and adherence to best practices in TypeScript. - Modified various comments to explicitly mention JSON Schema Draft 7, ensuring developers are aware of the JSON Schema version being implemented. - These adjustments are informed by research into how popular libraries and tools handle JSON Schema typing, aiming to integrate best practices for improved maintainability and interoperability.
1 parent 9350900 commit 3935c1e

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

packages/core/src/v3/schemas/resources.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const TaskResource = z.object({
1313
triggerSource: z.string().optional(),
1414
schedule: ScheduleMetadata.optional(),
1515
maxDuration: z.number().optional(),
16-
payloadSchema: z.any().optional(),
16+
payloadSchema: z.record(z.unknown()).optional(),
1717
});
1818

1919
export type TaskResource = z.infer<typeof TaskResource>;

packages/core/src/v3/schemas/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ const taskMetadata = {
189189
triggerSource: z.string().optional(),
190190
schedule: ScheduleMetadata.optional(),
191191
maxDuration: z.number().optional(),
192-
payloadSchema: z.any().optional(),
192+
payloadSchema: z.record(z.unknown()).optional(),
193193
};
194194

195195
export const TaskMetadata = z.object(taskMetadata);

packages/core/src/v3/types/tasks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@ type CommonTaskOptions<
342342

343343
/**
344344
* JSON Schema for the task payload. This will be synced to the server during indexing.
345+
* Should be a valid JSON Schema Draft 7 object.
345346
*/
346-
payloadSchema?: any;
347+
payloadSchema?: Record<string, unknown>;
347348
};
348349

349350
export type TaskOptions<

packages/schema-to-json/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"check-exports": "tshy --check-exports"
4444
},
4545
"dependencies": {
46+
"@types/json-schema": "^7.0.15",
4647
"zod-to-json-schema": "^3.24.5",
4748
"@sodaru/yup-to-json-schema": "^2.0.1"
4849
},

packages/schema-to-json/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import type { JSONSchema7, JSONSchema7Definition } from '@types/json-schema';
2+
13
export type Schema = unknown;
4+
export type JSONSchema = JSONSchema7;
5+
export type JSONSchemaDefinition = JSONSchema7Definition;
26

37
export interface ConversionOptions {
48
/**
@@ -13,9 +17,9 @@ export interface ConversionOptions {
1317

1418
export interface ConversionResult {
1519
/**
16-
* The JSON Schema representation
20+
* The JSON Schema representation (JSON Schema Draft 7)
1721
*/
18-
jsonSchema: any;
22+
jsonSchema: JSONSchema;
1923
/**
2024
* The detected schema type
2125
*/

0 commit comments

Comments
 (0)