Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.0.0-alpha.7 #17

Merged
merged 31 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5393ef7
ci: fix skip config
JoaoPedroAS51 Nov 25, 2020
2271799
chore: update readme.md
JoaoPedroAS51 Nov 26, 2020
18b9c23
chore: setup gitpod
JoaoPedroAS51 Nov 26, 2020
2c7f901
chore: fix lint of readme.md
JoaoPedroAS51 Nov 26, 2020
248a4a0
chore: organize package.json
JoaoPedroAS51 Nov 26, 2020
10d0c16
docs: installation, configuration and basic usage (#9)
JoaoPedroAS51 Nov 26, 2020
a87a520
ci: fix docs workflow
JoaoPedroAS51 Nov 26, 2020
6f5cc4e
docs: add readme to `static` dir
JoaoPedroAS51 Nov 26, 2020
246c315
docs: remove undefined references
JoaoPedroAS51 Nov 26, 2020
114e210
ci: set docs `cname` to `collection.eloqjs.com`
JoaoPedroAS51 Nov 26, 2020
f2747f9
docs: add `nuxt module not released` alert
JoaoPedroAS51 Nov 26, 2020
988b383
chore: update readme.md
JoaoPedroAS51 Nov 26, 2020
d666d5c
docs: fix example of `context` in nuxt usage
JoaoPedroAS51 Nov 27, 2020
bc0d670
chore: remove header of release notes
JoaoPedroAS51 Nov 27, 2020
dab3350
ci: remove docs workflow
JoaoPedroAS51 Nov 28, 2020
0e7c8d3
chore: update readme.md
JoaoPedroAS51 Dec 1, 2020
7e5b370
chore: update keywords
JoaoPedroAS51 Dec 1, 2020
2041c09
revert: docs: add `nuxt module not released` alert
JoaoPedroAS51 Dec 1, 2020
0bc1af9
feat: add `LIKE` operations to `where` method
JoaoPedroAS51 Dec 3, 2020
9bc5e1f
refactor: some refactors to `LIKE` operations
JoaoPedroAS51 Dec 3, 2020
5624c04
feat: deprecate `findIndexBy` in favor of `search`
JoaoPedroAS51 Dec 3, 2020
d095b7a
chore(tsconfig): disable "suppressImplicitAnyIndexErrors"
JoaoPedroAS51 Dec 5, 2020
62e4e41
fix: implicit any index errors
JoaoPedroAS51 Dec 5, 2020
67c171a
test: expect `mapInto` to return an instance of Collection
JoaoPedroAS51 Dec 5, 2020
3dc1391
fix: accept instances of classes
JoaoPedroAS51 Dec 7, 2020
b951300
feat(types): add type `ValueOf`
JoaoPedroAS51 Dec 7, 2020
b7dc5fb
feat: improve return type of `pluck`
JoaoPedroAS51 Dec 7, 2020
608ae35
feat(types): add type `Obj`
JoaoPedroAS51 Dec 7, 2020
0a6c7b2
fix: groups of `groupBy` should be instance of Collection
JoaoPedroAS51 Dec 7, 2020
07219f6
refactor: use type `Obj` instead of `Record`
JoaoPedroAS51 Dec 9, 2020
0207153
fix(helpers): fix pluck `buildKeyPathMap` to always return obj type
JoaoPedroAS51 Jan 7, 2021
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
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