Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-spiders-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": minor
---

Delete `concurrency` field in favour of `concurrency` operator
5 changes: 5 additions & 0 deletions .changeset/dry-comics-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": patch
---

Get rid off `response.clone()` to support streaming in edge runtimes
5 changes: 5 additions & 0 deletions .changeset/famous-hornets-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": minor
---

Delete `attachOperation` operator
5 changes: 5 additions & 0 deletions .changeset/metal-dragons-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/dev-tools": minor
---

Add option `logErrorsToConsole`
5 changes: 5 additions & 0 deletions .changeset/old-onions-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": patch
---

Export `ExecutionMeta`
5 changes: 5 additions & 0 deletions .changeset/strange-apes-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farfetched/core": patch
---

Export `attachObservability`
2 changes: 1 addition & 1 deletion apps/showcase-solid-real-world-rick-morty/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import { App } from './app';

render(() => <App />, document.getElementById('root') as HTMLElement);

attachFarfetchedDevTools();
attachFarfetchedDevTools({ logErrorsToConsole: true });
5 changes: 1 addition & 4 deletions apps/website/docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ export default withMermaid(
{ text: 'concurrency', link: '/api/operators/concurrency' },
{ text: 'applyBarrier', link: '/api/operators/apply_barrier' },
{ text: 'update', link: '/api/operators/update' },
{
text: 'attachOperation',
link: '/api/operators/attach_operation',
},
{ text: 'connectQuery', link: '/api/operators/connect_query' },
],
},
Expand Down Expand Up @@ -407,6 +403,7 @@ export default withMermaid(
{
text: 'Releases',
items: [
{ text: 'v0.14', link: '/releases/0-14' },
{ text: 'v0.13 Naiharn', link: '/releases/0-13' },
{ text: 'v0.12 Talat Noi', link: '/releases/0-12' },
{ text: 'v0.11 Namtok Ngao', link: '/releases/0-11' },
Expand Down
11 changes: 0 additions & 11 deletions apps/website/docs/api/factories/create_json_mutation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,3 @@ Config fields:
- `headers`: <Badge type="tip" text="since v0.13" /> raw response headers

- `status.expected`: `number` or `Array<number>` of expected HTTP status codes, if the response status code is not in the list, the mutation will be treated as failed

- `concurrency?`: concurrency settings for the [_Mutation_](/api/primitives/mutation)
::: danger Deprecation warning

This field is deprecated since [v0.12](/releases/0-12) and will be removed in v0.14. Use [`concurrency` operator](/api/operators/concurrency) instead.

Please read [this ADR](/adr/concurrency) for more information and migration guide.

:::

- `abort?`: [_Event_](https://effector.dev/en/api/effector/event/) after calling which all in-flight requests will be aborted
15 changes: 0 additions & 15 deletions apps/website/docs/api/factories/create_json_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,6 @@ Config fields:
- `params`: params which were passed to the [_Query_](/api/primitives/query)
- `headers`: <Badge type="tip" text="since v0.13" /> raw response headers

- `concurrency?`: concurrency settings for the [_Query_](/api/primitives/query)
::: danger Deprecation warning

This field is deprecated since [v0.12](/releases/0-12) and will be removed in v0.14. Use [`concurrency` operator](/api/operators/concurrency) instead.

Please read [this ADR](/adr/concurrency) for more information and migration guide.

:::

- `strategy?`: available values:
- `TAKE_EVERY` execute every request
- `TAKE_FIRST` skip all requests if there is a pending one
- `TAKE_LATEST` (**default value**) cancel all pending requests and execute the latest one
- `abort?`: [_Event_](https://effector.dev/en/api/effector/event/) after calling which all in-flight requests will be aborted

## Showcases

- [Real-world showcase with SolidJS around JSON API](https://github.com/igorkamyshev/farfetched/tree/master/apps/showcase-solid-real-world-rick-morty/)
Expand Down
110 changes: 2 additions & 108 deletions apps/website/docs/api/operators/attach_operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,9 @@
outline: [2, 3]
---

# `attachOperation` <Badge type="tip" text="since v0.6" />
# `attachOperation`

::: danger

This operator is deprecated since [v0.12](/releases/0-12) and will be removed in v0.14. Please read [this ADR](/adr/attach_operation_deprecation) for more information and migration guide.
This operator is removed in [v0.14](/releases/0-14). Please read [this ADR](/adr/attach_operation_deprecation) for more information and migration guide.
:::

Creates new [_Query_](/api/primitives/query) or [_Mutation_](/api/primitives/mutation) on top of the existing one.

::: tip
It is analog of [attach](https://effector.dev/en/api/effector/attach/) from Effector for [_Queries_](/api/primitives/query) or [_Mutations_](/api/primitives/mutation).
:::

## Formulae

### `attachOperation(query)`

Creates new [_Query_](/api/primitives/query) on top of the existing one.

```ts
import { attachOperation, createQuery } from '@farfetched/core';

const originalQuery = createQuery({ handler: async () => 'some data' });
const attachedQuery = attachOperation(originalQuery);
```

### `attachOperation(query, { mapParams })`

Creates new [_Query_](/api/primitives/query) on top of the existing one, transforming its parameters through `mapParams` function.

```ts
import { attachOperation, createQuery } from '@farfetched/core';

const originalQuery = createQuery({
handler: async (params: string) => 'some data',
});

const attachedQuery = attachOperation(originalQuery, {
mapParams: (params: number) => params.toString(),
});
```

### `attachOperation(query, { source, mapParams })`

Creates new [_Query_](/api/primitives/query) on top of the existing one, transforming its parameters through `mapParams` function with accept a value from `source` [_Store_](https://effector.dev/en/api/effector/store/) as a second argument.

```ts
import { createStore } from 'effector';
import { attachOperation, createQuery } from '@farfetched/core';

const $externalStore = createStore(12);

const originalQuery = createQuery({
handler: async (params: string) => 'some data',
});

const attachedQuery = attachOperation(originalQuery, {
source: $externalStore,
mapParams: (params: number, externalSource) => (params + externalSource).toString(),
});
```

### `attachOperation(mutation)`

Creates new [_Mutation_](/api/primitives/mutation) on top of the existing one.

```ts
import { attachOperation, createMutation } from '@farfetched/core';

const originalMutation = createMutation({ handler: async () => 'some data' });
const attachedMutation = attachOperation(originalMutation);
```

### `attachOperation(mutation, { mapParams })`

Creates new [_Mutation_](/api/primitives/mutation) on top of the existing one, transforming its parameters through `mapParams` function.

```ts
import { attachOperation, createMutation } from '@farfetched/core';

const originaMutation = createMutation({
handler: async (params: string) => 'some data',
});

const attachedMutation = attachOperation(originaMutation, {
mapParams: (params: number) => params.toString(),
});
```

### `attachOperation(mutation, { source, mapParams })`

Creates new [_Mutation_](/api/primitives/mutation) on top of the existing one, transforming its parameters through `mapParams` function with accept a value from `source` [_Store_](https://effector.dev/en/api/effector/store/) as a second argument.

```ts
import { createStore } from 'effector';
import { attachOperation, createMutation } from '@farfetched/core';

const $externalStore = createStore(12);

const originalMutation = createMutation({
handler: async (params: string) => 'some data',
});

const attachedMutation = attachOperation(originalMutation, {
source: $externalStore,
mapParams: (params: number, externalSource) => (params + externalSource).toString(),
});
```

## Showcases

- [Real-world showcase with SolidJS around JSON API](https://github.com/igorkamyshev/farfetched/tree/master/apps/showcase-solid-real-world-rick-morty/)
15 changes: 15 additions & 0 deletions apps/website/docs/releases/0-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# v0.14

Mostly about improving and cleaning the APIs of Farfetched. We are preparing for the big release v1.0, so [as promised](/roadmap), all 0.X releases will be about improving the existing features and cleaning the APIs.

## Migration guide

### `attachOperation` operator

This operator is deprecated since [v0.12](/releases/0-12) and removed in v0.14. Please read [this ADR](/adr/attach_operation_deprecation) for more information and migration guide.

### `concurrency` operator

Field `concurrency` in `createJsonQuery` and `createJsonMutation` is deprecated since [v0.12](/releases/0-12) and removed in v0.14. It has to be replaced by the [`concurrency` operator](/api/operators/concurrency). Please read [this ADR](/adr/concurrency) for more information and migration guide.

<!--@include: ./0-14.changelog.md-->
1 change: 0 additions & 1 deletion apps/website/docs/tutorial/built_in_query_factories.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Built-in factories consider any response as `unknown` by default, so you have to
`createJsonQuery` does some additional job to make your life easier. It does the following:

- Add `Content-Type: application/json` header to the request
- Apply `TAKE_LATEST` strategy and cancel all previous requests, you can override this behavior by passing `concurrency.strategy` option to the factory
- Parse the response as JSON

## Custom factories
Expand Down
16 changes: 16 additions & 0 deletions apps/website/docs/tutorial/devtools.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ if (process.env.NODE_ENV === 'development') {

That is it, now you can open Farfetched Dev Tools in your browser and see all your [_Queries_](/api/primitives/query) and its states.

## Log all errors

You can enable logging of all failed [_Queries_](/api/primitives/query) to console by passing `logErrorsToConsole` field to `attachFarfetchedDevTools` function.

```ts
// main.ts

if (process.env.NODE_ENV === 'development') {
const { attachFarfetchedDevTools } = await import('@farfetched/dev-tools');

attachFarfetchedDevTools({
logErrorsToConsole: true, // [!code focus]
});
}
```

## Roadmap

::: tip
Expand Down
102 changes: 0 additions & 102 deletions apps/website/docs/tutorial/operation_copying.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,105 +4,3 @@

This topic is considered obsolete since [v0.12](/releases/0-12) and will be removed in v0.14. Please read [this ADR](/adr/attach_operation_deprecation) for more information and migration guide.
:::

> It is advanced topic, so you can write an application without it. But it is useful when you have a lot of similar _Queries_ and _Mutations_ and want to simplify your code.

:::tip You will learn:

- When you need to copy _Queries_ and _Mutations_
- How to copy _Queries_ and _Mutations_
- How to simplify your code with _Queries_ and _Mutations_ copying

:::

## Use-case for copying _Queries_ and _Mutations_

Let's revise the example from the [previous chapters](/tutorial/dependent_queries). We have two [_Queries_](/api/primitives/query): `characterQuery` and `originQuery`. Let's imagine, we want to add a new _Query_ `currentLocationQuery` that will be similar to `originQuery`, but will fetch the current location of the character.

```ts{9-15}
const characterQuery = createQuery(/* ... */);

const originQuery = createQuery({
handler: async ({ originUrl }) => {
const response = await fetch(originUrl);
return response.json();
},
});

const currentLocationQuery = createQuery({
handler: async ({ currentLocationUrl }) => {
const response = await fetch(currentLocationUrl);
return response.json();
},
});
```

As you can see, the only difference between `originQuery` and `currentLocationQuery` is parameters, so it would be nice to have a way to copy the _Query_ and change only the parameters.

## Extract base _Query_

To copy the [_Query_](/api/primitives/query), we need to extract the base [_Query_](/api/primitives/query) that will be used as a template for the new ones:

```ts
const locationQuery = createQuery({
handler: async ({ locationUrl }) => {
const response = await fetch(locationUrl);
return response.json();
},
});
```

Now, we can copy the `locationQuery` and change only the parameters:

```ts{3-7,9-13}
import { attachOperation } from '@farfetched/core'

const originQuery = attachOperation(locationQuery, {
mapParams: ({ originUrl }) => ({
locationUrl: originUrl
}),
});

const currentLocationQuery = attachOperation(locationQuery, {
mapParams: ({ currentLocationUrl }) => ({
locationUrl: currentLocationUrl
}),
});
```

So, `originQuery` and `currentLocationQuery` are copies of `locationQuery`, they have separate states and can be used independently.

## Additional parameters from external source

If you want to use additional parameters from external source, you can use the `source` field of `attachOperation` config:

```ts{7}
import { createStore } from 'effector';
import { attachOperation } from '@farfetched/core';

const $someExtarnalSource = createStore({});

const currentLocationQuery = attachOperation(locationQuery, {
source: $someExternalSource,
mapParams: ({ currentLocationUrl }, valueOfExternalSource) => ({
locationUrl: currentLocationUrl,
}),
});
```

In this case, the `valueOfExternalSource` will be equal to the current value of the `$someExternalSource` [_Store_](https://effector.dev/en/api/effector/store/).

## Using `attachOperation` with _Mutations_

The `attachOperation` operator can be used with [_Mutations_](/api/primitives/mutation) as well:

```ts
import { attachOperation } from '@farfetched/core';

const baseMutation = createMutation(/* ... */);
const newMutation = attachOperation(baseMutation);
```

## API reference

You can find the full API reference for the `attachOperation` operator in the [API reference](/api/operators/attach_operation).
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"size-limit": [
{
"path": "./dist/core.js",
"limit": "16 kB"
"limit": "15.5 kB"
}
]
}
Loading