@tsed/adapters 8.28.7 → 8.29.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/lib/esm/adapters/FileSyncAdapter.js +4 -5
- package/lib/esm/adapters/LowDbAdapter.js +2 -1
- package/lib/esm/adapters/MemoryAdapter.js +4 -5
- package/lib/esm/domain/Adapter.js +5 -10
- package/lib/types/adapters/FileSyncAdapter.d.ts +1 -2
- package/lib/types/adapters/MemoryAdapter.d.ts +1 -2
- package/lib/types/domain/Adapter.d.ts +1 -3
- package/package.json +9 -9
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { nameOf } from "@tsed/core";
|
|
4
|
-
import {
|
|
4
|
+
import { Injectable, Opts, ProviderScope, Scope } from "@tsed/di";
|
|
5
5
|
import fs from "fs-extra";
|
|
6
6
|
import { LowSync } from "lowdb";
|
|
7
7
|
import { JSONFileSync } from "lowdb/node";
|
|
8
8
|
import { LowDbAdapter } from "./LowDbAdapter.js";
|
|
9
9
|
let FileSyncAdapter = class FileSyncAdapter extends LowDbAdapter {
|
|
10
|
-
constructor(options
|
|
11
|
-
super(options
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options);
|
|
12
12
|
fs.ensureDirSync(dirname(this.dbFilePath));
|
|
13
13
|
const file = new JSONFileSync(this.dbFilePath);
|
|
14
14
|
this.db = new LowSync(file, {
|
|
@@ -26,7 +26,6 @@ FileSyncAdapter = __decorate([
|
|
|
26
26
|
Injectable(),
|
|
27
27
|
Scope(ProviderScope.INSTANCE),
|
|
28
28
|
__param(0, Opts),
|
|
29
|
-
|
|
30
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
29
|
+
__metadata("design:paramtypes", [Object])
|
|
31
30
|
], FileSyncAdapter);
|
|
32
31
|
export { FileSyncAdapter };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cleanObject } from "@tsed/core";
|
|
2
|
+
import { constant } from "@tsed/di";
|
|
2
3
|
import _ from "lodash";
|
|
3
4
|
import isMatch from "lodash/isMatch.js";
|
|
4
5
|
import { v4 as uuid } from "uuid";
|
|
@@ -8,7 +9,7 @@ export class LowDbAdapter extends Adapter {
|
|
|
8
9
|
return this.db.data.collection;
|
|
9
10
|
}
|
|
10
11
|
get dbFilePath() {
|
|
11
|
-
const lowdbDir =
|
|
12
|
+
const lowdbDir = constant("adapters.lowdbDir", ".db");
|
|
12
13
|
return `${lowdbDir}/${this.collectionName}.json`;
|
|
13
14
|
}
|
|
14
15
|
async create(payload, expiresAt) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
-
import {
|
|
2
|
+
import { Injectable, Opts, ProviderScope, Scope } from "@tsed/di";
|
|
3
3
|
import { Low, Memory } from "lowdb";
|
|
4
4
|
import { LowDbAdapter } from "./LowDbAdapter.js";
|
|
5
5
|
let MemoryAdapter = class MemoryAdapter extends LowDbAdapter {
|
|
6
|
-
constructor(options
|
|
7
|
-
super(options
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
8
|
this.db = new Low(new Memory(), {
|
|
9
9
|
collection: []
|
|
10
10
|
});
|
|
@@ -17,7 +17,6 @@ MemoryAdapter = __decorate([
|
|
|
17
17
|
Injectable(),
|
|
18
18
|
Scope(ProviderScope.INSTANCE),
|
|
19
19
|
__param(0, Opts),
|
|
20
|
-
|
|
21
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
20
|
+
__metadata("design:paramtypes", [Object])
|
|
22
21
|
], MemoryAdapter);
|
|
23
22
|
export { MemoryAdapter };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { AjvService } from "@tsed/ajv";
|
|
3
3
|
import { classOf, isArray, isPlainObject, nameOf } from "@tsed/core";
|
|
4
|
-
import {
|
|
4
|
+
import { constant, inject, Opts } from "@tsed/di";
|
|
5
5
|
import { deserialize, serialize } from "@tsed/json-mapper";
|
|
6
6
|
import { getPropertiesStores } from "@tsed/schema";
|
|
7
7
|
function getIndexes(model) {
|
|
@@ -26,12 +26,12 @@ function pluralize(name) {
|
|
|
26
26
|
return name.slice(-1) === "y" ? `${name.slice(0, name.length - 1)}ies` : name + "s";
|
|
27
27
|
}
|
|
28
28
|
let Adapter = class Adapter {
|
|
29
|
-
constructor(options
|
|
30
|
-
this.configuration = configuration;
|
|
29
|
+
constructor(options) {
|
|
31
30
|
this.useAlias = false;
|
|
31
|
+
this.ajvService = inject(AjvService);
|
|
32
32
|
this.model = options.model;
|
|
33
33
|
this.collectionName = options.collectionName || pluralize(nameOf(options.model));
|
|
34
|
-
let indexes = options.indexes ||
|
|
34
|
+
let indexes = options.indexes || constant(`adapters.${this.collectionName}.indexes`) || getIndexes(this.model);
|
|
35
35
|
if (!isArray(indexes)) {
|
|
36
36
|
indexes = mapIndexes(indexes);
|
|
37
37
|
}
|
|
@@ -64,13 +64,8 @@ let Adapter = class Adapter {
|
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
66
|
};
|
|
67
|
-
__decorate([
|
|
68
|
-
Inject(),
|
|
69
|
-
__metadata("design:type", AjvService)
|
|
70
|
-
], Adapter.prototype, "ajvService", void 0);
|
|
71
67
|
Adapter = __decorate([
|
|
72
68
|
__param(0, Opts),
|
|
73
|
-
|
|
74
|
-
__metadata("design:paramtypes", [Object, Object])
|
|
69
|
+
__metadata("design:paramtypes", [Object])
|
|
75
70
|
], Adapter);
|
|
76
71
|
export { Adapter };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Configuration } from "@tsed/di";
|
|
2
1
|
import { AdapterConstructorOptions } from "../domain/Adapter.js";
|
|
3
2
|
import { AdapterModel, LowDbAdapter } from "./LowDbAdapter.js";
|
|
4
3
|
export interface FileSyncAdapterConstructorOptions extends AdapterConstructorOptions {
|
|
5
4
|
readOnly: true;
|
|
6
5
|
}
|
|
7
6
|
export declare class FileSyncAdapter<T extends AdapterModel> extends LowDbAdapter<T> {
|
|
8
|
-
constructor(options: FileSyncAdapterConstructorOptions
|
|
7
|
+
constructor(options: FileSyncAdapterConstructorOptions);
|
|
9
8
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Configuration } from "@tsed/di";
|
|
2
1
|
import { AdapterModel, LowDbAdapter } from "./LowDbAdapter.js";
|
|
3
2
|
export declare class MemoryAdapter<T extends AdapterModel> extends LowDbAdapter<T> {
|
|
4
|
-
constructor(options: any
|
|
3
|
+
constructor(options: any);
|
|
5
4
|
$onInit(): void | Promise<void>;
|
|
6
5
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AjvService } from "@tsed/ajv";
|
|
2
2
|
import { Type } from "@tsed/core";
|
|
3
|
-
import { Configuration } from "@tsed/di";
|
|
4
3
|
import { JsonDeserializerOptions, JsonSerializerOptions } from "@tsed/json-mapper";
|
|
5
4
|
export interface AdapterConstructorOptions<T = any> extends Record<string, any> {
|
|
6
5
|
model: Type<T> | Object;
|
|
@@ -11,7 +10,6 @@ export interface AdapterConstructorOptions<T = any> extends Record<string, any>
|
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
export declare abstract class Adapter<Model = any> {
|
|
14
|
-
protected configuration: Configuration;
|
|
15
13
|
readonly model: Type<Model> | Object;
|
|
16
14
|
readonly collectionName: string;
|
|
17
15
|
readonly indexes: {
|
|
@@ -20,7 +18,7 @@ export declare abstract class Adapter<Model = any> {
|
|
|
20
18
|
}[];
|
|
21
19
|
readonly useAlias: boolean;
|
|
22
20
|
protected ajvService: AjvService;
|
|
23
|
-
constructor(options: AdapterConstructorOptions
|
|
21
|
+
constructor(options: AdapterConstructorOptions);
|
|
24
22
|
validate(value: Model): Promise<void>;
|
|
25
23
|
abstract create(value: Partial<Omit<Model, "_id">>, expiresAt?: Date): Promise<Model>;
|
|
26
24
|
abstract update(id: string, value: Model, expiresAt?: Date): Promise<Model | undefined>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/adapters",
|
|
3
3
|
"description": "Database adapters for Ts.ED",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.29.0",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"uuid": "^14.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@tsed/ajv": "8.
|
|
37
|
-
"@tsed/barrels": "8.
|
|
38
|
-
"@tsed/core": "8.
|
|
39
|
-
"@tsed/di": "8.
|
|
40
|
-
"@tsed/json-mapper": "8.
|
|
41
|
-
"@tsed/platform-http": "8.
|
|
42
|
-
"@tsed/schema": "8.
|
|
43
|
-
"@tsed/typescript": "8.
|
|
36
|
+
"@tsed/ajv": "8.29.0",
|
|
37
|
+
"@tsed/barrels": "8.29.0",
|
|
38
|
+
"@tsed/core": "8.29.0",
|
|
39
|
+
"@tsed/di": "8.29.0",
|
|
40
|
+
"@tsed/json-mapper": "8.29.0",
|
|
41
|
+
"@tsed/platform-http": "8.29.0",
|
|
42
|
+
"@tsed/schema": "8.29.0",
|
|
43
|
+
"@tsed/typescript": "8.29.0",
|
|
44
44
|
"@types/fs-extra": "11.0.4",
|
|
45
45
|
"eslint": "9.12.0",
|
|
46
46
|
"typescript": "6.0.2",
|