-
Notifications
You must be signed in to change notification settings - Fork 175
feat(schema): Add support for Liam Schema format JSON files #3708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a901705
feat(schema): Add support for Liam Schema format JSON files
devin-ai-integration[bot] e4aec27
test(cli): Update tests to include 'liam' in supported formats
devin-ai-integration[bot] 2010001
chore: Add changeset for Liam Schema format support
devin-ai-integration[bot] 623b79f
refactor(schema): Replace try-catch with neverthrow in liam parser
MH4GF 3276e9b
chore changeset
MH4GF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
--- | ||
"@liam-hq/schema": minor | ||
"@liam-hq/cli": patch | ||
--- | ||
|
||
- Add support for Liam Schema format JSON files in ERD page parser | ||
- Liam format requires no conversion - just JSON parsing and validation against schemaSchema | ||
- Users can specify format using `?format=liam` query parameter | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,113 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { aColumn, anEnum, aSchema, aTable } from '../../schema/index.js' | ||
import { processor } from './index.js' | ||
|
||
describe('liam processor', () => { | ||
it('should parse valid Liam Schema JSON correctly', async () => { | ||
const input = JSON.stringify({ | ||
tables: { | ||
users: { | ||
name: 'users', | ||
columns: { | ||
id: { | ||
name: 'id', | ||
type: 'integer', | ||
notNull: true, | ||
default: null, | ||
check: null, | ||
comment: null, | ||
}, | ||
email: { | ||
name: 'email', | ||
type: 'varchar(255)', | ||
notNull: false, | ||
default: null, | ||
check: null, | ||
comment: 'User email address', | ||
}, | ||
}, | ||
indexes: {}, | ||
constraints: {}, | ||
comment: 'Users table', | ||
}, | ||
}, | ||
enums: {}, | ||
extensions: {}, | ||
}) | ||
|
||
const { value, errors } = await processor(input) | ||
|
||
expect(errors).toEqual([]) | ||
expect(value).toEqual( | ||
aSchema({ | ||
tables: { | ||
users: aTable({ | ||
name: 'users', | ||
columns: { | ||
id: aColumn({ | ||
name: 'id', | ||
type: 'integer', | ||
notNull: true, | ||
comment: null, | ||
}), | ||
email: aColumn({ | ||
name: 'email', | ||
type: 'varchar(255)', | ||
notNull: false, | ||
comment: 'User email address', | ||
}), | ||
}, | ||
comment: 'Users table', | ||
}), | ||
}, | ||
}), | ||
) | ||
}) | ||
|
||
it('should handle schema with enums', async () => { | ||
const input = JSON.stringify({ | ||
tables: {}, | ||
enums: { | ||
status: { | ||
name: 'status', | ||
values: ['active', 'inactive'], | ||
comment: null, | ||
}, | ||
}, | ||
extensions: {}, | ||
}) | ||
|
||
const { value, errors } = await processor(input) | ||
|
||
expect(errors).toEqual([]) | ||
expect(value.enums).toEqual({ | ||
status: anEnum({ | ||
name: 'status', | ||
values: ['active', 'inactive'], | ||
comment: null, | ||
}), | ||
}) | ||
}) | ||
|
||
it('should return error for invalid JSON', async () => { | ||
const input = 'invalid json{' | ||
|
||
const { value, errors } = await processor(input) | ||
|
||
expect(errors.length).toBeGreaterThan(0) | ||
expect(value).toEqual({ tables: {}, enums: {}, extensions: {} }) | ||
}) | ||
|
||
it('should return error for invalid schema structure', async () => { | ||
const input = JSON.stringify({ | ||
tables: 'not an object', | ||
enums: {}, | ||
extensions: {}, | ||
}) | ||
|
||
const { value, errors } = await processor(input) | ||
|
||
expect(errors.length).toBeGreaterThan(0) | ||
expect(value).toEqual({ tables: {}, enums: {}, extensions: {} }) | ||
}) | ||
}) |
This file contains hidden or 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,37 @@ | ||
import { err, ok, Result } from 'neverthrow' | ||
import * as v from 'valibot' | ||
import { schemaSchema } from '../../schema/index.js' | ||
import type { ProcessResult } from '../types.js' | ||
|
||
const parseJson = Result.fromThrowable( | ||
(s: string) => JSON.parse(s), | ||
(error) => | ||
error instanceof Error ? error : new Error('Failed to parse JSON'), | ||
) | ||
|
||
const parseSchema = ( | ||
data: unknown, | ||
): Result<v.InferOutput<typeof schemaSchema>, Error> => { | ||
const result = v.safeParse(schemaSchema, data) | ||
if (result.success) { | ||
return ok(result.output) | ||
} | ||
const errorMessage = result.issues.map((issue) => issue.message).join(', ') | ||
return err(new Error(`Invalid Liam Schema format: ${errorMessage}`)) | ||
} | ||
|
||
export const processor = async (str: string): Promise<ProcessResult> => { | ||
const result = parseJson(str).andThen(parseSchema) | ||
|
||
if (result.isOk()) { | ||
return { | ||
value: result.value, | ||
errors: [], | ||
} | ||
} | ||
|
||
return { | ||
value: { tables: {}, enums: {}, extensions: {} }, | ||
errors: [result.error], | ||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.