@tsed/adapters 7.79.4 → 7.80.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.
@@ -0,0 +1,9 @@
1
+ import { Configuration } from "@tsed/di";
2
+ import { AdapterConstructorOptions } from "../domain/Adapter.js";
3
+ import { AdapterModel, LowDbAdapter } from "./LowDbAdapter.js";
4
+ export interface FileSyncAdapterConstructorOptions extends AdapterConstructorOptions {
5
+ readOnly: true;
6
+ }
7
+ export declare class FileSyncAdapter<T extends AdapterModel> extends LowDbAdapter<T> {
8
+ constructor(options: FileSyncAdapterConstructorOptions, configuration: Configuration);
9
+ }
@@ -0,0 +1,31 @@
1
+ /// <reference types="lodash" />
2
+ /// <reference types="lodash" />
3
+ /// <reference types="lodash" />
4
+ /// <reference types="lodash" />
5
+ /// <reference types="lodash" />
6
+ /// <reference types="lodash" />
7
+ /// <reference types="lodash" />
8
+ import low from "lowdb";
9
+ import { Adapter } from "../domain/Adapter.js";
10
+ export interface AdapterModel {
11
+ _id: string;
12
+ expires_at?: Date;
13
+ [key: string]: any;
14
+ }
15
+ export declare class LowDbAdapter<T extends AdapterModel> extends Adapter<T> {
16
+ protected db: low.LowdbSync<{
17
+ collection: T[];
18
+ }>;
19
+ get collection(): import("lodash").CollectionChain<T>;
20
+ protected get dbFilePath(): string;
21
+ create(payload: Partial<T>, expiresAt?: Date): Promise<T>;
22
+ upsert(id: string, payload: T, expiresAt?: Date): Promise<T>;
23
+ update(id: string, payload: T, expiresAt?: Date): Promise<T | undefined>;
24
+ updateOne(predicate: Partial<T & any>, payload: T, expiresAt?: Date): Promise<T | undefined>;
25
+ findOne(predicate: Partial<T & any>): Promise<T | undefined>;
26
+ findById(_id: string): Promise<T | undefined>;
27
+ findAll(predicate?: Partial<T & any>): Promise<T[]>;
28
+ deleteOne(predicate: Partial<T & any>): Promise<T | undefined>;
29
+ deleteById(_id: string): Promise<T | undefined>;
30
+ deleteMany(predicate: Partial<T>): Promise<T[]>;
31
+ }
@@ -0,0 +1,5 @@
1
+ import { Configuration } from "@tsed/di";
2
+ import { AdapterModel, LowDbAdapter } from "./LowDbAdapter.js";
3
+ export declare class MemoryAdapter<T extends AdapterModel> extends LowDbAdapter<T> {
4
+ constructor(options: any, configuration: Configuration);
5
+ }
@@ -0,0 +1 @@
1
+ export declare function Indexed(): PropertyDecorator;
@@ -0,0 +1,5 @@
1
+ import { Type } from "@tsed/core";
2
+ import { AdapterInvokeOptions } from "../services/Adapters.js";
3
+ export declare function InjectAdapter(options: AdapterInvokeOptions): PropertyDecorator;
4
+ export declare function InjectAdapter(model: Type<any>, options?: Partial<Omit<AdapterInvokeOptions, "client">>): PropertyDecorator;
5
+ export declare function InjectAdapter(collectionName: string, model: Type<any>, options?: Partial<Omit<AdapterInvokeOptions, "collectionName" | "client">>): PropertyDecorator;
@@ -0,0 +1,38 @@
1
+ import { AjvService } from "@tsed/ajv";
2
+ import { Type } from "@tsed/core";
3
+ import { Configuration } from "@tsed/di";
4
+ import { JsonDeserializerOptions, JsonSerializerOptions } from "@tsed/json-mapper";
5
+ export interface AdapterConstructorOptions<T = any> extends Record<string, any> {
6
+ model: Type<T> | Object;
7
+ collectionName?: string;
8
+ useAlias?: string;
9
+ indexes?: {
10
+ [propertyKey: string]: Record<string, any>;
11
+ };
12
+ }
13
+ export declare abstract class Adapter<Model = any> {
14
+ protected configuration: Configuration;
15
+ readonly model: Type<Model> | Object;
16
+ readonly collectionName: string;
17
+ readonly indexes: {
18
+ propertyKey: string;
19
+ options: any;
20
+ }[];
21
+ readonly useAlias: boolean;
22
+ protected ajvService: AjvService;
23
+ constructor(options: AdapterConstructorOptions, configuration: Configuration);
24
+ validate(value: Model): Promise<void>;
25
+ abstract create(value: Partial<Omit<Model, "_id">>, expiresAt?: Date): Promise<Model>;
26
+ abstract update(id: string, value: Model, expiresAt?: Date): Promise<Model | undefined>;
27
+ abstract updateOne(predicate: Partial<Model>, value: Partial<Model>, expiresAt?: Date): Promise<Model | undefined>;
28
+ abstract upsert(id: string, value: Model, expiresAt?: Date): Promise<Model>;
29
+ abstract findOne(predicate: Partial<Model>): Promise<Model | undefined>;
30
+ abstract findById(id: string): Promise<Model | undefined>;
31
+ abstract findAll(predicate?: Partial<Model>): Promise<Model[]>;
32
+ abstract deleteOne(predicate: Partial<Model>): Promise<Model | undefined>;
33
+ abstract deleteMany(predicate: Partial<Model>): Promise<Model[]>;
34
+ abstract deleteById(id: string): Promise<Model | undefined>;
35
+ getModel(): Object | undefined;
36
+ protected deserialize(obj: any, opts?: JsonDeserializerOptions): any;
37
+ protected serialize(obj: any, opts?: JsonSerializerOptions): any;
38
+ }
@@ -0,0 +1,24 @@
1
+ import { Type } from "@tsed/core";
2
+ import { Adapter } from "./Adapter.js";
3
+ export interface AdaptersSettings {
4
+ /**
5
+ * Injectable service to manage database connexion
6
+ */
7
+ Adapter?: Type<Adapter>;
8
+ /**
9
+ *
10
+ */
11
+ lowdbDir?: string;
12
+ /**
13
+ * Use the connection name for the RedisAdapter.
14
+ */
15
+ connectionName?: string;
16
+ [key: string]: any;
17
+ }
18
+ declare global {
19
+ namespace TsED {
20
+ interface Configuration {
21
+ adapters: AdaptersSettings;
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./adapters/FileSyncAdapter.js";
5
+ export * from "./adapters/LowDbAdapter.js";
6
+ export * from "./adapters/MemoryAdapter.js";
7
+ export * from "./decorators/indexed.js";
8
+ export * from "./decorators/injectAdapter.js";
9
+ export * from "./domain/Adapter.js";
10
+ export * from "./domain/AdaptersSettings.js";
11
+ export * from "./services/Adapters.js";
@@ -0,0 +1,11 @@
1
+ import { Type } from "@tsed/core";
2
+ import { InjectorService } from "@tsed/di";
3
+ import { Adapter, AdapterConstructorOptions } from "../domain/Adapter.js";
4
+ export interface AdapterInvokeOptions<T = any> extends AdapterConstructorOptions<T> {
5
+ adapter?: Type<Adapter<T>>;
6
+ }
7
+ export declare class Adapters {
8
+ injector: InjectorService;
9
+ protected adapter: Type<Adapter>;
10
+ invokeAdapter<T = any>(options: AdapterInvokeOptions): Adapter<T>;
11
+ }
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "@tsed/adapters",
3
- "version": "7.79.4",
4
3
  "description": "Database adapters for Ts.ED",
4
+ "type": "commonjs",
5
+ "version": "7.80.0",
5
6
  "source": "./src/index.ts",
6
7
  "main": "./lib/cjs/index.js",
7
8
  "module": "./lib/esm/index.js",
8
9
  "typings": "./lib/types/index.d.ts",
9
10
  "exports": {
10
- "types": "./lib/types/index.d.ts",
11
- "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js",
13
- "default": "./lib/esm/index.js"
11
+ ".": {
12
+ "types": "./lib/types/index.d.ts",
13
+ "import": "./lib/esm/index.js",
14
+ "default": "./lib/cjs/index.js"
15
+ }
14
16
  },
15
17
  "scripts": {
16
18
  "build": "yarn barrels && yarn build:ts",
17
19
  "barrels": "barrels",
18
- "test": "jest && jest-coverage-thresholds-bumper",
19
- "build:ts": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json"
20
+ "test": "vitest run",
21
+ "build:ts": "tsc --build tsconfig.json",
22
+ "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
20
23
  },
21
24
  "dependencies": {
22
25
  "@types/lowdb": "1.0.15",
@@ -29,25 +32,26 @@
29
32
  "uuid": "9.0.1"
30
33
  },
31
34
  "devDependencies": {
32
- "@tsed/ajv": "7.79.4",
33
- "@tsed/barrels": "7.79.4",
34
- "@tsed/common": "7.79.4",
35
- "@tsed/core": "7.79.4",
36
- "@tsed/di": "7.79.4",
37
- "@tsed/json-mapper": "7.79.4",
38
- "@tsed/schema": "7.79.4",
39
- "@tsed/typescript": "7.79.4",
35
+ "@tsed/ajv": "7.80.0",
36
+ "@tsed/barrels": "7.80.0",
37
+ "@tsed/common": "7.80.0",
38
+ "@tsed/core": "7.80.0",
39
+ "@tsed/di": "7.80.0",
40
+ "@tsed/json-mapper": "7.80.0",
41
+ "@tsed/schema": "7.80.0",
42
+ "@tsed/typescript": "7.80.0",
40
43
  "@types/fs-extra": "11.0.4",
41
44
  "eslint": "^8.57.0",
42
- "jest": "^29.7.0"
45
+ "typescript": "4.9.5",
46
+ "vitest": "2.0.4"
43
47
  },
44
48
  "peerDependencies": {
45
- "@tsed/ajv": "7.79.4",
46
- "@tsed/common": "7.79.4",
47
- "@tsed/core": "7.79.4",
48
- "@tsed/di": "7.79.4",
49
- "@tsed/json-mapper": "7.79.4",
50
- "@tsed/schema": "7.79.4"
49
+ "@tsed/ajv": "7.80.0",
50
+ "@tsed/common": "7.80.0",
51
+ "@tsed/core": "7.80.0",
52
+ "@tsed/di": "7.80.0",
53
+ "@tsed/json-mapper": "7.80.0",
54
+ "@tsed/schema": "7.80.0"
51
55
  },
52
56
  "peerDependenciesMeta": {
53
57
  "@tsed/ajv": {
@@ -0,0 +1,21 @@
1
+ // @ts-ignore
2
+ import {presets} from "@tsed/vitest/presets";
3
+ import {defineConfig} from "vitest/config";
4
+
5
+ export default defineConfig(
6
+ {
7
+ ...presets,
8
+ test: {
9
+ ...presets.test,
10
+ coverage: {
11
+ ...presets.test.coverage,
12
+ thresholds: {
13
+ statements: 0,
14
+ branches: 0,
15
+ functions: 0,
16
+ lines: 0
17
+ }
18
+ }
19
+ }
20
+ }
21
+ );
package/jest.config.js DELETED
@@ -1,20 +0,0 @@
1
- // For a detailed explanation regarding each configuration property, visit:
2
- // https://jestjs.io/docs/en/configuration.html
3
- const config = require("@tsed/jest-config");
4
-
5
- module.exports = {
6
- ...config,
7
- roots: ["<rootDir>/src", "<rootDir>/test"],
8
- moduleNameMapper: {
9
- ...config.moduleNameMapper,
10
- "@tsed/adapters": "<rootDir>/src/index.ts"
11
- },
12
- coverageThreshold: {
13
- global: {
14
- branches: 88.6,
15
- functions: 100,
16
- lines: 100,
17
- statements: 100
18
- }
19
- }
20
- };
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
package/tsconfig.esm.json DELETED
@@ -1,48 +0,0 @@
1
- {
2
- "extends": "@tsed/typescript/tsconfig.node.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "module": "ES2020",
6
- "rootDir": "src",
7
- "outDir": "./lib/esm",
8
- "declaration": true,
9
- "declarationDir": "./lib/types",
10
- "composite": true,
11
- "noEmit": false
12
- },
13
- "include": ["src", "src/**/*.json"],
14
- "exclude": [
15
- "node_modules",
16
- "test",
17
- "lib",
18
- "benchmark",
19
- "coverage",
20
- "spec",
21
- "**/*.benchmark.ts",
22
- "**/*.spec.ts",
23
- "keys",
24
- "jest.config.js",
25
- "**/__mock__/**",
26
- "webpack.config.js"
27
- ],
28
- "references": [
29
- {
30
- "path": "../../specs/ajv"
31
- },
32
- {
33
- "path": "../../platform/common"
34
- },
35
- {
36
- "path": "../../core"
37
- },
38
- {
39
- "path": "../../di"
40
- },
41
- {
42
- "path": "../../specs/json-mapper"
43
- },
44
- {
45
- "path": "../../specs/schema"
46
- }
47
- ]
48
- }