-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generate and export CollectionResponses (#51)
* generate and export CollectionResponses * add workflow badges to readme * add new type to readme
- Loading branch information
Showing
12 changed files
with
153 additions
and
74 deletions.
There are no files selected for viewing
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
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
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
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,33 @@ | ||
import { toPascalCase } from "./utils" | ||
|
||
export function createCollectionEnum(collectionNames: Array<string>): string { | ||
const collections = collectionNames | ||
.map((name) => `\t${toPascalCase(name)} = "${name}",`) | ||
.join("\n") | ||
const typeString = `export enum Collections { | ||
${collections} | ||
}` | ||
return typeString | ||
} | ||
|
||
export function createCollectionRecords( | ||
collectionNames: Array<string> | ||
): string { | ||
const nameRecordMap = collectionNames | ||
.map((name) => `\t${name}: ${toPascalCase(name)}Record`) | ||
.join("\n") | ||
return `export type CollectionRecords = { | ||
${nameRecordMap} | ||
}` | ||
} | ||
|
||
export function createCollectionResponses( | ||
collectionNames: Array<string> | ||
): string { | ||
const nameRecordMap = collectionNames | ||
.map((name) => `\t${name}: ${toPascalCase(name)}Response`) | ||
.join("\n") | ||
return `export type CollectionResponses = { | ||
${nameRecordMap} | ||
}` | ||
} |
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
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
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createCollectionEnum creates enum of collection names 1`] = ` | ||
"export enum Collections { | ||
Book = "book", | ||
Magazine = "magazine", | ||
}" | ||
`; | ||
|
||
exports[`createCollectionRecords creates mapping of collection name to record type 1`] = ` | ||
"export type CollectionRecords = { | ||
book: BookRecord | ||
magazine: MagazineRecord | ||
}" | ||
`; | ||
|
||
exports[`createCollectionResponses creates mapping of collection name to response type 1`] = ` | ||
"export type CollectionResponses = { | ||
book: BookResponse | ||
magazine: MagazineResponse | ||
}" | ||
`; |
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
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
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,26 @@ | ||
import { | ||
createCollectionEnum, | ||
createCollectionRecords, | ||
createCollectionResponses, | ||
} from "../src/collections" | ||
|
||
describe("createCollectionEnum", () => { | ||
it("creates enum of collection names", () => { | ||
const names = ["book", "magazine"] | ||
expect(createCollectionEnum(names)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe("createCollectionRecords", () => { | ||
it("creates mapping of collection name to record type", () => { | ||
const names = ["book", "magazine"] | ||
expect(createCollectionRecords(names)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe("createCollectionResponses", () => { | ||
it("creates mapping of collection name to response type", () => { | ||
const names = ["book", "magazine"] | ||
expect(createCollectionResponses(names)).toMatchSnapshot() | ||
}) | ||
}) |
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
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