diff --git a/goldens/public-api/common/http/index.api.md b/goldens/public-api/common/http/index.api.md index b0dbeb59c6b..ba335014e62 100644 --- a/goldens/public-api/common/http/index.api.md +++ b/goldens/public-api/common/http/index.api.md @@ -1724,7 +1724,7 @@ export interface HttpResourceOptions { defaultValue?: NoInfer; equal?: ValueEqualityFn>; injector?: Injector; - map?: (value: TRaw) => TResult; + parse?: (value: TRaw) => TResult; } // @public diff --git a/packages/common/http/src/resource.ts b/packages/common/http/src/resource.ts index 1db25db8116..e7f37021d70 100644 --- a/packages/common/http/src/resource.ts +++ b/packages/common/http/src/resource.ts @@ -239,7 +239,7 @@ function makeHttpResourceFn(responseType: 'arraybuffer' | 'blob' | 'json' injector, () => normalizeRequest(request, responseType), options?.defaultValue, - options?.map as (value: unknown) => TResult, + options?.parse as (value: unknown) => TResult, ) as HttpResourceRef; }; } @@ -312,7 +312,7 @@ class HttpResourceImpl injector: Injector, request: () => HttpRequest | undefined, defaultValue: T, - map?: (value: unknown) => T, + parse?: (value: unknown) => T, ) { super( request, @@ -342,7 +342,7 @@ class HttpResourceImpl this._headers.set(event.headers); this._statusCode.set(event.status); try { - send({value: map ? map(event.body) : (event.body as T)}); + send({value: parse ? parse(event.body) : (event.body as T)}); } catch (error) { send({error}); } diff --git a/packages/common/http/src/resource_api.ts b/packages/common/http/src/resource_api.ts index f99f971397e..3b5219a35a6 100644 --- a/packages/common/http/src/resource_api.ts +++ b/packages/common/http/src/resource_api.ts @@ -81,12 +81,12 @@ export interface HttpResourceOptions { /** * Transform the result of the HTTP request before it's delivered to the resource. * - * `map` receives the value from the HTTP layer as its raw type (e.g. as `unknown` for JSON data). + * `parse` receives the value from the HTTP layer as its raw type (e.g. as `unknown` for JSON data). * It can be used to validate or transform the type of the resource, and return a more specific * type. This is also useful for validating backend responses using a runtime schema validation * library such as Zod. */ - map?: (value: TRaw) => TResult; + parse?: (value: TRaw) => TResult; /** * Value that the resource will take when in Idle, Loading, or Error states. diff --git a/packages/common/http/test/resource_spec.ts b/packages/common/http/test/resource_spec.ts index 631c5325d89..4e7d629cd5a 100644 --- a/packages/common/http/test/resource_spec.ts +++ b/packages/common/http/test/resource_spec.ts @@ -154,7 +154,7 @@ describe('httpResource', () => { }, { injector: TestBed.inject(Injector), - map: (value) => JSON.stringify(value), + parse: (value) => JSON.stringify(value), }, ); TestBed.flushEffects();