@opra/sqb 1.0.0-beta.1 → 1.0.0-beta.3

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.
@@ -8,69 +8,73 @@ var SQBAdapter;
8
8
  (function (SQBAdapter) {
9
9
  SQBAdapter.parseFilter = parse_filter_js_1.default;
10
10
  async function parseRequest(context) {
11
- const { operation } = context;
11
+ if (context.protocol !== 'http') {
12
+ throw new TypeError('SQBAdapter can parse only HttpContext');
13
+ }
14
+ const ctx = context;
15
+ const { operation } = ctx;
12
16
  if (operation?.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
13
- const dataType = context.document.node.getComplexType(operation.compositionOptions?.type);
17
+ const dataType = ctx.document.node.getComplexType(operation.compositionOptions?.type);
14
18
  const entityMetadata = connect_1.EntityMetadata.get(dataType.ctor);
15
19
  if (!entityMetadata)
16
20
  throw new Error(`Type class "${dataType.ctor}" is not an SQB entity`);
17
21
  const controller = operation.owner;
18
22
  switch (operation.composition) {
19
23
  case 'Entity.Create': {
20
- const data = await context.getBody();
24
+ const data = await ctx.getBody();
21
25
  const options = {
22
- projection: context.queryParams.projection,
26
+ projection: ctx.queryParams.projection,
23
27
  };
24
28
  return { method: 'create', data, options };
25
29
  }
26
30
  case 'Entity.Delete': {
27
31
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
28
- const key = keyParam && context.pathParams[String(keyParam.name)];
32
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
29
33
  const options = {
30
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
34
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
31
35
  };
32
36
  return { method: 'delete', key, options };
33
37
  }
34
38
  case 'Entity.DeleteMany': {
35
39
  const options = {
36
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
40
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
37
41
  };
38
42
  return { method: 'deleteMany', options };
39
43
  }
40
44
  case 'Entity.FindMany': {
41
45
  const options = {
42
- count: context.queryParams.count,
43
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
44
- projection: context.queryParams.projection || operation.compositionOptions.defaultProjection,
45
- limit: context.queryParams.limit || operation.compositionOptions.defaultLimit,
46
- offset: context.queryParams.skip,
47
- sort: context.queryParams.sort || operation.compositionOptions.defaultSort,
46
+ count: ctx.queryParams.count,
47
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
48
+ projection: ctx.queryParams.projection || operation.compositionOptions.defaultProjection,
49
+ limit: ctx.queryParams.limit || operation.compositionOptions.defaultLimit,
50
+ offset: ctx.queryParams.skip,
51
+ sort: ctx.queryParams.sort || operation.compositionOptions.defaultSort,
48
52
  };
49
53
  return { method: 'findMany', options };
50
54
  }
51
55
  case 'Entity.Get': {
52
56
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
53
- const key = keyParam && context.pathParams[String(keyParam.name)];
57
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
54
58
  const options = {
55
- projection: context.queryParams.projection,
56
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
59
+ projection: ctx.queryParams.projection,
60
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
57
61
  };
58
62
  return { method: 'get', key, options };
59
63
  }
60
64
  case 'Entity.Update': {
61
- const data = await context.getBody();
65
+ const data = await ctx.getBody();
62
66
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
63
- const key = keyParam && context.pathParams[String(keyParam.name)];
67
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
64
68
  const options = {
65
- projection: context.queryParams.projection,
66
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
69
+ projection: ctx.queryParams.projection,
70
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
67
71
  };
68
72
  return { method: 'update', key, data, options };
69
73
  }
70
74
  case 'Entity.UpdateMany': {
71
- const data = await context.getBody();
75
+ const data = await ctx.getBody();
72
76
  const options = {
73
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
77
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
74
78
  };
75
79
  return { method: 'updateMany', data, options };
76
80
  }
@@ -4,69 +4,73 @@ export var SQBAdapter;
4
4
  (function (SQBAdapter) {
5
5
  SQBAdapter.parseFilter = _parseFilter;
6
6
  async function parseRequest(context) {
7
- const { operation } = context;
7
+ if (context.protocol !== 'http') {
8
+ throw new TypeError('SQBAdapter can parse only HttpContext');
9
+ }
10
+ const ctx = context;
11
+ const { operation } = ctx;
8
12
  if (operation?.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
9
- const dataType = context.document.node.getComplexType(operation.compositionOptions?.type);
13
+ const dataType = ctx.document.node.getComplexType(operation.compositionOptions?.type);
10
14
  const entityMetadata = EntityMetadata.get(dataType.ctor);
11
15
  if (!entityMetadata)
12
16
  throw new Error(`Type class "${dataType.ctor}" is not an SQB entity`);
13
17
  const controller = operation.owner;
14
18
  switch (operation.composition) {
15
19
  case 'Entity.Create': {
16
- const data = await context.getBody();
20
+ const data = await ctx.getBody();
17
21
  const options = {
18
- projection: context.queryParams.projection,
22
+ projection: ctx.queryParams.projection,
19
23
  };
20
24
  return { method: 'create', data, options };
21
25
  }
22
26
  case 'Entity.Delete': {
23
27
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
24
- const key = keyParam && context.pathParams[String(keyParam.name)];
28
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
25
29
  const options = {
26
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
30
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
27
31
  };
28
32
  return { method: 'delete', key, options };
29
33
  }
30
34
  case 'Entity.DeleteMany': {
31
35
  const options = {
32
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
36
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
33
37
  };
34
38
  return { method: 'deleteMany', options };
35
39
  }
36
40
  case 'Entity.FindMany': {
37
41
  const options = {
38
- count: context.queryParams.count,
39
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
40
- projection: context.queryParams.projection || operation.compositionOptions.defaultProjection,
41
- limit: context.queryParams.limit || operation.compositionOptions.defaultLimit,
42
- offset: context.queryParams.skip,
43
- sort: context.queryParams.sort || operation.compositionOptions.defaultSort,
42
+ count: ctx.queryParams.count,
43
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
44
+ projection: ctx.queryParams.projection || operation.compositionOptions.defaultProjection,
45
+ limit: ctx.queryParams.limit || operation.compositionOptions.defaultLimit,
46
+ offset: ctx.queryParams.skip,
47
+ sort: ctx.queryParams.sort || operation.compositionOptions.defaultSort,
44
48
  };
45
49
  return { method: 'findMany', options };
46
50
  }
47
51
  case 'Entity.Get': {
48
52
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
49
- const key = keyParam && context.pathParams[String(keyParam.name)];
53
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
50
54
  const options = {
51
- projection: context.queryParams.projection,
52
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
55
+ projection: ctx.queryParams.projection,
56
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
53
57
  };
54
58
  return { method: 'get', key, options };
55
59
  }
56
60
  case 'Entity.Update': {
57
- const data = await context.getBody();
61
+ const data = await ctx.getBody();
58
62
  const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
59
- const key = keyParam && context.pathParams[String(keyParam.name)];
63
+ const key = keyParam && ctx.pathParams[String(keyParam.name)];
60
64
  const options = {
61
- projection: context.queryParams.projection,
62
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
65
+ projection: ctx.queryParams.projection,
66
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
63
67
  };
64
68
  return { method: 'update', key, data, options };
65
69
  }
66
70
  case 'Entity.UpdateMany': {
67
- const data = await context.getBody();
71
+ const data = await ctx.getBody();
68
72
  const options = {
69
- filter: SQBAdapter.parseFilter(context.queryParams.filter),
73
+ filter: SQBAdapter.parseFilter(ctx.queryParams.filter),
70
74
  };
71
75
  return { method: 'updateMany', data, options };
72
76
  }
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@opra/sqb",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Opra SQB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "reflect-metadata": "^0.2.2",
9
9
  "tslib": "^2.7.0",
10
- "valgen": "^5.9.0"
10
+ "valgen": "^5.10.0"
11
11
  },
12
12
  "peerDependencies": {
13
- "@opra/core": "^1.0.0-beta.1",
13
+ "@opra/core": "^1.0.0-beta.3",
14
+ "@opra/http": "^1.0.0-beta.3",
14
15
  "@sqb/connect": ">= 4.18.0"
15
16
  },
16
17
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  import type { OpraFilter } from '@opra/common';
2
- import type { HttpContext } from '@opra/core';
2
+ import type { ExecutionContext } from '@opra/core';
3
3
  import { type Repository } from '@sqb/connect';
4
4
  import _parseFilter from './adapter-utils/parse-filter.js';
5
5
  export declare namespace SQBAdapter {
@@ -13,5 +13,5 @@ export declare namespace SQBAdapter {
13
13
  data?: any;
14
14
  options: any;
15
15
  }
16
- function parseRequest(context: HttpContext): Promise<TransformedRequest>;
16
+ function parseRequest(context: ExecutionContext): Promise<TransformedRequest>;
17
17
  }
@@ -1,5 +1,5 @@
1
1
  import { ComplexType } from '@opra/common';
2
- import { HttpContext, ServiceBase } from '@opra/core';
2
+ import { ExecutionContext, ServiceBase } from '@opra/core';
3
3
  import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
4
4
  import type { Nullish, PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
5
5
  import { type IsObject } from 'valgen';
@@ -205,7 +205,7 @@ export declare class SqbEntityService<T extends object = object> extends Service
205
205
  * @throws {TypeError} If metadata is not available
206
206
  */
207
207
  get entityMetadata(): EntityMetadata;
208
- for<C extends HttpContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
208
+ for<C extends ExecutionContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
209
209
  /**
210
210
  * Retrieves the resource name.
211
211
  *