59 Commits

Author SHA1 Message Date
daffl
3189c26dba chore: Update changelog 2022-12-14 11:41:50 -08:00
daffl
42cca600d0 chore(release): publish v5.0.0-pre.34 2022-12-14 11:40:34 -08:00
philipimperato
d9449fa835
fix(schema): Check for undefined value in resolveQueryObjectId resolver (#2914) 2022-12-11 15:44:27 -08:00
David Luecke
9f712bf569
chore(dependencies): Update all dependencies (#2901) 2022-12-06 11:54:13 -08:00
David Luecke
9ddc2e6b02
feat(adapter): Add patch data type to adapters and refactor AdapterBase usage (#2906) 2022-12-05 22:06:41 -08:00
daffl
bffb634dec chore: Update changelog 2022-11-07 20:15:54 -08:00
daffl
89f516bcb1 chore(release): publish v5.0.0-pre.33 2022-11-07 20:14:53 -08:00
David Luecke
6853277e1f
chore: Edit Readme and contribution templates (#2866) 2022-11-07 20:12:03 -08:00
Marshall Thompson
742e5b8256
docs(styles): Fix home footer (#2855) 2022-11-04 22:58:45 -07:00
David Luecke
c5c1fba571
feat(mongodb): Add ObjectId resolvers and MongoDB option in the guide (#2847) 2022-11-04 21:10:58 -07:00
Marshall Thompson
cb70e0778e
feat(mongodb) aggregation pipeline queries (#2840)
* feat(mongodb) aggregation pipeline queries

Makes queries using the MongoDB Aggregation Pipeline, by default, unless either of these conditions is met:

- `params.mongodb` is provided. This object is for the `collection.find` method, and won’t work for `collection.aggregate`.
- `params.query.$limit` is set to `0`. The aggregation pipeline will not accept 0 as a value for the `$limit` stage.

## Updates to `service.find`

The `find` method has been updated so that queries not meeting the two criteria, above, are created using the aggregation pipeline, which is an array of the document objects representing the stages of the request. Here’s an example query:

```ts
app.service(‘todos’).find({
  query: {
    $sort: { name: 1 },
    $skip: 1,
    $limit: 4
  }
})

// the internal aggregation request looks like this
const query = collection.aggregate([
  { $match: {} },
  { $sort: { name: 1 } },
  { $skip: 1 },
  { $limit: 4 },
  …params.pipeline || []
])
```

## New `pipeline` param

Notice that it’s now possible to pass `params.pipeline`.  This means you can set params.pipeline as an array of additional stages in the aggregation pipeline and they will be executed during the same request.  This means that it’s now possible to perform `$lookup` and `$unwind` stages alongside the normal Feathers queries.

## Feathers Query with `params.pipeline`

This example shows how to populate the `user` onto a query for `todos`, assuming that each `todo` contains a `userId` property.

```ts
const result = await app.service('todos').find({
  query: { $sort: { name: 1 } },
  pipeline: [
    {
      $lookup: {
        from: ‘users’,
        localField: 'userId',
        foreignField: '_id',
        as: ‘user’
      }
    },
    { $unwind: { path: '$user’ } }
  ],
  paginate: false
})
```

In the above example, the `query` is added to the pipeline, first (under the hood) then additional stages are added in the `pipeline` option:

- The `$lookup` stage creates an array called `user` which contains any matches in `todo.userId`, so if `userId` were an array of ids, any matches would be in the `users` array.  However, in this example, the `userId` is a single id, so…
- The `$unwind` stage turns the array into a single object.

All stages of the pipeline happen directly on the MongoDB server.

## Custom `.aggregate` requests

It’s still possible to make `.aggregate` requests without the Feathers syntax by directly accessing `service.model`:

```ts
const result = await app.service(‘todos’).model.aggregate([
   // …stages go here
]).toArray()
```

* refactor(mongodb): decouple find logic, getModel

Splits the `find` method into two utilities for converting params into MongoDB requests:

- `asFindQuery`
- `asAggregateQuery`

Each of the above methods returns the raw MongoDB request object, without having called `.toArray`, so it’s likely also possible to directly use MongoDB cursors on the returned object, though I’ve not added a test for such a use case.

This PR also optimizes the `find` method to parallelize the `count` query (for pagination) and the `results` query.  This makes it so we don’t have to wait for the count before we start querying the results.

One more thing: this PR also combines non-DRY code that was found in every method into a single `getModel` method.

* feat(mongodb) control stages with $feathers stage

A custom `$feathers` stage has been added to our wrapper for the MongoDB aggregation pipeline.  It allows you to specify where in the pipeline the Feathers-related stages get injected.  This means you can now specify for some pipeline operations to run BEFORE the ones related to the Feathers query.

The `$feathers` stage is an object optionally containing a `handleStages` function.  The `handleStages` function receives the Feathers stages and allows them to be modified.  It’s a feature that will only be used in complex, modular/layered queries, since it would usually be simpler to just modify the incoming query before passing it to `service.find`.

* refactor(mongodb) rename utils and combine methods

- rename `asFindQuery` to `findRaw`
- rename `asAggregateQuery` to `aggregateRaw`
- combine the `makePipeline` method into the `aggregateRaw` method,

* docs(mongodb) document aggregation queries

* feat(mongodb) remove handleStages from aggregation
2022-11-04 15:58:35 -06:00
David Luecke
8b89c8bab5
chore(dependencies): Update all dependencies (#2841) 2022-11-03 11:49:33 -07:00
daffl
8c6f2efa9d chore: Update changelog 2022-10-25 21:11:31 -07:00
daffl
b405e205fc chore(release): publish v5.0.0-pre.32 2022-10-25 21:10:10 -07:00
daffl
4abe6c52ed chore: Update changelog 2022-10-12 11:40:36 -07:00
daffl
4500dbeb8c chore(release): publish v5.0.0-pre.31 2022-10-12 11:39:39 -07:00
David Luecke
57119b6bb2
feat(cli): Generate full client test suite and improve typed client (#2788) 2022-10-12 11:18:35 -07:00
David Luecke
474a9fda21
feat(cli): Improve generated schema definitions (#2783) 2022-10-08 12:08:54 -07:00
daffl
d886f333ac chore: Update changelog 2022-10-06 17:06:32 -07:00
daffl
b535c91197 chore(release): publish v5.0.0-pre.30 2022-10-06 17:05:35 -07:00
David Luecke
26a4b95f8f
chore(dependencies): Update all dependencies (#2780) 2022-10-06 10:30:32 -07:00
David Luecke
ea31f15d42
chore(build): Move npm package buildpack folder (#2781) 2022-10-06 10:30:21 -07:00
David Luecke
d16601f227
feat(core): Allow to unregister services at runtime (#2756) 2022-09-16 18:12:53 -07:00
daffl
190d609fb9 chore: Update changelog 2022-09-15 17:09:23 -07:00
daffl
4314dc89a4 chore(release): publish v5.0.0-pre.29 2022-09-15 17:08:05 -07:00
David Luecke
6dd1311750
chore(dependencies): Update dependencies (#2747) 2022-09-13 10:45:55 +02:00
David Luecke
0e2a9b3664
chore(dependencies): Update all dependencies (#2738) 2022-08-30 13:21:50 +02:00
daffl
489de505a1 chore: Update changelog 2022-08-03 08:38:05 -07:00
daffl
bf8e54fddc chore(release): publish v5.0.0-pre.28 2022-08-03 08:36:53 -07:00
David Luecke
bd55ffb812
fix(cli): Improve generated application and client (#2701) 2022-08-03 08:35:51 -07:00
David Luecke
c19c063623
chore(dependencies): Update dependencies (#2707)
Co-authored-by: GitHub Actions Bot <hello@feathersjs.com>
2022-08-02 11:34:27 -07:00
David Luecke
fe22615b7f
fix(mongodb): Ensure transactions are used properly in create (#2699) 2022-07-18 21:02:24 -07:00
daffl
f886640ac5 chore: Update changelog 2022-07-12 17:30:09 -07:00
daffl
6032742bce chore(release): publish v5.0.0-pre.27 2022-07-12 17:28:56 -07:00
David Luecke
45f359dd64
chore(dependencies): Update all dependencies (#2683) 2022-07-03 14:08:41 -07:00
daffl
252c872e74 chore: Update changelog 2022-06-22 00:54:47 -07:00
daffl
0e7553ded9 chore(release): publish v5.0.0-pre.26 2022-06-22 00:53:35 -07:00
daffl
2085504f6a chore: Update changelog 2022-06-21 23:43:44 -07:00
daffl
c0ab3b6039 chore(release): publish v5.0.0-pre.25 2022-06-21 23:42:37 -07:00
daffl
5b84925a22 chore: Update changelog 2022-06-20 22:00:24 -07:00
daffl
72779fa293 chore(release): publish v5.0.0-pre.24 2022-06-20 21:59:15 -07:00
David Luecke
9380fff585
feat(knex): Add KnexJS SQL database adapter to core (#2671) 2022-06-20 13:57:06 -07:00
David Luecke
b41279b55e
feat(authentication-local): Add passwordHash property resolver (#2660) 2022-06-07 16:25:01 -07:00
daffl
98f426071d chore: Update changelog 2022-06-06 11:15:26 -07:00
daffl
a60910bd73 chore(release): publish v5.0.0-pre.23 2022-06-06 11:14:34 -07:00
David Luecke
aa972a9f71
chore(dependencies): Update all dependencies (#2651) 2022-06-06 10:52:55 -07:00
David Luecke
532eda03ff
chore: Remove unnecessary dependencies file and adjust Prettier line width (#2650) 2022-05-31 13:47:07 -07:00
David Luecke
c606c56dc2
chore: Format code using Prettier and updated ESLint rules (#2647)
Co-authored-by: Marshall Thompson <marshall@creativeideal.net>
2022-05-27 15:21:13 -07:00
daffl
6a4ed58a90 chore: Update changelog 2022-05-23 22:07:58 -07:00
daffl
e452e02063 chore(release): publish v5.0.0-pre.22 2022-05-23 22:06:27 -07:00