Skip to content

Commit 6c2b931

Browse files
committed
refactor: update generated output spacing and import grouping
1 parent cd21677 commit 6c2b931

File tree

39 files changed

+1209
-1450
lines changed

39 files changed

+1209
-1450
lines changed
Lines changed: 43 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,45 @@
1-
import {
2-
parseLoadSubsetOptions,
3-
queryCollectionOptions,
4-
} from "@tanstack/query-db-collection";
5-
import { createCollection } from "@tanstack/react-db";
1+
import { parseLoadSubsetOptions, queryCollectionOptions } from "@tanstack/query-db-collection"
2+
import { createCollection } from "@tanstack/react-db"
63

7-
import {
8-
createPet,
9-
createUser,
10-
deletePet,
11-
deleteUser,
12-
listPets,
13-
listUsers,
14-
updatePet,
15-
updateUser,
16-
} from "../functions";
4+
import { createPet, createUser, deletePet, deleteUser, listPets, listUsers, updatePet, updateUser } from "../functions"
175

18-
import type { LoadSubsetOptions } from "@tanstack/db";
19-
import type { QueryClient } from "@tanstack/react-query";
20-
import type { ListUsersParams } from "./../schema";
6+
import type { LoadSubsetOptions } from "@tanstack/db"
7+
import type { QueryClient } from "@tanstack/react-query"
8+
import type { ListUsersParams } from "./../schema"
219

2210
/**
2311
* Translate TanStack DB predicates to User query parameters
2412
*/
2513
function translateUserPredicates(
26-
options?: LoadSubsetOptions,
14+
options?: LoadSubsetOptions
2715
): Partial<ListUsersParams> {
28-
if (!options) return {};
16+
if (!options) return {}
2917

30-
const parsed = parseLoadSubsetOptions(options);
31-
const params: Record<string, unknown> = {};
18+
const parsed = parseLoadSubsetOptions(options)
19+
const params: Record<string, unknown> = {}
3220

3321
// Map filters to query params
3422
for (const filter of parsed.filters) {
35-
const fieldName = filter.field.join(".");
23+
const fieldName = filter.field.join(".")
3624
switch (filter.operator) {
3725
case "eq":
38-
params[fieldName] = filter.value;
39-
break;
26+
params[fieldName] = filter.value
27+
break
4028
case "lt":
41-
params[`${fieldName}_lt`] = filter.value;
42-
break;
29+
params[`${fieldName}_lt`] = filter.value
30+
break
4331
case "lte":
44-
params[`${fieldName}_lte`] = filter.value;
45-
break;
32+
params[`${fieldName}_lte`] = filter.value
33+
break
4634
case "gt":
47-
params[`${fieldName}_gt`] = filter.value;
48-
break;
35+
params[`${fieldName}_gt`] = filter.value
36+
break
4937
case "gte":
50-
params[`${fieldName}_gte`] = filter.value;
51-
break;
38+
params[`${fieldName}_gte`] = filter.value
39+
break
5240
case "in":
53-
params[`${fieldName}_in`] = filter.value;
54-
break;
41+
params[`${fieldName}_in`] = filter.value
42+
break
5543
// Silently ignore unsupported operators
5644
}
5745
}
@@ -60,14 +48,14 @@ function translateUserPredicates(
6048
if (parsed.sorts.length > 0) {
6149
params["sort"] = parsed.sorts
6250
.map((s) => `${s.direction === "desc" ? "-" : ""}${s.field.join(".")}`)
63-
.join(",");
51+
.join(",")
6452
}
6553

6654
// Map pagination (limit from parsed, offset from original options)
67-
if (parsed.limit != null) params["limit"] = parsed.limit;
68-
if (options.offset != null) params["offset"] = options.offset;
55+
if (parsed.limit != null) params["limit"] = parsed.limit
56+
if (options.offset != null) params["offset"] = options.offset
6957

70-
return params as Partial<ListUsersParams>;
58+
return params as Partial<ListUsersParams>
7159
}
7260

7361
/**
@@ -78,30 +66,22 @@ export const petCollectionOptions = (queryClient: QueryClient) =>
7866
queryCollectionOptions({
7967
queryKey: ["Pet"],
8068
queryFn: async () => {
81-
const response = await listPets();
82-
return response.data;
69+
const response = await listPets()
70+
return response.data
8371
},
8472
queryClient,
8573
getKey: (item) => item.id,
8674
onInsert: async ({ transaction }) => {
87-
await Promise.all(
88-
transaction.mutations.map((m) => createPet({ body: m.modified })),
89-
);
75+
await Promise.all(transaction.mutations.map((m) => createPet({ body: m.modified })))
9076
},
9177
onUpdate: async ({ transaction }) => {
92-
await Promise.all(
93-
transaction.mutations.map((m) =>
94-
updatePet({ petId: m.original.id, body: m.changes }),
95-
),
96-
);
78+
await Promise.all(transaction.mutations.map((m) => updatePet({ petId: m.original.id, body: m.changes })))
9779
},
9880
onDelete: async ({ transaction }) => {
99-
await Promise.all(
100-
transaction.mutations.map((m) => deletePet({ petId: m.key })),
101-
);
81+
await Promise.all(transaction.mutations.map((m) => deletePet({ petId: m.key })))
10282
},
103-
}),
104-
);
83+
})
84+
)
10585

10686
/**
10787
* Collection options for User
@@ -113,28 +93,21 @@ export const userCollectionOptions = (queryClient: QueryClient) =>
11393
queryKey: ["User"],
11494
syncMode: "on-demand",
11595
queryFn: async (ctx) => {
116-
const params = translateUserPredicates(ctx.meta?.loadSubsetOptions);
117-
const response = await listUsers(params);
118-
return response.data;
96+
const params = translateUserPredicates(ctx.meta?.loadSubsetOptions)
97+
const response = await listUsers(params)
98+
return response.data
11999
},
120100
queryClient,
121101
getKey: (item) => item.id,
122102
onInsert: async ({ transaction }) => {
123-
await Promise.all(
124-
transaction.mutations.map((m) => createUser({ body: m.modified })),
125-
);
103+
await Promise.all(transaction.mutations.map((m) => createUser({ body: m.modified })))
126104
},
127105
onUpdate: async ({ transaction }) => {
128-
await Promise.all(
129-
transaction.mutations.map((m) =>
130-
updateUser({ userId: m.original.id, body: m.changes }),
131-
),
132-
);
106+
await Promise.all(transaction.mutations.map((m) => updateUser({ userId: m.original.id, body: m.changes })))
133107
},
134108
onDelete: async ({ transaction }) => {
135-
await Promise.all(
136-
transaction.mutations.map((m) => deleteUser({ userId: m.key })),
137-
);
109+
await Promise.all(transaction.mutations.map((m) => deleteUser({ userId: m.key })))
138110
},
139-
}),
140-
);
111+
})
112+
)
113+
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,37 @@
11
/* eslint-disable */
22
/* This file is auto-generated by tangrams. Do not edit. */
33

4-
import { formOptions } from "@tanstack/react-form";
5-
6-
import {
7-
createPetRequestSchema,
8-
createUserRequestSchema,
9-
updatePetRequestSchema,
10-
updateUserRequestSchema,
11-
} from "./../schema";
12-
13-
import type {
14-
CreatePetRequest,
15-
CreateUserRequest,
16-
UpdatePetRequest,
17-
UpdateUserRequest,
18-
} from "./../schema";
4+
import { formOptions } from "@tanstack/react-form"
5+
6+
import { createPetRequestSchema, createUserRequestSchema, updatePetRequestSchema, updateUserRequestSchema } from "./../schema"
7+
8+
import type { CreatePetRequest, CreateUserRequest, UpdatePetRequest, UpdateUserRequest } from "./../schema"
199

2010
export const createPetFormOptions = formOptions({
2111
defaultValues: {} as CreatePetRequest,
2212
validators: {
2313
onSubmitAsync: createPetRequestSchema,
2414
},
25-
});
15+
})
2616

2717
export const updatePetFormOptions = formOptions({
2818
defaultValues: {} as UpdatePetRequest,
2919
validators: {
3020
onSubmitAsync: updatePetRequestSchema,
3121
},
32-
});
22+
})
3323

3424
export const createUserFormOptions = formOptions({
3525
defaultValues: {} as CreateUserRequest,
3626
validators: {
3727
onSubmitAsync: createUserRequestSchema,
3828
},
39-
});
29+
})
4030

4131
export const updateUserFormOptions = formOptions({
4232
defaultValues: {} as UpdateUserRequest,
4333
validators: {
4434
onSubmitAsync: updateUserRequestSchema,
4535
},
46-
});
36+
})
37+

0 commit comments

Comments
 (0)