Skip to content

Commit

Permalink
Merge pull request #50 from web-pacotes/49-refactor-replace-internal-…
Browse files Browse the repository at this point in the history
…monads-with-foundation-types

refactor: replace internal monads with those provided in @web-pacotes/foundation-types
  • Loading branch information
freitzzz authored May 20, 2024
2 parents d433644 + 43798f3 commit 7717d55
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 253 deletions.
12 changes: 10 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,8 @@
"ts-jest": "^29.1.0",
"tsup": "^6.7.0",
"typescript": "^5.0.4"
},
"dependencies": {
"@web-pacotes/foundation-types": "^0.0.4"
}
}
14 changes: 7 additions & 7 deletions src/clients/networking_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
resolveUrl
} from '../models';
import { FetchClient } from '../models';
import { Either, fold, left, right } from '../type-utils';
import { Either, fold, Left, Right } from '@web-pacotes/foundation-types';

/**
* An alias for {@link NetworkingClient} positional parameters.
Expand Down Expand Up @@ -235,26 +235,26 @@ export class NetworkingClient {
});

if (eager ?? true) {
result = right(
result = Right(
await HttpResponse.fromEagerFetchResponse(fetchResponse)
);
} else {
result = right(HttpResponse.fromFetchResponse(fetchResponse));
result = Right(HttpResponse.fromFetchResponse(fetchResponse));
}
} catch (err) {
if (err === undefined) {
result = left(new NoInternetConnectionError());
result = Left(new NoInternetConnectionError());
} else if (!(err instanceof Error)) {
result = left(new UnknownError({ cause: `${err}` }));
result = Left(new UnknownError({ cause: `${err}` }));
} else if (err.name === 'TimeoutError') {
result = left(
result = Left(
new TimeoutError({
cause: err.message,
timeoutMS: this.timeoutMS
})
);
} else {
result = left(new UnknownError({ cause: JSON.stringify(err) }));
result = Left(new UnknownError({ cause: JSON.stringify(err) }));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/clients/proxy_networking_client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpRequest, HttpRequestError, HttpResponse } from '../models';
import { Either } from '../type-utils';
import type { Either } from '@web-pacotes/foundation-types';
import {
NetworkingClient,
NetworkingClientPositionalParameters
Expand Down
12 changes: 4 additions & 8 deletions src/models/body.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Lazy } from '../type-utils';
import { Lazy, compute, computed } from "@web-pacotes/foundation-types";

export type Text = string;
export type Binary = Blob;
Expand Down Expand Up @@ -28,7 +28,7 @@ export function empty(): HttpBody<null> {
* @returns a lazy {@link HttpBody} that does not resolve until computed.
*/
export function of<T = Anything>(value: () => T): HttpBody<T> {
return Lazy.sync(value);
return Lazy(value);
}

/**
Expand All @@ -38,8 +38,8 @@ export function of<T = Anything>(value: () => T): HttpBody<T> {
* @returns a value of {@link T} type, extracted from the {@link HttpBody} type.
*/
export function extract<T = Anything>(body: HttpBody<T>): T {
if (isLazyBody(body)) {
return body.get();
if (!computed(body)) {
return compute(body);
}

return body;
Expand All @@ -63,10 +63,6 @@ export function convert<T = Anything>(body: HttpBody<T>): FetchBody {
}
}

function isLazyBody<T = Anything>(body: HttpBody<T>): body is LazyHttpBody<T> {
return body instanceof Lazy;
}

function isBinary(data: Anything): data is Blob {
return data instanceof Blob;
}
Expand Down
66 changes: 0 additions & 66 deletions src/type-utils/either.test.ts

This file was deleted.

75 changes: 0 additions & 75 deletions src/type-utils/either.ts

This file was deleted.

3 changes: 0 additions & 3 deletions src/type-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
export * from './either';
export * from './lazy';
export * from './option';
export * from './range';
49 changes: 0 additions & 49 deletions src/type-utils/lazy.test.ts

This file was deleted.

38 changes: 0 additions & 38 deletions src/type-utils/lazy.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/type-utils/option.ts

This file was deleted.

0 comments on commit 7717d55

Please sign in to comment.