Commit graph

355 commits

Author SHA1 Message Date
Andrew Scott
abcb865474 fix(common): avoid injecting ApplicationRef in FetchBackend (#61649)
fixes a circular dependency caused by injecting applicationRef

fixes #61644

PR Close #61649
2025-05-23 10:04:08 -07:00
Maciej Sawicki
05eb028c7a fix(core): narrow error type for resources API (#61441)
`Resource.error` used to return `unknown`. Now it's `Error | undefined`.
For non-`Error` types they are encapsulated with the `Error` type.

PR Close #61441
2025-05-21 12:06:40 -07:00
Maciej Sawicki
07811ddd7d fix(core): move reload method from Resource to WritableResource (#61441)
Now only mutable resources can be reloaded.

PR Close #61441
2025-05-21 12:06:40 -07:00
arturovt
93e8565f0e fix(core): cleanup rxResource abort listener (#58306)
The observable terminates immediately when `error` is called, and no further emissions or completion notifications occur. Thus, we have to remove the `abort` listener in both the `error` and `complete` notifications.

PR Close #58306
2025-05-21 15:17:22 +00:00
arturovt
17fe731e8e fix(common): cancel reader when app is destroyed (#61528)
Streams left in a pending state (due to `break` without cancel) may continue consuming or holding onto data behind the scenes. Calling `reader.cancel()` allows the browser or the underlying system to release any network or memory resources associated with the stream.

PR Close #61528
2025-05-21 15:07:17 +00:00
arturovt
216222f8b4 refactor(common): drop httpResource error message (#61570)
Drops `httpResource` error message in production and replaces with an error code.

PR Close #61570
2025-05-21 14:16:53 +00:00
arturovt
62185714b5 refactor(core): drop injection context assertion in production (#61564)
In other parts of the code, calls to the `assertInInjectionContext` function are guarded with `ngDevMode`. This change aligns these parts of the code with other implementations that drop such assertions in production.

PR Close #61564
2025-05-21 12:42:10 +00:00
arturovt
87688942d4 fix(common): prevent reading chunks if app is destroyed (#61354)
Prevents processing response chunks after the application has been destroyed.

PR Close #61354
2025-05-20 15:09:44 +00:00
Joey Perrott
3440338d45 build: migrate common to use rules_js based toolchain (#61433)
Migrate packages/common to use ts_project and ng_project.

PR Close #61433
2025-05-20 15:07:56 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Paul Gschwendtner
b763059bdd build: migrate packages/core/schematics to ts_project (#61370)
Migrates `packages/core/schematics` to `ts_project`. As part of this,
this commit cleans up some of the mixed module types and tsconfigs in
the folder. A single tsconfig (and it's test variant) are now used.

For the shipped schematics, we explicitly use the `.cjs` extension, so
that the bundles are properly recognized as CommonJS; even if they are
part of the `type: module` `@angular/core` package.

The `package.json` with `type: commonjs` is removed from
`packages/core/schematics` as it's no longer needed given the explicit
extension & caused issues as schematics are compiled with ESM but are
only later bundled for shipping & some tests as ESM.

PR Close #61370
2025-05-16 11:02:07 +00:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Matthieu Riegler
f580318411 docs(docs-infra): Add version of introduction for APIs (#60814)
For new APIs we'll mention since when a particular API is in its current status (experimental, devPreview, stable)

fixes #49668

PR Close #60814
2025-05-02 07:51:33 -07:00
arturovt
1e2a70c8db refactor(common): drop platform checks in HttpXsrfCookieExtractor (#59810)
Replaces `PLATFORM_ID` checks with `ngServerMode` within the `HttpXsrfCookieExtractor`. It is not part of the public API, and thus this change should not affect consumers who may have called the constructor directly.

PR Close #59810
2025-05-01 08:41:10 -07:00
cexbrayat
fc4a56d5c5 fix(common): rename httpResource function in factory (#60022)
As the function in the factory was named `httpResourceRef`, error NG0203 had with the following message:

```
Error: NG0203: httpResourceRef() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.dev/errors/NG0203
```

PR Close #60022
2025-04-30 08:51:39 -07:00
SkyZeroZx
ccc5cc068f feat(http): add keepalive support for fetch requests (#60621)
This commit adds support for the Fetch API's keepalive option when using HttpClient with the withFetch provider.

The change includes:
- Added keepalive to HttpRequestInit interface
- Modified FetchBackend to pass the option
- Added some unit test

PR Close #60621
2025-04-24 15:08:52 -07:00
Alex Rickabaugh
d0c9a6401a refactor(core): rename resource's request to params (#60919)
As decided in the resource RFC, this commit renames the `request` option of
a resource to `params`, including the subsequent argument passed to the
loader. It also corrects the type in the process to properly allow narrowing
of the `undefined` value.

Fixes #58871

PR Close #60919
2025-04-23 19:34:50 +00:00
Alex Rickabaugh
d8ca560a15 refactor(core): convert ResourceStatus to a string type (#60919)
An outcome of the Resource RFC was that we should use string constants for
communicating the resource status instead of an enum. This commit converts
`ResourceStatus` accordingly.

PR Close #60919
2025-04-23 19:34:50 +00:00
Alex Rickabaugh
b1bfb214ef refactor(common): delete unused code for HttpResource (#60919)
Remove the code related to exposing the response of an HTTP request as a
`Resource` itself, as the final API will not go in this direction.

PR Close #60919
2025-04-23 19:34:50 +00:00
Pawel Kozlowski
0859a99e89 refactor(core): replace TestBed.flushEffects with tick (#60959)
Instead of stabilizing the TestBed.flushEffects() API we intend to
replace it with the tick() method (equivalent of ApplicationRef.tick().
The reasoning here is that we prefer tests running the entire
synchronization process (as in production apps) instead of invoking
parts of the synchronization process in a way that would naver happen
in a running application.

PR Close #60959
2025-04-23 09:54:30 +02:00
Vincent
9f31947aad fix(http): Include HTTP status code and headers when HTTP requests errored in httpResource (#60802)
Currently the HTTP status code and headers are only included if the request succeeded. Given status codes convey more information in case of a request error vs. success, this makes it more useful than inspecting what is contained in `.error()`.

PR Close #60802
2025-04-09 14:25:02 -07:00
Kirill Cherkashin
80a32588b4 docs: Update guide link in http package md file (#59955)
PR Close #59955
2025-04-08 09:20:19 -07:00
Andrew Scott
5795e03cdf fix(http): Delay stabilization until next app synchronization (#60656)
This commit updates the `HttpClient` internals to use the public
`PendingTasks` API which delays stability until the next
`ApplicationRef.tick` instead of causing the application to become
stable synchronously. This is helpful to resolve unexpected issues where
computations happen as follow-up work to the value coming out of the
response.

fixes https://github.com/angular/angular/issues/59352

PR Close #60656
2025-04-03 12:52:34 -07:00
arturovt
1c7b356625 fix(core): release hasPendingTasks observers (#59723)
In this commit, we unsubscribe the `hasPendingTasks` subject to remove all active observers and enable granular garbage collection, as users may forget to unsubscribe manually when subscribing to `isStable`.

PR Close #59723
2025-04-02 18:26:06 +00:00
( Nechiforel David-Samuel ) NsdHSO
84ca0ef2d0 refactor: added typing for Response (#60541)
This adds a better re-usable type for Response in HttpResource.

PR Close #60541
2025-04-02 16:33:22 +00:00
Matthieu Riegler
23e4da430a refactor(http): remove non reactive signature from httpResource. (#60537)
The non reactive usage ``httpResource(\`http://test/${myId()}\`` gave the false impression that it was reactive when the signal was invoked. We prevent any possibility of oversight by removing the non reactive signature.

PR Close #60537
2025-04-02 11:35:23 +00:00
Andrew Kushnir
3fa7b2b136 refactor(common): convert scripts within packages/common to relative imports (#60623)
This commit updates scripts within `packages/common` to relative imports as a prep work to the upcoming infra updates.

PR Close #60623
2025-04-01 15:58:51 +00:00
Matthieu Riegler
51c303a45c refactor(core): remove TODOs referencing #24571 (#60648)
Fixing those todos are now mostly breaking changes.
The situation is "good" as is.

PR Close #60648
2025-03-31 20:24:29 +00:00
Vlad Boisa
302cb83d85 docs: remove todo comment (#59928)
Removes outdated todo comment

PR Close #59928
2025-03-31 19:57:56 +00:00
Kristiyan Kostadinov
5e209cb560 feat(core): remove TestBed.get (#60414)
`TestBed.get` isn't type safe and has been deprecated for several years now. These changes remove it from the public API and a follow-up change will add an automated migration to `TestBed.inject`.

BREAKING CHANGE:
* `TestBed.get` has been removed. Use `TestBed.inject` instead.

PR Close #60414
2025-03-19 15:52:26 +01:00
Matthieu Riegler
f5f2549808 refactor(http): replace overriden method with a ts declare (#60278)
This allows us to drop the useless `super.hasValue()`.

PR Close #60278
2025-03-12 12:27:47 -07:00
arturovt
3602c536e4 refactor(common): drop error messages in production (#60242)
Drops more error messages in production.

PR Close #60242
2025-03-10 10:04:03 -07:00
Matthieu Riegler
2668bd96b9 refactor(http): Make sur to pass context & transferCache from httpResource to the underlying request. (#60228)
Prior to this change, both were accepted as argument but never passed to the client.

PR Close #60228
2025-03-06 07:59:06 -08:00
cexbrayat
92250493ff fix(common): support equality function in httpResource (#60026)
The `equal` option was not passed to the underlying resource.

PR Close #60026
2025-03-05 14:41:15 -08:00
Matthieu Riegler
bb14fe86e3 refactor(http): add context property to httpResource (#60188)
This was an oversight, `context` can be supported out of the box.

PR Close #60188
2025-03-04 19:57:21 +00:00
Matthieu Riegler
919c4521ec refactor(http): rename map to parse on HttpResourceOptions (#60112)
This reflects more the feature intended for this callback.

PR Close #60112
2025-02-26 11:52:43 -05:00
Kristiyan Kostadinov
07338c0aeb fix(common): make types for HttpClient more readable (#59901)
`HttpClient` has a lot of overloads to achieve proper type checking, however each overload is also very long which makes it hard to read on adev. These changes replace the object literal types with `Record` to make them a bit more concise.

PR Close #59901
2025-02-25 13:01:09 -05:00
Alex Rickabaugh
3e39da593a feat(common): introduce experimental httpResource (#59876)
`httpResource` is a new frontend to the `HttpClient` infrastructure. It
declares a dependency on an HTTP endpoint. The request to be made can be
reactive, updating in response to signals for the URL, method, or otherwise.
The response is returned as an instance of `HttpResource`, a
`WritableResource` with some additional signals which represent parts of the
HTTP response metadata (status, headers, etc).

PR Close #59876
2025-02-14 18:40:37 +00:00
arturovt
f34aeaeaad refactor(common): remove redundant transferCacheInterceptorFn dependencies (#59819)
The `transferCacheInterceptorFn` injects dependencies in itself; the `TransferCache` and cache options are redundant in the `deps` list.

PR Close #59819
2025-02-13 15:11:19 +00:00
arturovt
b7dd0483d0 refactor(common): drop error messages in production (#59545)
Switches to using `RuntimeError` and drops error messages in production by replacing it with an error code.

PR Close #59545
2025-01-28 09:39:42 +01:00
arturovt
6fc180b3ff refactor(common): prevent duplicating Accept header name (#59546)
Drops some bytes by moving `Accept` into a variable, which is then minified to something like `var a="Accept"` and reused in all the places.

PR Close #59546
2025-01-23 14:21:51 -08:00
arturovt
2e138e644c refactor(common): prevent duplicating Content-Type header (#59518)
Drops some bytes by moving `Content-Type` into a variable, which is then minified to something like `var b="Content-Type"` and reused in all the places.

PR Close #59518
2025-01-15 12:22:29 -08:00
arturovt
3b3040d32a refactor(common): drop error message in production (#59471)
Switches to using `RuntimeError` and drops the error message in production by replacing it with an error code.

PR Close #59471
2025-01-15 12:28:29 -05:00
Andrew Kushnir
eadf6a35bb Revert "refactor: initialize headers map directly in HttpHeaders class (#59268)" (#59523)
This reverts commit e15226a444.

PR Close #59523
2025-01-14 17:48:34 -05:00
hawkgs
b9155b5121 docs: set syntax highlighting to the remaining Markdown code examples blocks (#59088)
There are some code blocks that slipped through the initial Regex-es.

Related to #59026

PR Close #59088
2025-01-14 15:14:02 -05:00
arturovt
1ff5cd6906 refactor(common): tree-shake transfer cache interceptor stuff (#59439)
In this commit, we replace `isPlatformServer` runtime call with the `ngServerMode` in the `transferCacheInterceptorFn` in order to make the functionality tree-shakable between client and server bundles.

PR Close #59439
2025-01-14 14:40:05 -05:00
RafaelJCamara
e15226a444 refactor: initialize headers map directly in HttpHeaders class (#59268)
Improved the initialization of the headers map to enhance performance
and code readability.

No breaking changes.

PR Close #59268
2025-01-14 10:50:15 -05:00
arturovt
5d6358168a refactor(common): prevent duplicating Accept header (#59467)
In this commit, we extract content types into a variable to eliminate extra bytes, as these values are duplicated in multiple places.

PR Close #59467
2025-01-13 12:38:46 -05:00
arturovt
d51d67b725 refactor(common): prevent duplicating X-Request-URL (#59420)
The `X-Request-URL` string is duplicated in multiple places. It is worth moving it to a shared constant that would be minified to something like `const a = "X-Request-URL"` and referenced in all the used places.

PR Close #59420
2025-01-09 18:18:24 -05:00
arturovt
e194573d0d refactor(common): tree-shake fetch backend (#59418)
This commit updates the code of the HTTP code to make the `FetchBackend` class tree-shakable. The class is only needed with `withFetch()` is called and it should not be included into bundles that do not use that feature.

PR Close #59418
2025-01-09 13:05:56 -05:00