Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .changeset/shaggy-mugs-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"graphile-build-pg": patch
"postgraphile": patch
"@dataplan/pg": patch
---

Tweak some types to allow defining the types of the final PgRegistry via
declaration merging (requires codegen).
3 changes: 1 addition & 2 deletions grafast/dataplan-pg/src/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,8 +961,7 @@ export function rangeOfCodec<
: null),
fromPg: needsCast
? function (value) {
const json = JSON.parse(value);
const [lowerInc, lower, upper, upperInc, empty] = json;
const [lowerInc, lower, upper, upperInc, empty] = JSON.parse(value);
return empty
? { empty: true }
: {
Expand Down
5 changes: 4 additions & 1 deletion grafast/dataplan-pg/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,14 @@ export interface PgResourceParameter<
*/
export interface PgResourceUnique<
TAttributes extends PgCodecAttributes = PgCodecAttributes,
TUniqueAttributes extends ReadonlyArray<
keyof TAttributes & string
> = ReadonlyArray<keyof TAttributes & string>,
> {
/**
* The attributes that are unique
*/
attributes: ReadonlyArray<keyof TAttributes & string>;
attributes: TUniqueAttributes;
/**
* If this is true, this represents the "primary key" of the resource.
*/
Expand Down
8 changes: 3 additions & 5 deletions grafast/dataplan-pg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export type {
PgCodecAttributeVia,
PgCodecAttributeViaExplicit,
PgCodecExtensions,
PgCodecFromJavaScriptType,
PgCodecFromPostgresType,
PgCodecList,
PgCodecPolymorphism,
PgCodecPolymorphismRelational,
Expand Down Expand Up @@ -281,6 +283,7 @@ export type {
PgPath,
PgPoint,
PgPolygon,
PgRangeValue,
PgRecordTypeCodecSpec,
PgRefDefinition,
PgRefDefinitionExtensions,
Expand Down Expand Up @@ -318,11 +321,6 @@ export type {
TuplePlanMap,
WithPgClient,
};
export type {
PgCodecFromJavaScriptType,
PgCodecFromPostgresType,
PgRangeValue,
};
export {
assertPgClassSingleStep,
domainOfCodec,
Expand Down
25 changes: 3 additions & 22 deletions grafast/dataplan-pg/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,7 @@ export type PlanByUniques<
TAttributes extends PgCodecAttributes,
TUniqueAttributes extends ReadonlyArray<PgResourceUnique<TAttributes>>,
> = TAttributes extends PgCodecAttributes
? TuplePlanMap<
TAttributes,
TUniqueAttributes[number]["attributes"] & string[]
>[number]
? TuplePlanMap<TAttributes, TUniqueAttributes[number]["attributes"]>[number]
: undefined;

export type PgConditionLike = Modifier<any> & {
Expand Down Expand Up @@ -652,12 +649,7 @@ export interface PgRegistry<
PgCodec<string, PgCodecAttributes | undefined, any, any, any, any, any>
>,
TResourceOptions extends {
[name in string]: PgResourceOptions<
name,
PgCodec, // TCodecs[keyof TCodecs],
ReadonlyArray<PgResourceUnique<PgCodecAttributes>>,
readonly PgResourceParameter[] | undefined
>;
[name in string]: PgResourceOptions<any, any, any, any>;
} = Record<
string,
PgResourceOptions<
Expand All @@ -670,18 +662,7 @@ export interface PgRegistry<
>,
TRelations extends {
[codecName in keyof TCodecs]?: {
[relationName in string]: PgCodecRelationConfig<
// TCodecs[keyof TCodecs] &
PgCodec<string, PgCodecAttributes, any, any, undefined, any, undefined>,
// TResourceOptions[keyof TResourceOptions] &
PgResourceOptions<
any,
// TCodecs[keyof TCodecs] &
PgCodecWithAttributes,
any,
any
>
>;
[relationName in string]: PgCodecRelationConfig<any, any>;
};
} = Record<
string,
Expand Down
9 changes: 8 additions & 1 deletion graphile-build/graphile-build-pg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,15 @@ declare global {
[tagName: string]: null | true | string | (string | true)[];
}

/** Augment this interface to provide generated build-time types. */
interface GeneratedTypes {}

interface BuildInput {
pgRegistry: PgRegistry;
pgRegistry: GeneratedTypes extends {
pgRegistry: infer TRegistry extends PgRegistry;
}
? TRegistry
: PgRegistry;
}

interface SchemaOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
PgCodec,
PgCodecRelation,
PgCodecWithAttributes,
PgExecutor,
PgRefDefinition,
PgResource,
PgResourceUnique,
Expand Down Expand Up @@ -142,8 +141,13 @@ declare global {
/**
* Shortcut to primary executor; equivalent for most users to `build.input.pgRegistry.pgExecutors.main`.
* (strictly it's `build.input.pgRegistry.pgExecutors[Object.keys(build.input.pgRegistry.pgExecutors)[0]]`)
*
* Note: the TypeScript type for this is an approximation, because
* TypeScript doesn't have a concept of "first key". For most people
* there will be just a single executor anyway, and the type of the
* executor doesn't tend to matter much.
*/
pgExecutor: PgExecutor;
pgExecutor: GraphileBuild.Build["input"]["pgRegistry"]["pgExecutors"][keyof GraphileBuild.Build["input"]["pgRegistry"]["pgExecutors"]];
/** Shortcut to the resources in the registry */
pgResources: GraphileBuild.Build["input"]["pgRegistry"]["pgResources"];
/** Shortcut to the codecs in the registry */
Expand Down
Loading