-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Improve schema types * Remove unused schema types * Refactor schema parser * Add test snapshots * Add more tests and comments * Throw error instead of just logging it * Cover more lines * Cover missing lines * Cover one more missing line * Add new `skipWords` * Remove unused `path` import * Add todo comment * Add test case of generated field IDs * Reduce coverage to `0.99` * Reduce coverage to `0.995` * Improve `error.ts` * Add comment * Apply suggestions from code review Co-authored-by: Ben <[email protected]> * Apply suggestions * Add more test for string utils * Update * Bring back coverage to 1 * Update bunfig.toml * Make types stronger * Update types * Remove non-null assertions * Make use of `Map`s * Update test order --------- Co-authored-by: Ben <[email protected]>
- Loading branch information
Showing
14 changed files
with
1,896 additions
and
544 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import pluralize from 'pluralize'; | ||
|
||
// Advanced fields types exported from 'ronin/schema'. | ||
const ADVANCED_FIELD_TYPES = ['Blob', 'JSON']; | ||
// Basic field types supported in defining schemas. | ||
const BASIC_FIELD_TYPES = ['string', 'number', 'boolean', 'Date']; | ||
|
||
export function createMissingSchemaError(missingSchemas: { name: string; parent: string; source: string }[]) { | ||
return ( | ||
`The following schemas were used as a reference but weren't included in ` + | ||
`the \`Schemas\` interface:\n\n` + | ||
`${missingSchemas | ||
.map(({ name, parent, source }) => ` - \`${name}\` in \`${parent}\` (${source})`) | ||
.join('\n')}\n\n` + | ||
`Please include them in the \`Schemas\` interface or remove their references.` | ||
); | ||
} | ||
|
||
export function createMissingPluralError( | ||
schemaName: string, | ||
schemaSlug: string, | ||
pluralSchemaSlug: string, | ||
schemaRecordsAlias: string, | ||
) { | ||
const pluralTypeName = pluralize(schemaName); | ||
|
||
return ( | ||
`The schema \`${schemaName}\` does not have a plural slug and name defined.\n\n` + | ||
`Please define them in your schema definition file and include them in the \`Schemas\` interface:\n\n` + | ||
`import type * as Schema from 'ronin/schema';\n\n` + | ||
`type ${pluralTypeName} = Schema.${schemaRecordsAlias}<${schemaName}>;\n\n` + | ||
`interface Schemas {\n ${schemaSlug}: ${schemaName};\n ${pluralize(pluralSchemaSlug)}: ${pluralTypeName};\n}` | ||
); | ||
} | ||
|
||
export function createUnknownFieldError( | ||
unknownFields: { parent: string; name: string; type: string; source: string }[], | ||
) { | ||
return ( | ||
`The type of the following fields could not be determined:\n\n` + | ||
`${unknownFields | ||
.map( | ||
({ name, parent, type, source }) => ` - \`${parent}.${name}\` is typed as \`${type}\` (${source})`, | ||
) | ||
.join('\n')}\n\n` + | ||
`Please make sure that the field is typed as any of the available field types:\n\n` + | ||
`${BASIC_FIELD_TYPES.map((type) => ` - \`${type}\``).join('\n')}\n` + | ||
`${ADVANCED_FIELD_TYPES.map((type) => ` - \`Schema.${type}\``).join('\n')}\n` + | ||
` - or a reference to another schema.` | ||
); | ||
} |
Oops, something went wrong.