faasjs/faasjs

View on GitHub
vscode/faasjs-snippets/snippets/func.code-snippets

Summary

Maintainability
Test Coverage
{
  "useFunc": {
    "description": "Generate a plain useFunc module",
    "prefix": ["uf", "useFunc"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "",
      "export default useFunc(function () {",
      "  return async function () {",
      "    $1",
      "  }",
      "})",
      "",
    ]
  },
  "useFunc with http": {
    "description": "Generate a useFunc module with http",
    "prefix": ["ufh", "useFuncWithHttp"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "import { useHttp } from '@faasjs/http'",
      "",
      "export default useFunc(function () {",
      "  const http = useHttp<{$1}>($2)",
      "",
      "  return async function () {",
      "    $3",
      "  }",
      "})",
      "",
    ]
  },
  "useFunc with knex": {
    "description": "Generate a useFunc module with knex",
    "prefix": ["ufk", "useFuncWithKnex"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "import { useKnex, query } from '@faasjs/knex'",
      "",
      "export default useFunc(function () {",
      "  useKnex()",
      "",
      "  return async function () {",
      "    $1",
      "  }",
      "})",
      "",
    ]
  },
  "useFunc with redis": {
    "description": "Generate a useFunc module with redis",
    "prefix": ["ufk", "useFuncWithRedis"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "import { useRedis, query } from '@faasjs/redis'",
      "",
      "export default useFunc(function () {",
      "  useRedis()",
      "",
      "  return async function () {",
      "    $1",
      "  }",
      "})",
      "",
    ]
  },
  "useFunc with http, knex": {
    "description": "Generate a useFunc module with http and knex",
    "prefix": ["ufhk", "useFuncWithHttpKnex"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "import { useHttp } from '@faasjs/http'",
      "import { useKnex, query } from '@faasjs/knex'",
      "",
      "export default useFunc(function () {",
      "  useKnex()",
      "  const http = useHttp<{$1}>($2)",
      "",
      "  return async function () {",
      "    $3",
      "  }",
      "})",
      "",
    ]
  },
  "useFunc with http, knex and redis": {
    "description": "Generate a useFunc module with http, knex and redis",
    "prefix": ["ufhkr", "useFuncWithHttpKnexRedis"],
    "body": [
      "import { useFunc } from '@faasjs/func'",
      "import { useHttp } from '@faasjs/http'",
      "import { useKnex } from '@faasjs/knex'",
      "import { useRedis } from '@faasjs/redis'",
      "",
      "export default useFunc(function () {",
      "  useKnex()",
      "  useRedis()",
      "  const http = useHttp<{$1}>($2)",
      "",
      "  return async function () {",
      "    $3",
      "  }",
      "})",
      "",
    ]
  },
  "http validator": {
    "description": "Generate a http validator",
    "prefix": ["valid", "httpValidator"],
    "body": [
      "validator: {",
      "  params: {",
      "    rules: {",
      "      $1",
      "    }",
      "  },",
      "  session: {",
      "    rules: {",
      "      $2",
      "    }",
      "  },",
      "}",
      "",
    ]
  },
  "test func": {
    "description": "Test a func",
    "prefix": ["test", "testFunc"],
    "body": [
      "import { test } from '@faasjs/test'",
      "",
      "describe('$1', () => {",
      "  const func = test(__dirname + '/../$2.func').handler",
      "",
      "  it('should work', async () => {",
      "    const res = await func({$3})",
      "",
      "    expect(res).toEqual($4)",
      "  })",
      "})",
      "",
    ]
  },
  "test func with http": {
    "description": "Test a func with http",
    "prefix": ["tfh", "testFuncWithHttp",],
    "body": [
      "import { test } from '@faasjs/test'",
      "",
      "describe('$1', () => {",
      "  const func = test(__dirname + '/../$2.func').JSONhandler",
      "",
      "  it('should work', async () => {",
      "    const { statusCode, data } = await func({$3})",
      "",
      "    expect(statusCode).toEqual($4)",
      "    expect(data).toEqual($5)",
      "  })",
      "})",
      "",
    ]
  },
  "test func with knex": {
    "description": "Test a func with knex",
    "prefix": ["tfk", "testFuncWithKnex",],
    "body": [
      "import { test } from '@faasjs/test'",
      "import { query } from '@faasjs/knex'",
      "",
      "describe('$1', () => {",
      "  const func = test(__dirname + '/../$2.func').handler",
      "",
      "  it('should work', async () => {",
      "    const res = await func({$3})",
      "",
      "    expect(res).toEqual($4)",
      "  })",
      "})",
      "",
    ]
  },
  "test func with http and knex": {
    "description": "Test a func with http and knex",
    "prefix": ["tfht", "testFuncWithHttpKnex",],
    "body": [
      "import { test } from '@faasjs/test'",
      "import { query } from '@faasjs/knex'",
      "",
      "describe('$1', () => {",
      "  const func = test(__dirname + '/../$2.func').JSONhandler",
      "",
      "  it('should work', async () => {",
      "    const { statusCode, data } = await func({$3})",
      "",
      "    expect(statusCode).toEqual($4)",
      "    expect(data).toEqual($5)",
      "  })",
      "})",
      "",
    ]
  }
}