Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
env:
browser: true
es2021: true
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
Comment on lines +4 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also want this to extend prettier so that it turns off syntax formatting rules that Prettier handles?

parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: latest
sourceType: module
plugins:
- '@typescript-eslint'
rules:
indent:
- error
- 2
linebreak-style:
- error
- unix
quotes:
- error
- backtick
semi:
- error
- always
6 changes: 0 additions & 6 deletions .husky/pre-commit

This file was deleted.

21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"build": "pnpm -r --filter !playground build",
"build:types": "pnpm -r --filter !playground exec -- tsup --dts-only",
"dev": "pnpm -r --parallel --filter !playground dev",
"lint": "prettier --check --plugin-search-dir=. .",
"lint:fix": "pnpm lint:fix:prettier",
"lint:fix:prettier": "prettier --write --plugin-search-dir=. .",
"lint": "prettier --check --plugin-search-dir=. . && eslint packages/**/src",
"lint:fix": "pnpm lint:fix:prettier && pnpm lint:fix:eslint",
"lint:fix:prettier": "pretty-quick --staged",
"lint:fix:eslint": "eslint packages/**/src --fix && eslint playground/src --fix",
"play": "cd playground && pnpm dev",
"play:build": "pnpm build && cd playground && pnpm build",
"prepublish:ci": "pnpm -r update",
"publish:ci": "esmo scripts/publish.ts",
"release": "esmo scripts/release.ts && git push --follow-tags",
"test": "ava",
"dev:test": "ava --watch --verbose",
"prepare": "husky install"
"dev:test": "ava --watch --verbose"
},
"repository": {
"type": "git",
Expand All @@ -45,14 +45,18 @@
"@ava/typescript": "^3.0.1",
"@nrwl/workspace": "^14.3.6",
"@types/node": "^16.11.42",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"ava": "^4.3.0",
"bumpp": "^7.2.0",
"eslint": "7.32.0",
"esno": "^0.12.1",
"export-size": "^0.5.2",
"husky": "^7.0.4",
"husky": "^8.0.1",
"kleur": "^4.1.5",
"npkill": "^0.8.3",
"prettier": "2.7.1",
"pretty-quick": "^3.1.3",
"ts-node": "^10.8.1",
"tsconfig-paths": "^3.14.1",
"tsup": "^6.1.2",
Expand All @@ -64,5 +68,10 @@
"graphql": "^16.0.1"
}
}
},
"husky": {
"hooks": {
"pre-commit": "lint:fix"
}
}
}
14 changes: 7 additions & 7 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const defineConfig = (config: FlatbreadConfig): FlatbreadConfig =>
export async function loadConfig({ cwd = process.cwd() } = {}): Promise<
ConfigResult<FlatbreadConfig>
> {
const configFilePath = path.join(cwd, 'flatbread.config.js');
const configFilePath = path.join(cwd, `flatbread.config.js`);

const configModule = validateConfigHasExports(
await import(url.pathToFileURL(configFilePath).href)
Expand All @@ -46,13 +46,13 @@ export function validateConfigHasExports<
>(config: unknown | any): C {
const type = typeof config;

if (type === 'undefined') {
if (type === `undefined`) {
throw new Error(
'Your flatbread config is missing default exports. Make sure to include "export default config;"'
`Your flatbread config is missing default exports. Make sure to include "export default config;"`
);
}

if (config.default && typeof config.default !== 'object') {
if (config.default && typeof config.default !== `object`) {
throw new Error(
`Unexpected default export type "${typeof config.default}" in your flatbread config, make sure your default export is an object.`
);
Expand All @@ -71,15 +71,15 @@ export function validateConfigHasExports<
export function validateConfigStructure<C extends FlatbreadConfig>(
config: C
): FlatbreadConfig {
if (typeof config.source !== 'object') {
if (typeof config.source !== `object`) {
throw new Error(
'Your Flatbread config is missing a valid "source" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem'
`Your Flatbread config is missing a valid "source" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem`
);
}

if (!Array.isArray(config.content)) {
throw new Error(
'Your Flatbread config is missing a valid "content" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem'
`Your Flatbread config is missing a valid "content" property. Make sure to include an Flatbread-compatible source plugin, such as @flatbread/source-filesystem`
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ export function createCacheKey(
// This should include serialized node contents to ensure that we don't hit old cache entries
const key = `${nodeType}:${uid}:${attribute}`;

return crypto.createHash('md5').update(key).digest('hex');
return crypto.createHash(`md5`).update(key).digest(`hex`);
}
20 changes: 10 additions & 10 deletions packages/core/src/generators/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export const generateArgsForAllItemQuery = (pluralType: string) => ({
...skip(),
...limit(pluralType),
...order(pluralType, 'ASC'),
...order(pluralType, `ASC`),
...sortBy(pluralType),
...filter(pluralType),
});
Expand All @@ -18,11 +18,11 @@ export const generateArgsForAllItemQuery = (pluralType: string) => ({
*/
export const generateArgsForManyItemQuery = (pluralType: string) => ({
ids: {
type: '[String]',
type: `[String]`,
},
...skip(),
...limit(pluralType),
...order(pluralType, 'ASC'),
...order(pluralType, `ASC`),
...sortBy(pluralType),
});

Expand All @@ -32,7 +32,7 @@ export const generateArgsForManyItemQuery = (pluralType: string) => ({
*/
export const generateArgsForSingleItemQuery = () => ({
id: {
type: 'String',
type: `String`,
},
});

Expand All @@ -41,8 +41,8 @@ export const generateArgsForSingleItemQuery = () => ({
*/
export const skip = () => ({
skip: {
description: 'Skip the first `n` results',
type: 'Int',
description: `Skip the first \`n\` results`,
type: `Int`,
},
});

Expand All @@ -54,7 +54,7 @@ export const skip = () => ({
export const limit = (pluralType: string) => ({
limit: {
description: `The maximum number of ${pluralType} to return`,
type: 'Int',
type: `Int`,
},
});

Expand All @@ -66,7 +66,7 @@ export const limit = (pluralType: string) => ({
*/
export const order = (
pluralType: string,
defaultValue: 'ASC' | 'DESC' = 'ASC'
defaultValue: `ASC` | `DESC` = `ASC`
) => ({
order: {
description: `Which order to return ${pluralType} in`,
Expand All @@ -83,7 +83,7 @@ export const order = (
export const sortBy = (pluralType: string) => ({
sortBy: {
description: `The field to sort ${pluralType} by`,
type: 'String',
type: `String`,
},
});

Expand All @@ -95,6 +95,6 @@ export const sortBy = (pluralType: string) => ({
export const filter = (pluralType: string) => ({
filter: {
description: `Filter ${pluralType} by a JSON object`,
type: 'JSON',
type: `JSON`,
},
});
26 changes: 13 additions & 13 deletions packages/core/src/generators/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface RootQueries {
const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
const { config } = configResult;
if (!config) {
throw new Error('Config is not defined');
throw new Error(`Config is not defined`);
}

// Invoke the content source resolver to retrieve the content nodes
Expand Down Expand Up @@ -61,24 +61,24 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
/**
* @todo potentially able to remove this
**/
let queries: RootQueries = {
const queries: RootQueries = {
maybeReturnsSingleItem: [],
maybeReturnsList: [],
};

// Main builder loop - iterate through each content type and generate query resolvers + relationships for it
for (const [type, schema] of Object.entries(schemaArray)) {
const pluralType = plur(type, 2);
const pluralTypeQueryName = 'all' + pluralType;
const pluralTypeQueryName = `all` + pluralType;

//
/// Global meta fields
//

schema.addFields({
_collection: {
type: 'String',
description: 'The collection name',
type: `String`,
description: `The collection name`,
resolve: () => type,
},
});
Expand All @@ -88,7 +88,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
//

schema.addResolver({
name: 'findById',
name: `findById`,
type: () => schema,
description: `Find one ${type} by its ID`,
args: generateArgsForSingleItemQuery(),
Expand All @@ -99,7 +99,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
});

schema.addResolver({
name: 'findMany',
name: `findMany`,
type: () => [schema],
description: `Find many ${pluralType} by their IDs`,
args: generateArgsForManyItemQuery(pluralType),
Expand All @@ -114,7 +114,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
});

schema.addResolver({
name: 'all',
name: `all`,
args: generateArgsForAllItemQuery(pluralType),
type: () => [schema],
description: `Return a set of ${pluralType}`,
Expand All @@ -128,11 +128,11 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
/**
* Add find by ID to each content type
*/
[type]: schema.getResolver('findById'),
[type]: schema.getResolver(`findById`),
/**
* Add find 'many' to each content type
*/
[pluralTypeQueryName]: schema.getResolver('all'),
[pluralTypeQueryName]: schema.getResolver(`all`),
});

/**
Expand Down Expand Up @@ -163,7 +163,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
String(refType),
2
)} that are referenced by this ${collection}`,
resolver: () => refTypeTC.getResolver('findMany'),
resolver: () => refTypeTC.getResolver(`findMany`),
prepareArgs: {
ids: (source) => source[refField],
},
Expand All @@ -173,7 +173,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
// If the reference field has a single node
typeTC.addRelation(refField, {
description: `The ${refType} referenced by this ${collection}`,
resolver: () => refTypeTC.getResolver('findById'),
resolver: () => refTypeTC.getResolver(`findById`),
prepareArgs: {
id: (source) => source[refField],
},
Expand All @@ -195,7 +195,7 @@ const generateSchema = async (configResult: ConfigResult<FlatbreadConfig>) => {
*/
const fetchPreknownSchemaFragments = (
config: FlatbreadConfig
): Record<string, any> | {} => {
): Record<string, any> => {
if (config.transformer && config.transformer.preknownSchemaFragments) {
return config.transformer.preknownSchemaFragments();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/resolvers/arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const resolveQueryArgs = async (
resolveSortBy(sortBy, nodes);
}

if (order === 'DESC') {
if (order === `DESC`) {
nodes.reverse();
}

Expand All @@ -54,7 +54,7 @@ export const resolveFilter = async (
) => {
// construct custom resolver of nodes to build temp list
const filterSetManifest = generateFilterSetManifest(filter);
console.log('filter manifest', filterSetManifest);
console.log(`filter manifest`, filterSetManifest);

for (const filter of filterSetManifest) {
for (const field of filter.path) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/deepEntries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const deepEntries = (
path: string[] = [],
stack: any[] = []
): [string[], any] => {
if (typeOf(obj) === 'object') {
for (let [key, value] of Object.entries(obj)) {
if (typeOf(obj) === `object`) {
for (const [key, value] of Object.entries(obj)) {
stack = deepEntries(value, [...path, key], stack);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/reduceBooleans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/
const reduceBooleans = (
array: Required<boolean[]>,
unionType: Required<'and' | 'or'>
unionType: Required<`and` | `or`>
): boolean => {
if (unionType === 'and') {
if (unionType === `and`) {
return array.reduce((acc, curr) => acc && curr, true);
} else if (unionType === 'or') {
} else if (unionType === `or`) {
return array.reduce((acc, curr) => acc || curr, false);
}
throw new Error(
Expand Down
Loading