@telperion/ng-pack 1.4.2 → 1.5.0
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/README.md +2 -1
- package/fesm2022/telperion-ng-pack-sse-client.mjs +32 -1
- package/fesm2022/telperion-ng-pack-sse-client.mjs.map +1 -1
- package/fesm2022/telperion-ng-pack-utils.mjs +1 -1
- package/fesm2022/telperion-ng-pack-utils.mjs.map +1 -1
- package/package.json +3 -3
- package/sse-client/README.md +37 -0
- package/types/telperion-ng-pack-sse-client.d.ts +17 -1
package/README.md
CHANGED
|
@@ -126,11 +126,12 @@ Angular service for Server-Sent Events (SSE) with RxJS Observables and HttpClien
|
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
128
|
import { ApplicationConfig } from '@angular/core';
|
|
129
|
-
import { provideSseClient, withSseInterceptors } from '@telperion/ng-pack/sse-client';
|
|
129
|
+
import { provideSseClient, withSseInterceptors, withBaseInit } from '@telperion/ng-pack/sse-client';
|
|
130
130
|
|
|
131
131
|
export const appConfig: ApplicationConfig = {
|
|
132
132
|
providers: [
|
|
133
133
|
provideSseClient(
|
|
134
|
+
withBaseInit({ withCredentials: true }),
|
|
134
135
|
withSseInterceptors(loggingInterceptor, authInterceptor)
|
|
135
136
|
),
|
|
136
137
|
]
|
|
@@ -10,6 +10,37 @@ var SseFeatureKind;
|
|
|
10
10
|
SseFeatureKind[SseFeatureKind["InterceptorFunction"] = 0] = "InterceptorFunction";
|
|
11
11
|
})(SseFeatureKind || (SseFeatureKind = {}));
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Configures default EventSource initialization options for the SSE client.
|
|
15
|
+
* Merges the provided options into every SSE request's `init` via an interceptor.
|
|
16
|
+
*
|
|
17
|
+
* @param init - Partial EventSource initialization options to apply as defaults
|
|
18
|
+
* @returns Array of SSE features to be used with `provideSseClient()`
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* provideSseClient(
|
|
23
|
+
* withBaseInit({ withCredentials: true })
|
|
24
|
+
* )
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
function withBaseInit(init) {
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
kind: SseFeatureKind.InterceptorFunction,
|
|
31
|
+
interceptor(req, next) {
|
|
32
|
+
return next({
|
|
33
|
+
...req,
|
|
34
|
+
init: {
|
|
35
|
+
...req.init,
|
|
36
|
+
...init
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
13
44
|
/**
|
|
14
45
|
* Configures functional interceptors for the SSE client.
|
|
15
46
|
* Interceptors are executed in the order they are provided.
|
|
@@ -148,5 +179,5 @@ function provideSseClient(...features) {
|
|
|
148
179
|
* Generated bundle index. Do not edit.
|
|
149
180
|
*/
|
|
150
181
|
|
|
151
|
-
export { SSE_INTERCEPTORS, SseClient, SseFeatureKind, provideSseClient, withSseInterceptors };
|
|
182
|
+
export { SSE_INTERCEPTORS, SseClient, SseFeatureKind, provideSseClient, withBaseInit, withSseInterceptors };
|
|
152
183
|
//# sourceMappingURL=telperion-ng-pack-sse-client.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telperion-ng-pack-sse-client.mjs","sources":["../../sse-client/src/features/feature.ts","../../sse-client/src/features/with-interceptors.ts","../../sse-client/src/interceptor.ts","../../sse-client/src/client.ts","../../sse-client/src/provider.ts","../../sse-client/src/telperion-ng-pack-sse-client.ts"],"sourcesContent":["/**\r\n * Enum identifying different types of SSE features.\r\n */\r\nexport enum SseFeatureKind {\r\n InterceptorFunction\r\n}\r\n\r\n/**\r\n * Base interface for SSE feature configurations.\r\n */\r\nexport interface SseFeature {\r\n kind: SseFeatureKind;\r\n}\r\n","import { SseInterceptorFn } from \"../interceptor\";\r\nimport { SseFeature, SseFeatureKind } from \"./feature\";\r\n\r\n/**\r\n * Feature interface for functional interceptors.\r\n * @internal\r\n */\r\nexport interface SseInterceptorFunctionFeature extends SseFeature {\r\n kind: SseFeatureKind.InterceptorFunction;\r\n interceptor: SseInterceptorFn<unknown>;\r\n}\r\n\r\n/**\r\n * Configures functional interceptors for the SSE client.\r\n * Interceptors are executed in the order they are provided.\r\n *\r\n * @param interceptors - One or more functional interceptor functions\r\n * @returns Array of SSE features to be used with provideSseClient()\r\n *\r\n * @example\r\n * ```typescript\r\n * const loggingInterceptor: SseInterceptorFn<any> = (req, next) => {\r\n * console.log('Connecting to:', req.url);\r\n * return next(req);\r\n * };\r\n *\r\n * provideSseClient(\r\n * withSseInterceptors(loggingInterceptor)\r\n * )\r\n * ```\r\n */\r\nexport function withSseInterceptors<T = unknown>(...interceptors: SseInterceptorFn<T>[]): SseFeature[] {\r\n return interceptors.map(interceptor => ({\r\n kind: SseFeatureKind.InterceptorFunction,\r\n interceptor,\r\n }));\r\n}\r\n","import { InjectionToken } from \"@angular/core\";\r\nimport type { Observable } from \"rxjs\";\r\n\r\n/**\r\n * Represents an SSE request with URL and initialization options.\r\n */\r\nexport interface SseRequest {\r\n url: string;\r\n init: EventSourceInit;\r\n}\r\n\r\n/**\r\n * Function type for passing the request to the next handler in the interceptor chain.\r\n */\r\nexport type SseNextFn<T> = (request: SseRequest) => Observable<T>;\r\n\r\n/**\r\n * Functional interceptor type for intercepting SSE requests.\r\n * Interceptors can modify requests, handle errors, add logging, etc.\r\n *\r\n * @example\r\n * ```typescript\r\n * const loggingInterceptor: SseInterceptorFn<any> = (req, next) => {\r\n * console.log('SSE Request:', req.url);\r\n * return next(req);\r\n * };\r\n * ```\r\n */\r\nexport type SseInterceptorFn<T> = (\r\n request: SseRequest,\r\n next: SseNextFn<T>\r\n) => Observable<T>;\r\n\r\n/**\r\n * Class-based interceptor interface for SSE requests.\r\n * Implements the same pattern as Angular's HttpInterceptor.\r\n */\r\nexport interface SseInterceptor<T = unknown> {\r\n sseIntercept<U = T>(...args: Parameters<SseInterceptorFn<U>>): ReturnType<SseInterceptorFn<U>>;\r\n}\r\n\r\n/**\r\n * Injection token for providing SSE interceptors.\r\n * Use with multi: true to provide multiple interceptors.\r\n */\r\nexport const SSE_INTERCEPTORS = new InjectionToken<SseInterceptor<unknown>[]>('Telperion/SSE_INTERCEPTORS');\r\n","import { inject, Injectable } from \"@angular/core\";\r\nimport { Observable } from \"rxjs\";\r\n\r\nimport { SSE_INTERCEPTORS, SseRequest } from \"./interceptor\";\r\n\r\n/**\r\n * Angular service for managing Server-Sent Events (SSE) connections.\r\n * Wraps the EventSource API with RxJS Observables and an HttpClient-inspired interceptor chain.\r\n *\r\n * @example\r\n * ```typescript\r\n * class MyComponent {\r\n * private sseClient = inject(SseClient);\r\n *\r\n * messages$ = this.sseClient.start<string>('/api/events');\r\n * }\r\n * ```\r\n */\r\n@Injectable()\r\nexport class SseClient {\r\n #interceptors = inject(SSE_INTERCEPTORS, { optional: true }) ?? [];\r\n\r\n constructor() {\r\n if (!(this.#interceptors instanceof Array)) {\r\n throw new Error('SSE_INTERCEPTORS must be provided as an array. Please ensure you are using multi: true when providing interceptors.');\r\n }\r\n }\r\n\r\n /**\r\n * Starts a new Server-Sent Events connection and returns an Observable stream.\r\n *\r\n * @param url - The URL endpoint for the SSE connection\r\n * @param init - Optional EventSource initialization configuration\r\n * @returns Observable stream of server-sent events\r\n *\r\n * @example\r\n * ```typescript\r\n * this.sseClient.start<MessageData>('/api/notifications', { withCredentials: true })\r\n * .subscribe(data => console.log('Received:', data));\r\n * ```\r\n */\r\n start<T>(url: string, init: EventSourceInit = {}): Observable<T> {\r\n return this.#interceptors.reduceRight(\r\n (next, interceptor) => (req) => interceptor.sseIntercept(req, next),\r\n (req: SseRequest) => this.#createEventSource(req) as Observable<T>\r\n )({ url, init });\r\n }\r\n\r\n #createEventSource<T>(request: SseRequest): Observable<T> {\r\n return new Observable<T>((subscriber) => {\r\n const eventSource = new EventSource(request.url, request.init);\r\n\r\n function handleMessage(event: MessageEvent) {\r\n subscriber.next(event.data);\r\n }\r\n\r\n function handleError(err: Event) {\r\n subscriber.error(err);\r\n eventSource.close();\r\n }\r\n\r\n eventSource.addEventListener('message', handleMessage);\r\n eventSource.addEventListener('error', handleError);\r\n\r\n return () => {\r\n eventSource.removeEventListener('message', handleMessage);\r\n eventSource.removeEventListener('error', handleError);\r\n eventSource.close();\r\n };\r\n });\r\n }\r\n}\r\n","import { Provider } from \"@angular/core\";\r\n\r\nimport { SseClient } from \"./client\";\r\nimport { SseFeature, SseFeatureKind, SseInterceptorFunctionFeature } from \"./features\";\r\nimport { SSE_INTERCEPTORS } from \"./interceptor\";\r\n\r\n/**\r\n * Provides the SseClient service with optional features.\r\n * Configure SSE client with interceptors and other features using a functional API.\r\n *\r\n * @param features - Optional feature configurations (e.g., withSseInterceptors())\r\n * @returns Array of Angular providers\r\n *\r\n * @example\r\n * ```typescript\r\n * import { provideSseClient, withSseInterceptors } from '@telperion/ng-pack/sse-client';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideSseClient(\r\n * withSseInterceptors(loggingInterceptor, authInterceptor)\r\n * )\r\n * ]\r\n * };\r\n * ```\r\n */\r\nexport function provideSseClient(...features: SseFeature[][]): Provider[] {\r\n const interceptorFns = features\r\n .flat()\r\n .filter(feature => feature.kind === SseFeatureKind.InterceptorFunction)\r\n .map(feature => ({\r\n provide: SSE_INTERCEPTORS,\r\n useValue: {\r\n sseIntercept: (feature as SseInterceptorFunctionFeature).interceptor,\r\n },\r\n multi: true,\r\n }));\r\n\r\n return [\r\n {\r\n provide: SseClient,\r\n useClass: SseClient\r\n },\r\n ...interceptorFns\r\n ];\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;;AAEG;IACS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,cAAA,CAAA,qBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,qBAAmB;A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
{"version":3,"file":"telperion-ng-pack-sse-client.mjs","sources":["../../sse-client/src/features/feature.ts","../../sse-client/src/features/with-base-init.ts","../../sse-client/src/features/with-interceptors.ts","../../sse-client/src/interceptor.ts","../../sse-client/src/client.ts","../../sse-client/src/provider.ts","../../sse-client/src/telperion-ng-pack-sse-client.ts"],"sourcesContent":["/**\r\n * Enum identifying different types of SSE features.\r\n */\r\nexport enum SseFeatureKind {\r\n InterceptorFunction\r\n}\r\n\r\n/**\r\n * Base interface for SSE feature configurations.\r\n */\r\nexport interface SseFeature {\r\n kind: SseFeatureKind;\r\n}\r\n","import { SseFeature, SseFeatureKind } from \"./feature\";\r\nimport { SseInterceptorFunctionFeature } from \"./with-interceptors\";\r\n\r\n/**\r\n * Configures default EventSource initialization options for the SSE client.\r\n * Merges the provided options into every SSE request's `init` via an interceptor.\r\n *\r\n * @param init - Partial EventSource initialization options to apply as defaults\r\n * @returns Array of SSE features to be used with `provideSseClient()`\r\n *\r\n * @example\r\n * ```typescript\r\n * provideSseClient(\r\n * withBaseInit({ withCredentials: true })\r\n * )\r\n * ```\r\n */\r\nexport function withBaseInit(init: Partial<EventSourceInit>): SseFeature[] {\r\n return [\r\n <SseInterceptorFunctionFeature>{\r\n kind: SseFeatureKind.InterceptorFunction,\r\n interceptor(req, next) {\r\n return next({\r\n ...req,\r\n init: {\r\n ...req.init,\r\n ...init\r\n }\r\n })\r\n }\r\n }\r\n ]\r\n}\r\n","import { SseInterceptorFn } from \"../interceptor\";\r\nimport { SseFeature, SseFeatureKind } from \"./feature\";\r\n\r\n/**\r\n * Feature interface for functional interceptors.\r\n * @internal\r\n */\r\nexport interface SseInterceptorFunctionFeature extends SseFeature {\r\n kind: SseFeatureKind.InterceptorFunction;\r\n interceptor: SseInterceptorFn<unknown>;\r\n}\r\n\r\n/**\r\n * Configures functional interceptors for the SSE client.\r\n * Interceptors are executed in the order they are provided.\r\n *\r\n * @param interceptors - One or more functional interceptor functions\r\n * @returns Array of SSE features to be used with provideSseClient()\r\n *\r\n * @example\r\n * ```typescript\r\n * const loggingInterceptor: SseInterceptorFn<any> = (req, next) => {\r\n * console.log('Connecting to:', req.url);\r\n * return next(req);\r\n * };\r\n *\r\n * provideSseClient(\r\n * withSseInterceptors(loggingInterceptor)\r\n * )\r\n * ```\r\n */\r\nexport function withSseInterceptors<T = unknown>(...interceptors: SseInterceptorFn<T>[]): SseFeature[] {\r\n return interceptors.map(interceptor => ({\r\n kind: SseFeatureKind.InterceptorFunction,\r\n interceptor,\r\n }));\r\n}\r\n","import { InjectionToken } from \"@angular/core\";\r\nimport type { Observable } from \"rxjs\";\r\n\r\n/**\r\n * Represents an SSE request with URL and initialization options.\r\n */\r\nexport interface SseRequest {\r\n url: string;\r\n init: EventSourceInit;\r\n}\r\n\r\n/**\r\n * Function type for passing the request to the next handler in the interceptor chain.\r\n */\r\nexport type SseNextFn<T> = (request: SseRequest) => Observable<T>;\r\n\r\n/**\r\n * Functional interceptor type for intercepting SSE requests.\r\n * Interceptors can modify requests, handle errors, add logging, etc.\r\n *\r\n * @example\r\n * ```typescript\r\n * const loggingInterceptor: SseInterceptorFn<any> = (req, next) => {\r\n * console.log('SSE Request:', req.url);\r\n * return next(req);\r\n * };\r\n * ```\r\n */\r\nexport type SseInterceptorFn<T> = (\r\n request: SseRequest,\r\n next: SseNextFn<T>\r\n) => Observable<T>;\r\n\r\n/**\r\n * Class-based interceptor interface for SSE requests.\r\n * Implements the same pattern as Angular's HttpInterceptor.\r\n */\r\nexport interface SseInterceptor<T = unknown> {\r\n sseIntercept<U = T>(...args: Parameters<SseInterceptorFn<U>>): ReturnType<SseInterceptorFn<U>>;\r\n}\r\n\r\n/**\r\n * Injection token for providing SSE interceptors.\r\n * Use with multi: true to provide multiple interceptors.\r\n */\r\nexport const SSE_INTERCEPTORS = new InjectionToken<SseInterceptor<unknown>[]>('Telperion/SSE_INTERCEPTORS');\r\n","import { inject, Injectable } from \"@angular/core\";\r\nimport { Observable } from \"rxjs\";\r\n\r\nimport { SSE_INTERCEPTORS, SseRequest } from \"./interceptor\";\r\n\r\n/**\r\n * Angular service for managing Server-Sent Events (SSE) connections.\r\n * Wraps the EventSource API with RxJS Observables and an HttpClient-inspired interceptor chain.\r\n *\r\n * @example\r\n * ```typescript\r\n * class MyComponent {\r\n * private sseClient = inject(SseClient);\r\n *\r\n * messages$ = this.sseClient.start<string>('/api/events');\r\n * }\r\n * ```\r\n */\r\n@Injectable()\r\nexport class SseClient {\r\n #interceptors = inject(SSE_INTERCEPTORS, { optional: true }) ?? [];\r\n\r\n constructor() {\r\n if (!(this.#interceptors instanceof Array)) {\r\n throw new Error('SSE_INTERCEPTORS must be provided as an array. Please ensure you are using multi: true when providing interceptors.');\r\n }\r\n }\r\n\r\n /**\r\n * Starts a new Server-Sent Events connection and returns an Observable stream.\r\n *\r\n * @param url - The URL endpoint for the SSE connection\r\n * @param init - Optional EventSource initialization configuration\r\n * @returns Observable stream of server-sent events\r\n *\r\n * @example\r\n * ```typescript\r\n * this.sseClient.start<MessageData>('/api/notifications', { withCredentials: true })\r\n * .subscribe(data => console.log('Received:', data));\r\n * ```\r\n */\r\n start<T>(url: string, init: EventSourceInit = {}): Observable<T> {\r\n return this.#interceptors.reduceRight(\r\n (next, interceptor) => (req) => interceptor.sseIntercept(req, next),\r\n (req: SseRequest) => this.#createEventSource(req) as Observable<T>\r\n )({ url, init });\r\n }\r\n\r\n #createEventSource<T>(request: SseRequest): Observable<T> {\r\n return new Observable<T>((subscriber) => {\r\n const eventSource = new EventSource(request.url, request.init);\r\n\r\n function handleMessage(event: MessageEvent) {\r\n subscriber.next(event.data);\r\n }\r\n\r\n function handleError(err: Event) {\r\n subscriber.error(err);\r\n eventSource.close();\r\n }\r\n\r\n eventSource.addEventListener('message', handleMessage);\r\n eventSource.addEventListener('error', handleError);\r\n\r\n return () => {\r\n eventSource.removeEventListener('message', handleMessage);\r\n eventSource.removeEventListener('error', handleError);\r\n eventSource.close();\r\n };\r\n });\r\n }\r\n}\r\n","import { Provider } from \"@angular/core\";\r\n\r\nimport { SseClient } from \"./client\";\r\nimport { SseFeature, SseFeatureKind, SseInterceptorFunctionFeature } from \"./features\";\r\nimport { SSE_INTERCEPTORS } from \"./interceptor\";\r\n\r\n/**\r\n * Provides the SseClient service with optional features.\r\n * Configure SSE client with interceptors and other features using a functional API.\r\n *\r\n * @param features - Optional feature configurations (e.g., withSseInterceptors())\r\n * @returns Array of Angular providers\r\n *\r\n * @example\r\n * ```typescript\r\n * import { provideSseClient, withSseInterceptors } from '@telperion/ng-pack/sse-client';\r\n *\r\n * export const appConfig: ApplicationConfig = {\r\n * providers: [\r\n * provideSseClient(\r\n * withSseInterceptors(loggingInterceptor, authInterceptor)\r\n * )\r\n * ]\r\n * };\r\n * ```\r\n */\r\nexport function provideSseClient(...features: SseFeature[][]): Provider[] {\r\n const interceptorFns = features\r\n .flat()\r\n .filter(feature => feature.kind === SseFeatureKind.InterceptorFunction)\r\n .map(feature => ({\r\n provide: SSE_INTERCEPTORS,\r\n useValue: {\r\n sseIntercept: (feature as SseInterceptorFunctionFeature).interceptor,\r\n },\r\n multi: true,\r\n }));\r\n\r\n return [\r\n {\r\n provide: SseClient,\r\n useClass: SseClient\r\n },\r\n ...interceptorFns\r\n ];\r\n}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAAA;;AAEG;IACS;AAAZ,CAAA,UAAY,cAAc,EAAA;AACxB,IAAA,cAAA,CAAA,cAAA,CAAA,qBAAA,CAAA,GAAA,CAAA,CAAA,GAAA,qBAAmB;AACrB,CAAC,EAFW,cAAc,KAAd,cAAc,GAAA,EAAA,CAAA,CAAA;;ACA1B;;;;;;;;;;;;;AAaG;AACG,SAAU,YAAY,CAAC,IAA8B,EAAA;IACzD,OAAO;AAC0B,QAAA;YAC7B,IAAI,EAAE,cAAc,CAAC,mBAAmB;YACxC,WAAW,CAAC,GAAG,EAAE,IAAI,EAAA;AACnB,gBAAA,OAAO,IAAI,CAAC;A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Q,EAAE;AACX,SAAA;AACD,QAAA,GAAG;KACJ;AACH;;AC7CA;;AAEG;;;;"}
|
|
@@ -3,7 +3,7 @@ import { forwardRef, Inject, Injectable, inject } from '@angular/core';
|
|
|
3
3
|
import { DOCUMENT } from '@angular/common';
|
|
4
4
|
import { EventManagerPlugin, EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
|
|
5
5
|
import { HttpClient } from '@angular/common/http';
|
|
6
|
-
import { tryCatch } from '@
|
|
6
|
+
import { tryCatch } from '@telperion/js-utils/promise/try-catch';
|
|
7
7
|
import { firstValueFrom } from 'rxjs';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telperion-ng-pack-utils.mjs","sources":["../../utils/src/provide-service-directive.ts","../../utils/src/event-modifiers.plugin.ts","../../utils/src/construct-fetcher.ts","../../utils/src/telperion-ng-pack-utils.ts"],"sourcesContent":["import { forwardRef, InjectionToken, Provider, Type } from \"@angular/core\";\r\n\r\n/**\r\n * Utility function to create a provider for a directive/component that can be injected as a service.\r\n * This is useful for cases where you want to inject a directive/component instance into another directive/component.\r\n *\r\n * Example usage:\r\n *\r\n * files:\r\n * - parent.directive.ts\r\n * - child.directive.ts\r\n * - parent.service.ts\r\n *\r\n * parent.service.ts:\r\n * ```\r\n * import { InjectionToken } from \"@angular/core\";\r\n * import type { ParentDirective } from \"./parent.directive\";\r\n *\r\n * export const ParentService = new InjectionToken<ParentDirective>(\"ParentService\");\r\n * ```\r\n *\r\n * parent.directive.ts:\r\n * ```\r\n * @Directive({\r\n * selector: 'parent',\r\n * providers: [provideServiceDirective(ParentService, ParentDirective)],\r\n * })\r\n * export class ParentDirective {...}\r\n * ```\r\n * child.directive.ts:\r\n * ```\r\n * @Directive({\r\n * selector: 'child',\r\n * })\r\n * export class ChildDirective {\r\n * #parent = inject(ParentService);\r\n * }\r\n * ```\r\n *\r\n * @param token - The injection token to provide.\r\n * @param directive - The directive/component class that will be provided.\r\n * @returns A provider object that can be used in the providers array of an Angular module or component.\r\n */\r\nexport function provideServiceDirective<T>(\r\n token: InjectionToken<T>,\r\n directive: Type<NoInfer<T>>\r\n): Provider {\r\n return {\r\n provide: token,\r\n useExisting: forwardRef(() => directive)\r\n }\r\n}\r\n","/**\r\n * Angular Event Manager Plugin that enables event modifier syntax in templates.\r\n *\r\n * @example\r\n * ```html\r\n * <form (submit.pd)=\"onSubmit()\">...</form>\r\n * <div (click.sp)=\"handleClick()\">...</div>\r\n * <button (click.pd.sp)=\"handleButtonClick()\">Click me</button>\r\n * ```\r\n */\r\n\r\nimport { DOCUMENT } from '@angular/common';\r\nimport { Inject, Injectable, Provider } from '@angular/core';\r\nimport { EVENT_MANAGER_PLUGINS, EventManagerPlugin } from '@angular/platform-browser';\r\n\r\n/**\r\n * Event Manager Plugin that adds support for event modifiers.\r\n * @internal\r\n */\r\n@Injectable()\r\nexport class EventModifiersPlugin extends EventManagerPlugin {\r\n /**\r\n * Supported modifiers: `pd` (preventDefault), `sp` (stopPropagation)\r\n */\r\n private static modifierMap: { [key: string]: (e: Event) => void } = {\r\n 'pd': (e: Event) => e.preventDefault(),\r\n 'sp': (e: Event) => e.stopPropagation(),\r\n };\r\n\r\n constructor(@Inject(DOCUMENT) doc: Document) {\r\n super(doc);\r\n }\r\n\r\n supports(eventName: string): boolean {\r\n return eventName.includes('.') &&\r\n eventName.split('.').some(part => part in EventModifiersPlugin.modifierMap);\r\n }\r\n\r\n addEventListener(element: HTMLElement, eventName: string, handler: (event: Event) => void): () => void {\r\n const parts = eventName.split('.');\r\n const domEventName = parts[0];\r\n const modifiers = parts.slice(1).filter(m => m in EventModifiersPlugin.modifierMap);\r\n\r\n const wrappedHandler = (event: Event) => {\r\n modifiers.forEach(mod => EventModifiersPlugin.modifierMap[mod](event));\r\n\r\n return handler(event);\r\n };\r\n\r\n element.addEventListener(domEventName, wrappedHandler);\r\n\r\n return () => element.removeEventListener(domEventName, wrappedHandler);\r\n }\r\n}\r\n\r\n/**\r\n * Provides the Event Modifiers Plugin.\r\n *\r\n * @example\r\n * ```typescript\r\n * bootstrapApplication(AppComponent, {\r\n * providers: [provideEventModifiersPlugin()]\r\n * });\r\n * ```\r\n */\r\nexport function provideEventModifiersPlugin(): Provider {\r\n return {\r\n provide: EVENT_MANAGER_PLUGINS,\r\n useClass: EventModifiersPlugin,\r\n multi: true\r\n };\r\n}\r\n","import { HttpClient } from \"@angular/common/http\";\nimport { inject } from \"@angular/core\";\nimport { AnyFunction } from '@
|
|
1
|
+
{"version":3,"file":"telperion-ng-pack-utils.mjs","sources":["../../utils/src/provide-service-directive.ts","../../utils/src/event-modifiers.plugin.ts","../../utils/src/construct-fetcher.ts","../../utils/src/telperion-ng-pack-utils.ts"],"sourcesContent":["import { forwardRef, InjectionToken, Provider, Type } from \"@angular/core\";\r\n\r\n/**\r\n * Utility function to create a provider for a directive/component that can be injected as a service.\r\n * This is useful for cases where you want to inject a directive/component instance into another directive/component.\r\n *\r\n * Example usage:\r\n *\r\n * files:\r\n * - parent.directive.ts\r\n * - child.directive.ts\r\n * - parent.service.ts\r\n *\r\n * parent.service.ts:\r\n * ```\r\n * import { InjectionToken } from \"@angular/core\";\r\n * import type { ParentDirective } from \"./parent.directive\";\r\n *\r\n * export const ParentService = new InjectionToken<ParentDirective>(\"ParentService\");\r\n * ```\r\n *\r\n * parent.directive.ts:\r\n * ```\r\n * @Directive({\r\n * selector: 'parent',\r\n * providers: [provideServiceDirective(ParentService, ParentDirective)],\r\n * })\r\n * export class ParentDirective {...}\r\n * ```\r\n * child.directive.ts:\r\n * ```\r\n * @Directive({\r\n * selector: 'child',\r\n * })\r\n * export class ChildDirective {\r\n * #parent = inject(ParentService);\r\n * }\r\n * ```\r\n *\r\n * @param token - The injection token to provide.\r\n * @param directive - The directive/component class that will be provided.\r\n * @returns A provider object that can be used in the providers array of an Angular module or component.\r\n */\r\nexport function provideServiceDirective<T>(\r\n token: InjectionToken<T>,\r\n directive: Type<NoInfer<T>>\r\n): Provider {\r\n return {\r\n provide: token,\r\n useExisting: forwardRef(() => directive)\r\n }\r\n}\r\n","/**\r\n * Angular Event Manager Plugin that enables event modifier syntax in templates.\r\n *\r\n * @example\r\n * ```html\r\n * <form (submit.pd)=\"onSubmit()\">...</form>\r\n * <div (click.sp)=\"handleClick()\">...</div>\r\n * <button (click.pd.sp)=\"handleButtonClick()\">Click me</button>\r\n * ```\r\n */\r\n\r\nimport { DOCUMENT } from '@angular/common';\r\nimport { Inject, Injectable, Provider } from '@angular/core';\r\nimport { EVENT_MANAGER_PLUGINS, EventManagerPlugin } from '@angular/platform-browser';\r\n\r\n/**\r\n * Event Manager Plugin that adds support for event modifiers.\r\n * @internal\r\n */\r\n@Injectable()\r\nexport class EventModifiersPlugin extends EventManagerPlugin {\r\n /**\r\n * Supported modifiers: `pd` (preventDefault), `sp` (stopPropagation)\r\n */\r\n private static modifierMap: { [key: string]: (e: Event) => void } = {\r\n 'pd': (e: Event) => e.preventDefault(),\r\n 'sp': (e: Event) => e.stopPropagation(),\r\n };\r\n\r\n constructor(@Inject(DOCUMENT) doc: Document) {\r\n super(doc);\r\n }\r\n\r\n supports(eventName: string): boolean {\r\n return eventName.includes('.') &&\r\n eventName.split('.').some(part => part in EventModifiersPlugin.modifierMap);\r\n }\r\n\r\n addEventListener(element: HTMLElement, eventName: string, handler: (event: Event) => void): () => void {\r\n const parts = eventName.split('.');\r\n const domEventName = parts[0];\r\n const modifiers = parts.slice(1).filter(m => m in EventModifiersPlugin.modifierMap);\r\n\r\n const wrappedHandler = (event: Event) => {\r\n modifiers.forEach(mod => EventModifiersPlugin.modifierMap[mod](event));\r\n\r\n return handler(event);\r\n };\r\n\r\n element.addEventListener(domEventName, wrappedHandler);\r\n\r\n return () => element.removeEventListener(domEventName, wrappedHandler);\r\n }\r\n}\r\n\r\n/**\r\n * Provides the Event Modifiers Plugin.\r\n *\r\n * @example\r\n * ```typescript\r\n * bootstrapApplication(AppComponent, {\r\n * providers: [provideEventModifiersPlugin()]\r\n * });\r\n * ```\r\n */\r\nexport function provideEventModifiersPlugin(): Provider {\r\n return {\r\n provide: EVENT_MANAGER_PLUGINS,\r\n useClass: EventModifiersPlugin,\r\n multi: true\r\n };\r\n}\r\n","import { HttpClient } from \"@angular/common/http\";\nimport { inject } from \"@angular/core\";\nimport { AnyFunction } from '@telperion/extra-ts-types';\nimport { tryCatch } from \"@telperion/js-utils/promise/try-catch\";\nimport { firstValueFrom, Observable } from 'rxjs';\n\nexport type Fetcher = {\n [P in keyof HttpClient]: HttpClient[P] extends (...args: infer A) => Observable<unknown> ? <T>(...args: A) => Promise<[unknown, T]> : never;\n}\n\n/**\n * Constructs a Fetcher that proxies HttpClient methods and returns a tuple of [error, response].\n * If the HttpClient method throws an error, it will be caught and returned as the first element of the tuple.\n * If the HttpClient method succeeds, the response will be returned as the second element of the tuple.\n * Example usage:\n * ```\n * @Component({\n * selector: 'app-example',\n * template: `<button (click)=\"fetchData()\">Fetch Data</button>`,\n * })\n * export class ExampleComponent {\n * private fetcher = constructFetcher();\n *\n * async fetchData() {\n * const [error, response] = await this.fetcher.get('/api/data');\n *\n* if (error) {\n* console.error('Error fetching data:', error);\n* } else {\n* console.log('Fetched data:', response);\n* }\n * }\n * }\n * ```\n */\nexport function constructFetcher() {\n const client = inject(HttpClient);\n\n return new Proxy({} as Fetcher, {\n get(target, prop) {\n if (prop in client) {\n return (...args: any[]) => {\n const method = (client as any)[prop] as AnyFunction;\n\n return tryCatch(firstValueFrom(method.apply(client, args)));\n }\n }\n\n throw new Error(`HttpClient does not have method ${String(prop)}`);\n }\n });\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCG;AACG,SAAU,uBAAuB,CACrC,KAAwB,EACxB,SAA2B,EAAA;IAE3B,OAAO;AACL,QAAA,OAAO,EAAE,KAAK;AACd,QAAA,WAAW,EAAE,UAAU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"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Collection of Angular utilities and libraries organized as secondary entry points. Includes signal-based storage (localStorage/sessionStorage/cookieStorage), SSE client with HttpClient-inspired interceptors, event modifier plugins, and more. Built with TypeScript, RxJS, and Angular Signals for modern Angular applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"angular",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"rxjs": "^7.8.1"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
35
|
+
"@telperion/extra-ts-types": "^1.5.0",
|
|
36
|
+
"@telperion/js-utils": "^3.5.0",
|
|
37
37
|
"@telperion/reactive-storage": "^1.2.0",
|
|
38
38
|
"tslib": "^2.3.0"
|
|
39
39
|
},
|
package/sse-client/README.md
CHANGED
|
@@ -373,6 +373,25 @@ export class SecureFeedComponent {
|
|
|
373
373
|
}
|
|
374
374
|
```
|
|
375
375
|
|
|
376
|
+
#### Base Init Configuration
|
|
377
|
+
|
|
378
|
+
Use `withBaseInit()` to set default `EventSourceInit` options for all SSE connections:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { ApplicationConfig } from '@angular/core';
|
|
382
|
+
import { provideSseClient, withBaseInit } from '@telperion/ng-pack/sse-client';
|
|
383
|
+
|
|
384
|
+
export const appConfig: ApplicationConfig = {
|
|
385
|
+
providers: [
|
|
386
|
+
provideSseClient(
|
|
387
|
+
withBaseInit({ withCredentials: true })
|
|
388
|
+
)
|
|
389
|
+
]
|
|
390
|
+
};
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Options provided via `withBaseInit()` are merged into every request and can be overridden per-call through `SseClient.start()`.
|
|
394
|
+
|
|
376
395
|
## API Reference
|
|
377
396
|
|
|
378
397
|
### `provideSseClient(...features: SseFeature[][]): Provider[]`
|
|
@@ -435,6 +454,24 @@ withSseInterceptors(
|
|
|
435
454
|
|
|
436
455
|
---
|
|
437
456
|
|
|
457
|
+
### `withBaseInit(init: Partial<EventSourceInit>): SseFeature[]`
|
|
458
|
+
|
|
459
|
+
Configures default `EventSourceInit` options that are merged into every SSE request.
|
|
460
|
+
|
|
461
|
+
**Parameters:**
|
|
462
|
+
- `init` - Partial EventSource initialization options (e.g., `{ withCredentials: true }`)
|
|
463
|
+
|
|
464
|
+
**Returns:** Array of SSE features to be used with `provideSseClient()`
|
|
465
|
+
|
|
466
|
+
**Example:**
|
|
467
|
+
```typescript
|
|
468
|
+
provideSseClient(
|
|
469
|
+
withBaseInit({ withCredentials: true })
|
|
470
|
+
)
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
---
|
|
474
|
+
|
|
438
475
|
### `SseInterceptorFn<T>`
|
|
439
476
|
|
|
440
477
|
Type definition for functional interceptors.
|
|
@@ -15,6 +15,22 @@ interface SseFeature {
|
|
|
15
15
|
kind: SseFeatureKind;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Configures default EventSource initialization options for the SSE client.
|
|
20
|
+
* Merges the provided options into every SSE request's `init` via an interceptor.
|
|
21
|
+
*
|
|
22
|
+
* @param init - Partial EventSource initialization options to apply as defaults
|
|
23
|
+
* @returns Array of SSE features to be used with `provideSseClient()`
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* provideSseClient(
|
|
28
|
+
* withBaseInit({ withCredentials: true })
|
|
29
|
+
* )
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function withBaseInit(init: Partial<EventSourceInit>): SseFeature[];
|
|
33
|
+
|
|
18
34
|
/**
|
|
19
35
|
* Represents an SSE request with URL and initialization options.
|
|
20
36
|
*/
|
|
@@ -137,5 +153,5 @@ declare class SseClient {
|
|
|
137
153
|
*/
|
|
138
154
|
declare function provideSseClient(...features: SseFeature[][]): Provider[];
|
|
139
155
|
|
|
140
|
-
export { SSE_INTERCEPTORS, SseClient, SseFeatureKind, provideSseClient, withSseInterceptors };
|
|
156
|
+
export { SSE_INTERCEPTORS, SseClient, SseFeatureKind, provideSseClient, withBaseInit, withSseInterceptors };
|
|
141
157
|
export type { SseFeature, SseInterceptor, SseInterceptorFn, SseInterceptorFunctionFeature, SseNextFn, SseRequest };
|