Skip to content
This repository was archived by the owner on Jul 10, 2022. It is now read-only.

Commit 5a6184b

Browse files
author
Dominik Zogg
committed
initial commit
0 parents  commit 5a6184b

10 files changed

+184
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
package-lock.json

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2021 Dominik Zogg
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# psr-http-message
2+
3+
## Description
4+
5+
Common Http-message Interface ([PHP FIG][2] [PSR-7][3]).
6+
7+
This are the differences to the PHP version:
8+
* `ServerRequestInterface` does not contain `getServerParams` and `withUploadedFiles` / `getUploadedFiles`
9+
* `StreamInterface` is missing, duplex streams are used for `getBody` on `MessageInterface`.
10+
* `UploadedFileInterface` is missing
11+
12+
## Requirements
13+
14+
* node: 12
15+
16+
## Installation
17+
18+
Through [NPM](https://www.npmjs.com) as [@chubbyjs/psr-http-message][1].
19+
20+
```sh
21+
npm i @chubbyjs/[email protected]
22+
```
23+
24+
## Copyright
25+
26+
Typescript:
27+
* 2021 Dominik Zogg
28+
29+
PHP:
30+
* 2014 PHP Framework Interoperability Group
31+
32+
[1]: https://www.npmjs.com/package/@chubbyjs/psr-http-message
33+
34+
[2]: https://www.php-fig.org/
35+
[3]: https://www.php-fig.org/psr/psr-7/

package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@chubbyjs/psr-http-message",
3+
"version": "1.0.0",
4+
"description": "Common Http-message Interface (PHP FIG PSR-7).",
5+
"keywords": [
6+
"psr",
7+
"psr-7",
8+
"http-message-interface"
9+
],
10+
"author": "Dominik Zogg",
11+
"license": "MIT",
12+
"repository": "chubbyjs/psr-http-message",
13+
"scripts": {
14+
"cs-fix": "prettier --write src",
15+
"cs": "prettier --check src",
16+
"build": "tsc",
17+
"prepare": "rm -Rf dist && npm run build && npm run cs"
18+
},
19+
"prettier": {
20+
"printWidth": 120,
21+
"tabWidth": 4,
22+
"singleQuote": true,
23+
"trailingComma": "all"
24+
},
25+
"files": [
26+
"dist"
27+
],
28+
"engines": {
29+
"node": ">=12"
30+
},
31+
"devDependencies": {
32+
"@types/node": "12",
33+
"prettier": "2.1.2",
34+
"typescript": "^4.0.5"
35+
},
36+
"publishConfig": {
37+
"access": "public"
38+
}
39+
}

src/MessageInterface.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Duplex } from 'stream';
2+
3+
interface MessageInterface {
4+
getProtocolVersion(): string;
5+
withProtocolVersion(version: string): MessageInterface;
6+
getHeaders(): Map<string, Array<string>>;
7+
hasHeader(name: string): boolean;
8+
getHeader(name: string): Array<string>;
9+
getHeaderLine(name: string): string;
10+
withHeader(name: string, value: Array<string> | string): MessageInterface;
11+
withAddedHeader(name: string, value: Array<string> | string): MessageInterface;
12+
withoutHeader(name: string): MessageInterface;
13+
getBody(): Duplex;
14+
withBody(body: Duplex): MessageInterface;
15+
}
16+
17+
export default MessageInterface;

src/RequestInterface.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import MessageInterface from './MessageInterface';
2+
import UriInterface from './UriInterface';
3+
4+
interface RequestInterface extends MessageInterface {
5+
getRequestTarget(): string;
6+
withRequestTarget(requestTarget: string): RequestInterface;
7+
getMethod(): string;
8+
withMethod(name: string): RequestInterface;
9+
getUri(): UriInterface;
10+
withUri(uri: UriInterface, preserveHost?: boolean): RequestInterface;
11+
}
12+
13+
export default RequestInterface;

src/ResponseInterface.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import MessageInterface from './MessageInterface';
2+
3+
interface ResponseInterface extends MessageInterface {
4+
getStatusCode(): number;
5+
withStatus(code: number, reasonPhrase?: string): ResponseInterface;
6+
getReasonPhrase(): string;
7+
}
8+
9+
export default ResponseInterface;

src/ServerRequestInterface.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import RequestInterface from './RequestInterface';
2+
3+
export type QueryParams = Map<string, string | Array<string> | QueryParams>;
4+
export type ParsedBody = Map<string, ParsedBody> | Array<ParsedBody> | string | number | boolean | null;
5+
6+
interface ServerRequestInterface extends RequestInterface {
7+
getCookieParams(): Map<string, string>;
8+
withCookieParams(cookieParams: Map<string, string>): ServerRequestInterface;
9+
getQueryParams(): QueryParams;
10+
withQueryParams(queryParams: QueryParams): ServerRequestInterface;
11+
getParsedBody(): ParsedBody | undefined;
12+
withParsedBody(parsedBody: ParsedBody | undefined): ServerRequestInterface;
13+
getAttributes(): Map<string, unknown>;
14+
getAttribute(name: string, defaultValue: unknown): unknown;
15+
withAttribute(name: string, value: unknown): ServerRequestInterface;
16+
withoutAttribute(name: string): ServerRequestInterface;
17+
}
18+
19+
export default ServerRequestInterface;

src/UriInterface.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
interface UriInterface {
2+
getSchema(): string;
3+
getAuthority(): string;
4+
getUserInfo(): string;
5+
getHost(): string;
6+
getPort(): number | undefined;
7+
getPath(): string;
8+
getQuery(): string;
9+
getFragment(): string;
10+
withScheme(scheme: string): UriInterface;
11+
withUserInfo(user: string, password?: string): UriInterface;
12+
withHost(scheme: string): UriInterface;
13+
withPort(port?: number): UriInterface;
14+
withPath(scheme: string): UriInterface;
15+
withQuery(scheme: string): UriInterface;
16+
withFragment(scheme: string): UriInterface;
17+
toString(): string;
18+
}
19+
20+
export default UriInterface;

tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2019",
4+
"module": "commonjs",
5+
"outDir": "dist",
6+
"strict": true,
7+
"declaration": true,
8+
},
9+
"include": ["src"]
10+
}

0 commit comments

Comments
 (0)