@angular-wave/angular.ts 0.7.3 → 0.7.4

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.
Files changed (206) hide show
  1. package/.prettierignore +2 -1
  2. package/@types/core/exception-handler.d.ts +2 -2
  3. package/@types/core/task-tracker-factory.d.ts +2 -2
  4. package/@types/directive/channel/channel.d.ts +2 -18
  5. package/@types/directive/http/http.d.ts +3 -0
  6. package/@types/directive/script/script.d.ts +2 -2
  7. package/@types/directive/setter/setter.d.ts +2 -2
  8. package/@types/injection-tokens.d.ts +3 -0
  9. package/@types/interface.d.ts +11 -0
  10. package/@types/loader.d.ts +3 -4
  11. package/@types/router/params/param-factory.d.ts +10 -2
  12. package/@types/router/params/param.d.ts +22 -3
  13. package/@types/router/template-factory.d.ts +2 -2
  14. package/@types/router/url/url-service.d.ts +2 -2
  15. package/@types/services/http/http.d.ts +2 -2
  16. package/@types/services/http/interface.d.ts +219 -0
  17. package/@types/services/http-backend/http-backend.d.ts +26 -19
  18. package/@types/services/log/interface.d.ts +33 -0
  19. package/@types/services/log/log.d.ts +25 -0
  20. package/@types/{core → services}/pubsub/pubsub.d.ts +6 -6
  21. package/@types/services/template-cache/interface.d.ts +4 -0
  22. package/@types/services/template-cache/template-cache.d.ts +11 -0
  23. package/@types/services/template-request.d.ts +1 -1
  24. package/@types/shared/cache.d.ts +9 -0
  25. package/@types/shared/dom.d.ts +2 -2
  26. package/Makefile +1 -1
  27. package/dist/angular-ts.esm.js +147 -141
  28. package/dist/angular-ts.umd.js +147 -141
  29. package/dist/angular-ts.umd.min.js +1 -1
  30. package/docs/assets/scss/_variables_project.scss +1 -1
  31. package/docs/assets/scss/_variables_project_after_bs.scss +5 -5
  32. package/docs/assets/scss/index.scss +2 -3
  33. package/docs/content/_index.md +1 -1
  34. package/docs/content/docs/_index.md +58 -25
  35. package/docs/content/docs/directive/_index.md +4 -0
  36. package/docs/content/docs/directive/app.md +11 -0
  37. package/docs/content/docs/directive/aria.md +0 -0
  38. package/docs/content/docs/directive/channel.md +39 -0
  39. package/docs/content/docs/directive/class-even.md +47 -0
  40. package/docs/content/docs/directive/class-odd.md +48 -0
  41. package/docs/content/docs/directive/class.md +64 -0
  42. package/docs/content/docs/directive/cloak.md +78 -0
  43. package/docs/content/docs/directive/include.md +7 -0
  44. package/docs/content/docs/filter/_index.md +4 -0
  45. package/docs/content/docs/provider/_index.md +4 -0
  46. package/docs/content/docs/provider/eventBusProvider.md +35 -0
  47. package/docs/content/docs/provider/logProvider.md +59 -0
  48. package/docs/content/docs/provider/templateCacheProvider.md +35 -0
  49. package/docs/content/docs/service/_index.md +4 -0
  50. package/docs/content/docs/service/eventBus.md +56 -0
  51. package/docs/content/docs/service/log.md +113 -0
  52. package/docs/content/docs/service/templateCache.md +64 -0
  53. package/docs/hugo.yaml +3 -3
  54. package/docs/layouts/partials/hooks/head-end.html +3 -0
  55. package/docs/layouts/shortcodes/showhtml.html +2 -0
  56. package/docs/layouts/shortcodes/showjs.html +2 -0
  57. package/docs/layouts/shortcodes/showraw.html +1 -0
  58. package/docs/static/examples/counter/counter-test.html +17 -0
  59. package/docs/static/examples/counter/counter.html +5 -0
  60. package/docs/static/examples/counter/counter.test.js +28 -0
  61. package/docs/static/examples/eventbus/eventbus-test.html +19 -0
  62. package/docs/static/examples/eventbus/eventbus.html +13 -0
  63. package/docs/static/examples/eventbus/eventbus.js +15 -0
  64. package/docs/static/examples/eventbus/eventbus.test.js +19 -0
  65. package/docs/static/examples/ng-channel/ng-channel-test.html +17 -0
  66. package/docs/static/examples/ng-channel/ng-channel.html +24 -0
  67. package/docs/static/examples/ng-channel/ng-channel.test.js +31 -0
  68. package/docs/static/examples/ng-class/ng-class.html +71 -0
  69. package/docs/static/examples/ng-class/ng-class.js +0 -0
  70. package/docs/static/examples/ng-class-even/ng-class-even.html +8 -0
  71. package/docs/static/examples/ng-class-odd/ng-class-odd.html +8 -0
  72. package/docs/static/typedoc/assets/hierarchy.js +1 -1
  73. package/docs/static/typedoc/assets/navigation.js +1 -1
  74. package/docs/static/typedoc/assets/search.js +1 -1
  75. package/docs/static/typedoc/classes/LogProvider.html +6 -0
  76. package/docs/static/typedoc/classes/PubSub.html +71 -0
  77. package/docs/static/typedoc/classes/PubSubProvider.html +3 -0
  78. package/docs/static/typedoc/classes/TemplateCacheProvider.html +5 -0
  79. package/docs/static/typedoc/hierarchy.html +1 -1
  80. package/docs/static/typedoc/index.html +1 -1
  81. package/docs/static/typedoc/interfaces/ChangesObject.html +1 -1
  82. package/docs/static/typedoc/interfaces/ComponentOptions.html +1 -1
  83. package/docs/static/typedoc/interfaces/Controller.html +1 -1
  84. package/docs/static/typedoc/interfaces/Directive.html +1 -1
  85. package/docs/static/typedoc/interfaces/DirectivePrePost.html +1 -1
  86. package/docs/static/typedoc/interfaces/HttpHeadersGetter.html +1 -0
  87. package/docs/static/typedoc/interfaces/HttpProviderDefaults.html +31 -0
  88. package/docs/static/typedoc/interfaces/HttpRequestConfigHeaders.html +6 -0
  89. package/docs/static/typedoc/interfaces/HttpRequestTransformer.html +1 -0
  90. package/docs/static/typedoc/interfaces/HttpResponse.html +8 -0
  91. package/docs/static/typedoc/interfaces/HttpResponseTransformer.html +1 -0
  92. package/docs/static/typedoc/interfaces/HttpService.html +38 -0
  93. package/docs/static/typedoc/interfaces/LogService.html +12 -0
  94. package/docs/static/typedoc/interfaces/NgModelController.html +1 -1
  95. package/docs/static/typedoc/interfaces/NgModelOptions.html +1 -1
  96. package/docs/static/typedoc/interfaces/Provider.html +1 -1
  97. package/docs/static/typedoc/interfaces/RequestConfig.html +48 -0
  98. package/docs/static/typedoc/interfaces/RequestShortcutConfig.html +38 -0
  99. package/docs/static/typedoc/interfaces/ServiceProvider.html +1 -1
  100. package/docs/static/typedoc/interfaces/TranscludeFunctionObject.html +1 -1
  101. package/docs/static/typedoc/types/AnnotatedFactory.html +1 -1
  102. package/docs/static/typedoc/types/CloneAttachFunction.html +1 -1
  103. package/docs/static/typedoc/types/ControllerConstructor.html +1 -1
  104. package/docs/static/typedoc/types/DirectiveCompileFn.html +1 -1
  105. package/docs/static/typedoc/types/DirectiveController.html +1 -1
  106. package/docs/static/typedoc/types/DirectiveFactory.html +1 -1
  107. package/docs/static/typedoc/types/DirectiveLinkFn.html +1 -1
  108. package/docs/static/typedoc/types/ExpandoStore.html +2 -0
  109. package/docs/static/typedoc/types/Expression.html +1 -1
  110. package/docs/static/typedoc/types/FilterFactory.html +1 -1
  111. package/docs/static/typedoc/types/FilterFn.html +1 -1
  112. package/docs/static/typedoc/types/HttpPromise.html +1 -0
  113. package/docs/static/typedoc/types/Injectable.html +1 -1
  114. package/docs/static/typedoc/types/InjectableFactory.html +1 -1
  115. package/docs/static/typedoc/types/LogCall.html +2 -0
  116. package/docs/static/typedoc/types/LogServiceFactory.html +2 -0
  117. package/docs/static/typedoc/types/OnChangesObject.html +1 -1
  118. package/docs/static/typedoc/types/SwapInsertPosition.html +1 -1
  119. package/docs/static/typedoc/types/TController.html +1 -1
  120. package/docs/static/typedoc/types/TemplateCache.html +2 -0
  121. package/docs/static/typedoc/variables/EventBus.html +1 -0
  122. package/index.html +4 -2
  123. package/package.json +3 -3
  124. package/src/animations/animate-css.js +5 -1
  125. package/src/binding.spec.js +3 -1
  126. package/src/core/compile/compile.spec.js +12 -5
  127. package/src/core/core.html +0 -1
  128. package/src/core/exception-handler.js +1 -1
  129. package/src/core/prop.spec.js +1 -0
  130. package/src/core/task-tracker-factory.js +2 -2
  131. package/src/directive/bind/bind.spec.js +1 -4
  132. package/src/directive/channel/channel.js +8 -24
  133. package/src/directive/channel/channel.spec.js +4 -2
  134. package/src/directive/class/class.js +16 -0
  135. package/src/directive/class/class.spec.js +2 -0
  136. package/src/directive/events/event.spec.js +1 -0
  137. package/src/directive/form/form.spec.js +2 -0
  138. package/src/directive/http/http.js +4 -4
  139. package/src/directive/if/if.spec.js +2 -0
  140. package/src/directive/include/include.spec.js +1 -0
  141. package/src/directive/input/input.spec.js +1 -0
  142. package/src/directive/model/model.spec.js +3 -0
  143. package/src/directive/model-options/model-options.spec.js +2 -0
  144. package/src/directive/observe/observe.spec.js +2 -1
  145. package/src/{core/pubsub/pubsub.html → directive/on/on.html} +1 -1
  146. package/src/{core → directive/on}/on.spec.js +5 -3
  147. package/src/directive/on/on.test.js +11 -0
  148. package/src/directive/options/options.spec.js +1 -0
  149. package/src/directive/script/script.js +1 -1
  150. package/src/directive/select/select.spec.js +1 -0
  151. package/src/directive/setter/setter.js +1 -1
  152. package/src/directive/setter/setter.spec.js +2 -0
  153. package/src/directive/switch/switch.spec.js +1 -0
  154. package/src/injection-tokens.js +3 -0
  155. package/src/interface.ts +10 -0
  156. package/src/loader.js +3 -6
  157. package/src/public.js +3 -3
  158. package/src/router/directives/state-directives.spec.js +3 -1
  159. package/src/router/params/param-factory.js +6 -0
  160. package/src/router/params/param.js +22 -7
  161. package/src/router/router.html +0 -1
  162. package/src/router/router.test.js +2 -1
  163. package/src/router/services.spec.js +2 -0
  164. package/src/router/state/state-builder.js +3 -0
  165. package/src/router/state/state-builder.spec.js +2 -0
  166. package/src/router/state/state-service.js +1 -1
  167. package/src/router/state-filter.spec.js +2 -0
  168. package/src/router/template-factory.html +19 -0
  169. package/src/router/template-factory.js +3 -3
  170. package/src/router/template-factory.spec.js +1 -0
  171. package/src/router/template-factory.test.js +12 -0
  172. package/src/router/transition/transition-hook.js +1 -1
  173. package/src/router/url/url-service.js +1 -1
  174. package/src/router/view-scroll.spec.js +3 -1
  175. package/src/services/http/http.js +4 -4
  176. package/src/services/http/http.test.js +1 -1
  177. package/src/services/http/interface.ts +243 -0
  178. package/src/services/http-backend/http-backend.js +21 -11
  179. package/src/services/log/interface.ts +39 -0
  180. package/src/services/log/log.html +19 -0
  181. package/src/services/log/log.js +74 -0
  182. package/src/services/log/log.spec.js +64 -0
  183. package/src/services/log/log.test.js +11 -0
  184. package/src/services/pubsub/pubsub.html +19 -0
  185. package/src/{core → services}/pubsub/pubsub.js +6 -5
  186. package/src/{core → services}/pubsub/pubsub.spec.js +3 -3
  187. package/src/{core → services}/pubsub/pubsub.test.js +1 -1
  188. package/src/services/template-cache/interface.ts +4 -0
  189. package/src/services/template-cache/template-cache.html +22 -0
  190. package/src/services/template-cache/template-cache.js +13 -0
  191. package/src/services/template-cache/template-cache.spec.js +62 -0
  192. package/src/services/template-cache/template-cache.test.js +11 -0
  193. package/src/services/template-request.js +2 -2
  194. package/src/shared/cache.js +9 -0
  195. package/src/shared/dom.js +13 -7
  196. package/utils/express.js +7 -9
  197. package/@types/core/cache/cache-factory.d.ts +0 -22
  198. package/@types/core/cache/cache.d.ts +0 -28
  199. package/@types/services/log.d.ts +0 -53
  200. package/src/core/cache/cache-factory.js +0 -19
  201. package/src/core/cache/cache.js +0 -27
  202. package/src/directive/class/class.md +0 -90
  203. package/src/directive/cloak/cloak.md +0 -24
  204. package/src/examples/counter.html +0 -20
  205. package/src/services/log.js +0 -95
  206. package/src/services/log.md +0 -39
@@ -17,7 +17,7 @@ import { Glob } from "../common/glob.js";
17
17
  import { ResolveContext } from "../resolve/resolve-context.js";
18
18
  import { lazyLoadState } from "../hooks/lazy-load.js";
19
19
  import { val } from "../../shared/hof.js";
20
- import { EventBus } from "../../core/pubsub/pubsub.js";
20
+ import { EventBus } from "../../services/pubsub/pubsub.js";
21
21
 
22
22
  const err = minErr("$stateProvider");
23
23
 
@@ -1,9 +1,11 @@
1
1
  import { Angular } from "../loader.js";
2
+ import { dealoc } from "../shared/dom.js";
2
3
 
3
4
  describe("router filters", function () {
4
5
  let module, $parse, $state, $rootScope, $location;
5
6
 
6
7
  beforeEach(() => {
8
+ dealoc(document.getElementById("app"));
7
9
  window.location.hash = "";
8
10
  window.angular = new Angular();
9
11
  });
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>AngularTS Test Runner</title>
6
+
7
+ <link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
8
+ <link rel="stylesheet" href="/jasmine/jasmine.css" />
9
+ <link rel="stylesheet" href="/public/jasmine-helper.css" />
10
+ <script src="/jasmine/jasmine.js"></script>
11
+ <script src="/jasmine/jasmine-html.js"></script>
12
+ <script src="/jasmine/boot0.js"></script>
13
+ <script src="/jasmine/boot1.js"></script>
14
+ <script type="module" src="/src/router/template-factory.spec.js"></script>
15
+ </head>
16
+ <body>
17
+ <div id="app"></div>
18
+ </body>
19
+ </html>
@@ -26,8 +26,8 @@ export class TemplateFactoryProvider {
26
26
  "$templateRequest",
27
27
  "$injector",
28
28
  /**
29
- * @param {any} $http
30
- * @param {import("../core/cache/cache-factory.js").TemplateCache} $templateCache
29
+ * @param {import("interface.ts").HttpService} $http
30
+ * @param {import("../services/template-cache/interface.ts").TemplateCache} $templateCache
31
31
  * @param {any} $templateRequest
32
32
  * @param {import("../core/di/internal-injector.js").InjectorService} $injector
33
33
  * @returns
@@ -126,7 +126,7 @@ export class TemplateFactoryProvider {
126
126
  if (url == null) return null;
127
127
  if (this._useHttp) {
128
128
  return this.$http
129
- .get(url, {
129
+ .get(/** @type {string} */ (url), {
130
130
  cache: this.$templateCache,
131
131
  headers: { Accept: "text/html" },
132
132
  })
@@ -14,6 +14,7 @@ describe("templateFactory", () => {
14
14
  error;
15
15
 
16
16
  beforeEach(() => {
17
+ dealoc(document.getElementById("app"));
17
18
  window.angular = new Angular();
18
19
  window.angular
19
20
  .module("defaultModule", [])
@@ -0,0 +1,12 @@
1
+ import { test, expect } from "@playwright/test";
2
+
3
+ const TEST_URL = "src/router/template-factory.html?random=false";
4
+
5
+ test("unit tests contain no errors", async ({ page }) => {
6
+ await page.goto(TEST_URL);
7
+ await page.content();
8
+ await page.waitForTimeout(4000);
9
+ await expect(page.locator(".jasmine-overall-result")).toHaveText(
10
+ /0 failures/,
11
+ );
12
+ });
@@ -6,7 +6,7 @@ import { parse } from "../../shared/hof.js";
6
6
  import { trace } from "../common/trace.js";
7
7
  import { Rejection } from "./reject-factory.js";
8
8
  import { TargetState } from "../state/target-state.js";
9
- import { EventBus } from "../../core/pubsub/pubsub.js";
9
+ import { EventBus } from "../../services/pubsub/pubsub.js";
10
10
 
11
11
  const defaultOptions = {
12
12
  current: () => {},
@@ -52,7 +52,7 @@ export class UrlService {
52
52
  * The nested [[UrlConfig]] API to configure the URL and retrieve URL information
53
53
  *
54
54
  * See: [[UrlConfig]] for details
55
- * @type {import("./url-config").UrlConfigProvider}
55
+ * @type {import("./url-config.js").UrlConfigProvider}
56
56
  */
57
57
  this.config = urlConfigProvider;
58
58
 
@@ -20,6 +20,7 @@ describe("ngView", () => {
20
20
  });
21
21
  elem = [{ scrollIntoView: jasmine.createSpy("scrollIntoView") }];
22
22
  });
23
+
23
24
  it("should scroll element into view after timeout", async () => {
24
25
  $ngViewScroll(elem[0]);
25
26
  expect(elem[0].scrollIntoView).not.toHaveBeenCalled();
@@ -29,9 +30,10 @@ describe("ngView", () => {
29
30
  });
30
31
 
31
32
  it("should return the promise from the timeout", async () => {
33
+ dealoc(document.getElementById("app"));
32
34
  const promise = $ngViewScroll(elem[0]);
33
35
 
34
- await wait(100);
36
+ await wait(10);
35
37
  expect(elem[0].scrollIntoView).toHaveBeenCalled();
36
38
  expect(promise).toBeDefined();
37
39
  });
@@ -386,8 +386,8 @@ export function HttpProvider() {
386
386
  *
387
387
  * @param {*} $browser
388
388
  * @param {*} $httpBackend
389
- * @param {*} $rootScope
390
- * @param {import("../../core/di/internal-injector").InjectorService} $injector
389
+ * @param {import("../../core/scope/scope.js").Scope} $rootScope
390
+ * @param {import("../../core/di/internal-injector.js").InjectorService} $injector
391
391
  * @param {*} $sce
392
392
  * @returns
393
393
  */
@@ -825,9 +825,9 @@ export function HttpProvider() {
825
825
  Object.entries(eventHandlers).forEach(([key, eventHandler]) => {
826
826
  applyHandlers[key] = function (event) {
827
827
  if (useApplyAsync) {
828
- setTimeout(() => $rootScope.$apply(callEventHandler));
828
+ setTimeout(() => callEventHandler());
829
829
  } else {
830
- $rootScope.$apply(callEventHandler);
830
+ callEventHandler();
831
831
  }
832
832
 
833
833
  function callEventHandler() {
@@ -1,6 +1,6 @@
1
1
  import { test, expect } from "@playwright/test";
2
2
 
3
- const TEST_URL = "src/services/http/http.html";
3
+ const TEST_URL = "src/services/http/http.html?random=false";
4
4
 
5
5
  test("unit tests contain no errors", async ({ page }) => {
6
6
  await page.goto(TEST_URL);
@@ -0,0 +1,243 @@
1
+ export interface HttpHeadersGetter {
2
+ (): { [name: string]: string };
3
+ (headerName: string): string;
4
+ }
5
+
6
+ export interface HttpRequestConfigHeaders {
7
+ [requestType: string]: any;
8
+ common?: any;
9
+ get?: any;
10
+ post?: any;
11
+ put?: any;
12
+ patch?: any;
13
+ }
14
+
15
+ // See the jsdoc for transformData() at https://github.com/angular/angular.js/blob/master/src/ng/http.js#L228
16
+ export interface HttpRequestTransformer {
17
+ (data: any, headersGetter: HttpHeadersGetter): any;
18
+ }
19
+
20
+ // The definition of fields are the same as HttpResponse
21
+ export interface HttpResponseTransformer {
22
+ (data: any, headersGetter: HttpHeadersGetter, status: number): any;
23
+ }
24
+
25
+ /**
26
+ * Object that controls the defaults for $http provider. Not all fields of RequestShortcutConfig can be configured
27
+ * via defaults and the docs do not say which. The following is based on the inspection of the source code.
28
+ * https://docs.angularjs.org/api/ng/service/$http#defaults
29
+ * https://docs.angularjs.org/api/ng/service/$http#usage
30
+ * https://docs.angularjs.org/api/ng/provider/$httpProvider The properties section
31
+ */
32
+ export interface HttpProviderDefaults {
33
+ /**
34
+ * {boolean|Cache}
35
+ * If true, a default $http cache will be used to cache the GET request, otherwise if a cache instance built with $cacheFactory, this cache will be used for caching.
36
+ */
37
+ cache?: any;
38
+
39
+ /**
40
+ * Transform function or an array of such functions. The transform function takes the http request body and
41
+ * headers and returns its transformed (typically serialized) version.
42
+ * @see {@link https://docs.angularjs.org/api/ng/service/$http#transforming-requests-and-responses}
43
+ */
44
+ transformRequest?:
45
+ | HttpRequestTransformer
46
+ | HttpRequestTransformer[]
47
+ | undefined;
48
+
49
+ /**
50
+ * Transform function or an array of such functions. The transform function takes the http response body and
51
+ * headers and returns its transformed (typically deserialized) version.
52
+ */
53
+ transformResponse?:
54
+ | HttpResponseTransformer
55
+ | HttpResponseTransformer[]
56
+ | undefined;
57
+
58
+ /**
59
+ * Map of strings or functions which return strings representing HTTP headers to send to the server. If the
60
+ * return value of a function is null, the header will not be sent.
61
+ * The key of the map is the request verb in lower case. The "common" key applies to all requests.
62
+ * @see {@link https://docs.angularjs.org/api/ng/service/$http#setting-http-headers}
63
+ */
64
+ headers?: HttpRequestConfigHeaders | undefined;
65
+
66
+ /** Name of HTTP header to populate with the XSRF token. */
67
+ xsrfHeaderName?: string | undefined;
68
+
69
+ /** Name of cookie containing the XSRF token. */
70
+ xsrfCookieName?: string | undefined;
71
+
72
+ /**
73
+ * whether to to set the withCredentials flag on the XHR object. See [requests with credentials]https://developer.mozilla.org/en/http_access_control#section_5 for more information.
74
+ */
75
+ withCredentials?: boolean | undefined;
76
+
77
+ /**
78
+ * A function used to the prepare string representation of request parameters (specified as an object). If
79
+ * specified as string, it is interpreted as a function registered with the $injector. Defaults to
80
+ * $httpParamSerializer.
81
+ */
82
+ paramSerializer?: string | ((obj: any) => string) | undefined;
83
+ }
84
+
85
+ /**
86
+ * Object describing the request to be made and how it should be processed.
87
+ * see http://docs.angularjs.org/api/ng/service/$http#usage
88
+ */
89
+ export interface RequestShortcutConfig extends HttpProviderDefaults {
90
+ /**
91
+ * {Object.<string|Object>}
92
+ * Map of strings or objects which will be turned to ?key1=value1&key2=value2 after the url. If the value is not a string, it will be JSONified.
93
+ */
94
+ params?: any;
95
+
96
+ /**
97
+ * {string|Object}
98
+ * Data to be sent as the request message data.
99
+ */
100
+ data?: any;
101
+
102
+ /**
103
+ * Timeout in milliseconds, or promise that should abort the request when resolved.
104
+ */
105
+ timeout?: number | Promise<any> | undefined;
106
+
107
+ /**
108
+ * See [XMLHttpRequest.responseType]https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype
109
+ */
110
+ responseType?: string | undefined;
111
+ }
112
+
113
+ /**
114
+ * Object describing the request to be made and how it should be processed.
115
+ * see http://docs.angularjs.org/api/ng/service/$http#usage
116
+ */
117
+ export interface RequestConfig extends RequestShortcutConfig {
118
+ /**
119
+ * HTTP method (e.g. 'GET', 'POST', etc)
120
+ */
121
+ method: string;
122
+ /**
123
+ * Absolute or relative URL of the resource that is being requested.
124
+ */
125
+ url: string;
126
+ /**
127
+ * Event listeners to be bound to the XMLHttpRequest object.
128
+ * To bind events to the XMLHttpRequest upload object, use uploadEventHandlers. The handler will be called in the context of a $apply block.
129
+ */
130
+ eventHandlers?:
131
+ | { [type: string]: EventListenerOrEventListenerObject }
132
+ | undefined;
133
+ /**
134
+ * Event listeners to be bound to the XMLHttpRequest upload object.
135
+ * To bind events to the XMLHttpRequest object, use eventHandlers. The handler will be called in the context of a $apply block.
136
+ */
137
+ uploadEventHandlers?:
138
+ | { [type: string]: EventListenerOrEventListenerObject }
139
+ | undefined;
140
+ }
141
+
142
+ export interface HttpResponse<T> {
143
+ data: T;
144
+ status: number;
145
+ headers: HttpHeadersGetter;
146
+ config: RequestConfig;
147
+ statusText: string;
148
+ /** Added in AngularJS 1.6.6 */
149
+ xhrStatus: "complete" | "error" | "timeout" | "abort";
150
+ }
151
+
152
+ export type HttpPromise<T> = Promise<HttpResponse<T>>;
153
+
154
+ /**
155
+ * HttpService
156
+ */
157
+ export interface HttpService {
158
+ /**
159
+ * Object describing the request to be made and how it should be processed.
160
+ */
161
+ <T>(config: RequestConfig): HttpPromise<T>;
162
+
163
+ /**
164
+ * Shortcut method to perform GET request.
165
+ *
166
+ * @param url Relative or absolute URL specifying the destination of the request
167
+ * @param config Optional configuration object
168
+ */
169
+ get<T>(url: string, config?: RequestShortcutConfig): HttpPromise<T>;
170
+
171
+ /**
172
+ * Shortcut method to perform DELETE request.
173
+ *
174
+ * @param url Relative or absolute URL specifying the destination of the request
175
+ * @param config Optional configuration object
176
+ */
177
+ delete<T>(url: string, config?: RequestShortcutConfig): HttpPromise<T>;
178
+
179
+ /**
180
+ * Shortcut method to perform HEAD request.
181
+ *
182
+ * @param url Relative or absolute URL specifying the destination of the request
183
+ * @param config Optional configuration object
184
+ */
185
+ head<T>(url: string, config?: RequestShortcutConfig): HttpPromise<T>;
186
+
187
+ /**
188
+ * Shortcut method to perform JSONP request.
189
+ *
190
+ * @param url Relative or absolute URL specifying the destination of the request
191
+ * @param config Optional configuration object
192
+ */
193
+ jsonp<T>(url: string, config?: RequestShortcutConfig): HttpPromise<T>;
194
+
195
+ /**
196
+ * Shortcut method to perform POST request.
197
+ *
198
+ * @param url Relative or absolute URL specifying the destination of the request
199
+ * @param data Request content
200
+ * @param config Optional configuration object
201
+ */
202
+ post<T>(
203
+ url: string,
204
+ data: any,
205
+ config?: RequestShortcutConfig,
206
+ ): HttpPromise<T>;
207
+
208
+ /**
209
+ * Shortcut method to perform PUT request.
210
+ *
211
+ * @param url Relative or absolute URL specifying the destination of the request
212
+ * @param data Request content
213
+ * @param config Optional configuration object
214
+ */
215
+ put<T>(
216
+ url: string,
217
+ data: any,
218
+ config?: RequestShortcutConfig,
219
+ ): HttpPromise<T>;
220
+
221
+ /**
222
+ * Shortcut method to perform PATCH request.
223
+ *
224
+ * @param url Relative or absolute URL specifying the destination of the request
225
+ * @param data Request content
226
+ * @param config Optional configuration object
227
+ */
228
+ patch<T>(
229
+ url: string,
230
+ data: any,
231
+ config?: RequestShortcutConfig,
232
+ ): HttpPromise<T>;
233
+
234
+ /**
235
+ * Runtime equivalent of the $httpProvider.defaults property. Allows configuration of default headers, withCredentials as well as request and response transformations.
236
+ */
237
+ defaults: HttpProviderDefaults;
238
+
239
+ /**
240
+ * Array of config objects for currently pending requests. This is primarily meant to be used for debugging purposes.
241
+ */
242
+ pendingRequests: RequestConfig[];
243
+ }
@@ -9,17 +9,27 @@ import { isDefined, isPromiseLike, isUndefined } from "../../shared/utils.js";
9
9
  * {@link ng.$http $http}.
10
10
  *
11
11
  */
12
- export function HttpBackendProvider() {
13
- this.$get = [
14
- "$browser",
15
- /**
16
- * @param {import('../browser.js').Browser} $browser
17
- * @returns
18
- */
19
- function ($browser) {
20
- return createHttpBackend($browser);
21
- },
22
- ];
12
+ /**
13
+ * HTTP backend used by the {@link ng.$http service} that delegates to
14
+ * XMLHttpRequest object and deals with browser incompatibilities.
15
+ *
16
+ * You should never need to use this service directly, instead use the higher-level abstractions:
17
+ * {@link ng.$http $http}.
18
+ *
19
+ */
20
+ export class HttpBackendProvider {
21
+ constructor() {
22
+ this.$get = [
23
+ "$browser",
24
+ /**
25
+ * @param {import('../browser.js').Browser} $browser
26
+ * @returns
27
+ */
28
+ function ($browser) {
29
+ return createHttpBackend($browser);
30
+ },
31
+ ];
32
+ }
23
33
  }
24
34
 
25
35
  /**
@@ -0,0 +1,39 @@
1
+ /**
2
+ * A function that logs messages. Accepts any number of arguments.
3
+ */
4
+ export type LogCall = (...args: any[]) => void;
5
+
6
+ /**
7
+ * A function that returns a LogService implementation.
8
+ */
9
+ export type LogServiceFactory = (...args: any[]) => LogService;
10
+
11
+ /**
12
+ * Service for logging messages at various levels.
13
+ */
14
+ export interface LogService {
15
+ /**
16
+ * Log a debug message.
17
+ */
18
+ debug: LogCall;
19
+
20
+ /**
21
+ * Log an error message.
22
+ */
23
+ error: LogCall;
24
+
25
+ /**
26
+ * Log an info message.
27
+ */
28
+ info: LogCall;
29
+
30
+ /**
31
+ * Log a general message.
32
+ */
33
+ log: LogCall;
34
+
35
+ /**
36
+ * Log a warning message.
37
+ */
38
+ warn: LogCall;
39
+ }
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>AngularTS Test Runner</title>
6
+
7
+ <link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
8
+ <link rel="stylesheet" href="/jasmine/jasmine.css" />
9
+ <link rel="stylesheet" href="/public/jasmine-helper.css" />
10
+ <script src="/jasmine/jasmine.js"></script>
11
+ <script src="/jasmine/jasmine-html.js"></script>
12
+ <script src="/jasmine/boot0.js"></script>
13
+ <script src="/jasmine/boot1.js"></script>
14
+ <script type="module" src="/src/services/log/log.spec.js"></script>
15
+ </head>
16
+ <body>
17
+ <div id="app"></div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,74 @@
1
+ import { isError } from "../../shared/utils.js";
2
+
3
+ /**
4
+ * Configuration provider for `$log` service
5
+ */
6
+ export class LogProvider {
7
+ /** @private */
8
+ constructor() {
9
+ /** @type {boolean} */
10
+ this.debug = false;
11
+ /** @private @type {import("./interface.ts").LogServiceFactory | null} */
12
+ this._override = null;
13
+ }
14
+
15
+ /**
16
+ * Override the default {@link LogService} implemenation
17
+ * @param {import("./interface.ts").LogServiceFactory} fn
18
+ */
19
+ setLogger(fn) {
20
+ this._override = fn;
21
+ }
22
+
23
+ /** @private */
24
+ formatError(arg) {
25
+ if (isError(arg)) {
26
+ if (arg.stack) {
27
+ arg =
28
+ arg.message && arg.stack.indexOf(arg.message) === -1
29
+ ? `Error: ${arg.message}\n${arg.stack}`
30
+ : arg.stack;
31
+ } else if (arg.sourceURL) {
32
+ arg = `${arg.message}\n${arg.sourceURL}:${arg.line}`;
33
+ }
34
+ }
35
+ return arg;
36
+ }
37
+
38
+ /**
39
+ * @private
40
+ * @param {string} type
41
+ */
42
+ consoleLog(type) {
43
+ const console = window.console || {};
44
+ const logFn = console[type] || console.log || (() => {});
45
+
46
+ return (...args) => {
47
+ const formattedArgs = args.map((arg) => this.formatError(arg));
48
+ return logFn.apply(console, formattedArgs);
49
+ };
50
+ }
51
+
52
+ /**
53
+ * @returns {import("./interface.ts").LogService}
54
+ */
55
+ $get() {
56
+ if (this._override) {
57
+ return this._override();
58
+ }
59
+ return {
60
+ log: this.consoleLog("log"),
61
+ info: this.consoleLog("info"),
62
+ warn: this.consoleLog("warn"),
63
+ error: this.consoleLog("error"),
64
+ debug: (() => {
65
+ const fn = this.consoleLog("debug");
66
+ return (...args) => {
67
+ if (this.debug) {
68
+ fn.apply(this, args);
69
+ }
70
+ };
71
+ })(),
72
+ };
73
+ }
74
+ }
@@ -0,0 +1,64 @@
1
+ import { createInjector } from "../../core/di/injector.js";
2
+ import { Angular } from "../../loader.js";
3
+ import { dealoc } from "../../shared/dom.js";
4
+
5
+ describe("$logService", () => {
6
+ let $logService,
7
+ logProvider,
8
+ el,
9
+ log = [];
10
+
11
+ beforeEach(() => {
12
+ el = document.getElementById("app");
13
+ el.innerHTML = "";
14
+ let angular = new Angular();
15
+ angular.module("default", []).config(($logProvider) => {
16
+ logProvider = $logProvider;
17
+ });
18
+ angular.bootstrap(el, ["default"]).invoke((_$log_) => {
19
+ $logService = _$log_;
20
+ });
21
+
22
+ window.console["error"] = (msg) => {
23
+ log.push(msg);
24
+ };
25
+ });
26
+
27
+ afterEach(() => {
28
+ dealoc(el);
29
+ });
30
+
31
+ it("should be available as a provider", () => {
32
+ expect(logProvider).toBeDefined();
33
+ expect(logProvider.debug).toBeFalse();
34
+ expect(typeof logProvider.$get).toBe("function");
35
+ });
36
+
37
+ it("should be injectable", () => {
38
+ expect($logService).toBeDefined();
39
+ expect(typeof $logService.debug).toBe("function");
40
+ });
41
+
42
+ it("should call console.error by default when $log.error is called", () => {
43
+ $logService.error("error message");
44
+ expect(log[0]).toEqual("error message");
45
+ });
46
+
47
+ it("can be overriden", () => {
48
+ let called = false;
49
+ angular.module("default2", []).config(($logProvider) => {
50
+ $logProvider.setLogger(() => ({
51
+ log: () => (called = true),
52
+ info: () => {},
53
+ warn: () => {},
54
+ error: () => {},
55
+ debug: () => {},
56
+ }));
57
+ });
58
+
59
+ let $injector = createInjector(["ng", "default2"]);
60
+ expect($injector).toBeDefined();
61
+ $injector.get("$log").log();
62
+ expect(called).toBeTrue();
63
+ });
64
+ });
@@ -0,0 +1,11 @@
1
+ import { test, expect } from "@playwright/test";
2
+
3
+ const TEST_URL = "src/services/log/log.html?random=false";
4
+
5
+ test("unit tests contain no errors", async ({ page }) => {
6
+ await page.goto(TEST_URL);
7
+ await page.content();
8
+ await expect(page.locator(".jasmine-overall-result")).toHaveText(
9
+ /0 failures/,
10
+ );
11
+ });
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>AngularTS Test Runner</title>
6
+
7
+ <link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
8
+ <link rel="stylesheet" href="/jasmine/jasmine.css" />
9
+ <link rel="stylesheet" href="/public/jasmine-helper.css" />
10
+ <script src="/jasmine/jasmine.js"></script>
11
+ <script src="/jasmine/jasmine-html.js"></script>
12
+ <script src="/jasmine/boot0.js"></script>
13
+ <script src="/jasmine/boot1.js"></script>
14
+ <script type="module" src="/src/services/pubsub/pubsub.spec.js"></script>
15
+ </head>
16
+ <body>
17
+ <div id="app"></div>
18
+ </body>
19
+ </html>