From 08a4a87faf4a0d5ee1c9f6ef73aecd93389cc77b Mon Sep 17 00:00:00 2001 From: Saihajpreet Singh Date: Fri, 18 Jun 2021 00:12:03 -0400 Subject: [PATCH] remove flow infra and use TS --- .babelrc-npm.json | 2 +- .babelrc.json | 2 +- .eslintignore | 3 - .eslintrc.yml | 65 +----- .github/workflows/ci.yml | 2 +- .mocharc.yml | 2 +- README.md | 2 +- cspell.json | 1 - flow-typed/npm/chai_vx.x.x.js | 331 ---------------------------- flow-typed/npm/mocha_vx.x.x.js | 316 -------------------------- package-lock.json | 194 ++++++++-------- package.json | 18 +- resources/build.js | 56 ++++- resources/ts-register.js | 3 + src/connection/arrayConnection.d.ts | 82 ------- src/connection/connection.d.ts | 90 -------- src/index.d.ts | 42 ---- src/mutation/mutation.d.ts | 46 ---- src/node/node.d.ts | 63 ------ src/node/plural.d.ts | 22 -- src/utils/base64.d.ts | 5 - tsconfig.json | 11 +- 22 files changed, 172 insertions(+), 1186 deletions(-) delete mode 100644 flow-typed/npm/chai_vx.x.x.js delete mode 100644 flow-typed/npm/mocha_vx.x.x.js create mode 100644 resources/ts-register.js delete mode 100644 src/connection/arrayConnection.d.ts delete mode 100644 src/connection/connection.d.ts delete mode 100644 src/index.d.ts delete mode 100644 src/mutation/mutation.d.ts delete mode 100644 src/node/node.d.ts delete mode 100644 src/node/plural.d.ts delete mode 100644 src/utils/base64.d.ts diff --git a/.babelrc-npm.json b/.babelrc-npm.json index 2d428f3..fac5923 100644 --- a/.babelrc-npm.json +++ b/.babelrc-npm.json @@ -1,5 +1,5 @@ { - "plugins": ["@babel/plugin-transform-flow-strip-types"], + "plugins": ["@babel/plugin-transform-typescript"], "presets": [ [ "@babel/preset-env", diff --git a/.babelrc.json b/.babelrc.json index d6bcc04..caa5300 100644 --- a/.babelrc.json +++ b/.babelrc.json @@ -1,5 +1,5 @@ { - "plugins": ["@babel/plugin-transform-flow-strip-types"], + "plugins": ["@babel/plugin-transform-typescript"], "presets": [ [ "@babel/preset-env", diff --git a/.eslintignore b/.eslintignore index 58b5df2..f02fc68 100644 --- a/.eslintignore +++ b/.eslintignore @@ -2,6 +2,3 @@ node_modules coverage npmDist - -# Ignore Flow typings for 3rd-party libraries -/flow-typed diff --git a/.eslintrc.yml b/.eslintrc.yml index bef09f3..3f11ac3 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -428,61 +428,6 @@ rules: yield-star-spacing: off overrides: - - files: 'src/**/*.js' - parser: '@babel/eslint-parser' - parserOptions: - sourceType: module - plugins: - - flowtype - - rules: - ############################################################################## - # `eslint-plugin-flowtype` rule list based on `v5.3.x` - # https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype - ############################################################################## - - flowtype/array-style-complex-type: error - flowtype/array-style-simple-type: error - flowtype/define-flow-type: error - flowtype/newline-after-flow-annotation: error - flowtype/no-dupe-keys: error - flowtype/no-existential-type: off # checked by Flow - flowtype/no-flow-fix-me-comments: off - flowtype/no-mixed: off - flowtype/no-mutable-array: off - flowtype/no-primitive-constructor-types: error - flowtype/no-types-missing-file-annotation: off - flowtype/no-unused-expressions: off - flowtype/no-weak-types: [error, { any: false }] - flowtype/require-compound-type-alias: off - flowtype/require-exact-type: [error, never] - flowtype/require-indexer-name: error - flowtype/require-inexact-type: off # checked by Flow - flowtype/require-parameter-type: off - flowtype/require-readonly-react-props: off - flowtype/require-return-type: off - flowtype/require-types-at-top: off - flowtype/require-valid-file-annotation: off - flowtype/require-variable-type: off - flowtype/sort-keys: off - flowtype/spread-exact-type: off - flowtype/type-id-match: [error, '^[A-Z]'] - flowtype/type-import-style: [error, declaration] - flowtype/use-flow-type: error - - # Bellow rules are disabled because coflicts with Prettier, see: - # https://github.com/prettier/eslint-config-prettier/blob/master/flowtype.js - flowtype/arrow-parens: off - flowtype/boolean-style: off - flowtype/delimiter-dangle: off - flowtype/generic-spacing: off - flowtype/object-type-curly-spacing: off - flowtype/object-type-delimiter: off - flowtype/semi: off - flowtype/space-after-type-colon: off - flowtype/space-before-generic-bracket: off - flowtype/space-before-type-colon: off - flowtype/union-intersection-spacing: off - files: '**/*.ts' parser: '@typescript-eslint/parser' parserOptions: @@ -505,7 +450,7 @@ overrides: '@typescript-eslint/ban-ts-comment': [error, { 'ts-expect-error': false }] '@typescript-eslint/ban-tslint-comment': error '@typescript-eslint/ban-types': error - '@typescript-eslint/class-literal-property-style': off # TODO enable after TS conversion + '@typescript-eslint/class-literal-property-style': error '@typescript-eslint/consistent-indexed-object-style': off # TODO enable after TS conversion '@typescript-eslint/consistent-type-assertions': [error, { assertionStyle: as, objectLiteralTypeAssertions: never }] @@ -527,7 +472,7 @@ overrides: '@typescript-eslint/no-extraneous-class': off # TODO consider '@typescript-eslint/no-floating-promises': error '@typescript-eslint/no-for-in-array': error - '@typescript-eslint/no-implicit-any-catch': off # TODO: Enable after TS convertion + '@typescript-eslint/no-implicit-any-catch': error '@typescript-eslint/no-implied-eval': error '@typescript-eslint/no-inferrable-types': [error, { ignoreParameters: true, ignoreProperties: true }] @@ -542,7 +487,7 @@ overrides: '@typescript-eslint/no-this-alias': error '@typescript-eslint/no-type-alias': off # TODO consider '@typescript-eslint/no-unnecessary-boolean-literal-compare': error - '@typescript-eslint/no-unnecessary-condition': error + '@typescript-eslint/no-unnecessary-condition': off # TODO temporarily disabled '@typescript-eslint/no-unnecessary-qualifier': error '@typescript-eslint/no-unnecessary-type-arguments': error '@typescript-eslint/no-unnecessary-type-assertion': error @@ -555,7 +500,7 @@ overrides: '@typescript-eslint/non-nullable-type-assertion-style': error '@typescript-eslint/prefer-as-const': off # TODO consider '@typescript-eslint/prefer-enum-initializers': off # TODO consider - '@typescript-eslint/prefer-for-of': off # TODO switch to error after TS migration + '@typescript-eslint/prefer-for-of': error '@typescript-eslint/prefer-function-type': error '@typescript-eslint/prefer-includes': off # TODO switch to error after IE11 drop '@typescript-eslint/prefer-literal-enum-member': error @@ -630,7 +575,7 @@ overrides: '@typescript-eslint/require-await': error '@typescript-eslint/return-await': error - # Disable for JS, Flow and TS + # Disable for JS and TS '@typescript-eslint/init-declarations': off '@typescript-eslint/no-magic-numbers': off '@typescript-eslint/no-use-before-define': off diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d9be713..80884ac 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: - name: Lint ESLint run: npm run lint - - name: Lint Flow + - name: Check TypeScript run: npm run check - name: Lint Prettier diff --git a/.mocharc.yml b/.mocharc.yml index 5e75d26..51cae89 100644 --- a/.mocharc.yml +++ b/.mocharc.yml @@ -1,4 +1,4 @@ throw-deprecation: true check-leaks: true require: - - '@babel/register' + - 'resources/ts-register.js' diff --git a/README.md b/README.md index ecabab5..fabceac 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,7 @@ After cloning this repo, ensure dependencies are installed by running: npm install ``` -This library is written in ES6 and uses [Babel](https://babeljs.io/) for ES5 transpilation and [Flow](https://flow.org/) for type safety. Widely consumable JavaScript can be produced by running: +This library is written in ES6 and uses [Babel](https://babeljs.io/) for ES5 transpilation and [TypeScript](https://www.typescriptlang.org/) for type safety. Widely consumable JavaScript can be produced by running: ```sh npm run build diff --git a/cspell.json b/cspell.json index 9de70a3..214dd32 100644 --- a/cspell.json +++ b/cspell.json @@ -8,7 +8,6 @@ "npmDist", // Excluded from spelling check - "flow-typed", "cspell.json", "package.json", "package-lock.json", diff --git a/flow-typed/npm/chai_vx.x.x.js b/flow-typed/npm/chai_vx.x.x.js deleted file mode 100644 index aa4cbe8..0000000 --- a/flow-typed/npm/chai_vx.x.x.js +++ /dev/null @@ -1,331 +0,0 @@ -declare module 'chai' { - declare type ExpectChain = { - and: ExpectChain, - at: ExpectChain, - be: ExpectChain, - been: ExpectChain, - have: ExpectChain, - has: ExpectChain, - is: ExpectChain, - of: ExpectChain, - same: ExpectChain, - that: ExpectChain, - to: ExpectChain, - which: ExpectChain, - with: ExpectChain, - not: ExpectChain, - deep: ExpectChain, - any: ExpectChain, - all: ExpectChain, - own: ExpectChain, - a: ExpectChain & ((type: string, message?: string) => ExpectChain), - an: ExpectChain & ((type: string, message?: string) => ExpectChain), - include: ExpectChain & - ((value: mixed, message?: string) => ExpectChain), - includes: ExpectChain & - ((value: mixed, message?: string) => ExpectChain), - contain: ExpectChain & - ((value: mixed, message?: string) => ExpectChain), - contains: ExpectChain & - ((value: mixed, message?: string) => ExpectChain), - eq: (value: T, message?: string) => ExpectChain, - eql: (value: T, message?: string) => ExpectChain, - equal: (value: T, message?: string) => ExpectChain, - equals: (value: T, message?: string) => ExpectChain, - above: (value: T & number, message?: string) => ExpectChain, - gt: (value: T & number, message?: string) => ExpectChain, - greaterThan: (value: T & number, message?: string) => ExpectChain, - least: (value: T & number, message?: string) => ExpectChain, - below: (value: T & number, message?: string) => ExpectChain, - lessThan: (value: T & number, message?: string) => ExpectChain, - lt: (value: T & number, message?: string) => ExpectChain, - most: (value: T & number, message?: string) => ExpectChain, - within: ( - start: T & number, - finish: T & number, - message?: string, - ) => ExpectChain, - instanceof: (constructor: mixed, message?: string) => ExpectChain, - instanceOf: (constructor: mixed, message?: string) => ExpectChain, - nested: ExpectChain, - property:

( - name: string, - value?: P, - message?: string, - ) => ExpectChain

& ((name: string) => ExpectChain), - length: ExpectChain & - ((value: number, message?: string) => ExpectChain), - lengthOf: ExpectChain & - ((value: number, message?: string) => ExpectChain), - match: (regex: RegExp, message?: string) => ExpectChain, - matches: (regex: RegExp, message?: string) => ExpectChain, - string: (string: string, message?: string) => ExpectChain, - key: (key: string) => ExpectChain, - keys: ( - key: string | Array, - ...keys: Array - ) => ExpectChain, - throw: ( - err?: Class | Error | RegExp | string, - errMsgMatcher?: RegExp | string, - msg?: string, - ) => ExpectChain, - respondTo: (method: string, message?: string) => ExpectChain, - itself: ExpectChain, - satisfy: ( - method: (value: T) => boolean, - message?: string, - ) => ExpectChain, - closeTo: ( - expected: T & number, - delta: number, - message?: string, - ) => ExpectChain, - members: (set: mixed, message?: string) => ExpectChain, - oneOf: (list: Array, message?: string) => ExpectChain, - change: (obj: mixed, key: string, message?: string) => ExpectChain, - increase: (obj: mixed, key: string, message?: string) => ExpectChain, - decrease: (obj: mixed, key: string, message?: string) => ExpectChain, - by: (delta: number, message?: string) => ExpectChain, - ordered: ExpectChain, - // dirty-chai - ok: () => ExpectChain, - true: () => ExpectChain, - false: () => ExpectChain, - null: () => ExpectChain, - undefined: () => ExpectChain, - exist: () => ExpectChain, - empty: () => ExpectChain, - extensible: () => ExpectChain, - sealed: () => ExpectChain, - frozen: () => ExpectChain, - NaN: () => ExpectChain, - // chai-immutable - size: (n: number) => ExpectChain, - // sinon-chai - called: () => ExpectChain, - callCount: (n: number) => ExpectChain, - calledOnce: () => ExpectChain, - calledTwice: () => ExpectChain, - calledThrice: () => ExpectChain, - calledBefore: (spy: mixed) => ExpectChain, - calledAfter: (spy: mixed) => ExpectChain, - calledImmediatelyBefore: (spy: mixed) => ExpectChain, - calledImmediatelyAfter: (spy: mixed) => ExpectChain, - calledWith: (...args: Array) => ExpectChain, - calledOnceWith: (...args: Array) => ExpectChain, - calledWithMatch: (...args: Array) => ExpectChain, - calledWithExactly: (...args: Array) => ExpectChain, - calledOnceWithExactly: (...args: Array) => ExpectChain, - returned: (returnVal: mixed) => ExpectChain, - alwaysReturned: (returnVal: mixed) => ExpectChain, - // chai-as-promised - eventually: ExpectChain, - resolvedWith: (value: mixed) => Promise & ExpectChain, - resolved: () => Promise & ExpectChain, - rejectedWith: ( - value: mixed, - errMsgMatcher?: RegExp | string, - msg?: string, - ) => Promise & ExpectChain, - rejected: () => Promise & ExpectChain, - notify: (callback: () => mixed) => ExpectChain, - fulfilled: () => Promise & ExpectChain, - // chai-subset - containSubset: (obj: { ... } | Array<{ ... }>) => ExpectChain, - // chai-redux-mock-store - dispatchedActions: ( - actions: Array<{ ... } | ((action: { ... }) => any)>, - ) => ExpectChain, - dispatchedTypes: (actions: Array) => ExpectChain, - // chai-enzyme - attr: (key: string, val?: any) => ExpectChain, - data: (key: string, val?: any) => ExpectChain, - prop: (key: string, val?: any) => ExpectChain, - state: (key: string, val?: any) => ExpectChain, - value: (val: string) => ExpectChain, - className: (val: string) => ExpectChain, - text: (val: string) => ExpectChain, - // chai-karma-snapshot - matchSnapshot: (lang?: any, update?: boolean, msg?: any) => ExpectChain, - ... - }; - - declare var expect: { - (actual: T, message?: string): ExpectChain, - fail: ((message?: string) => void) & - (( - actual: any, - expected: any, - message?: string, - operator?: string, - ) => void), - ... - }; - - declare function use(plugin: (chai: Object, utils: Object) => void): void; - - declare class assert { - static (expression: mixed, message?: string): void; - static fail( - actual: mixed, - expected: mixed, - message?: string, - operator?: string, - ): void; - - static isOk(object: mixed, message?: string): void; - static isNotOk(object: mixed, message?: string): void; - - static empty(object: mixed, message?: string): void; - static isEmpty(object: mixed, message?: string): void; - static notEmpty(object: mixed, message?: string): void; - static isNotEmpty(object: mixed, message?: string): void; - - static equal(actual: mixed, expected: mixed, message?: string): void; - static notEqual(actual: mixed, expected: mixed, message?: string): void; - - static strictEqual(act: mixed, exp: mixed, msg?: string): void; - static notStrictEqual(act: mixed, exp: mixed, msg?: string): void; - - static deepEqual(act: mixed, exp: mixed, msg?: string): void; - static notDeepEqual(act: mixed, exp: mixed, msg?: string): void; - - static ok(val: mixed, msg?: string): void; - static isTrue(val: mixed, msg?: string): void; - static isNotTrue(val: mixed, msg?: string): void; - static isFalse(val: mixed, msg?: string): void; - static isNotFalse(val: mixed, msg?: string): void; - - static isNull(val: mixed, msg?: string): void; - static isNotNull(val: mixed, msg?: string): void; - - static isUndefined(val: mixed, msg?: string): void; - static isDefined(val: mixed, msg?: string): void; - - static isNaN(val: mixed, msg?: string): void; - static isNotNaN(val: mixed, msg?: string): void; - - static isAbove(val: number, abv: number, msg?: string): void; - static isBelow(val: number, blw: number, msg?: string): void; - - static exists(val: mixed, msg?: string): void; - static notExists(val: mixed, msg?: string): void; - - static isAtMost(val: number, atmst: number, msg?: string): void; - static isAtLeast(val: number, atlst: number, msg?: string): void; - - static isFunction(val: mixed, msg?: string): void; - static isNotFunction(val: mixed, msg?: string): void; - - static isObject(val: mixed, msg?: string): void; - static isNotObject(val: mixed, msg?: string): void; - - static isArray(val: mixed, msg?: string): void; - static isNotArray(val: mixed, msg?: string): void; - - static isString(val: mixed, msg?: string): void; - static isNotString(val: mixed, msg?: string): void; - - static isNumber(val: mixed, msg?: string): void; - static isNotNumber(val: mixed, msg?: string): void; - - static isBoolean(val: mixed, msg?: string): void; - static isNotBoolean(val: mixed, msg?: string): void; - - static typeOf(val: mixed, type: string, msg?: string): void; - static notTypeOf(val: mixed, type: string, msg?: string): void; - - static instanceOf(val: mixed, constructor: Class<*>, msg?: string): void; - static notInstanceOf(val: mixed, constructor: Class<*>, msg?: string): void; - - static include(exp: string, inc: mixed, msg?: string): void; - static include(exp: Array, inc: T, msg?: string): void; - - static notInclude(exp: string, inc: mixed, msg?: string): void; - static notInclude(exp: Array, inc: T, msg?: string): void; - - static deepInclude( - haystack: T[] | string, - needle: $Shape, - msg?: string, - ): void; - static notDeepInclude( - haystack: T[] | string, - needle: $Shape, - msg?: string, - ): void; - - static match(exp: mixed, re: RegExp, msg?: string): void; - static notMatch(exp: mixed, re: RegExp, msg?: string): void; - - static property(obj: Object, prop: string, msg?: string): void; - static notProperty(obj: Object, prop: string, msg?: string): void; - static deepProperty(obj: Object, prop: string, msg?: string): void; - static notDeepProperty(obj: Object, prop: string, msg?: string): void; - - static propertyVal( - obj: Object, - prop: string, - val: mixed, - msg?: string, - ): void; - static propertyNotVal( - obj: Object, - prop: string, - val: mixed, - msg?: string, - ): void; - - static deepPropertyVal( - obj: Object, - prop: string, - val: mixed, - msg?: string, - ): void; - static deepPropertyNotVal( - obj: Object, - prop: string, - val: mixed, - msg?: string, - ): void; - - static lengthOf(exp: mixed, len: number, msg?: string): void; - - static throws( - func: () => any, - err?: Class | Error | RegExp | string, - errorMsgMatcher?: string | RegExp, - msg?: string, - ): void; - static doesNotThrow( - func: () => any, - err?: Class | Error | RegExp | string, - errorMsgMatcher?: string | RegExp, - msg?: string, - ): void; - - static closeTo( - actual: number, - expected: number, - delta: number, - msg?: string, - ): void; - static approximately( - actual: number, - expected: number, - delta: number, - msg?: string, - ): void; - - // chai-immutable - static sizeOf(val: mixed, length: number): void; - } - - declare var config: { - includeStack: boolean, - showDiff: boolean, - truncateThreshold: number, - ... - }; -} diff --git a/flow-typed/npm/mocha_vx.x.x.js b/flow-typed/npm/mocha_vx.x.x.js deleted file mode 100644 index f83b48a..0000000 --- a/flow-typed/npm/mocha_vx.x.x.js +++ /dev/null @@ -1,316 +0,0 @@ -declare interface $npm$mocha$SetupOptions { - slow?: number; - timeout?: number; - ui?: string; - globals?: Array; - reporter?: any; - bail?: boolean; - ignoreLeaks?: boolean; - grep?: any; -} - -declare type $npm$mocha$done = (error?: any) => any; - -// declare interface $npm$mocha$SuiteCallbackContext { -// timeout(ms: number): void; -// retries(n: number): void; -// slow(ms: number): void; -// } - -// declare interface $npm$mocha$TestCallbackContext { -// skip(): void; -// timeout(ms: number): void; -// retries(n: number): void; -// slow(ms: number): void; -// [index: string]: any; -// } - -declare interface $npm$mocha$Suite { - parent: $npm$mocha$Suite; - title: string; - fullTitle(): string; -} - -declare type $npm$mocha$ContextDefinition = {| - ( - description: string, - callback: () => /* this: $npm$mocha$SuiteCallbackContext */ void, - ): $npm$mocha$Suite, - only( - description: string, - callback: () => /* this: $npm$mocha$SuiteCallbackContext */ void, - ): $npm$mocha$Suite, - skip( - description: string, - callback: () => /* this: $npm$mocha$SuiteCallbackContext */ void, - ): void, - timeout(ms: number): void, -|}; - -declare type $npm$mocha$TestDefinition = {| - ( - expectation: string, - callback?: ( - /* this: $npm$mocha$TestCallbackContext, */ done: $npm$mocha$done, - ) => mixed, - ): $npm$mocha$Test, - only( - expectation: string, - callback?: ( - /* this: $npm$mocha$TestCallbackContext, */ done: $npm$mocha$done, - ) => mixed, - ): $npm$mocha$Test, - skip( - expectation: string, - callback?: ( - /* this: $npm$mocha$TestCallbackContext, */ done: $npm$mocha$done, - ) => mixed, - ): void, - timeout(ms: number): void, - state: 'failed' | 'passed', -|}; - -declare interface $npm$mocha$Runner {} - -declare class $npm$mocha$BaseReporter { - stats: { - suites: number, - tests: number, - passes: number, - pending: number, - failures: number, - ... - }; - - constructor(runner: $npm$mocha$Runner): $npm$mocha$BaseReporter; -} - -declare class $npm$mocha$DocReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$DotReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$HTMLReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$HTMLCovReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$JSONReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$JSONCovReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$JSONStreamReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$LandingReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$ListReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$MarkdownReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$MinReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$NyanReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$ProgressReporter extends $npm$mocha$BaseReporter { - constructor( - runner: $npm$mocha$Runner, - options?: { - open?: string, - complete?: string, - incomplete?: string, - close?: string, - ... - }, - ): $npm$mocha$ProgressReporter; -} -declare class $npm$mocha$SpecReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$TAPReporter extends $npm$mocha$BaseReporter {} -declare class $npm$mocha$XUnitReporter extends $npm$mocha$BaseReporter { - constructor( - runner: $npm$mocha$Runner, - options?: any, - ): $npm$mocha$XUnitReporter; -} - -declare class $npm$mocha$Mocha { - currentTest: $npm$mocha$TestDefinition; - constructor(options?: { - grep?: RegExp, - ui?: string, - reporter?: string, - timeout?: number, - reporterOptions?: any, - slow?: number, - bail?: boolean, - ... - }): $npm$mocha$Mocha; - setup(options: $npm$mocha$SetupOptions): this; - bail(value?: boolean): this; - addFile(file: string): this; - reporter(name: string): this; - reporter(reporter: (runner: $npm$mocha$Runner, options: any) => any): this; - ui(value: string): this; - grep(value: string): this; - grep(value: RegExp): this; - invert(): this; - ignoreLeaks(value: boolean): this; - checkLeaks(): this; - throwError(error: Error): void; - growl(): this; - globals(value: string): this; - globals(values: Array): this; - useColors(value: boolean): this; - useInlineDiffs(value: boolean): this; - timeout(value: number): this; - slow(value: number): this; - enableTimeouts(value: boolean): this; - asyncOnly(value: boolean): this; - noHighlighting(value: boolean): this; - run(onComplete?: (failures: number) => void): $npm$mocha$Runner; - - static reporters: { - Doc: $npm$mocha$DocReporter, - Dot: $npm$mocha$DotReporter, - HTML: $npm$mocha$HTMLReporter, - HTMLCov: $npm$mocha$HTMLCovReporter, - JSON: $npm$mocha$JSONReporter, - JSONCov: $npm$mocha$JSONCovReporter, - JSONStream: $npm$mocha$JSONStreamReporter, - Landing: $npm$mocha$LandingReporter, - List: $npm$mocha$ListReporter, - Markdown: $npm$mocha$MarkdownReporter, - Min: $npm$mocha$MinReporter, - Nyan: $npm$mocha$NyanReporter, - Progress: $npm$mocha$ProgressReporter, - ... - }; -} - -// declare interface $npm$mocha$HookCallbackContext { -// skip(): void; -// timeout(ms: number): void; -// [index: string]: any; -// } - -declare interface $npm$mocha$Runnable { - title: string; - fn: Function; - async: boolean; - sync: boolean; - timedOut: boolean; -} - -declare interface $npm$mocha$Test extends $npm$mocha$Runnable { - parent: $npm$mocha$Suite; - pending: boolean; - state: 'failed' | 'passed' | void; - fullTitle(): string; - timeout(ms: number): void; -} - -// declare interface $npm$mocha$BeforeAndAfterContext extends $npm$mocha$HookCallbackContext { -// currentTest: $npm$mocha$Test; -// } - -declare var mocha: $npm$mocha$Mocha; -declare var describe: $npm$mocha$ContextDefinition; -declare var xdescribe: $npm$mocha$ContextDefinition; -declare var context: $npm$mocha$ContextDefinition; -declare var suite: $npm$mocha$ContextDefinition; -declare var it: $npm$mocha$TestDefinition; -declare var xit: $npm$mocha$TestDefinition; -declare var test: $npm$mocha$TestDefinition; -declare var specify: $npm$mocha$TestDefinition; - -type Run = () => void; - -declare var run: Run; - -type Setup = ( - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, -) => void; -type Teardown = ( - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, -) => void; -type SuiteSetup = ( - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, -) => void; -type SuiteTeardown = ( - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, -) => void; -type Before = ( - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, -) => - | void - | (( - description: string, - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, - ) => void); -type After = ( - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, -) => - | void - | (( - description: string, - callback: ( - /* this: $npm$mocha$HookCallbackContext, */ done: $npm$mocha$done, - ) => mixed, - ) => void); -type BeforeEach = ( - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, -) => - | void - | (( - description: string, - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, - ) => void); -type AfterEach = ( - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, -) => - | void - | (( - description: string, - callback: ( - /* this: $npm$mocha$BeforeAndAfterContext, */ done: $npm$mocha$done, - ) => mixed, - ) => void); - -declare var setup: Setup; -declare var teardown: Teardown; -declare var suiteSetup: SuiteSetup; -declare var suiteTeardown; -declare var before: Before; -declare var after: After; -declare var beforeEach: BeforeEach; -declare var afterEach: AfterEach; - -declare module 'mocha' { - declare export var mocha: $npm$mocha$TestDefinition; - declare export var describe: $npm$mocha$ContextDefinition; - declare export var xdescribe: $npm$mocha$ContextDefinition; - declare export var context: $npm$mocha$ContextDefinition; - declare export var suite: $npm$mocha$ContextDefinition; - declare export var it: $npm$mocha$TestDefinition; - declare export var xit: $npm$mocha$TestDefinition; - declare export var test: $npm$mocha$TestDefinition; - declare export var specify: $npm$mocha$TestDefinition; - - declare export var run: Run; - - declare export var setup: Setup; - declare export var teardown: Teardown; - declare export var suiteSetup: SuiteSetup; - declare export var suiteTeardown: SuiteTeardown; - declare export var before: Before; - declare export var after: After; - declare export var beforeEach: BeforeEach; - declare export var afterEach: AfterEach; - - declare export default $npm$mocha$Mocha; -} diff --git a/package-lock.json b/package-lock.json index 720b04f..d02282b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,15 +12,17 @@ "@babel/core": "7.15.5", "@babel/eslint-parser": "7.15.4", "@babel/node": "7.15.4", - "@babel/plugin-transform-flow-strip-types": "7.14.5", + "@babel/plugin-transform-typescript": "7.14.6", "@babel/preset-env": "7.15.6", "@babel/register": "7.15.3", + "@types/chai": "4.2.19", + "@types/mocha": "8.2.2", + "@types/node": "15.12.5", "@typescript-eslint/eslint-plugin": "4.31.0", "@typescript-eslint/parser": "4.31.0", "chai": "4.3.4", "cspell": "5.9.0", "eslint": "7.32.0", - "eslint-plugin-flowtype": "5.9.2", "eslint-plugin-import": "2.24.2", "eslint-plugin-istanbul": "0.1.2", "eslint-plugin-node": "11.1.0", @@ -822,21 +824,6 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-syntax-flow": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.14.5.tgz", - "integrity": "sha512-9WK5ZwKCdWHxVuU13XNT6X73FGmutAXeor5lGFq6qhOFtMFUF4jkbijuyUdZZlpYq6E2hZeZf/u3959X9wsv0Q==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.14.5" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-syntax-json-strings": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", @@ -951,6 +938,21 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-syntax-typescript": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.14.5.tgz", + "integrity": "sha512-u6OXzDaIXjEstBRRoBCQ/uKQKlbuaeE5in0RvWdA4pN6AhqxTIwUsnHPU1CFZA/amYObMsuWhYfRl3Ch90HD0Q==", + "dev": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-transform-arrow-functions": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.14.5.tgz", @@ -1111,22 +1113,6 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-transform-flow-strip-types": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.14.5.tgz", - "integrity": "sha512-KhcolBKfXbvjwI3TV7r7TkYm8oNXHNBqGOy6JDVwtecFaRoKYsUUqJdS10q0YDKW1c6aZQgO+Ys3LfGkox8pXA==", - "dev": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.14.5", - "@babel/plugin-syntax-flow": "^7.14.5" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-transform-for-of": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.15.4.tgz", @@ -1440,6 +1426,23 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-typescript": { + "version": "7.14.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.14.6.tgz", + "integrity": "sha512-XlTdBq7Awr4FYIzqhmYY80WN0V0azF74DMPyFqVHBvf81ZUgc4X7ZOpx6O8eLDK6iM5cCQzeyJw0ynTaefixRA==", + "dev": true, + "dependencies": { + "@babel/helper-create-class-features-plugin": "^7.14.6", + "@babel/helper-plugin-utils": "^7.14.5", + "@babel/plugin-syntax-typescript": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, "node_modules/@babel/plugin-transform-unicode-escapes": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.14.5.tgz", @@ -2096,6 +2099,12 @@ "node": ">= 8" } }, + "node_modules/@types/chai": { + "version": "4.2.19", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.19.tgz", + "integrity": "sha512-jRJgpRBuY+7izT7/WNXP/LsMO9YonsstuL+xuvycDyESpoDoIAsMd7suwpB4h9oEWB+ZlPTqJJ8EHomzNhwTPQ==", + "dev": true + }, "node_modules/@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -2108,6 +2117,18 @@ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", "dev": true }, + "node_modules/@types/mocha": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.2.tgz", + "integrity": "sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==", + "dev": true + }, + "node_modules/@types/node": { + "version": "15.12.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.5.tgz", + "integrity": "sha512-se3yX7UHv5Bscf8f1ERKvQOD6sTyycH3hdaoozvaLxgUiY5lIGEeH37AD0G0Qi9kPqihPn0HOfd2yaIEN9VwEg==", + "dev": true + }, "node_modules/@types/parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", @@ -3504,22 +3525,6 @@ "node": ">=4" } }, - "node_modules/eslint-plugin-flowtype": { - "version": "5.9.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-5.9.2.tgz", - "integrity": "sha512-qxE/eo9DCN7800MIB/O1ToOiFuOPOlaMJWQY2BEm69oY7RCm3s2X1z4CdgtFvDDWf9RSSugZm1KRhdBMBueKbg==", - "dev": true, - "dependencies": { - "lodash": "^4.17.15", - "string-natural-compare": "^3.0.1" - }, - "engines": { - "node": "^10.12.0 || >=12.0.0" - }, - "peerDependencies": { - "eslint": "^7.1.0" - } - }, "node_modules/eslint-plugin-import": { "version": "2.24.2", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.24.2.tgz", @@ -5265,12 +5270,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true - }, "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -6999,12 +6998,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "node_modules/string-natural-compare": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/string-natural-compare/-/string-natural-compare-3.0.1.tgz", - "integrity": "sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==", - "dev": true - }, "node_modules/string-width": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", @@ -8238,15 +8231,6 @@ "@babel/helper-plugin-utils": "^7.8.3" } }, - "@babel/plugin-syntax-flow": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.14.5.tgz", - "integrity": "sha512-9WK5ZwKCdWHxVuU13XNT6X73FGmutAXeor5lGFq6qhOFtMFUF4jkbijuyUdZZlpYq6E2hZeZf/u3959X9wsv0Q==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.14.5" - } - }, "@babel/plugin-syntax-json-strings": { "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", @@ -8328,6 +8312,15 @@ "@babel/helper-plugin-utils": "^7.14.5" } }, + "@babel/plugin-syntax-typescript": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.14.5.tgz", + "integrity": "sha512-u6OXzDaIXjEstBRRoBCQ/uKQKlbuaeE5in0RvWdA4pN6AhqxTIwUsnHPU1CFZA/amYObMsuWhYfRl3Ch90HD0Q==", + "dev": true, + "requires": { + "@babel/helper-plugin-utils": "^7.14.5" + } + }, "@babel/plugin-transform-arrow-functions": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.14.5.tgz", @@ -8428,16 +8421,6 @@ "@babel/helper-plugin-utils": "^7.14.5" } }, - "@babel/plugin-transform-flow-strip-types": { - "version": "7.14.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.14.5.tgz", - "integrity": "sha512-KhcolBKfXbvjwI3TV7r7TkYm8oNXHNBqGOy6JDVwtecFaRoKYsUUqJdS10q0YDKW1c6aZQgO+Ys3LfGkox8pXA==", - "dev": true, - "requires": { - "@babel/helper-plugin-utils": "^7.14.5", - "@babel/plugin-syntax-flow": "^7.14.5" - } - }, "@babel/plugin-transform-for-of": { "version": "7.15.4", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.15.4.tgz", @@ -8631,6 +8614,17 @@ "@babel/helper-plugin-utils": "^7.14.5" } }, + "@babel/plugin-transform-typescript": { + "version": "7.14.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.14.6.tgz", + "integrity": "sha512-XlTdBq7Awr4FYIzqhmYY80WN0V0azF74DMPyFqVHBvf81ZUgc4X7ZOpx6O8eLDK6iM5cCQzeyJw0ynTaefixRA==", + "dev": true, + "requires": { + "@babel/helper-create-class-features-plugin": "^7.14.6", + "@babel/helper-plugin-utils": "^7.14.5", + "@babel/plugin-syntax-typescript": "^7.14.5" + } + }, "@babel/plugin-transform-unicode-escapes": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.14.5.tgz", @@ -9198,6 +9192,12 @@ "fastq": "^1.6.0" } }, + "@types/chai": { + "version": "4.2.19", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.19.tgz", + "integrity": "sha512-jRJgpRBuY+7izT7/WNXP/LsMO9YonsstuL+xuvycDyESpoDoIAsMd7suwpB4h9oEWB+ZlPTqJJ8EHomzNhwTPQ==", + "dev": true + }, "@types/json-schema": { "version": "7.0.9", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", @@ -9210,6 +9210,18 @@ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", "dev": true }, + "@types/mocha": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-8.2.2.tgz", + "integrity": "sha512-Lwh0lzzqT5Pqh6z61P3c3P5nm6fzQK/MMHl9UKeneAeInVflBSz1O2EkX6gM6xfJd7FBXBY5purtLx7fUiZ7Hw==", + "dev": true + }, + "@types/node": { + "version": "15.12.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-15.12.5.tgz", + "integrity": "sha512-se3yX7UHv5Bscf8f1ERKvQOD6sTyycH3hdaoozvaLxgUiY5lIGEeH37AD0G0Qi9kPqihPn0HOfd2yaIEN9VwEg==", + "dev": true + }, "@types/parse-json": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz", @@ -10357,16 +10369,6 @@ } } }, - "eslint-plugin-flowtype": { - "version": "5.9.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-flowtype/-/eslint-plugin-flowtype-5.9.2.tgz", - "integrity": "sha512-qxE/eo9DCN7800MIB/O1ToOiFuOPOlaMJWQY2BEm69oY7RCm3s2X1z4CdgtFvDDWf9RSSugZm1KRhdBMBueKbg==", - "dev": true, - "requires": { - "lodash": "^4.17.15", - "string-natural-compare": "^3.0.1" - } - }, "eslint-plugin-import": { "version": "2.24.2", "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.24.2.tgz", @@ -11518,12 +11520,6 @@ "p-locate": "^5.0.0" } }, - "lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true - }, "lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", @@ -12829,12 +12825,6 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, - "string-natural-compare": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/string-natural-compare/-/string-natural-compare-3.0.1.tgz", - "integrity": "sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw==", - "dev": true - }, "string-width": { "version": "4.2.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz", diff --git a/package.json b/package.json index 72d7796..a7d1dbe 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,13 @@ "license": "MIT", "private": true, "main": "index", - "types": "index.d.ts", + "typesVersions": { + ">=4.1.0": { + "*": [ + "*" + ] + } + }, "sideEffects": false, "homepage": "https://github.com/graphql/graphql-relay-js", "bugs": { @@ -25,8 +31,8 @@ "preversion": "npm ci && npm run test", "test": "npm run lint && npm run check && npm run testonly && npm run prettier:check && npm run check:spelling", "lint": "eslint --max-warnings 0 .", - "check": "flow check", - "testonly": "mocha --full-trace src/**/__tests__/**/*-test.js", + "check": "tsc --pretty", + "testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts", "testonly:cover": "nyc npm run testonly", "prettier": "prettier --write --list-different .", "prettier:check": "prettier --check .", @@ -40,15 +46,17 @@ "@babel/core": "7.15.5", "@babel/eslint-parser": "7.15.4", "@babel/node": "7.15.4", - "@babel/plugin-transform-flow-strip-types": "7.14.5", + "@babel/plugin-transform-typescript": "7.14.6", "@babel/preset-env": "7.15.6", "@babel/register": "7.15.3", + "@types/chai": "4.2.19", + "@types/mocha": "8.2.2", + "@types/node": "15.12.5", "@typescript-eslint/eslint-plugin": "4.31.0", "@typescript-eslint/parser": "4.31.0", "chai": "4.3.4", "cspell": "5.9.0", "eslint": "7.32.0", - "eslint-plugin-flowtype": "5.9.2", "eslint-plugin-import": "2.24.2", "eslint-plugin-istanbul": "0.1.2", "eslint-plugin-node": "11.1.0", diff --git a/resources/build.js b/resources/build.js index 5834e95..c1d9175 100644 --- a/resources/build.js +++ b/resources/build.js @@ -4,6 +4,7 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert'); +const ts = require('typescript'); const babel = require('@babel/core'); const { @@ -24,17 +25,58 @@ if (require.main === module) { const destPath = path.join('./npmDist', filepath); fs.mkdirSync(path.dirname(destPath), { recursive: true }); - if (filepath.endsWith('.js')) { - const flowBody = '// @flow strict\n' + fs.readFileSync(srcPath, 'utf-8'); - writeGeneratedFile(destPath + '.flow', flowBody); - + if (filepath.endsWith('.ts')) { const cjs = babelBuild(srcPath, { envName: 'cjs' }); - writeGeneratedFile(destPath, cjs); - } else if (filepath.endsWith('.d.ts')) { - fs.copyFileSync(srcPath, destPath); + writeGeneratedFile(destPath.replace(/\.ts$/, '.js'), cjs); } } + // Based on https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#getting-the-dts-from-a-javascript-file + const tsConfig = JSON.parse( + fs.readFileSync(require.resolve('../tsconfig.json'), 'utf-8'), + ); + assert( + tsConfig.compilerOptions, + '"tsconfig.json" should have `compilerOptions`', + ); + const tsOptions = { + ...tsConfig.compilerOptions, + noEmit: false, + declaration: true, + declarationDir: './npmDist', + emitDeclarationOnly: true, + }; + + const tsHost = ts.createCompilerHost(tsOptions); + tsHost.writeFile = (filepath, body) => { + writeGeneratedFile(filepath, body); + }; + + const tsProgram = ts.createProgram(['src/index.ts'], tsOptions, tsHost); + const tsResult = tsProgram.emit(); + assert( + !tsResult.emitSkipped, + 'Fail to generate `*.d.ts` files, please run `npm run check`', + ); + + assert(packageJSON.types === undefined, 'Unexpected "types" in package.json'); + const supportedTSVersions = Object.keys(packageJSON.typesVersions); + assert( + supportedTSVersions.length === 1, + 'Property "typesVersions" should have exactly one key.', + ); + // TODO: revisit once TS implements https://github.com/microsoft/TypeScript/issues/32166 + const notSupportedTSVersionFile = 'NotSupportedTSVersion.d.ts'; + fs.writeFileSync( + path.join('./npmDist', notSupportedTSVersionFile), + // Provoke syntax error to show this message + `"Package 'graphql' support only TS versions that are ${supportedTSVersions[0]}".`, + ); + packageJSON.typesVersions = { + ...packageJSON.typesVersions, + '*': { '*': [notSupportedTSVersionFile] }, + }; + fs.copyFileSync('./LICENSE', './npmDist/LICENSE'); fs.copyFileSync('./README.md', './npmDist/README.md'); diff --git a/resources/ts-register.js b/resources/ts-register.js new file mode 100644 index 0000000..649eb5f --- /dev/null +++ b/resources/ts-register.js @@ -0,0 +1,3 @@ +'use strict'; + +require('@babel/register')({ extensions: ['.ts'] }); diff --git a/src/connection/arrayConnection.d.ts b/src/connection/arrayConnection.d.ts deleted file mode 100644 index f309987..0000000 --- a/src/connection/arrayConnection.d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { - Connection, - ConnectionArguments, - ConnectionCursor, -} from './connection'; - -interface ArraySliceMetaInfo { - sliceStart: number; - arrayLength: number; -} - -/** - * A simple function that accepts an array and connection arguments, and returns - * a connection object for use in GraphQL. It uses array offsets as pagination, - * so pagination will only work if the array is static. - */ -export declare function connectionFromArray( - data: ReadonlyArray, - args: ConnectionArguments, -): Connection; - -/** - * A version of `connectionFromArray` that takes a promised array, and returns a - * promised connection. - */ -export declare function connectionFromPromisedArray( - dataPromise: Promise>, - args: ConnectionArguments, -): Promise>; - -/** - * Given a slice (subset) of an array, returns a connection object for use in - * GraphQL. - * - * This function is similar to `connectionFromArray`, but is intended for use - * cases where you know the cardinality of the connection, consider it too large - * to materialize the entire array, and instead wish pass in a slice of the - * total result large enough to cover the range specified in `args`. - */ -export declare function connectionFromArraySlice( - arraySlice: ReadonlyArray, - args: ConnectionArguments, - meta: ArraySliceMetaInfo, -): Connection; - -/** - * A version of `connectionFromArraySlice` that takes a promised array slice, - * and returns a promised connection. - */ -export declare function connectionFromPromisedArraySlice( - dataPromise: Promise>, - args: ConnectionArguments, - arrayInfo: ArraySliceMetaInfo, -): Promise>; - -/** - * Creates the cursor string from an offset. - */ -export declare function offsetToCursor(offset: number): ConnectionCursor; - -/** - * Extracts the offset from the cursor string. - */ -export declare function cursorToOffset(cursor: ConnectionCursor): number; - -/** - * Return the cursor associated with an object in an array. - */ -export declare function cursorForObjectInConnection( - data: ReadonlyArray, - object: T, -): ConnectionCursor | null; - -/** - * Given an optional cursor and a default offset, returns the offset - * to use; if the cursor contains a valid offset, that will be used, - * otherwise it will be the default. - */ -export declare function getOffsetWithDefault( - cursor: ConnectionCursor | null | undefined, - defaultOffset: number, -): number; diff --git a/src/connection/connection.d.ts b/src/connection/connection.d.ts deleted file mode 100644 index d979b3b..0000000 --- a/src/connection/connection.d.ts +++ /dev/null @@ -1,90 +0,0 @@ -import type { - GraphQLNonNull, - GraphQLObjectType, - GraphQLNamedOutputType, - GraphQLFieldConfigArgumentMap, - GraphQLFieldConfigMap, - GraphQLFieldResolver, - Thunk, -} from 'graphql'; - -/** - * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field - * whose return type is a connection type with forward pagination. - */ -export declare const forwardConnectionArgs: GraphQLFieldConfigArgumentMap; - -/** - * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field - * whose return type is a connection type with backward pagination. - */ -export declare const backwardConnectionArgs: GraphQLFieldConfigArgumentMap; - -/** - * Returns a GraphQLFieldConfigArgumentMap appropriate to include on a field - * whose return type is a connection type with bidirectional pagination. - */ -export declare const connectionArgs: GraphQLFieldConfigArgumentMap; - -/** - * A type alias for cursors in this implementation. - */ -export declare type ConnectionCursor = string; - -/** - * A type describing the arguments a connection field receives in GraphQL. - */ -export interface ConnectionArguments { - before?: ConnectionCursor | null; - after?: ConnectionCursor | null; - first?: number | null; - last?: number | null; -} - -export interface ConnectionConfig { - name?: string; - nodeType: GraphQLNamedOutputType | GraphQLNonNull; - resolveNode?: GraphQLFieldResolver; - resolveCursor?: GraphQLFieldResolver; - edgeFields?: Thunk>; - connectionFields?: Thunk>; -} - -export interface GraphQLConnectionDefinitions { - edgeType: GraphQLObjectType; - connectionType: GraphQLObjectType; -} - -/** - * Returns a GraphQLObjectType for a connection with the given name, - * and whose nodes are of the specified type. - */ -export declare function connectionDefinitions( - config: ConnectionConfig, -): GraphQLConnectionDefinitions; - -/** - * A type designed to be exposed as a `Connection` over GraphQL. - */ -export interface Connection { - edges: Array>; - pageInfo: PageInfo; -} - -/** - * A type designed to be exposed as a `Edge` over GraphQL. - */ -export interface Edge { - node: T; - cursor: ConnectionCursor; -} - -/** - * A type designed to be exposed as `PageInfo` over GraphQL. - */ -export interface PageInfo { - startCursor: ConnectionCursor | null; - endCursor: ConnectionCursor | null; - hasPreviousPage: boolean; - hasNextPage: boolean; -} diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 9be6bcc..0000000 --- a/src/index.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -// Types for creating connection types in the schema -export type { - Connection, - ConnectionArguments, - ConnectionCursor, - ConnectionConfig, - GraphQLConnectionDefinitions, - Edge, - PageInfo, -} from './connection/connection'; - -// Helpers for creating connection types in the schema -export { - backwardConnectionArgs, - connectionArgs, - connectionDefinitions, - forwardConnectionArgs, -} from './connection/connection'; - -// Helpers for creating connections from arrays -export { - connectionFromArray, - connectionFromArraySlice, - connectionFromPromisedArray, - connectionFromPromisedArraySlice, - cursorForObjectInConnection, - cursorToOffset, - getOffsetWithDefault, - offsetToCursor, -} from './connection/arrayConnection'; - -// Helper for creating mutations with client mutation IDs -export { mutationWithClientMutationId } from './mutation/mutation'; - -// Helper for creating node definitions -export { nodeDefinitions } from './node/node'; - -// Helper for creating plural identifying root fields -export { pluralIdentifyingRootField } from './node/plural'; - -// Utilities for creating global IDs in systems that don't have them. -export { fromGlobalId, globalIdField, toGlobalId } from './node/node'; diff --git a/src/mutation/mutation.d.ts b/src/mutation/mutation.d.ts deleted file mode 100644 index 838a33c..0000000 --- a/src/mutation/mutation.d.ts +++ /dev/null @@ -1,46 +0,0 @@ -import type { - GraphQLFieldConfig, - GraphQLFieldExtensions, - GraphQLInputFieldConfigMap, - GraphQLFieldConfigMap, - GraphQLResolveInfo, - Thunk, -} from 'graphql'; - -declare type MutationFn = ( - object: any, - ctx: any, - info: GraphQLResolveInfo, -) => unknown; - -/** - * A description of a mutation consumable by mutationWithClientMutationId - * to create a GraphQLFieldConfig for that mutation. - * - * The inputFields and outputFields should not include `clientMutationId`, - * as this will be provided automatically. - * - * An input object will be created containing the input fields, and an - * object will be created containing the output fields. - * - * mutateAndGetPayload will receive an Object with a key for each - * input field, and it should return an Object with a key for each - * output field. It may return synchronously, or return a Promise. - */ -interface MutationConfig { - name: string; - description?: string; - deprecationReason?: string; - extensions?: GraphQLFieldExtensions; - inputFields: Thunk; - outputFields: Thunk>; - mutateAndGetPayload: MutationFn; -} - -/** - * Returns a GraphQLFieldConfig for the mutation described by the - * provided MutationConfig. - */ -export declare function mutationWithClientMutationId( - config: MutationConfig, -): GraphQLFieldConfig; diff --git a/src/node/node.d.ts b/src/node/node.d.ts deleted file mode 100644 index 9476540..0000000 --- a/src/node/node.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { - GraphQLFieldConfig, - GraphQLInterfaceType, - GraphQLResolveInfo, - GraphQLTypeResolver, -} from 'graphql'; - -interface GraphQLNodeDefinitions { - nodeInterface: GraphQLInterfaceType; - nodeField: GraphQLFieldConfig; - nodesField: GraphQLFieldConfig; -} - -/** - * Given a function to map from an ID to an underlying object, and a function - * to map from an underlying object to the concrete GraphQLObjectType it - * corresponds to, constructs a `Node` interface that objects can implement, - * and a field config for a `node` root field. - * - * If the typeResolver is omitted, object resolution on the interface will be - * handled with the `isTypeOf` method on object types, as with any GraphQL - * interface without a provided `resolveType` method. - */ -export declare function nodeDefinitions( - fetchById: ( - id: string, - context: TContext, - info: GraphQLResolveInfo, - ) => unknown, - typeResolver?: GraphQLTypeResolver, -): GraphQLNodeDefinitions; - -interface ResolvedGlobalId { - type: string; - id: string; -} - -/** - * Takes a type name and an ID specific to that type name, and returns a - * "global ID" that is unique among all types. - */ -export declare function toGlobalId(type: string, id: string | number): string; - -/** - * Takes the "global ID" created by toGlobalID, and returns the type name and ID - * used to create it. - */ -export declare function fromGlobalId(globalId: string): ResolvedGlobalId; - -/** - * Creates the configuration for an id field on a node, using `toGlobalId` to - * construct the ID from the provided typename. The type-specific ID is fetched - * by calling idFetcher on the object, or if not provided, by accessing the `id` - * property on the object. - */ -export declare function globalIdField( - typeName?: string, - idFetcher?: ( - obj: any, - context: TContext, - info: GraphQLResolveInfo, - ) => string | number, -): GraphQLFieldConfig; diff --git a/src/node/plural.d.ts b/src/node/plural.d.ts deleted file mode 100644 index b38f245..0000000 --- a/src/node/plural.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { - GraphQLFieldConfig, - GraphQLInputType, - GraphQLOutputType, - GraphQLResolveInfo, -} from 'graphql'; - -interface PluralIdentifyingRootFieldConfig { - argName: string; - inputType: GraphQLInputType; - outputType: GraphQLOutputType; - resolveSingleInput: ( - input: any, - context: any, - info: GraphQLResolveInfo, - ) => unknown; - description?: string; -} - -export declare function pluralIdentifyingRootField( - config: PluralIdentifyingRootFieldConfig, -): GraphQLFieldConfig; diff --git a/src/utils/base64.d.ts b/src/utils/base64.d.ts deleted file mode 100644 index 5c39799..0000000 --- a/src/utils/base64.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -export declare type Base64String = string; - -export declare function base64(input: string): Base64String; - -export declare function unbase64(input: Base64String): string; diff --git a/tsconfig.json b/tsconfig.json index d25aa26..717ecdf 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,13 +1,12 @@ { + "include": ["src/**/*"], "compilerOptions": { "module": "commonjs", - "lib": ["es6", "esnext.asynciterable"], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "types": [], + "lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"], + "target": "es2019", + "strict": true, "noEmit": true, + "isolatedModules": true, "forceConsistentCasingInFileNames": true } }