Skip to content

Commit 05ad00f

Browse files
committed
Refactor JSON Schema test files for clarity
Whitespace and formatting changes were applied across the `json-schema-test` reference project to enhance code readability and cohesion. This included removing unnecessary trailing spaces and ensuring consistent indentation patterns, which improves maintainability and readability by following the project's code style guidelines. - Renamed JSONSchema type annotations to adhere to TypeScript conventions, ensuring that all schema definitions properly satisfy the JSONSchema interface. - Restructured some object declarations for improved clarity, especially within complex schema definitions. - These adjustments are crucial for better future maintainability, reducing potential developer errors when interacting with these test schemas.
1 parent 7b224f4 commit 05ad00f

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

references/json-schema-test/src/trigger/simple-type-test.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export const testZodTypeInference = schemaTask({
1919
const name = payload.name; // string
2020
const email = payload.email; // string
2121
const age = payload.age; // number
22-
22+
2323
// This would cause a TypeScript error if uncommented:
2424
// const invalid = payload.nonExistentField;
25-
25+
2626
return {
2727
userId: id,
2828
userName: name,
@@ -33,15 +33,15 @@ export const testZodTypeInference = schemaTask({
3333
});
3434

3535
// Test 2: JSONSchema type is properly exported and usable
36-
const jsonSchemaExample: JSONSchema = {
36+
const jsonSchemaExample = {
3737
type: "object",
3838
properties: {
3939
message: { type: "string" },
4040
count: { type: "integer" },
4141
active: { type: "boolean" },
4242
},
4343
required: ["message", "count"],
44-
};
44+
} satisfies JSONSchema;
4545

4646
export const testJSONSchemaType = task({
4747
id: "test-json-schema-type",
@@ -68,30 +68,30 @@ export const testTriggerTypeSafety = task({
6868
6969
age: 30,
7070
});
71-
71+
7272
// This would cause TypeScript errors if uncommented:
7373
// const handle2 = await testZodTypeInference.trigger({
7474
// id: 123, // wrong type
7575
// name: "Jane",
7676
// email: "not-an-email", // invalid format (caught at runtime)
7777
// age: "thirty", // wrong type
7878
// });
79-
79+
8080
// Test triggerAndWait
8181
const result = await testZodTypeInference.triggerAndWait({
8282
id: "456",
8383
name: "Jane Smith",
8484
8585
age: 25,
8686
});
87-
87+
8888
if (result.ok) {
8989
// Type inference works on the output
9090
const userId: string = result.output.userId;
9191
const userName: string = result.output.userName;
9292
const userEmail: string = result.output.userEmail;
9393
const userAge: number = result.output.userAge;
94-
94+
9595
return {
9696
success: true,
9797
userId,
@@ -124,14 +124,14 @@ export const testBatchTypeSafety = task({
124124
},
125125
{
126126
payload: {
127-
id: "2",
127+
id: "2",
128128
name: "User Two",
129129
130130
age: 30,
131131
},
132132
},
133133
]);
134-
134+
135135
// Batch trigger and wait
136136
const batchResult = await testZodTypeInference.batchTriggerAndWait([
137137
{
@@ -145,17 +145,17 @@ export const testBatchTypeSafety = task({
145145
{
146146
payload: {
147147
id: "4",
148-
name: "User Four",
148+
name: "User Four",
149149
150150
age: 50,
151151
},
152152
},
153153
]);
154-
154+
155155
// Process results with type safety
156156
const successfulUsers: string[] = [];
157157
const failedUsers: string[] = [];
158-
158+
159159
for (const run of batchResult.runs) {
160160
if (run.ok) {
161161
// output is properly typed
@@ -164,7 +164,7 @@ export const testBatchTypeSafety = task({
164164
failedUsers.push(run.id);
165165
}
166166
}
167-
167+
168168
return {
169169
batchId: batchHandle.batchId,
170170
batchRunCount: batchHandle.runCount,
@@ -179,19 +179,23 @@ export const testBatchTypeSafety = task({
179179
const complexSchema = z.object({
180180
order: z.object({
181181
id: z.string(),
182-
items: z.array(z.object({
183-
productId: z.string(),
184-
quantity: z.number(),
185-
price: z.number(),
186-
})),
182+
items: z.array(
183+
z.object({
184+
productId: z.string(),
185+
quantity: z.number(),
186+
price: z.number(),
187+
})
188+
),
187189
customer: z.object({
188190
id: z.string(),
189191
email: z.string().email(),
190-
address: z.object({
191-
street: z.string(),
192-
city: z.string(),
193-
country: z.string(),
194-
}).optional(),
192+
address: z
193+
.object({
194+
street: z.string(),
195+
city: z.string(),
196+
country: z.string(),
197+
})
198+
.optional(),
195199
}),
196200
}),
197201
metadata: z.record(z.unknown()).optional(),
@@ -207,13 +211,10 @@ export const testComplexSchema = schemaTask({
207211
const quantity = firstItem?.quantity ?? 0;
208212
const customerEmail = payload.order.customer.email;
209213
const city = payload.order.customer.address?.city;
210-
214+
211215
// Calculate total
212-
const total = payload.order.items.reduce(
213-
(sum, item) => sum + (item.quantity * item.price),
214-
0
215-
);
216-
216+
const total = payload.order.items.reduce((sum, item) => sum + item.quantity * item.price, 0);
217+
217218
return {
218219
orderId,
219220
customerEmail,
@@ -231,7 +232,7 @@ export const verifySchemaRegistration = task({
231232
run: async (_, { ctx }) => {
232233
// This test verifies that when we create tasks with schemas,
233234
// they properly register the payloadSchema for syncing to the server
234-
235+
235236
return {
236237
test: "Schema registration",
237238
message: "If this task runs, schema registration is working",

0 commit comments

Comments
 (0)