-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby) Migrate joi schema to Typescript (#22738)
* Migrate joi schema to Typescript * Add joi schema for gatsby-cli's structured-errors as well * Fixes unit-test * Use types from redux/types - they seem to be newer than types in gatsby/index.d.ts * consolidate structured errors types into types file to be imported by others * force rebuild Co-authored-by: madalynrose <madalyn@gatsbyjs.com>
- Loading branch information
1 parent
9bc2026
commit 5b35acc
Showing
12 changed files
with
122 additions
and
107 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
packages/gatsby-cli/src/structured-errors/__tests__/error-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 33 additions & 32 deletions
65
packages/gatsby-cli/src/structured-errors/error-schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
import Joi from "@hapi/joi" | ||
import { ILocationPosition, IStructuredError } from "./types" | ||
|
||
const Position = Joi.object().keys({ | ||
export const Position: Joi.ObjectSchema<ILocationPosition> = Joi.object().keys({ | ||
line: Joi.number(), | ||
column: Joi.number(), | ||
}) | ||
|
||
const errorSchema = Joi.object().keys({ | ||
code: Joi.string(), | ||
text: Joi.string(), | ||
stack: Joi.array() | ||
.items( | ||
Joi.object().keys({ | ||
fileName: Joi.string(), | ||
functionName: Joi.string().allow(null), | ||
lineNumber: Joi.number().allow(null), | ||
columnNumber: Joi.number().allow(null), | ||
}) | ||
) | ||
.allow(null), | ||
level: Joi.string().valid([`ERROR`, `WARNING`, `INFO`, `DEBUG`]), | ||
type: Joi.string().valid([`GRAPHQL`, `CONFIG`, `WEBPACK`, `PLUGIN`]), | ||
filePath: Joi.string(), | ||
location: Joi.object({ | ||
start: Position.required(), | ||
end: Position, | ||
}), | ||
docsUrl: Joi.string().uri({ | ||
allowRelative: false, | ||
relativeOnly: false, | ||
}), | ||
error: Joi.object({}).unknown(), | ||
context: Joi.object({}).unknown(), | ||
group: Joi.string(), | ||
panicOnBuild: Joi.boolean(), | ||
}) | ||
|
||
export default errorSchema | ||
export const errorSchema: Joi.ObjectSchema<IStructuredError> = Joi.object().keys( | ||
{ | ||
code: Joi.string(), | ||
text: Joi.string(), | ||
stack: Joi.array() | ||
.items( | ||
Joi.object().keys({ | ||
fileName: Joi.string(), | ||
functionName: Joi.string().allow(null), | ||
lineNumber: Joi.number().allow(null), | ||
columnNumber: Joi.number().allow(null), | ||
}) | ||
) | ||
.allow(null), | ||
level: Joi.string().valid([`ERROR`, `WARNING`, `INFO`, `DEBUG`]), | ||
type: Joi.string().valid([`GRAPHQL`, `CONFIG`, `WEBPACK`, `PLUGIN`]), | ||
filePath: Joi.string(), | ||
location: Joi.object({ | ||
start: Position.required(), | ||
end: Position, | ||
}), | ||
docsUrl: Joi.string().uri({ | ||
allowRelative: false, | ||
relativeOnly: false, | ||
}), | ||
error: Joi.object({}).unknown(), | ||
context: Joi.object({}).unknown(), | ||
group: Joi.string(), | ||
panicOnBuild: Joi.boolean(), | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { IErrorMapEntry, ErrorId } from "./error-map" | ||
|
||
export interface IConstructError { | ||
details: { | ||
id?: ErrorId | ||
context?: Record<string, string> | ||
error?: Error | ||
[key: string]: unknown | ||
} | ||
} | ||
|
||
export interface ILocationPosition { | ||
line: number | ||
column: number | ||
} | ||
|
||
export interface IStructuredError { | ||
code?: string | ||
text: string | ||
stack: { | ||
fileName: string | ||
functionName?: string | ||
lineNumber?: number | ||
columnNumber?: number | ||
}[] | ||
filePath?: string | ||
location?: { | ||
start: ILocationPosition | ||
end?: ILocationPosition | ||
} | ||
error?: unknown | ||
group?: string | ||
level: IErrorMapEntry["level"] | ||
type?: IErrorMapEntry["type"] | ||
docsUrl?: string | ||
} | ||
|
||
export interface IOptionalGraphQLInfoContext { | ||
codeFrame?: string | ||
filePath?: string | ||
urlPath?: string | ||
plugin?: string | ||
} | ||
|
||
export enum Level { | ||
ERROR = `ERROR`, | ||
WARNING = `WARNING`, | ||
INFO = `INFO`, | ||
DEBUG = `DEBUG`, | ||
} | ||
|
||
export enum Type { | ||
GRAPHQL = `GRAPHQL`, | ||
CONFIG = `CONFIG`, | ||
WEBPACK = `WEBPACK`, | ||
PLUGIN = `PLUGIN`, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters