@angular-wave/angular.ts 0.9.7 → 0.9.8
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/@types/directive/http/http.d.ts +2 -0
- package/@types/namespace.d.ts +6 -0
- package/@types/services/http/http.d.ts +1 -1
- package/@types/services/sse/interface.d.ts +16 -0
- package/@types/services/sse/sse.d.ts +26 -0
- package/dist/angular-ts.esm.js +153 -11
- package/dist/angular-ts.umd.js +153 -11
- package/dist/angular-ts.umd.min.js +1 -1
- package/package.json +1 -1
|
@@ -43,4 +43,6 @@ export const ngDeleteDirective: ng.DirectiveFactory;
|
|
|
43
43
|
export const ngPostDirective: ng.DirectiveFactory;
|
|
44
44
|
/** @type {ng.DirectiveFactory} */
|
|
45
45
|
export const ngPutDirective: ng.DirectiveFactory;
|
|
46
|
+
/** @type {ng.DirectiveFactory} */
|
|
47
|
+
export const ngSseDirective: ng.DirectiveFactory;
|
|
46
48
|
export type EventType = "click" | "change" | "submit";
|
package/@types/namespace.d.ts
CHANGED
|
@@ -30,6 +30,10 @@ import {
|
|
|
30
30
|
import { StateProvider } from "./router/state/state-service.js";
|
|
31
31
|
import { HttpService as THttpService } from "./services/http/interface.ts";
|
|
32
32
|
import { LogService as TLogService } from "./services/log/interface.ts";
|
|
33
|
+
import {
|
|
34
|
+
SseService as TSseService,
|
|
35
|
+
SseConfig as TSseConfig,
|
|
36
|
+
} from "./services/sse/interface.ts";
|
|
33
37
|
declare global {
|
|
34
38
|
interface Function {
|
|
35
39
|
$inject?: readonly string[] | undefined;
|
|
@@ -67,6 +71,8 @@ declare global {
|
|
|
67
71
|
type RootElementService = Element;
|
|
68
72
|
type RootScopeService = InstanceType<typeof Scope>;
|
|
69
73
|
type StateService = InstanceType<typeof StateProvider>;
|
|
74
|
+
type SseService = TSseService;
|
|
75
|
+
type SseConfig = TSseConfig;
|
|
70
76
|
type TemplateCacheService = InstanceType<typeof Map<string, string>>;
|
|
71
77
|
type TemplateRequestService = TTemplateRequestService;
|
|
72
78
|
type ErrorHandlingConfig = TErrorHandlingConfig;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration object for SSE
|
|
3
|
+
*/
|
|
4
|
+
export interface SseConfig {
|
|
5
|
+
withCredentials?: boolean;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
onOpen?: (event: Event) => void;
|
|
8
|
+
onMessage?: (data: any, event: MessageEvent) => void;
|
|
9
|
+
onError?: (err: Event) => void;
|
|
10
|
+
transformMessage?: (data: string) => any;
|
|
11
|
+
params?: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* $sse service type
|
|
15
|
+
*/
|
|
16
|
+
export type SseService = (url: string, config?: SseConfig) => EventSource;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE Provider
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* const source = $sse('/events', {
|
|
6
|
+
* onMessage: (data) => console.log(data),
|
|
7
|
+
* onError: (err) => console.error(err),
|
|
8
|
+
* withCredentials: true
|
|
9
|
+
* });
|
|
10
|
+
*
|
|
11
|
+
* // later:
|
|
12
|
+
* source.close();
|
|
13
|
+
*/
|
|
14
|
+
export class SseProvider {
|
|
15
|
+
/**
|
|
16
|
+
* Optional provider-level defaults
|
|
17
|
+
* @type {ng.SseConfig}
|
|
18
|
+
*/
|
|
19
|
+
defaults: ng.SseConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the $sse service function
|
|
22
|
+
* @returns {ng.SseService}
|
|
23
|
+
*/
|
|
24
|
+
$get: () => ng.SseService;
|
|
25
|
+
#private;
|
|
26
|
+
}
|
package/dist/angular-ts.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Version: 0.9.
|
|
1
|
+
/* Version: 0.9.8 - October 26, 2025 19:05:36 */
|
|
2
2
|
const VALID_CLASS = "ng-valid";
|
|
3
3
|
const INVALID_CLASS = "ng-invalid";
|
|
4
4
|
const PRISTINE_CLASS = "ng-pristine";
|
|
@@ -1810,6 +1810,7 @@ const $injectTokens = Object.freeze({
|
|
|
1810
1810
|
$sceDelegate: "$sceDelegate",
|
|
1811
1811
|
$state: "$state",
|
|
1812
1812
|
$stateRegistry: "$stateRegistry",
|
|
1813
|
+
$sse: "$sse",
|
|
1813
1814
|
$$sanitizeUri: "$$sanitizeUri",
|
|
1814
1815
|
$$sanitizeUriProvider: "$$sanitizeUriProvider",
|
|
1815
1816
|
$templateCache: "$templateCache",
|
|
@@ -18301,7 +18302,7 @@ function HttpProvider() {
|
|
|
18301
18302
|
$injectTokens.$sce,
|
|
18302
18303
|
/**
|
|
18303
18304
|
*
|
|
18304
|
-
* @param {
|
|
18305
|
+
* @param {ng.InjectorService} $injector
|
|
18305
18306
|
* @param {*} $sce
|
|
18306
18307
|
* @returns
|
|
18307
18308
|
*/
|
|
@@ -35105,10 +35106,18 @@ function ngSetterDirective($parse, $log) {
|
|
|
35105
35106
|
* @param {"get" | "delete" | "post" | "put"} method
|
|
35106
35107
|
* @returns {ng.DirectiveFactory}
|
|
35107
35108
|
*/
|
|
35108
|
-
function defineDirective(method) {
|
|
35109
|
-
const attrName =
|
|
35109
|
+
function defineDirective(method, attrOverride) {
|
|
35110
|
+
const attrName =
|
|
35111
|
+
attrOverride || "ng" + method.charAt(0).toUpperCase() + method.slice(1);
|
|
35110
35112
|
const directive = createHttpDirective(method, attrName);
|
|
35111
|
-
directive["$inject"] = [
|
|
35113
|
+
directive["$inject"] = [
|
|
35114
|
+
$injectTokens.$http,
|
|
35115
|
+
$injectTokens.$compile,
|
|
35116
|
+
$injectTokens.$log,
|
|
35117
|
+
$injectTokens.$parse,
|
|
35118
|
+
$injectTokens.$state,
|
|
35119
|
+
$injectTokens.$sse,
|
|
35120
|
+
];
|
|
35112
35121
|
return directive;
|
|
35113
35122
|
}
|
|
35114
35123
|
|
|
@@ -35124,6 +35133,9 @@ const ngPostDirective = defineDirective("post");
|
|
|
35124
35133
|
/** @type {ng.DirectiveFactory} */
|
|
35125
35134
|
const ngPutDirective = defineDirective("put");
|
|
35126
35135
|
|
|
35136
|
+
/** @type {ng.DirectiveFactory} */
|
|
35137
|
+
const ngSseDirective = defineDirective("get", "ngSse");
|
|
35138
|
+
|
|
35127
35139
|
/**
|
|
35128
35140
|
* @typedef {"click" | "change" | "submit"} EventType
|
|
35129
35141
|
*/
|
|
@@ -35241,9 +35253,10 @@ function createHttpDirective(method, attrName) {
|
|
|
35241
35253
|
* @param {ng.LogService} $log
|
|
35242
35254
|
* @param {ng.ParseService} $parse
|
|
35243
35255
|
* @param {ng.StateService} $state
|
|
35256
|
+
* @param {Function} $sse
|
|
35244
35257
|
* @returns {ng.Directive}
|
|
35245
35258
|
*/
|
|
35246
|
-
return function ($http, $compile, $log, $parse, $state) {
|
|
35259
|
+
return function ($http, $compile, $log, $parse, $state, $sse) {
|
|
35247
35260
|
/**
|
|
35248
35261
|
* Collects form data from the element or its associated form.
|
|
35249
35262
|
*
|
|
@@ -35332,7 +35345,6 @@ function createHttpDirective(method, attrName) {
|
|
|
35332
35345
|
element.addEventListener(eventName, async (event) => {
|
|
35333
35346
|
if (/** @type {HTMLButtonElement} */ (element).disabled) return;
|
|
35334
35347
|
if (tag === "form") event.preventDefault();
|
|
35335
|
-
|
|
35336
35348
|
const swap = attrs["swap"] || "innerHTML";
|
|
35337
35349
|
const targetSelector = attrs["target"];
|
|
35338
35350
|
const target = targetSelector
|
|
@@ -35386,7 +35398,6 @@ function createHttpDirective(method, attrName) {
|
|
|
35386
35398
|
$compile,
|
|
35387
35399
|
);
|
|
35388
35400
|
};
|
|
35389
|
-
|
|
35390
35401
|
if (isDefined(attrs["delay"])) {
|
|
35391
35402
|
await wait(parseInt(attrs["delay"]) | 0);
|
|
35392
35403
|
}
|
|
@@ -35425,11 +35436,57 @@ function createHttpDirective(method, attrName) {
|
|
|
35425
35436
|
}
|
|
35426
35437
|
$http[method](url, data, config).then(handler).catch(handler);
|
|
35427
35438
|
} else {
|
|
35428
|
-
|
|
35439
|
+
// If SSE mode is enabled
|
|
35440
|
+
if (method === "get" && attrs["ngSse"]) {
|
|
35441
|
+
const sseUrl = url;
|
|
35442
|
+
const config = {
|
|
35443
|
+
withCredentials: attrs["withCredentials"] === "true",
|
|
35444
|
+
transformMessage: (data) => {
|
|
35445
|
+
try {
|
|
35446
|
+
return JSON.parse(data);
|
|
35447
|
+
} catch {
|
|
35448
|
+
return data;
|
|
35449
|
+
}
|
|
35450
|
+
},
|
|
35451
|
+
onOpen: () => {
|
|
35452
|
+
$log.info(`${attrName}: SSE connection opened to ${sseUrl}`);
|
|
35453
|
+
if (isDefined(attrs["loading"])) attrs.$set("loading", false);
|
|
35454
|
+
if (isDefined(attrs["loadingClass"]))
|
|
35455
|
+
attrs.$removeClass(attrs["loadingClass"]);
|
|
35456
|
+
},
|
|
35457
|
+
onMessage: (data) => {
|
|
35458
|
+
const res = { status: 200, data };
|
|
35459
|
+
handler(res);
|
|
35460
|
+
},
|
|
35461
|
+
onError: (err) => {
|
|
35462
|
+
$log.error(`${attrName}: SSE error`, err);
|
|
35463
|
+
const res = { status: 500, data: err };
|
|
35464
|
+
handler(res);
|
|
35465
|
+
},
|
|
35466
|
+
};
|
|
35467
|
+
|
|
35468
|
+
// Open the SSE connection using the injected service
|
|
35469
|
+
const source = $sse(sseUrl, config);
|
|
35470
|
+
|
|
35471
|
+
// Cleanup on scope destroy
|
|
35472
|
+
scope.$on("$destroy", () => {
|
|
35473
|
+
$log.info(`${attrName}: closing SSE connection`);
|
|
35474
|
+
source.close();
|
|
35475
|
+
});
|
|
35476
|
+
} else {
|
|
35477
|
+
$http[method](url).then(handler).catch(handler);
|
|
35478
|
+
}
|
|
35429
35479
|
}
|
|
35430
35480
|
});
|
|
35431
35481
|
|
|
35432
|
-
|
|
35482
|
+
if (intervalId) {
|
|
35483
|
+
scope.$on("$destroy", () => clearInterval(intervalId));
|
|
35484
|
+
}
|
|
35485
|
+
|
|
35486
|
+
// Eagerly execute for 'load' event
|
|
35487
|
+
if (eventName == "load") {
|
|
35488
|
+
element.dispatchEvent(new Event("load"));
|
|
35489
|
+
}
|
|
35433
35490
|
},
|
|
35434
35491
|
};
|
|
35435
35492
|
};
|
|
@@ -35500,6 +35557,89 @@ function ngElDirective() {
|
|
|
35500
35557
|
};
|
|
35501
35558
|
}
|
|
35502
35559
|
|
|
35560
|
+
/**
|
|
35561
|
+
* SSE Provider
|
|
35562
|
+
*
|
|
35563
|
+
* Usage:
|
|
35564
|
+
* const source = $sse('/events', {
|
|
35565
|
+
* onMessage: (data) => console.log(data),
|
|
35566
|
+
* onError: (err) => console.error(err),
|
|
35567
|
+
* withCredentials: true
|
|
35568
|
+
* });
|
|
35569
|
+
*
|
|
35570
|
+
* // later:
|
|
35571
|
+
* source.close();
|
|
35572
|
+
*/
|
|
35573
|
+
|
|
35574
|
+
class SseProvider {
|
|
35575
|
+
constructor() {
|
|
35576
|
+
/**
|
|
35577
|
+
* Optional provider-level defaults
|
|
35578
|
+
* @type {ng.SseConfig}
|
|
35579
|
+
*/
|
|
35580
|
+
this.defaults = {};
|
|
35581
|
+
}
|
|
35582
|
+
|
|
35583
|
+
/**
|
|
35584
|
+
* Returns the $sse service function
|
|
35585
|
+
* @returns {ng.SseService}
|
|
35586
|
+
*/
|
|
35587
|
+
$get =
|
|
35588
|
+
() =>
|
|
35589
|
+
(url, config = {}) => {
|
|
35590
|
+
const finalUrl = this.#buildUrl(url, config.params);
|
|
35591
|
+
return this.#createEventSource(finalUrl, config);
|
|
35592
|
+
};
|
|
35593
|
+
|
|
35594
|
+
/**
|
|
35595
|
+
* Build URL with query parameters
|
|
35596
|
+
* @param {string} url - Base URL
|
|
35597
|
+
* @param {Record<string, any>=} params - Query parameters
|
|
35598
|
+
* @returns {string} URL with serialized query string
|
|
35599
|
+
*/
|
|
35600
|
+
#buildUrl(url, params) {
|
|
35601
|
+
if (!params) return url;
|
|
35602
|
+
const query = Object.entries(params)
|
|
35603
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
35604
|
+
.join("&");
|
|
35605
|
+
return url + (url.includes("?") ? "&" : "?") + query;
|
|
35606
|
+
}
|
|
35607
|
+
|
|
35608
|
+
/**
|
|
35609
|
+
* Create and manage an EventSource
|
|
35610
|
+
* @param {string} url - URL for SSE connection
|
|
35611
|
+
* @param {ng.SseConfig} config - Configuration object
|
|
35612
|
+
* @returns {EventSource} The EventSource instance wrapped as SseService
|
|
35613
|
+
*/
|
|
35614
|
+
#createEventSource(url, config) {
|
|
35615
|
+
const es = new EventSource(url, {
|
|
35616
|
+
withCredentials: !!config.withCredentials,
|
|
35617
|
+
});
|
|
35618
|
+
|
|
35619
|
+
if (config.onOpen) {
|
|
35620
|
+
es.addEventListener("open", (e) => config.onOpen(e));
|
|
35621
|
+
}
|
|
35622
|
+
|
|
35623
|
+
es.addEventListener("message", (e) => {
|
|
35624
|
+
let data = e.data;
|
|
35625
|
+
try {
|
|
35626
|
+
data = config.transformMessage
|
|
35627
|
+
? config.transformMessage(data)
|
|
35628
|
+
: JSON.parse(data);
|
|
35629
|
+
} catch {
|
|
35630
|
+
// leave as raw string if not JSON
|
|
35631
|
+
}
|
|
35632
|
+
config.onMessage?.(data, e);
|
|
35633
|
+
});
|
|
35634
|
+
|
|
35635
|
+
if (config.onError) {
|
|
35636
|
+
es.addEventListener("error", (e) => config.onError(e));
|
|
35637
|
+
}
|
|
35638
|
+
|
|
35639
|
+
return es;
|
|
35640
|
+
}
|
|
35641
|
+
}
|
|
35642
|
+
|
|
35503
35643
|
/**
|
|
35504
35644
|
* Initializes core `ng` module.
|
|
35505
35645
|
* @param {import('./angular.js').Angular} angular
|
|
@@ -35560,6 +35700,7 @@ function registerNgModule(angular) {
|
|
|
35560
35700
|
ngSetter: ngSetterDirective,
|
|
35561
35701
|
ngShow: ngShowDirective,
|
|
35562
35702
|
ngStyle: ngStyleDirective,
|
|
35703
|
+
ngSse: ngSseDirective,
|
|
35563
35704
|
ngSwitch: ngSwitchDirective,
|
|
35564
35705
|
ngSwitchWhen: ngSwitchWhenDirective,
|
|
35565
35706
|
ngSwitchDefault: ngSwitchDefaultDirective,
|
|
@@ -35631,6 +35772,7 @@ function registerNgModule(angular) {
|
|
|
35631
35772
|
$router: Router,
|
|
35632
35773
|
$sce: SceProvider,
|
|
35633
35774
|
$sceDelegate: SceDelegateProvider,
|
|
35775
|
+
$sse: SseProvider,
|
|
35634
35776
|
$templateCache: TemplateCacheProvider,
|
|
35635
35777
|
$templateRequest: TemplateRequestProvider,
|
|
35636
35778
|
$urlConfig: UrlConfigProvider,
|
|
@@ -35673,7 +35815,7 @@ class Angular {
|
|
|
35673
35815
|
/**
|
|
35674
35816
|
* @type {string} `version` from `package.json`
|
|
35675
35817
|
*/
|
|
35676
|
-
this.version = "0.9.
|
|
35818
|
+
this.version = "0.9.8"; //inserted via rollup plugin
|
|
35677
35819
|
|
|
35678
35820
|
/** @type {!Array<string|any>} */
|
|
35679
35821
|
this.bootsrappedModules = [];
|
package/dist/angular-ts.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Version: 0.9.
|
|
1
|
+
/* Version: 0.9.8 - October 26, 2025 19:05:34 */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
@@ -1816,6 +1816,7 @@
|
|
|
1816
1816
|
$sceDelegate: "$sceDelegate",
|
|
1817
1817
|
$state: "$state",
|
|
1818
1818
|
$stateRegistry: "$stateRegistry",
|
|
1819
|
+
$sse: "$sse",
|
|
1819
1820
|
$$sanitizeUri: "$$sanitizeUri",
|
|
1820
1821
|
$$sanitizeUriProvider: "$$sanitizeUriProvider",
|
|
1821
1822
|
$templateCache: "$templateCache",
|
|
@@ -18307,7 +18308,7 @@
|
|
|
18307
18308
|
$injectTokens.$sce,
|
|
18308
18309
|
/**
|
|
18309
18310
|
*
|
|
18310
|
-
* @param {
|
|
18311
|
+
* @param {ng.InjectorService} $injector
|
|
18311
18312
|
* @param {*} $sce
|
|
18312
18313
|
* @returns
|
|
18313
18314
|
*/
|
|
@@ -35111,10 +35112,18 @@
|
|
|
35111
35112
|
* @param {"get" | "delete" | "post" | "put"} method
|
|
35112
35113
|
* @returns {ng.DirectiveFactory}
|
|
35113
35114
|
*/
|
|
35114
|
-
function defineDirective(method) {
|
|
35115
|
-
const attrName =
|
|
35115
|
+
function defineDirective(method, attrOverride) {
|
|
35116
|
+
const attrName =
|
|
35117
|
+
attrOverride || "ng" + method.charAt(0).toUpperCase() + method.slice(1);
|
|
35116
35118
|
const directive = createHttpDirective(method, attrName);
|
|
35117
|
-
directive["$inject"] = [
|
|
35119
|
+
directive["$inject"] = [
|
|
35120
|
+
$injectTokens.$http,
|
|
35121
|
+
$injectTokens.$compile,
|
|
35122
|
+
$injectTokens.$log,
|
|
35123
|
+
$injectTokens.$parse,
|
|
35124
|
+
$injectTokens.$state,
|
|
35125
|
+
$injectTokens.$sse,
|
|
35126
|
+
];
|
|
35118
35127
|
return directive;
|
|
35119
35128
|
}
|
|
35120
35129
|
|
|
@@ -35130,6 +35139,9 @@
|
|
|
35130
35139
|
/** @type {ng.DirectiveFactory} */
|
|
35131
35140
|
const ngPutDirective = defineDirective("put");
|
|
35132
35141
|
|
|
35142
|
+
/** @type {ng.DirectiveFactory} */
|
|
35143
|
+
const ngSseDirective = defineDirective("get", "ngSse");
|
|
35144
|
+
|
|
35133
35145
|
/**
|
|
35134
35146
|
* @typedef {"click" | "change" | "submit"} EventType
|
|
35135
35147
|
*/
|
|
@@ -35247,9 +35259,10 @@
|
|
|
35247
35259
|
* @param {ng.LogService} $log
|
|
35248
35260
|
* @param {ng.ParseService} $parse
|
|
35249
35261
|
* @param {ng.StateService} $state
|
|
35262
|
+
* @param {Function} $sse
|
|
35250
35263
|
* @returns {ng.Directive}
|
|
35251
35264
|
*/
|
|
35252
|
-
return function ($http, $compile, $log, $parse, $state) {
|
|
35265
|
+
return function ($http, $compile, $log, $parse, $state, $sse) {
|
|
35253
35266
|
/**
|
|
35254
35267
|
* Collects form data from the element or its associated form.
|
|
35255
35268
|
*
|
|
@@ -35338,7 +35351,6 @@
|
|
|
35338
35351
|
element.addEventListener(eventName, async (event) => {
|
|
35339
35352
|
if (/** @type {HTMLButtonElement} */ (element).disabled) return;
|
|
35340
35353
|
if (tag === "form") event.preventDefault();
|
|
35341
|
-
|
|
35342
35354
|
const swap = attrs["swap"] || "innerHTML";
|
|
35343
35355
|
const targetSelector = attrs["target"];
|
|
35344
35356
|
const target = targetSelector
|
|
@@ -35392,7 +35404,6 @@
|
|
|
35392
35404
|
$compile,
|
|
35393
35405
|
);
|
|
35394
35406
|
};
|
|
35395
|
-
|
|
35396
35407
|
if (isDefined(attrs["delay"])) {
|
|
35397
35408
|
await wait(parseInt(attrs["delay"]) | 0);
|
|
35398
35409
|
}
|
|
@@ -35431,11 +35442,57 @@
|
|
|
35431
35442
|
}
|
|
35432
35443
|
$http[method](url, data, config).then(handler).catch(handler);
|
|
35433
35444
|
} else {
|
|
35434
|
-
|
|
35445
|
+
// If SSE mode is enabled
|
|
35446
|
+
if (method === "get" && attrs["ngSse"]) {
|
|
35447
|
+
const sseUrl = url;
|
|
35448
|
+
const config = {
|
|
35449
|
+
withCredentials: attrs["withCredentials"] === "true",
|
|
35450
|
+
transformMessage: (data) => {
|
|
35451
|
+
try {
|
|
35452
|
+
return JSON.parse(data);
|
|
35453
|
+
} catch {
|
|
35454
|
+
return data;
|
|
35455
|
+
}
|
|
35456
|
+
},
|
|
35457
|
+
onOpen: () => {
|
|
35458
|
+
$log.info(`${attrName}: SSE connection opened to ${sseUrl}`);
|
|
35459
|
+
if (isDefined(attrs["loading"])) attrs.$set("loading", false);
|
|
35460
|
+
if (isDefined(attrs["loadingClass"]))
|
|
35461
|
+
attrs.$removeClass(attrs["loadingClass"]);
|
|
35462
|
+
},
|
|
35463
|
+
onMessage: (data) => {
|
|
35464
|
+
const res = { status: 200, data };
|
|
35465
|
+
handler(res);
|
|
35466
|
+
},
|
|
35467
|
+
onError: (err) => {
|
|
35468
|
+
$log.error(`${attrName}: SSE error`, err);
|
|
35469
|
+
const res = { status: 500, data: err };
|
|
35470
|
+
handler(res);
|
|
35471
|
+
},
|
|
35472
|
+
};
|
|
35473
|
+
|
|
35474
|
+
// Open the SSE connection using the injected service
|
|
35475
|
+
const source = $sse(sseUrl, config);
|
|
35476
|
+
|
|
35477
|
+
// Cleanup on scope destroy
|
|
35478
|
+
scope.$on("$destroy", () => {
|
|
35479
|
+
$log.info(`${attrName}: closing SSE connection`);
|
|
35480
|
+
source.close();
|
|
35481
|
+
});
|
|
35482
|
+
} else {
|
|
35483
|
+
$http[method](url).then(handler).catch(handler);
|
|
35484
|
+
}
|
|
35435
35485
|
}
|
|
35436
35486
|
});
|
|
35437
35487
|
|
|
35438
|
-
|
|
35488
|
+
if (intervalId) {
|
|
35489
|
+
scope.$on("$destroy", () => clearInterval(intervalId));
|
|
35490
|
+
}
|
|
35491
|
+
|
|
35492
|
+
// Eagerly execute for 'load' event
|
|
35493
|
+
if (eventName == "load") {
|
|
35494
|
+
element.dispatchEvent(new Event("load"));
|
|
35495
|
+
}
|
|
35439
35496
|
},
|
|
35440
35497
|
};
|
|
35441
35498
|
};
|
|
@@ -35506,6 +35563,89 @@
|
|
|
35506
35563
|
};
|
|
35507
35564
|
}
|
|
35508
35565
|
|
|
35566
|
+
/**
|
|
35567
|
+
* SSE Provider
|
|
35568
|
+
*
|
|
35569
|
+
* Usage:
|
|
35570
|
+
* const source = $sse('/events', {
|
|
35571
|
+
* onMessage: (data) => console.log(data),
|
|
35572
|
+
* onError: (err) => console.error(err),
|
|
35573
|
+
* withCredentials: true
|
|
35574
|
+
* });
|
|
35575
|
+
*
|
|
35576
|
+
* // later:
|
|
35577
|
+
* source.close();
|
|
35578
|
+
*/
|
|
35579
|
+
|
|
35580
|
+
class SseProvider {
|
|
35581
|
+
constructor() {
|
|
35582
|
+
/**
|
|
35583
|
+
* Optional provider-level defaults
|
|
35584
|
+
* @type {ng.SseConfig}
|
|
35585
|
+
*/
|
|
35586
|
+
this.defaults = {};
|
|
35587
|
+
}
|
|
35588
|
+
|
|
35589
|
+
/**
|
|
35590
|
+
* Returns the $sse service function
|
|
35591
|
+
* @returns {ng.SseService}
|
|
35592
|
+
*/
|
|
35593
|
+
$get =
|
|
35594
|
+
() =>
|
|
35595
|
+
(url, config = {}) => {
|
|
35596
|
+
const finalUrl = this.#buildUrl(url, config.params);
|
|
35597
|
+
return this.#createEventSource(finalUrl, config);
|
|
35598
|
+
};
|
|
35599
|
+
|
|
35600
|
+
/**
|
|
35601
|
+
* Build URL with query parameters
|
|
35602
|
+
* @param {string} url - Base URL
|
|
35603
|
+
* @param {Record<string, any>=} params - Query parameters
|
|
35604
|
+
* @returns {string} URL with serialized query string
|
|
35605
|
+
*/
|
|
35606
|
+
#buildUrl(url, params) {
|
|
35607
|
+
if (!params) return url;
|
|
35608
|
+
const query = Object.entries(params)
|
|
35609
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
35610
|
+
.join("&");
|
|
35611
|
+
return url + (url.includes("?") ? "&" : "?") + query;
|
|
35612
|
+
}
|
|
35613
|
+
|
|
35614
|
+
/**
|
|
35615
|
+
* Create and manage an EventSource
|
|
35616
|
+
* @param {string} url - URL for SSE connection
|
|
35617
|
+
* @param {ng.SseConfig} config - Configuration object
|
|
35618
|
+
* @returns {EventSource} The EventSource instance wrapped as SseService
|
|
35619
|
+
*/
|
|
35620
|
+
#createEventSource(url, config) {
|
|
35621
|
+
const es = new EventSource(url, {
|
|
35622
|
+
withCredentials: !!config.withCredentials,
|
|
35623
|
+
});
|
|
35624
|
+
|
|
35625
|
+
if (config.onOpen) {
|
|
35626
|
+
es.addEventListener("open", (e) => config.onOpen(e));
|
|
35627
|
+
}
|
|
35628
|
+
|
|
35629
|
+
es.addEventListener("message", (e) => {
|
|
35630
|
+
let data = e.data;
|
|
35631
|
+
try {
|
|
35632
|
+
data = config.transformMessage
|
|
35633
|
+
? config.transformMessage(data)
|
|
35634
|
+
: JSON.parse(data);
|
|
35635
|
+
} catch {
|
|
35636
|
+
// leave as raw string if not JSON
|
|
35637
|
+
}
|
|
35638
|
+
config.onMessage?.(data, e);
|
|
35639
|
+
});
|
|
35640
|
+
|
|
35641
|
+
if (config.onError) {
|
|
35642
|
+
es.addEventListener("error", (e) => config.onError(e));
|
|
35643
|
+
}
|
|
35644
|
+
|
|
35645
|
+
return es;
|
|
35646
|
+
}
|
|
35647
|
+
}
|
|
35648
|
+
|
|
35509
35649
|
/**
|
|
35510
35650
|
* Initializes core `ng` module.
|
|
35511
35651
|
* @param {import('./angular.js').Angular} angular
|
|
@@ -35566,6 +35706,7 @@
|
|
|
35566
35706
|
ngSetter: ngSetterDirective,
|
|
35567
35707
|
ngShow: ngShowDirective,
|
|
35568
35708
|
ngStyle: ngStyleDirective,
|
|
35709
|
+
ngSse: ngSseDirective,
|
|
35569
35710
|
ngSwitch: ngSwitchDirective,
|
|
35570
35711
|
ngSwitchWhen: ngSwitchWhenDirective,
|
|
35571
35712
|
ngSwitchDefault: ngSwitchDefaultDirective,
|
|
@@ -35637,6 +35778,7 @@
|
|
|
35637
35778
|
$router: Router,
|
|
35638
35779
|
$sce: SceProvider,
|
|
35639
35780
|
$sceDelegate: SceDelegateProvider,
|
|
35781
|
+
$sse: SseProvider,
|
|
35640
35782
|
$templateCache: TemplateCacheProvider,
|
|
35641
35783
|
$templateRequest: TemplateRequestProvider,
|
|
35642
35784
|
$urlConfig: UrlConfigProvider,
|
|
@@ -35679,7 +35821,7 @@
|
|
|
35679
35821
|
/**
|
|
35680
35822
|
* @type {string} `version` from `package.json`
|
|
35681
35823
|
*/
|
|
35682
|
-
this.version = "0.9.
|
|
35824
|
+
this.version = "0.9.8"; //inserted via rollup plugin
|
|
35683
35825
|
|
|
35684
35826
|
/** @type {!Array<string|any>} */
|
|
35685
35827
|
this.bootsrappedModules = [];
|