Skip to content

Commit

Permalink
Merge branch 'master' into next-013
Browse files Browse the repository at this point in the history
  • Loading branch information
igorkamyshev authored Jul 31, 2024
2 parents f415680 + 56db427 commit 7f303b9
Show file tree
Hide file tree
Showing 72 changed files with 230 additions and 370 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
Latest canary version is ${{ steps.canary_info.outputs.canaryVersion }}
[More information about canary versions](https://farfetched.pages.dev/releases/canary.html)
[More information about canary versions](https://ff.effector.dev/releases/canary.html)
---
Expand All @@ -76,7 +76,7 @@ jobs:
Latest canary version is ${{ steps.canary_info.outputs.canaryVersion }}
[More information about canary versions](https://farfetched.pages.dev/releases/canary.html)
[More information about canary versions](https://ff.effector.dev/releases/canary.html)
---
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ While writing RFC, keep in mind that the new API (or changes in the existing API
2. Be consistent. The new feature should be consistent with the existing API. It should not introduce new concepts or patterns that are not used in the existing API unless it is necessary.
3. Simple solutions for simple problems, complex solutions for complex problems. Not vice versa.

Read existing [ADRs](https://farfetched.pages.dev/adr/) to get an understanding of the existing API and principles.
Read existing [ADRs](https://ff.effector.dev/adr/) to get an understanding of the existing API and principles.

## How to create a good implementation

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The advanced data fetching tool for web applications

### Documentation

Continue reading about Farfetched in the [documentation](https://farfetched.pages.dev). It covers integration with the most popular UI-frameworks (such React and Solid), error handling, dependent queries, advanced contracts and other great tools.
Continue reading about Farfetched in the [documentation](https://ff.effector.dev). It covers integration with the most popular UI-frameworks (such React and Solid), error handling, dependent queries, advanced contracts and other great tools.

### Showcases

Expand Down
3 changes: 1 addition & 2 deletions apps/showcase-forest-real-world-breaking-bad/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"build": "vite build"
},
"dependencies": {
"runtypes": "^6.5.1",
"@farfetched/runtypes": "workspace:*",
"@withease/contracts": "^1.0.0",
"@farfetched/core": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Record, String } from 'runtypes';
import { obj, str } from '@withease/contracts';

export const Quote = Record({
author: String,
quote: String,
export const Quote = obj({
author: str,
quote: str,
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { concurrency, createJsonQuery, declareParams } from '@farfetched/core';
import { runtypeContract } from '@farfetched/runtypes';
import { Array } from 'runtypes';
import { arr } from '@withease/contracts';

import { Quote } from './contract';

Expand All @@ -13,7 +12,7 @@ export const randomQuotesQuery = createJsonQuery({
`https://api.breakingbadquotes.xyz/v1/quotes/${amount}`,
},
response: {
contract: runtypeContract(Array(Quote)),
contract: arr(Quote),
},
});

Expand Down
3 changes: 1 addition & 2 deletions apps/showcase-react-real-world-pokemons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"build": "vite build"
},
"dependencies": {
"runtypes": "^6.5.1",
"@farfetched/runtypes": "workspace:*",
"@withease/contracts": "^1.0.0",
"@farfetched/core": "workspace:*"
}
}
4 changes: 1 addition & 3 deletions apps/showcase-react-real-world-pokemons/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const router = createBrowserRouter([
},
]);

function App() {
export function App() {
return <RouterProvider router={router} />;
}

export { App };
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { TId } from '../../shared/id';
export function pokemonUrl(): string;
export function pokemonUrl({ id }: { id: number }): string;

function pokemonUrl(): string;
function pokemonUrl({ id }: { id: TId }): string;

function pokemonUrl(params?: { id: TId }) {
export function pokemonUrl(params?: { id: number }) {
if (params?.id) {
return `https://pokeapi.co/api/v2/pokemon/${params.id}`;
}

return 'https://pokeapi.co/api/v2/pokemon';
}

function speciesUrl(): string;
function speciesUrl({ id }: { id: TId }): string;
export function speciesUrl(): string;
export function speciesUrl({ id }: { id: number }): string;

function speciesUrl(params?: { id: TId }) {
export function speciesUrl(params?: { id: number }) {
if (params?.id) {
return `https://pokeapi.co/api/v2/pokemon-species/${params.id}`;
}

return 'https://pokeapi.co/api/v2/pokemon-species';
}

export { pokemonUrl, speciesUrl };
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { Number, Record, String } from 'runtypes';
import { obj, num, str } from '@withease/contracts';

import { EntityLink } from '../../shared/entity_link';
import { Id } from '../../shared/id';
import { Url } from '../../shared/url';

export const Pokemon = Record({
id: Id,
name: String,
height: Number,
weight: Number,
sprites: Record({ front_default: Url }),
export const Pokemon = obj({
id: num,
name: str,
height: num,
weight: num,
sprites: obj({ front_default: str }),
species: EntityLink,
});

export const Species = Record({
id: Id,
name: String,
export const Species = obj({
id: num,
name: str,
color: EntityLink,
generation: EntityLink,
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { concurrency, createJsonQuery, declareParams } from '@farfetched/core';
import { runtypeContract } from '@farfetched/runtypes';
import { Array, Number, Record } from 'runtypes';
import { arr, num, obj } from '@withease/contracts';
import { createGate } from 'effector-react';
import { combine, createStore, sample } from 'effector';

Expand All @@ -23,9 +22,7 @@ const pokemonListQuery = createJsonQuery({
},
},
response: {
contract: runtypeContract(
Record({ count: Number, results: Array(EntityLink) })
),
contract: obj({ count: num, results: arr(EntityLink) }),
mapData({ result }) {
return {
...result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
createJsonQuery,
declareParams,
} from '@farfetched/core';
import { runtypeContract } from '@farfetched/runtypes';
import { createGate } from 'effector-react';
import { combine, sample } from 'effector';

Expand All @@ -14,18 +13,18 @@ import {
Species,
speciesUrl,
} from '../../entities/pokemon';
import { TId, urlToId } from '../../shared/id';
import { urlToId } from '../../shared/id';

export const PokemonPageGate = createGate<{ id: number }>();

const pokemonQuery = createJsonQuery({
params: declareParams<{ id: TId }>(),
params: declareParams<{ id: number }>(),
request: {
method: 'GET',
url: ({ id }) => pokemonUrl({ id }),
},
response: {
contract: runtypeContract(Pokemon),
contract: Pokemon,
mapData({ result: { sprites, ...data } }) {
return {
...data,
Expand All @@ -38,13 +37,13 @@ const pokemonQuery = createJsonQuery({
concurrency(pokemonQuery, { strategy: 'TAKE_LATEST' });

const speciesQuery = createJsonQuery({
params: declareParams<{ id: TId }>(),
params: declareParams<{ id: string }>(),
request: {
method: 'GET',
url: ({ id }) => speciesUrl({ id }),
},
response: {
contract: runtypeContract(Species),
contract: Species,
},
});

Expand All @@ -59,7 +58,7 @@ export const $pokemon = combine(
sample({
clock: PokemonPageGate.state,
filter: (params) => Boolean(params.id),
fn: ({ id }) => ({ id }) as { id: TId },
fn: ({ id }) => ({ id }),
target: pokemonQuery.start,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Record, String } from 'runtypes';
import { obj, str } from '@withease/contracts';

import { Url } from './url';

export const EntityLink = Record({
name: String,
url: Url,
export const EntityLink = obj({
name: str,
url: str,
});
11 changes: 1 addition & 10 deletions apps/showcase-react-real-world-pokemons/src/shared/id.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import { Number, Static } from 'runtypes';

import { TUrl } from './url';

const Id = Number.withBrand('Id');

type TId = Static<typeof Id>;

function urlToId(url: TUrl): TId {
export function urlToId(url: string): string {
return parseInt(url.split('/').filter(Boolean).at(-1) ?? '', 10) as TId;
}
export { urlToId, Id, type TId };
7 changes: 0 additions & 7 deletions apps/showcase-react-real-world-pokemons/src/shared/url.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/showcase-solid-real-world-rick-morty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"build": "vite build"
},
"dependencies": {
"runtypes": "^6.5.1",
"@farfetched/runtypes": "workspace:*",
"@withease/contracts": "^1.0.0",
"@farfetched/core": "workspace:*",
"@farfetched/solid": "workspace:*",
"@farfetched/dev-tools": "workspace:*"
Expand Down
5 changes: 1 addition & 4 deletions apps/showcase-solid-real-world-rick-morty/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ const router = createHistoryRouter({
});

const history = createBrowserHistory();
// @ts-expect-error will be fixes after new router
router.setHistory(history);

function App() {
export function App() {
return (
<RouterProvider router={router}>
<Menu />
Expand All @@ -42,5 +41,3 @@ function App() {
</RouterProvider>
);
}

export { App };
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { TId } from '../../shared/id';
export function characterUrl(): string;
export function characterUrl({ id }: { id: number }): string;
export function characterUrl({ ids }: { ids: number[] }): string;

function characterUrl(): string;
function characterUrl({ id }: { id: TId }): string;
function characterUrl({ ids }: { ids: TId[] }): string;

function characterUrl(params?: { id?: TId; ids?: TId[] }) {
export function characterUrl(params?: { id?: number; ids?: number[] }) {
if (params?.ids) {
return `https://rickandmortyapi.com/api/character/[${params.ids.join(
','
Expand All @@ -17,5 +15,3 @@ function characterUrl(params?: { id?: TId; ids?: TId[] }) {

return 'https://rickandmortyapi.com/api/character';
}

export { characterUrl };
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import { Array, Literal, Record, String, Union } from 'runtypes';
import { arr, val, obj, str, or, num } from '@withease/contracts';

import { Id } from '../../shared/id';
import { Url } from '../../shared/url';
const UnknownLiteral = val('unknown');

const UnknownLiteral = Literal('unknown');
const Status = or(val('Alive'), val('Dead'), UnknownLiteral);

const Status = Union(Literal('Alive'), Literal('Dead'), UnknownLiteral);

const Gender = Union(
Literal('Female'),
Literal('Male'),
Literal('Genderless'),
const Gender = or(
val('Female'),
val('Male'),
val('Genderless'),
UnknownLiteral
);

const LocationLink = Record({ name: String, url: Url });
const LocationLink = obj({ name: str, url: str });

const Character = Record({
id: Id,
name: String,
export const Character = obj({
id: num,
name: str,
status: Status,
species: String,
type: String,
species: str,
type: str,
gender: Gender,
origin: LocationLink,
location: LocationLink,
image: Url,
episode: Array(Url),
episode: arr(str),
image: str,
});

export { Character };
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { createRoute } from 'atomic-router';

import { TId } from '../../shared/id';

const characterRoute = createRoute<{ characterId: TId }>();
const characterListRoute = createRoute<{ page?: number }>();

export { characterRoute, characterListRoute };
export const characterRoute = createRoute<{ characterId: number }>();
export const characterListRoute = createRoute<{ page?: number }>();
Loading

0 comments on commit 7f303b9

Please sign in to comment.