Skip to content

Commit 5845375

Browse files
authored
Initial commit
0 parents  commit 5845375

25 files changed

+419
-0
lines changed

.cspell.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// cSpell Settings
2+
{
3+
// Version of the setting file. Always 0.1
4+
"version": "0.1",
5+
// language - current active spelling language
6+
"language": "en",
7+
// words - list of words to be always considered correct
8+
"words": ["vrerv"],
9+
// flagWords - list of words to be always considered incorrect
10+
// This is useful for offensive words and common spelling errors.
11+
// For example "hte" should be "the"
12+
"flagWords": ["hte"],
13+
"ignorePaths": [
14+
"package.json",
15+
"package-lock.json",
16+
"node_modules/**",
17+
"examples/**/node_modules/**",
18+
"build/**"
19+
]
20+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

.eslintrc.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
root: true,
5+
parser: "@typescript-eslint/parser",
6+
plugins: ["@typescript-eslint"],
7+
extends: [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
],
12+
env: {
13+
node: true,
14+
commonjs: true,
15+
},
16+
rules: {
17+
"@typescript-eslint/no-unused-vars": [
18+
"error",
19+
{
20+
args: "all",
21+
argsIgnorePattern: "^_",
22+
// Allow assertion types.
23+
varsIgnorePattern: "^_assert",
24+
caughtErrors: "none",
25+
ignoreRestSiblings: true,
26+
},
27+
],
28+
"no-mixed-spaces-and-tabs": ["error", "smart-tabs"],
29+
},
30+
}

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: CI
5+
6+
on:
7+
push:
8+
branches: [main]
9+
pull_request:
10+
branches: [main]
11+
12+
jobs:
13+
build-and-test:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [14.x, 15.x, 16.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v2
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: npm install
27+
- run: npm run build
28+
- run: npm run lint
29+
- run: npm test

.github/workflows/semgrep.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Security - Semgrep
2+
3+
on:
4+
pull_request: {}
5+
workflow_dispatch: {}
6+
push:
7+
branches-ignore: ["main"]
8+
schedule:
9+
- cron: "20 17 * * *"
10+
11+
jobs:
12+
semgrep:
13+
name: semgrep/ci
14+
runs-on: ubuntu-latest
15+
container:
16+
image: returntocorp/semgrep
17+
timeout-minutes: 480
18+
steps:
19+
- uses: actions/checkout@v3
20+
- run: semgrep ci
21+
env:
22+
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP }}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
3+
package-lock.json
4+
/build
5+
6+
/examples/**/node_modules
7+
/examples/**/package-lock.json
8+
/examples/**/.env
9+
10+
.vscode
11+
.idea

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/fermium

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
.github/**/*.md

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false,
4+
"trailingComma": "es5",
5+
"endOfLine": "lf"
6+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 VReRV
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div align="center">
2+
<h1>Node package template</h1>
3+
<p>
4+
<b>A node package template project</b>
5+
</p>
6+
<br>
7+
</div>
8+
9+
![Build status](https://github.com/vrerv/node-package-template/actions/workflows/ci.yml/badge.svg)
10+
[![npm version](https://badge.fury.io/js/%40vrerv%2Fnode-package-template.svg)](https://www.npmjs.com/package/@vrerv/node-package-template)
11+
12+
## Usage
13+
14+
TODO: build software and write usage instructions
15+
16+
## Requirements
17+
18+
This package supports the following minimum versions:
19+
20+
- Runtime: `node >= 14`
21+
- Type definitions (optional): `typescript >= 4.5`
22+
23+
Earlier versions may still work, but we encourage people building new applications to upgrade to the current stable.
24+
25+
## References
26+
27+
- This codebase has been stripped down from the original [notion-sdk-js](https://github.com/makenotion/notion-sdk-js)

examples/example-project/.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"arrowParens": "avoid",
3+
"tabWidth": 2,
4+
"semi": false,
5+
"trailingComma": "es5",
6+
"endOfLine": "lf",
7+
"singleQuote": false
8+
}

examples/example-project/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Example Project Sample

examples/example-project/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Example } from "@vrerv/node-package-template"
2+
3+
const sdk = new Example()
4+
5+
async function main() {
6+
await sdk.hello()
7+
}
8+
9+
main()

examples/example-project/package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "example-project",
3+
"version": "1.0.0",
4+
"description": "Example of using sdk.",
5+
"main": "index.js",
6+
"type": "module",
7+
"engines": {
8+
"node": "12.x"
9+
},
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1",
12+
"ts-run": "node --loader ts-node/esm index.ts"
13+
},
14+
"dependencies": {
15+
"@vrerv/node-package-template": "file:../../"
16+
},
17+
"author": "VReRV",
18+
"license": "MIT"
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"compilerOptions": {
3+
"incremental": true,
4+
"sourceMap": false,
5+
6+
"target": "ESNext",
7+
"module": "commonjs",
8+
9+
"moduleResolution": "Node",
10+
11+
"allowSyntheticDefaultImports": true,
12+
13+
"useDefineForClassFields": false,
14+
15+
"strict": false,
16+
"suppressImplicitAnyIndexErrors": true,
17+
18+
"isolatedModules": true,
19+
"esModuleInterop": true,
20+
"noUncheckedIndexedAccess": true,
21+
"allowJs": true,
22+
"checkJs": false
23+
},
24+
"include": ["src/**/*"]
25+
}

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
}

package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@vrerv/node-package-template",
3+
"version": "2.2.15",
4+
"description": "A node package template",
5+
"engines": {
6+
"node": ">=12"
7+
},
8+
"homepage": "https://vrerv.com",
9+
"bugs": {
10+
"url": "https://github.com/vrerv/node-package-template/issues"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/vrerv/node-package-template/"
15+
},
16+
"keywords": [
17+
"vrerv"
18+
],
19+
"main": "./build/src",
20+
"types": "./build/src/index.d.ts",
21+
"scripts": {
22+
"prepare": "npm run build",
23+
"prepublishOnly": "npm run && npm run lint && npm run test",
24+
"build": "tsc",
25+
"prettier": "prettier --write .",
26+
"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
27+
"test": "jest ./test",
28+
"check-links": "git ls-files | grep md$ | xargs -n 1 markdown-link-check",
29+
"prebuild": "npm run clean",
30+
"clean": "rm -rf ./build"
31+
},
32+
"author": "",
33+
"license": "MIT",
34+
"files": [
35+
"build/package.json",
36+
"build/src/**"
37+
],
38+
"dependencies": {},
39+
"devDependencies": {
40+
"@types/jest": "^28.1.4",
41+
"@typescript-eslint/eslint-plugin": "^5.39.0",
42+
"@typescript-eslint/parser": "^5.39.0",
43+
"cspell": "^5.4.1",
44+
"eslint": "^7.24.0",
45+
"jest": "^28.1.2",
46+
"markdown-link-check": "^3.8.7",
47+
"prettier": "^2.8.8",
48+
"ts-jest": "^28.0.5",
49+
"typescript": "^4.8.4"
50+
}
51+
}

src/Example.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export class Example {
2+
constructor() {
3+
console.log("Example constructor")
4+
}
5+
6+
hello() {
7+
console.log("Hello Example")
8+
}
9+
}

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { LogLevel, Logger } from "./logging"
2+
export { Example } from "./Example"

src/logging.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { assertNever } from "./utils"
2+
3+
export enum LogLevel {
4+
DEBUG = "debug",
5+
INFO = "info",
6+
WARN = "warn",
7+
ERROR = "error",
8+
}
9+
10+
export interface Logger {
11+
(level: LogLevel, message: string, extraInfo: Record<string, unknown>): void
12+
}
13+
14+
export function makeConsoleLogger(name: string): Logger {
15+
return (level, message, extraInfo) => {
16+
console[level](`${name} ${level}:`, message, extraInfo)
17+
}
18+
}
19+
20+
/**
21+
* Transforms a log level into a comparable (numerical) value ordered by severity.
22+
*/
23+
export function logLevelSeverity(level: LogLevel): number {
24+
switch (level) {
25+
case LogLevel.DEBUG:
26+
return 20
27+
case LogLevel.INFO:
28+
return 40
29+
case LogLevel.WARN:
30+
return 60
31+
case LogLevel.ERROR:
32+
return 80
33+
default:
34+
return assertNever(level)
35+
}
36+
}

src/type-utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* Utilities for working with typescript types
3+
*/
4+
5+
/**
6+
* Assert U is assignable to T.
7+
*/
8+
export type Assert<T, U extends T> = U

src/utils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Utility for enforcing exhaustiveness checks in the type system.
3+
*
4+
* @see https://basarat.gitbook.io/typescript/type-system/discriminated-unions#throw-in-exhaustive-checks
5+
*
6+
* @param value The variable with no remaining values
7+
*/
8+
export function assertNever(value: never): never {
9+
throw new Error(`Unexpected value should never occur: ${value}`)
10+
}
11+
12+
type AllKeys<T> = T extends unknown ? keyof T : never
13+
14+
export function pick<O, K extends AllKeys<O>>(
15+
base: O,
16+
keys: readonly K[]
17+
): Pick<O, K> {
18+
const entries = keys.map(key => [key, base?.[key]])
19+
return Object.fromEntries(entries)
20+
}
21+
22+
export function isObject(o: unknown): o is Record<PropertyKey, unknown> {
23+
return typeof o === "object" && o !== null
24+
}

0 commit comments

Comments
 (0)