patrick
patrick
Explore posts from servers
TtRPC
Created by patrick on 9/8/2023 in #❓-help
query with no input reports error
also, important data point, it compiles with tsc and esbuild just fine, and runs just fine, this is a VSCode only error!?
4 replies
TtRPC
Created by patrick on 9/8/2023 in #❓-help
query with no input reports error
I just checked and nothing has changed in createTPCReact.tsx in 9 months, so it must be something i am doing wrong.
4 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
it it because of this?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
it's this last schema that i can't call .pick on... because it's no longer a schema?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
import { z } from "zod";

const baseTableEntitySchema = z.object({
id: z.string().uuid().default("00000000-0000-0000-0000-000000000000").describe("the generated uuid rowKey.")
});

const baseCollectorSchema = z
.object({
name: z.string().min(1).describe("display name of collector")
})
.merge(baseTableEntitySchema);

const kustoParametersSchema = z.object({
query: z.string().min(1).describe("the kql query")
});
const kSchema = z
.object({
type: z.literal("kusto"),
parameters: kustoParametersSchema
})
.merge(baseCollectorSchema);

const metricsParametersSchema = z.object({
namespace: z.string().min(1).describe("the Azure metrics namespace")
});
const mSchema = z
.object({
type: z.literal("metrics"),
parameters: metricsParametersSchema
})
.merge(baseCollectorSchema);

const collectorSchema = z.discriminatedUnion("type", [mSchema, kSchema]);
import { z } from "zod";

const baseTableEntitySchema = z.object({
id: z.string().uuid().default("00000000-0000-0000-0000-000000000000").describe("the generated uuid rowKey.")
});

const baseCollectorSchema = z
.object({
name: z.string().min(1).describe("display name of collector")
})
.merge(baseTableEntitySchema);

const kustoParametersSchema = z.object({
query: z.string().min(1).describe("the kql query")
});
const kSchema = z
.object({
type: z.literal("kusto"),
parameters: kustoParametersSchema
})
.merge(baseCollectorSchema);

const metricsParametersSchema = z.object({
namespace: z.string().min(1).describe("the Azure metrics namespace")
});
const mSchema = z
.object({
type: z.literal("metrics"),
parameters: metricsParametersSchema
})
.merge(baseCollectorSchema);

const collectorSchema = z.discriminatedUnion("type", [mSchema, kSchema]);
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
this is where i ended up with the discriminated union.
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
not coming from GraphQL... just trying to store discriminated unions in the same azure table...
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
ugh. some of my schema inputs are discriminated unions and ZodDiscriminatedUnion is not assignable to parameter of type 'AnyZodObject'.
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
thanks for the tips!
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
.query(async ({ input: options }) => { const result = await queryRows(client, options); if (options?.select) { const picker = options.select.reduce<Record<string, true>>((a, f) => { a[f] = true; return a; }, {}); const resultSchema = schema.pick(picker).array(); resultSchema.parse(result); } else { schema.array().parse(result); } return result; }),
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
then just split on if there are selected fields and call parse separately?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
function makeRouter<Schema extends z.AnyZodObject>( tableName: string, schema: Schema, ... like this?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
but it doesn't have .pick().. have i chosen the wrong type?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
so as you can see above, i've declared my schema as a generic that extends z.ZodSchema...
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
so is there a zod method to construct a narrowed type?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
oh! that sounds promising...
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
are the input fields available to the .output() step?
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
e.g. const { data } = api.entity.list.useQuery({ select: ["id", "name"] });
40 replies
TtRPC
Created by patrick on 3/6/2023 in #❓-help
Is it possible to narrow an output schema if the query optionally doesn't return all fields?
the use case is someone wants to display a <Select> of just the id and name fields from an entity that may have many more columns in the zod schema.
40 replies