Skip to content

Commit

Permalink
Fix MariaDB issue, allow BigInt serialization #335
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Nov 30, 2024
1 parent 38624ba commit f18f109
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 69 deletions.
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azimutt",
"version": "0.1.34",
"version": "0.1.35",
"description": "Export database schema from relational or document databases. Import it to https://azimutt.app",
"keywords": [
"database",
Expand Down
2 changes: 1 addition & 1 deletion cli/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const version = '0.1.32' // FIXME: `process.env.npm_package_version` is not available :/
export const version = '0.1.35' // FIXME: `process.env.npm_package_version` is not available :/
34 changes: 17 additions & 17 deletions gateway/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions gateway/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azimutt/gateway",
"version": "0.1.21",
"version": "0.1.22",
"description": "A Gateway to proxy database access for Azimutt frontend",
"keywords": [
"database",
Expand Down Expand Up @@ -42,15 +42,15 @@
"dependencies": {
"@azimutt/connector-bigquery": "^0.1.2",
"@azimutt/connector-couchbase": "^0.1.2",
"@azimutt/connector-mariadb": "^0.1.7",
"@azimutt/connector-mariadb": "^0.1.8",
"@azimutt/connector-mongodb": "^0.1.4",
"@azimutt/connector-mysql": "^0.1.5",
"@azimutt/connector-oracle": "^0.1.3",
"@azimutt/connector-postgres": "^0.1.11",
"@azimutt/connector-snowflake": "^0.1.2",
"@azimutt/connector-sqlserver": "^0.1.4",
"@azimutt/models": "^0.1.16",
"@azimutt/utils": "^0.1.7",
"@azimutt/models": "^0.1.17",
"@azimutt/utils": "^0.1.8",
"@fastify/cors": "9.0.1",
"@sinclair/typebox": "0.29.6",
"ajv": "8.17.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/connector-mariadb/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azimutt/connector-mariadb",
"version": "0.1.7",
"version": "0.1.8",
"description": "Connect to MariaDB, extract schema, run analysis and queries",
"keywords": [],
"homepage": "https://azimutt.app",
Expand Down
2 changes: 1 addition & 1 deletion libs/models/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azimutt/models",
"version": "0.1.16",
"version": "0.1.17",
"description": "Define a standard database models for Azimutt.",
"keywords": [],
"homepage": "https://azimutt.app",
Expand Down
4 changes: 2 additions & 2 deletions libs/models/src/zod.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {describe, expect, test} from "@jest/globals";
import {z} from "zod";
import {zodParse} from "./index";
import {zodParse} from "./zod";

describe('zod', () => {
const user = {id: 1, name: 'Loïc', roles: ['admin'], org: {id: 1, name: 'Azimutt', admin: {id: 1, name: 'Loïc'}}, version: 1}
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('zod', () => {
})
test('required', () => {
const {id, ...data} = user
expect(zodParse(User)(data as any).toJson()).toEqual({failure: "Invalid User, at .id: expect 'number' but got 'undefined' (undefined)"})
expect(zodParse(User)(data as any).toJson()).toEqual({failure: "Invalid User, at .id: expect 'number' but got 'undefined' ()"})
})
test('bad type', () => {
const data = {...user, name: 2}
Expand Down
14 changes: 7 additions & 7 deletions libs/models/src/zod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {z, ZodError, ZodIssue, ZodType} from "zod";
import {limitDepth, getValueDeep, groupBy, pluralizeL, Result} from "@azimutt/utils";
import {limitDepth, getValueDeep, groupBy, pluralizeL, Result, stringify} from "@azimutt/utils";

export const zodParse = <T>(typ: ZodType<T>, label?: string) => (value: T): Result<T, string> => {
const res = typ.safeParse(value)
Expand Down Expand Up @@ -40,17 +40,17 @@ function zodIssueToString(issue: ZodIssue, value: any): string {

function zodIssueMessageToString(issue: ZodIssue, value: any): string {
if (issue.code === z.ZodIssueCode.unrecognized_keys) {
return `invalid additional key${issue.keys.length > 1 ? 's:' : ''} ${issue.keys.map(k => `'${k}' (${JSON.stringify(getValueDeep(value, issue.path.concat(k)))})`).join(', ')}`
return `invalid additional key${issue.keys.length > 1 ? 's:' : ''} ${issue.keys.map(k => `'${k}' (${stringify(getValueDeep(value, issue.path.concat(k)))})`).join(', ')}`
} else if (issue.code === z.ZodIssueCode.invalid_type) {
return `expect '${issue.expected}' but got '${issue.received}' (${JSON.stringify(getValueDeep(value, issue.path))})`
return `expect '${issue.expected}' but got '${issue.received}' (${stringify(getValueDeep(value, issue.path))})`
} else if (issue.code === z.ZodIssueCode.invalid_literal) {
return `expect ${JSON.stringify(issue.expected)} but got ${JSON.stringify(getValueDeep(value, issue.path))}`
return `expect ${stringify(issue.expected)} but got ${stringify(getValueDeep(value, issue.path))}`
} else if (issue.code === z.ZodIssueCode.invalid_enum_value) {
return `expect \`${issue.options.map(o => JSON.stringify(o)).join(' | ')}\` but got ${JSON.stringify(getValueDeep(value, issue.path))}`
return `expect \`${issue.options.map(o => stringify(o)).join(' | ')}\` but got ${stringify(getValueDeep(value, issue.path))}`
} else if (issue.code === z.ZodIssueCode.invalid_union_discriminator) {
return `expect \`${issue.options.map(o => JSON.stringify(o)).join(' | ')}\` but got ${JSON.stringify(getValueDeep(value, issue.path))}`
return `expect \`${issue.options.map(o => stringify(o)).join(' | ')}\` but got ${stringify(getValueDeep(value, issue.path))}`
} else if (issue.code === z.ZodIssueCode.invalid_union) {
return `invalid union for ${JSON.stringify(limitDepth(getValueDeep(value, issue.path), 3))}`
return `invalid union for ${stringify(limitDepth(getValueDeep(value, issue.path), 3))}`
} else {
return issue.message
}
Expand Down
2 changes: 1 addition & 1 deletion libs/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azimutt/utils",
"version": "0.1.7",
"version": "0.1.8",
"description": "Define common helpers for all Azimutt projects",
"keywords": [],
"homepage": "https://azimutt.app",
Expand Down
4 changes: 4 additions & 0 deletions libs/utils/src/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ describe('json', () => {
expect(stringify(v, '---')).toEqual(JSON.stringify(v, null, '---') || '')
})
})
test('more permissive than JSON.stringify', () => {
expect(stringify(BigInt('2'))).toEqual('2')
expect(() => JSON.stringify(BigInt('2'))).toThrow(TypeError)
})
test('custom', () => {
const db = {
entities: [{
Expand Down
2 changes: 2 additions & 0 deletions libs/utils/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ function stringifyInner(value: unknown, indent: undefined | number | string | ((
return value ? 'true' : 'false'
} else if (typeof value === 'string' || value instanceof String) {
return JSON.stringify(value) // 🤷 (escaping was not worth coding ^^)
} else if (typeof value === 'bigint') {
return value.toString()
} else if (Array.isArray(value)) {
const {inner, end, depth} = stringifyIndent(indent, path, value, nesting)
const items = value.map((v, i) => {
Expand Down
68 changes: 34 additions & 34 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f18f109

Please sign in to comment.