Skip to content

Commit 41d3f7f

Browse files
committed
chore: upgrade neostandard
1 parent e70d453 commit 41d3f7f

File tree

21 files changed

+292
-298
lines changed

21 files changed

+292
-298
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"eslint": "^9.4.0",
5656
"fastify-tsconfig": "^2.0.0",
5757
"mysql2": "^3.10.1",
58-
"neostandard": "^0.7.0",
58+
"neostandard": "^0.11.5",
5959
"tap": "^21.0.1",
6060
"typescript": "^5.4.5"
6161
}

src/app.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,49 @@
22
* If you would like to turn your application into a standalone executable, look at server.js file
33
*/
44

5-
import path from "node:path";
6-
import fastifyAutoload from "@fastify/autoload";
7-
import { FastifyInstance, FastifyPluginOptions } from "fastify";
8-
import fastifyVite from "@fastify/vite";
5+
import path from 'node:path'
6+
import fastifyAutoload from '@fastify/autoload'
7+
import { FastifyInstance, FastifyPluginOptions } from 'fastify'
8+
import fastifyVite from '@fastify/vite'
99

1010
export const options = {
1111
ajv: {
1212
customOptions: {
13-
coerceTypes: "array",
14-
removeAdditional: "all"
13+
coerceTypes: 'array',
14+
removeAdditional: 'all'
1515
}
1616
}
17-
};
17+
}
1818

19-
export default async function serviceApp(
19+
export default async function serviceApp (
2020
fastify: FastifyInstance,
2121
opts: FastifyPluginOptions
2222
) {
23-
const { avoidViteRegistration = true } = opts;
23+
const { avoidViteRegistration = true } = opts
2424

2525
// This loads all external plugins defined in plugins/external
2626
// those should be registered first as your custom plugins might depend on them
2727
await fastify.register(fastifyAutoload, {
28-
dir: path.join(import.meta.dirname, "plugins/external"),
28+
dir: path.join(import.meta.dirname, 'plugins/external'),
2929
options: {}
30-
});
30+
})
3131

3232
// This loads all your custom plugins defined in plugins/custom
3333
// those should be support plugins that are reused
3434
// through your application
3535
await fastify.register(fastifyAutoload, {
36-
dir: path.join(import.meta.dirname, "plugins/custom"),
36+
dir: path.join(import.meta.dirname, 'plugins/custom'),
3737
options: {}
38-
});
38+
})
3939

4040
// This loads all plugins defined in routes
4141
// define your routes in one of these
4242
await fastify.register(fastifyAutoload, {
43-
dir: path.join(import.meta.dirname, "routes"),
43+
dir: path.join(import.meta.dirname, 'routes'),
4444
autoHooks: true,
4545
cascadeHooks: true,
4646
options: {}
47-
});
47+
})
4848

4949
fastify.setErrorHandler((err, request, reply) => {
5050
request.log.error(
@@ -57,14 +57,14 @@ export default async function serviceApp(
5757
params: request.params
5858
}
5959
},
60-
"Unhandled error occurred"
61-
);
60+
'Unhandled error occurred'
61+
)
6262

63-
const statusCode = err.statusCode ?? 500;
64-
reply.code(statusCode);
63+
const statusCode = err.statusCode ?? 500
64+
reply.code(statusCode)
6565

66-
return { message: "Internal Server Error" };
67-
});
66+
return { message: 'Internal Server Error' }
67+
})
6868

6969
// An attacker could search for valid URLs if your 404 error handling is not rate limited.
7070
fastify.setNotFoundHandler(
@@ -84,47 +84,47 @@ export default async function serviceApp(
8484
params: request.params
8585
}
8686
},
87-
"Resource not found"
88-
);
87+
'Resource not found'
88+
)
8989

90-
reply.code(404);
90+
reply.code(404)
9191

92-
return { message: "Not Found" };
92+
return { message: 'Not Found' }
9393
}
94-
);
94+
)
9595

9696
await handleVite(fastify, {
9797
register: !avoidViteRegistration
98-
});
98+
})
9999
}
100100

101-
async function handleVite(
101+
async function handleVite (
102102
fastify: FastifyInstance,
103103
{ register }: { register: boolean }
104104
) {
105105
if (!register) {
106106
// Route must match vite "base": https://vitejs.dev/config/shared-options.html#base
107-
fastify.get("/", () => {
108-
return "Vite is not registered.";
109-
});
107+
fastify.get('/', () => {
108+
return 'Vite is not registered.'
109+
})
110110

111-
return;
111+
return
112112
}
113113
/* c8 ignore start - We don't launch the spa tests with the api tests */
114114
// We setup the SPA
115115
await fastify.register(fastifyVite, function (fastify) {
116116
return {
117-
root: path.resolve(import.meta.dirname, "../"),
117+
root: path.resolve(import.meta.dirname, '../'),
118118
dev: fastify.config.FASTIFY_VITE_DEV_MODE,
119119
spa: true
120-
};
121-
});
120+
}
121+
})
122122

123123
// Route must match vite "base": https://vitejs.dev/config/shared-options.html#base
124-
fastify.get("/", (req, reply) => {
125-
return reply.html();
126-
});
124+
fastify.get('/', (req, reply) => {
125+
return reply.html()
126+
})
127127

128-
await fastify.vite.ready();
128+
await fastify.vite.ready()
129129
/* c8 ignore end */
130130
}

src/client/mount.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createRoot } from "react-dom/client";
2-
import { App } from "./App";
1+
import { createRoot } from 'react-dom/client'
2+
import { App } from './App'
33

44
const rootElement =
5-
document.getElementById("root") || document.createElement("div");
5+
document.getElementById('root') || document.createElement('div')
66

7-
const root = createRoot(rootElement);
8-
root.render(<App />);
7+
const root = createRoot(rootElement)
8+
root.render(<App />)

src/plugins/custom/repository.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,96 @@
1-
import { MySQLPromisePool } from "@fastify/mysql";
2-
import { FastifyInstance } from "fastify";
3-
import fp from "fastify-plugin";
4-
import { RowDataPacket, ResultSetHeader } from "mysql2";
1+
import { MySQLPromisePool } from '@fastify/mysql'
2+
import { FastifyInstance } from 'fastify'
3+
import fp from 'fastify-plugin'
4+
import { RowDataPacket, ResultSetHeader } from 'mysql2'
55

6-
declare module "fastify" {
6+
declare module 'fastify' {
77
export interface FastifyInstance {
88
repository: Repository;
99
}
1010
}
1111

12-
export type Repository = MySQLPromisePool & ReturnType<typeof createRepository>;
12+
export type Repository = MySQLPromisePool & ReturnType<typeof createRepository>
1313

14-
type QuerySeparator = 'AND' | ',';
14+
type QuerySeparator = 'AND' | ','
1515

1616
type QueryOptions = {
1717
select?: string;
1818
where?: Record<string, any>;
19-
};
19+
}
2020

2121
type WriteOptions = {
2222
data: Record<string, any>;
2323
where?: Record<string, any>;
24-
};
24+
}
2525

26-
function createRepository(fastify: FastifyInstance) {
26+
function createRepository (fastify: FastifyInstance) {
2727
const processAssignmentRecord = (record: Record<string, any>, separator: QuerySeparator) => {
28-
const keys = Object.keys(record);
29-
const values = Object.values(record);
30-
const clause = keys.map((key) => `${key} = ?`).join(` ${separator} `);
28+
const keys = Object.keys(record)
29+
const values = Object.values(record)
30+
const clause = keys.map((key) => `${key} = ?`).join(` ${separator} `)
3131

32-
return [clause, values] as const;
33-
};
32+
return [clause, values] as const
33+
}
3434

3535
const repository = {
3636
...fastify.mysql,
3737
find: async <T>(table: string, opts: QueryOptions): Promise<T | null> => {
38-
const { select = '*', where = {1:1} } = opts;
39-
const [clause, values] = processAssignmentRecord(where, 'AND');
38+
const { select = '*', where = { 1: 1 } } = opts
39+
const [clause, values] = processAssignmentRecord(where, 'AND')
4040

41-
const query = `SELECT ${select} FROM ${table} WHERE ${clause} LIMIT 1`;
42-
const [rows] = await fastify.mysql.query<RowDataPacket[]>(query, values);
41+
const query = `SELECT ${select} FROM ${table} WHERE ${clause} LIMIT 1`
42+
const [rows] = await fastify.mysql.query<RowDataPacket[]>(query, values)
4343
if (rows.length < 1) {
44-
return null;
44+
return null
4545
}
4646

47-
return rows[0] as T;
47+
return rows[0] as T
4848
},
4949

5050
findMany: async <T>(table: string, opts: QueryOptions = {}): Promise<T[]> => {
51-
const { select = '*', where = {1:1} } = opts;
52-
const [clause, values] = processAssignmentRecord(where, 'AND');
51+
const { select = '*', where = { 1: 1 } } = opts
52+
const [clause, values] = processAssignmentRecord(where, 'AND')
5353

54-
const query = `SELECT ${select} FROM ${table} WHERE ${clause}`;
55-
const [rows] = await fastify.mysql.query<RowDataPacket[]>(query, values);
54+
const query = `SELECT ${select} FROM ${table} WHERE ${clause}`
55+
const [rows] = await fastify.mysql.query<RowDataPacket[]>(query, values)
5656

57-
return rows as T[];
57+
return rows as T[]
5858
},
5959

6060
create: async (table: string, opts: WriteOptions): Promise<number> => {
61-
const { data } = opts;
62-
const columns = Object.keys(data).join(', ');
63-
const placeholders = Object.keys(data).map(() => '?').join(', ');
64-
const values = Object.values(data);
61+
const { data } = opts
62+
const columns = Object.keys(data).join(', ')
63+
const placeholders = Object.keys(data).map(() => '?').join(', ')
64+
const values = Object.values(data)
6565

66-
const query = `INSERT INTO ${table} (${columns}) VALUES (${placeholders})`;
67-
const [result] = await fastify.mysql.query<ResultSetHeader>(query, values);
66+
const query = `INSERT INTO ${table} (${columns}) VALUES (${placeholders})`
67+
const [result] = await fastify.mysql.query<ResultSetHeader>(query, values)
6868

69-
return result.insertId;
69+
return result.insertId
7070
},
7171

7272
update: async (table: string, opts: WriteOptions): Promise<number> => {
73-
const { data, where = {} } = opts;
74-
const [dataClause, dataValues] = processAssignmentRecord(data, ',');
75-
const [whereClause, whereValues] = processAssignmentRecord(where, 'AND');
73+
const { data, where = {} } = opts
74+
const [dataClause, dataValues] = processAssignmentRecord(data, ',')
75+
const [whereClause, whereValues] = processAssignmentRecord(where, 'AND')
7676

77-
const query = `UPDATE ${table} SET ${dataClause} WHERE ${whereClause}`;
78-
const [result] = await fastify.mysql.query<ResultSetHeader>(query, [...dataValues, ...whereValues]);
77+
const query = `UPDATE ${table} SET ${dataClause} WHERE ${whereClause}`
78+
const [result] = await fastify.mysql.query<ResultSetHeader>(query, [...dataValues, ...whereValues])
7979

80-
return result.affectedRows;
80+
return result.affectedRows
8181
},
8282

8383
delete: async (table: string, where: Record<string, any>): Promise<number> => {
84-
const [clause, values] = processAssignmentRecord(where, 'AND');
84+
const [clause, values] = processAssignmentRecord(where, 'AND')
8585

86-
const query = `DELETE FROM ${table} WHERE ${clause}`;
87-
const [result] = await fastify.mysql.query<ResultSetHeader>(query, values);
86+
const query = `DELETE FROM ${table} WHERE ${clause}`
87+
const [result] = await fastify.mysql.query<ResultSetHeader>(query, values)
8888

89-
return result.affectedRows;
89+
return result.affectedRows
9090
}
91-
};
91+
}
9292

93-
return repository;
93+
return repository
9494
}
9595

9696
/**
@@ -101,9 +101,9 @@ function createRepository(fastify: FastifyInstance) {
101101
*/
102102
export default fp(
103103
async function (fastify) {
104-
fastify.decorate("repository", createRepository(fastify));
104+
fastify.decorate('repository', createRepository(fastify))
105105
// You should name your plugins if you want to avoid name collisions
106106
// and/or to perform dependency checks.
107107
},
108-
{ name: "repository", dependencies: ['mysql'] }
109-
);
108+
{ name: 'repository', dependencies: ['mysql'] }
109+
)

0 commit comments

Comments
 (0)