Skip to content

Commit

Permalink
Merge pull request #38 from GuoXiCheng/dev-c
Browse files Browse the repository at this point in the history
update
  • Loading branch information
GuoXiCheng authored Dec 14, 2023
2 parents 341522f + fc11666 commit 8ff0522
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-crud",
"version": "1.0.14",
"version": "1.0.15",
"description": "",
"main": "dist/bundle.cjs.js",
"module": "dist/bundle.esm.js",
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/helper/start-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import 'dotenv/config';
import {createRequest} from '../../request-lib';
import { createRequest } from '../..';

export class StartTest {
constructor() {

Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/helper/user-model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseModel } from '../../storage-lib/base/base-model';
import { BaseModel } from "../..";
export interface UserModel extends BaseModel {
name: string;
age: number;
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/helper/user-storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GiteeStorage } from '../../storage-lib/gitee/gitee-storage';
import { GiteeStorage } from '../..';
import { StartTest } from './start-test';
import { UserModel } from './user-model';

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createRequest} from "./request-lib/create-request";
import { OfficialUrl } from "./enums";
export {createRequest, OfficialUrl};
import { BaseModel, GiteeStorage } from "./storage-lib";
export {createRequest, BaseModel, GiteeStorage};

9 changes: 5 additions & 4 deletions src/storage-lib/base/base-storage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BaseComment } from "./base-comment";
import { BaseModel } from "./base-model";

export abstract class BaseStorage {
export abstract class BaseStorage<T extends BaseModel> {
abstract findById(id: number): void;
abstract find(): Promise<any[]>;
abstract find(): Promise<T[]>;
abstract create(data: any): void;
abstract deleteById(id: number): Promise<void>;

Expand All @@ -13,7 +14,7 @@ export abstract class BaseStorage {
}

// 序列化: 将对象转换为字符串
serialize<M>(obj: M): string {
serialize<T>(obj: T): string {
try {
return JSON.stringify(obj);
} catch (error) {
Expand All @@ -23,7 +24,7 @@ export abstract class BaseStorage {
}

// 反序列化: 将字符串转换为对象
deserialize<M>(comment: BaseComment): M {
deserialize<T>(comment: BaseComment): T {
try {
const {id, body, created_at, updated_at} = comment;
const obj = JSON.parse(body);
Expand Down
2 changes: 1 addition & 1 deletion src/storage-lib/gitee/gitee-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseComment } from "../base/base-comment";
import { BaseModel } from "../base/base-model";
import { BaseStorage } from "../base/base-storage";

export class GiteeStorage<T extends BaseModel> extends BaseStorage {
export class GiteeStorage<T extends BaseModel> extends BaseStorage<T> {
private endpoint: string;

constructor(private request: BaseRequest, private issueNumber: string) {
Expand Down
2 changes: 2 additions & 0 deletions src/storage-lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export {BaseModel} from './base/base-model';
/** Gitee */
export {GiteeUser} from './gitee/gitee-user';
export {GiteeOptions} from './gitee/gitee-options';
export {GiteeStorage} from './gitee/gitee-storage';
/** Github */
export {GithubUser} from './github/github-user';
export {GithubOptions} from './github/github-options';
Expand Down

0 comments on commit 8ff0522

Please sign in to comment.