Skip to content
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

feat: add json validate and version #393

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
- [X] [zhi-env](https://github.com/terwer/zhi/tree/main/libs/zhi-env) ![zhi-env](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-env%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-log](https://github.com/terwer/zhi/tree/main/libs/zhi-log) ![zhi-log](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-log%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-common](https://github.com/terwer/zhi/tree/main/libs/zhi-common) ![zhi-common](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-common-basic](https://github.com/terwer/zhi/tree/main/libs/zhi-common-basic)
- [ ] [zhi-common-json-validate](https://github.com/terwer/zhi/tree/main/libs/zhi-common-json-validate)
- [X] [zhi-common-json-validate](https://github.com/terwer/zhi/tree/main/libs/zhi-common-json-validate) ![zhi-common-json-validate](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-json-validate%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-common-markdown](https://github.com/terwer/zhi/tree/main/libs/zhi-common-markdown) ![zhi-common-markdown](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-markdown%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-common-version](https://github.com/terwer/zhi/tree/main/libs/zhi-common-version)
- [X] [zhi-common-version](https://github.com/terwer/zhi/tree/main/libs/zhi-common-version) ![zhi-common-version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-version%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-infra](https://github.com/terwer/zhi/tree/main/libs/zhi-infra) ![zhi-infra](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-infra%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-cmd](https://github.com/terwer/zhi/tree/main/libs/zhi-cmd) ![zhi-infra](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-cmd%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-blog-api](https://github.com/terwer/zhi/tree/main/libs/zhi-blog-api) ![zhi-blog-api](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-blog-api%2Fpackage.json&query=%24.version&label=release)
Expand All @@ -33,7 +32,7 @@
- [X] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) ![zhi-siyuan-api](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-siyuan-api%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-picgo-core](https://github.com/terwer/zhi/tree/main/libs/zhi-picgo-core) ![zhi-picgo-core](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-picgo-core%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-siyuan-picgo](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-picgo) ![zhi-siyuan-picgo](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-siyuan-picgo%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-chatgpt](https://github.com/terwer/zhi/tree/main/libs/zhi-chatgpt) ![zhi-chatgpt](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-chatgpt%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-chatgpt](https://github.com/terwer/zhi/tree/main/libs/zhi-chatgpt) ![zhi-chatgpt](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-chatgpt%2Fpackage.json&query=%24.version&label=release)

### scaffold && docs

Expand Down
7 changes: 3 additions & 4 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
- [X] [zhi-env](https://github.com/terwer/zhi/tree/main/libs/zhi-env) ![zhi-env](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-env%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-log](https://github.com/terwer/zhi/tree/main/libs/zhi-log) ![zhi-log](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-log%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-common](https://github.com/terwer/zhi/tree/main/libs/zhi-common) ![zhi-common](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-common-basic](https://github.com/terwer/zhi/tree/main/libs/zhi-common-basic)
- [ ] [zhi-common-json-validate](https://github.com/terwer/zhi/tree/main/libs/zhi-common-json-validate)
- [X] [zhi-common-json-validate](https://github.com/terwer/zhi/tree/main/libs/zhi-common-json-validate) ![zhi-common-json-validate](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-json-validate%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-common-markdown](https://github.com/terwer/zhi/tree/main/libs/zhi-common-markdown) ![zhi-common-markdown](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-markdown%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-common-version](https://github.com/terwer/zhi/tree/main/libs/zhi-common-version)
- [X] [zhi-common-version](https://github.com/terwer/zhi/tree/main/libs/zhi-common-version) ![zhi-common-version](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-common-version%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-infra](https://github.com/terwer/zhi/tree/main/libs/zhi-infra) ![zhi-infra](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-infra%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-cmd](https://github.com/terwer/zhi/tree/main/libs/zhi-cmd) ![zhi-infra](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-cmd%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-blog-api](https://github.com/terwer/zhi/tree/main/libs/zhi-blog-api) ![zhi-blog-api](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-blog-api%2Fpackage.json&query=%24.version&label=release)
Expand All @@ -33,7 +32,7 @@
- [X] [zhi-siyuan-api](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-api) ![zhi-siyuan-api](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-siyuan-api%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-picgo-core](https://github.com/terwer/zhi/tree/main/libs/zhi-picgo-core) ![zhi-picgo-core](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-picgo-core%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-siyuan-picgo](https://github.com/terwer/zhi/tree/main/libs/zhi-siyuan-picgo) ![zhi-siyuan-picgo](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-siyuan-picgo%2Fpackage.json&query=%24.version&label=release)
- [ ] [zhi-chatgpt](https://github.com/terwer/zhi/tree/main/libs/zhi-chatgpt) ![zhi-chatgpt](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-chatgpt%2Fpackage.json&query=%24.version&label=release)
- [X] [zhi-chatgpt](https://github.com/terwer/zhi/tree/main/libs/zhi-chatgpt) ![zhi-chatgpt](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fraw.githubusercontent.com%2Fterwer%2Fzhi%2Fmain%2Flibs%2Fzhi-chatgpt%2Fpackage.json&query=%24.version&label=release)

### 脚手架 && 文档

Expand Down
6 changes: 6 additions & 0 deletions libs/zhi-cmd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# zhi-cmd

## 0.2.0

### Minor Changes

- feat: add json validate and version

## 0.1.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions libs/zhi-cmd/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "zhi-cmd",
"version": "0.1.1",
"version": "0.2.0",
"type": "module",
"description": "commond utils for siyuan-note",
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"typings": "./dist/index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/apps/zhi-cmd",
Expand Down
4 changes: 4 additions & 0 deletions libs/zhi-common-json-validate/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["./node_modules/@terwer/eslint-config-custom/typescript/index.cjs"],
}
2 changes: 2 additions & 0 deletions libs/zhi-common-json-validate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.DS_Store
11 changes: 11 additions & 0 deletions libs/zhi-common-json-validate/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# platform

# Ignore artifacts:
dist
node_modules

# Ignore all dts files:
*.d.ts

# lib
/pnpm-lock.yaml
30 changes: 30 additions & 0 deletions libs/zhi-common-json-validate/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

module.exports = {
semi: false,
singleQuote: false,
printWidth: 120
}
7 changes: 7 additions & 0 deletions libs/zhi-common-json-validate/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# zhi-common-json-validate

## 0.1.0

### Minor Changes

- feat: add json validate and version
41 changes: 41 additions & 0 deletions libs/zhi-common-json-validate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# zhi-common-json-validate

utilized for the execution of json schema validation

## Usage

```js
// usage
```

## Deps

```
## Congregations! zhi-common-json-validate need no deps, it is just pure js code 🎉
```

## Dev

```bash
pnpm dev -F zhi-common-json-validate
```

## Build

```bash
pnpm build -F zhi-common-json-validate
```

## Test

Execute the unit tests via [vitest](https://vitest.dev)

```bash
pnpm test -F zhi-common-json-validate
```

## Publish

```bash
pnpm publish -F zhi-common-json-validate --tag latest
```
12 changes: 12 additions & 0 deletions libs/zhi-common-json-validate/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Vue + TS</title>
</head>
<body>
This file is for lib hot-load test only, see <a href="/src/index.ts">/src/index.ts</a>
<script type="module" src="/src/index.ts"></script>
</body>
</html>
37 changes: 37 additions & 0 deletions libs/zhi-common-json-validate/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "zhi-common-json-validate",
"version": "0.1.0",
"type": "module",
"description": "utilized for the execution of json schema validation",
"main": "./dist/index.cjs",
"typings": "./dist/index.d.ts",
"repository": "terwer/zhi",
"homepage": "https://github.com/terwer/zhi/tree/main/libs/zhi-common-json-validate",
"author": "terwer",
"license": "MIT",
"files": [
"dist",
"README.md"
],
"keywords": [
"zhi",
"lib"
],
"scripts": {
"serve": "vite",
"dev": "vite build --watch",
"build": "vite build",
"start": "vite preview",
"test": "npx vitest --watch"
},
"devDependencies": {
"@terwer/eslint-config-custom": "workspace:*",
"@terwer/vite-config-custom": "workspace:*"
},
"dependencies": {
"ajv": "^8.12.0"
},
"publishConfig": {
"access": "public"
}
}
7 changes: 7 additions & 0 deletions libs/zhi-common-json-validate/src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it } from "vitest"

describe("index", () => {
it("test index", () => {
console.log("hello")
})
})
2 changes: 2 additions & 0 deletions libs/zhi-common-json-validate/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import JsonValidateUtil from "./lib/jsonValidateUtil"
export { JsonValidateUtil }
52 changes: 52 additions & 0 deletions libs/zhi-common-json-validate/src/lib/jsonValidateUtil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import Ajv, { JSONSchemaType } from "ajv"

/**
* Json 验证相关
*/
class JsonValidateUtil {
private static ajv = new Ajv()
public static validateJson<T>(schema: JSONSchemaType<T>, data: T): { valid: boolean; error?: string } {
const valid = this.ajv.validate(schema, data)
if (valid) {
return { valid }
} else {
return { valid, error: this.ajv.errorsText() }
}
}

public static validateObjectSchema(schemaObject: object, dataObject: object): { valid: boolean; error?: string } {
const valid = this.ajv.validate(schemaObject, dataObject)
if (valid) {
return { valid }
} else {
return { valid, error: this.ajv.errorsText() }
}
}
}

export default JsonValidateUtil
42 changes: 42 additions & 0 deletions libs/zhi-common-json-validate/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": [
"ES2020",
"DOM",
"DOM.Iterable"
],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "Node",
// "allowImportingTsExtensions": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"types": [
"node",
"vite/client"
]
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"references": [
{
"path": "./tsconfig.node.json"
}
],
"root": "."
}
10 changes: 10 additions & 0 deletions libs/zhi-common-json-validate/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
Loading