@decaf-ts/for-http 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Tiago Venceslau
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,297 @@
1
+ ![Banner](./workdocs/assets/Banner.png)
2
+ ## Typescript Template
3
+
4
+
5
+
6
+ ![Licence](https://img.shields.io/github/license/decaf-ts/ts-workspace.svg?style=plastic)
7
+ ![GitHub language count](https://img.shields.io/github/languages/count/decaf-ts/ts-workspace?style=plastic)
8
+ ![GitHub top language](https://img.shields.io/github/languages/top/decaf-ts/ts-workspace?style=plastic)
9
+ [![Tests](https://github.com/decaf-ts/ts-workspace/actions/workflows/jest-test.yaml/badge.svg)](http://www.pdmfc.com)
10
+ [![CodeQL](https://github.com/starnowski/posmulten/workflows/CodeQL/badge.svg)](https://github.com/decaf-ts/ts-workspace/actions?query=workflow%3ACodeQL)
11
+
12
+ ![Open Issues](https://img.shields.io/github/issues/decaf-ts/ts-workspace.svg)
13
+ ![Closed Issues](https://img.shields.io/github/issues-closed/decaf-ts/ts-workspace.svg)
14
+ ![Pull Requests](https://img.shields.io/github/issues-pr-closed/decaf-ts/ts-workspace.svg)
15
+ ![Maintained](https://img.shields.io/badge/Maintained%3F-yes-green.svg)
16
+
17
+ ![Line Coverage](workdocs/coverage/badge-lines.svg)
18
+ ![Function Coverage](workdocs/coverage/badge-functions.svg)
19
+ ![Statement Coverage](workdocs/coverage/badge-statements.svg)
20
+ ![Branch Coverage](workdocs/coverage/badge-branches.svg)
21
+
22
+
23
+ ![Forks](https://img.shields.io/github/forks/decaf-ts/ts-workspace.svg)
24
+ ![Stars](https://img.shields.io/github/stars/decaf-ts/ts-workspace.svg)
25
+ ![Watchers](https://img.shields.io/github/watchers/decaf-ts/ts-workspace.svg)
26
+
27
+ ![Node Version](https://img.shields.io/badge/dynamic/json.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbadges%2Fshields%2Fmaster%2Fpackage.json&label=Node&query=$.engines.node&colorB=blue)
28
+ ![NPM Version](https://img.shields.io/badge/dynamic/json.svg?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbadges%2Fshields%2Fmaster%2Fpackage.json&label=NPM&query=$.engines.npm&colorB=purple)
29
+
30
+ Defaults to module, but exports to CommonJS and ESM.
31
+
32
+ With documentation, update and release mechanisms and gitlab/github workflows to match;
33
+
34
+ Defines a 'way' to write jsDocs to optimize the output
35
+
36
+ Optimized for github in terms of badges. CI is equivalent between Gitlab and Github.
37
+
38
+ Auto setup on first `npm install`
39
+
40
+ Will accept a `.token` file containing token valid for private npm dependencies, npm and docker registries
41
+
42
+ ### ***Initial Setup***
43
+
44
+ #### if you use github
45
+
46
+ create a new project using this one as a template.
47
+
48
+ clone it `git clone <project>` and navigate to the root folder `cd <project>`
49
+
50
+ #### If your project has private dependencies or publishes to private npm registries, create an `.npmrc` containing:
51
+
52
+ ```text
53
+ @<scope1>:registry=https://<ADDRESS>.com/api/v4/packages/npm/
54
+ @<scope2>:registry=https://<ADDRESS>.<DOMAIN>.com/api/v4/packages/npm/
55
+ //<ADDRESS>.<DOMAIN>.com/:_authToken=${TOKEN}
56
+ //<ADDRESS>.<DOMAIN>.com/api/v4/groups/<GROUP_ID>/packages/npm/:_authToken=${TOKEN}
57
+ //<ADDRESS>.<DOMAIN>.com/api/v4/projects/<PROJECT_ID>/packages/npm/:_authToken=${TOKEN}
58
+ ```
59
+
60
+ Changing:
61
+ - <ADDRESS> to `gitlab` or `github` (or other);
62
+ - <DOMAIN> to your domain if any (if you are using plain gitlab or github use empty and take care to remove the extra `.`);
63
+ - <GROUP_ID> to your project's group id (if any). otherwise remove this line
64
+ - <PROJECT_ID> to your project's id
65
+
66
+ and adding a `.token` file containing your access token to the private registries na repositories.
67
+
68
+ ### Installation
69
+
70
+ Run `npm install` (or `npm run do-install` if you have private dependencies and a `.token` file) to install the dependencies:
71
+
72
+ If this is the first time you are running this command it will also:
73
+ - update this repository's dependencies to their latest version;
74
+ - creates a `.token` file which you can leave empty unless you have private dependencies or publish to private registries
75
+ - delete this 'first run script' file and npm call from the `package.json`;
76
+ - try to commit the updated `package.json` and deleted files (having ssh access helps here);
77
+ ## Linting
78
+
79
+ This repo comes with eslint + prettier preconfigured to the default standards
80
+ ## Testing
81
+
82
+ Preconfigured Jest based testing:
83
+
84
+ - unit tests under the `tests/unit` folder;
85
+ - include a default bundle test (helps with circular dependencies and such);
86
+ - integration tests under the `tests/integration` folder;
87
+ - stores converage results under `workdocs/coverage`;
88
+ - publishes coverage result to docs;
89
+ - ignores `cli.ts` from coverage since that is an executable file;
90
+ - defines the coverage threshold in `jest.config.ts`;
91
+ ### Releases
92
+
93
+ This repository automates releases in the following manner:
94
+
95
+ - run `npm run release -- <major|minor|patch|version> <message>`:
96
+ - if arguments are missing you will be prompted for them;
97
+ - it will run `npm run prepare-release` npm script;
98
+ - it will commit all changes;
99
+ - it will push the new tag;
100
+
101
+ If publishing to a private repo's npm registry, make sure you add to your `package.json`:
102
+
103
+ ```json
104
+ {
105
+ "publishConfig": {
106
+ "<SCOPE>:registry": " https://<REGISTRY>/api/v4/projects/<PROJECT_ID>/packages/npm/"
107
+ }
108
+ }
109
+ ```
110
+
111
+ Where:
112
+
113
+ - `<SCOPE>` - Is the scope of your package;
114
+ - `<REGISTRY>` - your registry host;
115
+ - `<PROJECT_ID>` - you project ID number (easy to grab via UI in gitlab or by
116
+ running `$("meta[name=octolytics-dimension-repository_id]").getAttribute('content')` in the repository page in github)
117
+ ;
118
+
119
+ ### Publishing
120
+
121
+ Unless the `-no-ci` flag is passed in the commit message to the `npm run release` command, publishing will be handled
122
+ automatically by github/gitlab (triggered by the tag).
123
+
124
+ When the `-no-ci` flag is passed then you can:
125
+
126
+ - run `npm run publish`. This command assumes :
127
+ - you have previously run the `npm run release`;
128
+ - you have you publishing properly configured in `npmrc` and `package.json`;
129
+ - The token for any special access required is stored in the `.token` file;
130
+
131
+ ## Continuous Integration/Deployment
132
+
133
+ While the implementationfor gitlab and github are not perfectly matched, they are perfectly usable.
134
+
135
+ The template comes with ci/cd for :
136
+ - gitlab (with caching for performance):
137
+ - stages:
138
+ - dependencies: Installs dependencies (on `package-lock.json` changes, caches node modules);
139
+ - build: builds the code (on `src/*` changes, caches `lib` and `dist`);
140
+ - test: tests the code (on `src/*`, `test/*` changes, caches `workdocs/{resources, badges, coverage}`);
141
+ - deploy:
142
+ - deploys to package registry on a tag (public|private);
143
+ - deploys docker image to docker registry (private);
144
+ - Deploys the documentation to the repository pages;
145
+ - github:
146
+ - jest-test: standard `install -> build -> test` loop;
147
+ - jest-coverage: extracts coverage from the tests;
148
+ - codeql-analysis: Code quality analisys;
149
+ - pages: builds the documentation and deploys to github pages
150
+ - release-on-tag: issues a release when the tag does not contain `-no-ci` string
151
+ - publish-on-release: publishes to package registry when the tag does not contain the `-no-ci` string
152
+ - Requires Variables:
153
+ - CONSECUTIVE_ACTION_TRIGGER: secret to enable actions to trigger other actions;
154
+ - NPM_TOKEN: npm/docker registry token
155
+ ## Considerations
156
+ - Setup for a linux based environment (Sorry windows users. use WSL... or just change already);
157
+ - Setup for node 20, but will work at least with 16;
158
+ - Requires docker to build documentation (drawings and PlantUML)
159
+ ## Documentation
160
+
161
+ The repository proposes a way to generate documentation that while still not ideal, produces verys consitest results.
162
+
163
+ In the code you see an example on how to properly document each code object, but the overall structure is:
164
+ - each package is a `@module`;
165
+ - Classes and Interfaces are categorized into `@category` and `@subcategory`;
166
+ - All other objects are categorized by `@namespace` and `@memberOf`;
167
+ - Enums and const are declared as `@const` and both must describe their properties as `@property` (when constants are objects);
168
+ - Interfaces must declare their methods `@method`;
169
+
170
+ There are 3 steps the generating the documentation (automated in CI):
171
+ - `npm run drawings` - generates png files from each drawing in the `workdocs/drawings` folder and moves them to the `workdocs/resources` folder (requires Docker);
172
+ - `npm run uml` - generates png files from each PlantUML diagram in the `workdocs/uml` folder and moves them to the `workdocs/resources` folder (requires Docker);
173
+ - `npm run docs` - this has several stages, defined under the `gulp docs` (gulpfile.js):
174
+ - compiles the Readme file via md compile:
175
+ - enables keeping separate files for sections that are then joined into a single file;
176
+ - Allows keeping specific files in the jsdocs tutorial folder so they show up on their own menu;
177
+ - compiles the documentation from the source code using jsdocs:
178
+ - uses the better docs template with the category and component plugins
179
+ - uses the mermaid jsdoc plugin to embue uml diagrams in the docs
180
+ - includes a nav link to the test coverage results;
181
+ - copies the jsdoc and mds to `/docs`;
182
+ - copies the `./workdocs/{drawings, uml, assets, resources}` to `./docs`;
183
+
184
+ The produced `docs` folder contains the resulting documentation;
185
+ ### Related
186
+
187
+ [![Readme Card](https://github-readme-stats.vercel.app/api/pin/?username=decaf-ts&repo=ts-workspace)](https://github.com/decaf-ts/ts-workspace)
188
+ ### Social
189
+
190
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/decaf-ts/)
191
+ ### Scripts
192
+
193
+ The following npm scripts are available for development:
194
+
195
+ - `preinstall` - will run only on the first install to trigger the dep update. will self delete;
196
+ - `do-install` - sets a `TOKEN` environment variable to the contents of `.token` and runs npm install (useful when you
197
+ have private dependencies);
198
+ - `flash-forward` - updates all dependencies. Take care, This may not be desirable is some cases;
199
+ - `reset` - updates all dependencies. Take care, This may not be desirable is some cases;
200
+ - `build` - builds the code (via gulp `gulpfile.js`) in development mode (generates `lib` and `dist` folder);
201
+ - `build:prod` - builds the code (via gulp `gulpfile.js`) in production mode (generates `lib` and `dist` folder);
202
+ - `test` - runs unit tests;
203
+ - `test:integration` - runs it tests;
204
+ - `test:all` - runs all tests;
205
+ - `lint` - runs es lint on the code folder;
206
+ - `lint-fix` - tries to auto-fix the code folder;
207
+ - `prepare-release` - defines the commands to run prior to a new tag (defaults to linting, building production code,
208
+ running tests and documentation generation);
209
+ - `release` - triggers a new tag being pushed to master (via `./bin/tag_release.sh`);
210
+ - `clean-publish` - cleans the package.json for publishing;
211
+ - `coverage` - runs all test, calculates coverage and generates badges for readme;
212
+ - `drawings` - compiles all DrawIO `*.drawio` files in the `workdocs/drawings` folder to png and moves them to
213
+ the `workdocs/resources` folder;
214
+ - `uml` - compiles all PlantUML `*.puml` files in the `workdocs/uml` folder to png and moves them to
215
+ the `workdocs/resources` folder;
216
+ - `docs` - compiles all the coverage, drawings, uml, jsdocs and md docs into a readable web page under `./docs`;
217
+
218
+ ### Repository Structure
219
+
220
+ ```
221
+ ts-workspace
222
+
223
+ │ .gitignore <-- Defines files ignored to git
224
+ │ .npmignore <-- Defines files ignored by npm
225
+ │ .nmprc <-- Defines the Npm registry for this package
226
+ │ .eslintrc.cjs <-- linting for the project
227
+ │ .prettier.config.cjs <-- Code style for the project
228
+ │ .gitlab-ci.yml <-- Gillab CI/CD file
229
+ │ gulpfile.js <-- Gulp build scripts. used for building na other features (eg docs)
230
+ │ jest.config.ts <-- Tests Configuration file
231
+ │ mdCompile.json <-- md Documentation generation configuration file
232
+ │ jsdocs.json <-- jsdoc Documentation generation configuration file
233
+ │ Dockerfile <-- minimal example of a node service Dockerfile
234
+ │ LICENCE.md <-- Licence disclamer
235
+ │ package.json
236
+ │ package-lock.json
237
+ │ README.md <-- Readme File dynamically compiled from 'workdocs' via the 'docs' npm script
238
+ │ tsconfig.json <-- Typescript config file. Is overriden in 'gulpfile.js'
239
+
240
+ └───bin
241
+ │ │ tag_release.sh <-- Script to help with releases
242
+
243
+ └───docs
244
+ │ │ ... <-- Dinamically generated folder, containing the compiled documentation for this repository. generated via the 'docs' npm script
245
+
246
+ └───src
247
+ │ │ ... <-- Source code for this repository
248
+
249
+ └───tests
250
+ │ │───unit <-- Unit tests
251
+ │ └───integration <-- Integration tests
252
+
253
+ └───workdocs <-- Folder with all pre-compiled documentation
254
+ │ │───assets <-- Documentation asset folder
255
+ │ │───badges <-- Auto generated coverage badges folder
256
+ │ │───coverage <-- Auto generated coverage results
257
+ │ │───drawings <-- DrawIO folder. Drawings (*.drawio) here will be processed to generate documentation (requires docker)
258
+ │ │───uml <-- PlantUML folder. Diagrams (*.puml) here will be processed to generate documentation (requires docker)
259
+ │ │───tutorials <-- Tutorial folder
260
+ │ │ ... <-- Categorized *.md files that are merged to generate the final readme (via md compile)
261
+ │ │ Readme.md <-- Entry point to the README.md
262
+
263
+ └───dist
264
+ │ │ ... <-- Dinamically generated folder containing the bundles for distribution
265
+
266
+ └───lib
267
+ | ... <-- Dinamically generated folder containing the compiled code
268
+ ```
269
+
270
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
271
+ ![JavaScript](https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black)
272
+ ![NodeJS](https://img.shields.io/badge/Node.js-43853D?style=for-the-badge&logo=node.js&logoColor=white)
273
+ ![ShellScript](https://img.shields.io/badge/Shell_Script-121011?style=for-the-badge&logo=gnu-bash&logoColor=white)
274
+
275
+ ## Getting help
276
+
277
+ If you have bug reports, questions or suggestions please [create a new issue](https://github.com/decaf-ts/ts-workspace/issues/new/choose).
278
+
279
+ ## Contributing
280
+
281
+ I am grateful for any contributions made to this project. Please read [this](./workdocs/98-Contributing.md) to get started.
282
+
283
+ ## Supporting
284
+
285
+ The first and easiest way you can support it is by [Contributing](./workdocs/98-Contributing.md). Even just finding a typo in the documentation is important.
286
+
287
+ Financial support is always welcome and helps keep the both me and the project alive and healthy.
288
+
289
+ So if you can, if this project in any way. either by learning something or simply by helping you save precious time, please consider donating.
290
+
291
+ ## License
292
+
293
+ This project is released under the [MIT License](LICENSE.md).
294
+
295
+ #### Disclaimer:
296
+
297
+ badges found [here](https://dev.to/envoy_/150-badges-for-github-pnk), [here](https://github.com/alexandresanlim/Badges4-README.md-Profile#-social-) and [here](https://github.com/Ileriayo/markdown-badges)