-
-
Notifications
You must be signed in to change notification settings - Fork 796
Expand file tree
/
Copy pathmongodb.tpl.ts
More file actions
62 lines (56 loc) · 1.79 KB
/
mongodb.tpl.ts
File metadata and controls
62 lines (56 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { generator, toFile } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { ServiceGeneratorContext } from '../index'
export const template = ({
className,
upperName,
schema,
fileName,
kebabPath,
relative
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.class.html#database-services
import type { Params } from '@feathersjs/feathers'
import { MongoDBService } from \'@feathersjs/mongodb\'
import type { MongoDBAdapterParams, MongoDBAdapterOptions } from \'@feathersjs/mongodb\'
import type { Application } from '${relative}/declarations'
${
schema
? `import type {
${upperName},
${upperName}Data,
${upperName}Patch,
${upperName}Query
} from './${fileName}.schema'
`
: `
export type ${upperName} = any
export type ${upperName}Data = any
export type ${upperName}Patch = any
export type ${upperName}Query = any
`
}
export interface ${upperName}Params extends MongoDBAdapterParams<${upperName}Query> {
}
// By default calls the standard MongoDB adapter service methods but can be customized with your own functionality.
export class ${className}<ServiceParams extends Params = ${upperName}Params>
extends MongoDBService<${upperName}, ${upperName}Data, ServiceParams, ${upperName}Patch> {
}
export const getOptions = (app: Application): MongoDBAdapterOptions => {
return {
paginate: app.get('paginate'),
Model: app.get('mongodbClient').then(db => db.collection('${kebabPath}'))
}
}
`
export const generate = (ctx: ServiceGeneratorContext) =>
generator(ctx).then(
renderSource(
template,
toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
lib,
'services',
...folder,
`${fileName}.class`
])
)
)