Skip to content

Commit

Permalink
refactor: no layers and co-locate doc builder (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Nov 3, 2024
1 parent 9e35b51 commit c69a48d
Show file tree
Hide file tree
Showing 51 changed files with 161 additions and 163 deletions.
10 changes: 5 additions & 5 deletions src/ClientPreset/ClientPreset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { CamelCase } from 'type-fest'
import type { UseExtensionDo } from '../client/builderExtensions/use.js'
import { type Client, createWithContext } from '../client/client.js'
import { type Context, createContext, type TypeHooksEmpty } from '../client/context.js'
import type { InputBase } from '../client/Settings/Input.js'
import type { NormalizeInput } from '../client/Settings/InputToConfig.js'
import type {
Extension,
ExtensionConstructor,
Expand All @@ -7,11 +12,6 @@ import type {
ExtensionInputParametersRequired,
InferExtensionFromConstructor,
} from '../extension/extension.js'
import type { UseExtensionDo } from '../layers/6_client/builderExtensions/use.js'
import { type Client, createWithContext } from '../layers/6_client/client.js'
import { type Context, createContext, type TypeHooksEmpty } from '../layers/6_client/context.js'
import type { InputBase } from '../layers/6_client/Settings/Input.js'
import type { NormalizeInput } from '../layers/6_client/Settings/InputToConfig.js'
import type { Builder } from '../lib/builder/__.js'
import type { ConfigManager } from '../lib/config-manager/__.js'
import { type mergeArrayOfObjects, type ToParametersExact } from '../lib/prelude.js'
Expand Down
2 changes: 1 addition & 1 deletion src/ClientPreset/__.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IntrospectionQuery } from 'graphql'
import { create } from '../client/client.js'
import { Introspection } from '../extensions/Introspection/Introspection.js'
import { create } from '../layers/6_client/client.js'
import { assertEqual, assertExtends } from '../lib/assert-equal.js'
import { ClientPreset } from './__.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQLSchema } from 'graphql'
import type { RequireProperties } from '../../../lib/prelude.js'
import type { TransportHttp, TransportMemory } from '../../../requestPipeline/Transport.js'
import type { RequireProperties } from '../../lib/prelude.js'
import type { TransportHttp, TransportMemory } from '../../requestPipeline/Transport.js'
import type { TransportHttpInput } from '../transportHttp/request.js'

export type OutputChannel = 'throw' | 'return'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GraphQLSchema } from 'graphql'
import type { GlobalRegistry } from '../../../types/GlobalRegistry/GlobalRegistry.js'
import type { SchemaDrivenDataMap } from '../../../types/SchemaDrivenDataMap/__.js'
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
import type { SchemaDrivenDataMap } from '../../types/SchemaDrivenDataMap/__.js'
import type { WithInput } from './inputIncrementable/inputIncrementable.js'

export type URLInput = URL | string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IsUnknown } from 'type-fest'
import type { ConfigManager } from '../../../lib/config-manager/__.js'
import { Transport } from '../../../requestPipeline/Transport.js'
import type { GlobalRegistry } from '../../../types/GlobalRegistry/GlobalRegistry.js'
import type { ConfigManager } from '../../lib/config-manager/__.js'
import { Transport } from '../../requestPipeline/Transport.js'
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
import { defaultMethodMode } from '../transportHttp/request.js'
import { outputConfigDefault, type TransportConfigHttp, type TransportConfigMemory } from './Config.js'
import type { InputOutputEnvelopeLonghand, InputStatic, URLInput } from './Input.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import { type ExecutionResult } from 'graphql'
import { describe } from 'node:test'
import { expectTypeOf, test } from 'vitest'
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import { assertEqual } from '../../../lib/assert-equal.js'
import { type GraphQLExecutionResultError } from '../../../lib/grafaid/graphql.js'
import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { assertEqual } from '../../lib/assert-equal.js'
import { type GraphQLExecutionResultError } from '../../lib/grafaid/graphql.js'
import type { ErrorsOther } from '../handleOutput.js'

const G = Graffle.create
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'vitest'
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import { QueryOnly } from '../../../../tests/_/schemas/query-only/graffle/__.js'
import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { QueryOnly } from '../../../tests/_/schemas/query-only/graffle/__.js'

test(`works`, () => {
Graffle.create({ schema, output: { errors: { execution: `throw` } } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Transport, TransportMemory } from '../../../../requestPipeline/Transport.js'
import type { Transport, TransportMemory } from '../../../requestPipeline/Transport.js'
import type { TransportHttpInput } from '../../transportHttp/request.js'
import type { OutputInput } from './output.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createExtension } from '../../../extension/extension.js'
import type { Anyware, Anyware as AnywareLib } from '../../../lib/anyware/__.js'
import { Builder } from '../../../lib/builder/__.js'
import type { RequestPipeline } from '../../../requestPipeline/__.js'
import { createExtension } from '../../extension/extension.js'
import type { Anyware, Anyware as AnywareLib } from '../../lib/anyware/__.js'
import { Builder } from '../../lib/builder/__.js'
import type { RequestPipeline } from '../../requestPipeline/__.js'
import { type Context } from '../context.js'

export interface BuilderExtensionAnyware extends Builder.Extension {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Builder } from '../../../lib/builder/__.js'
import { Builder } from '../../lib/builder/__.js'
import type { Context } from '../context.js'

export interface BuilderExtensionInternal extends Builder.Extension {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DateScalar, FooScalar } from '../../../../tests/_/fixtures/scalars.js'
import { schemaMap } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { Graffle } from '../../../entrypoints/__Graffle.js'
import { assertEqual } from '../../../lib/assert-equal.js'
import { any, type SomeFunction } from '../../../lib/prelude.js'
import { DateScalar, FooScalar } from '../../../tests/_/fixtures/scalars.js'
import { schemaMap } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { Graffle } from '../../entrypoints/__Graffle.js'
import { assertEqual } from '../../lib/assert-equal.js'
import { any, type SomeFunction } from '../../lib/prelude.js'
import type { TypeErrorMissingSchemaMap } from './scalar.js'

const g1 = Graffle.create({ schema: `foo` })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { Simplify } from 'type-fest'
import { Builder } from '../../../lib/builder/__.js'
import type { ConfigManager } from '../../../lib/config-manager/__.js'
import type { GlobalRegistry } from '../../../types/GlobalRegistry/GlobalRegistry.js'
import { Schema } from '../../../types/Schema/__.js'
import { Builder } from '../../lib/builder/__.js'
import type { ConfigManager } from '../../lib/config-manager/__.js'
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
import { Schema } from '../../types/Schema/__.js'
import { type Context } from '../context.js'

export interface BuilderExtensionScalar extends Builder.Extension {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable */
import { describe, expect, expectTypeOf } from 'vitest'
import { createResponse, test } from '../../../../tests/_/helpers.js'
import { db } from '../../../../tests/_/schemas/db.js'
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { createExtension } from '../../../entrypoints/extensionkit.js'
import { Throws } from '../../../extensions/Throws/Throws.js'
import { createResponse, test } from '../../../tests/_/helpers.js'
import { db } from '../../../tests/_/schemas/db.js'
import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { createExtension } from '../../extension/extension.js'
import { Throws } from '../../extensions/Throws/Throws.js'
// import { oops } from '../../../lib/anyware/specHelpers.js'

const client = Graffle.create({ schema: 'https://foo', output: { defaults: { errorChannel: 'return' } } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Extension } from '../../../extension/extension.js'
import { Builder } from '../../../lib/builder/__.js'
import type { ConfigManager } from '../../../lib/config-manager/__.js'
import type { Extension } from '../../extension/extension.js'
import { Builder } from '../../lib/builder/__.js'
import type { ConfigManager } from '../../lib/config-manager/__.js'
import { type Context } from '../context.js'

export interface BuilderExtensionUse extends Builder.Extension {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Builder } from '../../../lib/builder/__.js'
import type { ConfigManager } from '../../../lib/config-manager/__.js'
import { mergeHeadersInit, mergeRequestInit } from '../../../lib/http.js'
import { Builder } from '../../lib/builder/__.js'
import type { ConfigManager } from '../../lib/config-manager/__.js'
import { mergeHeadersInit, mergeRequestInit } from '../../lib/http.js'
import { type Context } from '../context.js'
import type { WithInput } from '../Settings/inputIncrementable/inputIncrementable.js'
import type { NormalizeInput } from '../Settings/InputToConfig.js'
Expand Down
10 changes: 5 additions & 5 deletions src/layers/6_client/client.test.ts → src/client/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, expectTypeOf } from 'vitest'
import { createResponse, test } from '../../../tests/_/helpers.js'
import { Graffle as Graffle2 } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { Graffle } from '../../entrypoints/main.js'
import { Throws } from '../../extensions/Throws/Throws.js'
import { createResponse, test } from '../../tests/_/helpers.js'
import { Graffle as Graffle2 } from '../../tests/_/schemas/kitchen-sink/graffle/__.js'
import { schema } from '../../tests/_/schemas/kitchen-sink/schema.js'
import { Graffle } from '../entrypoints/main.js'
import { Throws } from '../extensions/Throws/Throws.js'

const endpoint = new URL(`https://foo.io/api/graphql`)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { describe, expect, expectTypeOf } from 'vitest'
import { createResponse, test } from '../../../tests/_/helpers.js'
import { serveSchema } from '../../../tests/_/lib/serveSchema.js'
import { Graffle as Pokemon } from '../../../tests/_/schemas/pokemon/graffle/__.js'
import { Graffle } from '../../entrypoints/main.js'
import { ACCEPT_REC, CONTENT_TYPE_REC } from '../../lib/grafaid/http/http.js'
import { Transport } from '../../requestPipeline/Transport.js'
import { createResponse, test } from '../../tests/_/helpers.js'
import { serveSchema } from '../../tests/_/lib/serveSchema.js'
import { Graffle as Pokemon } from '../../tests/_/schemas/pokemon/graffle/__.js'
import { schema as schemaPokemon } from '../../tests/_/schemas/pokemon/schema.js'
import { Graffle } from '../entrypoints/main.js'
import { ACCEPT_REC, CONTENT_TYPE_REC } from '../lib/grafaid/http/http.js'
import type { CoreExchangeGetRequest, CoreExchangePostRequest } from '../requestPipeline/hooks.js'
import { Transport } from '../requestPipeline/Transport.js'

const schema = new URL(`https://foo.io/api/graphql`)

Expand All @@ -31,9 +33,6 @@ test(`anyware hooks are typed to http transport`, () => {
})
})

import { schema as schemaPokemon } from '../../../tests/_/schemas/pokemon/schema.js'
import type { CoreExchangeGetRequest, CoreExchangePostRequest } from '../../requestPipeline/hooks.js'

test(`when envelope is used then response property is present even if relying on schema url default`, async () => {
const service = await serveSchema({ schema: schemaPokemon })
const pokemon = Pokemon.create({ output: { envelope: true } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expectTypeOf } from 'vitest'
import { test } from '../../../tests/_/helpers.js'
import { schema } from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { Graffle } from '../../entrypoints/main.js'
import { Transport } from '../../requestPipeline/Transport.js'
import { test } from '../../tests/_/helpers.js'
import { schema } from '../../tests/_/schemas/kitchen-sink/schema.js'
import { Graffle } from '../entrypoints/main.js'
import { Transport } from '../requestPipeline/Transport.js'

test(`anyware hooks are typed to memory transport`, () => {
Graffle.create({ schema }).anyware(async ({ encode }) => {
Expand Down
17 changes: 10 additions & 7 deletions src/layers/6_client/client.ts → src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { defaultName } from '../../generator/config/defaults.js'
import type { Builder } from '../../lib/builder/__.js'
import type { ConfigManager } from '../../lib/config-manager/__.js'
import { type Exact, proxyGet } from '../../lib/prelude.js'
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
import { Schema } from '../../types/Schema/__.js'
import {
type BuilderExtensionRequestMethods,
requestMethodsProperties,
} from '../documentBuilder/requestMethods/requestMethods.js' // todo
import { defaultName } from '../generator/config/defaults.js'
import type { Builder } from '../lib/builder/__.js'
import type { ConfigManager } from '../lib/config-manager/__.js'
import { type Exact, proxyGet } from '../lib/prelude.js'
import type { GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
import { Schema } from '../types/Schema/__.js'
import { type BuilderExtensionAnyware, builderExtensionAnyware } from './builderExtensions/anyware.js'
import { type BuilderExtensionInternal, builderExtensionInternal } from './builderExtensions/internal.js'
import { type BuilderExtensionScalar, builderExtensionScalar } from './builderExtensions/scalar.js'
import { type BuilderExtensionUse, builderExtensionUse } from './builderExtensions/use.js'
import { type BuilderExtensionWith, builderExtensionWith } from './builderExtensions/with.js'
import { type Context, type ContextWithoutConfig, createContext, type TypeHooksEmpty } from './context.js'
import { type BuilderExtensionGql, builderExtensionGql } from './gql/gql.js'
import { type BuilderExtensionRequestMethods, requestMethodsProperties } from './requestMethods/requestMethods.js' // todo
import { type InputStatic } from './Settings/Input.js'
import { type NormalizeInput } from './Settings/InputToConfig.js'

Expand Down
6 changes: 3 additions & 3 deletions src/layers/6_client/context.ts → src/client/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// import type { Anyware } from '../../lib/anyware/__.js'
// import type { RequestPipeline } from '../../requestPipeline/__.js'
import type { Extension } from '../../extension/extension.js'
import type { Schema } from '../../types/Schema/__.js'
import type { SchemaDrivenDataMap } from '../../types/SchemaDrivenDataMap/SchemaDrivenDataMap.js'
import type { Extension } from '../extension/extension.js'
import type { Schema } from '../types/Schema/__.js'
import type { SchemaDrivenDataMap } from '../types/SchemaDrivenDataMap/SchemaDrivenDataMap.js'
import type { Config } from './Settings/Config.js'
import type { InputStatic } from './Settings/Input.js'
import { inputToConfig } from './Settings/InputToConfig.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { kitchenSink as g } from '../../../../tests/_/helpers.js'
import { AssertTypeOf } from '../../../lib/assert-equal.js'
import type { Grafaid } from '../../../lib/grafaid/__.js'
import { kitchenSink as g } from '../../../tests/_/helpers.js'
import { AssertTypeOf } from '../../lib/assert-equal.js'
import type { Grafaid } from '../../lib/grafaid/__.js'

type D = { id: 0 }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect } from 'vitest'
import { test } from '../../../../tests/_/helpers.js'
import { Spy } from '../../../../tests/_/SpyExtension.js'
import { test } from '../../../tests/_/helpers.js'
import { Spy } from '../../../tests/_/SpyExtension.js'

// todo test with custom scalars

Expand Down
10 changes: 5 additions & 5 deletions src/layers/6_client/gql/gql.ts → src/client/gql/gql.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Builder } from '../../../lib/builder/__.js'
import type { Grafaid } from '../../../lib/grafaid/__.js'
import { getOperationType } from '../../../lib/grafaid/document.js'
import { Builder } from '../../lib/builder/__.js'
import type { Grafaid } from '../../lib/grafaid/__.js'
import { getOperationType } from '../../lib/grafaid/document.js'
import {
isTemplateStringArguments,
joinTemplateStringArrayAndArgs,
type TemplateStringsArguments,
} from '../../../lib/template-string.js'
import { RequestPipeline } from '../../../requestPipeline/__.js' // todo
} from '../../lib/template-string.js'
import { RequestPipeline } from '../../requestPipeline/__.js' // todo
import { type Context } from '../context.js'
import { handleOutput } from '../handleOutput.js'
import type { Config } from '../Settings/Config.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertEqual } from '../../../lib/assert-equal.js'
import type { Grafaid } from '../../../lib/grafaid/__.js'
import { assertEqual } from '../../lib/assert-equal.js'
import type { Grafaid } from '../../lib/grafaid/__.js'
import type { SendArguments } from './send.js'

assertEqual<
Expand Down
4 changes: 2 additions & 2 deletions src/layers/6_client/gql/send.ts → src/client/gql/send.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Grafaid } from '../../../lib/grafaid/__.js'
import { isString, type SimplifyNullable } from '../../../lib/prelude.js'
import type { Grafaid } from '../../lib/grafaid/__.js'
import { isString, type SimplifyNullable } from '../../lib/prelude.js'
import type { Context } from '../context.js'
import type { HandleOutput } from '../handleOutput.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { GraphQLError } from 'graphql'
import type { RunTypeHookOnRequestResult } from '../../extension/extension.js'
import { Errors } from '../../lib/errors/__.js'
import type { Grafaid } from '../../lib/grafaid/__.js'
import type { SomeObjectData } from '../../lib/grafaid/graphql.js'
import type { GraphQLExecutionResultError } from '../../lib/grafaid/graphql.js'
import type { RunTypeHookOnRequestResult } from '../extension/extension.js'
import { Errors } from '../lib/errors/__.js'
import type { Grafaid } from '../lib/grafaid/__.js'
import type { SomeObjectData } from '../lib/grafaid/graphql.js'
import type { GraphQLExecutionResultError } from '../lib/grafaid/graphql.js'
import {
type ExcludeNull,
type ExcludeNullAndUndefined,
type ExcludeUndefined,
type GetOrNever,
type Values,
} from '../../lib/prelude.js'
import type { TransportHttp } from '../../requestPipeline/Transport.js'
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
} from '../lib/prelude.js'
import type { TransportHttp } from '../requestPipeline/Transport.js'
import type { GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
import type { Context } from './context.js'
import {
type Config,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expectTypeOf, test } from 'vitest'
import { Graffle } from '../../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import * as Schema from '../../../../tests/_/schemas/kitchen-sink/schema.js'
import { MutationOnly } from '../../../../tests/_/schemas/mutation-only/graffle/__.js'
import * as SchemaMutationOnly from '../../../../tests/_/schemas/mutation-only/schema.js'
import { QueryOnly } from '../../../../tests/_/schemas/query-only/graffle/__.js'
import * as SchemaQueryOnly from '../../../../tests/_/schemas/query-only/schema.js'
import { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
import * as Schema from '../../../tests/_/schemas/kitchen-sink/schema.js'
import { MutationOnly } from '../../../tests/_/schemas/mutation-only/graffle/__.js'
import * as SchemaMutationOnly from '../../../tests/_/schemas/mutation-only/schema.js'
import { QueryOnly } from '../../../tests/_/schemas/query-only/graffle/__.js'
import * as SchemaQueryOnly from '../../../tests/_/schemas/query-only/schema.js'

const graffle = Graffle.create({ schema: Schema.schema })

Expand Down
Loading

0 comments on commit c69a48d

Please sign in to comment.