@opra/sqb 1.0.0-alpha.32 → 1.0.0-alpha.34
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/sqb-entity-service.js +16 -2
- package/esm/package.json +3 -0
- package/esm/sqb-entity-service.js +16 -2
- package/package.json +25 -36
- package/types/sqb-entity-service.d.ts +8 -13
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SqbEntityService = void 0;
|
|
4
4
|
const common_1 = require("@opra/common");
|
|
5
5
|
const core_1 = require("@opra/core");
|
|
6
|
+
const builder_1 = require("@sqb/builder");
|
|
6
7
|
const connect_1 = require("@sqb/connect");
|
|
7
8
|
const valgen_1 = require("valgen");
|
|
8
9
|
const sqb_adapter_js_1 = require("./sqb-adapter.js");
|
|
@@ -63,6 +64,17 @@ class SqbEntityService extends core_1.ServiceBase {
|
|
|
63
64
|
}
|
|
64
65
|
return this._entityMetadata;
|
|
65
66
|
}
|
|
67
|
+
for(context, overwriteProperties, overwriteContext) {
|
|
68
|
+
if (overwriteProperties?.commonFilter && this.commonFilter) {
|
|
69
|
+
overwriteProperties.commonFilter = [
|
|
70
|
+
...(Array.isArray(this.commonFilter) ? this.commonFilter : [this.commonFilter]),
|
|
71
|
+
...(Array.isArray(overwriteProperties?.commonFilter)
|
|
72
|
+
? overwriteProperties?.commonFilter
|
|
73
|
+
: [overwriteProperties?.commonFilter]),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
return super.for(context, overwriteProperties, overwriteContext);
|
|
77
|
+
}
|
|
66
78
|
/**
|
|
67
79
|
* Retrieves the resource name.
|
|
68
80
|
*
|
|
@@ -444,8 +456,10 @@ class SqbEntityService extends core_1.ServiceBase {
|
|
|
444
456
|
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
445
457
|
* that resolves to the common filter, or undefined if not available.
|
|
446
458
|
*/
|
|
447
|
-
_getCommonFilter(
|
|
448
|
-
|
|
459
|
+
_getCommonFilter(command) {
|
|
460
|
+
const commonFilter = Array.isArray(this.commonFilter) ? this.commonFilter : [this.commonFilter];
|
|
461
|
+
const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
|
|
462
|
+
return mapped.length > 1 ? builder_1.op.and(...mapped) : mapped[0];
|
|
449
463
|
}
|
|
450
464
|
async _executeCommand(command, commandFn) {
|
|
451
465
|
let proto;
|
package/esm/package.json
ADDED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InternalServerError } from '@opra/common';
|
|
2
2
|
import { ServiceBase } from '@opra/core';
|
|
3
|
+
import { op } from '@sqb/builder';
|
|
3
4
|
import { EntityMetadata } from '@sqb/connect';
|
|
4
5
|
import { isNotNullish } from 'valgen';
|
|
5
6
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
@@ -60,6 +61,17 @@ export class SqbEntityService extends ServiceBase {
|
|
|
60
61
|
}
|
|
61
62
|
return this._entityMetadata;
|
|
62
63
|
}
|
|
64
|
+
for(context, overwriteProperties, overwriteContext) {
|
|
65
|
+
if (overwriteProperties?.commonFilter && this.commonFilter) {
|
|
66
|
+
overwriteProperties.commonFilter = [
|
|
67
|
+
...(Array.isArray(this.commonFilter) ? this.commonFilter : [this.commonFilter]),
|
|
68
|
+
...(Array.isArray(overwriteProperties?.commonFilter)
|
|
69
|
+
? overwriteProperties?.commonFilter
|
|
70
|
+
: [overwriteProperties?.commonFilter]),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
return super.for(context, overwriteProperties, overwriteContext);
|
|
74
|
+
}
|
|
63
75
|
/**
|
|
64
76
|
* Retrieves the resource name.
|
|
65
77
|
*
|
|
@@ -441,8 +453,10 @@ export class SqbEntityService extends ServiceBase {
|
|
|
441
453
|
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
442
454
|
* that resolves to the common filter, or undefined if not available.
|
|
443
455
|
*/
|
|
444
|
-
_getCommonFilter(
|
|
445
|
-
|
|
456
|
+
_getCommonFilter(command) {
|
|
457
|
+
const commonFilter = Array.isArray(this.commonFilter) ? this.commonFilter : [this.commonFilter];
|
|
458
|
+
const mapped = commonFilter.map(f => (typeof f === 'function' ? f(command, this) : f));
|
|
459
|
+
return mapped.length > 1 ? op.and(...mapped) : mapped[0];
|
|
446
460
|
}
|
|
447
461
|
async _executeCommand(command, commandFn) {
|
|
448
462
|
let proto;
|
package/package.json
CHANGED
|
@@ -1,52 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/sqb",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.34",
|
|
4
4
|
"description": "Opra SQB adapter package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/panates/opra.git",
|
|
10
|
-
"directory": "packages/sqb"
|
|
11
|
-
},
|
|
12
|
-
"scripts": {
|
|
13
|
-
"compile": "tsc",
|
|
14
|
-
"prebuild": "npm run lint && npm run clean",
|
|
15
|
-
"build": "npm run build:cjs && npm run build:esm",
|
|
16
|
-
"build:cjs": "tsc -b tsconfig-build-cjs.json",
|
|
17
|
-
"build:esm": "tsc -b tsconfig-build-esm.json",
|
|
18
|
-
"postbuild": "cp README.md package.json ../../LICENSE ../../build/sqb && cp ../../package.cjs.json ../../build/sqb/cjs/package.json",
|
|
19
|
-
"lint": "eslint . --max-warnings=0",
|
|
20
|
-
"lint:fix": "eslint . --max-warnings=0 --fix",
|
|
21
|
-
"format": "prettier . --write --log-level=warn",
|
|
22
|
-
"test": "jest --passWithNoTests",
|
|
23
|
-
"cover": "jest --passWithNoTests --collect-coverage",
|
|
24
|
-
"clean": "npm run clean:src && npm run clean:test && npm run clean:dist && npm run clean:cover",
|
|
25
|
-
"clean:src": "ts-cleanup -s src --all",
|
|
26
|
-
"clean:test": "ts-cleanup -s test --all",
|
|
27
|
-
"clean:dist": "rimraf ../../build/client",
|
|
28
|
-
"clean:cover": "rimraf ../../coverage/client"
|
|
29
|
-
},
|
|
30
7
|
"dependencies": {
|
|
31
8
|
"reflect-metadata": "^0.2.2",
|
|
32
|
-
"tslib": "^2.6.3"
|
|
33
|
-
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@faker-js/faker": "^8.4.1",
|
|
36
|
-
"@sqb/builder": "^4.14.1",
|
|
37
|
-
"@sqb/connect": "^4.14.1",
|
|
38
|
-
"@sqb/postgres": "^4.14.1",
|
|
39
|
-
"postgrejs": "^2.15.4",
|
|
40
|
-
"ts-gems": "^3.4.0"
|
|
9
|
+
"tslib": "^2.6.3",
|
|
10
|
+
"valgen": "^5.8.2"
|
|
41
11
|
},
|
|
42
12
|
"peerDependencies": {
|
|
43
|
-
"@opra/core": "^1.0.0-alpha.
|
|
13
|
+
"@opra/core": "^1.0.0-alpha.34",
|
|
44
14
|
"@sqb/connect": ">= 4.10.6"
|
|
45
15
|
},
|
|
46
16
|
"type": "module",
|
|
47
|
-
"
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"import": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"default": "./esm/index.js"
|
|
22
|
+
},
|
|
23
|
+
"require": {
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"default": "./cjs/index.js"
|
|
26
|
+
},
|
|
27
|
+
"default": "./esm/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
48
31
|
"main": "./cjs/index.js",
|
|
32
|
+
"module": "./esm/index.js",
|
|
49
33
|
"types": "./types/index.d.ts",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/panates/opra.git",
|
|
37
|
+
"directory": "packages/sqb"
|
|
38
|
+
},
|
|
50
39
|
"engines": {
|
|
51
40
|
"node": ">=16.0",
|
|
52
41
|
"npm": ">=7.0.0"
|
|
@@ -64,4 +53,4 @@
|
|
|
64
53
|
"sqb",
|
|
65
54
|
"adapter"
|
|
66
55
|
]
|
|
67
|
-
}
|
|
56
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ComplexType } from '@opra/common';
|
|
2
|
-
import { ServiceBase } from '@opra/core';
|
|
2
|
+
import { HttpContext, ServiceBase } from '@opra/core';
|
|
3
3
|
import { EntityMetadata, Repository, SqbClient, SqbConnection } from '@sqb/connect';
|
|
4
|
-
import { PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
|
|
4
|
+
import { Nullish, PartialDTO, PatchDTO, RequiredSome, StrictOmit, Type } from 'ts-gems';
|
|
5
5
|
import { IsObject } from 'valgen';
|
|
6
6
|
import { SQBAdapter } from './sqb-adapter.js';
|
|
7
7
|
/**
|
|
@@ -24,6 +24,7 @@ export declare namespace SqbEntityService {
|
|
|
24
24
|
input?: Record<string, any>;
|
|
25
25
|
options?: Record<string, any>;
|
|
26
26
|
}
|
|
27
|
+
type CommonFilter = SQBAdapter.FilterInput | ((args: SqbEntityService.CommandInfo, _this: SqbEntityService<any>) => SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined);
|
|
27
28
|
/**
|
|
28
29
|
* Represents options for "create" operation
|
|
29
30
|
*
|
|
@@ -158,18 +159,18 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
158
159
|
/**
|
|
159
160
|
* Represents a SqbClient or SqbConnection object
|
|
160
161
|
*/
|
|
161
|
-
db?: (SqbClient | SqbConnection) | ((_this:
|
|
162
|
+
db?: (SqbClient | SqbConnection) | ((_this: this) => SqbClient | SqbConnection);
|
|
162
163
|
/**
|
|
163
164
|
* Represents the name of a resource.
|
|
164
165
|
* @type {string}
|
|
165
166
|
*/
|
|
166
|
-
resourceName?: string | ((_this:
|
|
167
|
+
resourceName?: string | ((_this: this) => string);
|
|
167
168
|
/**
|
|
168
169
|
* Represents a common filter function for a service.
|
|
169
170
|
*
|
|
170
171
|
* @type {SqbEntityService.Filter | Function}
|
|
171
172
|
*/
|
|
172
|
-
commonFilter?:
|
|
173
|
+
commonFilter?: SqbEntityService.CommonFilter | SqbEntityService.CommonFilter[];
|
|
173
174
|
/**
|
|
174
175
|
* Callback function for handling errors.
|
|
175
176
|
*
|
|
@@ -203,6 +204,7 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
203
204
|
* @throws {TypeError} If metadata is not available
|
|
204
205
|
*/
|
|
205
206
|
get entityMetadata(): EntityMetadata;
|
|
207
|
+
for<C extends HttpContext, P extends Partial<this>>(context: C, overwriteProperties?: Nullish<P>, overwriteContext?: Partial<C>): this & Required<P>;
|
|
206
208
|
/**
|
|
207
209
|
* Retrieves the resource name.
|
|
208
210
|
*
|
|
@@ -424,13 +426,6 @@ export declare class SqbEntityService<T extends object = object> extends Service
|
|
|
424
426
|
* @returns {FilterInput | Promise<FilterInput> | undefined} The common filter or a Promise
|
|
425
427
|
* that resolves to the common filter, or undefined if not available.
|
|
426
428
|
*/
|
|
427
|
-
protected _getCommonFilter(
|
|
428
|
-
crud: SqbEntityService.CrudOp;
|
|
429
|
-
method: string;
|
|
430
|
-
byId: boolean;
|
|
431
|
-
documentId?: SQBAdapter.IdOrIds;
|
|
432
|
-
input?: Object;
|
|
433
|
-
options?: Record<string, any>;
|
|
434
|
-
}): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
|
|
429
|
+
protected _getCommonFilter(command: SqbEntityService.CommandInfo): SQBAdapter.FilterInput | Promise<SQBAdapter.FilterInput> | undefined;
|
|
435
430
|
protected _executeCommand(command: SqbEntityService.CommandInfo, commandFn: () => any): Promise<any>;
|
|
436
431
|
}
|