@opra/mongodb 1.0.0-alpha.4 → 1.0.0-alpha.6

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.
@@ -17,7 +17,7 @@ var MongoAdapter;
17
17
  async function parseRequest(context) {
18
18
  const { operation } = context;
19
19
  if (operation.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
20
- const { compositionOptions } = operation;
20
+ const controller = operation.owner;
21
21
  switch (operation.composition) {
22
22
  case 'Entity.Create': {
23
23
  const data = await context.getBody();
@@ -27,7 +27,8 @@ var MongoAdapter;
27
27
  return { method: 'create', data, options };
28
28
  }
29
29
  case 'Entity.Delete': {
30
- const key = context.pathParams[compositionOptions.keyParameter];
30
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
31
+ const key = keyParam && context.pathParams[String(keyParam.name)];
31
32
  const options = {
32
33
  filter: context.queryParams.filter,
33
34
  };
@@ -51,7 +52,8 @@ var MongoAdapter;
51
52
  return { method: 'findMany', options };
52
53
  }
53
54
  case 'Entity.Get': {
54
- const key = context.pathParams[compositionOptions.keyParameter];
55
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
56
+ const key = keyParam && context.pathParams[String(keyParam.name)];
55
57
  const options = {
56
58
  projection: context.queryParams.projection,
57
59
  filter: context.queryParams.filter,
@@ -60,7 +62,8 @@ var MongoAdapter;
60
62
  }
61
63
  case 'Entity.Update': {
62
64
  const data = await context.getBody();
63
- const key = context.pathParams[compositionOptions.keyParameter];
65
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
66
+ const key = keyParam && context.pathParams[String(keyParam.name)];
64
67
  const options = {
65
68
  projection: context.queryParams.projection,
66
69
  filter: context.queryParams.filter,
@@ -85,7 +85,7 @@ class MongoService extends core_1.ServiceBase {
85
85
  let validator = this._inputCodecs[operation];
86
86
  if (validator)
87
87
  return validator;
88
- const options = { projection: '*', ignoreReadonlyFields: true };
88
+ const options = { projection: '*' };
89
89
  if (operation === 'update')
90
90
  options.partial = 'deep';
91
91
  const dataType = this.dataType;
@@ -100,7 +100,7 @@ class MongoService extends core_1.ServiceBase {
100
100
  let validator = this._outputCodecs[operation];
101
101
  if (validator)
102
102
  return validator;
103
- const options = { projection: '*', partial: 'deep', ignoreWriteonlyFields: true };
103
+ const options = { projection: '*', partial: 'deep' };
104
104
  const dataType = this.dataType;
105
105
  validator = dataType.generateCodec('decode', options);
106
106
  this._outputCodecs[operation] = validator;
@@ -13,7 +13,7 @@ export var MongoAdapter;
13
13
  async function parseRequest(context) {
14
14
  const { operation } = context;
15
15
  if (operation.composition?.startsWith('Entity.') && operation.compositionOptions?.type) {
16
- const { compositionOptions } = operation;
16
+ const controller = operation.owner;
17
17
  switch (operation.composition) {
18
18
  case 'Entity.Create': {
19
19
  const data = await context.getBody();
@@ -23,7 +23,8 @@ export var MongoAdapter;
23
23
  return { method: 'create', data, options };
24
24
  }
25
25
  case 'Entity.Delete': {
26
- const key = context.pathParams[compositionOptions.keyParameter];
26
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
27
+ const key = keyParam && context.pathParams[String(keyParam.name)];
27
28
  const options = {
28
29
  filter: context.queryParams.filter,
29
30
  };
@@ -47,7 +48,8 @@ export var MongoAdapter;
47
48
  return { method: 'findMany', options };
48
49
  }
49
50
  case 'Entity.Get': {
50
- const key = context.pathParams[compositionOptions.keyParameter];
51
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
52
+ const key = keyParam && context.pathParams[String(keyParam.name)];
51
53
  const options = {
52
54
  projection: context.queryParams.projection,
53
55
  filter: context.queryParams.filter,
@@ -56,7 +58,8 @@ export var MongoAdapter;
56
58
  }
57
59
  case 'Entity.Update': {
58
60
  const data = await context.getBody();
59
- const key = context.pathParams[compositionOptions.keyParameter];
61
+ const keyParam = operation.parameters.find(p => p.keyParam) || controller.parameters.find(p => p.keyParam);
62
+ const key = keyParam && context.pathParams[String(keyParam.name)];
60
63
  const options = {
61
64
  projection: context.queryParams.projection,
62
65
  filter: context.queryParams.filter,
@@ -82,7 +82,7 @@ export class MongoService extends ServiceBase {
82
82
  let validator = this._inputCodecs[operation];
83
83
  if (validator)
84
84
  return validator;
85
- const options = { projection: '*', ignoreReadonlyFields: true };
85
+ const options = { projection: '*' };
86
86
  if (operation === 'update')
87
87
  options.partial = 'deep';
88
88
  const dataType = this.dataType;
@@ -97,7 +97,7 @@ export class MongoService extends ServiceBase {
97
97
  let validator = this._outputCodecs[operation];
98
98
  if (validator)
99
99
  return validator;
100
- const options = { projection: '*', partial: 'deep', ignoreWriteonlyFields: true };
100
+ const options = { projection: '*', partial: 'deep' };
101
101
  const dataType = this.dataType;
102
102
  validator = dataType.generateCodec('decode', options);
103
103
  this._outputCodecs[operation] = validator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opra/mongodb",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "description": "Opra MongoDB adapter package",
5
5
  "author": "Panates",
6
6
  "license": "MIT",
@@ -31,8 +31,8 @@
31
31
  "ts-gems": "^3.4.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@opra/common": "^1.0.0-alpha.4",
35
- "@opra/core": "^1.0.0-alpha.4",
34
+ "@opra/common": "^1.0.0-alpha.6",
35
+ "@opra/core": "^1.0.0-alpha.6",
36
36
  "mongodb": ">= 6.0.0"
37
37
  },
38
38
  "type": "module",