@feathersjs/generators 5.0.0-pre.35
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.
- package/CHANGELOG.md +10 -0
- package/LICENSE +22 -0
- package/README.md +23 -0
- package/lib/app/index.d.ts +29 -0
- package/lib/app/index.js +146 -0
- package/lib/app/index.js.map +1 -0
- package/lib/app/index.ts +228 -0
- package/lib/app/static/.gitignore +121 -0
- package/lib/app/templates/app.test.tpl.d.ts +2 -0
- package/lib/app/templates/app.test.tpl.js +49 -0
- package/lib/app/templates/app.test.tpl.js.map +1 -0
- package/lib/app/templates/app.test.tpl.ts +50 -0
- package/lib/app/templates/app.tpl.d.ts +2 -0
- package/lib/app/templates/app.tpl.js +123 -0
- package/lib/app/templates/app.tpl.js.map +1 -0
- package/lib/app/templates/app.tpl.ts +138 -0
- package/lib/app/templates/channels.tpl.d.ts +2 -0
- package/lib/app/templates/channels.tpl.js +50 -0
- package/lib/app/templates/channels.tpl.js.map +1 -0
- package/lib/app/templates/channels.tpl.ts +56 -0
- package/lib/app/templates/client.test.tpl.d.ts +2 -0
- package/lib/app/templates/client.test.tpl.js +27 -0
- package/lib/app/templates/client.test.tpl.js.map +1 -0
- package/lib/app/templates/client.test.tpl.ts +26 -0
- package/lib/app/templates/client.tpl.d.ts +2 -0
- package/lib/app/templates/client.tpl.js +38 -0
- package/lib/app/templates/client.tpl.js.map +1 -0
- package/lib/app/templates/client.tpl.ts +45 -0
- package/lib/app/templates/configuration.tpl.d.ts +2 -0
- package/lib/app/templates/configuration.tpl.js +71 -0
- package/lib/app/templates/configuration.tpl.js.map +1 -0
- package/lib/app/templates/configuration.tpl.ts +82 -0
- package/lib/app/templates/declarations.tpl.d.ts +2 -0
- package/lib/app/templates/declarations.tpl.js +28 -0
- package/lib/app/templates/declarations.tpl.js.map +1 -0
- package/lib/app/templates/declarations.tpl.ts +37 -0
- package/lib/app/templates/index.html.tpl.d.ts +2 -0
- package/lib/app/templates/index.html.tpl.js +45 -0
- package/lib/app/templates/index.html.tpl.js.map +1 -0
- package/lib/app/templates/index.html.tpl.ts +44 -0
- package/lib/app/templates/index.tpl.d.ts +2 -0
- package/lib/app/templates/index.tpl.js +22 -0
- package/lib/app/templates/index.tpl.js.map +1 -0
- package/lib/app/templates/index.tpl.ts +26 -0
- package/lib/app/templates/logger.tpl.d.ts +3 -0
- package/lib/app/templates/logger.tpl.js +45 -0
- package/lib/app/templates/logger.tpl.js.map +1 -0
- package/lib/app/templates/logger.tpl.ts +56 -0
- package/lib/app/templates/package.json.tpl.d.ts +2 -0
- package/lib/app/templates/package.json.tpl.js +58 -0
- package/lib/app/templates/package.json.tpl.js.map +1 -0
- package/lib/app/templates/package.json.tpl.ts +71 -0
- package/lib/app/templates/prettierrc.tpl.d.ts +2 -0
- package/lib/app/templates/prettierrc.tpl.js +11 -0
- package/lib/app/templates/prettierrc.tpl.js.map +1 -0
- package/lib/app/templates/prettierrc.tpl.ts +14 -0
- package/lib/app/templates/readme.md.tpl.d.ts +2 -0
- package/lib/app/templates/readme.md.tpl.js +54 -0
- package/lib/app/templates/readme.md.tpl.js.map +1 -0
- package/lib/app/templates/readme.md.tpl.ts +57 -0
- package/lib/app/templates/services.tpl.d.ts +2 -0
- package/lib/app/templates/services.tpl.js +15 -0
- package/lib/app/templates/services.tpl.js.map +1 -0
- package/lib/app/templates/services.tpl.ts +20 -0
- package/lib/app/templates/tsconfig.json.tpl.d.ts +2 -0
- package/lib/app/templates/tsconfig.json.tpl.js +22 -0
- package/lib/app/templates/tsconfig.json.tpl.js.map +1 -0
- package/lib/app/templates/tsconfig.json.tpl.ts +28 -0
- package/lib/app/templates/validators.tpl.d.ts +2 -0
- package/lib/app/templates/validators.tpl.js +36 -0
- package/lib/app/templates/validators.tpl.js.map +1 -0
- package/lib/app/templates/validators.tpl.ts +40 -0
- package/lib/authentication/index.d.ts +73 -0
- package/lib/authentication/index.js +107 -0
- package/lib/authentication/index.js.map +1 -0
- package/lib/authentication/index.ts +126 -0
- package/lib/authentication/templates/authentication.tpl.d.ts +2 -0
- package/lib/authentication/templates/authentication.tpl.js +40 -0
- package/lib/authentication/templates/authentication.tpl.js.map +1 -0
- package/lib/authentication/templates/authentication.tpl.ts +51 -0
- package/lib/authentication/templates/client.test.tpl.d.ts +2 -0
- package/lib/authentication/templates/client.test.tpl.js +62 -0
- package/lib/authentication/templates/client.test.tpl.js.map +1 -0
- package/lib/authentication/templates/client.test.tpl.ts +74 -0
- package/lib/authentication/templates/config.tpl.d.ts +2 -0
- package/lib/authentication/templates/config.tpl.js +50 -0
- package/lib/authentication/templates/config.tpl.js.map +1 -0
- package/lib/authentication/templates/config.tpl.ts +57 -0
- package/lib/authentication/templates/declarations.tpl.d.ts +2 -0
- package/lib/authentication/templates/declarations.tpl.js +19 -0
- package/lib/authentication/templates/declarations.tpl.js.map +1 -0
- package/lib/authentication/templates/declarations.tpl.ts +34 -0
- package/lib/authentication/templates/knex.tpl.d.ts +2 -0
- package/lib/authentication/templates/knex.tpl.js +45 -0
- package/lib/authentication/templates/knex.tpl.js.map +1 -0
- package/lib/authentication/templates/knex.tpl.ts +62 -0
- package/lib/authentication/templates/schema.json.tpl.d.ts +2 -0
- package/lib/authentication/templates/schema.json.tpl.js +103 -0
- package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
- package/lib/authentication/templates/schema.json.tpl.ts +124 -0
- package/lib/authentication/templates/schema.typebox.tpl.d.ts +3 -0
- package/lib/authentication/templates/schema.typebox.tpl.js +86 -0
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/authentication/templates/schema.typebox.tpl.ts +108 -0
- package/lib/commons.d.ts +150 -0
- package/lib/commons.js +198 -0
- package/lib/commons.js.map +1 -0
- package/lib/commons.ts +284 -0
- package/lib/connection/index.d.ts +55 -0
- package/lib/connection/index.js +88 -0
- package/lib/connection/index.js.map +1 -0
- package/lib/connection/index.ts +123 -0
- package/lib/connection/templates/knex.tpl.d.ts +2 -0
- package/lib/connection/templates/knex.tpl.js +48 -0
- package/lib/connection/templates/knex.tpl.js.map +1 -0
- package/lib/connection/templates/knex.tpl.ts +67 -0
- package/lib/connection/templates/mongodb.tpl.d.ts +2 -0
- package/lib/connection/templates/mongodb.tpl.js +34 -0
- package/lib/connection/templates/mongodb.tpl.js.map +1 -0
- package/lib/connection/templates/mongodb.tpl.ts +40 -0
- package/lib/hook/index.d.ts +22 -0
- package/lib/hook/index.js +43 -0
- package/lib/hook/index.js.map +1 -0
- package/lib/hook/index.ts +47 -0
- package/lib/hook/templates/hook.tpl.d.ts +2 -0
- package/lib/hook/templates/hook.tpl.js +22 -0
- package/lib/hook/templates/hook.tpl.js.map +1 -0
- package/lib/hook/templates/hook.tpl.ts +33 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/index.ts +8 -0
- package/lib/service/index.d.ts +64 -0
- package/lib/service/index.js +116 -0
- package/lib/service/index.js.map +1 -0
- package/lib/service/index.ts +191 -0
- package/lib/service/templates/client.tpl.d.ts +2 -0
- package/lib/service/templates/client.tpl.js +30 -0
- package/lib/service/templates/client.tpl.js.map +1 -0
- package/lib/service/templates/client.tpl.ts +56 -0
- package/lib/service/templates/schema.json.tpl.d.ts +2 -0
- package/lib/service/templates/schema.json.tpl.js +83 -0
- package/lib/service/templates/schema.json.tpl.js.map +1 -0
- package/lib/service/templates/schema.json.tpl.ts +98 -0
- package/lib/service/templates/schema.typebox.tpl.d.ts +2 -0
- package/lib/service/templates/schema.typebox.tpl.js +61 -0
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/service/templates/schema.typebox.tpl.ts +76 -0
- package/lib/service/templates/service.tpl.d.ts +3 -0
- package/lib/service/templates/service.tpl.js +112 -0
- package/lib/service/templates/service.tpl.js.map +1 -0
- package/lib/service/templates/service.tpl.ts +152 -0
- package/lib/service/templates/test.tpl.d.ts +2 -0
- package/lib/service/templates/test.tpl.js +25 -0
- package/lib/service/templates/test.tpl.js.map +1 -0
- package/lib/service/templates/test.tpl.ts +33 -0
- package/lib/service/type/custom.tpl.d.ts +3 -0
- package/lib/service/type/custom.tpl.js +98 -0
- package/lib/service/type/custom.tpl.js.map +1 -0
- package/lib/service/type/custom.tpl.ts +109 -0
- package/lib/service/type/knex.tpl.d.ts +3 -0
- package/lib/service/type/knex.tpl.js +71 -0
- package/lib/service/type/knex.tpl.js.map +1 -0
- package/lib/service/type/knex.tpl.ts +92 -0
- package/lib/service/type/mongodb.tpl.d.ts +3 -0
- package/lib/service/type/mongodb.tpl.js +50 -0
- package/lib/service/type/mongodb.tpl.js.map +1 -0
- package/lib/service/type/mongodb.tpl.ts +62 -0
- package/package.json +89 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commons.js","sourceRoot":"","sources":["../src/commons.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAmB;AACnB,+BAA2B;AAE3B,0CAAiD;AACjD,+CAS2B;AAC3B,+CAAgC;AAChC,wDAA+D;AAC/D,gDAAuB;AAER,eAAO,GAAK,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,SAAA;AASxG;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,QAAsB,EAAE,EAAE,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAA9F,QAAA,kBAAkB,sBAA4E;AA8D3G;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CAAC,YAAsB,EAAE,QAA4B,EAAE,EAAE,CAClF,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG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C,UAAU,CAAC,IAAA,WAAI,EAAC,GAAG,SAAS,CAAC,CAAC,CAAA;AAA1E,QAAA,UAAU,cAAgE"}
|
package/lib/commons.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { PackageJson } from 'type-fest'
|
|
4
|
+
import { readFile, writeFile } from 'fs/promises'
|
|
5
|
+
import {
|
|
6
|
+
Callable,
|
|
7
|
+
PinionContext,
|
|
8
|
+
loadJSON,
|
|
9
|
+
fromFile,
|
|
10
|
+
getCallable,
|
|
11
|
+
renderTemplate,
|
|
12
|
+
inject,
|
|
13
|
+
Location
|
|
14
|
+
} from '@feathershq/pinion'
|
|
15
|
+
import * as ts from 'typescript'
|
|
16
|
+
import prettier, { Options as PrettierOptions } from 'prettier'
|
|
17
|
+
import path from 'path'
|
|
18
|
+
|
|
19
|
+
export const { version } = JSON.parse(fs.readFileSync(join(__dirname, '..', 'package.json')).toString())
|
|
20
|
+
|
|
21
|
+
export type DependencyVersions = { [key: string]: string }
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The database types supported by this generator
|
|
25
|
+
*/
|
|
26
|
+
export type DatabaseType = 'mongodb' | 'mysql' | 'postgresql' | 'sqlite' | 'mssql'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns the name of the Feathers database adapter for a supported database type
|
|
30
|
+
*
|
|
31
|
+
* @param database The type of the database
|
|
32
|
+
* @returns The name of the adapter
|
|
33
|
+
*/
|
|
34
|
+
export const getDatabaseAdapter = (database: DatabaseType) => (database === 'mongodb' ? 'mongodb' : 'knex')
|
|
35
|
+
|
|
36
|
+
export type FeathersAppInfo = {
|
|
37
|
+
/**
|
|
38
|
+
* The application language
|
|
39
|
+
*/
|
|
40
|
+
language: 'ts' | 'js'
|
|
41
|
+
/**
|
|
42
|
+
* The main database
|
|
43
|
+
*/
|
|
44
|
+
database: DatabaseType
|
|
45
|
+
/**
|
|
46
|
+
* The package manager used
|
|
47
|
+
*/
|
|
48
|
+
packager: 'yarn' | 'npm'
|
|
49
|
+
/**
|
|
50
|
+
* A list of all chosen transports
|
|
51
|
+
*/
|
|
52
|
+
transports: ('rest' | 'websockets')[]
|
|
53
|
+
/**
|
|
54
|
+
* The HTTP framework used
|
|
55
|
+
*/
|
|
56
|
+
framework: 'koa' | 'express'
|
|
57
|
+
/**
|
|
58
|
+
* The main schema definition format
|
|
59
|
+
*/
|
|
60
|
+
schema: 'typebox' | 'json'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface AppPackageJson extends PackageJson {
|
|
64
|
+
feathers?: FeathersAppInfo
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface FeathersBaseContext extends PinionContext {
|
|
68
|
+
/**
|
|
69
|
+
* Information about the Feathers application (like chosen language, database etc.)
|
|
70
|
+
* usually taken from `package.json`
|
|
71
|
+
*/
|
|
72
|
+
feathers: FeathersAppInfo
|
|
73
|
+
/**
|
|
74
|
+
* The package.json file
|
|
75
|
+
*/
|
|
76
|
+
pkg: AppPackageJson
|
|
77
|
+
/**
|
|
78
|
+
* The folder where source files are put
|
|
79
|
+
*/
|
|
80
|
+
lib: string
|
|
81
|
+
/**
|
|
82
|
+
* The folder where test files are put
|
|
83
|
+
*/
|
|
84
|
+
test: string
|
|
85
|
+
/**
|
|
86
|
+
* The language the app is generated in
|
|
87
|
+
*/
|
|
88
|
+
language: 'js' | 'ts'
|
|
89
|
+
/**
|
|
90
|
+
* A list dependencies that should be installed with a certain version.
|
|
91
|
+
* Used for installing development dependencies during testing.
|
|
92
|
+
*/
|
|
93
|
+
dependencyVersions?: DependencyVersions
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns dependencies with the versions from the context attached (if available)
|
|
98
|
+
*
|
|
99
|
+
* @param dependencies The dependencies to install
|
|
100
|
+
* @param versions The dependency version list
|
|
101
|
+
* @returns A list of dependencies with their versions
|
|
102
|
+
*/
|
|
103
|
+
export const addVersions = (dependencies: string[], versions: DependencyVersions) =>
|
|
104
|
+
dependencies.map((dep) => `${dep}@${versions[dep] ? versions[dep] : 'latest'}`)
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Loads the application package.json and populates information like the library and test directory
|
|
108
|
+
* and Feathers app specific information.
|
|
109
|
+
*
|
|
110
|
+
* @returns The updated context
|
|
111
|
+
*/
|
|
112
|
+
export const initializeBaseContext =
|
|
113
|
+
() =>
|
|
114
|
+
<C extends FeathersBaseContext>(ctx: C) =>
|
|
115
|
+
Promise.resolve(ctx)
|
|
116
|
+
.then(loadJSON(fromFile('package.json'), (pkg) => ({ pkg }), {}))
|
|
117
|
+
.then(
|
|
118
|
+
loadJSON(path.join(__dirname, '..', 'package.json'), (pkg: PackageJson) => ({
|
|
119
|
+
dependencyVersions: {
|
|
120
|
+
...pkg.devDependencies,
|
|
121
|
+
...ctx.dependencyVersions,
|
|
122
|
+
'@feathersjs/cli': version
|
|
123
|
+
}
|
|
124
|
+
}))
|
|
125
|
+
)
|
|
126
|
+
.then((ctx) => ({
|
|
127
|
+
...ctx,
|
|
128
|
+
lib: ctx.pkg?.directories?.lib || 'src',
|
|
129
|
+
test: ctx.pkg?.directories?.test || 'test',
|
|
130
|
+
language: ctx.language || ctx.pkg?.feathers?.language,
|
|
131
|
+
feathers: ctx.pkg?.feathers
|
|
132
|
+
}))
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Checks if the current context contains a valid generated application. This is necesary for most
|
|
136
|
+
* generators (besides the app generator).
|
|
137
|
+
*
|
|
138
|
+
* @param ctx The context to check against
|
|
139
|
+
* @returns Throws an error or returns the original context
|
|
140
|
+
*/
|
|
141
|
+
export const checkPreconditions =
|
|
142
|
+
() =>
|
|
143
|
+
async <T extends FeathersBaseContext>(ctx: T) => {
|
|
144
|
+
if (!ctx.feathers) {
|
|
145
|
+
throw new Error(`Can not run generator since the current folder does not appear to be a Feathers application.
|
|
146
|
+
Either your package.json is missing or it does not have \`feathers\` property.
|
|
147
|
+
`)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return ctx
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const importRegex = /from '(\..*)'/g
|
|
154
|
+
const escapeNewLines = (code: string) => code.replace(/\n\n/g, '\n/* :newline: */')
|
|
155
|
+
const restoreNewLines = (code: string) => code.replace(/\/\* :newline: \*\//g, '\n')
|
|
156
|
+
const fixLocalImports = (code: string) => code.replace(importRegex, "from '$1.js'")
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Returns the transpiled and prettified JavaScript for a TypeScript source code
|
|
160
|
+
*
|
|
161
|
+
* @param typescript The TypeScript source code
|
|
162
|
+
* @param options TypeScript transpilation options
|
|
163
|
+
* @returns The formatted JavaScript source code
|
|
164
|
+
*/
|
|
165
|
+
export const getJavaScript = (typescript: string, options: ts.TranspileOptions = {}) => {
|
|
166
|
+
const source = escapeNewLines(typescript)
|
|
167
|
+
const transpiled = ts.transpileModule(source, {
|
|
168
|
+
...options,
|
|
169
|
+
compilerOptions: {
|
|
170
|
+
module: ts.ModuleKind.ESNext,
|
|
171
|
+
target: ts.ScriptTarget.ES2020,
|
|
172
|
+
preserveValueImports: true,
|
|
173
|
+
...options.compilerOptions
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return fixLocalImports(restoreNewLines(transpiled.outputText))
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const getFileName = async <C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
181
|
+
target: Callable<string, C>,
|
|
182
|
+
ctx: C
|
|
183
|
+
) => `${await getCallable(target, ctx)}.${ctx.language}`
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The default configuration for prettifying files
|
|
187
|
+
*/
|
|
188
|
+
export const PRETTIERRC: PrettierOptions = {
|
|
189
|
+
tabWidth: 2,
|
|
190
|
+
useTabs: false,
|
|
191
|
+
printWidth: 110,
|
|
192
|
+
semi: false,
|
|
193
|
+
trailingComma: 'none',
|
|
194
|
+
singleQuote: true
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/*
|
|
198
|
+
* Format a source file using Prettier. Will use the local configuration, the settings set in
|
|
199
|
+
* `options` or a default configuration
|
|
200
|
+
*
|
|
201
|
+
* @param target The file to prettify
|
|
202
|
+
* @param options The Prettier options
|
|
203
|
+
* @returns The updated context
|
|
204
|
+
*/
|
|
205
|
+
export const prettify =
|
|
206
|
+
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
207
|
+
target: Callable<string, C>,
|
|
208
|
+
options: PrettierOptions = PRETTIERRC
|
|
209
|
+
) =>
|
|
210
|
+
async (ctx: C) => {
|
|
211
|
+
const fileName = await getFileName(target, ctx)
|
|
212
|
+
const config = (await prettier.resolveConfig(ctx.cwd)) || options
|
|
213
|
+
const content = (await readFile(fileName)).toString()
|
|
214
|
+
|
|
215
|
+
try {
|
|
216
|
+
await writeFile(
|
|
217
|
+
fileName,
|
|
218
|
+
await prettier.format(content, {
|
|
219
|
+
parser: ctx.language === 'ts' ? 'typescript' : 'babel',
|
|
220
|
+
...config
|
|
221
|
+
})
|
|
222
|
+
)
|
|
223
|
+
} catch (error: any) {
|
|
224
|
+
throw new Error(`Error prettifying ${fileName}: ${error.message}`)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return ctx
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Render a source file template for the language set in the context.
|
|
232
|
+
*
|
|
233
|
+
* @param templates The JavaScript and TypeScript template to render
|
|
234
|
+
* @param target The target filename without extension (will be added based on language)
|
|
235
|
+
* @returns The updated context
|
|
236
|
+
*/
|
|
237
|
+
export const renderSource =
|
|
238
|
+
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
239
|
+
template: Callable<string, C>,
|
|
240
|
+
target: Callable<string, C>,
|
|
241
|
+
options?: { force: boolean }
|
|
242
|
+
) =>
|
|
243
|
+
async (ctx: C) => {
|
|
244
|
+
const { language } = ctx
|
|
245
|
+
const fileName = await getFileName(target, ctx)
|
|
246
|
+
const content = language === 'js' ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
|
|
247
|
+
const renderer = renderTemplate(content, fileName, options)
|
|
248
|
+
|
|
249
|
+
return renderer(ctx).then(prettify(target))
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Inject a source template as the language set in the context.
|
|
254
|
+
*
|
|
255
|
+
* @param template The source template to render
|
|
256
|
+
* @param location The location to inject the code to. Must use the target language.
|
|
257
|
+
* @param target The target file name
|
|
258
|
+
* @param transpile Set to `false` if the code should not be transpiled to JavaScript
|
|
259
|
+
* @returns
|
|
260
|
+
*/
|
|
261
|
+
export const injectSource =
|
|
262
|
+
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
263
|
+
template: Callable<string, C>,
|
|
264
|
+
location: Location<C>,
|
|
265
|
+
target: Callable<string, C>,
|
|
266
|
+
transpile = true
|
|
267
|
+
) =>
|
|
268
|
+
async (ctx: C) => {
|
|
269
|
+
const { language } = ctx
|
|
270
|
+
const source =
|
|
271
|
+
language === 'js' && transpile ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
|
|
272
|
+
const fileName = await getFileName(target, ctx)
|
|
273
|
+
const injector = inject(source, location, fileName)
|
|
274
|
+
|
|
275
|
+
return injector(ctx).then(prettify(target))
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Synchronously checks if a file exits
|
|
280
|
+
* @param context The base context
|
|
281
|
+
* @param filenames The filenames to check
|
|
282
|
+
* @returns Wether the file exists or not
|
|
283
|
+
*/
|
|
284
|
+
export const fileExists = (...filenames: string[]) => fs.existsSync(join(...filenames))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { FeathersBaseContext, DatabaseType } from '../commons';
|
|
2
|
+
export interface ConnectionGeneratorContext extends FeathersBaseContext {
|
|
3
|
+
name?: string;
|
|
4
|
+
database: DatabaseType;
|
|
5
|
+
connectionString: string;
|
|
6
|
+
dependencies: string[];
|
|
7
|
+
}
|
|
8
|
+
export type ConnectionGeneratorArguments = FeathersBaseContext & Partial<Pick<ConnectionGeneratorContext, 'database' | 'connectionString' | 'name'>>;
|
|
9
|
+
export declare const defaultConnectionString: (type: DatabaseType, name: string) => string;
|
|
10
|
+
export declare const prompts: ({ database, connectionString, pkg, name }: ConnectionGeneratorArguments) => ({
|
|
11
|
+
name: string;
|
|
12
|
+
type: string;
|
|
13
|
+
when: boolean;
|
|
14
|
+
message: string;
|
|
15
|
+
suffix: string;
|
|
16
|
+
choices: {
|
|
17
|
+
value: string;
|
|
18
|
+
name: string;
|
|
19
|
+
}[];
|
|
20
|
+
default?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
when: boolean;
|
|
25
|
+
message: string;
|
|
26
|
+
default: (answers: {
|
|
27
|
+
name?: string;
|
|
28
|
+
database: DatabaseType;
|
|
29
|
+
}) => string;
|
|
30
|
+
suffix?: undefined;
|
|
31
|
+
choices?: undefined;
|
|
32
|
+
})[];
|
|
33
|
+
export declare const DATABASE_CLIENTS: {
|
|
34
|
+
mongodb: string;
|
|
35
|
+
sqlite: string;
|
|
36
|
+
postgresql: string;
|
|
37
|
+
mysql: string;
|
|
38
|
+
mssql: string;
|
|
39
|
+
};
|
|
40
|
+
export declare const getDatabaseClient: (database: DatabaseType) => string;
|
|
41
|
+
export declare const generate: (ctx: ConnectionGeneratorArguments) => Promise<{
|
|
42
|
+
dependencies: string[];
|
|
43
|
+
name?: string;
|
|
44
|
+
database: DatabaseType;
|
|
45
|
+
connectionString: string;
|
|
46
|
+
feathers: import("../commons").FeathersAppInfo;
|
|
47
|
+
pkg: import("../commons").AppPackageJson;
|
|
48
|
+
lib: string;
|
|
49
|
+
test: string;
|
|
50
|
+
language: "ts" | "js";
|
|
51
|
+
dependencyVersions?: import("../commons").DependencyVersions;
|
|
52
|
+
cwd: string;
|
|
53
|
+
_?: (string | number)[];
|
|
54
|
+
pinion: import("@feathershq/pinion").Configuration;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generate = exports.getDatabaseClient = exports.DATABASE_CLIENTS = exports.prompts = exports.defaultConnectionString = void 0;
|
|
7
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const commons_1 = require("../commons");
|
|
10
|
+
const defaultConnectionString = (type, name) => {
|
|
11
|
+
const connectionStrings = {
|
|
12
|
+
mongodb: `mongodb://127.0.0.1:27017/${name}`,
|
|
13
|
+
mysql: `mysql://root:@localhost:3306/${name}`,
|
|
14
|
+
postgresql: `postgres://postgres:@localhost:5432/${name}`,
|
|
15
|
+
sqlite: `${name}.sqlite`,
|
|
16
|
+
mssql: `mssql://root:password@localhost:1433/${name}`
|
|
17
|
+
};
|
|
18
|
+
return connectionStrings[type];
|
|
19
|
+
};
|
|
20
|
+
exports.defaultConnectionString = defaultConnectionString;
|
|
21
|
+
const prompts = ({ database, connectionString, pkg, name }) => [
|
|
22
|
+
{
|
|
23
|
+
name: 'database',
|
|
24
|
+
type: 'list',
|
|
25
|
+
when: !database,
|
|
26
|
+
message: 'Which database are you connecting to?',
|
|
27
|
+
suffix: chalk_1.default.grey(' Other databases can be added at any time'),
|
|
28
|
+
choices: [
|
|
29
|
+
{ value: 'sqlite', name: 'SQLite' },
|
|
30
|
+
{ value: 'mongodb', name: 'MongoDB' },
|
|
31
|
+
{ value: 'postgresql', name: 'PostgreSQL' },
|
|
32
|
+
{ value: 'mysql', name: 'MySQL/MariaDB' },
|
|
33
|
+
{ value: 'mssql', name: 'Microsoft SQL' }
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: 'connectionString',
|
|
38
|
+
type: 'input',
|
|
39
|
+
when: !connectionString,
|
|
40
|
+
message: 'Enter your database connection string',
|
|
41
|
+
default: (answers) => (0, exports.defaultConnectionString)(answers.database, answers.name || name || pkg.name)
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
exports.prompts = prompts;
|
|
45
|
+
exports.DATABASE_CLIENTS = {
|
|
46
|
+
mongodb: 'mongodb',
|
|
47
|
+
sqlite: 'sqlite3',
|
|
48
|
+
postgresql: 'pg',
|
|
49
|
+
mysql: 'mysql',
|
|
50
|
+
mssql: 'mssql'
|
|
51
|
+
};
|
|
52
|
+
const getDatabaseClient = (database) => exports.DATABASE_CLIENTS[database];
|
|
53
|
+
exports.getDatabaseClient = getDatabaseClient;
|
|
54
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
55
|
+
.then((0, commons_1.initializeBaseContext)())
|
|
56
|
+
.then((0, commons_1.checkPreconditions)())
|
|
57
|
+
.then((0, pinion_1.prompt)(exports.prompts))
|
|
58
|
+
.then((0, pinion_1.runGenerator)(__dirname, 'templates', ({ database }) => `${(0, commons_1.getDatabaseAdapter)(database)}.tpl`))
|
|
59
|
+
.then((0, pinion_1.mergeJSON)(({ connectionString, database }) => (0, commons_1.getDatabaseAdapter)(database) === 'knex'
|
|
60
|
+
? {
|
|
61
|
+
[database]: {
|
|
62
|
+
client: (0, exports.getDatabaseClient)(database),
|
|
63
|
+
connection: connectionString,
|
|
64
|
+
...(database === 'sqlite' ? { useNullAsDefault: true } : {})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
: {
|
|
68
|
+
[database]: connectionString
|
|
69
|
+
}, (0, pinion_1.toFile)('config', 'default.json')))
|
|
70
|
+
.then((ctx) => {
|
|
71
|
+
const dependencies = [];
|
|
72
|
+
const adapter = (0, commons_1.getDatabaseAdapter)(ctx.database);
|
|
73
|
+
const dbClient = (0, exports.getDatabaseClient)(ctx.database);
|
|
74
|
+
dependencies.push(`@feathersjs/${adapter}`);
|
|
75
|
+
if (adapter === 'knex') {
|
|
76
|
+
dependencies.push('knex');
|
|
77
|
+
}
|
|
78
|
+
dependencies.push(dbClient);
|
|
79
|
+
if (ctx.dependencies) {
|
|
80
|
+
return {
|
|
81
|
+
...ctx,
|
|
82
|
+
dependencies: [...ctx.dependencies, ...dependencies]
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return (0, pinion_1.install)((0, commons_1.addVersions)(dependencies, ctx.dependencyVersions), false, ctx.feathers.packager)(ctx);
|
|
86
|
+
});
|
|
87
|
+
exports.generate = generate;
|
|
88
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAgG;AAChG,kDAAyB;AACzB,wCAOmB;AAYZ,MAAM,uBAAuB,GAAG,CAAC,IAAkB,EAAE,IAAY,EAAE,EAAE;IAC1E,MAAM,iBAAiB,GAAG;QACxB,OAAO,EAAE,6BAA6B,IAAI,EAAE;QAC5C,KAAK,EAAE,gCAAgC,IAAI,EAAE;QAC7C,UAAU,EAAE,uCAAuC,IAAI,EAAE;QACzD,MAAM,EAAE,GAAG,IAAI,SAAS;QACxB,KAAK,EAAE,wCAAwC,IAAI,EAAE;KACtD,CAAA;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC,CAAA;AAVY,QAAA,uBAAuB,2BAUnC;AAEM,MAAM,OAAO,GAAG,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,IAAI,EAAgC,EAAE,EAAE,CAAC;IAClG;QACE,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,CAAC,QAAQ;QACf,OAAO,EAAE,uCAAuC;QAChD,MA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AA;KACF;IAED,OAAO,IAAA,gBAAO,EACZ,IAAA,qBAAW,EAAC,YAAY,EAAE,GAAG,CAAC,kBAAkB,CAAC,EACjD,KAAK,EACL,GAAG,CAAC,QAAQ,CAAC,QAAQ,CACtB,CAAC,GAAG,CAAC,CAAA;AACR,CAAC,CAAC,CAAA;AAtDO,QAAA,QAAQ,YAsDf"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { generator, runGenerator, prompt, install, mergeJSON, toFile } from '@feathershq/pinion'
|
|
2
|
+
import chalk from 'chalk'
|
|
3
|
+
import {
|
|
4
|
+
FeathersBaseContext,
|
|
5
|
+
DatabaseType,
|
|
6
|
+
getDatabaseAdapter,
|
|
7
|
+
addVersions,
|
|
8
|
+
checkPreconditions,
|
|
9
|
+
initializeBaseContext
|
|
10
|
+
} from '../commons'
|
|
11
|
+
|
|
12
|
+
export interface ConnectionGeneratorContext extends FeathersBaseContext {
|
|
13
|
+
name?: string
|
|
14
|
+
database: DatabaseType
|
|
15
|
+
connectionString: string
|
|
16
|
+
dependencies: string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ConnectionGeneratorArguments = FeathersBaseContext &
|
|
20
|
+
Partial<Pick<ConnectionGeneratorContext, 'database' | 'connectionString' | 'name'>>
|
|
21
|
+
|
|
22
|
+
export const defaultConnectionString = (type: DatabaseType, name: string) => {
|
|
23
|
+
const connectionStrings = {
|
|
24
|
+
mongodb: `mongodb://127.0.0.1:27017/${name}`,
|
|
25
|
+
mysql: `mysql://root:@localhost:3306/${name}`,
|
|
26
|
+
postgresql: `postgres://postgres:@localhost:5432/${name}`,
|
|
27
|
+
sqlite: `${name}.sqlite`,
|
|
28
|
+
mssql: `mssql://root:password@localhost:1433/${name}`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return connectionStrings[type]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const prompts = ({ database, connectionString, pkg, name }: ConnectionGeneratorArguments) => [
|
|
35
|
+
{
|
|
36
|
+
name: 'database',
|
|
37
|
+
type: 'list',
|
|
38
|
+
when: !database,
|
|
39
|
+
message: 'Which database are you connecting to?',
|
|
40
|
+
suffix: chalk.grey(' Other databases can be added at any time'),
|
|
41
|
+
choices: [
|
|
42
|
+
{ value: 'sqlite', name: 'SQLite' },
|
|
43
|
+
{ value: 'mongodb', name: 'MongoDB' },
|
|
44
|
+
{ value: 'postgresql', name: 'PostgreSQL' },
|
|
45
|
+
{ value: 'mysql', name: 'MySQL/MariaDB' },
|
|
46
|
+
{ value: 'mssql', name: 'Microsoft SQL' }
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: 'connectionString',
|
|
51
|
+
type: 'input',
|
|
52
|
+
when: !connectionString,
|
|
53
|
+
message: 'Enter your database connection string',
|
|
54
|
+
default: (answers: { name?: string; database: DatabaseType }) =>
|
|
55
|
+
defaultConnectionString(answers.database, answers.name || name || pkg.name)
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
export const DATABASE_CLIENTS = {
|
|
60
|
+
mongodb: 'mongodb',
|
|
61
|
+
sqlite: 'sqlite3',
|
|
62
|
+
postgresql: 'pg',
|
|
63
|
+
mysql: 'mysql',
|
|
64
|
+
mssql: 'mssql'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const getDatabaseClient = (database: DatabaseType) => DATABASE_CLIENTS[database]
|
|
68
|
+
|
|
69
|
+
export const generate = (ctx: ConnectionGeneratorArguments) =>
|
|
70
|
+
generator(ctx)
|
|
71
|
+
.then(initializeBaseContext())
|
|
72
|
+
.then(checkPreconditions())
|
|
73
|
+
.then(prompt<ConnectionGeneratorArguments, ConnectionGeneratorContext>(prompts))
|
|
74
|
+
.then(
|
|
75
|
+
runGenerator<ConnectionGeneratorContext>(
|
|
76
|
+
__dirname,
|
|
77
|
+
'templates',
|
|
78
|
+
({ database }) => `${getDatabaseAdapter(database)}.tpl`
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
.then(
|
|
82
|
+
mergeJSON<ConnectionGeneratorContext>(
|
|
83
|
+
({ connectionString, database }) =>
|
|
84
|
+
getDatabaseAdapter(database) === 'knex'
|
|
85
|
+
? {
|
|
86
|
+
[database]: {
|
|
87
|
+
client: getDatabaseClient(database),
|
|
88
|
+
connection: connectionString,
|
|
89
|
+
...(database === 'sqlite' ? { useNullAsDefault: true } : {})
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
: {
|
|
93
|
+
[database]: connectionString
|
|
94
|
+
},
|
|
95
|
+
toFile('config', 'default.json')
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
.then((ctx: ConnectionGeneratorContext) => {
|
|
99
|
+
const dependencies: string[] = []
|
|
100
|
+
const adapter = getDatabaseAdapter(ctx.database)
|
|
101
|
+
const dbClient = getDatabaseClient(ctx.database)
|
|
102
|
+
|
|
103
|
+
dependencies.push(`@feathersjs/${adapter}`)
|
|
104
|
+
|
|
105
|
+
if (adapter === 'knex') {
|
|
106
|
+
dependencies.push('knex')
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
dependencies.push(dbClient)
|
|
110
|
+
|
|
111
|
+
if (ctx.dependencies) {
|
|
112
|
+
return {
|
|
113
|
+
...ctx,
|
|
114
|
+
dependencies: [...ctx.dependencies, ...dependencies]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return install<ConnectionGeneratorContext>(
|
|
119
|
+
addVersions(dependencies, ctx.dependencyVersions),
|
|
120
|
+
false,
|
|
121
|
+
ctx.feathers.packager
|
|
122
|
+
)(ctx)
|
|
123
|
+
})
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
+
const commons_1 = require("../../commons");
|
|
6
|
+
const template = ({ database }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
|
|
7
|
+
import knex from 'knex'
|
|
8
|
+
import type { Knex } from 'knex'
|
|
9
|
+
import type { Application } from './declarations'
|
|
10
|
+
|
|
11
|
+
declare module './declarations' {
|
|
12
|
+
interface Configuration {
|
|
13
|
+
${database}Client: Knex
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const ${database} = (app: Application) => {
|
|
18
|
+
const config = app.get('${database}')
|
|
19
|
+
const db = knex(config!)
|
|
20
|
+
|
|
21
|
+
app.set('${database}Client', db)
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const knexfile = ({ lib, language, database }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
|
|
25
|
+
import { app } from './${lib}/app'
|
|
26
|
+
|
|
27
|
+
// Load our database connection info from the app configuration
|
|
28
|
+
const config = app.get('${database}')
|
|
29
|
+
|
|
30
|
+
${language === 'js' ? 'export default config' : 'module.exports = config'}
|
|
31
|
+
`;
|
|
32
|
+
const importTemplate = ({ database }) => `import { ${database} } from './${database}'`;
|
|
33
|
+
const configureTemplate = ({ database }) => `app.configure(${database})`;
|
|
34
|
+
const toAppFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'app']);
|
|
35
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
36
|
+
.then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, database }) => [lib, database])))
|
|
37
|
+
.then((0, commons_1.renderSource)(knexfile, (0, pinion_1.toFile)('knexfile')))
|
|
38
|
+
.then((0, pinion_1.mergeJSON)({
|
|
39
|
+
scripts: {
|
|
40
|
+
migrate: 'knex migrate:latest',
|
|
41
|
+
'migrate:make': 'knex migrate:make',
|
|
42
|
+
test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
|
|
43
|
+
}
|
|
44
|
+
}, (0, pinion_1.toFile)('package.json')))
|
|
45
|
+
.then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.before)('import { services } from'), toAppFile))
|
|
46
|
+
.then((0, commons_1.injectSource)(configureTemplate, (0, pinion_1.before)('app.configure(services)'), toAppFile));
|
|
47
|
+
exports.generate = generate;
|
|
48
|
+
//# sourceMappingURL=knex.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAyE;AAEzE,2CAA0D;AAE1D,MAAM,QAAQ,GAAG,CAAC,EAChB,QAAQ,EACmB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;;;MAOrC,QAAQ;;;;eAIC,QAAQ;4BACK,QAAQ;;;aAGvB,QAAQ;;CAEpB,CAAA;AAED,MAAM,QAAQ,GAAG,CAAC,EAChB,GAAG,EACH,QAAQ,EACR,QAAQ,EACmB,EAAE,EAAE,CAAC,QAAQ,CAAC;yBAClB,GAAG;;;0BAGF,QAAQ;;EAEhC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,yBAAyB;CACxE,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAA8B,EAAE,EAAE,CAClE,YAAY,QAAQ,cAAc,QAAQ,GAAG,CAAA;AAC/C,MAAM,iBAAiB,GAAG,CAAC,EAAE,QAAQ,EAA8B,EAAE,EAAE,CAAC,iBAAiB,QAAQ,GAAG,CAAA;AAEpG,MAAM,SAAS,GAAG,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAExE,MAAM,QAAQ,GAAG,CAAC,GAA+B,EAAE,EAAE,CAC1D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,QAAQ,EAA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