Skip to content

Commit

Permalink
feat(inception): initial working version
Browse files Browse the repository at this point in the history
  • Loading branch information
djMax committed Jan 22, 2024
0 parents commit e35edea
Show file tree
Hide file tree
Showing 12 changed files with 9,537 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Node build, test and publish

on:
pull_request:
types: [assigned, opened, synchronize, reopened]
push:
branches:
- main

permissions:
contents: read

jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: Cleanup stale actions
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 20
cache: yarn
- name: npm install, lint, build, and test
run: |
yarn install --immutable
yarn lint
yarn build
yarn test
env:
CI: true

publish-npm:
needs: build
if: github.ref == 'refs/heads/main'
permissions:
contents: write
issues: write
id-token: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v3
with:
node-version: 20
cache: yarn
- run: yarn install --immutable
- run: yarn build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.SESAMECARE_OSS_NPM_TOKEN }}
run: |
yarn dlx semantic-release
67 changes: 67 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Custom
src/generated
.transpiled
.nyc_output
.eslintcache

# TypeScript incremental compilation cache
*.tsbuildinfo

# Stock
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
*.orig

work
/build
pids
logs
results
coverage
lib-cov
html-report
xunit.xml
node_modules
npm-debug.log

.project
.idea
.settings
.iml
*.sublime-workspace
*.sublime-project

.DS_Store*
ehthumbs.db
Icon?
Thumbs.db
.AppleDouble
.LSOverride
.Spotlight-V100
.Trashes

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

.node_repl_history

# TypeScript incremental compilation cache
*.tsbuildinfo
# Added by coconfig
.eslintignore
.npmignore
tsconfig.json
tsconfig.build.json
.prettierrc.js
.eslintrc.js
.commitlintrc.json
vitest.config.ts
14 changes: 14 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/.retool_types/**": true,
"**/*tsconfig.json": true,
".cache": true,
"retool.config.json": true
}
}
541 changes: 541 additions & 0 deletions .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs

Large diffs are not rendered by default.

875 changes: 875 additions & 0 deletions .yarn/releases/yarn-3.7.0.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.7.0.cjs
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# rate-limit



This project has been made with @sesamecare/create. You should write a glowing and detailed README about
all the things your package does.
5 changes: 5 additions & 0 deletions __tests__/config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"routing": {
"openapi": false
}
}
42 changes: 42 additions & 0 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, test } from 'vitest';
import { getReusableApp } from '@openapi-typescript-infra/service-tester';
import { useService } from '@openapi-typescript-infra/service';

import { RateLimiters } from '../src/index';

describe('Basic function', () => {
test('should limit things', async () => {
const key = `test-${Date.now()}`;
const app = await getReusableApp({ name: 'test', service: useService, rootDirectory: __dirname });
const rateLimiter = new RateLimiters(app, 'memory', {
default: {
points: 10,
duration: 1,
blockDuration: 1,
},
});

const keys = { default: key };
expect(rateLimiter.instances.default, 'should get a valid rate limiter').toBeDefined();
let status = await rateLimiter.getRemainingPoints(keys);
expect(status.default?.remainingPoints).toBeUndefined();
expect((await rateLimiter.isLimited(keys)).isLimited).toBe(false);

status = await rateLimiter.consume({ default: key });
expect(status.default?.remainingPoints).toBe(9);

status = await rateLimiter.getRemainingPoints(keys);
expect(status.default?.remainingPoints).toBe(9);

status = await rateLimiter.consume(keys, 9);
expect(status.default?.remainingPoints).toBe(0);

let limit = await rateLimiter.isLimited(keys);
expect(limit.isLimited).toBe(true);
expect(limit.causes).toEqual(['default']);

limit = await rateLimiter.consumeAndCheckLimit(keys);
expect(limit.isLimited).toBe(true);
expect(limit.causes).toEqual(['default']);
});
});
69 changes: 69 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@sesamecare-oss/rate-limit",
"version": "0.0.0",
"description": "",
"main": "build/index.js",
"types": "build/index.d.ts",
"author": "Developers <developers@sesamecare.com>",
"license": "UNLICENSED",
"packageManager": "yarn@3.7.0",
"scripts": {
"build": "tsc -p tsconfig.build.json",
"clean": "yarn dlx rimraf ./dist",
"lint": "eslint .",
"postinstall": "coconfig",
"test": "vitest"
},
"keywords": [
"typescript",
"sesame"
],
"repository": {
"type": "git",
"url": "git+https://github.com/sesamecare/rate-limit.git"
},
"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"main"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
"publishCmd": "yarn dlx pinst --disable"
}
],
"@semantic-release/npm",
"@semantic-release/github"
]
},
"config": {
"coconfig": "@openapi-typescript-infra/coconfig"
},
"devDependencies": {
"@openapi-typescript-infra/coconfig": "^4.3.0",
"@openapi-typescript-infra/service-tester": "^4.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/github": "^9.2.6",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"coconfig": "^1.4.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"typescript": "^5.3.3",
"vitest": "^1.2.1"
},
"dependencies": {
"@openapi-typescript-infra/service": "^4.12.1",
"ioredis": "^5.3.2",
"rate-limiter-flexible": "^4.0.0"
}
}
Loading

0 comments on commit e35edea

Please sign in to comment.