-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
sdkIssue or PR related to our SDKsIssue or PR related to our SDKsts-sdkRelated to TypeScript SDKRelated to TypeScript SDKtypescriptIssue or PR related to TypeScript toolingIssue or PR related to TypeScript tooling
Description
Summary
Implement defineConfig() which accepts SchemaExtensions and returns a PluginConfig with .extensions and .schemas. The function composes Zod schemas from the provided extensions using withCustomFields(), so that TypeScript users get fully typed schemas at authoring time with no generation step.
Example
// plugins/combined/commongrants.config.ts
import { defineConfig, mergeExtensions } from "@commongrants/sdk/extensions";
import type { SchemaExtensions } from "@commongrants/sdk/extensions";
import hhs from "@commongrants/hhs-plugin";
import ca from "@commongrants/california-plugin";
const localExtensions = {
Opportunity: {
eligibilityType: {
fieldType: "array",
description: "Types of eligible organizations",
valueSchema: z.array(z.string()),
},
},
} as const satisfies SchemaExtensions;
export default defineConfig(
compose(
[hhs.extensions, ca.extensions, localExtensions],
{ onConflict: "error" },
),
);// Usage — schemas are typed immediately, no generation step
import combined from "../plugins/combined/commongrants.config";
const opp = combined.schemas.Opportunity.parse(apiResponse);
opp.customFields.programArea.value; // string
opp.customFields.eligibilityType.value; // string[]Acceptance criteria
-
PluginConfiginterface is exported withextensions: SchemaExtensionsandschemascontaining typed Zod schemas keyed by base model name -
defineConfig()acceptsSchemaExtensionsdirectly (not wrapped in an options object) and returns aPluginConfig -
as const satisfies SchemaExtensionsinputs produce fully inferred literal types on.schemasoutput — field keys and value types are preserved through toz.infer - Any directory with a
cg.config.tsthat exports aPluginConfigcan be imported as a plugin by another config, with.extensionsavailable for further composition - Integration test:
- define extensions
- call
defineConfig() - assert
config.schemas.Opportunity.parse()validates correct payloads and rejects invalid ones
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
sdkIssue or PR related to our SDKsIssue or PR related to our SDKsts-sdkRelated to TypeScript SDKRelated to TypeScript SDKtypescriptIssue or PR related to TypeScript toolingIssue or PR related to TypeScript tooling
Type
Projects
Status
Todo