From d23928cbb0d50490a61f2ec48fc3b28f286bf4e0 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 08:06:37 +0800 Subject: [PATCH 01/16] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 排除yarn的lockfile --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 43d7c43..29449b6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ run/ .DS_Store *.swp .vscode - +yarn.lock From 9b9f498d3c34bb4f2a821e319e92a9e88d6888fc Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 08:43:07 +0800 Subject: [PATCH 02/16] =?UTF-8?q?chore:=20=E5=AE=89=E8=A3=85=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/nodejs.yml | 46 ++++++++++++++++++++++++++++++++++++ .travis.yml | 5 ++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/nodejs.yml diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..35a058f --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,46 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + schedule: + - cron: '0 2 * * *' + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node-version: [8, 10] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Checkout Git Source + uses: actions/checkout@v2 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install Dependencies + run: npm i -g npminstall && npminstall + + - name: Continuous Integration + run: npm run ci + + - name: Code Coverage + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.travis.yml b/.travis.yml index ce21122..cdaac48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ -sudo: false language: node_js node_js: - '8' - '10' +before_install: + - npm i npminstall -g install: - - npm i npminstall && npminstall + - npminstall script: - npm run ci after_script: From 9c761ba7f72a6daeb74e7d6273367f636d45b1f4 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 09:44:24 +0800 Subject: [PATCH 03/16] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0typescript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加typescript相关依赖项并完成相关配置 --- tsconfig.json | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0737b24 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,101 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Projects */ + // "incremental": true, /* Enable incremental compilation */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + + /* Language and Environment */ + "target": "es2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ + // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + + /* Modules */ + "module": "commonjs", /* Specify what module code is generated. */ + "rootDir": "./src", /* Specify the root folder within your source files. */ + // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "resolveJsonModule": true, /* Enable importing .json files */ + // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ + + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./lib", /* Specify an output folder for all emitted files. */ + "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + + /* Type Checking */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ + // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ + // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + } +} From 8a29d71e262fa6ce4150f45272d2beff166e2cd8 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 09:53:57 +0800 Subject: [PATCH 04/16] =?UTF-8?q?chore:=20=E6=B7=BB=E5=8A=A0typescript\n\n?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0typescript=E7=9B=B8=E5=85=B3=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E9=A1=B9=E5=B9=B6=E5=AE=8C=E6=88=90=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 8 ++++++-- src/client.ts | 3 +++ src/doc.ts | 3 +++ src/group.ts | 1 + src/index.ts | 18 ++++++++++++++++++ src/repo.ts | 1 + src/user.ts | 1 + 7 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/client.ts create mode 100644 src/doc.ts create mode 100644 src/group.ts create mode 100644 src/index.ts create mode 100644 src/repo.ts create mode 100644 src/user.ts diff --git a/package.json b/package.json index 65e667a..dd992ad 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,14 @@ "urllib": "^2.33.1" }, "devDependencies": { + "@types/node": "^17.0.23", "autod": "^3.0.1", "egg-bin": "^4.3.7", "egg-ci": "^1.8.0", "eslint": "^4.18.1", - "eslint-config-egg": "^7.0.0" + "eslint-config-egg": "^7.0.0", + "ts-node": "^10.7.0", + "typescript": "^4.6.3" }, "engines": { "node": ">=8.0.0" @@ -25,7 +28,8 @@ "test-local": "egg-bin test", "cov": "egg-bin cov", "ci": "npm run lint && egg-bin pkgfiles --check && npm run cov", - "pkgfiles": "egg-bin pkgfiles" + "pkgfiles": "egg-bin pkgfiles", + "build": "tsc -p ." }, "ci": { "version": "8, 10" diff --git a/src/client.ts b/src/client.ts new file mode 100644 index 0000000..95cc750 --- /dev/null +++ b/src/client.ts @@ -0,0 +1,3 @@ +export default class CLient{ + +} \ No newline at end of file diff --git a/src/doc.ts b/src/doc.ts new file mode 100644 index 0000000..6bda38b --- /dev/null +++ b/src/doc.ts @@ -0,0 +1,3 @@ +export default class Doc{ + +} \ No newline at end of file diff --git a/src/group.ts b/src/group.ts new file mode 100644 index 0000000..693da49 --- /dev/null +++ b/src/group.ts @@ -0,0 +1 @@ +export {} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..d4e2c8c --- /dev/null +++ b/src/index.ts @@ -0,0 +1,18 @@ +import * as doc from './doc'; +import {RequestOptions} from 'urllib'; + +interface YuqueOptions { + token: string, + endpoint?: string, + userAgent?: string, + requestOpts?:RequestOptions, + handler?:(res:any)=>any, +} + +export default class Yuque { + private options:YuqueOptions; + public constructor(options:YuqueOptions) { + this.options=options; + + } +} \ No newline at end of file diff --git a/src/repo.ts b/src/repo.ts new file mode 100644 index 0000000..693da49 --- /dev/null +++ b/src/repo.ts @@ -0,0 +1 @@ +export {} \ No newline at end of file diff --git a/src/user.ts b/src/user.ts new file mode 100644 index 0000000..693da49 --- /dev/null +++ b/src/user.ts @@ -0,0 +1 @@ +export {} \ No newline at end of file From 4d91eb1489c6660253191d7d52afca441e1983c4 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 10:49:43 +0800 Subject: [PATCH 05/16] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90index.ts?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基本完成入口文件(index.ts)的编写工作,同时完成各类的定义与export --- src/client.ts | 4 +--- src/group.ts | 4 +++- src/index.ts | 5 +++-- src/repo.ts | 4 +++- src/user.ts | 4 +++- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index 95cc750..9b68753 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,3 +1 @@ -export default class CLient{ - -} \ No newline at end of file +export default class Client{} diff --git a/src/group.ts b/src/group.ts index 693da49..4cd6b4c 100644 --- a/src/group.ts +++ b/src/group.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class Group{ + +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d4e2c8c..12361c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import * as doc from './doc'; +import Client from './client'; import {RequestOptions} from 'urllib'; interface YuqueOptions { @@ -11,8 +11,9 @@ interface YuqueOptions { export default class Yuque { private options:YuqueOptions; + public client:Client; public constructor(options:YuqueOptions) { this.options=options; - + this.client=new Client(); } } \ No newline at end of file diff --git a/src/repo.ts b/src/repo.ts index 693da49..a72948e 100644 --- a/src/repo.ts +++ b/src/repo.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class Repo{ + +} \ No newline at end of file diff --git a/src/user.ts b/src/user.ts index 693da49..db929fa 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class User{ + +} \ No newline at end of file From 1bfe30464b67223e6f010f8f53959fd2f76340a9 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 10:49:43 +0800 Subject: [PATCH 06/16] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90index.ts?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基本完成入口文件(index.ts)的编写工作,同时完成各类的定义与export --- src/client.ts | 4 +--- src/group.ts | 4 +++- src/index.ts | 21 +++++++++++++++++---- src/repo.ts | 4 +++- src/user.ts | 4 +++- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/client.ts b/src/client.ts index 95cc750..9b68753 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,3 +1 @@ -export default class CLient{ - -} \ No newline at end of file +export default class Client{} diff --git a/src/group.ts b/src/group.ts index 693da49..4cd6b4c 100644 --- a/src/group.ts +++ b/src/group.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class Group{ + +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index d4e2c8c..49c64a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,8 @@ -import * as doc from './doc'; +import Client from './client'; +import Group from "./group"; +import User from "./user"; +import Repo from "./repo"; +import Doc from "./doc"; import {RequestOptions} from 'urllib'; interface YuqueOptions { @@ -11,8 +15,17 @@ interface YuqueOptions { export default class Yuque { private options:YuqueOptions; - public constructor(options:YuqueOptions) { - this.options=options; - + public client:Client; + public users:User; + public groups:Group; + public repos:Repo; + public docs:Doc; + constructor(options: YuqueOptions) { + this.options = options; + this.client = new Client(); + this.users = new User(); + this.groups = new Group(); + this.repos = new Repo(); + this.docs = new Doc(); } } \ No newline at end of file diff --git a/src/repo.ts b/src/repo.ts index 693da49..a72948e 100644 --- a/src/repo.ts +++ b/src/repo.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class Repo{ + +} \ No newline at end of file diff --git a/src/user.ts b/src/user.ts index 693da49..db929fa 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1 +1,3 @@ -export {} \ No newline at end of file +export default class User{ + +} \ No newline at end of file From e987f998089cb16fef5f70beb4322250afb9e1a1 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 10:58:41 +0800 Subject: [PATCH 07/16] =?UTF-8?q?refactor:=20=E8=B6=85=E5=B0=8F=E5=B9=85?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 只是给Yuque Class的constructor加了个public修饰符而已 --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 49c64a0..037214f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,7 +20,7 @@ export default class Yuque { public groups:Group; public repos:Repo; public docs:Doc; - constructor(options: YuqueOptions) { + public constructor(options: YuqueOptions) { this.options = options; this.client = new Client(); this.users = new User(); From 636f0dd0326039dfa6fdd41262058263271ac9d1 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 11:41:57 +0800 Subject: [PATCH 08/16] =?UTF-8?q?chore(npm):=20=E6=9B=B4=E6=96=B0=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将debug包的类型声明包加入依赖项 --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index dd992ad..c4dbd21 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "urllib": "^2.33.1" }, "devDependencies": { + "@types/debug": "^4.1.7", "@types/node": "^17.0.23", "autod": "^3.0.1", "egg-bin": "^4.3.7", From 889a768e1c557788505cc079a80357e997225c70 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 11:46:04 +0800 Subject: [PATCH 09/16] =?UTF-8?q?chore:=20=E6=9B=B4=E6=94=B9=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将原来的js源文件全部移动到src文件夹下 --- {lib => src}/client.js | 0 {lib => src}/doc.js | 0 {lib => src}/group.js | 0 {lib => src}/index.js | 0 {lib => src}/repo.js | 0 {lib => src}/user.js | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename {lib => src}/client.js (100%) rename {lib => src}/doc.js (100%) rename {lib => src}/group.js (100%) rename {lib => src}/index.js (100%) rename {lib => src}/repo.js (100%) rename {lib => src}/user.js (100%) diff --git a/lib/client.js b/src/client.js similarity index 100% rename from lib/client.js rename to src/client.js diff --git a/lib/doc.js b/src/doc.js similarity index 100% rename from lib/doc.js rename to src/doc.js diff --git a/lib/group.js b/src/group.js similarity index 100% rename from lib/group.js rename to src/group.js diff --git a/lib/index.js b/src/index.js similarity index 100% rename from lib/index.js rename to src/index.js diff --git a/lib/repo.js b/src/repo.js similarity index 100% rename from lib/repo.js rename to src/repo.js diff --git a/lib/user.js b/src/user.js similarity index 100% rename from lib/user.js rename to src/user.js From f5267954b6e88c7467ed66e181b27a50d42c87b8 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 12:04:32 +0800 Subject: [PATCH 10/16] =?UTF-8?q?feat(client):=20=E5=AE=8C=E6=88=90client.?= =?UTF-8?q?ts=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成client.ts文件编写,并修改index.ts中对Client的引用 --- src/client.ts | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/index.ts | 4 ++-- 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index 9b68753..c08972d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1 +1,65 @@ -export default class Client{} +import assert from "assert"; +import httpclient, {RequestOptions} from 'urllib'; + +const extend = require('extend2'); +import DBG from 'debug' +const debug=DBG('yuque'); + +import {YuqueOptions} from "./index"; +class CError extends Error{ + public status?:string; + public code?:number; + public data?:any; + public constructor(message?:string) { + super(message); + } +} + +export default class Client { + private options: YuqueOptions; + + public constructor(options: YuqueOptions) { + this.options = Object.assign({ + endpoint: 'https://www.yuque.com/api/v2', + userAgent: '@yuque/sdk', + }, options); + assert(this.options.token, 'token is required'); + } + + public async request(api:string,opts:RequestOptions) { + const {endpoint, token, userAgent, requestOpts, handler} = this.options; + const url=`${endpoint}${api}`; + opts=extend(true,{ + method: 'GET', + contentType: 'json', + dataType: 'json', + headers: { + 'User-Agent': userAgent, + 'X-Auth-Token': token, + }, + gzip: true, + + // proxy + rejectUnauthorized: !process.env.http_proxy, + enableProxy: !!process.env.http_proxy, + proxy: process.env.http_proxy, + }, requestOpts, opts); + debug(`${opts.method},${url}`); + + const res=await httpclient.request(url,opts); + debug('response',res.data); + + //custom response + if(handler) return handler(res); + + //default handler + if(res.status !== 200){ + const err=new CError(res.data.message); + /* istanbul ignore next */ + err.status = res.data.status || res.status; + err.code = res.data.code; + err.data = res; + throw err; + } + } +} diff --git a/src/index.ts b/src/index.ts index 037214f..252c7dc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import Repo from "./repo"; import Doc from "./doc"; import {RequestOptions} from 'urllib'; -interface YuqueOptions { +export interface YuqueOptions { token: string, endpoint?: string, userAgent?: string, @@ -22,7 +22,7 @@ export default class Yuque { public docs:Doc; public constructor(options: YuqueOptions) { this.options = options; - this.client = new Client(); + this.client = new Client(this.options); this.users = new User(); this.groups = new Group(); this.repos = new Repo(); From 9c6831ce7acb65ee7f7b889b3ef927179cb50185 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 15:57:44 +0800 Subject: [PATCH 11/16] =?UTF-8?q?feat(client):=20=E5=AE=8C=E6=88=90doc.ts?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成doc.ts文件编写,并修改index.ts中对Doc的引用 --- src/doc.ts | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/index.ts | 5 ++-- 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/doc.ts b/src/doc.ts index 6bda38b..d87efc4 100644 --- a/src/doc.ts +++ b/src/doc.ts @@ -1,3 +1,71 @@ -export default class Doc{ +import assert from "assert"; +import Client from "./client"; + +interface DocArg{ + client:Client, +} +interface DocListArg{ + namespace:string, +} +interface DocGetArg{ + namespace:string, + slug:string, + data?:{ + raw:number + } +} +type DocFormat='markdown'|'lake'; +interface DocCreateArg{ + namespace:string, + data:{ + title:string, + slug:string, + public?:number, + format?:DocFormat, + body:string, + } +} +interface DocUpdateArg{ + namespace:string, + id:string, + data:{ + title?:string, + slug?:string, + public?:number, + body?:string + } +} +interface DocDeleteArg{ + namespace:string, + id:string, +} +export default class Doc{ + private client:Client; + constructor({client}:DocArg) { + this.client=client; + } + public async list({namespace}:DocListArg){ + assert(namespace,'repo namespace or id is required'); + return this.client.request(`repos/${namespace}/docs`, { method: 'GET' }); + } + public async get({namespace,slug,data}:DocGetArg){ + assert(namespace,'repo namespace or id is required'); + assert(slug,'doc slug or id is required'); + return this.client.request(`repos/${namespace}/docs/${slug}`, { method: 'GET', data }); + } + public async create({namespace,data}:DocCreateArg){ + assert(namespace, 'repo namespace or id is required'); + return this.client.request(`repos/${namespace}/docs`, { method: 'POST', data }); + } + public async update({ namespace, id, data }:DocUpdateArg) { + assert(namespace, 'repo namespace or id is required'); + assert(id, 'doc id is required'); + return this.client.request(`repos/${namespace}/docs/${id}`, { method: 'PUT', data }); + } + public async delete({ namespace, id }:DocDeleteArg) { + assert(namespace, 'repo namespace or id is required'); + assert(id, 'doc id is required'); + return this.client.request(`repos/${namespace}/docs/${id}`, { method: 'DELETE' }); + } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 252c7dc..014a9de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,10 +22,11 @@ export default class Yuque { public docs:Doc; public constructor(options: YuqueOptions) { this.options = options; - this.client = new Client(this.options); + const client = new Client(this.options); + this.client=client; this.users = new User(); this.groups = new Group(); this.repos = new Repo(); - this.docs = new Doc(); + this.docs = new Doc({client}); } } \ No newline at end of file From d2d346518f8ab43e5b5a64fbead4decef8ee2781 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 16:09:36 +0800 Subject: [PATCH 12/16] =?UTF-8?q?feat(client):=20=E5=AE=8C=E6=88=90group.t?= =?UTF-8?q?s=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成group.ts文件编写,并修改index.ts中对Group的引用 --- src/doc.ts | 6 ++---- src/group.ts | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/index.ts | 8 ++++++- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/doc.ts b/src/doc.ts index d87efc4..a450ed9 100644 --- a/src/doc.ts +++ b/src/doc.ts @@ -1,9 +1,7 @@ import assert from "assert"; import Client from "./client"; +import {GArg} from "./index"; -interface DocArg{ - client:Client, -} interface DocListArg{ namespace:string, } @@ -42,7 +40,7 @@ interface DocDeleteArg{ export default class Doc{ private client:Client; - constructor({client}:DocArg) { + constructor({client}:GArg) { this.client=client; } public async list({namespace}:DocListArg){ diff --git a/src/group.ts b/src/group.ts index 4cd6b4c..a93bd54 100644 --- a/src/group.ts +++ b/src/group.ts @@ -1,3 +1,62 @@ -export default class Group{ +import assert from "assert"; +import {GArg, QArg} from "./index"; +import Client from "./client"; +interface GCreate{ + data:{ + name:string, + login:string, + description?:string, + } +} +interface GGetArg { + login:string +} +interface GAddUserArg{ + group:string, + user:string, + data:{ + role:0|1, + } +} +interface GUArg{ + group:string, + user:string, +} + +export default class Group { + private client: Client; + + public constructor({client}: GArg) { + this.client = client; + } + + public async list({login}: QArg = {}) { + const api: string = login ? `users/${login}/groups` : 'groups'; + return this.client.request(api, {method: 'GET'}); + } + public async create({ data }:GCreate) { + assert(data, 'data is required'); + assert(data.name, 'data.name is required'); + assert(data.login, 'data.login is required'); + return this.client.request('groups', { method: 'POST', data }); + } + public async get({ login }:GGetArg) { + assert(login, 'group login or id is required'); + return this.client.request(`groups/${login}`, { method: 'GET' }); + } + public async listUser({ login }:GGetArg) { + assert(login, 'group login or id is required'); + return this.client.request(`groups/${login}/users`, { method: 'GET' }); + } + public async addUser({ group, user, data }:GAddUserArg) { + assert(group, 'group login or id is required'); + assert(user, 'user login or id is required'); + return this.client.request(`groups/${group}/users/${user}`, { method: 'PUT', data }); + } + public async removeUser({ group, user }:GUArg) { + assert(group, 'group login or id is required'); + assert(user, 'user login or id is required'); + return this.client.request(`groups/${group}/users/${user}`, { method: 'DELETE' }); + } } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 014a9de..fd7924c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,12 @@ export interface YuqueOptions { requestOpts?:RequestOptions, handler?:(res:any)=>any, } +export interface GArg{ + client:Client, +} +export interface QArg{ + login?:string, +} export default class Yuque { private options:YuqueOptions; @@ -25,7 +31,7 @@ export default class Yuque { const client = new Client(this.options); this.client=client; this.users = new User(); - this.groups = new Group(); + this.groups = new Group({client}); this.repos = new Repo(); this.docs = new Doc({client}); } From 03b6a271ce16a07bcad3b76238b319369f63679d Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 16:19:32 +0800 Subject: [PATCH 13/16] =?UTF-8?q?feat(repo):=20=E5=AE=8C=E6=88=90repo.ts?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成repo.ts文件编写,并修改index.ts中对Repo的引用 --- src/index.ts | 4 +-- src/repo.ts | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index fd7924c..a4db0b4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,9 +30,9 @@ export default class Yuque { this.options = options; const client = new Client(this.options); this.client=client; - this.users = new User(); + this.users = new User({client}); this.groups = new Group({client}); - this.repos = new Repo(); + this.repos = new Repo({client}); this.docs = new Doc({client}); } } \ No newline at end of file diff --git a/src/repo.ts b/src/repo.ts index a72948e..a29eac8 100644 --- a/src/repo.ts +++ b/src/repo.ts @@ -1,3 +1,76 @@ -export default class Repo{ +import assert from "assert"; +import {GArg,QArg} from "./index"; +import Client from "./client"; + +interface RListArg{ + user?:string, + group?:string, + data?:{ + type?:'Book'|'Design'|'Column'|'all', + include_membered:boolean, + offset:number, + } +} +interface RCreateArg{ + user?:string, + group?:string, + data:{ + name:string, + slug:string, + type:'Book'|'Design'|'Column', + description?:string, + public:0|1, + } +} +interface RGetArg { + namespace:string|number, + data:{ + type?:'Book'|'Design'|'Column', + } +} +interface RUpdateArg{ + namespace:string|number, + data:{ + name?:string, + slug?:string, + toc?:string, + description?:string, + public:0|1, + } +} +interface RGArg { + namespace:string|number, +} +export default class Repo{ + private client: Client; + public constructor({client}:GArg) { + this.client=client; + } + public async list({ user, group, data }:RListArg) { + assert(user || group, 'user or group is required'); + const api = user ? `users/${user}/repos` : `groups/${group}/repos`; + return this.client.request(api, { method: 'GET', data }); + } + public async create({ user, group, data }:RCreateArg) { + assert(user || group, 'user or group is required'); + const api = user ? `users/${user}/repos` : `groups/${group}/repos`; + return this.client.request(api, { method: 'POST', data }); + } + public async get({ namespace, data }:RGetArg) { + assert(namespace, 'namespace is required'); + return this.client.request(`repos/${namespace}`, { method: 'GET', data }); + } + public async update({ namespace, data }:RUpdateArg) { + assert(namespace, 'namespace is required'); + return this.client.request(`repos/${namespace}`, { method: 'PUT', data }); + } + public async delete({ namespace }:RGArg) { + assert(namespace, 'namespace is required'); + return this.client.request(`repos/${namespace}`, { method: 'DELETE' }); + } + public async getTOC({ namespace }:RGArg) { + assert(namespace, 'namespace is required'); + return this.client.request(`repos/${namespace}/toc`, { method: 'GET' }); + } } \ No newline at end of file From 7d57b6e84334a6da1d4acf9bf7a106de3817b991 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 16:22:07 +0800 Subject: [PATCH 14/16] =?UTF-8?q?feat(user):=20=E5=AE=8C=E6=88=90user.ts?= =?UTF-8?q?=E7=BC=96=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成user.ts文件编写,并修改index.ts中对User的引用 --- src/user.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/user.ts b/src/user.ts index db929fa..a888495 100644 --- a/src/user.ts +++ b/src/user.ts @@ -1,3 +1,15 @@ -export default class User{ +import {GArg, QArg} from "./index"; +import Client from "./client"; +export default class User { + private client: Client; + + public constructor({client}: GArg) { + this.client = client; + } + + public async get({login}: QArg = {}) { + const api = login ? `users/${login}` : 'user'; + return this.client.request(api, {method: 'GET'}); + } } \ No newline at end of file From c2117968a0a130e9164c29c574a36ff614dd83f6 Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 16:25:30 +0800 Subject: [PATCH 15/16] chore(git): Ignored complied files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 29449b6..26b1839 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ run/ *.swp .vscode yarn.lock +lib/ From 301585d258043050810dbd850d744a79e0cbe43b Mon Sep 17 00:00:00 2001 From: ConstasJ <2020212726@qq.com> Date: Tue, 29 Mar 2022 16:31:22 +0800 Subject: [PATCH 16/16] ASD --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c4dbd21..5979e2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yuque/sdk", - "version": "1.1.1", + "version": "1.2.0", "description": "Node SDK for yuque", "main": "lib/index.js", "dependencies": {