diff --git a/core/server-context/CHANGELOG.md b/core/server-context/CHANGELOG.md new file mode 100644 index 000000000..e3c9de5ee --- /dev/null +++ b/core/server-context/CHANGELOG.md @@ -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)) diff --git a/core/server-context/README.md b/core/server-context/README.md new file mode 100644 index 000000000..e79f97457 --- /dev/null +++ b/core/server-context/README.md @@ -0,0 +1,3 @@ +# Alwatr Context - `@alwatr/server-context` + +Elegant powerful server-context manager base on alwatr signal, written in tiny TypeScript, ES module. diff --git a/core/server-context/package.json b/core/server-context/package.json new file mode 100644 index 000000000..33dd7fd46 --- /dev/null +++ b/core/server-context/package.json @@ -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 (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" + } +} diff --git a/core/server-context/src/index.ts b/core/server-context/src/index.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/core/server-context/src/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/core/server-context/src/server-context.ts b/core/server-context/src/server-context.ts new file mode 100644 index 000000000..6a3ee1ac8 --- /dev/null +++ b/core/server-context/src/server-context.ts @@ -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 extends AlwatrBaseSignal { + stateMachine = new FiniteStateMachine({ + initial: '', + }); + + constructor(protected _config: ServerRequestConfig) { + super(_config.name, 'srv-request'); + } + + request(): void ( + fsm: FsmConsumerInterface, + options?: ServerContextFsm['TContext']['options'], + mergeOption = true, +): void => { + logger.logMethodArgs?.('request', fsm.id); + if (options != null) setOptions(fsm, options, mergeOption); + fsm.transition('REQUEST'); +}; +} diff --git a/core/server-context/tsconfig.json b/core/server-context/tsconfig.json new file mode 100644 index 000000000..eb5bac5be --- /dev/null +++ b/core/server-context/tsconfig.json @@ -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"} + ] +} diff --git a/tsconfig.json b/tsconfig.json index 9b17e1446..33fb91887 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"},