@opra/sqb 0.22.0 → 0.23.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/sqb-adapter.js +23 -24
- package/cjs/sqb-collection-resource.js +4 -4
- package/cjs/sqb-singleton-resource.js +1 -0
- package/esm/augmentation/document-factory.augmentation.js +1 -1
- package/esm/sqb-adapter.js +23 -24
- package/esm/sqb-collection-resource.js +5 -5
- package/esm/sqb-singleton-resource.js +1 -0
- package/package.json +2 -2
- package/types/sqb-collection-resource.d.ts +13 -11
- package/types/sqb-entity-service.d.ts +3 -3
- package/types/sqb-singleton-resource.d.ts +6 -6
|
@@ -26,7 +26,7 @@ common_1.DocumentFactory.prototype.extractFieldSchema = async function (target,
|
|
|
26
26
|
else if (sqbField.kind === 'column') {
|
|
27
27
|
if (typeof sqbField.enum === 'object')
|
|
28
28
|
metadata.enum = sqbField.enum;
|
|
29
|
-
if (sqbField.notNull)
|
|
29
|
+
if (target.required == null && sqbField.notNull)
|
|
30
30
|
target.required = true;
|
|
31
31
|
if (sqbField.type && Reflect.hasMetadata(common_1.METADATA_KEY, sqbField.type)) {
|
|
32
32
|
target.type = sqbField.type;
|
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 {
|
|
18
|
+
const { params, operation } = request;
|
|
19
19
|
let options = {};
|
|
20
20
|
const entityMetadata = connect_1.EntityMetadata.get(resource.type.ctor);
|
|
21
21
|
if (!entityMetadata)
|
|
@@ -29,27 +29,27 @@ var SQBAdapter;
|
|
|
29
29
|
}
|
|
30
30
|
if (operation === 'create' || operation === 'update' ||
|
|
31
31
|
operation === 'get' || operation === 'findMany') {
|
|
32
|
-
options.pick =
|
|
33
|
-
options.omit =
|
|
34
|
-
options.include =
|
|
32
|
+
options.pick = params?.pick;
|
|
33
|
+
options.omit = params?.omit;
|
|
34
|
+
options.include = params?.include;
|
|
35
35
|
}
|
|
36
|
-
if (resource instanceof common_1.Collection &&
|
|
37
|
-
options.filter = (0, transform_filter_js_1.default)(
|
|
36
|
+
if (resource instanceof common_1.Collection && params?.filter) {
|
|
37
|
+
options.filter = (0, transform_filter_js_1.default)(params.filter);
|
|
38
38
|
}
|
|
39
39
|
if (operation === 'findMany') {
|
|
40
|
-
options.sort =
|
|
41
|
-
options.limit =
|
|
42
|
-
options.offset =
|
|
43
|
-
options.distinct =
|
|
44
|
-
options.count =
|
|
40
|
+
options.sort = params?.sort;
|
|
41
|
+
options.limit = params?.limit;
|
|
42
|
+
options.offset = params?.skip;
|
|
43
|
+
options.distinct = params?.distinct;
|
|
44
|
+
options.count = params?.count;
|
|
45
45
|
}
|
|
46
46
|
options = (0, lodash_omitby_1.default)(options, lodash_isnil_1.default);
|
|
47
47
|
if (operation === 'create') {
|
|
48
48
|
return {
|
|
49
49
|
method: 'create',
|
|
50
|
-
data:
|
|
50
|
+
data: request.data,
|
|
51
51
|
options,
|
|
52
|
-
args: [
|
|
52
|
+
args: [request.data, options]
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
if (operation === 'deleteMany' || (operation === 'delete' && resource instanceof common_1.Singleton)) {
|
|
@@ -62,9 +62,9 @@ var SQBAdapter;
|
|
|
62
62
|
if (operation === 'delete') {
|
|
63
63
|
return {
|
|
64
64
|
method: 'delete',
|
|
65
|
-
key:
|
|
65
|
+
key: request.key,
|
|
66
66
|
options,
|
|
67
|
-
args: [
|
|
67
|
+
args: [request.key, options]
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
if (operation === 'get') {
|
|
@@ -76,9 +76,9 @@ var SQBAdapter;
|
|
|
76
76
|
};
|
|
77
77
|
return {
|
|
78
78
|
method: 'find',
|
|
79
|
-
key:
|
|
79
|
+
key: request.key,
|
|
80
80
|
options,
|
|
81
|
-
args: [
|
|
81
|
+
args: [request.key, options]
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
if (operation === 'findMany') {
|
|
@@ -87,25 +87,24 @@ var SQBAdapter;
|
|
|
87
87
|
options,
|
|
88
88
|
args: [options]
|
|
89
89
|
};
|
|
90
|
-
|
|
91
|
-
out.count = args.count;
|
|
90
|
+
out.count = params?.count;
|
|
92
91
|
return out;
|
|
93
92
|
}
|
|
94
93
|
if (operation === 'updateMany' || (operation === 'update' && resource instanceof common_1.Singleton)) {
|
|
95
94
|
return {
|
|
96
95
|
method: 'updateMany',
|
|
97
|
-
data:
|
|
96
|
+
data: request.data,
|
|
98
97
|
options,
|
|
99
|
-
args: [
|
|
98
|
+
args: [request.data, options]
|
|
100
99
|
};
|
|
101
100
|
}
|
|
102
101
|
if (operation === 'update') {
|
|
103
102
|
return {
|
|
104
103
|
method: 'update',
|
|
105
|
-
key:
|
|
106
|
-
data:
|
|
104
|
+
key: request.key,
|
|
105
|
+
data: request.data,
|
|
107
106
|
options,
|
|
108
|
-
args: [
|
|
107
|
+
args: [request.key, request.data, options]
|
|
109
108
|
};
|
|
110
109
|
}
|
|
111
110
|
}
|
|
@@ -6,9 +6,9 @@ const common_1 = require("@opra/common");
|
|
|
6
6
|
const core_1 = require("@opra/core");
|
|
7
7
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
8
8
|
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
9
|
-
class SqbCollectionResource
|
|
9
|
+
class SqbCollectionResource {
|
|
10
10
|
constructor(options) {
|
|
11
|
-
|
|
11
|
+
this.defaultLimit = options?.defaultLimit || 100;
|
|
12
12
|
}
|
|
13
13
|
async create(ctx) {
|
|
14
14
|
const prepared = sqb_adapter_js_1.SQBAdapter.transformRequest(ctx.request);
|
|
@@ -25,7 +25,7 @@ class SqbCollectionResource extends core_1.CollectionResourceBase {
|
|
|
25
25
|
const service = await this.getService(ctx);
|
|
26
26
|
return service.with(ctx).deleteMany(prepared.options);
|
|
27
27
|
}
|
|
28
|
-
async
|
|
28
|
+
async get(ctx) {
|
|
29
29
|
const prepared = sqb_adapter_js_1.SQBAdapter.transformRequest(ctx.request);
|
|
30
30
|
const service = await this.getService(ctx);
|
|
31
31
|
return service.with(ctx).find(prepared.key, prepared.options);
|
|
@@ -79,7 +79,7 @@ tslib_1.__decorate([
|
|
|
79
79
|
tslib_1.__metadata("design:type", Function),
|
|
80
80
|
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
81
81
|
tslib_1.__metadata("design:returntype", Promise)
|
|
82
|
-
], SqbCollectionResource.prototype, "
|
|
82
|
+
], SqbCollectionResource.prototype, "get", null);
|
|
83
83
|
tslib_1.__decorate([
|
|
84
84
|
common_1.Collection.Update(),
|
|
85
85
|
tslib_1.__metadata("design:type", Function),
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SqbSingletonResource = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@opra/common");
|
|
6
|
+
const core_1 = require("@opra/core");
|
|
6
7
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
7
8
|
class SqbSingletonResource {
|
|
8
9
|
async create(ctx) {
|
|
@@ -24,7 +24,7 @@ DocumentFactory.prototype.extractFieldSchema = async function (target, ctor, met
|
|
|
24
24
|
else if (sqbField.kind === 'column') {
|
|
25
25
|
if (typeof sqbField.enum === 'object')
|
|
26
26
|
metadata.enum = sqbField.enum;
|
|
27
|
-
if (sqbField.notNull)
|
|
27
|
+
if (target.required == null && sqbField.notNull)
|
|
28
28
|
target.required = true;
|
|
29
29
|
if (sqbField.type && Reflect.hasMetadata(METADATA_KEY, sqbField.type)) {
|
|
30
30
|
target.type = sqbField.type;
|
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 {
|
|
14
|
+
const { params, operation } = request;
|
|
15
15
|
let options = {};
|
|
16
16
|
const entityMetadata = EntityMetadata.get(resource.type.ctor);
|
|
17
17
|
if (!entityMetadata)
|
|
@@ -25,27 +25,27 @@ export var SQBAdapter;
|
|
|
25
25
|
}
|
|
26
26
|
if (operation === 'create' || operation === 'update' ||
|
|
27
27
|
operation === 'get' || operation === 'findMany') {
|
|
28
|
-
options.pick =
|
|
29
|
-
options.omit =
|
|
30
|
-
options.include =
|
|
28
|
+
options.pick = params?.pick;
|
|
29
|
+
options.omit = params?.omit;
|
|
30
|
+
options.include = params?.include;
|
|
31
31
|
}
|
|
32
|
-
if (resource instanceof Collection &&
|
|
33
|
-
options.filter = _transformFilter(
|
|
32
|
+
if (resource instanceof Collection && params?.filter) {
|
|
33
|
+
options.filter = _transformFilter(params.filter);
|
|
34
34
|
}
|
|
35
35
|
if (operation === 'findMany') {
|
|
36
|
-
options.sort =
|
|
37
|
-
options.limit =
|
|
38
|
-
options.offset =
|
|
39
|
-
options.distinct =
|
|
40
|
-
options.count =
|
|
36
|
+
options.sort = params?.sort;
|
|
37
|
+
options.limit = params?.limit;
|
|
38
|
+
options.offset = params?.skip;
|
|
39
|
+
options.distinct = params?.distinct;
|
|
40
|
+
options.count = params?.count;
|
|
41
41
|
}
|
|
42
42
|
options = omitBy(options, isNil);
|
|
43
43
|
if (operation === 'create') {
|
|
44
44
|
return {
|
|
45
45
|
method: 'create',
|
|
46
|
-
data:
|
|
46
|
+
data: request.data,
|
|
47
47
|
options,
|
|
48
|
-
args: [
|
|
48
|
+
args: [request.data, options]
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
if (operation === 'deleteMany' || (operation === 'delete' && resource instanceof Singleton)) {
|
|
@@ -58,9 +58,9 @@ export var SQBAdapter;
|
|
|
58
58
|
if (operation === 'delete') {
|
|
59
59
|
return {
|
|
60
60
|
method: 'delete',
|
|
61
|
-
key:
|
|
61
|
+
key: request.key,
|
|
62
62
|
options,
|
|
63
|
-
args: [
|
|
63
|
+
args: [request.key, options]
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
if (operation === 'get') {
|
|
@@ -72,9 +72,9 @@ export var SQBAdapter;
|
|
|
72
72
|
};
|
|
73
73
|
return {
|
|
74
74
|
method: 'find',
|
|
75
|
-
key:
|
|
75
|
+
key: request.key,
|
|
76
76
|
options,
|
|
77
|
-
args: [
|
|
77
|
+
args: [request.key, options]
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
if (operation === 'findMany') {
|
|
@@ -83,25 +83,24 @@ export var SQBAdapter;
|
|
|
83
83
|
options,
|
|
84
84
|
args: [options]
|
|
85
85
|
};
|
|
86
|
-
|
|
87
|
-
out.count = args.count;
|
|
86
|
+
out.count = params?.count;
|
|
88
87
|
return out;
|
|
89
88
|
}
|
|
90
89
|
if (operation === 'updateMany' || (operation === 'update' && resource instanceof Singleton)) {
|
|
91
90
|
return {
|
|
92
91
|
method: 'updateMany',
|
|
93
|
-
data:
|
|
92
|
+
data: request.data,
|
|
94
93
|
options,
|
|
95
|
-
args: [
|
|
94
|
+
args: [request.data, options]
|
|
96
95
|
};
|
|
97
96
|
}
|
|
98
97
|
if (operation === 'update') {
|
|
99
98
|
return {
|
|
100
99
|
method: 'update',
|
|
101
|
-
key:
|
|
102
|
-
data:
|
|
100
|
+
key: request.key,
|
|
101
|
+
data: request.data,
|
|
103
102
|
options,
|
|
104
|
-
args: [
|
|
103
|
+
args: [request.key, request.data, options]
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
106
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Collection } from '@opra/common';
|
|
3
|
-
import {
|
|
3
|
+
import { OperationContext } from '@opra/core';
|
|
4
4
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
5
5
|
// noinspection TypeScriptAbstractClassConstructorCanBeMadeProtected
|
|
6
|
-
export class SqbCollectionResource
|
|
6
|
+
export class SqbCollectionResource {
|
|
7
7
|
constructor(options) {
|
|
8
|
-
|
|
8
|
+
this.defaultLimit = options?.defaultLimit || 100;
|
|
9
9
|
}
|
|
10
10
|
async create(ctx) {
|
|
11
11
|
const prepared = SQBAdapter.transformRequest(ctx.request);
|
|
@@ -22,7 +22,7 @@ export class SqbCollectionResource extends CollectionResourceBase {
|
|
|
22
22
|
const service = await this.getService(ctx);
|
|
23
23
|
return service.with(ctx).deleteMany(prepared.options);
|
|
24
24
|
}
|
|
25
|
-
async
|
|
25
|
+
async get(ctx) {
|
|
26
26
|
const prepared = SQBAdapter.transformRequest(ctx.request);
|
|
27
27
|
const service = await this.getService(ctx);
|
|
28
28
|
return service.with(ctx).find(prepared.key, prepared.options);
|
|
@@ -75,7 +75,7 @@ __decorate([
|
|
|
75
75
|
__metadata("design:type", Function),
|
|
76
76
|
__metadata("design:paramtypes", [Object]),
|
|
77
77
|
__metadata("design:returntype", Promise)
|
|
78
|
-
], SqbCollectionResource.prototype, "
|
|
78
|
+
], SqbCollectionResource.prototype, "get", null);
|
|
79
79
|
__decorate([
|
|
80
80
|
Collection.Update(),
|
|
81
81
|
__metadata("design:type", Function),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@opra/core": "^0.
|
|
40
|
+
"@opra/core": "^0.23.0",
|
|
41
41
|
"@sqb/connect": ">= 4.9.0"
|
|
42
42
|
},
|
|
43
43
|
"type": "module",
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
2
|
import { PartialOutput } from '@opra/common';
|
|
3
|
-
import {
|
|
3
|
+
import { OperationContext } from '@opra/core';
|
|
4
4
|
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
5
|
export declare namespace SqbCollectionResource {
|
|
6
|
-
interface Options
|
|
6
|
+
interface Options {
|
|
7
|
+
defaultLimit?: number;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
export declare abstract class SqbCollectionResource<T, TOutput = PartialOutput<T>>
|
|
10
|
+
export declare abstract class SqbCollectionResource<T, TOutput = PartialOutput<T>> {
|
|
11
|
+
defaultLimit?: number;
|
|
10
12
|
constructor(options?: SqbCollectionResource.Options);
|
|
11
|
-
create(ctx:
|
|
12
|
-
delete(ctx:
|
|
13
|
-
deleteMany(ctx:
|
|
14
|
-
|
|
15
|
-
update(ctx:
|
|
16
|
-
updateMany(ctx:
|
|
17
|
-
findMany(ctx:
|
|
18
|
-
abstract getService(ctx:
|
|
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>>;
|
|
19
21
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Maybe, Type } from 'ts-gems';
|
|
2
|
-
import { PartialInput, PartialOutput
|
|
2
|
+
import { OperationContext, 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: OperationContext;
|
|
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: OperationContext, 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>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Maybe } from 'ts-gems';
|
|
2
2
|
import { PartialOutput } from '@opra/common';
|
|
3
|
-
import {
|
|
3
|
+
import { OperationContext } from '@opra/core';
|
|
4
4
|
import { SqbEntityService } from './sqb-entity-service.js';
|
|
5
5
|
export declare abstract class SqbSingletonResource<T> {
|
|
6
|
-
create(ctx:
|
|
7
|
-
delete(ctx:
|
|
8
|
-
get(ctx:
|
|
9
|
-
update(ctx:
|
|
10
|
-
abstract getService(req:
|
|
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
11
|
}
|