4.0.7 • Published 2 months ago

@travetto/rest-model-query v4.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

RESTful Model Query Routes

RESTful support for generating query APIs from Model classes.

Install: @travetto/rest-model-query

npm install @travetto/rest-model-query

# or

yarn add @travetto/rest-model-query

Data Model Querying support can also be added support in the form of ModelQueryRoutes. This provides listing by query as well as an endpoint to facilitate suggestion behaviors.

Code: ModelQueryRoutes example

import { Inject } from '@travetto/di';
import { ModelQuerySupport } from '@travetto/model-query';
import { Controller } from '@travetto/rest';
import { ModelQueryRoutes } from '@travetto/rest-model-query';

import { User } from './user';

@Controller('/user')
@ModelQueryRoutes(User)
class UserQueryController {
  @Inject()
  source: ModelQuerySupport;
}

is a shorthand that is equal to:

Code: Comparable UserController, built manually

import { Inject } from '@travetto/di';
import { ModelQuerySupport, SortClause, ValidStringFields } from '@travetto/model-query';
import { isQuerySuggestSupported } from '@travetto/model-query/src/internal/service/common';
import { Controller, Get } from '@travetto/rest';
import { RestModelQuery, RestModelSuggestQuery } from '@travetto/rest-model-query';

import { User } from './user';

const convert = <T>(k?: string) => k && typeof k === 'string' && /^[\{\[]/.test(k) ? JSON.parse(k) as T : k;

@Controller('/user')
class UserQueryController {

  @Inject()
  service: ModelQuerySupport;

  @Get('')
  async getAllUser(query: RestModelQuery) {
    return this.service.query(User, {
      limit: query.limit,
      offset: query.offset,
      sort: convert(query.sort) as SortClause<User>[],
      where: convert(query.where)
    });
  }

  @Get('/suggest/:field')
  async suggest(field: ValidStringFields<User>, suggest: RestModelSuggestQuery) {
    if (isQuerySuggestSupported(this.service)) {
      return this.service.suggest(User, field, suggest.q, suggest);
    }
  }
}
4.0.7

2 months ago

4.0.6

2 months ago

4.0.5

2 months ago

4.0.4

2 months ago

4.0.3

2 months ago

4.0.1

3 months ago

4.0.0

3 months ago

4.0.2

3 months ago

4.0.0-rc.10

3 months ago

4.0.0-rc.9

3 months ago

4.0.0-rc.8

3 months ago

3.4.6

3 months ago

4.0.0-rc.7

3 months ago

4.0.0-rc.6

3 months ago

4.0.0-rc.5

3 months ago

4.0.0-rc.3

3 months ago

4.0.0-rc.4

3 months ago

4.0.0-rc.1

3 months ago

4.0.0-rc.2

3 months ago

4.0.0-rc.0

4 months ago

3.4.4

6 months ago

3.4.5

6 months ago

3.3.8

7 months ago

3.3.7

8 months ago

3.3.6

8 months ago

3.2.2

10 months ago

3.2.1

10 months ago

3.2.5

10 months ago

3.2.4

10 months ago

3.2.3

10 months ago

3.4.0

6 months ago

3.4.3

6 months ago

3.4.2

6 months ago

3.4.1

6 months ago

3.4.0-rc.9

6 months ago

3.4.0-rc.7

6 months ago

3.4.0-rc.8

6 months ago

3.4.0-rc.5

6 months ago

3.4.0-rc.6

6 months ago

3.4.0-rc.3

6 months ago

3.4.0-rc.4

6 months ago

3.4.0-rc.1

7 months ago

3.4.0-rc.2

6 months ago

3.4.0-rc.0

7 months ago

3.3.1

9 months ago

3.3.0

9 months ago

3.3.5

8 months ago

3.3.4

8 months ago

3.3.3

8 months ago

3.3.2

9 months ago

3.2.0

11 months ago

3.1.18

11 months ago

3.2.0-rc.0

11 months ago

3.1.12

12 months ago

3.1.11

12 months ago

3.1.14

12 months ago

3.1.13

12 months ago

3.1.16

11 months ago

3.1.15

11 months ago

3.1.17

11 months ago

3.1.10

12 months ago

3.1.9

1 year ago

3.1.8

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.0.3

1 year ago

3.1.0-rc.10

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.1.0-rc.2

1 year ago

3.1.0-rc.3

1 year ago

3.1.0-rc.0

1 year ago

3.1.0-rc.1

1 year ago

3.1.0-rc.6

1 year ago

3.1.0-rc.7

1 year ago

3.1.0-rc.4

1 year ago

3.1.0-rc.5

1 year ago

3.1.0-rc.8

1 year ago

3.1.0-rc.9

1 year ago

3.0.0-rc.28

1 year ago

3.0.0-rc.27

1 year ago

3.0.1-rc.1

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

3.0.2-rc.1

1 year ago

3.0.2-rc.0

1 year ago

3.0.0-rc.24

1 year ago

3.0.0-rc.23

1 year ago

3.0.0-rc.26

1 year ago

3.0.0-rc.25

1 year ago

3.0.0-rc.20

1 year ago

3.0.0-rc.22

1 year ago

3.0.0-rc.21

1 year ago

3.0.0-rc.15

1 year ago

3.0.0-rc.17

1 year ago

3.0.0-rc.16

1 year ago

3.0.0-rc.19

1 year ago

3.0.0-rc.18

1 year ago

3.0.0-rc.13

1 year ago

3.0.0-rc.12

1 year ago

3.0.0-rc.14

1 year ago

3.0.0-rc.6

1 year ago

3.0.0-rc.11

1 year ago

3.0.0-rc.10

1 year ago

3.0.0-rc.9

1 year ago

3.0.0-rc.8

1 year ago

3.0.0-rc.7

1 year ago

3.0.0-rc.4

2 years ago

3.0.0-rc.3

2 years ago

3.0.0-rc.2

2 years ago

3.0.0-rc.1

2 years ago

3.0.0-rc.0

2 years ago