-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(typescript): correctly dump typescript files when collections nam…
…e are complexe (#653)
- Loading branch information
1 parent
e9e4445
commit 269fc41
Showing
10 changed files
with
157 additions
and
6 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
src/services/dumpers/templates/agent-nodejs/typescript/models/index.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{{#each models as |model|}} | ||
import type { {{capitalise model.collectionName}}Interface } from './{{model.modelFileName}}'; | ||
import type { {{capitalise model.modelName}}Interface } from './{{model.modelFileName}}'; | ||
{{/each}} | ||
|
||
import Mongoose from 'mongoose'; | ||
|
||
{{#each models as |model|}} | ||
import { {{model.collectionName}}Schema } from './{{model.modelFileName}}'; | ||
import { {{model.modelName}}Schema } from './{{model.modelFileName}}'; | ||
{{/each}} | ||
|
||
const connection = Mongoose.createConnection(process.env.DATABASE_URL); | ||
|
||
{{#each models as |model|}} | ||
export const {{model.modelName}} = connection.model<{{capitalise model.collectionName}}Interface>('{{model.modelName}}', {{model.collectionName}}Schema, '{{model.collectionName}}'); | ||
export const {{model.modelName}} = connection.model<{{capitalise model.modelName}}Interface>('{{model.modelName}}', {{model.modelName}}Schema, '{{model.collectionName}}'); | ||
{{/each}} | ||
|
||
export default connection; |
6 changes: 3 additions & 3 deletions
6
src/services/dumpers/templates/agent-nodejs/typescript/models/model.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import Mongoose from 'mongoose'; | ||
|
||
interface {{capitalise collectionName}}Interface { | ||
interface {{capitalise modelName}}Interface { | ||
{{#each fields as |field|}} | ||
{{wsc field.name}}: {{#if (isObject field.type)}}{{>renderNestedInterface type=field.type level=1}}{{else}}{{toInterfaceType field.type}}{{/if}}; | ||
{{/each}} | ||
} | ||
|
||
const {{collectionName}}Schema = new Mongoose.Schema({ | ||
const {{modelName}}Schema = new Mongoose.Schema({ | ||
{{#each fields as |field|}} | ||
{{wsc field.name}}: {{#if field.ref}}{ type: {{field.type}}, ref: '{{field.ref}}' }{{else if (isObject field.type)}}{{>renderNested type=field.type level=1}}{{else}}{{field.type}}{{/if}}, | ||
{{/each}} | ||
}, { | ||
timestamps: {{timestamps}}, | ||
}); | ||
|
||
export { {{capitalise collectionName}}Interface, {{collectionName}}Schema }; | ||
export { {{capitalise modelName}}Interface, {{modelName}}Schema }; |
28 changes: 28 additions & 0 deletions
28
...lyzer/expected/mongo/db-analysis-output/collections-with-special-characters.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"_special:character": { | ||
"fields": [{ | ||
"name": "name", | ||
"type": "String" | ||
}], | ||
"options": { | ||
"timestamps": false | ||
}, | ||
"primaryKeys": [ | ||
"_id" | ||
], | ||
"references": [] | ||
}, | ||
":otherSpecial*character": { | ||
"fields": [{ | ||
"name": "age", | ||
"type": "Number" | ||
}], | ||
"options": { | ||
"timestamps": false | ||
}, | ||
"primaryKeys": [ | ||
"_id" | ||
], | ||
"references": [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...pers/agent-nodejs/expected/javascript/mongo-models/collection-special-characters/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Mongoose = require('mongoose'); | ||
|
||
const connection = Mongoose.createConnection(process.env.DATABASE_URL); | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter((file) => file !== 'index.js') | ||
.forEach((file) => { | ||
try { | ||
const { schema, modelName, collectionName } = require(path.join(__dirname, file)); | ||
connection.model(modelName, schema, collectionName); | ||
} catch (error) { | ||
console.error(`Model creation error: ${error}`); | ||
} | ||
}); | ||
|
||
module.exports = connection; |
13 changes: 13 additions & 0 deletions
13
...javascript/mongo-models/collection-special-characters/other-special-character.expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Mongoose = require('mongoose'); | ||
|
||
const schema = new Mongoose.Schema({ | ||
age: Number, | ||
}, { | ||
timestamps: false, | ||
}); | ||
|
||
module.exports = { | ||
collectionName: ':otherSpecial*character', | ||
modelName: 'otherSpecialCharacter', | ||
schema, | ||
}; |
13 changes: 13 additions & 0 deletions
13
...ected/javascript/mongo-models/collection-special-characters/special-character.expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const Mongoose = require('mongoose'); | ||
|
||
const schema = new Mongoose.Schema({ | ||
name: String, | ||
}, { | ||
timestamps: false, | ||
}); | ||
|
||
module.exports = { | ||
collectionName: '_special:character', | ||
modelName: 'specialCharacter', | ||
schema, | ||
}; |
14 changes: 14 additions & 0 deletions
14
...pers/agent-nodejs/expected/typescript/mongo-models/collection-special-characters/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { OtherSpecialCharacterInterface } from './other-special-character'; | ||
import type { SpecialCharacterInterface } from './special-character'; | ||
|
||
import Mongoose from 'mongoose'; | ||
|
||
import { otherSpecialCharacterSchema } from './other-special-character'; | ||
import { specialCharacterSchema } from './special-character'; | ||
|
||
const connection = Mongoose.createConnection(process.env.DATABASE_URL); | ||
|
||
export const otherSpecialCharacter = connection.model<OtherSpecialCharacterInterface>('otherSpecialCharacter', otherSpecialCharacterSchema, ':otherSpecial*character'); | ||
export const specialCharacter = connection.model<SpecialCharacterInterface>('specialCharacter', specialCharacterSchema, '_special:character'); | ||
|
||
export default connection; |
13 changes: 13 additions & 0 deletions
13
...typescript/mongo-models/collection-special-characters/other-special-character.expected.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Mongoose from 'mongoose'; | ||
|
||
interface OtherSpecialCharacterInterface { | ||
age: number; | ||
} | ||
|
||
const otherSpecialCharacterSchema = new Mongoose.Schema({ | ||
age: Number, | ||
}, { | ||
timestamps: false, | ||
}); | ||
|
||
export { OtherSpecialCharacterInterface, otherSpecialCharacterSchema }; |
13 changes: 13 additions & 0 deletions
13
...ected/typescript/mongo-models/collection-special-characters/special-character.expected.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Mongoose from 'mongoose'; | ||
|
||
interface SpecialCharacterInterface { | ||
name: string; | ||
} | ||
|
||
const specialCharacterSchema = new Mongoose.Schema({ | ||
name: String, | ||
}, { | ||
timestamps: false, | ||
}); | ||
|
||
export { SpecialCharacterInterface, specialCharacterSchema }; |