Skip to content

Commit

Permalink
docs: updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 14, 2024
1 parent 6d8e1b9 commit 0d4810c
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 181 deletions.
49 changes: 49 additions & 0 deletions docs/guide/fields-api-reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# Fields

## `parseQueryFields`

**Type**
```ts
declare function parseQueryFields<T>(
input: unknown,
options?: FieldsParseOptions<T>
): FieldsParseOutput
```

**Example**

```typescript
import {
parseQueryFields,
} from 'rapiq';
const output = parseQueryFields(
['+name'],
{
allowed: ['id', 'name'],
defaultAlias: 'user'
}
);
console.log(output);
// [{key: 'id', value: FieldOperator.INCLUDE}] ||
// [{key: 'id', value: '+'}]
```

**Type parameters**

| Name | Description |
|:------|:------------|


**Parameters**

| Name | Type | Description |
|:----------|:------------------------|:-------------------------------------------------------------|
| `input` | `unknown` | Query input data passed e.g. via URL . |
| `options` | `FieldsParseOptions<T>` | Options for parsing fields data [more](#fieldsparseoptions). |

**Returns**

[FieldsParseOutput](#fieldsparseoutput)

The function returns an object.

## `FieldsBuildInput`
The following types are defined, to illustrate which kind of input data is covered by the
`FieldsBuildInput<T>` type.
Expand Down
48 changes: 48 additions & 0 deletions docs/guide/filters-api-reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,53 @@
# Filters

## `parseQueryFilters`

**Type**
```ts
declare function parseQueryFilters<T>(
input: unknown,
options?: FiltersParseOptions<T>
): FiltersParseOutput
```

**Example**

```typescript
import {
parseQueryFilters
} from 'rapiq';
const output = parseQueryFilters(
{id: 1},
{
allowed: ['id', 'name'],
defaultAlias: 'user'
}
);
console.log(output);
// [{alias: 'user', key: 'id', value: 1, }]
```

**Type parameters**

| Name | Description |
|:------|:------------|


**Parameters**

| Name | Type | Description |
|:----------|:-------------------------|:---------------------------------------------------------------|
| `input` | `unknown` | Query input data passed e.g. via URL . |
| `options` | `FiltersParseOptions<T>` | Options for parsing filters data [more](#filtersparseoptions). |

**Returns**

[FiltersParseOutput](#filtersparseoutput)

The function returns an object.

## `FiltersBuildInput`

The following types are defined, to illustrate which kind of input data is covered by the
Expand Down
47 changes: 47 additions & 0 deletions docs/guide/pagination-api-reference.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# Pagination

## `parseQueryPagination`

**Type**
```ts
declare function parseQueryPagination(
input: unknown,
options?: PaginationParseOptions
): PaginationParseOutput
```

**Example**

```typescript
import {
parseQueryPagination
} from 'rapiq';
const output = parseQueryPagination(
{limit: 100},
{
maxLimit: 50
}
);
console.log(output);
// {limit: 50}
```

**Type parameters**

| Name | Description |
|:------|:------------|


**Parameters**

| Name | Type | Description |
|:----------|:----------------------------|:---------------------------------------------------------------------|
| `input` | `unknown` | Query input data passed e.g. via URL . |
| `options` | `PaginationParseOptions<T>` | Options for parsing pagination data [more](#paginationparseoptions). |

**Returns**

[PaginationParseOutput](#paginationparseoutput)

The function returns an object.

## `PaginationBuildInput`

```typescript
Expand Down
193 changes: 17 additions & 176 deletions docs/guide/parse-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,165 +59,26 @@ The function returns an object.
- [ParseOutput](#parseoutput)
- [ParseOptions](#parseoptions)

## `parseQueryParameter`

Parse a query string to an efficient data structure ⚡. The output will
be an object with each possible value of the [Parameter](parameter-api-reference#parameter) enum as property key and the
parsed data as value.

**Type**
```ts
declare function parseQueryParameter(
key: T,
input: unknown,
options?: ParseParameterOptions<T>
): ParseParameterOutput<T>
```

**Example: Fields**

```typescript
import {
parseQueryParameter,
} from 'rapiq';
const output = parseQueryParameter(
// 'fields' ||
// Parameter.FIELDS | URLParameter.FIELDS
'fields',
['+name'],
{
allowed: ['id', 'name'],
defaultAlias: 'user'
}
);
console.log(output);
// [{key: 'id', value: FieldOperator.INCLUDE}] ||
// [{key: 'id', value: '+'}]
```

**Example: Filters**

```typescript
import {
parseQueryParameter
} from 'rapiq';
const output = parseQueryParameter(
// 'filters' | 'filter' |
// Parameter.FILTERS | URLParameter.FILTERS
'filters',
{id: 1},
{
allowed: ['id', 'name'],
defaultAlias: 'user'
}
);
console.log(output);
// [{alias: 'user', key: 'id', value: 1, }]
```

**Example: Pagination**

```typescript
import {
parseQueryParameter
} from 'rapiq';
const output = parseQueryParameter(
// 'pagination' | 'page' |
// Parameter.PAGINATION | URLParameter.PAGINATION
'pagination',
{limit: 100},
{
maxLimit: 50
}
);
console.log(output);
// {limit: 50}
```

**Example: Relations**

```typescript
import {
parseQueryParameter
} from 'rapiq';
const output = parseQueryParameter(
// 'relations' || 'include' ||
// Parameter.RELATIONS | URLParameter.RELATIONS
'relations',
['roles'],
{
allowed: ['roles', 'photos'],
defaultAlias: 'user'
}
);
console.log(output);
// [{key: 'user.roles', value: 'roles'}]
```

**Example: Sort**

```typescript
import {
parseQueryParameter
} from 'rapiq';
const output = parseQueryParameter(
// 'sort' ||
// Parameter.SORT || URLParameter.SORT
'sort',
['-name'],
{
allowed: ['id', 'name'],
defaultAlias: 'user'
}
);
console.log(output);
// [{alias: 'user', key: 'name', value: 'DESC'}]
```

**Type parameters**

| Name | Description |
|:------|:------------|


**Parameters**

| Name | Type | Description |
|:----------|:-----------------------------------|:-----------------------------------------------------------------------|
| `input` | `unknown` | Query input data passed e.g. via URL [more](#parseinput). |
| `options` | `ParseParameterOptions<Parameter>` | Options for parsing fields, filter, include, ... [more](#parseoptions) |

**Returns**

[ParseOutput](#parseoutput)

The function returns an object.

## ParseOptions

```typescript
type ParseOptions = {
/**
* On default all query keys are enabled.
*/
[K in Parameter]?: ParseParameterOptions<K> | boolean
} & {
[Parameter.FIELDS]?: FieldsParseOptions<T> | boolean,
[Parameter.FILTERS]?: FiltersParseOptions<T> | boolean,
[Parameter.RELATIONS]?: RelationsParseOptions<T> | boolean,
[Parameter.PAGINATION]?: PaginationParseOptions | boolean,
[Parameter.SORT]?: SortParseOptions<T> | boolean,
defaultPath?: string,
throwOnFailure?: boolean
}
```
**References**
- [ParseParameterOptions](#parseparameteroptions)
- [Parameter](parameter-api-reference#parameter)
- [FieldsParseOptions](fields-api-reference.md#fieldsparseoptions),
- [FiltersParseOptions](filters-api-reference.md#filtersparseoptions)
- [PaginationParseOptions](pagination-api-reference.md#paginationparseoptions)
- [RelationsParseOptions](relations-api-reference.md#relationsparseoptions)
- [SortParseOptions](sort-api-reference.md#sortparseoptions)
## ParseInput
Expand All @@ -234,35 +95,15 @@ type ParseInput = {
```typescript
type ParseOutput = {
[K in Parameter]?: ParseParameterOutput<K>
[Parameter.FIELDS]?: FieldsParseOutput,
[Parameter.FILTERS]?: FiltersParseOutput,
[Parameter.RELATIONS]?: RelationsParseOutput,
[Parameter.PAGINATION]?: PaginationParseOutput,
[Parameter.SORT]?: SortParseOutput,
}
```
**References**
- [ParseParameterOutput](#parseparameteroutput)

## ParseParameterOptions
```typescript
type ParseParameterOptions<
P extends ParameterType | URLParameterType,
T extends Record<string, any> = Record<string, any>
>;
```
is a generic type and returns the available options for a given parameter type:
**References**
- [FieldsParseOptions](fields-api-reference.md#fieldsparseoptions),
- [FiltersParseOptions](filters-api-reference.md#filtersparseoptions)
- [PaginationParseOptions](pagination-api-reference.md#paginationparseoptions)
- [RelationsParseOptions](relations-api-reference.md#relationsparseoptions)
- [SortParseOptions](sort-api-reference.md#sortparseoptions)

## ParseParameterOutput
```typescript
type ParseParameterOutput<P extends ParameterType | URLParameterType>;
```

is a generic type and returns the parsed output data for a given parameter type:

**References**
- [Parameter](parameter-api-reference#parameter)
- [FieldsParseOutput](fields-api-reference.md#fieldsparseoutput)
- [FiltersParseOutput](filters-api-reference.md#filtersparseoutput)
- [PaginationParseOutput](pagination-api-reference.md#paginationparseoutput)
Expand Down
Loading

0 comments on commit 0d4810c

Please sign in to comment.