Skip to content

Commit

Permalink
chore: update diagnostic app schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicGBauer committed Sep 9, 2024
1 parent a8bb3d9 commit f7fb98a
Show file tree
Hide file tree
Showing 7 changed files with 676 additions and 236 deletions.
744 changes: 533 additions & 211 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

33 changes: 18 additions & 15 deletions tools/diagnostics-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,36 @@
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"test": "vitest",
"start": "pnpm build && pnpm preview"
},
"dependencies": {
"@powersync/react": "workspace:*",
"@powersync/web": "workspace:*",
"@powersync/service-sync-rules": "0.18.2",
"@journeyapps/wa-sqlite": "^0.3.0",
"@mui/material": "^5.15.12",
"@mui/x-data-grid": "^6.19.6",
"@mui/material": "^5.16.7",
"@mui/x-data-grid": "^6.20.4",
"js-logger": "^1.6.1",
"lodash": "^4.17.21",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3"
"react-router-dom": "^6.26.1"
},
"devDependencies": {
"@swc/core": "~1.6.0",
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.25",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.18",
"@swc/core": "~1.6.13",
"@types/lodash": "^4.17.7",
"@types/node": "^20.16.5",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.20",
"babel-loader": "^9.1.3",
"typescript": "^5.5.3",
"vite": "^5.1.5",
"vite-plugin-pwa": "^0.19.2",
"vite-plugin-top-level-await": "^1.4.1",
"vite-plugin-wasm": "^3.3.0"
"typescript": "^5.5.4",
"vite": "^5.4.3",
"vite-plugin-pwa": "^0.19.8",
"vite-plugin-top-level-await": "^1.4.4",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.0.5"
}
}
6 changes: 3 additions & 3 deletions tools/diagnostics-app/src/library/powersync/AppSchema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { column, Schema, TableV2 } from '@powersync/web';
import { column, Schema, Table } from '@powersync/web';

export const local_bucket_data = new TableV2(
export const local_bucket_data = new Table(
{
total_operations: column.integer,
last_op: column.text,
Expand All @@ -10,7 +10,7 @@ export const local_bucket_data = new TableV2(
{ localOnly: true }
);

export const local_schema = new TableV2(
export const local_schema = new Table(
{
data: column.text
},
Expand Down
35 changes: 28 additions & 7 deletions tools/diagnostics-app/src/library/powersync/JsSchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@ export class JsSchemaGenerator {
generate(schema: Schema): string {
const tables = schema.tables;

return `new Schema([
return `new Schema({
${tables.map((table) => this.generateTable(table.name, table.columns)).join(',\n ')}
])
})
`;
}

private generateTable(name: string, columns: Column[]): string {
return `new Table({
name: '${name}',
columns: [
${columns.map((c) => this.generateColumn(c)).join(',\n ')}
]
})`;
}

private generateColumn(column: Column) {
const t = column.type;
return `new Column({ name: '${column.name}', type: ColumnType.${column.type} })`;
return `${column.name}: column.${column.type?.toLocaleLowerCase()}`;
}
}


// const todos = new Table(
// {
// list_id: column.text,
// created_at: column.text,
// completed_at: column.text,
// description: column.text,
// created_by: column.text,
// completed_by: column.text,
// completed: column.integer
// },
// { indexes: { list: ['list_id'] } }
// );

// const lists = new Table({
// created_at: column.text,
// name: column.text,
// owner_id: column.text
// });

// export const AppSchema = new Schema({
// todos,
// lists
// });
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, it, expect } from 'vitest';
import { JsSchemaGenerator } from '../../../src/library/powersync/JsSchemaGenerator'
import { Schema, Table, Column, ColumnType, column } from '@powersync/web';

describe('JsSchemaGenerator', () => {
const generator = new JsSchemaGenerator();

describe('generate', () => {
it('should generate a schema with multiple tables', () => {
const users = new Table({
id: column.text,
name: column.text,
})
const posts = new Table({
id: column.text,
title: column.text,
content: column.text
})
const schema = new Schema({ users, posts });

const result = generator.generate(schema);

expect(result).toBe(
`new Schema({
new Table({
id: column.text,
name: column.text
}),
new Table({
id: column.text,
title: column.text,
content: column.text
})
})
`
);
});
});

describe('generateTable', () => {
it('should generate a table with columns', () => {
const columns = [
new Column({ name: 'id', type: ColumnType.TEXT }),
new Column({ name: 'age', type: ColumnType.INTEGER }),
];

const result = (generator as any).generateTable('users', columns);

expect(result).toBe(
`new Table({
id: column.text,
age: column.integer
})`
);
});
});

describe('generateColumn', () => {
it('should generate a column', () => {
const column = new Column({ name: 'email', type: ColumnType.TEXT });

const result = (generator as any).generateColumn(column);

expect(result).toBe('email: column.text');
});
});
});
22 changes: 22 additions & 0 deletions tools/diagnostics-app/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"baseUrl": "./",
"esModuleInterop": true,
"jsx": "react",
"rootDir": "../",
"composite": true,
"outDir": "./lib",
"lib": ["esnext", "DOM"],
"module": "esnext",
"sourceMap": true,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noStrictGenericChecks": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"target": "esnext"
},
"include": ["../src/**/*"]
}
5 changes: 5 additions & 0 deletions tools/diagnostics-app/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {},
})

0 comments on commit f7fb98a

Please sign in to comment.