Skip to content

Commit

Permalink
Don't 'declare global' in interface files
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Dec 1, 2023
1 parent 722f787 commit 9fc77e1
Show file tree
Hide file tree
Showing 18 changed files with 1,129 additions and 1,092 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ module.exports = {
},
},

// Rules for interfaces.ts files
{
files: ["**/interfaces.ts"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "TSModuleDeclaration[kind='global']",
message:
"No `declare global` allowed in `interface.ts` files since these type-only files may not be imported by dependents, recommend adding to `index.ts` instead.",
},
],
},
},

// Rules for TypeScript only
{
files: ["*.ts", "*.tsx"],
Expand Down
1 change: 1 addition & 0 deletions grafast/bench/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface GrafastBenchConfig {
) => object;
}

// eslint-disable-next-line no-restricted-syntax
declare global {
namespace GraphileConfig {
interface Preset {
Expand Down
87 changes: 87 additions & 0 deletions grafast/dataplan-pg/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { GrafastSubscriber } from "grafast";
import { exportAsMany } from "grafast";

import type { PgAdaptorOptions } from "./adaptors/pg.js";
import {
domainOfCodec,
enumCodec,
Expand Down Expand Up @@ -406,3 +408,88 @@ export {
};

export { version } from "./version.js";

declare global {
namespace GraphileConfig {
interface PgServiceConfiguration<
TAdaptor extends
keyof GraphileConfig.PgDatabaseAdaptorOptions = keyof GraphileConfig.PgDatabaseAdaptorOptions,
> {
name: string;
schemas?: string[];

adaptor: TAdaptor;
adaptorSettings?: GraphileConfig.PgDatabaseAdaptorOptions[TAdaptor];

/** The key on 'context' where the withPgClient function will be sourced */
withPgClientKey: KeysOfType<Grafast.Context & object, WithPgClient>;

/** Return settings to set in the session */
pgSettings?: (
requestContext: Grafast.RequestContext,
) => { [key: string]: string } | null;

/** Settings to set in the session that performs introspection (during gather phase) */
pgSettingsForIntrospection?: { [key: string]: string } | null;

/** The key on 'context' where the pgSettings for this DB will be sourced */
pgSettingsKey?: KeysOfType<
Grafast.Context & object,
{ [key: string]: string } | null | undefined
>;

/** The GrafastSubscriber to use for subscriptions */
pgSubscriber?: GrafastSubscriber<Record<string, string>> | null;

/** Where on the context should the PgSubscriber be stored? */
pgSubscriberKey?: KeysOfType<
Grafast.Context & object,
GrafastSubscriber<any> | null | undefined
>;
}

interface Preset {
pgServices?: ReadonlyArray<PgServiceConfiguration>;
}

interface PgDatabaseAdaptorOptions {
"@dataplan/pg/adaptors/pg": PgAdaptorOptions;
/* Add your own via declaration merging */
}
}
namespace DataplanPg {
interface PgConditionStepExtensions {}
/**
* Custom metadata for a codec
*/
interface PgCodecExtensions {
oid?: string;
pg?: {
serviceName: string;
schemaName: string;
name: string;
};
listItemNonNull?: boolean;
isEnumTableEnum?: boolean;
}

/**
* Extra metadata you can attach to a unique constraint.
*/
interface PgResourceUniqueExtensions {}

/**
* Space for extra metadata about this resource
*/
interface PgResourceExtensions {}

interface PgResourceParameterExtensions {
variant?: string;
}

interface PgCodecRefExtensions {}
interface PgCodecAttributeExtensions {}
interface PgRefDefinitionExtensions {}
interface PgCodecRelationExtensions {}
}
}
90 changes: 2 additions & 88 deletions grafast/dataplan-pg/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ExecutableStep, GrafastSubscriber, ModifierStep } from "grafast";
import type { ExecutableStep, ModifierStep } from "grafast";
import type { SQL, SQLRawValue } from "pg-sql2";

import type { PgAdaptorOptions } from "./adaptors/pg.js";
import type { PgCodecAttributes } from "./codecs.js";
import type {
PgCodecRefs,
Expand All @@ -10,7 +9,7 @@ import type {
PgResourceParameter,
PgResourceUnique,
} from "./datasource.js";
import type { PgExecutor, WithPgClient } from "./executor.js";
import type { PgExecutor } from "./executor.js";
import type { PgDeleteSingleStep } from "./steps/pgDeleteSingle.js";
import type { PgInsertSingleStep } from "./steps/pgInsertSingle.js";
import type { PgSelectSingleStep } from "./steps/pgSelectSingle.js";
Expand Down Expand Up @@ -416,91 +415,6 @@ export type KeysOfType<TObject, TValueType> = {
[key in keyof TObject]: TObject[key] extends TValueType ? key : never;
}[keyof TObject];

declare global {
namespace GraphileConfig {
interface PgServiceConfiguration<
TAdaptor extends
keyof GraphileConfig.PgDatabaseAdaptorOptions = keyof GraphileConfig.PgDatabaseAdaptorOptions,
> {
name: string;
schemas?: string[];

adaptor: TAdaptor;
adaptorSettings?: GraphileConfig.PgDatabaseAdaptorOptions[TAdaptor];

/** The key on 'context' where the withPgClient function will be sourced */
withPgClientKey: KeysOfType<Grafast.Context & object, WithPgClient>;

/** Return settings to set in the session */
pgSettings?: (
requestContext: Grafast.RequestContext,
) => { [key: string]: string } | null;

/** Settings to set in the session that performs introspection (during gather phase) */
pgSettingsForIntrospection?: { [key: string]: string } | null;

/** The key on 'context' where the pgSettings for this DB will be sourced */
pgSettingsKey?: KeysOfType<
Grafast.Context & object,
{ [key: string]: string } | null | undefined
>;

/** The GrafastSubscriber to use for subscriptions */
pgSubscriber?: GrafastSubscriber<Record<string, string>> | null;

/** Where on the context should the PgSubscriber be stored? */
pgSubscriberKey?: KeysOfType<
Grafast.Context & object,
GrafastSubscriber<any> | null | undefined
>;
}

interface Preset {
pgServices?: ReadonlyArray<PgServiceConfiguration>;
}

interface PgDatabaseAdaptorOptions {
"@dataplan/pg/adaptors/pg": PgAdaptorOptions;
/* Add your own via declaration merging */
}
}
namespace DataplanPg {
interface PgConditionStepExtensions {}
/**
* Custom metadata for a codec
*/
interface PgCodecExtensions {
oid?: string;
pg?: {
serviceName: string;
schemaName: string;
name: string;
};
listItemNonNull?: boolean;
isEnumTableEnum?: boolean;
}

/**
* Extra metadata you can attach to a unique constraint.
*/
interface PgResourceUniqueExtensions {}

/**
* Space for extra metadata about this resource
*/
interface PgResourceExtensions {}

interface PgResourceParameterExtensions {
variant?: string;
}

interface PgCodecRefExtensions {}
interface PgCodecAttributeExtensions {}
interface PgRefDefinitionExtensions {}
interface PgCodecRelationExtensions {}
}
}

export interface MakePgServiceOptions
extends Partial<
Pick<
Expand Down
Loading

0 comments on commit 9fc77e1

Please sign in to comment.