Skip to content

Commit

Permalink
Merge pull request #17 from eloqjs/dev
Browse files Browse the repository at this point in the history
Release v1.0.0-alpha.7
  • Loading branch information
JoaoPedroAS51 authored Jan 7, 2021
2 parents 3661d5b + 0207153 commit c9b2f21
Show file tree
Hide file tree
Showing 30 changed files with 10,490 additions and 207 deletions.
Empty file.
51 changes: 0 additions & 51 deletions .github/workflows/docs.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ jobs:
uses: fkirc/skip-duplicate-actions@master
with:
github_token: ${{ github.token }}
paths_ignore: '["**/*.md", ".codeclimate.json", ".editorconfig", ".gitignore", ".eslintignore", ".prettierignore", "docs/**", ".github/**"]'
paths_ignore: '["**/*.md", ".codeclimate.json", ".gitpod.yml", ".releaserc", ".editorconfig", ".gitignore", ".eslintignore", ".prettierignore", "docs/**", ".github/**"]'
do_not_skip: '["workflow_dispatch", "schedule"]'

test:
name: Test

needs: pre_job

if: needs.pre_job.outputs.should_skip != 'true' || (github.ref != 'refs/heads/dev' && github.head_ref != 'dev')
if: needs.pre_job.outputs.should_skip != 'true' || (github.ref != 'refs/heads/dev' && github.head_ref != 'dev' && github.base_ref != 'dev')

runs-on: ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tasks:
- init: yarn install
12 changes: 12 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"plugins": [
"@semantic-release/commit-analyzer",
["@semantic-release/release-notes-generator", {
"writerOpts": {
"headerPartial": ".github/templates/release-notes-generator/header.hbs"
}
}],
"@semantic-release/npm",
"@semantic-release/github"
]
}
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
[![Code Climate maintainability][code-climate-maintainability-src]][code-climate-maintainability-href]
[![Codecov][codecov-src]][codecov-href]
[![Gitpod ready-to-code][gitpod-src]][gitpod-href]
[![Contributions][contributions-src]][contributions-href]
[![License][license-src]][license-href]

> The collection for your resources. Made specifically to work with arrays of objects from your API Responses.
**Collection** | [Vue Collection](https://github.com/eloqjs/vue-collection) | [Nuxt Collection](https://github.com/eloqjs/nuxt-collection)

- [ Release Notes](https://collection.eloqjs.com/releases)
- [📖  Read the Documentation](https://collection.eloqjs.com)

## Features

- Made specifically to work with arrays of objects
- JSON API specification support
- Extends the Array class
Expand All @@ -25,18 +29,24 @@

[📖  Read the Documentation](https://collection.eloqjs.com)

## Development
## Contributing

You can contribute online with Gitpod:

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)][gitpod-href]

Or locally:

1. Clone this repository
2. Install dependencies using `yarn install`
3. Test using `yarn test`

## Thanks

- 🔥 Inspiration from [Laravel Eloquent Collections](https://laravel.com/docs/eloquent-collections).
## Credits

- 💎 Based on [collect.js](https://github.com/ecrmnn/collect.js) by [Daniel Eckermann](https://github.com/ecrmnn).
Thank you so much for your amazing package!
- 🔥 Inspiration from [Laravel Eloquent Collections](https://laravel.com/docs/eloquent-collections).
- 💎 Based on [collect.js](https://github.com/ecrmnn/collect.js) by [Daniel Eckermann](https://github.com/ecrmnn).
Thank you so much for your amazing package!
- ❤️ Whoever contributes to this project!

## 📑 License

Expand All @@ -61,6 +71,9 @@ Copyright (c) João Pedro Antunes Silva
[codecov-src]: https://img.shields.io/codecov/c/github/eloqjs/collection.svg?logo=codecov&style=flat-square
[codecov-href]: https://codecov.io/gh/eloqjs/collection

[gitpod-src]: https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod&style=flat-square
[gitpod-href]: https://gitpod.io/#https://github.com/eloqjs/collection

[contributions-src]: https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square
[contributions-href]: https://github.com/eloqjs/collection/issues

Expand Down
4 changes: 4 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.nuxt
dist
static/sw.js
196 changes: 196 additions & 0 deletions docs/content/en/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
---
title: Configuration
description: You can configure @eloqjs/collection with the Collection.config property in src/main.js.
category: Getting Started
position: 3
---

<alert type="warning">This documentation still in development.</alert>

<alert type="info">If you are using **Nuxt** or **Vue**, please follow their configuration steps instead of this one.</alert>

You can configure `@eloqjs/collection` with the `Collection.config` property in `src/main.js`.

```js{}[src/main.js]
import { Collection } from '@eloqjs/collection'
Collection.config = {
// My custom configuration
}
```

## Frameworks

### Nuxt

You can configure `@eloqjs/nuxt-collection` with the `collection` property in your `nuxt.config.js`.

```js{}[nuxt.config.js]
export default {
collection: {
// My custom configuration
}
}
```

### Vue

You can configure `@eloqjs/vue-collection` by passing the options to `Vue.use` in `src/main.js`.

```js{}[src/main.js]
import vue from 'vue'
import Collection from '@eloqjs/vue-collection'
Vue.use(Collection, {
// My custom configuration
})
```


## Properties

### `primaryKey`

- Type: `() => string`
- Arguments: `({ collection })`
- Default: `id`

The primary key of the items.

<code-group>
<code-block label="JavaScript" active>

```js
{
primaryKey: ({ collection }) => {
const item = collection.first()

if (item.type === 'article') {
return 'slug'
}

return 'id'
}
}
```

</code-block>
<code-block label="TypeScript">

```ts
import { Collection, ItemData } from '@eloqjs/collection'
{
primaryKey: <T extends ItemData>({
collection
}: {
collection: Collection<T>
}): string => {
const item = collection.first()
if (item.type === 'article') {
return 'slug'
}
return 'id'
}
}
```

</code-block>
</code-group>

### `toQuery`

- Type: `() => Class`
- Arguments: `({ collection, item })`

If our items are Model classes with Query Builder, we can configure this option to
convert the collection into a Query Builder.

> This example is from `vue-api-query` integration.

<code-group>
<code-block label="JavaScript" active>

```js
{
toQuery: ({ collection, item }) => {
return item.newModelQuery().whereIn(
collection.primaryKey(), collection.modelKeys()
)
}
}
```

</code-block>
<code-block label="TypeScript">

```ts
import { Collection, ItemData } from '@eloqjs/collection'
{
toQuery: <T extends ItemData>({
collection,
item
}: {
collection: Collection<T>
item: T
}): T => {
const model = item.newModelQuery().whereIn(
collection.primaryKey(), collection.modelKeys()
)
return (model as unknown) as T
}
}
```


</code-block>
</code-group>

### `fresh`

- Type: `() => Promise`
- Arguments: `({ collection, include })`

If our items are Model classes with Query Builder, we can configure this option to
reload a fresh item instance from the database for all the items.

> This example is from `vue-api-query` integration.

<code-group>
<code-block label="JavaScript" active>

```js
{
fresh: async ({ collection, include }) => {
return await collection.toQuery().include(...include).$get()
}
}
```

</code-block>
<code-block label="TypeScript">

```ts
import { Collection, ItemData } from '@eloqjs/collection'
{
fresh: async <T extends ItemData>({
collection,
include
}: {
collection: Collection<T>,
include: string[]
}): Promise<Collection<T>> => {
const _collection = await collection.toQuery()
.include(...include).$get()
return (_collection as unknown) as Promise<Collection<T>>
}
}
```

</code-block>
</code-group>
22 changes: 22 additions & 0 deletions docs/content/en/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Introduction
description: The collection for your resources. Made specifically to work with arrays of objects from your API Responses.
position: 1
category: Getting Started
features:
- Made specifically to work with arrays of objects
- JSON API specification support
- Extends the Array class
- Names and conventions that makes sense
- Models support, fully compatible with vue-api-query, sarala and coloquent
- Integrable `primaryKey`, `fresh` and `toQuery`
- TypeScript support
---

<alert type="warning">This documentation still in development.</alert>

The collection for your resources. Made specifically to work with arrays of objects from your API Responses.

## Features

<list :items="features"></list>
Loading

0 comments on commit c9b2f21

Please sign in to comment.