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

publish 1.1.1 #93

Merged
merged 6 commits into from
Jan 28, 2024
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
155 changes: 155 additions & 0 deletions README.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
[简体中文](README.md) | ENGLISH

# TinyCRUD

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/GuoXiCheng/TinyCRUD/ci.yml)
![Codecov branch](https://img.shields.io/codecov/c/github/GuoXiCheng/TinyCRUD/main)

## Introduction

TinyCRUD is a lightweight data storage library based on the Issue API of the code hosting platform. It can use Issues as database tables, and Issue comments as records in these tables. It performs data serialization/deserialization through the Issue API to enable data addition, deletion, modification, and querying.

## Applicable Scenarios

TinyCRUD is suitable for small teams or personal projects that require simple and lightweight data storage, but do not want or need to set up a complex database system.

## Supported code hosting platforms

<table>
<tr>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/github.svg" title="Github"/>
</p>
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/gitlab.svg" title="Gitlab"/>
</p>
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/gitee.svg" title="Gitee"/>
</p>
</td>
</tr>
<tr>
<td>
Github API latest
</td>
<td>
Gitlab API v4
</td>
<td>
Gitee API v5
</td>
</tr>
</table>

## Supported request libraries

<table>
<tr>
<td>
<img src="https://axios-http.com/assets/logo.svg" />
</td>
<td>
<p align="center">
<img src="https://guoxicheng.top/assets/image/tiny-crud-docs/wechat.svg" />
</p>
</td>
</tr>
<tr>
<td>
axios
</td>
<td>
wx(WeChat Mini Program)
</td>
</tr>
</table>

## Installation

```shell
npm install tiny-crud
```

## Usage

### Initialization

```ts
import axios from "axios";
import { createRequest } from "tiny-crud";

const GithubRequest = createRequest({
httpLib: "axios",
httpClient: axios,
accessToken: "Your Personal Access Token",

platform: "github",
owner: "Your Owner",
repo: "Your Repo",
});
```

### Create Model

```ts
import { BaseModel } from "tiny-crud";

export interface UserModel extends BaseModel {
name: string;
age: number;
gender: string;
}
```

### Create Repository

```ts
import { GithubRepository } from "tiny-crud";
import { githubRequest } from "./github-request";

export class UserRepository extends GithubRepository<UserModel> {
constructor() {
super(githubRequest, "Your Issue Number");
}
}
```

### Basic Operations

```ts
const userRepository = new UserRepository();

// create data
userRepository.create({
name: "John",
age: 30,
gender: "male",
});

// find data
userRepository.find();

// update data
userRepository.updateById(1, {
name: "Mary",
age: 25,
gender: "female",
});

// delete data
userRepository.deleteById(1);
```

## Documentation

- more detailed documentation 👉[TinyCRUD Docs](https://guoxicheng.top/en/projects/TinyCRUD-Docs)
- If you find it helpful, please consider giving it a little star, and thank you for your support! 🌟

## License

[MIT](https://github.com/GuoXiCheng/TinyCRUD/blob/main/LICENSE)
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
简体中文 | [English](README.en.md)

# TinyCRUD

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/GuoXiCheng/TinyCRUD/ci.yml)
Expand Down Expand Up @@ -33,13 +35,13 @@ TinyCRUD 适合用于满足小型团队或个人项目中需要简单、轻量
</tr>
<tr>
<td>
API latest
Github API latest
</td>
<td>
API v4
Gitlab API v4
</td>
<td>
API v5
Gitee API v5
</td>
</tr>
</table>
Expand All @@ -59,10 +61,10 @@ TinyCRUD 适合用于满足小型团队或个人项目中需要简单、轻量
</tr>
<tr>
<td>
<p align="center">axios</p>
<p align="center">axios</p>
</td>
<td>
wx(微信小程序)
wx(微信小程序)
</td>
</tr>
</table>
Expand Down Expand Up @@ -144,7 +146,7 @@ userRepository.updateById(1, {
userRepository.deleteById(1);
```

## 说明
## 详细文档

* 更好的阅读体验以及详细的使用文档请戳 👉[TinyCRUD Docs](https://guoxicheng.top/projects/TinyCRUD-Docs/)
* 如果对你有帮助的话可以给颗小星星,感谢支持!🌟
Expand Down
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tiny-crud",
"version": "1.1.0",
"description": "A tiny CRUD library based on Git Issue API",
"version": "1.1.1",
"description": "Lightweight Data Repository Based on Git Issue API",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
"types": "dist/index.d.ts",
Expand All @@ -17,6 +17,19 @@
"dist/bundle.esm.js",
"dist/index.d.ts"
],
"keywords": [
"git",
"issue",
"crud",
"data",
"repository",
"api"
],
"homepage": "https://guoxicheng.top/projects/TinyCRUD-Docs",
"repository": {
"type": "git",
"url": "https://github.com/GuoXiCheng/TinyCRUD.git"
},
"devDependencies": {
"@babel/preset-env": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/authenticate-gitee.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { USE_API, giteeRequest } from './helper/helper';
import { mockGiteeUser } from './mock/mock-git-user';
import { GiteeMock } from './mock/gitee-mock';

describe('Test Authenticate Gitee', () => {
beforeAll(()=>{
if (USE_API) return;
mockGiteeUser();
new GiteeMock().setUpMock();
});

test('Test Authenticate Gitee', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/authenticate-github.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { GithubUser } from "../index";
import { USE_API, githubRequest } from "./helper/helper";
import { mockGithubUser } from "./mock/mock-git-user";
import { GithubMock } from "./mock/github-mock";

describe('Test Authenticate Github', () => {
beforeAll(() => {
if (USE_API) return;
mockGithubUser();
new GithubMock().setUpMock();
});

test('Test Authenticate Github', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/authenticate-gitlab.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { USE_API, gitlabRequest } from "./helper/helper";
import { mockGitlabUser } from "./mock/mock-git-user";
import { GitlabMock } from "./mock/gitlab-mock";

describe('Test Authenticate Gitlab', () => {
beforeAll(() => {
if (USE_API) return;
mockGitlabUser();
new GitlabMock().setUpMock();
});

test('Test Authenticate Gitlab', async () => {
Expand Down
15 changes: 10 additions & 5 deletions src/__tests__/book-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlainObject } from "../index";
import { BookModel } from "./helper/book-model";
import { USE_API } from "./helper/helper";
import { Book } from "./helper/book-repository";
import { setupGithubMock } from "./mock/mock-github-api";
import { GithubMock } from "./mock/github-mock";


describe('Test Book Storage', () => {
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('Test Book Storage', () => {
if (USE_API) {
await Book.deleteAll();
} else {
await setupGithubMock();
new GithubMock().setUpMock();
}
});

Expand Down Expand Up @@ -149,7 +149,7 @@ describe('Test Book Storage', () => {
}
});

(USE_API ? test: test.skip)('Test createAll Book', async () => {
(USE_API ? test : test.skip)('Test createAll Book', async () => {
await Book.deleteAll();
const result = await Book.createAll(bookList);
expect(result.length).toEqual(10);
Expand All @@ -176,6 +176,11 @@ describe('Test Book Storage', () => {
});
});

test('Test find Book with params since undefined', async () => {
const result = await Book.find({ since: undefined });
expect(result.length).toBeGreaterThan(0);
});

test('Test find Book with params page & per_page', async () => {
const firstPage = await Book.find({ page: 1, per_page: 3 });
expect(firstPage.length).toEqual(3);
Expand All @@ -184,9 +189,9 @@ describe('Test Book Storage', () => {
expect(lastPage.length).toEqual(1);
});

test('Test get Book Detail', async()=>{
test('Test get Book Detail', async () => {
const result = await Book.detail();
const {id, issue_number, comments, created_at, updated_at} = result;
const { id, issue_number, comments, created_at, updated_at } = result;
expect(id).not.toBeNull();
expect(issue_number).not.toBeNull();
expect(comments).not.toBeNull();
Expand Down
9 changes: 7 additions & 2 deletions src/__tests__/chat-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PlainObject } from "../index";
import { ChatModel } from "./helper/chat-model";
import { Chat } from "./helper/chat-repository";
import { USE_API } from "./helper/helper";
import { setupGitlabMock} from "./mock/mock-gitlab-api";
import { GitlabMock } from "./mock/gitlab-mock";


describe('Use Gitlab Test Chat Storage', () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Use Gitlab Test Chat Storage', () => {
if (USE_API) {
await Chat.deleteAll();
} else {
setupGitlabMock();
new GitlabMock().setUpMock();
}
});

Expand Down Expand Up @@ -235,6 +235,11 @@ describe('Use Gitlab Test Chat Storage', () => {
expect(findAsc.map(item => item.id)).toEqual(findDesc.map(item => item.id).reverse());
});

test('Test find Chat with params sort & order_by undefined', async () => {
const result = await Chat.find({ sort: undefined, order_by: undefined });
expect(result.length).toBeGreaterThan(0);
});

test('Test get Chat Detail', async()=>{
const result = await Chat.detail();
const {id, issue_number, comments, created_at, updated_at} = result;
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import timezone from 'dayjs/plugin/timezone';
import MockAdapter from 'axios-mock-adapter';
import jsonfile from 'jsonfile';

// export const mock = new MockAdapter(axios);

dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault('Asia/Shanghai');
Expand Down
25 changes: 25 additions & 0 deletions src/__tests__/mock/base-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { writeJSONSync } from "../helper/helper";

export abstract class BaseMock {
constructor(filename: string) {
writeJSONSync(filename, []);
}

setUpMock() {
this.mockUser();
this.mockCreate();
this.mockFind();
this.mockFindById();
this.mockUpdateById();
this.mockDeleteById();
this.mockDetail();
}

abstract mockUser(): void;
abstract mockCreate(): void;
abstract mockFind(): void;
abstract mockFindById(): void;
abstract mockUpdateById(): void;
abstract mockDeleteById(): void;
abstract mockDetail(): void;
}
Loading
Loading