@feathersjs/generators 5.0.27 → 5.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/lib/app/index.d.ts +3 -3
  3. package/lib/app/index.js +1 -2
  4. package/lib/app/index.js.map +1 -1
  5. package/lib/app/templates/gitignore.tpl.d.ts +5 -0
  6. package/lib/app/{static/.gitignore → templates/gitignore.tpl.js} +5 -1
  7. package/lib/app/templates/gitignore.tpl.js.map +1 -0
  8. package/lib/authentication/index.d.ts +3 -3
  9. package/lib/commons.d.ts +4 -4
  10. package/lib/commons.js +4 -0
  11. package/lib/commons.js.map +1 -1
  12. package/lib/hook/index.d.ts +2 -2
  13. package/package.json +32 -33
  14. package/lib/app/index.ts +0 -215
  15. package/lib/app/templates/app.test.tpl.ts +0 -50
  16. package/lib/app/templates/app.tpl.ts +0 -141
  17. package/lib/app/templates/channels.tpl.ts +0 -54
  18. package/lib/app/templates/client.test.tpl.ts +0 -28
  19. package/lib/app/templates/client.tpl.ts +0 -53
  20. package/lib/app/templates/configuration.tpl.ts +0 -89
  21. package/lib/app/templates/declarations.tpl.ts +0 -42
  22. package/lib/app/templates/index.html.tpl.ts +0 -44
  23. package/lib/app/templates/index.tpl.ts +0 -26
  24. package/lib/app/templates/logger.tpl.ts +0 -56
  25. package/lib/app/templates/package.json.tpl.ts +0 -78
  26. package/lib/app/templates/prettierrc.tpl.ts +0 -14
  27. package/lib/app/templates/readme.md.tpl.ts +0 -57
  28. package/lib/app/templates/services.tpl.ts +0 -20
  29. package/lib/app/templates/tsconfig.json.tpl.ts +0 -29
  30. package/lib/app/templates/validators.tpl.ts +0 -39
  31. package/lib/authentication/index.ts +0 -119
  32. package/lib/authentication/templates/authentication.tpl.ts +0 -52
  33. package/lib/authentication/templates/client.test.tpl.ts +0 -78
  34. package/lib/authentication/templates/config.tpl.ts +0 -60
  35. package/lib/authentication/templates/declarations.tpl.ts +0 -38
  36. package/lib/commons.ts +0 -341
  37. package/lib/connection/index.ts +0 -138
  38. package/lib/connection/templates/knex.tpl.ts +0 -73
  39. package/lib/connection/templates/mongodb.tpl.ts +0 -50
  40. package/lib/hook/index.ts +0 -52
  41. package/lib/hook/templates/hook.tpl.ts +0 -33
  42. package/lib/index.ts +0 -8
  43. package/lib/service/index.ts +0 -214
  44. package/lib/service/templates/client.tpl.ts +0 -33
  45. package/lib/service/templates/schema.json.tpl.ts +0 -143
  46. package/lib/service/templates/schema.typebox.tpl.ts +0 -131
  47. package/lib/service/templates/service.tpl.ts +0 -161
  48. package/lib/service/templates/shared.tpl.ts +0 -64
  49. package/lib/service/templates/test.tpl.ts +0 -33
  50. package/lib/service/type/custom.tpl.ts +0 -112
  51. package/lib/service/type/knex.tpl.ts +0 -105
  52. package/lib/service/type/mongodb.tpl.ts +0 -64
@@ -1,57 +0,0 @@
1
- import { renderTemplate, toFile } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
-
4
- const template = ({ name, description, language, database }: AppGeneratorContext) => /* md */ `# ${name}
5
-
6
- > ${description}
7
-
8
- ## About
9
-
10
- This project uses [Feathers](http://feathersjs.com). An open source framework for building APIs and real-time applications.
11
-
12
- ## Getting Started
13
-
14
- 1. Make sure you have [NodeJS](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed.
15
- 2. Install your dependencies
16
-
17
- \`\`\`
18
- cd path/to/${name}
19
- npm install
20
- \`\`\`
21
-
22
- 3. Start your app
23
-
24
- \`\`\`${
25
- language === 'ts'
26
- ? `
27
- npm run compile # Compile TypeScript source`
28
- : ''
29
- }${
30
- database !== 'mongodb'
31
- ? `
32
- npm run migrate # Run migrations to set up the database`
33
- : ''
34
- }
35
- npm start
36
- \`\`\`
37
-
38
- ## Testing
39
-
40
- Run \`npm test\` and all your tests in the \`test/\` directory will be run.
41
-
42
- ## Scaffolding
43
-
44
- This app comes with a powerful command line interface for Feathers. Here are a few things it can do:
45
-
46
- \`\`\`
47
- $ npx feathers help # Show all commands
48
- $ npx feathers generate service # Generate a new Service
49
- \`\`\`
50
-
51
- ## Help
52
-
53
- For more information on all the things you can do with Feathers visit [docs.feathersjs.com](http://docs.feathersjs.com).
54
- `
55
-
56
- export const generate = (ctx: AppGeneratorContext) =>
57
- Promise.resolve(ctx).then(renderTemplate(template, toFile('readme.md')))
@@ -1,20 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const template =
6
- ({}: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/application.html#configure-functions
7
- import type { Application } from '../declarations'
8
-
9
- export const services = (app: Application) => {
10
- // All services will be registered here
11
- }
12
- `
13
-
14
- export const generate = (ctx: AppGeneratorContext) =>
15
- Promise.resolve(ctx).then(
16
- renderSource(
17
- template,
18
- toFile<AppGeneratorContext>(({ lib }) => lib, 'services', 'index')
19
- )
20
- )
@@ -1,29 +0,0 @@
1
- import { toFile, when, writeJSON } from '@featherscloud/pinion'
2
- import { AppGeneratorContext } from '../index.js'
3
-
4
- export const generate = (ctx: AppGeneratorContext) =>
5
- Promise.resolve(ctx).then(
6
- when<AppGeneratorContext>(
7
- (ctx) => ctx.language === 'ts',
8
- writeJSON<AppGeneratorContext>(
9
- ({ lib }) => ({
10
- 'ts-node': {
11
- files: true
12
- },
13
- compilerOptions: {
14
- target: 'es2020',
15
- module: 'commonjs',
16
- outDir: './lib',
17
- rootDir: `./${lib}`,
18
- declaration: true,
19
- strict: true,
20
- esModuleInterop: true,
21
- sourceMap: true
22
- },
23
- include: [lib],
24
- exclude: ['test']
25
- }),
26
- toFile('tsconfig.json')
27
- )
28
- )
29
- )
@@ -1,39 +0,0 @@
1
- import { toFile } from '@featherscloud/pinion'
2
- import { renderSource } from '../../commons.js'
3
- import { AppGeneratorContext } from '../index.js'
4
-
5
- const validatorTemplate = /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/validators.html
6
- import { Ajv, addFormats } from '@feathersjs/schema'
7
- import type { FormatsPluginOptions } from '@feathersjs/schema'
8
-
9
- const formats: FormatsPluginOptions = [
10
- 'date-time',
11
- 'time',
12
- 'date',
13
- 'email',
14
- 'hostname',
15
- 'ipv4',
16
- 'ipv6',
17
- 'uri',
18
- 'uri-reference',
19
- 'uuid',
20
- 'uri-template',
21
- 'json-pointer',
22
- 'relative-json-pointer',
23
- 'regex'
24
- ]
25
-
26
- export const dataValidator: Ajv = addFormats(new Ajv({}), formats)
27
-
28
- export const queryValidator: Ajv = addFormats(new Ajv({
29
- coerceTypes: true
30
- }), formats)
31
- `
32
-
33
- export const generate = (ctx: AppGeneratorContext) =>
34
- Promise.resolve(ctx).then(
35
- renderSource(
36
- validatorTemplate,
37
- toFile<AppGeneratorContext>(({ lib }) => lib, 'validators')
38
- )
39
- )
@@ -1,119 +0,0 @@
1
- import chalk from 'chalk'
2
- import { dirname } from 'path'
3
- import { runGenerators, prompt } from '@featherscloud/pinion'
4
- import { fileURLToPath } from 'url'
5
- import {
6
- addVersions,
7
- checkPreconditions,
8
- FeathersBaseContext,
9
- initializeBaseContext,
10
- install
11
- } from '../commons.js'
12
- import { generate as serviceGenerator, ServiceGeneratorContext } from '../service/index.js'
13
-
14
- // Set __dirname in es module
15
- const __dirname = dirname(fileURLToPath(import.meta.url))
16
-
17
- export interface AuthenticationGeneratorContext extends ServiceGeneratorContext {
18
- service: string
19
- entity: string
20
- authStrategies: string[]
21
- dependencies: string[]
22
- }
23
-
24
- export type AuthenticationGeneratorArguments = FeathersBaseContext &
25
- Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'path' | 'schema' | 'type'>>
26
-
27
- export const generate = (ctx: AuthenticationGeneratorArguments) =>
28
- Promise.resolve(ctx)
29
- .then(initializeBaseContext())
30
- .then(checkPreconditions())
31
- .then(
32
- prompt((ctx: AuthenticationGeneratorArguments) => [
33
- {
34
- type: 'checkbox',
35
- name: 'authStrategies',
36
- when: !ctx.authStrategies,
37
- message: 'Which authentication methods do you want to use?',
38
- suffix: chalk.grey(' Other methods and providers can be added at any time.'),
39
- choices: [
40
- {
41
- name: 'Email + Password',
42
- value: 'local',
43
- checked: true
44
- },
45
- {
46
- name: 'Google',
47
- value: 'google'
48
- },
49
- {
50
- name: 'Facebook',
51
- value: 'facebook'
52
- },
53
- {
54
- name: 'Twitter',
55
- value: 'twitter'
56
- },
57
- {
58
- name: 'GitHub',
59
- value: 'github'
60
- },
61
- {
62
- name: 'Auth0',
63
- value: 'auth0'
64
- }
65
- ]
66
- },
67
- {
68
- name: 'service',
69
- type: 'input',
70
- when: !ctx.service,
71
- message: 'What is your authentication service name?',
72
- default: 'user'
73
- },
74
- {
75
- name: 'path',
76
- type: 'input',
77
- when: !ctx.path,
78
- message: 'What path should the service be registered on?',
79
- default: 'users'
80
- }
81
- ])
82
- )
83
- .then(async (ctx) => {
84
- const serviceContext = await serviceGenerator({
85
- ...ctx,
86
- name: ctx.service,
87
- isEntityService: true
88
- })
89
-
90
- return {
91
- ...ctx,
92
- entity: ctx.service,
93
- ...serviceContext
94
- }
95
- })
96
- .then(runGenerators(__dirname, 'templates'))
97
- .then((ctx) => ctx as AuthenticationGeneratorContext)
98
- .then((ctx) => {
99
- const dependencies: string[] = []
100
-
101
- dependencies.push('@feathersjs/authentication-oauth')
102
-
103
- if (ctx.authStrategies.includes('local')) {
104
- dependencies.push('@feathersjs/authentication-local')
105
- }
106
-
107
- if (ctx.dependencies) {
108
- return {
109
- ...ctx,
110
- dependencies: [...ctx.dependencies, ...dependencies]
111
- }
112
- }
113
-
114
- return install<AuthenticationGeneratorContext>(
115
- addVersions(dependencies, ctx.dependencyVersions),
116
- false,
117
- ctx.feathers.packager
118
- )(ctx)
119
- })
@@ -1,52 +0,0 @@
1
- import { before, toFile } from '@featherscloud/pinion'
2
- import { injectSource, renderSource } from '../../commons.js'
3
- import { AuthenticationGeneratorContext } from '../index.js'
4
- import { localTemplate, oauthTemplate } from '../../commons.js'
5
-
6
- const template = ({
7
- authStrategies
8
- }: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/authentication.html
9
- import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
10
- ${localTemplate(authStrategies, `import { LocalStrategy } from '@feathersjs/authentication-local'`)}
11
- ${oauthTemplate(authStrategies, `import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'`)}
12
-
13
- import type { Application } from './declarations'
14
-
15
- declare module './declarations' {
16
- interface ServiceTypes {
17
- 'authentication': AuthenticationService
18
- }
19
- }
20
-
21
- export const authentication = (app: Application) => {
22
- const authentication = new AuthenticationService(app)
23
-
24
- authentication.register('jwt', new JWTStrategy())
25
- ${authStrategies
26
- .map(
27
- (strategy) =>
28
- ` authentication.register('${strategy}', ${
29
- strategy === 'local' ? `new LocalStrategy()` : `new OAuthStrategy()`
30
- })`
31
- )
32
- .join('\n')}
33
-
34
- app.use('authentication', authentication)
35
- ${oauthTemplate(authStrategies, `app.configure(oauth())`)}
36
- }
37
- `
38
-
39
- const importTemplate = "import { authentication } from './authentication'"
40
- const configureTemplate = 'app.configure(authentication)'
41
- const toAppFile = toFile<AuthenticationGeneratorContext>(({ lib }) => [lib, 'app'])
42
-
43
- export const generate = (ctx: AuthenticationGeneratorContext) =>
44
- Promise.resolve(ctx)
45
- .then(
46
- renderSource(
47
- template,
48
- toFile<AuthenticationGeneratorContext>(({ lib }) => lib, 'authentication')
49
- )
50
- )
51
- .then(injectSource(importTemplate, before('import { services } from'), toAppFile))
52
- .then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
@@ -1,78 +0,0 @@
1
- import { toFile, when } from '@featherscloud/pinion'
2
- import { fileExists, renderSource } from '../../commons.js'
3
- import { AuthenticationGeneratorContext } from '../index.js'
4
- import { localTemplate } from '../../commons.js'
5
-
6
- const template = ({
7
- authStrategies,
8
- upperName,
9
- type,
10
- lib
11
- }: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/client.test.html
12
- import assert from 'assert'
13
- import axios from 'axios'
14
-
15
- import rest from '@feathersjs/rest-client'
16
- ${localTemplate(authStrategies, `import authenticationClient from '@feathersjs/authentication-client'`)}
17
- import { app } from '../${lib}/app'
18
- import { createClient } from '../${lib}/client'
19
- ${localTemplate(authStrategies, `import type { ${upperName}Data } from '../${lib}/client'`)}
20
-
21
- const port = app.get('port')
22
- const appUrl = \`http://\${app.get('host')}:\${port}\`
23
-
24
- describe('application client tests', () => {
25
- const client = createClient(rest(appUrl).axios(axios))
26
-
27
- before(async () => {
28
- await app.listen(port)
29
- })
30
-
31
- after(async () => {
32
- await app.teardown()
33
- })
34
-
35
- it('initialized the client', () => {
36
- assert.ok(client)
37
- })
38
-
39
- ${localTemplate(
40
- authStrategies,
41
- `
42
- it('creates and authenticates a user with email and password', async () => {
43
- const userData: ${upperName}Data = {
44
- email: 'someone@example.com',
45
- password: 'supersecret'
46
- }
47
-
48
- await client.service('users').create(userData)
49
-
50
- const { user, accessToken } = await client.authenticate({
51
- strategy: 'local',
52
- ...userData
53
- })
54
-
55
- assert.ok(accessToken, 'Created access token for user')
56
- assert.ok(user, 'Includes user in authentication data')
57
- assert.strictEqual(user.password, undefined, 'Password is hidden to clients')
58
-
59
- await client.logout()
60
-
61
- // Remove the test user on the server
62
- await app.service('users').remove(user.${type === 'mongodb' ? '_id' : 'id'})
63
- })`
64
- )}
65
- })
66
- `
67
-
68
- export const generate = (ctx: AuthenticationGeneratorContext) =>
69
- Promise.resolve(ctx).then(
70
- when<AuthenticationGeneratorContext>(
71
- ({ lib, language }) => fileExists(lib, `client.${language}`),
72
- renderSource(
73
- template,
74
- toFile<AuthenticationGeneratorContext>(({ test }) => test, 'client.test'),
75
- { force: true }
76
- )
77
- )
78
- )
@@ -1,60 +0,0 @@
1
- import crypto from 'crypto'
2
- import { toFile, mergeJSON } from '@featherscloud/pinion'
3
- import { AuthenticationGeneratorContext } from '../index.js'
4
-
5
- export const generate = (ctx: AuthenticationGeneratorContext) =>
6
- Promise.resolve(ctx)
7
- .then(
8
- mergeJSON<AuthenticationGeneratorContext>(
9
- ({ authStrategies }) => {
10
- const authentication: any = {
11
- entity: ctx.entity,
12
- service: ctx.path,
13
- secret: crypto.randomBytes(24).toString('base64'),
14
- authStrategies: ['jwt'],
15
- jwtOptions: {
16
- header: {
17
- typ: 'access'
18
- },
19
- audience: 'https://yourdomain.com',
20
- algorithm: 'HS256',
21
- expiresIn: '1d'
22
- }
23
- }
24
-
25
- if (authStrategies.includes('local')) {
26
- authentication.authStrategies.push('local')
27
- authentication.local = {
28
- usernameField: 'email',
29
- passwordField: 'password'
30
- }
31
- }
32
-
33
- const oauthStrategies = authStrategies.filter((name) => name !== 'local')
34
-
35
- if (oauthStrategies.length) {
36
- authentication.oauth = oauthStrategies.reduce((oauth, name) => {
37
- oauth[name] = {
38
- key: '<Client ID>',
39
- secret: '<Client secret>'
40
- }
41
-
42
- return oauth
43
- }, {} as any)
44
- }
45
-
46
- return { authentication }
47
- },
48
- toFile('config', 'default.json')
49
- )
50
- )
51
- .then(
52
- mergeJSON<AuthenticationGeneratorContext>(
53
- {
54
- authentication: {
55
- secret: 'FEATHERS_SECRET'
56
- }
57
- },
58
- toFile('config', 'custom-environment-variables.json')
59
- )
60
- )
@@ -1,38 +0,0 @@
1
- import { inject, before, toFile, when, append } from '@featherscloud/pinion'
2
- import { AuthenticationGeneratorContext } from '../index.js'
3
-
4
- const importTemplate = ({
5
- upperName,
6
- folder,
7
- fileName
8
- }: AuthenticationGeneratorContext) => /* ts */ `import { ${upperName} } from './services/${folder.join(
9
- '/'
10
- )}/${fileName}'
11
- `
12
-
13
- const paramsTemplate = ({
14
- entity,
15
- upperName
16
- }: AuthenticationGeneratorContext) => /* ts */ `// Add the ${entity} as an optional property to all params
17
- declare module '@feathersjs/feathers' {
18
- interface Params {
19
- ${entity}?: ${upperName}
20
- }
21
- }
22
- `
23
-
24
- const toDeclarationFile = toFile<AuthenticationGeneratorContext>(({ lib }) => lib, 'declarations.ts')
25
-
26
- export const generate = (ctx: AuthenticationGeneratorContext) =>
27
- Promise.resolve(ctx)
28
- .then(
29
- when(
30
- (ctx) => ctx.language === 'ts',
31
- inject(
32
- importTemplate,
33
- before(/export \{ NextFunction \}|export type \{ NextFunction \}/),
34
- toDeclarationFile
35
- )
36
- )
37
- )
38
- .then(when((ctx) => ctx.language === 'ts', inject(paramsTemplate, append(), toDeclarationFile)))