From 0f131b0cb61b8d5c9d6c83dfff85363401897f97 Mon Sep 17 00:00:00 2001 From: Phil Pluckthun Date: Wed, 10 Jan 2024 15:48:09 +0000 Subject: [PATCH] Rename tada namespace to $tada to indicate it's private --- src/__tests__/selection.test-d.ts | 6 +++--- src/index.ts | 2 -- src/namespace.ts | 12 ++++++++++-- src/selection.ts | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/__tests__/selection.test-d.ts b/src/__tests__/selection.test-d.ts index 3482ef1e..ab34ce46 100644 --- a/src/__tests__/selection.test-d.ts +++ b/src/__tests__/selection.test-d.ts @@ -1,6 +1,6 @@ import { expectTypeOf, test } from 'vitest'; import { simpleSchema } from './fixtures/simpleSchema'; -import { tada } from '../namespace'; +import { $tada } from '../namespace'; import { parseDocument } from '../parser'; import { mapIntrospection } from '../introspection'; import { getDocumentType } from '../selection'; @@ -116,7 +116,7 @@ test('infers fragment spreads for fragment refs', () => { type fragment = parseDocument['definitions'][0] & { - [tada.fragmentName]: 'Fields'; + [$tada.fragmentName]: 'Fields'; }; type query = parseDocument { type expected = { todos: Array<{ - [tada.fragmentRefs]: { + [$tada.fragmentRefs]: { Fields: fragment; }; } | null> | null; diff --git a/src/index.ts b/src/index.ts index 23572db9..b1c13e73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1 @@ -export type { tada } from './namespace'; - export * from './api'; diff --git a/src/namespace.ts b/src/namespace.ts index ea5e0dc4..321598fd 100644 --- a/src/namespace.ts +++ b/src/namespace.ts @@ -1,4 +1,12 @@ -declare namespace tada { +/** Private namespace holding our symbols for markers. + * + * @remarks + * Markers are used to indicate, for example, which fragments a given GraphQL document + * is referring to or which fragments a document exposes. This ties into “fragment masking”, + * a process by which the type of a fragment is hidden away until it’s unwrapped, to enforce + * isolation and code-reuse. + */ +declare namespace $tada { const fragmentRefs: unique symbol; export type fragmentRefs = typeof fragmentRefs; @@ -6,4 +14,4 @@ declare namespace tada { export type fragmentName = typeof fragmentName; } -export type { tada }; +export type { $tada }; diff --git a/src/selection.ts b/src/selection.ts index da67ae39..655a1226 100644 --- a/src/selection.ts +++ b/src/selection.ts @@ -6,7 +6,7 @@ import type { NameNode, } from '@0no-co/graphql.web'; -import type { tada } from './namespace'; +import type { $tada } from './namespace'; import type { obj, objValues } from './utils'; import type { getFragmentMap } from './fragments'; import type { DocumentNodeLike } from './parser'; @@ -82,9 +82,9 @@ type getFragmentSelection< : Node extends { kind: Kind.FRAGMENT_SPREAD; name: any } ? Node['name']['value'] extends keyof Fragments ? Fragments[Node['name']['value']] extends infer Fragment extends { - [tada.fragmentName]: string; + [$tada.fragmentName]: string; } - ? { [tada.fragmentRefs]: { [Name in Fragment[tada.fragmentName]]: Fragment } } + ? { [$tada.fragmentRefs]: { [Name in Fragment[$tada.fragmentName]]: Fragment } } : getSelection< Fragments[Node['name']['value']]['selectionSet']['selections'], Type,