mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/json-to-schema' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
87512fc8a9
6 files changed
+126
-1
No files matched your search
@@ -109,6 +109,7 @@
|
||||
"flatten-anything": "^4.0.1",
|
||||
"fuse.js": "^6.6.2",
|
||||
"hash-wasm": "^4.11.0",
|
||||
"generate-schema": "^2.6.0",
|
||||
"highlight.js": "^11.7.0",
|
||||
"iarna-toml-esm": "^3.0.5",
|
||||
"ibantools": "^4.3.3",
|
||||
|
||||
Generated
+17
-1
@@ -203,6 +203,9 @@ dependencies:
|
||||
fuse.js:
|
||||
specifier: ^6.6.2
|
||||
version: 6.6.2
|
||||
generate-schema:
|
||||
specifier: ^2.6.0
|
||||
version: 2.6.0
|
||||
hash-wasm:
|
||||
specifier: ^4.11.0
|
||||
version: 4.11.0
|
||||
@@ -4951,7 +4954,7 @@ packages:
|
||||
/@vueuse/shared@10.0.0(vue@3.3.4):
|
||||
resolution: {integrity: sha512-Zh3LgJqvUBWVY3SiMvXanTcfAneGbt63QPczBRDNgQ6jd/ehodO9a1lCFzaA6SWJJoI+ugVTjHFYJdoR656DVQ==}
|
||||
dependencies:
|
||||
vue-demi: 0.14.10(vue@3.3.4)
|
||||
vue-demi: 0.14.5(vue@3.3.4)
|
||||
transitivePeerDependencies:
|
||||
- '@vue/composition-api'
|
||||
- vue
|
||||
@@ -7467,6 +7470,14 @@ packages:
|
||||
engines: {node: '>=10'}
|
||||
dev: false
|
||||
|
||||
/generate-schema@2.6.0:
|
||||
resolution: {integrity: sha512-EUBKfJNzT8f91xUk5X5gKtnbdejZeE065UAJ3BCzE8VEbvwKI9Pm5jaWmqVeK1MYc1g5weAVFDTSJzN7ymtTqA==}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
commander: 2.20.3
|
||||
type-of-is: 3.5.1
|
||||
dev: false
|
||||
|
||||
/gensync@1.0.0-beta.2:
|
||||
resolution: {integrity: sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==}
|
||||
engines: {node: '>=6.9.0'}
|
||||
@@ -11447,6 +11458,11 @@ packages:
|
||||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/type-of-is@3.5.1:
|
||||
resolution: {integrity: sha512-SOnx8xygcAh8lvDU2exnK2bomASfNjzB3Qz71s2tw9QnX8fkAo7aC+D0H7FV0HjRKj94CKV2Hi71kVkkO6nOxg==}
|
||||
engines: {node: '>=0.10.5'}
|
||||
dev: false
|
||||
|
||||
/typed-array-buffer@1.0.0:
|
||||
resolution: {integrity: sha512-Y8KTSIglk9OZEr8zywiIHG/kmQ7KWyjseXs1CbSo8vC42w7hg2HgYTxSWwP0+is7bWDc1H+Fo026CpHFwm8tkw==}
|
||||
engines: {node: '>= 0.4'}
|
||||
|
||||
@@ -56,6 +56,7 @@ import { tool as icalParser } from './ical-parser';
|
||||
import { tool as icalGenerator } from './ical-generator';
|
||||
import { tool as imageToCss } from './image-to-css';
|
||||
import { tool as jsonToGo } from './json-to-go';
|
||||
import { tool as jsonToSchema } from './json-to-schema';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -259,6 +260,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
jqTester,
|
||||
jqMemo,
|
||||
jsonpathMemo,
|
||||
jsonToSchema,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
declare module 'generate-schema' {
|
||||
function generic(jsonObject: object);
|
||||
function mongoose(jsonObject: object);
|
||||
function bigquery(jsonObject: object);
|
||||
function json(title: string, jsonObject: object);
|
||||
function mysql(tableName: string, jsonObject: object);
|
||||
function clickhouse(tableName: string, jsonObject: object, dateField: string);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Braces } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Json to Schema',
|
||||
path: '/json-to-schema',
|
||||
description: 'Convert JSON data to JSON Schema, MySQL DDL, Mongoose Schema, Google BigQuery schema or ClickHouse Table Schema',
|
||||
keywords: ['json', 'schema', 'mysql', 'sql', 'ddl', 'mongoose', 'bigquery', 'clickhouse', 'table'],
|
||||
component: () => import('./json-to-schema.vue'),
|
||||
icon: Braces,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import JSON5 from 'json5';
|
||||
import GenerateSchema from 'generate-schema';
|
||||
import { withDefaultOnError } from '../../utils/defaults';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
const formats = [
|
||||
{ value: 'generic', label: 'Generic' },
|
||||
{ value: 'json', label: 'JSON Schema' },
|
||||
{ value: 'mysql', label: 'MySQL Table Schema' },
|
||||
{ value: 'mongoose', label: 'Mongoose Schema' },
|
||||
{ value: 'bigquery', label: 'Google BigQuery schema' },
|
||||
{ value: 'clickhouse', label: 'ClickHouse Table Schema' },
|
||||
];
|
||||
|
||||
const tableName = ref('TableName');
|
||||
const format = useQueryParamOrStorage({ name: 'fmt', storageName: 'json-to-schema:fmt', defaultValue: 'json' });
|
||||
|
||||
function convertJsonToSchema(value: string) {
|
||||
const object = JSON5.parse(value);
|
||||
switch (format.value) {
|
||||
case 'json':
|
||||
return JSON.stringify(GenerateSchema.json(tableName.value, object), null, 2);
|
||||
case 'mysql':
|
||||
return GenerateSchema.mysql(tableName.value, object);
|
||||
case 'mongoose':
|
||||
return JSON.stringify(GenerateSchema.mongoose(object), null, 2);
|
||||
case 'bigquery':
|
||||
return JSON.stringify(GenerateSchema.bigquery(object), null, 2);
|
||||
case 'clickhouse':
|
||||
return JSON.stringify(GenerateSchema.clickhouse(tableName.value, object, 'theDateField'), null, 2);
|
||||
default:
|
||||
return JSON.stringify(GenerateSchema.generic(object), null, 2);
|
||||
}
|
||||
}
|
||||
const transformer = (value: string) => value.trim() === '' ? '' : withDefaultOnError(() => convertJsonToSchema(value), '');
|
||||
const schemaLanguage = computed(() => {
|
||||
switch (format.value) {
|
||||
case 'mysql':
|
||||
return 'sql';
|
||||
case 'mongoose':
|
||||
return 'json';
|
||||
case 'bigquery':
|
||||
return 'json';
|
||||
case 'clickhouse':
|
||||
return 'json';
|
||||
default:
|
||||
return 'json';
|
||||
}
|
||||
});
|
||||
|
||||
const rules: UseValidationRule<string>[] = [
|
||||
{
|
||||
validator: (v: string) => v === '' || JSON5.parse(v),
|
||||
message: 'Provided JSON is not valid.',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-select
|
||||
v-model:value="format"
|
||||
:options="formats"
|
||||
placeholder="Target Schema format"
|
||||
/>
|
||||
<c-input-text
|
||||
v-if="['clickhouse', 'json', 'mysql'].includes(format)"
|
||||
v-model:value="tableName"
|
||||
label="Table Name"
|
||||
placeholder="Table Name"
|
||||
mb-2
|
||||
/>
|
||||
<n-divider />
|
||||
|
||||
<format-transformer
|
||||
input-label="Your JSON"
|
||||
input-placeholder="Paste your JSON here..."
|
||||
output-label="Your schema"
|
||||
:output-language="schemaLanguage"
|
||||
:input-validation-rules="rules"
|
||||
:transformer="transformer"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user