-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🚧 Current State * 🐛 Fixed issue with wrong convertions * ✨ Implemented Debounce Decorator * ✨ Implemented Throttle Decorator * 💡 Documented Debounce * ✨ Implemented Retry Decorator It ensures the return type stays unchanged. * 💡 Documented Types + Helpers * 🔧 Altered TODO Config * 🚧 Added temporary plans * ✅ Setup Jest Tests * 🐛 Fixed Issues with Debounce Decorator Both with Typings and Operation * 🚧 Current state of other decorators * ✅ Wrote basic set of tests for debounce decorator * ✅ Organized Test in describe * 🐛 Smaller fixes to type + calling * ♻️ Corrected Types & Calling * ✅ Created tests * ♻️ Fixed up throttle * 🚚 Moved Tests to folder * 🐛 Fixed imports * ✨ Implemented Broadcaster for Metrics Will be used by Metric Decorators * ✨ Implemented Counter Decorator Currently increases metric for every call * ✨ Implemented Time capture * ✅ Created Tests for counter * ♻️ Uses jest.mock for call recording * 🐛 Should not floor * ♻️ Minor * ✨ Started measure decorator * ✅ Extended Tests * ✅ Finished Tests for Transformers * ✨ Created new Counter Decorator and renamed old * ✨ Created Once Decorator * 📝 Fixed Typo * ✅ Addes tests for new counter and renamed old * ✅ Added test for throttle * ✅ Added test for once * 📝 Added Documentation * ✨ Implemented Gauge Decorator * ♻️ Exporting Decorators * ✅ Added predicate tests * 🔧 Specified Includes * 🧑💻 Added GH Action Syntax Highlighter to Devcontainer * ♻️ Renamed entry * 👷 Basic CI Setup * 👷 Forgot installing deps * 🔧 Updated Script for CI * 🔧 Updated Dependabot Config * 📝 Initial README
- Loading branch information
Showing
34 changed files
with
5,669 additions
and
880 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: CI Flow | ||
on: | ||
push: | ||
paths-ignore: | ||
- ".gitignore" | ||
- "LICENSE" | ||
- "README.md" | ||
branches: | ||
- "main" | ||
- "develop" | ||
jobs: | ||
flow: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: ['18.x', '20.x'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- name: Check Lint | ||
run: npm run check:lint | ||
- name: Check Typescript | ||
run: npm run check:tsc | ||
- name: Run Unit Tests | ||
run: npm run test:unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: PR Flow | ||
on: [pull_request] | ||
jobs: | ||
flow: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: ['18.x', '20.x'] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 2 | ||
- run: git checkout HEAD^2 | ||
if: ${{ github.event_name == 'pull_request' }} | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm ci | ||
- name: Check Lint | ||
run: npm run check:lint | ||
- name: Check Typescript | ||
run: npm run check:tsc | ||
- name: Run Unit Tests | ||
run: npm run test:unit | ||
- uses: ArtiomTr/jest-coverage-report-action@v2 | ||
with: | ||
package-manager: npm | ||
continue-on-error: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Prepare Release | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
new_version: | ||
required: true | ||
description: "SEMVER Version of the next release" | ||
type: string | ||
jobs: | ||
prepare: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: "Generate Changelog" | ||
uses: sercanuste/gitmoji-changelog-action@v1 | ||
with: | ||
add_author: true | ||
- uses: rickstaa/action-create-tag@v1 | ||
id: "tag_create" | ||
with: | ||
tag: "${{ github.event.inputs.new_version }}" | ||
message: ":bookmark: Releasing ${{ github.event.inputs.new_version }}" | ||
tag_exists_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: PR Flow | ||
on: | ||
push: # Only trigger for tags with format v**** | ||
tags: | ||
- v[0-9]+.[0-9]+.[0-9]+ | ||
jobs: | ||
flow: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
id-token: write # The OIDC ID token is used for authentication with JSR. | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.x" | ||
- run: npm ci | ||
- run: npm run check:tsc | ||
- run: npm run test:unit | ||
- run: npx jsr publish | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Debug Tests", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
"program": "${workspaceFolder}/node_modules/.bin/jest", | ||
"args": [ | ||
"--runInBand", | ||
"false" | ||
], | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ | |
"HACK", | ||
"FIXME", | ||
"TODO", | ||
"IDEA", | ||
], | ||
"todo-tree.general.statusBar": "current file", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# @templum/decorators | ||
|
||
This library is exclusively published in the JavaScript Registry ([JSR](https://jsr.io/)) and offers a variety of decorators with different functionalities. They are based on TypeScript 5.0 decorators and don't require the legacy flag. | ||
|
||
## Installation | ||
|
||
Deno: | ||
```sh | ||
deno add @templum/decorators | ||
``` | ||
|
||
NPM (use any of npx, yarn dlx, pnpm dlx, or bunx): | ||
```sh | ||
npx jsr add @templum/decorators | ||
``` | ||
|
||
Afterwards can be used like any ESModule: | ||
```TypeScript | ||
import { Once } from "@templum/decorators"; | ||
|
||
class Test { | ||
@Once() | ||
public init(): void { | ||
... | ||
} | ||
} | ||
``` | ||
|
||
## Documentation | ||
|
||
Follows... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Debounce } from "../../lib/execution/debounce.js"; | ||
import { UnitOfTime } from "../../lib/util/types.js"; | ||
|
||
class Test { | ||
constructor(private spy: jest.Mock){} | ||
|
||
@Debounce(5, UnitOfTime.Millisecond) | ||
public increment(): void { | ||
this.spy(); | ||
} | ||
} | ||
|
||
describe('Debounce Decorator', () => { | ||
test('should call through if not in debounce window', async () => { | ||
const callRecorder = jest.fn(); | ||
const target = new Test(callRecorder); | ||
|
||
target.increment(); | ||
expect(callRecorder).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should block additional calls while in debounce window', async () => { | ||
const callRecorder = jest.fn(); | ||
const target = new Test(callRecorder); | ||
|
||
target.increment(); | ||
target.increment(); | ||
target.increment(); | ||
target.increment(); | ||
target.increment(); | ||
|
||
expect(callRecorder).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should allow a call after debounce window passed', async () => { | ||
const callRecorder = jest.fn(); | ||
const target = new Test(callRecorder) | ||
|
||
target.increment(); | ||
target.increment(); | ||
target.increment(); | ||
|
||
expect(callRecorder).toHaveBeenCalledTimes(1); | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
|
||
target.increment(); | ||
target.increment(); | ||
target.increment(); | ||
|
||
expect(callRecorder).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Once } from "../../lib/execution/once"; | ||
|
||
|
||
class Test { | ||
constructor(private spy: jest.Mock){} | ||
|
||
@Once() | ||
public init(): void { | ||
this.spy(); | ||
} | ||
|
||
@Once(true) | ||
public strictInit(): void { | ||
this.spy(); | ||
} | ||
} | ||
|
||
|
||
describe('Once Decorator', () => { | ||
test('should call original method once and drop further calls if force=false', async () => { | ||
const callRecorder = jest.fn(); | ||
const target = new Test(callRecorder); | ||
|
||
target.init(); | ||
target.init(); | ||
|
||
expect(callRecorder).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('should call original method once and raise error for further calls if force=true', async () => { | ||
const callRecorder = jest.fn(); | ||
const target = new Test(callRecorder); | ||
|
||
target.strictInit(); | ||
expect(() => target.strictInit()).toThrow(`strictInit is only callable once and was already called`); | ||
expect(callRecorder).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
Oops, something went wrong.