-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[L] Add new output options that make use of CST node location data (#84)
Blocked on MrLeebo/prisma-ast#26
- Loading branch information
Showing
30 changed files
with
551 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
model DbUser { | ||
id String @id | ||
fooBar String | ||
@@map(name: "users") | ||
} |
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,3 @@ | ||
import chalk from 'chalk'; | ||
|
||
chalk.level = 2; |
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,14 @@ | ||
import { getTruncatedFileName } from '#src/common/file.js'; | ||
|
||
describe('get truncated file name', () => { | ||
it('returns truncated file name', () => { | ||
const result = getTruncatedFileName('src/common/file.spec.ts'); | ||
expect(result).toBe('src/common/file.spec.ts'); | ||
}); | ||
|
||
it('strips the current cwd', () => { | ||
const cwd = process.cwd(); | ||
const result = getTruncatedFileName(`${cwd}/src/common/file.spec.ts`); | ||
expect(result).toBe('src/common/file.spec.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,8 @@ | ||
import path from 'path'; | ||
|
||
export function getTruncatedFileName(fileName: string) { | ||
const cwd = process.cwd(); | ||
return fileName.includes(cwd) | ||
? path.relative(process.cwd(), fileName) | ||
: fileName; | ||
} |
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 { | ||
PrismaParser, | ||
VisitorClassFactory, | ||
getSchema, | ||
} from '@mrleebo/prisma-ast'; | ||
|
||
export function getPrismaSchema(sourceCode: string) { | ||
const parser = new PrismaParser({ nodeLocationTracking: 'full' }); | ||
const VisitorClass = VisitorClassFactory(parser); | ||
const visitor = new VisitorClass(); | ||
const prismaSchema = getSchema(sourceCode, { parser, visitor }); | ||
return prismaSchema; | ||
} |
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,40 @@ | ||
import { isRegexOrRegexStr, toRegExp } from '#src/common/regex.js'; | ||
|
||
describe('isRegexOrRegexStr', () => { | ||
it('should return true for RegExp instance', () => { | ||
const regex = /[a-z]/; | ||
expect(isRegexOrRegexStr(regex)).toBe(true); | ||
}); | ||
|
||
it('should return true for string representing a regex', () => { | ||
const regexStr = '/[0-9]+/'; | ||
expect(isRegexOrRegexStr(regexStr)).toBe(true); | ||
}); | ||
|
||
it('should return false for other values', () => { | ||
expect(isRegexOrRegexStr('test')).toBe(false); | ||
expect(isRegexOrRegexStr(123)).toBe(false); | ||
expect(isRegexOrRegexStr({})).toBe(false); | ||
expect(isRegexOrRegexStr(null)).toBe(false); | ||
expect(isRegexOrRegexStr(undefined)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('toRegExp', () => { | ||
it('should return the same RegExp instance if passed a RegExp', () => { | ||
const regex = /[a-z]/; | ||
expect(toRegExp(regex)).toBe(regex); | ||
}); | ||
|
||
it('should convert a string representing a regex to a RegExp instance', () => { | ||
const regexStr = '/[0-9]+/'; | ||
const expectedRegExp = new RegExp('[0-9]+'); | ||
expect(toRegExp(regexStr)).toEqual(expectedRegExp); | ||
}); | ||
|
||
it('should create a RegExp from a string', () => { | ||
const stringVal = 'test'; | ||
const expectedRegExp = new RegExp('^test$'); | ||
expect(toRegExp(stringVal)).toEqual(expectedRegExp); | ||
}); | ||
}); |
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
Oops, something went wrong.