@cedvict/http-guardian-rx 0.0.1-next.5 → 0.0.1-next.7

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/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on *Keep a Changelog*, and this project adheres to *Semantic Versioning*.
6
+
7
+ ## 1.0.0 - 2026-02-22
8
+
9
+ - Align with @cedvict/http-guardian 1.0.0
10
+ - Node >= 22
11
+ - Switch to peerDependencies for core + rxjs
12
+ - Adapter behavior unchanged
13
+
14
+ ## Unreleased
15
+
16
+ - Initial public release of the `@cedvict/http-guardian` workspace.
package/LICENSE CHANGED
@@ -1 +1,21 @@
1
- MIT
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cedvict
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 CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  RxJS adapter for `@cedvict/http-guardian`.
4
4
 
5
+ ## Requirements
6
+
7
+ - Node >= 22
8
+ - @cedvict/http-guardian ^1.0.0
9
+ - rxjs >=7 <9
10
+
11
+ ## Behavior
12
+
13
+ - Unsubscribing from the Observable aborts the underlying HTTP request.
14
+ - Uses AbortController (native in Node >=22).
15
+
5
16
  ## Install
6
17
  ```bash
7
18
  npm i @cedvict/http-guardian @cedvict/http-guardian-rx rxjs
package/dist/index.cjs ADDED
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ var rxjs = require('rxjs');
4
+
5
+ // src/rxClient.ts
6
+ function toObservableClient(api) {
7
+ return {
8
+ get$: (path, ro) => request$(api.get, path, ro),
9
+ post$: (path, ro) => request$(api.post, path, ro),
10
+ put$: (path, ro) => request$(api.put, path, ro),
11
+ patch$: (path, ro) => request$(api.patch, path, ro),
12
+ delete$: (path, ro) => request$(api.delete, path, ro)
13
+ };
14
+ }
15
+ function request$(fn, path, ro) {
16
+ return rxjs.defer(() => {
17
+ const ac = new AbortController();
18
+ const merged = { ...ro ?? {}, signal: ro?.signal ? anySignal([ro.signal, ac.signal]) : ac.signal };
19
+ const p = fn(path, merged);
20
+ return new rxjs.Observable((subscriber) => {
21
+ p.then((v) => {
22
+ subscriber.next(v);
23
+ subscriber.complete();
24
+ }).catch((e) => subscriber.error(e));
25
+ return () => ac.abort();
26
+ });
27
+ });
28
+ }
29
+ function anySignal(signals) {
30
+ const controller = new AbortController();
31
+ const onAbort = () => controller.abort();
32
+ for (const s of signals) {
33
+ if (s.aborted) controller.abort();
34
+ s.addEventListener("abort", onAbort, { once: true });
35
+ }
36
+ return controller.signal;
37
+ }
38
+
39
+ exports.toObservableClient = toObservableClient;
40
+ //# sourceMappingURL=index.cjs.map
41
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/rxClient.ts"],"names":["defer","Observable"],"mappings":";;;;;AAmBO,SAAS,mBAAmB,G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AClC,MAAA,OAAO,MAAM,GAAG,KAAA,EAAM;AAAA,IACxB,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AACH;AAEA,SAAS,UAAU,OAAA,EAAqC;AACtD,EAAA,MAAM,UAAA,GAAa,IAAI,eAAA,EAAgB;AACvC,EAAA,MAAM,OAAA,GAAU,MAAM,UAAA,CAAW,KAAA,EAAM;AACvC,EAAA,KAAA,MAAW,KAAK,OAAA,EAAS;AACvB,IAAA,IAAI,CAAA,CAAE,OAAA,EAAS,UAAA,CAAW,KAAA,EAAM;AAChC,IAAA,CAAA,CAAE,iBAAiB,OAAA,EAAS,OAAA,EAAS,EAAE,IAAA,EAAM,MAAM,CAAA;AAAA,EACrD;AACA,EAAA,OAAO,UAAA,CAAW,MAAA;AACpB","file":"index.cjs","sourcesContent":["import { defer, Observable } from \"rxjs\";\nimport type { ClientResult, RequestOptions } from \"@cedvict/http-guardian\";\n\n/**\n * Minimal interface of the promise client we wrap.\n */\nexport type PromiseHttpClient = {\n get: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;\n post: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;\n put: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;\n patch: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;\n delete: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;\n};\n\n/**\n * Wraps the Promise client to Observable methods.\n * - Each subscription triggers one request.\n * - Unsubscribe aborts the underlying fetch (AbortController).\n */\nexport function toObservableClient(api: PromiseHttpClient) {\n return {\n get$: <T>(path: string, ro?: RequestOptions<T>): Observable<ClientResult<T>> => request$(api.get, path, ro),\n post$: <T>(path: string, ro?: RequestOptions<T>): Observable<ClientResult<T>> => request$(api.post, path, ro),\n put$: <T>(path: string, ro?: RequestOptions<T>): Observable<ClientResult<T>> => request$(api.put, path, ro),\n patch$: <T>(path: string, ro?: RequestOptions<T>): Observable<ClientResult<T>> => request$(api.patch, path, ro),\n delete$: <T>(path: string, ro?: RequestOptions<T>): Observable<ClientResult<T>> => request$(api.delete, path, ro),\n };\n}\n\nfunction request$<T>(\n fn: <U>(path: string, ro?: RequestOptions<U>) => Promise<ClientResult<U>>,\n path: string,\n ro?: RequestOptions<T>\n): Observable<ClientResult<T>> {\n return defer(() => {\n const ac = new AbortController();\n const merged: RequestOptions<T> = { ...(ro ?? {}), signal: ro?.signal ? anySignal([ro.signal, ac.signal]) : ac.signal };\n const p = fn<T>(path, merged);\n\n return new Observable<ClientResult<T>>((subscriber) => {\n p.then((v) => { subscriber.next(v); subscriber.complete(); })\n .catch((e) => subscriber.error(e));\n return () => ac.abort();\n });\n });\n}\n\nfunction anySignal(signals: AbortSignal[]): AbortSignal {\n const controller = new AbortController();\n const onAbort = () => controller.abort();\n for (const s of signals) {\n if (s.aborted) controller.abort();\n s.addEventListener(\"abort\", onAbort, { once: true });\n }\n return controller.signal;\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import { Observable } from 'rxjs';
2
+ import { RequestOptions, ClientResult } from '@cedvict/http-guardian';
3
+
4
+ /**
5
+ * Minimal interface of the promise client we wrap.
6
+ */
7
+ type PromiseHttpClient = {
8
+ get: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
9
+ post: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
10
+ put: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
11
+ patch: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
12
+ delete: <T>(path: string, ro?: RequestOptions<T>) => Promise<ClientResult<T>>;
13
+ };
14
+ /**
15
+ * Wraps the Promise client to Observable methods.
16
+ * - Each subscription triggers one request.
17
+ * - Unsubscribe aborts the underlying fetch (AbortController).
18
+ */
19
+ declare function toObservableClient(api: PromiseHttpClient): {
20
+ get$: <T>(path: string, ro?: RequestOptions<T>) => Observable<ClientResult<T>>;
21
+ post$: <T>(path: string, ro?: RequestOptions<T>) => Observable<ClientResult<T>>;
22
+ put$: <T>(path: string, ro?: RequestOptions<T>) => Observable<ClientResult<T>>;
23
+ patch$: <T>(path: string, ro?: RequestOptions<T>) => Observable<ClientResult<T>>;
24
+ delete$: <T>(path: string, ro?: RequestOptions<T>) => Observable<ClientResult<T>>;
25
+ };
26
+
27
+ export { type PromiseHttpClient, toObservableClient };
package/package.json CHANGED
@@ -1,24 +1,29 @@
1
1
  {
2
2
  "name": "@cedvict/http-guardian-rx",
3
- "version": "0.0.1-next.5",
3
+ "version": "0.0.1-next.7",
4
4
  "description": "RxJS adapter for @cedvict/http-guardian (Observables).",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
+ "browser": "./dist/index.js",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.cjs",
9
12
  "default": "./dist/index.js"
10
13
  }
11
14
  },
12
- "main": "./dist/index.js",
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
13
17
  "types": "./dist/index.d.ts",
14
18
  "files": [
15
19
  "dist",
16
20
  "README.md",
17
- "LICENSE"
21
+ "LICENSE",
22
+ "CHANGELOG.md"
18
23
  ],
19
24
  "sideEffects": false,
20
25
  "engines": {
21
- "node": ">=18"
26
+ "node": ">=22"
22
27
  },
23
28
  "license": "MIT",
24
29
  "repository": {
@@ -29,7 +34,7 @@
29
34
  "rxjs": ">=7 <9"
30
35
  },
31
36
  "dependencies": {
32
- "@cedvict/http-guardian": "^0.0.1-next.5"
37
+ "@cedvict/http-guardian": "^0.0.1-next.7"
33
38
  },
34
39
  "scripts": {
35
40
  "build": "tsup",