Skip to content

Commit a32ec8d

Browse files
authored
refactor: global registry use client term (#1203)
1 parent f44b086 commit a32ec8d

File tree

23 files changed

+51
-55
lines changed

23 files changed

+51
-55
lines changed

src/entrypoints/utilities-for-generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { type Simplify } from 'type-fest'
22
export { type SchemaDrivenDataMap } from '../extensions/CustomScalars/schemaDrivenDataMap/__.js'
33
export * from '../layers/2_Select/__.js'
44
export { type Schema as SchemaIndexBase } from '../layers/4_generator/generators/Schema.js'
5-
export { type GlobalRegistry } from '../layers/4_generator/globalRegistry.js'
5+
export { type GlobalRegistry } from '../layers/4_generator/GlobalRegistry.js'
66
export type {
77
ConfigGetOutputError,
88
HandleOutput,

src/extensions/SchemaErrors/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GlobalRegistry } from '../../layers/4_generator/globalRegistry.js'
1+
import type { GlobalRegistry } from '../../layers/4_generator/GlobalRegistry.js'
22

33
declare global {
44
namespace GraffleGlobal {

src/extensions/SchemaErrors/tests/fixture/graffle/modules/Global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { Schema } from './Schema.js'
77

88
declare global {
99
export namespace GraffleGlobal {
10-
export interface Schemas {
10+
export interface Clients {
1111
GraffleSchemaErrors: {
1212
name: Data.Name
1313
schema: Schema

src/layers/1_Schema/Hybrid/types/Scalar/Scalar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GlobalRegistry } from '../../../../4_generator/globalRegistry.js'
1+
import type { GlobalRegistry } from '../../../../4_generator/GlobalRegistry.js'
22
import type { Codec, Mapper } from './codec.js'
33
import { JavaScriptScalarCodecs } from './nativeScalarCodecs.js'
44

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { IsNever } from 'type-fest'
12
import type { TypeFunction } from '../../entrypoints/utilities-for-generated.js'
23
import type { ConfigManager } from '../../lib/config-manager/__.js'
34
import type { Values } from '../../lib/prelude.js'
@@ -6,14 +7,12 @@ import type { Schema } from './generators/Schema.js'
67

78
declare global {
89
export namespace GraffleGlobal {
9-
interface Schemas {}
10-
// Use this is for manual internal type testing.
11-
interface SchemasAlwaysEmpty {}
10+
interface Clients {}
1211
}
1312
}
1413

15-
interface ZeroClient extends GlobalRegistry.RegisteredSchema {
16-
name: GlobalRegistry.DefaultSchemaName
14+
interface ZeroClient extends GlobalRegistry.Client {
15+
name: GlobalRegistry.DefaultClientName
1716
schema: Schema
1817
interfaces: {
1918
Root: TypeFunction.Fn
@@ -23,7 +22,7 @@ interface ZeroClient extends GlobalRegistry.RegisteredSchema {
2322
defaultSchemaUrl: null
2423
}
2524

26-
export type GlobalRegistry = Record<string, GlobalRegistry.RegisteredSchema>
25+
export type GlobalRegistry = Record<string, GlobalRegistry.Client>
2726

2827
export namespace GlobalRegistry {
2928
export type TypeExtensions = Record<string, Record<string, unknown>>
@@ -36,7 +35,7 @@ export namespace GlobalRegistry {
3635
Schema: ConfigManager.OrDefault<$Extensions['Schema'], TypeExtensions>
3736
}
3837

39-
export interface RegisteredSchema<$Extensions extends Extensions = Extensions> {
38+
export interface Client<$Extensions extends Extensions = Extensions> {
4039
name: string
4140
schema: Schema<$Extensions['Schema']>
4241
interfaces: {
@@ -50,17 +49,17 @@ export namespace GlobalRegistry {
5049
defaultSchemaUrl: string | null
5150
}
5251

53-
export type DefaultSchemaName = 'default'
52+
export type DefaultClientName = 'default'
5453

55-
export type Clients = GraffleGlobal.Schemas // todo rename to Clients
54+
export type Clients = GraffleGlobal.Clients
5655

57-
export type IsEmpty = keyof Clients extends never ? true : false
56+
export type IsEmpty = IsNever<keyof Clients> extends true ? true : false
5857

5958
export type ClientUnion = IsEmpty extends true ? ZeroClient : Values<Clients>
6059

61-
export type SchemaNames = keyof GraffleGlobal.Schemas extends never
60+
export type ClientNames = keyof GraffleGlobal.Clients extends never
6261
? TSErrorDescriptive<'SchemaNames', 'No schemas have been registered. Did you run graffle generate?'>
63-
: keyof GraffleGlobal.Schemas
62+
: keyof GraffleGlobal.Clients
6463

6564
// dprint-ignore
6665
export type HasDefaultUrlForSchema<$Schema extends ClientUnion> =
@@ -70,25 +69,25 @@ export namespace GlobalRegistry {
7069

7170
// eslint-disable-next-line
7271
// @ts-ignore passes after generation
73-
export type GetSchema<$Name extends SchemaNames> = GraffleGlobal.Schemas[$Name]['schema']
72+
export type GetSchema<$Name extends ClientNames> = GraffleGlobal.Clients[$Name]['schema']
7473

7574
// eslint-disable-next-line
7675
// @ts-ignore passes after generation
77-
export type SchemaDefault = GetSchema<DefaultSchemaName>
76+
export type SchemaDefault = GetSchema<DefaultClientName>
7877

7978
// dprint-ignore
80-
export type GetOrDefault<$Name extends SchemaNames | undefined> =
81-
$Name extends SchemaNames
79+
export type GetOrDefault<$Name extends ClientNames | undefined> =
80+
$Name extends ClientNames
8281
// eslint-disable-next-line
8382
// @ts-ignore passes after generation
84-
? GraffleGlobal.Schemas[$Name]
83+
? GraffleGlobal.Clients[$Name]
8584
// eslint-disable-next-line
8685
// @ts-ignore passes after generation
87-
: GraffleGlobal.Schemas[DefaultSchemaName]
86+
: GraffleGlobal.Clients[DefaultClientName]
8887

8988
// dprint-ignore
90-
export type GetSchemaOrDefault<$Name extends SchemaNames | undefined> =
91-
$Name extends SchemaNames
89+
export type GetSchemaOrDefault<$Name extends ClientNames | undefined> =
90+
$Name extends ClientNames
9291
? GetSchema<$Name>
9392
: SchemaDefault
9493
}

src/layers/4_generator/generator/__snapshots__/generate.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import type { Schema } from './Schema.js'
4747
4848
declare global {
4949
export namespace GraffleGlobal {
50-
export interface Schemas {
50+
export interface Clients {
5151
default: {
5252
name: Data.Name
5353
schema: Schema

src/layers/4_generator/generators/Schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Grafaid } from '../../../lib/grafaid/__.js'
44
import { entries, isObjectEmpty, values } from '../../../lib/prelude.js'
55
import type { SchemaKit } from '../../1_Schema/__.js'
66
import type { Config } from '../config/config.js'
7-
import type { GlobalRegistry } from '../globalRegistry.js'
7+
import type { GlobalRegistry } from '../GlobalRegistry.js'
88
import { identifiers } from '../helpers/identifiers.js'
99
import { createModuleGenerator } from '../helpers/moduleGenerator.js'
1010
import { createCodeGenerator } from '../helpers/moduleGeneratorRunner.js'
@@ -20,7 +20,7 @@ import { ModuleGeneratorScalar } from './Scalar.js'
2020
export interface Schema<
2121
$Extensions extends GlobalRegistry.TypeExtensions = GlobalRegistry.TypeExtensions,
2222
> {
23-
name: GlobalRegistry.SchemaNames
23+
name: GlobalRegistry.ClientNames
2424
RootTypesPresent: ('Query' | 'Mutation' | 'Subscription')[]
2525
RootUnion: SchemaKit.Output.RootType
2626
Root: {

src/layers/4_generator/generators/global.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const ModuleGeneratorGlobal = createModuleGenerator(
3131
const customScalarsProperties = config.schema.kindMap.GraphQLScalarTypeCustom
3232
.map((_) => [_.name, `${identifiers.Scalar}.${_.name}`])
3333

34-
const ClientFields = Code.termObjectFields({
34+
const Clients = Code.termObjectFields({
3535
[config.name]: {
3636
name: `Data.Name`,
3737
schema: identifiers.Schema,
@@ -48,17 +48,14 @@ export const ModuleGeneratorGlobal = createModuleGenerator(
4848
},
4949
})
5050

51-
// todo rename "Schemas" to "Clients"
5251
code(`
5352
declare global {
5453
export namespace GraffleGlobal {
55-
export interface Schemas {
56-
${ClientFields}
54+
export interface Clients {
55+
${Clients}
5756
}
5857
}
5958
}
6059
`)
61-
62-
return code
6360
},
6461
)

src/layers/5_select/select.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { identityProxy } from '../../lib/prelude.js'
2-
import type { GlobalRegistry } from '../4_generator/globalRegistry.js'
2+
import type { GlobalRegistry } from '../4_generator/GlobalRegistry.js'
33

44
// dprint-ignore
5-
type Create = <$Name extends GlobalRegistry.SchemaNames>(name: $Name) =>
5+
type Create = <$Name extends GlobalRegistry.ClientNames>(name: $Name) =>
66
// eslint-disable-next-line
77
// @ts-ignore passes after generation
88
GlobalRegistry.GetOrDefault<$Name>['interfaces']['MethodsSelect']

src/layers/6_client/Settings/Config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { GraphQLSchema } from 'graphql'
22
import type { SchemaDrivenDataMap } from '../../../extensions/CustomScalars/schemaDrivenDataMap/__.js'
33
import type { RequireProperties } from '../../../lib/prelude.js'
4-
import type { GlobalRegistry } from '../../4_generator/globalRegistry.js'
4+
import type { GlobalRegistry } from '../../4_generator/GlobalRegistry.js'
55
import type { TransportHttp, TransportMemory } from '../../5_request/types.js'
66
import type { Extension } from '../extension/extension.js'
77
import type { TransportHttpInput } from '../transportHttp/request.js'
@@ -115,7 +115,7 @@ export type Config = {
115115
typeHooks: {
116116
onRequestResult: Extension.Hooks.OnRequestResult[]
117117
}
118-
name: GlobalRegistry.SchemaNames
118+
name: GlobalRegistry.ClientNames
119119
output: OutputConfig
120120
schemaMap: SchemaDrivenDataMap | null
121121
transport: TransportConfigHttp | TransportConfigMemory

0 commit comments

Comments
 (0)