@opra/sqb 0.23.2 → 0.24.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.
- package/cjs/augmentation/document-factory.augmentation.js +1 -1
- package/cjs/augmentation/mapped-type.augmentation.js +4 -4
- package/cjs/index.js +2 -2
- package/cjs/sqb-adapter.js +12 -12
- package/cjs/{sqb-collection-resource.js → sqb-collection.js} +17 -39
- package/cjs/sqb-entity-service.js +1 -1
- package/cjs/{sqb-singleton-resource.js → sqb-singleton.js} +11 -24
- package/esm/augmentation/document-factory.augmentation.js +2 -2
- package/esm/augmentation/mapped-type.augmentation.js +4 -4
- package/esm/index.js +2 -2
- package/esm/sqb-adapter.js +12 -12
- package/esm/{sqb-collection-resource.js → sqb-collection.js} +16 -38
- package/esm/sqb-entity-service.js +1 -1
- package/esm/{sqb-singleton-resource.js → sqb-singleton.js} +10 -23
- package/package.json +2 -2
- package/types/index.d.ts +2 -2
- package/types/sqb-collection.d.ts +21 -0
- package/types/sqb-entity-service.d.ts +3 -3
- package/types/sqb-singleton.d.ts +11 -0
- package/types/sqb-collection-resource.d.ts +0 -21
- package/types/sqb-singleton-resource.d.ts +0 -11
|
@@ -28,7 +28,7 @@ common_1.DocumentFactory.prototype.extractFieldSchema = async function (target,
|
|
|
28
28
|
metadata.enum = sqbField.enum;
|
|
29
29
|
if (target.required == null && sqbField.notNull)
|
|
30
30
|
target.required = true;
|
|
31
|
-
if (sqbField.type && Reflect.hasMetadata(common_1.
|
|
31
|
+
if (sqbField.type && Reflect.hasMetadata(common_1.DATATYPE_METADATA, sqbField.type)) {
|
|
32
32
|
target.type = sqbField.type;
|
|
33
33
|
}
|
|
34
34
|
switch (sqbField.dataType) {
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const common_1 = require("@opra/common");
|
|
4
4
|
const connect_1 = require("@sqb/connect");
|
|
5
5
|
const _applyMixin = common_1.MappedType._applyMixin;
|
|
6
|
-
common_1.MappedType._applyMixin = function (
|
|
7
|
-
_applyMixin.call(null,
|
|
8
|
-
const srcMeta = connect_1.Entity.getMetadata(
|
|
6
|
+
common_1.MappedType._applyMixin = function (targetType, sourceType, options) {
|
|
7
|
+
_applyMixin.call(null, targetType, sourceType, options);
|
|
8
|
+
const srcMeta = connect_1.Entity.getMetadata(sourceType);
|
|
9
9
|
if (srcMeta) {
|
|
10
|
-
const trgMeta = connect_1.EntityMetadata.define(
|
|
10
|
+
const trgMeta = connect_1.EntityMetadata.define(targetType);
|
|
11
11
|
const { isInheritedPredicate } = options;
|
|
12
12
|
connect_1.EntityMetadata.mixin(trgMeta, srcMeta, k => isInheritedPredicate(k));
|
|
13
13
|
}
|
package/cjs/index.js
CHANGED
|
@@ -5,6 +5,6 @@ require("./augmentation/document-factory.augmentation.js");
|
|
|
5
5
|
require("./augmentation/mapped-type.augmentation.js");
|
|
6
6
|
require("./augmentation/union-type.augmentation.js");
|
|
7
7
|
tslib_1.__exportStar(require("./sqb-adapter.js"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./sqb-collection
|
|
8
|
+
tslib_1.__exportStar(require("./sqb-collection.js"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./sqb-entity-service.js"), exports);
|
|
10
|
-
tslib_1.__exportStar(require("./sqb-singleton
|
|
10
|
+
tslib_1.__exportStar(require("./sqb-singleton.js"), exports);
|
package/cjs/sqb-adapter.js
CHANGED
|
@@ -15,7 +15,7 @@ var SQBAdapter;
|
|
|
15
15
|
function transformRequest(request) {
|
|
16
16
|
const { resource } = request;
|
|
17
17
|
if (resource instanceof common_1.Collection || resource instanceof common_1.Singleton) {
|
|
18
|
-
const { params,
|
|
18
|
+
const { params, endpoint } = request;
|
|
19
19
|
let options = {};
|
|
20
20
|
const entityMetadata = connect_1.EntityMetadata.get(resource.type.ctor);
|
|
21
21
|
if (!entityMetadata)
|
|
@@ -27,8 +27,8 @@ var SQBAdapter;
|
|
|
27
27
|
if (primaryKeys.sort().join() !== [...resource.primaryKey].sort().join())
|
|
28
28
|
throw new Error('Resource primaryKey definition differs from SQB Entity primaryKey definition');
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
30
|
+
if (endpoint === 'create' || endpoint === 'update' ||
|
|
31
|
+
endpoint === 'get' || endpoint === 'findMany') {
|
|
32
32
|
options.pick = params?.pick;
|
|
33
33
|
options.omit = params?.omit;
|
|
34
34
|
options.include = params?.include;
|
|
@@ -36,7 +36,7 @@ var SQBAdapter;
|
|
|
36
36
|
if (resource instanceof common_1.Collection && params?.filter) {
|
|
37
37
|
options.filter = (0, transform_filter_js_1.default)(params.filter);
|
|
38
38
|
}
|
|
39
|
-
if (
|
|
39
|
+
if (endpoint === 'findMany') {
|
|
40
40
|
options.sort = params?.sort;
|
|
41
41
|
options.limit = params?.limit;
|
|
42
42
|
options.offset = params?.skip;
|
|
@@ -44,7 +44,7 @@ var SQBAdapter;
|
|
|
44
44
|
options.count = params?.count;
|
|
45
45
|
}
|
|
46
46
|
options = (0, lodash_omitby_1.default)(options, lodash_isnil_1.default);
|
|
47
|
-
if (
|
|
47
|
+
if (endpoint === 'create') {
|
|
48
48
|
return {
|
|
49
49
|
method: 'create',
|
|
50
50
|
data: request.data,
|
|
@@ -52,14 +52,14 @@ var SQBAdapter;
|
|
|
52
52
|
args: [request.data, options]
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
55
|
+
if (endpoint === 'deleteMany' || (endpoint === 'delete' && resource instanceof common_1.Singleton)) {
|
|
56
56
|
return {
|
|
57
57
|
method: 'deleteMany',
|
|
58
58
|
options,
|
|
59
59
|
args: [options]
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
if (
|
|
62
|
+
if (endpoint === 'delete') {
|
|
63
63
|
return {
|
|
64
64
|
method: 'delete',
|
|
65
65
|
key: request.key,
|
|
@@ -67,7 +67,7 @@ var SQBAdapter;
|
|
|
67
67
|
args: [request.key, options]
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
if (
|
|
70
|
+
if (endpoint === 'get') {
|
|
71
71
|
if (resource instanceof common_1.Singleton)
|
|
72
72
|
return {
|
|
73
73
|
method: 'findOne',
|
|
@@ -81,7 +81,7 @@ var SQBAdapter;
|
|
|
81
81
|
args: [request.key, options]
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
if (
|
|
84
|
+
if (endpoint === 'findMany') {
|
|
85
85
|
const out = {
|
|
86
86
|
method: 'findMany',
|
|
87
87
|
options,
|
|
@@ -90,7 +90,7 @@ var SQBAdapter;
|
|
|
90
90
|
out.count = params?.count;
|
|
91
91
|
return out;
|
|
92
92
|
}
|
|
93
|
-
if (
|
|
93
|
+
if (endpoint === 'updateMany' || (endpoint === 'update' && resource instanceof common_1.Singleton)) {
|
|
94
94
|
return {
|
|
95
95
|
method: 'updateMany',
|
|
96
96
|
data: request.data,
|
|
@@ -98,7 +98,7 @@ var SQBAdapter;
|
|
|
98
98
|
args: [request.data, options]
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
if (
|
|
101
|
+
if (endpoint === 'update') {
|
|
102
102
|
return {
|
|
103
103
|
method: 'update',
|
|
104
104
|
key: request.key,
|
|
@@ -108,7 +108,7 @@ var SQBAdapter;
|
|
|
108
108
|
};
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
throw new Error(`Unimplemented request method "${request.
|
|
111
|
+
throw new Error(`Unimplemented request method "${request.endpoint}"`);
|
|
112
112
|
}
|
|
113
113
|
SQBAdapter.transformRequest = transformRequest;
|
|
114
114
|
})(SQBAdapter || (exports.SQBAdapter = SQBAdapter = {}));
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SqbCollection = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@opra/common");
|
|
6
|
-
const core_1 = require("@opra/core");
|
|
7
6
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
8
7
|
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
9
|
-
class
|
|
8
|
+
class SqbCollection {
|
|
10
9
|
constructor(options) {
|
|
11
10
|
this.defaultLimit = options?.defaultLimit || 100;
|
|
12
11
|
}
|
|
@@ -55,46 +54,25 @@ class SqbCollectionResource {
|
|
|
55
54
|
return service.with(ctx).findMany(prepared.options);
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
|
-
exports.
|
|
57
|
+
exports.SqbCollection = SqbCollection;
|
|
59
58
|
tslib_1.__decorate([
|
|
60
|
-
common_1.Collection.Create()
|
|
61
|
-
|
|
62
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
63
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
64
|
-
], SqbCollectionResource.prototype, "create", null);
|
|
59
|
+
common_1.Collection.Create()
|
|
60
|
+
], SqbCollection.prototype, "create", null);
|
|
65
61
|
tslib_1.__decorate([
|
|
66
|
-
common_1.Collection.Delete()
|
|
67
|
-
|
|
68
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
69
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
70
|
-
], SqbCollectionResource.prototype, "delete", null);
|
|
62
|
+
common_1.Collection.Delete()
|
|
63
|
+
], SqbCollection.prototype, "delete", null);
|
|
71
64
|
tslib_1.__decorate([
|
|
72
|
-
common_1.Collection.DeleteMany()
|
|
73
|
-
|
|
74
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
75
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
76
|
-
], SqbCollectionResource.prototype, "deleteMany", null);
|
|
65
|
+
common_1.Collection.DeleteMany()
|
|
66
|
+
], SqbCollection.prototype, "deleteMany", null);
|
|
77
67
|
tslib_1.__decorate([
|
|
78
|
-
common_1.Collection.Get()
|
|
79
|
-
|
|
80
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
81
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
82
|
-
], SqbCollectionResource.prototype, "get", null);
|
|
68
|
+
common_1.Collection.Get()
|
|
69
|
+
], SqbCollection.prototype, "get", null);
|
|
83
70
|
tslib_1.__decorate([
|
|
84
|
-
common_1.Collection.Update()
|
|
85
|
-
|
|
86
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
87
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
88
|
-
], SqbCollectionResource.prototype, "update", null);
|
|
71
|
+
common_1.Collection.Update()
|
|
72
|
+
], SqbCollection.prototype, "update", null);
|
|
89
73
|
tslib_1.__decorate([
|
|
90
|
-
common_1.Collection.UpdateMany()
|
|
91
|
-
|
|
92
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
93
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
94
|
-
], SqbCollectionResource.prototype, "updateMany", null);
|
|
74
|
+
common_1.Collection.UpdateMany()
|
|
75
|
+
], SqbCollection.prototype, "updateMany", null);
|
|
95
76
|
tslib_1.__decorate([
|
|
96
|
-
common_1.Collection.FindMany()
|
|
97
|
-
|
|
98
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
99
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
100
|
-
], SqbCollectionResource.prototype, "findMany", null);
|
|
77
|
+
common_1.Collection.FindMany()
|
|
78
|
+
], SqbCollection.prototype, "findMany", null);
|
|
@@ -36,7 +36,7 @@ class SqbEntityService {
|
|
|
36
36
|
if (out && this.transformData)
|
|
37
37
|
out = this.transformData(out);
|
|
38
38
|
if (!out)
|
|
39
|
-
throw new Error('"create"
|
|
39
|
+
throw new Error('"create" endpoint returned no result!');
|
|
40
40
|
return out;
|
|
41
41
|
}
|
|
42
42
|
async delete(keyValue, options) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SqbSingleton = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@opra/common");
|
|
6
|
-
const core_1 = require("@opra/core");
|
|
7
6
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
8
|
-
class
|
|
7
|
+
class SqbSingleton {
|
|
9
8
|
async create(ctx) {
|
|
10
9
|
const prepared = sqb_adapter_js_1.SQBAdapter.transformRequest(ctx.request);
|
|
11
10
|
const service = await this.getService(ctx);
|
|
@@ -28,28 +27,16 @@ class SqbSingletonResource {
|
|
|
28
27
|
return service.with(ctx).findOne(prepared.options);
|
|
29
28
|
}
|
|
30
29
|
}
|
|
31
|
-
exports.
|
|
30
|
+
exports.SqbSingleton = SqbSingleton;
|
|
32
31
|
tslib_1.__decorate([
|
|
33
|
-
common_1.Singleton.Create()
|
|
34
|
-
|
|
35
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
36
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
37
|
-
], SqbSingletonResource.prototype, "create", null);
|
|
32
|
+
common_1.Singleton.Create()
|
|
33
|
+
], SqbSingleton.prototype, "create", null);
|
|
38
34
|
tslib_1.__decorate([
|
|
39
|
-
common_1.Singleton.Delete()
|
|
40
|
-
|
|
41
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
42
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
43
|
-
], SqbSingletonResource.prototype, "delete", null);
|
|
35
|
+
common_1.Singleton.Delete()
|
|
36
|
+
], SqbSingleton.prototype, "delete", null);
|
|
44
37
|
tslib_1.__decorate([
|
|
45
|
-
common_1.Singleton.Get()
|
|
46
|
-
|
|
47
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
48
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
49
|
-
], SqbSingletonResource.prototype, "get", null);
|
|
38
|
+
common_1.Singleton.Get()
|
|
39
|
+
], SqbSingleton.prototype, "get", null);
|
|
50
40
|
tslib_1.__decorate([
|
|
51
|
-
common_1.Singleton.Update()
|
|
52
|
-
|
|
53
|
-
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
54
|
-
tslib_1.__metadata("design:returntype", Promise)
|
|
55
|
-
], SqbSingletonResource.prototype, "update", null);
|
|
41
|
+
common_1.Singleton.Update()
|
|
42
|
+
], SqbSingleton.prototype, "update", null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DATATYPE_METADATA, DocumentFactory } from "@opra/common";
|
|
2
2
|
import { DataType as SqbDataType, EntityMetadata, isAssociationField } from '@sqb/connect';
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
const _extractFieldSchema = DocumentFactory.prototype.extractFieldSchema;
|
|
@@ -26,7 +26,7 @@ DocumentFactory.prototype.extractFieldSchema = async function (target, ctor, met
|
|
|
26
26
|
metadata.enum = sqbField.enum;
|
|
27
27
|
if (target.required == null && sqbField.notNull)
|
|
28
28
|
target.required = true;
|
|
29
|
-
if (sqbField.type && Reflect.hasMetadata(
|
|
29
|
+
if (sqbField.type && Reflect.hasMetadata(DATATYPE_METADATA, sqbField.type)) {
|
|
30
30
|
target.type = sqbField.type;
|
|
31
31
|
}
|
|
32
32
|
switch (sqbField.dataType) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MappedType } from "@opra/common";
|
|
2
2
|
import { Entity, EntityMetadata } from '@sqb/connect';
|
|
3
3
|
const _applyMixin = MappedType._applyMixin;
|
|
4
|
-
MappedType._applyMixin = function (
|
|
5
|
-
_applyMixin.call(null,
|
|
6
|
-
const srcMeta = Entity.getMetadata(
|
|
4
|
+
MappedType._applyMixin = function (targetType, sourceType, options) {
|
|
5
|
+
_applyMixin.call(null, targetType, sourceType, options);
|
|
6
|
+
const srcMeta = Entity.getMetadata(sourceType);
|
|
7
7
|
if (srcMeta) {
|
|
8
|
-
const trgMeta = EntityMetadata.define(
|
|
8
|
+
const trgMeta = EntityMetadata.define(targetType);
|
|
9
9
|
const { isInheritedPredicate } = options;
|
|
10
10
|
EntityMetadata.mixin(trgMeta, srcMeta, k => isInheritedPredicate(k));
|
|
11
11
|
}
|
package/esm/index.js
CHANGED
|
@@ -2,6 +2,6 @@ import './augmentation/document-factory.augmentation.js';
|
|
|
2
2
|
import './augmentation/mapped-type.augmentation.js';
|
|
3
3
|
import './augmentation/union-type.augmentation.js';
|
|
4
4
|
export * from './sqb-adapter.js';
|
|
5
|
-
export * from './sqb-collection
|
|
5
|
+
export * from './sqb-collection.js';
|
|
6
6
|
export * from './sqb-entity-service.js';
|
|
7
|
-
export * from './sqb-singleton
|
|
7
|
+
export * from './sqb-singleton.js';
|
package/esm/sqb-adapter.js
CHANGED
|
@@ -11,7 +11,7 @@ export var SQBAdapter;
|
|
|
11
11
|
function transformRequest(request) {
|
|
12
12
|
const { resource } = request;
|
|
13
13
|
if (resource instanceof Collection || resource instanceof Singleton) {
|
|
14
|
-
const { params,
|
|
14
|
+
const { params, endpoint } = request;
|
|
15
15
|
let options = {};
|
|
16
16
|
const entityMetadata = EntityMetadata.get(resource.type.ctor);
|
|
17
17
|
if (!entityMetadata)
|
|
@@ -23,8 +23,8 @@ export var SQBAdapter;
|
|
|
23
23
|
if (primaryKeys.sort().join() !== [...resource.primaryKey].sort().join())
|
|
24
24
|
throw new Error('Resource primaryKey definition differs from SQB Entity primaryKey definition');
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
27
|
-
|
|
26
|
+
if (endpoint === 'create' || endpoint === 'update' ||
|
|
27
|
+
endpoint === 'get' || endpoint === 'findMany') {
|
|
28
28
|
options.pick = params?.pick;
|
|
29
29
|
options.omit = params?.omit;
|
|
30
30
|
options.include = params?.include;
|
|
@@ -32,7 +32,7 @@ export var SQBAdapter;
|
|
|
32
32
|
if (resource instanceof Collection && params?.filter) {
|
|
33
33
|
options.filter = _transformFilter(params.filter);
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (endpoint === 'findMany') {
|
|
36
36
|
options.sort = params?.sort;
|
|
37
37
|
options.limit = params?.limit;
|
|
38
38
|
options.offset = params?.skip;
|
|
@@ -40,7 +40,7 @@ export var SQBAdapter;
|
|
|
40
40
|
options.count = params?.count;
|
|
41
41
|
}
|
|
42
42
|
options = omitBy(options, isNil);
|
|
43
|
-
if (
|
|
43
|
+
if (endpoint === 'create') {
|
|
44
44
|
return {
|
|
45
45
|
method: 'create',
|
|
46
46
|
data: request.data,
|
|
@@ -48,14 +48,14 @@ export var SQBAdapter;
|
|
|
48
48
|
args: [request.data, options]
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
51
|
+
if (endpoint === 'deleteMany' || (endpoint === 'delete' && resource instanceof Singleton)) {
|
|
52
52
|
return {
|
|
53
53
|
method: 'deleteMany',
|
|
54
54
|
options,
|
|
55
55
|
args: [options]
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
|
-
if (
|
|
58
|
+
if (endpoint === 'delete') {
|
|
59
59
|
return {
|
|
60
60
|
method: 'delete',
|
|
61
61
|
key: request.key,
|
|
@@ -63,7 +63,7 @@ export var SQBAdapter;
|
|
|
63
63
|
args: [request.key, options]
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
if (
|
|
66
|
+
if (endpoint === 'get') {
|
|
67
67
|
if (resource instanceof Singleton)
|
|
68
68
|
return {
|
|
69
69
|
method: 'findOne',
|
|
@@ -77,7 +77,7 @@ export var SQBAdapter;
|
|
|
77
77
|
args: [request.key, options]
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
|
-
if (
|
|
80
|
+
if (endpoint === 'findMany') {
|
|
81
81
|
const out = {
|
|
82
82
|
method: 'findMany',
|
|
83
83
|
options,
|
|
@@ -86,7 +86,7 @@ export var SQBAdapter;
|
|
|
86
86
|
out.count = params?.count;
|
|
87
87
|
return out;
|
|
88
88
|
}
|
|
89
|
-
if (
|
|
89
|
+
if (endpoint === 'updateMany' || (endpoint === 'update' && resource instanceof Singleton)) {
|
|
90
90
|
return {
|
|
91
91
|
method: 'updateMany',
|
|
92
92
|
data: request.data,
|
|
@@ -94,7 +94,7 @@ export var SQBAdapter;
|
|
|
94
94
|
args: [request.data, options]
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
|
-
if (
|
|
97
|
+
if (endpoint === 'update') {
|
|
98
98
|
return {
|
|
99
99
|
method: 'update',
|
|
100
100
|
key: request.key,
|
|
@@ -104,7 +104,7 @@ export var SQBAdapter;
|
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
throw new Error(`Unimplemented request method "${request.
|
|
107
|
+
throw new Error(`Unimplemented request method "${request.endpoint}"`);
|
|
108
108
|
}
|
|
109
109
|
SQBAdapter.transformRequest = transformRequest;
|
|
110
110
|
})(SQBAdapter || (SQBAdapter = {}));
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { __decorate
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { Collection } from '@opra/common';
|
|
3
|
-
import { OperationContext } from '@opra/core';
|
|
4
3
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
5
4
|
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
6
|
-
export class
|
|
5
|
+
export class SqbCollection {
|
|
7
6
|
constructor(options) {
|
|
8
7
|
this.defaultLimit = options?.defaultLimit || 100;
|
|
9
8
|
}
|
|
@@ -53,44 +52,23 @@ export class SqbCollectionResource {
|
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
54
|
__decorate([
|
|
56
|
-
Collection.Create()
|
|
57
|
-
|
|
58
|
-
__metadata("design:paramtypes", [Object]),
|
|
59
|
-
__metadata("design:returntype", Promise)
|
|
60
|
-
], SqbCollectionResource.prototype, "create", null);
|
|
55
|
+
Collection.Create()
|
|
56
|
+
], SqbCollection.prototype, "create", null);
|
|
61
57
|
__decorate([
|
|
62
|
-
Collection.Delete()
|
|
63
|
-
|
|
64
|
-
__metadata("design:paramtypes", [Object]),
|
|
65
|
-
__metadata("design:returntype", Promise)
|
|
66
|
-
], SqbCollectionResource.prototype, "delete", null);
|
|
58
|
+
Collection.Delete()
|
|
59
|
+
], SqbCollection.prototype, "delete", null);
|
|
67
60
|
__decorate([
|
|
68
|
-
Collection.DeleteMany()
|
|
69
|
-
|
|
70
|
-
__metadata("design:paramtypes", [Object]),
|
|
71
|
-
__metadata("design:returntype", Promise)
|
|
72
|
-
], SqbCollectionResource.prototype, "deleteMany", null);
|
|
61
|
+
Collection.DeleteMany()
|
|
62
|
+
], SqbCollection.prototype, "deleteMany", null);
|
|
73
63
|
__decorate([
|
|
74
|
-
Collection.Get()
|
|
75
|
-
|
|
76
|
-
__metadata("design:paramtypes", [Object]),
|
|
77
|
-
__metadata("design:returntype", Promise)
|
|
78
|
-
], SqbCollectionResource.prototype, "get", null);
|
|
64
|
+
Collection.Get()
|
|
65
|
+
], SqbCollection.prototype, "get", null);
|
|
79
66
|
__decorate([
|
|
80
|
-
Collection.Update()
|
|
81
|
-
|
|
82
|
-
__metadata("design:paramtypes", [Object]),
|
|
83
|
-
__metadata("design:returntype", Promise)
|
|
84
|
-
], SqbCollectionResource.prototype, "update", null);
|
|
67
|
+
Collection.Update()
|
|
68
|
+
], SqbCollection.prototype, "update", null);
|
|
85
69
|
__decorate([
|
|
86
|
-
Collection.UpdateMany()
|
|
87
|
-
|
|
88
|
-
__metadata("design:paramtypes", [Object]),
|
|
89
|
-
__metadata("design:returntype", Promise)
|
|
90
|
-
], SqbCollectionResource.prototype, "updateMany", null);
|
|
70
|
+
Collection.UpdateMany()
|
|
71
|
+
], SqbCollection.prototype, "updateMany", null);
|
|
91
72
|
__decorate([
|
|
92
|
-
Collection.FindMany()
|
|
93
|
-
|
|
94
|
-
__metadata("design:paramtypes", [Object]),
|
|
95
|
-
__metadata("design:returntype", Promise)
|
|
96
|
-
], SqbCollectionResource.prototype, "findMany", null);
|
|
73
|
+
Collection.FindMany()
|
|
74
|
+
], SqbCollection.prototype, "findMany", null);
|
|
@@ -33,7 +33,7 @@ export class SqbEntityService {
|
|
|
33
33
|
if (out && this.transformData)
|
|
34
34
|
out = this.transformData(out);
|
|
35
35
|
if (!out)
|
|
36
|
-
throw new Error('"create"
|
|
36
|
+
throw new Error('"create" endpoint returned no result!');
|
|
37
37
|
return out;
|
|
38
38
|
}
|
|
39
39
|
async delete(keyValue, options) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { __decorate
|
|
1
|
+
import { __decorate } from "tslib";
|
|
2
2
|
import { Singleton } from '@opra/common';
|
|
3
|
-
import { OperationContext } from '@opra/core';
|
|
4
3
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
5
|
-
export class
|
|
4
|
+
export class SqbSingleton {
|
|
6
5
|
async create(ctx) {
|
|
7
6
|
const prepared = SQBAdapter.transformRequest(ctx.request);
|
|
8
7
|
const service = await this.getService(ctx);
|
|
@@ -26,26 +25,14 @@ export class SqbSingletonResource {
|
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
__decorate([
|
|
29
|
-
Singleton.Create()
|
|
30
|
-
|
|
31
|
-
__metadata("design:paramtypes", [Object]),
|
|
32
|
-
__metadata("design:returntype", Promise)
|
|
33
|
-
], SqbSingletonResource.prototype, "create", null);
|
|
28
|
+
Singleton.Create()
|
|
29
|
+
], SqbSingleton.prototype, "create", null);
|
|
34
30
|
__decorate([
|
|
35
|
-
Singleton.Delete()
|
|
36
|
-
|
|
37
|
-
__metadata("design:paramtypes", [Object]),
|
|
38
|
-
__metadata("design:returntype", Promise)
|
|
39
|
-
], SqbSingletonResource.prototype, "delete", null);
|
|
31
|
+
Singleton.Delete()
|
|
32
|
+
], SqbSingleton.prototype, "delete", null);
|
|
40
33
|
__decorate([
|
|
41
|
-
Singleton.Get()
|
|
42
|
-
|
|
43
|
-
__metadata("design:paramtypes", [Object]),
|
|
44
|
-
__metadata("design:returntype", Promise)
|
|
45
|
-
], SqbSingletonResource.prototype, "get", null);
|
|
34
|
+
Singleton.Get()
|
|
35
|
+
], SqbSingleton.prototype, "get", null);
|
|
46
36
|
__decorate([
|
|
47
|
-
Singleton.Update()
|
|
48
|
-
|
|
49
|
-
__metadata("design:paramtypes", [Object]),
|
|
50
|
-
__metadata("design:returntype", Promise)
|
|
51
|
-
], SqbSingletonResource.prototype, "update", null);
|
|
37
|
+
Singleton.Update()
|
|
38
|
+
], SqbSingleton.prototype, "update", null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"ts-gems": "^2.4.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@opra/core": "^0.
|
|
40
|
+
"@opra/core": "^0.24.0",
|
|
41
41
|
"@sqb/connect": ">= 4.9.0"
|
|
42
42
|
},
|
|
43
43
|
"type": "module",
|
package/types/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import './augmentation/document-factory.augmentation.js';
|
|
|
2
2
|
import './augmentation/mapped-type.augmentation.js';
|
|
3
3
|
import './augmentation/union-type.augmentation.js';
|
|
4
4
|
export * from './sqb-adapter.js';
|
|
5
|
-
export * from './sqb-collection
|
|
5
|
+
export * from './sqb-collection.js';
|
|
6
6
|
export * from './sqb-entity-service.js';
|
|
7
|
-
export * from './sqb-singleton
|
|
7
|
+
export * from './sqb-singleton.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Maybe } from 'ts-gems';
|
|
2
|
+
import { PartialOutput } from '@opra/common';
|
|
3
|
+
import { EndpointContext } from '@opra/core';
|
|
4
|
+
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
|
+
export declare namespace SqbCollection {
|
|
6
|
+
interface Options {
|
|
7
|
+
defaultLimit?: number;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class SqbCollection<T, TOutput = PartialOutput<T>> {
|
|
11
|
+
defaultLimit?: number;
|
|
12
|
+
constructor(options?: SqbCollection.Options);
|
|
13
|
+
create(ctx: EndpointContext): Promise<TOutput>;
|
|
14
|
+
delete(ctx: EndpointContext): Promise<boolean>;
|
|
15
|
+
deleteMany(ctx: EndpointContext): Promise<number>;
|
|
16
|
+
get(ctx: EndpointContext): Promise<Maybe<TOutput>>;
|
|
17
|
+
update(ctx: EndpointContext): Promise<Maybe<TOutput>>;
|
|
18
|
+
updateMany(ctx: EndpointContext): Promise<number>;
|
|
19
|
+
findMany(ctx: EndpointContext): Promise<TOutput[]>;
|
|
20
|
+
abstract getService(ctx: EndpointContext): SqbEntityService<T, TOutput> | Promise<SqbEntityService<T, TOutput>>;
|
|
21
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Maybe, Type } from 'ts-gems';
|
|
2
|
-
import {
|
|
2
|
+
import { EndpointContext, PartialInput, PartialOutput } from '@opra/core';
|
|
3
3
|
import { EntityInput, Repository, SqbClient, SqbConnection } from '@sqb/connect';
|
|
4
4
|
export declare namespace SqbEntityService {
|
|
5
5
|
interface Options {
|
|
@@ -9,7 +9,7 @@ export declare namespace SqbEntityService {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class SqbEntityService<T, TOutput = PartialOutput<T>> {
|
|
11
11
|
readonly typeClass: Type<T>;
|
|
12
|
-
context:
|
|
12
|
+
context: EndpointContext;
|
|
13
13
|
defaultLimit: number;
|
|
14
14
|
db?: SqbClient | SqbConnection;
|
|
15
15
|
constructor(typeClass: Type<T>, options?: SqbEntityService.Options);
|
|
@@ -23,7 +23,7 @@ export declare class SqbEntityService<T, TOutput = PartialOutput<T>> {
|
|
|
23
23
|
exists(options?: Repository.ExistsOptions): Promise<boolean>;
|
|
24
24
|
update(keyValue: any, data: EntityInput<T>, options?: Repository.UpdateOptions): Promise<Maybe<TOutput>>;
|
|
25
25
|
updateMany(data: PartialInput<T>, options?: Repository.UpdateManyOptions): Promise<number>;
|
|
26
|
-
with(context:
|
|
26
|
+
with(context: EndpointContext, db?: SqbClient | SqbConnection): SqbEntityService<T, TOutput>;
|
|
27
27
|
protected _onError(error: unknown): Promise<void>;
|
|
28
28
|
protected getConnection(): SqbConnection | SqbClient | Promise<SqbConnection | SqbClient>;
|
|
29
29
|
protected onError?(error: unknown): void | Promise<void>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Maybe } from 'ts-gems';
|
|
2
|
+
import { PartialOutput } from '@opra/common';
|
|
3
|
+
import { EndpointContext } from '@opra/core';
|
|
4
|
+
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
|
+
export declare abstract class SqbSingleton<T> {
|
|
6
|
+
create(ctx: EndpointContext): Promise<PartialOutput<T>>;
|
|
7
|
+
delete(ctx: EndpointContext): Promise<boolean>;
|
|
8
|
+
get(ctx: EndpointContext): Promise<Maybe<PartialOutput<T>>>;
|
|
9
|
+
update(ctx: EndpointContext): Promise<Maybe<PartialOutput<T>>>;
|
|
10
|
+
abstract getService(req: EndpointContext): SqbEntityService<T> | Promise<SqbEntityService<T>>;
|
|
11
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Maybe } from 'ts-gems';
|
|
2
|
-
import { PartialOutput } from '@opra/common';
|
|
3
|
-
import { OperationContext } from '@opra/core';
|
|
4
|
-
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
|
-
export declare namespace SqbCollectionResource {
|
|
6
|
-
interface Options {
|
|
7
|
-
defaultLimit?: number;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare abstract class SqbCollectionResource<T, TOutput = PartialOutput<T>> {
|
|
11
|
-
defaultLimit?: number;
|
|
12
|
-
constructor(options?: SqbCollectionResource.Options);
|
|
13
|
-
create(ctx: OperationContext): Promise<TOutput>;
|
|
14
|
-
delete(ctx: OperationContext): Promise<boolean>;
|
|
15
|
-
deleteMany(ctx: OperationContext): Promise<number>;
|
|
16
|
-
get(ctx: OperationContext): Promise<Maybe<TOutput>>;
|
|
17
|
-
update(ctx: OperationContext): Promise<Maybe<TOutput>>;
|
|
18
|
-
updateMany(ctx: OperationContext): Promise<number>;
|
|
19
|
-
findMany(ctx: OperationContext): Promise<TOutput[]>;
|
|
20
|
-
abstract getService(ctx: OperationContext): SqbEntityService<T, TOutput> | Promise<SqbEntityService<T, TOutput>>;
|
|
21
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Maybe } from 'ts-gems';
|
|
2
|
-
import { PartialOutput } from '@opra/common';
|
|
3
|
-
import { OperationContext } from '@opra/core';
|
|
4
|
-
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
|
-
export declare abstract class SqbSingletonResource<T> {
|
|
6
|
-
create(ctx: OperationContext): Promise<PartialOutput<T>>;
|
|
7
|
-
delete(ctx: OperationContext): Promise<boolean>;
|
|
8
|
-
get(ctx: OperationContext): Promise<Maybe<PartialOutput<T>>>;
|
|
9
|
-
update(ctx: OperationContext): Promise<Maybe<PartialOutput<T>>>;
|
|
10
|
-
abstract getService(req: OperationContext): SqbEntityService<T> | Promise<SqbEntityService<T>>;
|
|
11
|
-
}
|