-
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.
- Loading branch information
Showing
17 changed files
with
2,847 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Changesets | ||
|
||
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
||
We have a quick list of common questions to get you started engaging with this project in | ||
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
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,11 @@ | ||
{ | ||
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json", | ||
"changelog": "@changesets/cli/changelog", | ||
"commit": false, | ||
"fixed": [], | ||
"linked": [], | ||
"access": "public", | ||
"baseBranch": "main", | ||
"updateInternalDependencies": "patch", | ||
"ignore": [] | ||
} |
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,5 @@ | ||
--- | ||
"polyuse": minor | ||
--- | ||
|
||
Initial release |
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,42 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
ci: | ||
name: CI | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: pnpm | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build | ||
run: pnpm run build | ||
|
||
- name: Lint | ||
run: pnpm run lint | ||
|
||
- name: Test | ||
run: pnpm run test |
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 @@ | ||
name: Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
concurrency: ${{ github.workflow }}-${{ github.ref }} | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
cache: pnpm | ||
node-version: 20 | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Create release pull request or publish to npm | ||
uses: changesets/action@v1 | ||
with: | ||
publish: pnpm run release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,3 @@ | ||
.DS_Store | ||
node_modules | ||
dist |
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,3 @@ | ||
pnpm run build | ||
pnpm run lint | ||
pnpm run test |
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 @@ | ||
pnpm-lock.yaml |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Timofey Dergachev | ||
Copyright (c) Timofey Dergachev <[email protected]> (https://exeto.dev) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
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,93 @@ | ||
# polyuse | ||
|
||
A modular library that provides building blocks for creating your own framework. | ||
|
||
> **Note:** This package is ESM only. | ||
## Installation | ||
|
||
```bash | ||
npm install polyuse | ||
``` | ||
|
||
## Modules | ||
|
||
Currently, polyuse includes the following modules: | ||
|
||
- `ioc`: Inversion of Control container | ||
|
||
More modules will be added in future releases. | ||
|
||
## Usage | ||
|
||
### IoC Container Example | ||
|
||
```typescript | ||
import { | ||
createContainer, | ||
createSingletonFactory, | ||
createTransientFactory, | ||
} from "polyuse/ioc"; | ||
|
||
class Logger { | ||
log(message: string) { | ||
console.log(`[${new Date().toISOString()}] ${message}`); | ||
} | ||
} | ||
|
||
const loggerFactory = createSingletonFactory(() => new Logger()); | ||
|
||
class Database { | ||
constructor(private readonly logger: Logger) {} | ||
|
||
connect() { | ||
this.logger.log("Connected to database"); | ||
} | ||
|
||
query(sql: string) { | ||
this.logger.log(`Executing query: ${sql}`); | ||
} | ||
} | ||
|
||
const databaseFactory = createSingletonFactory( | ||
() => new Database(loggerFactory.create()), | ||
); | ||
|
||
class UserService { | ||
constructor( | ||
private readonly logger: Logger, | ||
private readonly database: Database, | ||
) {} | ||
|
||
createUser(username: string) { | ||
this.logger.log(`Creating user: ${username}`); | ||
this.database.query(`INSERT INTO users (username) VALUES ('${username}')`); | ||
} | ||
} | ||
|
||
const userServiceFactory = createTransientFactory( | ||
() => new UserService(loggerFactory.create(), databaseFactory.create()), | ||
); | ||
|
||
const container = createContainer({ | ||
database: databaseFactory, | ||
userService: userServiceFactory, | ||
}); | ||
|
||
// Usage | ||
container.database.connect(); | ||
|
||
const userService1 = container.resolve("userService"); | ||
const userService2 = container.resolve("userService"); | ||
|
||
userService1.createUser("alice"); | ||
userService2.createUser("bob"); | ||
``` | ||
|
||
### Getting the container type | ||
|
||
To get the type of the container for type-safe usage: | ||
|
||
```typescript | ||
type Container = typeof container; | ||
``` |
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,9 @@ | ||
import js from "@eslint/js"; | ||
import ts from "typescript-eslint"; | ||
|
||
export default [ | ||
{ files: ["**/*.{js,mjs,cjs,ts}"] }, | ||
{ ignores: ["dist"] }, | ||
js.configs.recommended, | ||
...ts.configs.recommended, | ||
]; |
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 |
---|---|---|
@@ -1,10 +1,44 @@ | ||
{ | ||
"name": "polyuse", | ||
"version": "0.0.0", | ||
"description": "A modular library that provides building blocks for creating your own framework", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Timofey Dergachev", | ||
"email": "[email protected]", | ||
"url": "https://exeto.dev" | ||
"homepage": "https://polyuse.dev", | ||
"author": "Timofey Dergachev <[email protected]> (https://exeto.dev)", | ||
"repository": "exeto/polyuse", | ||
"type": "module", | ||
"exports": { | ||
".": "./dist/index.js", | ||
"./ioc": "./dist/ioc/index.js" | ||
}, | ||
"sideEffects": false, | ||
"keywords": [ | ||
"di", | ||
"ioc" | ||
], | ||
"files": [ | ||
"dist" | ||
], | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"scripts": { | ||
"dev": "vitest", | ||
"build": "rm -rf dist && tsc", | ||
"lint": "eslint && prettier --check .", | ||
"lint:fix": "eslint --fix && prettier --write .", | ||
"test": "vitest run", | ||
"release": "pnpm run build && changeset publish", | ||
"prepare": "husky" | ||
}, | ||
"devDependencies": { | ||
"@changesets/cli": "^2.27.9", | ||
"@eslint/js": "^9.12.0", | ||
"eslint": "^9.12.0", | ||
"husky": "^9.1.6", | ||
"prettier": "^3.3.3", | ||
"typescript": "^5.6.2", | ||
"typescript-eslint": "^8.8.0", | ||
"vitest": "^2.1.2" | ||
} | ||
} |
Oops, something went wrong.