Skip to content

Commit

Permalink
feat(server-context): add new module
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadhonarvar committed Jun 7, 2023
1 parent cdbdce6 commit 01d843c
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 0 deletions.
26 changes: 26 additions & 0 deletions core/server-context/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.32.0](https://github.com/AliMD/alwatr/compare/v0.31.0...v0.32.0) (2023-05-27)

### Bug Fixes

- **context:** compatible with new storage api ([5251ff0](https://github.com/AliMD/alwatr/commit/5251ff005624720e091cdbc40e6b0142743428cb))

# [0.31.0](https://github.com/AliMD/alwatr/compare/v0.30.0...v0.31.0) (2023-05-08)

### Bug Fixes

- build issues ([e1060bc](https://github.com/AliMD/alwatr/commit/e1060bccbfe3c775c32b85e9b8eb601e48b2998c))
- **context:** merge request option issue ([e24e695](https://github.com/AliMD/alwatr/commit/e24e695a8c25ab1dcb1c351a3ae0434e921610d0))
- new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300))
- packages and refs ([eea2382](https://github.com/AliMD/alwatr/commit/eea2382e459ccaa3e7b4b329d9c196eda146a08e))

### Features

- **context:** add `requestIfNotComplete` ([580d5c9](https://github.com/AliMD/alwatr/commit/580d5c9c74f1c8921b45d402641df9444f438547))
- **context:** awesome server context ([c001c58](https://github.com/AliMD/alwatr/commit/c001c58a2b1b4e13fd1c34b5128031fd640a98e1))
- **context:** new package ([98ee43d](https://github.com/AliMD/alwatr/commit/98ee43d83b1ad5b3806ec6053c5cac70912000b3))
- **context:** simple context api ([2a1b152](https://github.com/AliMD/alwatr/commit/2a1b152380f267a6b173f08bbbe10295325b1fd8))
3 changes: 3 additions & 0 deletions core/server-context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Alwatr Context - `@alwatr/server-context`

Elegant powerful server-context manager base on alwatr signal, written in tiny TypeScript, ES module.
44 changes: 44 additions & 0 deletions core/server-context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@alwatr/server-context",
"version": "0.32.0",
"description": "Elegant powerful context manager base on alwatr signal, written in tiny TypeScript, ES module.",
"keywords": [
"context",
"server-context",
"signal",
"typescript",
"esm",
"alwatr"
],
"main": "index.js",
"type": "module",
"types": "index.d.ts",
"author": "S. Ali Mihandoost <[email protected]> (https://ali.mihandoost.com)",
"license": "MIT",
"files": [
"**/*.{d.ts.map,d.ts,js.map,js,html,md}"
],
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/AliMD/alwatr",
"directory": "core/server-context"
},
"homepage": "https://github.com/AliMD/alwatr/tree/main/core/server-context#readme",
"bugs": {
"url": "https://github.com/AliMD/alwatr/issues"
},
"dependencies": {
"@alwatr/fetch": "^0.32.0",
"@alwatr/fsm": "^0.32.0",
"@alwatr/logger": "^0.32.0",
"@alwatr/signal": "^0.32.0",
"@alwatr/util": "^0.32.0",
"tslib": "^2.5.2"
},
"devDependencies": {
"@alwatr/type": "^0.32.0"
}
}
1 change: 1 addition & 0 deletions core/server-context/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
28 changes: 28 additions & 0 deletions core/server-context/src/server-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {AlwatrBaseSignal} from '@alwatr/signal2';
import {FiniteStateMachine} from '@alwatr/fsm2';

import type { FetchOptions } from '../../fetch/src/type.js';

export interface ServerRequestConfig extends FetchOptions {
name: string;
}

export class AlwatrServerRequest<TResponse> extends AlwatrBaseSignal<TResponse> {
stateMachine = new FiniteStateMachine({
initial: '',
});

constructor(protected _config: ServerRequestConfig) {
super(_config.name, 'srv-request');
}

request(): void (
fsm: FsmConsumerInterface<ServerContextFsm>,
options?: ServerContextFsm['TContext']['options'],
mergeOption = true,
): void => {
logger.logMethodArgs?.('request', fsm.id);
if (options != null) setOptions(fsm, options, mergeOption);
fsm.transition('REQUEST');
};
}
19 changes: 19 additions & 0 deletions core/server-context/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base",
"compilerOptions": {
"composite": true,
"tsBuildInfoFile": ".tsbuildinfo",
"rootDir": "src",
"outDir": "."
},

"include": ["src/**/*.ts"],
"exclude": [],
"references": [
{"path": "../logger"},
{"path": "../signal2"},
{"path": "../fetch"},
{"path": "../fsm2"},
{"path": "../type"}
]
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{"path": "./core/signal"},
{"path": "./core/signal2"},
{"path": "./core/context"},
{"path": "./core/server-context"},
{"path": "./core/router"},
{"path": "./core/i18n"},
{"path": "./core/math"},
Expand Down

0 comments on commit 01d843c

Please sign in to comment.