@opra/sqb 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/cjs/augmentation/document-factory.augmentation.js +2 -0
  2. package/cjs/sqb-adapter.js +102 -199
  3. package/cjs/sqb-collection-resource.js +20 -20
  4. package/cjs/sqb-entity-service.js +86 -54
  5. package/cjs/sqb-singleton-resource.js +10 -10
  6. package/cjs/{convert-filter.js → transform-filter.js} +8 -12
  7. package/cjs/transform-key-values.js +14 -0
  8. package/esm/augmentation/document-factory.augmentation.js +32 -28
  9. package/esm/augmentation/mapped-type.augmentation.js +9 -7
  10. package/esm/augmentation/union-type.augmentation.js +7 -5
  11. package/esm/index.js +10 -7
  12. package/esm/sqb-adapter.js +110 -203
  13. package/esm/sqb-collection-resource.js +56 -52
  14. package/esm/sqb-entity-service.js +92 -56
  15. package/esm/sqb-singleton-resource.js +34 -30
  16. package/esm/transform-filter.js +68 -0
  17. package/esm/transform-key-values.js +14 -0
  18. package/package.json +8 -7
  19. package/types/sqb-adapter.d.ts +14 -0
  20. package/{esm → types}/sqb-collection-resource.d.ts +1 -1
  21. package/types/sqb-entity-service.d.ts +31 -0
  22. package/types/transform-filter.d.ts +2 -0
  23. package/types/transform-key-values.d.ts +3 -0
  24. package/esm/convert-filter.d.ts +0 -2
  25. package/esm/convert-filter.js +0 -67
  26. package/esm/sqb-adapter.d.ts +0 -64
  27. package/esm/sqb-entity-service.d.ts +0 -21
  28. /package/{esm → types}/augmentation/document-factory.augmentation.d.ts +0 -0
  29. /package/{esm → types}/augmentation/mapped-type.augmentation.d.ts +0 -0
  30. /package/{esm → types}/augmentation/union-type.augmentation.d.ts +0 -0
  31. /package/{esm → types}/index.d.ts +0 -0
  32. /package/{esm → types}/sqb-singleton-resource.d.ts +0 -0
@@ -1,67 +0,0 @@
1
- import { ArrayExpression, BooleanLiteral, ComparisonExpression, DateLiteral, LogicalExpression, NullLiteral, NumberLiteral, ParenthesesExpression, parseFilter, QualifiedIdentifier, StringLiteral, TimeLiteral } from '@opra/common';
2
- import * as sqb from '@sqb/builder';
3
- export function convertFilter(str) {
4
- const ast = typeof str === 'string' ? parseFilter(str) : str;
5
- if (!ast)
6
- return;
7
- if (ast instanceof ComparisonExpression) {
8
- const left = ast.left instanceof QualifiedIdentifier
9
- ? sqb.Field(ast.left.value)
10
- : convertFilter(ast.left);
11
- const right = convertFilter(ast.right);
12
- switch (ast.op) {
13
- case '=':
14
- return sqb.Eq(left, right);
15
- case '!=':
16
- return sqb.Ne(left, right);
17
- case '>':
18
- return sqb.Gt(left, right);
19
- case '>=':
20
- return sqb.Gte(left, right);
21
- case '<':
22
- return sqb.Lt(left, right);
23
- case '<=':
24
- return sqb.Lte(left, right);
25
- case 'in':
26
- return sqb.In(left, right);
27
- case '!in':
28
- return sqb.Nin(left, right);
29
- case 'like':
30
- return sqb.Like(left, right);
31
- case 'ilike':
32
- return sqb.Ilike(left, right);
33
- case '!like':
34
- return sqb.NotLike(left, right);
35
- case '!ilike':
36
- return sqb.NotILike(left, right);
37
- default:
38
- throw new Error(`ComparisonExpression operator (${ast.op}) not implemented yet`);
39
- }
40
- }
41
- if (ast instanceof QualifiedIdentifier) {
42
- return ast.value;
43
- }
44
- if (ast instanceof NumberLiteral ||
45
- ast instanceof StringLiteral ||
46
- ast instanceof BooleanLiteral ||
47
- ast instanceof NullLiteral ||
48
- ast instanceof DateLiteral ||
49
- ast instanceof TimeLiteral) {
50
- return ast.value;
51
- }
52
- if (ast instanceof ArrayExpression) {
53
- return ast.items.map(convertFilter);
54
- }
55
- if (ast instanceof LogicalExpression) {
56
- if (ast.op === 'or')
57
- return sqb.Or(...ast.items.map(convertFilter));
58
- return sqb.And(...ast.items.map(convertFilter));
59
- }
60
- if (ast instanceof ArrayExpression) {
61
- return ast.items.map(convertFilter);
62
- }
63
- if (ast instanceof ParenthesesExpression) {
64
- return convertFilter(ast.expression);
65
- }
66
- throw new Error(`${ast.type} is not implemented yet`);
67
- }
@@ -1,64 +0,0 @@
1
- import { Request } from '@opra/core';
2
- import { convertFilter } from './convert-filter.js';
3
- export declare namespace SQBAdapter {
4
- const parseFilter: typeof convertFilter;
5
- type parseFilter = typeof convertFilter;
6
- function parseCollectionCreateRequest(request: Request): {
7
- method: string;
8
- data: any;
9
- options: any;
10
- };
11
- function parseCollectionDeleteRequest(request: Request): {
12
- method: string;
13
- key: any;
14
- options: {};
15
- };
16
- function parseCollectionDeleteManyRequest(request: Request): {
17
- method: string;
18
- options: any;
19
- };
20
- function parseCollectionGetRequest(request: Request): {
21
- method: string;
22
- key: any;
23
- options: any;
24
- };
25
- function parseCollectionUpdateRequest(request: Request): {
26
- method: string;
27
- key: any;
28
- data: any;
29
- options: any;
30
- };
31
- function parseCollectionUpdateManyRequest(request: Request): {
32
- method: string;
33
- data: any;
34
- options: any;
35
- };
36
- function parseCollectionSearchRequest(request: Request): {
37
- method: string;
38
- options: any;
39
- };
40
- function parseSingletonGetRequest(request: Request): {
41
- method: string;
42
- options: any;
43
- };
44
- function parseSingletonCreateRequest(request: Request): {
45
- method: string;
46
- data: any;
47
- options: any;
48
- };
49
- function parseSingletonDeleteRequest(request: Request): {
50
- method: string;
51
- options: {};
52
- };
53
- function parseSingletonUpdateRequest(request: Request): {
54
- method: string;
55
- data: any;
56
- options: any;
57
- };
58
- function parseRequest(request: Request): {
59
- method: string;
60
- key?: any;
61
- data?: any;
62
- options: any;
63
- };
64
- }
@@ -1,21 +0,0 @@
1
- import { Maybe, Type } from 'ts-gems';
2
- import { PartialInput, PartialOutput, RequestContext } from '@opra/core';
3
- import { EntityInput, EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
- export declare abstract class SqbEntityService<T, TOutput = PartialOutput<T>> {
5
- readonly resourceType: Type<T>;
6
- protected _entityMetadata: EntityMetadata;
7
- protected constructor(resourceType: Type<T>);
8
- create(context: RequestContext, data: PartialInput<T>, options?: Repository.CreateOptions): Promise<TOutput>;
9
- count(context: RequestContext, options?: Repository.CountOptions): Promise<number>;
10
- destroy(context: RequestContext, keyValue: any, options?: Repository.DestroyOptions): Promise<boolean>;
11
- destroyAll(context: RequestContext, options?: Repository.DestroyOptions): Promise<number>;
12
- findByPk(context: RequestContext, keyValue: any, options?: Repository.GetOptions): Promise<Maybe<TOutput>>;
13
- findOne(context: RequestContext, options?: Repository.FindOneOptions): Promise<Maybe<TOutput>>;
14
- findAll(context: RequestContext, options?: Repository.FindAllOptions): Promise<TOutput[]>;
15
- update(context: RequestContext, keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<Maybe<TOutput>>;
16
- updateAll(context: RequestContext, data: PartialInput<T>, options?: Repository.UpdateAllOptions): Promise<number>;
17
- protected _onError(context: RequestContext, error: unknown): Promise<void>;
18
- protected abstract getConnection(context: RequestContext): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
19
- protected onError?(context: RequestContext, error: unknown): void | Promise<void>;
20
- protected onTransformRow?(context: RequestContext, row: TOutput, method: string): TOutput;
21
- }
File without changes
File without changes