From d8839d243349288bd5c767ce3ab8d8bfee8ccbf9 Mon Sep 17 00:00:00 2001 From: Aryan Singh <114330931+aryanas159@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:42:20 +0530 Subject: [PATCH 1/3] fix: issue #16 --- snippets/snippets-ts.json | 250 +++++++++++++++++++++++++++++++++++++- 1 file changed, 249 insertions(+), 1 deletion(-) diff --git a/snippets/snippets-ts.json b/snippets/snippets-ts.json index 9e26dfe..aedde90 100644 --- a/snippets/snippets-ts.json +++ b/snippets/snippets-ts.json @@ -1 +1,249 @@ -{} \ No newline at end of file +{ + "fastify hello server": { + "scope": "javascript,typescript", + "prefix": "ffhello", + "body": [ + "const app = require('fastify')({ logger: true })", + "app.get('/', async (request, reply) => {", + " return { hello: 'world' }", + "})", + "app.post('/', async (request, reply) => {", + " return request.body", + "})", + "app.listen({ port: 8080 })" + ], + "description": "Create an hello world server" + }, + "fastify register": { + "scope": "javascript,typescript", + "prefix": ["ffregister", "ffplugin"], + "body": [ + "app.register(function plugin (app, opts, next) {", + " next()", + "})" + ], + "description": "Add an empty plugin" + }, + "fastify print routes": { + "scope": "javascript,typescript", + "prefix": "ffprintroutes", + "body": ["app.ready(() => {", " console.log(app.printRoutes())", "})"], + "description": "Print to stdout the routes tree" + }, + "fastify error handler": { + "scope": "javascript,typescript", + "prefix": ["fferrorhandler"], + "body": [ + "app.setErrorHandler(function (error, request, reply) {", + " this.log.error(error)", + " reply.status(500).send({ ok: false })", + "})" + ], + "description": "Add a custom error handler" + }, + "fastify decorate server": { + "scope": "javascript,typescript", + "prefix": ["ffdecorateserver"], + "body": [ + "app.decorate('utility', function () {", + " ${TM_SELECTED_TEXT:${0}}", + "})" + ], + "description": "Add a server decorator" + }, + "fastify decorate request": { + "scope": "javascript,typescript", + "prefix": ["ffdecoraterequest"], + "body": [ + "app.decorateRequest('utility', function () {", + " ${TM_SELECTED_TEXT:${0}}", + "})" + ], + "description": "Add a request decorator" + }, + "fastify decorate reply": { + "scope": "javascript,typescript", + "prefix": ["ffdecoratereply"], + "body": [ + "app.decorateReply('utility', function () {", + " ${TM_SELECTED_TEXT:${0}}", + "})" + ], + "description": "Add a reply decorator" + }, + "fastify hook onRequest": { + "scope": "javascript,typescript", + "prefix": ["ffonrequest", "hookonrequest"], + "body": [ + "app.addHook('onRequest', async function hook (request, reply) {", + " ${TM_SELECTED_TEXT:${0}}", + "})" + ], + "description": "Add an instance fastify onRequest hook" + }, + "fastify hook preParsing": { + "scope": "javascript,typescript", + "prefix": ["ffpreparsing", "hookpreparsing"], + "body": [ + "app.addHook('preParsing', async function hook (request, reply, payload) {", + " const newPayload = $0", + " return newPayload", + "})" + ], + "description": "Add an instance fastify preParsing hook" + }, + "fastify hook preValidation": { + "scope": "javascript,typescript", + "prefix": ["ffprevalidation", "hookprevalidation"], + "body": [ + "app.addHook('preValidation', async function hook (request, reply) {", + " // request's fields are not been validated yet by the JSON Schema", + "})" + ], + "description": "Add an instance fastify preValidation hook" + }, + "fastify hook preHandler": { + "scope": "javascript,typescript", + "prefix": ["ffprehandler", "hookprehandler"], + "body": [ + "app.addHook('preHandler', async function hook (request, reply) {", + " $0", + "})" + ], + "description": "Add an instance fastify preHandler hook" + }, + "fastify hook preSerialization": { + "scope": "javascript,typescript", + "prefix": ["ffpreserialization", "hookpreserialization"], + "body": [ + "app.addHook('preSerialization', async function hook (request, reply, payload) {", + " // the hook is NOT called if the payload is a string, a Buffer, a stream or null.", + " const newPayload = $0", + " return newPayload", + "})" + ], + "description": "Add an instance fastify preSerialization hook" + }, + "fastify hook onError": { + "scope": "javascript,typescript", + "prefix": ["ffonerror", "hookonerror"], + "body": [ + "app.addHook('onError', async function hook (request, reply, error) {", + " // You should not use this hook to update the error", + "})" + ], + "description": "Add an instance fastify onError hook" + }, + "fastify hook onRequestAbort": { + "scope": "javascript,typescript", + "prefix": ["ffonrequestabort", "hookonrequestabort"], + "body": [ + "app.addHook('onRequestAbort', async function hook (request, reply) {", + " // Notice: run when a client closes the connection before. Therefore, you will not be able to send data to the client.", + "})" + ], + "description": "Add an instance fastify onRequestAbort hook" + }, + "fastify hook onSend": { + "scope": "javascript,typescript", + "prefix": ["ffonsend", "hookonsend"], + "body": [ + "app.addHook('onSend', async function hook (request, reply, payload) {", + " // If you change the payload, you may only change it to a string, a Buffer, a stream, or null.", + " const newPayload = $0", + " return newPayload", + "})" + ], + "description": "Add an instance fastify onSend hook" + }, + "fastify hook onResponse": { + "scope": "javascript,typescript", + "prefix": ["ffonresponse", "hookonresponse"], + "body": [ + "app.addHook('onResponse', async function hook (request, reply) {", + " // The onResponse hook is executed when a response has been sent", + "})" + ], + "description": "Add an instance fastify onResponse hook" + }, + "fastify hook onTimeout": { + "scope": "javascript,typescript", + "prefix": ["ffontimeout", "hookontimeout"], + "body": [ + "app.addHook('onTimeout', async function hook (request, reply) {", + " // The onTimeout hook is executed when a request is timed out and the http socket has been hanged up", + "})" + ], + "description": "Add an instance fastify onTimeout hook" + }, + "fastify application hook onReady": { + "scope": "javascript,typescript", + "prefix": ["ffonready", "hookonready"], + "body": ["app.addHook('onReady', async function hook () {", "", "})"], + "description": "Add the fastify onReady application hook" + }, + "fastify application hook preClose": { + "scope": "javascript,typescript", + "prefix": ["ffpreclose", "hookpreclose"], + "body": ["app.addHook('preClose', async function hook () {", "", "})"], + "description": "Add the fastify preClose application hook" + }, + "fastify application hook onClose": { + "scope": "javascript,typescript", + "prefix": ["ffonclose", "hookonclose"], + "body": ["app.addHook('onClose', async function hook (app) {", "", "})"], + "description": "Add the fastify onClose application hook" + }, + "fastify application hook onRoute": { + "scope": "javascript,typescript", + "prefix": ["ffonroute", "hookonroute"], + "body": [ + "app.addHook('onRoute', function hook (routeOptions) {", + " // routeOptions.method", + " // routeOptions.schema", + " // routeOptions.url", + " // routeOptions.path", + " // routeOptions.routePath", + " // routeOptions.bodyLimit", + " // routeOptions.logLevel", + " // routeOptions.logSerializers", + " // routeOptions.prefix", + " // routeOptions[hooksName] to get the hooks array", + "})" + ], + "description": "Add the fastify onRoute application hook" + }, + "fastify application hook onRegister": { + "scope": "javascript,typescript", + "prefix": ["ffonregister", "hookonregister"], + "body": [ + "app.addHook('onRegister', function hook (app, opts) {", + " // The hook will be executed before the registered code", + "})" + ], + "description": "Add the fastify onRegister application hook" + }, + "fastify add schema": { + "scope": "javascript,typescript", + "prefix": ["ffaddschema", "ffsharedschema", "ffjsonschema", "ffschema"], + "body": ["app.addSchema($0)"], + "description": "Add a shared JSON schema to fastify" + }, + "fastify not found handler": { + "scope": "javascript,typescript", + "prefix": ["ffnotfound", "ff404"], + "body": [ + "app.setNotFoundHandler(function basic404(request, reply) {", + " const { url, method } = request.raw", + " const message = `Route ${method}:${url} not found`", + " request.log.info(message)", + " reply.code(404).send({", + " message,", + " error: 'Not Found',", + " statusCode: 404", + " })", + "})" + ], + "description": "Add the default 404 not found handler" + } +} From 14095b6aef1b285a0842f62f0eea15b90769735d Mon Sep 17 00:00:00 2001 From: Aryan Singh <114330931+aryanas159@users.noreply.github.com> Date: Thu, 13 Jul 2023 19:03:08 +0530 Subject: [PATCH 2/3] requested changes Signed-off-by: Aryan Singh <114330931+aryanas159@users.noreply.github.com> --- snippets/snippets-ts.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/snippets/snippets-ts.json b/snippets/snippets-ts.json index aedde90..b637d30 100644 --- a/snippets/snippets-ts.json +++ b/snippets/snippets-ts.json @@ -1,9 +1,10 @@ { "fastify hello server": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": "ffhello", "body": [ - "const app = require('fastify')({ logger: true })", + "import fastify from 'fastify'", + "const app = fastify({ logger: true })", "app.get('/', async (request, reply) => {", " return { hello: 'world' }", "})", From 259621b905084a3fa7cb254294625430c29b4f01 Mon Sep 17 00:00:00 2001 From: Aryan Singh Date: Thu, 20 Jul 2023 10:08:56 +0530 Subject: [PATCH 3/3] changes in scope of snippets-ts.json --- snippets/snippets-ts.json | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/snippets/snippets-ts.json b/snippets/snippets-ts.json index b637d30..e074d10 100644 --- a/snippets/snippets-ts.json +++ b/snippets/snippets-ts.json @@ -16,7 +16,7 @@ "description": "Create an hello world server" }, "fastify register": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffregister", "ffplugin"], "body": [ "app.register(function plugin (app, opts, next) {", @@ -26,13 +26,13 @@ "description": "Add an empty plugin" }, "fastify print routes": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": "ffprintroutes", "body": ["app.ready(() => {", " console.log(app.printRoutes())", "})"], "description": "Print to stdout the routes tree" }, "fastify error handler": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["fferrorhandler"], "body": [ "app.setErrorHandler(function (error, request, reply) {", @@ -43,7 +43,7 @@ "description": "Add a custom error handler" }, "fastify decorate server": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffdecorateserver"], "body": [ "app.decorate('utility', function () {", @@ -53,7 +53,7 @@ "description": "Add a server decorator" }, "fastify decorate request": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffdecoraterequest"], "body": [ "app.decorateRequest('utility', function () {", @@ -63,7 +63,7 @@ "description": "Add a request decorator" }, "fastify decorate reply": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffdecoratereply"], "body": [ "app.decorateReply('utility', function () {", @@ -73,7 +73,7 @@ "description": "Add a reply decorator" }, "fastify hook onRequest": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonrequest", "hookonrequest"], "body": [ "app.addHook('onRequest', async function hook (request, reply) {", @@ -83,7 +83,7 @@ "description": "Add an instance fastify onRequest hook" }, "fastify hook preParsing": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffpreparsing", "hookpreparsing"], "body": [ "app.addHook('preParsing', async function hook (request, reply, payload) {", @@ -94,7 +94,7 @@ "description": "Add an instance fastify preParsing hook" }, "fastify hook preValidation": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffprevalidation", "hookprevalidation"], "body": [ "app.addHook('preValidation', async function hook (request, reply) {", @@ -104,7 +104,7 @@ "description": "Add an instance fastify preValidation hook" }, "fastify hook preHandler": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffprehandler", "hookprehandler"], "body": [ "app.addHook('preHandler', async function hook (request, reply) {", @@ -114,7 +114,7 @@ "description": "Add an instance fastify preHandler hook" }, "fastify hook preSerialization": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffpreserialization", "hookpreserialization"], "body": [ "app.addHook('preSerialization', async function hook (request, reply, payload) {", @@ -126,7 +126,7 @@ "description": "Add an instance fastify preSerialization hook" }, "fastify hook onError": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonerror", "hookonerror"], "body": [ "app.addHook('onError', async function hook (request, reply, error) {", @@ -136,7 +136,7 @@ "description": "Add an instance fastify onError hook" }, "fastify hook onRequestAbort": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonrequestabort", "hookonrequestabort"], "body": [ "app.addHook('onRequestAbort', async function hook (request, reply) {", @@ -146,7 +146,7 @@ "description": "Add an instance fastify onRequestAbort hook" }, "fastify hook onSend": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonsend", "hookonsend"], "body": [ "app.addHook('onSend', async function hook (request, reply, payload) {", @@ -158,7 +158,7 @@ "description": "Add an instance fastify onSend hook" }, "fastify hook onResponse": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonresponse", "hookonresponse"], "body": [ "app.addHook('onResponse', async function hook (request, reply) {", @@ -168,7 +168,7 @@ "description": "Add an instance fastify onResponse hook" }, "fastify hook onTimeout": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffontimeout", "hookontimeout"], "body": [ "app.addHook('onTimeout', async function hook (request, reply) {", @@ -178,25 +178,25 @@ "description": "Add an instance fastify onTimeout hook" }, "fastify application hook onReady": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonready", "hookonready"], "body": ["app.addHook('onReady', async function hook () {", "", "})"], "description": "Add the fastify onReady application hook" }, "fastify application hook preClose": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffpreclose", "hookpreclose"], "body": ["app.addHook('preClose', async function hook () {", "", "})"], "description": "Add the fastify preClose application hook" }, "fastify application hook onClose": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonclose", "hookonclose"], "body": ["app.addHook('onClose', async function hook (app) {", "", "})"], "description": "Add the fastify onClose application hook" }, "fastify application hook onRoute": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonroute", "hookonroute"], "body": [ "app.addHook('onRoute', function hook (routeOptions) {", @@ -215,7 +215,7 @@ "description": "Add the fastify onRoute application hook" }, "fastify application hook onRegister": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffonregister", "hookonregister"], "body": [ "app.addHook('onRegister', function hook (app, opts) {", @@ -225,13 +225,13 @@ "description": "Add the fastify onRegister application hook" }, "fastify add schema": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffaddschema", "ffsharedschema", "ffjsonschema", "ffschema"], "body": ["app.addSchema($0)"], "description": "Add a shared JSON schema to fastify" }, "fastify not found handler": { - "scope": "javascript,typescript", + "scope": "typescript", "prefix": ["ffnotfound", "ff404"], "body": [ "app.setNotFoundHandler(function basic404(request, reply) {",