@decaf-ts/core 0.5.0 → 0.5.2
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/LICENSE.md +21 -157
- package/README.md +652 -15
- package/dist/core.cjs +2638 -1085
- package/dist/core.esm.cjs +2636 -1070
- package/lib/esm/identity/decorators.d.ts +52 -14
- package/lib/esm/identity/decorators.js +54 -16
- package/lib/esm/identity/utils.d.ts +20 -1
- package/lib/esm/identity/utils.js +22 -2
- package/lib/esm/index.d.ts +11 -15
- package/lib/esm/index.js +17 -19
- package/lib/esm/interfaces/ErrorParser.d.ts +12 -0
- package/lib/esm/interfaces/ErrorParser.js +1 -1
- package/lib/esm/interfaces/Executor.d.ts +10 -13
- package/lib/esm/interfaces/Executor.js +1 -1
- package/lib/esm/interfaces/Observable.d.ts +20 -18
- package/lib/esm/interfaces/Observable.js +1 -1
- package/lib/esm/interfaces/Observer.d.ts +7 -8
- package/lib/esm/interfaces/Observer.js +1 -1
- package/lib/esm/interfaces/Paginatable.d.ts +18 -2
- package/lib/esm/interfaces/Paginatable.js +1 -1
- package/lib/esm/interfaces/Queriable.d.ts +44 -3
- package/lib/esm/interfaces/Queriable.js +1 -1
- package/lib/esm/interfaces/RawExecutor.d.ts +10 -13
- package/lib/esm/interfaces/RawExecutor.js +1 -1
- package/lib/esm/interfaces/SequenceOptions.d.ts +50 -5
- package/lib/esm/interfaces/SequenceOptions.js +19 -1
- package/lib/esm/interfaces/index.d.ts +0 -1
- package/lib/esm/interfaces/index.js +1 -2
- package/lib/esm/model/BaseModel.d.ts +31 -0
- package/lib/esm/model/BaseModel.js +24 -1
- package/lib/esm/model/construction.d.ts +442 -9
- package/lib/esm/model/construction.js +441 -2
- package/lib/esm/model/decorators.d.ts +166 -42
- package/lib/esm/model/decorators.js +161 -37
- package/lib/esm/model/index.js +1 -2
- package/lib/esm/model/types.d.ts +9 -0
- package/lib/esm/model/types.js +1 -1
- package/lib/esm/persistence/Adapter.d.ts +384 -40
- package/lib/esm/persistence/Adapter.js +415 -59
- package/lib/esm/persistence/Dispatch.d.ts +131 -0
- package/lib/esm/persistence/Dispatch.js +187 -0
- package/lib/esm/persistence/ObserverHandler.d.ts +109 -0
- package/lib/esm/persistence/ObserverHandler.js +137 -0
- package/lib/esm/persistence/Sequence.d.ts +89 -8
- package/lib/esm/persistence/Sequence.js +91 -1
- package/lib/esm/persistence/constants.d.ts +22 -5
- package/lib/esm/persistence/constants.js +23 -7
- package/lib/esm/persistence/decorators.d.ts +10 -0
- package/lib/esm/persistence/decorators.js +11 -1
- package/lib/esm/persistence/errors.d.ts +23 -3
- package/lib/esm/persistence/errors.js +25 -7
- package/lib/esm/persistence/index.d.ts +3 -0
- package/lib/esm/persistence/index.js +4 -1
- package/lib/esm/persistence/types.d.ts +21 -0
- package/lib/esm/persistence/types.js +2 -0
- package/lib/esm/query/Condition.d.ts +88 -44
- package/lib/esm/query/Condition.js +144 -62
- package/lib/esm/query/Paginator.d.ts +67 -10
- package/lib/esm/query/Paginator.js +64 -10
- package/lib/esm/query/Statement.d.ts +82 -47
- package/lib/esm/query/Statement.js +175 -122
- package/lib/esm/query/constants.d.ts +25 -64
- package/lib/esm/query/constants.js +26 -68
- package/lib/esm/query/errors.d.ts +14 -0
- package/lib/esm/query/errors.js +15 -1
- package/lib/esm/query/index.d.ts +0 -5
- package/lib/esm/query/index.js +1 -6
- package/lib/esm/query/options.d.ts +69 -178
- package/lib/esm/query/options.js +1 -1
- package/lib/esm/query/selectors.d.ts +20 -24
- package/lib/esm/query/selectors.js +1 -1
- package/lib/esm/ram/RamAdapter.d.ts +322 -20
- package/lib/esm/ram/RamAdapter.js +360 -140
- package/lib/esm/ram/RamContext.d.ts +16 -1
- package/lib/esm/ram/RamContext.js +18 -3
- package/lib/esm/ram/RamPaginator.d.ts +51 -6
- package/lib/esm/ram/RamPaginator.js +58 -6
- package/lib/esm/ram/RamSequence.d.ts +49 -24
- package/lib/esm/ram/RamSequence.js +52 -40
- package/lib/esm/ram/RamStatement.d.ts +84 -6
- package/lib/esm/ram/RamStatement.js +175 -6
- package/lib/esm/ram/constants.d.ts +9 -0
- package/lib/esm/ram/constants.js +10 -0
- package/lib/esm/ram/handlers.d.ts +25 -0
- package/lib/esm/ram/handlers.js +27 -0
- package/lib/esm/ram/index.d.ts +4 -4
- package/lib/esm/ram/index.js +9 -5
- package/lib/esm/ram/model/RamSequence.d.ts +21 -9
- package/lib/esm/ram/model/RamSequence.js +19 -1
- package/lib/esm/ram/types.d.ts +47 -5
- package/lib/esm/ram/types.js +1 -1
- package/lib/esm/repository/Repository.d.ts +381 -22
- package/lib/esm/repository/Repository.js +446 -43
- package/lib/esm/repository/constants.d.ts +23 -13
- package/lib/esm/repository/constants.js +24 -14
- package/lib/esm/repository/decorators.d.ts +27 -0
- package/lib/esm/repository/decorators.js +28 -1
- package/lib/esm/repository/errors.d.ts +12 -11
- package/lib/esm/repository/errors.js +13 -16
- package/lib/esm/repository/injectables.d.ts +18 -0
- package/lib/esm/repository/injectables.js +19 -1
- package/lib/esm/repository/types.d.ts +13 -1
- package/lib/esm/repository/types.js +1 -1
- package/lib/esm/repository/utils.d.ts +11 -0
- package/lib/esm/repository/utils.js +12 -1
- package/lib/esm/utils/decorators.d.ts +9 -0
- package/lib/esm/utils/decorators.js +19 -0
- package/lib/esm/utils/errors.d.ts +56 -0
- package/lib/esm/utils/errors.js +63 -0
- package/lib/esm/utils/index.d.ts +2 -0
- package/lib/esm/utils/index.js +3 -0
- package/lib/identity/decorators.cjs +54 -16
- package/lib/identity/decorators.d.ts +52 -14
- package/lib/identity/utils.cjs +22 -2
- package/lib/identity/utils.d.ts +20 -1
- package/lib/index.cjs +17 -19
- package/lib/index.d.ts +11 -15
- package/lib/interfaces/ErrorParser.cjs +1 -1
- package/lib/interfaces/ErrorParser.d.ts +12 -0
- package/lib/interfaces/Executor.cjs +1 -1
- package/lib/interfaces/Executor.d.ts +10 -13
- package/lib/interfaces/Observable.cjs +1 -1
- package/lib/interfaces/Observable.d.ts +20 -18
- package/lib/interfaces/Observer.cjs +1 -1
- package/lib/interfaces/Observer.d.ts +7 -8
- package/lib/interfaces/Paginatable.cjs +1 -1
- package/lib/interfaces/Paginatable.d.ts +18 -2
- package/lib/interfaces/Queriable.cjs +1 -1
- package/lib/interfaces/Queriable.d.ts +44 -3
- package/lib/interfaces/RawExecutor.cjs +1 -1
- package/lib/interfaces/RawExecutor.d.ts +10 -13
- package/lib/interfaces/SequenceOptions.cjs +19 -1
- package/lib/interfaces/SequenceOptions.d.ts +50 -5
- package/lib/interfaces/index.cjs +1 -2
- package/lib/interfaces/index.d.ts +0 -1
- package/lib/model/BaseModel.cjs +24 -1
- package/lib/model/BaseModel.d.ts +31 -0
- package/lib/model/construction.cjs +441 -2
- package/lib/model/construction.d.ts +442 -9
- package/lib/model/decorators.cjs +161 -37
- package/lib/model/decorators.d.ts +166 -42
- package/lib/model/index.cjs +1 -2
- package/lib/model/types.cjs +1 -1
- package/lib/model/types.d.ts +9 -0
- package/lib/persistence/Adapter.cjs +414 -58
- package/lib/persistence/Adapter.d.ts +384 -40
- package/lib/persistence/Dispatch.cjs +191 -0
- package/lib/persistence/Dispatch.d.ts +131 -0
- package/lib/persistence/ObserverHandler.cjs +141 -0
- package/lib/persistence/ObserverHandler.d.ts +109 -0
- package/lib/persistence/Sequence.cjs +91 -1
- package/lib/persistence/Sequence.d.ts +89 -8
- package/lib/persistence/constants.cjs +24 -8
- package/lib/persistence/constants.d.ts +22 -5
- package/lib/persistence/decorators.cjs +11 -1
- package/lib/persistence/decorators.d.ts +10 -0
- package/lib/persistence/errors.cjs +26 -9
- package/lib/persistence/errors.d.ts +23 -3
- package/lib/persistence/index.cjs +4 -1
- package/lib/persistence/index.d.ts +3 -0
- package/lib/persistence/types.cjs +3 -0
- package/lib/persistence/types.d.ts +21 -0
- package/lib/query/Condition.cjs +143 -61
- package/lib/query/Condition.d.ts +88 -44
- package/lib/query/Paginator.cjs +64 -10
- package/lib/query/Paginator.d.ts +67 -10
- package/lib/query/Statement.cjs +174 -121
- package/lib/query/Statement.d.ts +82 -47
- package/lib/query/constants.cjs +27 -69
- package/lib/query/constants.d.ts +25 -64
- package/lib/query/errors.cjs +15 -1
- package/lib/query/errors.d.ts +14 -0
- package/lib/query/index.cjs +1 -6
- package/lib/query/index.d.ts +0 -5
- package/lib/query/options.cjs +1 -1
- package/lib/query/options.d.ts +69 -178
- package/lib/query/selectors.cjs +1 -1
- package/lib/query/selectors.d.ts +20 -24
- package/lib/ram/RamAdapter.cjs +358 -172
- package/lib/ram/RamAdapter.d.ts +322 -20
- package/lib/ram/RamContext.cjs +18 -3
- package/lib/ram/RamContext.d.ts +16 -1
- package/lib/ram/RamPaginator.cjs +58 -6
- package/lib/ram/RamPaginator.d.ts +51 -6
- package/lib/ram/RamSequence.cjs +52 -41
- package/lib/ram/RamSequence.d.ts +49 -24
- package/lib/ram/RamStatement.cjs +175 -6
- package/lib/ram/RamStatement.d.ts +84 -6
- package/lib/ram/constants.cjs +13 -0
- package/lib/ram/constants.d.ts +9 -0
- package/lib/ram/handlers.cjs +30 -0
- package/lib/ram/handlers.d.ts +25 -0
- package/lib/ram/index.cjs +9 -5
- package/lib/ram/index.d.ts +4 -4
- package/lib/ram/model/RamSequence.cjs +19 -1
- package/lib/ram/model/RamSequence.d.ts +21 -9
- package/lib/ram/types.cjs +1 -1
- package/lib/ram/types.d.ts +47 -5
- package/lib/repository/Repository.cjs +445 -42
- package/lib/repository/Repository.d.ts +381 -22
- package/lib/repository/constants.cjs +24 -14
- package/lib/repository/constants.d.ts +23 -13
- package/lib/repository/decorators.cjs +28 -1
- package/lib/repository/decorators.d.ts +27 -0
- package/lib/repository/errors.cjs +14 -19
- package/lib/repository/errors.d.ts +12 -11
- package/lib/repository/injectables.cjs +19 -1
- package/lib/repository/injectables.d.ts +18 -0
- package/lib/repository/types.cjs +1 -1
- package/lib/repository/types.d.ts +13 -1
- package/lib/repository/utils.cjs +12 -1
- package/lib/repository/utils.d.ts +11 -0
- package/lib/utils/decorators.cjs +22 -0
- package/lib/utils/decorators.d.ts +9 -0
- package/lib/utils/errors.cjs +69 -0
- package/lib/utils/errors.d.ts +56 -0
- package/lib/{validators → utils}/index.cjs +2 -2
- package/lib/utils/index.d.ts +2 -0
- package/package.json +5 -5
- package/lib/esm/interfaces/Builder.d.ts +0 -16
- package/lib/esm/interfaces/Builder.js +0 -2
- package/lib/esm/model/IdentifiedBaseModel.d.ts +0 -7
- package/lib/esm/model/IdentifiedBaseModel.js +0 -25
- package/lib/esm/query/Clause.d.ts +0 -50
- package/lib/esm/query/Clause.js +0 -82
- package/lib/esm/query/ClauseFactory.d.ts +0 -71
- package/lib/esm/query/ClauseFactory.js +0 -6
- package/lib/esm/query/Query.d.ts +0 -43
- package/lib/esm/query/Query.js +0 -54
- package/lib/esm/query/clauses/FromClause.d.ts +0 -45
- package/lib/esm/query/clauses/FromClause.js +0 -59
- package/lib/esm/query/clauses/GroupByClause.d.ts +0 -21
- package/lib/esm/query/clauses/GroupByClause.js +0 -19
- package/lib/esm/query/clauses/InsertClause.d.ts +0 -37
- package/lib/esm/query/clauses/InsertClause.js +0 -55
- package/lib/esm/query/clauses/LimitClause.d.ts +0 -29
- package/lib/esm/query/clauses/LimitClause.js +0 -27
- package/lib/esm/query/clauses/OffsetClause.d.ts +0 -21
- package/lib/esm/query/clauses/OffsetClause.js +0 -19
- package/lib/esm/query/clauses/OrderByClause.d.ts +0 -37
- package/lib/esm/query/clauses/OrderByClause.js +0 -39
- package/lib/esm/query/clauses/SelectClause.d.ts +0 -47
- package/lib/esm/query/clauses/SelectClause.js +0 -62
- package/lib/esm/query/clauses/SelectorBasedClause.d.ts +0 -25
- package/lib/esm/query/clauses/SelectorBasedClause.js +0 -44
- package/lib/esm/query/clauses/ValuesClause.d.ts +0 -21
- package/lib/esm/query/clauses/ValuesClause.js +0 -36
- package/lib/esm/query/clauses/WhereClause.d.ts +0 -46
- package/lib/esm/query/clauses/WhereClause.js +0 -71
- package/lib/esm/query/clauses/index.d.ts +0 -10
- package/lib/esm/query/clauses/index.js +0 -11
- package/lib/esm/query/types.d.ts +0 -2
- package/lib/esm/query/types.js +0 -2
- package/lib/esm/ram/RamClauseFactory.d.ts +0 -17
- package/lib/esm/ram/RamClauseFactory.js +0 -92
- package/lib/esm/ram/clauses/FromClause.d.ts +0 -7
- package/lib/esm/ram/clauses/FromClause.js +0 -11
- package/lib/esm/ram/clauses/InsertClause.d.ts +0 -7
- package/lib/esm/ram/clauses/InsertClause.js +0 -13
- package/lib/esm/ram/clauses/OrderByClause.d.ts +0 -7
- package/lib/esm/ram/clauses/OrderByClause.js +0 -39
- package/lib/esm/ram/clauses/SelectClause.d.ts +0 -7
- package/lib/esm/ram/clauses/SelectClause.js +0 -16
- package/lib/esm/ram/clauses/ValuesClause.d.ts +0 -7
- package/lib/esm/ram/clauses/ValuesClause.js +0 -12
- package/lib/esm/ram/clauses/WhereClause.d.ts +0 -7
- package/lib/esm/ram/clauses/WhereClause.js +0 -11
- package/lib/esm/ram/clauses/index.d.ts +0 -6
- package/lib/esm/ram/clauses/index.js +0 -7
- package/lib/esm/validators/ClauseSequenceValidator.d.ts +0 -28
- package/lib/esm/validators/ClauseSequenceValidator.js +0 -95
- package/lib/esm/validators/decorators.d.ts +0 -10
- package/lib/esm/validators/decorators.js +0 -24
- package/lib/esm/validators/index.d.ts +0 -2
- package/lib/esm/validators/index.js +0 -3
- package/lib/interfaces/Builder.cjs +0 -3
- package/lib/interfaces/Builder.d.ts +0 -16
- package/lib/model/IdentifiedBaseModel.cjs +0 -29
- package/lib/model/IdentifiedBaseModel.d.ts +0 -7
- package/lib/query/Clause.cjs +0 -86
- package/lib/query/Clause.d.ts +0 -50
- package/lib/query/ClauseFactory.cjs +0 -10
- package/lib/query/ClauseFactory.d.ts +0 -71
- package/lib/query/Query.cjs +0 -58
- package/lib/query/Query.d.ts +0 -43
- package/lib/query/clauses/FromClause.cjs +0 -63
- package/lib/query/clauses/FromClause.d.ts +0 -45
- package/lib/query/clauses/GroupByClause.cjs +0 -23
- package/lib/query/clauses/GroupByClause.d.ts +0 -21
- package/lib/query/clauses/InsertClause.cjs +0 -59
- package/lib/query/clauses/InsertClause.d.ts +0 -37
- package/lib/query/clauses/LimitClause.cjs +0 -31
- package/lib/query/clauses/LimitClause.d.ts +0 -29
- package/lib/query/clauses/OffsetClause.cjs +0 -23
- package/lib/query/clauses/OffsetClause.d.ts +0 -21
- package/lib/query/clauses/OrderByClause.cjs +0 -43
- package/lib/query/clauses/OrderByClause.d.ts +0 -37
- package/lib/query/clauses/SelectClause.cjs +0 -66
- package/lib/query/clauses/SelectClause.d.ts +0 -47
- package/lib/query/clauses/SelectorBasedClause.cjs +0 -48
- package/lib/query/clauses/SelectorBasedClause.d.ts +0 -25
- package/lib/query/clauses/ValuesClause.cjs +0 -40
- package/lib/query/clauses/ValuesClause.d.ts +0 -21
- package/lib/query/clauses/WhereClause.cjs +0 -75
- package/lib/query/clauses/WhereClause.d.ts +0 -46
- package/lib/query/clauses/index.cjs +0 -27
- package/lib/query/clauses/index.d.ts +0 -10
- package/lib/query/types.cjs +0 -3
- package/lib/query/types.d.ts +0 -2
- package/lib/ram/RamClauseFactory.cjs +0 -96
- package/lib/ram/RamClauseFactory.d.ts +0 -17
- package/lib/ram/clauses/FromClause.cjs +0 -15
- package/lib/ram/clauses/FromClause.d.ts +0 -7
- package/lib/ram/clauses/InsertClause.cjs +0 -17
- package/lib/ram/clauses/InsertClause.d.ts +0 -7
- package/lib/ram/clauses/OrderByClause.cjs +0 -43
- package/lib/ram/clauses/OrderByClause.d.ts +0 -7
- package/lib/ram/clauses/SelectClause.cjs +0 -20
- package/lib/ram/clauses/SelectClause.d.ts +0 -7
- package/lib/ram/clauses/ValuesClause.cjs +0 -16
- package/lib/ram/clauses/ValuesClause.d.ts +0 -7
- package/lib/ram/clauses/WhereClause.cjs +0 -15
- package/lib/ram/clauses/WhereClause.d.ts +0 -7
- package/lib/ram/clauses/index.cjs +0 -23
- package/lib/ram/clauses/index.d.ts +0 -6
- package/lib/validators/ClauseSequenceValidator.cjs +0 -98
- package/lib/validators/ClauseSequenceValidator.d.ts +0 -28
- package/lib/validators/decorators.cjs +0 -27
- package/lib/validators/decorators.d.ts +0 -10
- package/lib/validators/index.d.ts +0 -2
@@ -1,41 +1,343 @@
|
|
1
|
-
import {
|
2
|
-
import { RamFlags, RamQuery, RamStorage } from "./types";
|
1
|
+
import { RamFlags, RawRamQuery, RamStorage, RamRepository } from "./types";
|
3
2
|
import { RamStatement } from "./RamStatement";
|
4
|
-
import { RamClauseFactory } from "./RamClauseFactory";
|
5
3
|
import { RamContext } from "./RamContext";
|
6
|
-
import { Repo } from "../repository/Repository";
|
7
|
-
import { RelationsMetadata } from "../model/types";
|
8
4
|
import { Adapter, Sequence } from "../persistence";
|
9
|
-
import { Paginator } from "../query/Paginator";
|
10
|
-
import { ClauseFactory, Condition } from "../query";
|
11
5
|
import { SequenceOptions } from "../interfaces";
|
12
6
|
import { Constructor, Model } from "@decaf-ts/decorator-validation";
|
13
|
-
import { BaseError } from "@decaf-ts/db-decorators";
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
7
|
+
import { BaseError, OperationKeys } from "@decaf-ts/db-decorators";
|
8
|
+
/**
|
9
|
+
* @description In-memory adapter for data persistence
|
10
|
+
* @summary The RamAdapter provides an in-memory implementation of the persistence layer.
|
11
|
+
* It stores data in JavaScript Maps and provides CRUD operations and query capabilities.
|
12
|
+
* This adapter is useful for testing, prototyping, and applications that don't require
|
13
|
+
* persistent storage across application restarts.
|
14
|
+
* @class RamAdapter
|
15
|
+
* @category Ram
|
16
|
+
* @example
|
17
|
+
* ```typescript
|
18
|
+
* // Create a new RAM adapter
|
19
|
+
* const adapter = new RamAdapter('myRamAdapter');
|
20
|
+
*
|
21
|
+
* // Create a repository for a model
|
22
|
+
* const userRepo = new (adapter.repository<User>())(User, adapter);
|
23
|
+
*
|
24
|
+
* // Perform CRUD operations
|
25
|
+
* const user = new User({ name: 'John', email: 'john@example.com' });
|
26
|
+
* await userRepo.create(user);
|
27
|
+
* const retrievedUser = await userRepo.findById(user.id);
|
28
|
+
* ```
|
29
|
+
* @mermaid
|
30
|
+
* sequenceDiagram
|
31
|
+
* participant Client
|
32
|
+
* participant Repository
|
33
|
+
* participant RamAdapter
|
34
|
+
* participant Storage as In-Memory Storage
|
35
|
+
*
|
36
|
+
* Client->>Repository: create(model)
|
37
|
+
* Repository->>RamAdapter: create(tableName, id, model)
|
38
|
+
* RamAdapter->>RamAdapter: lock.acquire()
|
39
|
+
* RamAdapter->>Storage: set(id, model)
|
40
|
+
* RamAdapter->>RamAdapter: lock.release()
|
41
|
+
* RamAdapter-->>Repository: model
|
42
|
+
* Repository-->>Client: model
|
43
|
+
*
|
44
|
+
* Client->>Repository: findById(id)
|
45
|
+
* Repository->>RamAdapter: read(tableName, id)
|
46
|
+
* RamAdapter->>Storage: get(id)
|
47
|
+
* Storage-->>RamAdapter: model
|
48
|
+
* RamAdapter-->>Repository: model
|
49
|
+
* Repository-->>Client: model
|
50
|
+
*/
|
51
|
+
export declare class RamAdapter extends Adapter<RamStorage, RawRamQuery<any>, RamFlags, RamContext> {
|
52
|
+
constructor(alias?: string);
|
53
|
+
/**
|
54
|
+
* @description Gets the repository constructor for a model
|
55
|
+
* @summary Returns a constructor for creating repositories that work with the specified model type.
|
56
|
+
* This method overrides the base implementation to provide RAM-specific repository functionality.
|
57
|
+
* @template M - The model type for the repository
|
58
|
+
* @return {Constructor<RamRepository<M>>} A constructor for creating RAM repositories
|
59
|
+
*/
|
60
|
+
repository<M extends Model>(): Constructor<RamRepository<M>>;
|
61
|
+
/**
|
62
|
+
* @description Creates operation flags with UUID
|
63
|
+
* @summary Extends the base flags with a UUID for user identification.
|
64
|
+
* This method ensures that all operations have a unique identifier for tracking purposes.
|
65
|
+
* @template M - The model type for the operation
|
66
|
+
* @param {OperationKeys} operation - The type of operation being performed
|
67
|
+
* @param {Constructor<M>} model - The model constructor
|
68
|
+
* @param {Partial<RamFlags>} flags - Partial flags to be extended
|
69
|
+
* @return {RamFlags} Complete flags with UUID
|
70
|
+
*/
|
71
|
+
flags<M extends Model>(operation: OperationKeys, model: Constructor<M>, flags: Partial<RamFlags>): RamFlags;
|
72
|
+
Context: typeof RamContext;
|
19
73
|
private indexes;
|
20
74
|
private lock;
|
21
|
-
|
75
|
+
/**
|
76
|
+
* @description Initializes the RAM adapter
|
77
|
+
* @summary A no-op initialization method for the RAM adapter.
|
78
|
+
* Since RAM adapter doesn't require any setup, this method simply resolves immediately.
|
79
|
+
* @param {...any[]} args - Initialization arguments (unused)
|
80
|
+
* @return {Promise<void>} A promise that resolves when initialization is complete
|
81
|
+
*/
|
22
82
|
initialize(...args: any[]): Promise<void>;
|
83
|
+
/**
|
84
|
+
* @description Indexes models in the RAM adapter
|
85
|
+
* @summary A no-op indexing method for the RAM adapter.
|
86
|
+
* Since RAM adapter doesn't require explicit indexing, this method simply resolves immediately.
|
87
|
+
* @param models - Models to be indexed (unused)
|
88
|
+
* @return {Promise<any>} A promise that resolves when indexing is complete
|
89
|
+
*/
|
23
90
|
index(...models: Record<string, any>[]): Promise<any>;
|
91
|
+
/**
|
92
|
+
* @description Prepares a model for storage
|
93
|
+
* @summary Converts a model instance to a format suitable for storage in the RAM adapter.
|
94
|
+
* This method extracts the primary key and creates a record without the primary key field.
|
95
|
+
* @template M - The model type being prepared
|
96
|
+
* @param {M} model - The model instance to prepare
|
97
|
+
* @param pk - The primary key property name
|
98
|
+
* @return Object containing the record and ID
|
99
|
+
*/
|
24
100
|
prepare<M extends Model>(model: M, pk: keyof M): {
|
25
101
|
record: Record<string, any>;
|
26
102
|
id: string;
|
27
103
|
};
|
104
|
+
/**
|
105
|
+
* @description Converts a stored record back to a model instance
|
106
|
+
* @summary Reconstructs a model instance from a stored record by adding back the primary key.
|
107
|
+
* This method is the inverse of the prepare method.
|
108
|
+
* @template M - The model type to revert to
|
109
|
+
* @param {Record<string, any>} obj - The stored record
|
110
|
+
* @param {string | Constructor<M>} clazz - The model class or name
|
111
|
+
* @param pk - The primary key property name
|
112
|
+
* @param {string | number} id - The primary key value
|
113
|
+
* @return {M} The reconstructed model instance
|
114
|
+
*/
|
28
115
|
revert<M extends Model>(obj: Record<string, any>, clazz: string | Constructor<M>, pk: keyof M, id: string | number): M;
|
116
|
+
/**
|
117
|
+
* @description Creates a new record in the in-memory storage
|
118
|
+
* @summary Stores a new record in the specified table with the given ID.
|
119
|
+
* This method acquires a lock to ensure thread safety, creates the table if it doesn't exist,
|
120
|
+
* checks for conflicts, and stores the model.
|
121
|
+
* @param {string} tableName - The name of the table to store the record in
|
122
|
+
* @param {string | number} id - The unique identifier for the record
|
123
|
+
* @param {Record<string, any>} model - The record data to store
|
124
|
+
* @return {Promise<Record<string, any>>} A promise that resolves to the stored record
|
125
|
+
* @mermaid
|
126
|
+
* sequenceDiagram
|
127
|
+
* participant Caller
|
128
|
+
* participant RamAdapter
|
129
|
+
* participant Storage as In-Memory Storage
|
130
|
+
*
|
131
|
+
* Caller->>RamAdapter: create(tableName, id, model)
|
132
|
+
* RamAdapter->>RamAdapter: lock.acquire()
|
133
|
+
* RamAdapter->>Storage: has(tableName)
|
134
|
+
* alt Table doesn't exist
|
135
|
+
* RamAdapter->>Storage: set(tableName, new Map())
|
136
|
+
* end
|
137
|
+
* RamAdapter->>Storage: has(id)
|
138
|
+
* alt Record exists
|
139
|
+
* RamAdapter-->>Caller: throw ConflictError
|
140
|
+
* end
|
141
|
+
* RamAdapter->>Storage: set(id, model)
|
142
|
+
* RamAdapter->>RamAdapter: lock.release()
|
143
|
+
* RamAdapter-->>Caller: model
|
144
|
+
*/
|
29
145
|
create(tableName: string, id: string | number, model: Record<string, any>): Promise<Record<string, any>>;
|
146
|
+
/**
|
147
|
+
* @description Retrieves a record from in-memory storage
|
148
|
+
* @summary Fetches a record with the specified ID from the given table.
|
149
|
+
* This method checks if the table and record exist and throws appropriate errors if not.
|
150
|
+
* @param {string} tableName - The name of the table to retrieve from
|
151
|
+
* @param {string | number} id - The unique identifier of the record to retrieve
|
152
|
+
* @return {Promise<Record<string, any>>} A promise that resolves to the retrieved record
|
153
|
+
* @mermaid
|
154
|
+
* sequenceDiagram
|
155
|
+
* participant Caller
|
156
|
+
* participant RamAdapter
|
157
|
+
* participant Storage as In-Memory Storage
|
158
|
+
*
|
159
|
+
* Caller->>RamAdapter: read(tableName, id)
|
160
|
+
* RamAdapter->>Storage: has(tableName)
|
161
|
+
* alt Table doesn't exist
|
162
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
163
|
+
* end
|
164
|
+
* RamAdapter->>Storage: has(id)
|
165
|
+
* alt Record doesn't exist
|
166
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
167
|
+
* end
|
168
|
+
* RamAdapter->>Storage: get(id)
|
169
|
+
* Storage-->>RamAdapter: record
|
170
|
+
* RamAdapter-->>Caller: record
|
171
|
+
*/
|
30
172
|
read(tableName: string, id: string | number): Promise<Record<string, any>>;
|
173
|
+
/**
|
174
|
+
* @description Updates an existing record in the in-memory storage
|
175
|
+
* @summary Updates a record with the specified ID in the given table.
|
176
|
+
* This method acquires a lock to ensure thread safety, checks if the table and record exist,
|
177
|
+
* and updates the record with the new data.
|
178
|
+
* @param {string} tableName - The name of the table containing the record
|
179
|
+
* @param {string | number} id - The unique identifier of the record to update
|
180
|
+
* @param {Record<string, any>} model - The new record data
|
181
|
+
* @return {Promise<Record<string, any>>} A promise that resolves to the updated record
|
182
|
+
* @mermaid
|
183
|
+
* sequenceDiagram
|
184
|
+
* participant Caller
|
185
|
+
* participant RamAdapter
|
186
|
+
* participant Storage as In-Memory Storage
|
187
|
+
*
|
188
|
+
* Caller->>RamAdapter: update(tableName, id, model)
|
189
|
+
* RamAdapter->>RamAdapter: lock.acquire()
|
190
|
+
* RamAdapter->>Storage: has(tableName)
|
191
|
+
* alt Table doesn't exist
|
192
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
193
|
+
* end
|
194
|
+
* RamAdapter->>Storage: has(id)
|
195
|
+
* alt Record doesn't exist
|
196
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
197
|
+
* end
|
198
|
+
* RamAdapter->>Storage: set(id, model)
|
199
|
+
* RamAdapter->>RamAdapter: lock.release()
|
200
|
+
* RamAdapter-->>Caller: model
|
201
|
+
*/
|
31
202
|
update(tableName: string, id: string | number, model: Record<string, any>): Promise<Record<string, any>>;
|
203
|
+
/**
|
204
|
+
* @description Deletes a record from the in-memory storage
|
205
|
+
* @summary Removes a record with the specified ID from the given table.
|
206
|
+
* This method acquires a lock to ensure thread safety, checks if the table and record exist,
|
207
|
+
* retrieves the record before deletion, and then removes it from storage.
|
208
|
+
* @param {string} tableName - The name of the table containing the record
|
209
|
+
* @param {string | number} id - The unique identifier of the record to delete
|
210
|
+
* @return {Promise<Record<string, any>>} A promise that resolves to the deleted record
|
211
|
+
* @mermaid
|
212
|
+
* sequenceDiagram
|
213
|
+
* participant Caller
|
214
|
+
* participant RamAdapter
|
215
|
+
* participant Storage as In-Memory Storage
|
216
|
+
*
|
217
|
+
* Caller->>RamAdapter: delete(tableName, id)
|
218
|
+
* RamAdapter->>RamAdapter: lock.acquire()
|
219
|
+
* RamAdapter->>Storage: has(tableName)
|
220
|
+
* alt Table doesn't exist
|
221
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
222
|
+
* end
|
223
|
+
* RamAdapter->>Storage: has(id)
|
224
|
+
* alt Record doesn't exist
|
225
|
+
* RamAdapter-->>Caller: throw NotFoundError
|
226
|
+
* end
|
227
|
+
* RamAdapter->>Storage: get(id)
|
228
|
+
* Storage-->>RamAdapter: record
|
229
|
+
* RamAdapter->>Storage: delete(id)
|
230
|
+
* RamAdapter->>RamAdapter: lock.release()
|
231
|
+
* RamAdapter-->>Caller: record
|
232
|
+
*/
|
32
233
|
delete(tableName: string, id: string | number): Promise<Record<string, any>>;
|
33
|
-
|
34
|
-
|
35
|
-
|
234
|
+
/**
|
235
|
+
* @description Gets or creates a table in the in-memory storage
|
236
|
+
* @summary Retrieves the Map representing a table for a given model or table name.
|
237
|
+
* If the table doesn't exist, it creates a new one. This is a helper method used
|
238
|
+
* by other methods to access the correct storage location.
|
239
|
+
* @template M - The model type for the table
|
240
|
+
* @param {string | Constructor<M>} from - The model class or table name
|
241
|
+
* @return {Map<string | number, any> | undefined} The table Map or undefined
|
242
|
+
*/
|
243
|
+
protected tableFor<M extends Model>(from: string | Constructor<M>): Map<string | number, any> | undefined;
|
244
|
+
/**
|
245
|
+
* @description Executes a raw query against the in-memory storage
|
246
|
+
* @summary Performs a query operation on the in-memory data store using the provided query specification.
|
247
|
+
* This method supports filtering, sorting, pagination, and field selection.
|
248
|
+
* @template R - The return type of the query
|
249
|
+
* @param {RawRamQuery<any>} rawInput - The query specification
|
250
|
+
* @return {Promise<R>} A promise that resolves to the query results
|
251
|
+
* @mermaid
|
252
|
+
* sequenceDiagram
|
253
|
+
* participant Caller
|
254
|
+
* participant RamAdapter
|
255
|
+
* participant Storage as In-Memory Storage
|
256
|
+
*
|
257
|
+
* Caller->>RamAdapter: raw(rawInput)
|
258
|
+
* RamAdapter->>RamAdapter: tableFor(from)
|
259
|
+
* alt Table doesn't exist
|
260
|
+
* RamAdapter-->>Caller: throw InternalError
|
261
|
+
* end
|
262
|
+
* RamAdapter->>RamAdapter: findPrimaryKey(new from())
|
263
|
+
* RamAdapter->>Storage: entries()
|
264
|
+
* Storage-->>RamAdapter: entries
|
265
|
+
* loop For each entry
|
266
|
+
* RamAdapter->>RamAdapter: revert(r, from, id, pk)
|
267
|
+
* end
|
268
|
+
* alt Where condition exists
|
269
|
+
* RamAdapter->>RamAdapter: result.filter(where)
|
270
|
+
* end
|
271
|
+
* alt Sort condition exists
|
272
|
+
* RamAdapter->>RamAdapter: result.sort(sort)
|
273
|
+
* end
|
274
|
+
* alt Skip specified
|
275
|
+
* RamAdapter->>RamAdapter: result.slice(skip)
|
276
|
+
* end
|
277
|
+
* alt Limit specified
|
278
|
+
* RamAdapter->>RamAdapter: result.slice(0, limit)
|
279
|
+
* end
|
280
|
+
* alt Select fields specified
|
281
|
+
* loop For each result
|
282
|
+
* RamAdapter->>RamAdapter: Filter to selected fields
|
283
|
+
* end
|
284
|
+
* end
|
285
|
+
* RamAdapter-->>Caller: result
|
286
|
+
*/
|
287
|
+
raw<R>(rawInput: RawRamQuery<any>): Promise<R>;
|
288
|
+
/**
|
289
|
+
* @description Parses and converts errors to appropriate types
|
290
|
+
* @summary Ensures that errors are of the correct type for consistent error handling.
|
291
|
+
* If the error is already a BaseError, it's returned as is; otherwise, it's wrapped in an InternalError.
|
292
|
+
* @template V - The expected error type, extending BaseError
|
293
|
+
* @param {Error} err - The error to parse
|
294
|
+
* @return {V} The parsed error of the expected type
|
295
|
+
*/
|
36
296
|
parseError<V extends BaseError>(err: Error): V;
|
37
|
-
|
38
|
-
|
297
|
+
/**
|
298
|
+
* @description Creates a new statement builder for queries
|
299
|
+
* @summary Factory method that creates a new RamStatement instance for building queries.
|
300
|
+
* This method allows for fluent query construction against the RAM adapter.
|
301
|
+
* @template M - The model type for the statement
|
302
|
+
* @return {RamStatement<M, any>} A new statement builder instance
|
303
|
+
*/
|
304
|
+
Statement<M extends Model>(): RamStatement<M, any>;
|
305
|
+
/**
|
306
|
+
* @description Creates a new sequence for generating sequential IDs
|
307
|
+
* @summary Factory method that creates a new RamSequence instance for ID generation.
|
308
|
+
* This method provides a way to create auto-incrementing sequences for entity IDs.
|
309
|
+
* @param {SequenceOptions} options - Configuration options for the sequence
|
310
|
+
* @return {Promise<Sequence>} A promise that resolves to the new sequence instance
|
311
|
+
*/
|
39
312
|
Sequence(options: SequenceOptions): Promise<Sequence>;
|
40
|
-
|
313
|
+
/**
|
314
|
+
* @description Sets up RAM-specific decorations for model properties
|
315
|
+
* @summary Configures decorations for createdBy and updatedBy fields in the RAM adapter.
|
316
|
+
* This static method is called during initialization to set up handlers that automatically
|
317
|
+
* populate these fields with the current user's UUID during create and update operations.
|
318
|
+
* @return {void}
|
319
|
+
* @mermaid
|
320
|
+
* sequenceDiagram
|
321
|
+
* participant RamAdapter
|
322
|
+
* participant Decoration
|
323
|
+
* participant Repository
|
324
|
+
*
|
325
|
+
* RamAdapter->>Repository: key(PersistenceKeys.CREATED_BY)
|
326
|
+
* Repository-->>RamAdapter: createdByKey
|
327
|
+
* RamAdapter->>Repository: key(PersistenceKeys.UPDATED_BY)
|
328
|
+
* Repository-->>RamAdapter: updatedByKey
|
329
|
+
*
|
330
|
+
* RamAdapter->>Decoration: flavouredAs(RamFlavour)
|
331
|
+
* Decoration-->>RamAdapter: DecoratorBuilder
|
332
|
+
* RamAdapter->>Decoration: for(createdByKey)
|
333
|
+
* RamAdapter->>Decoration: define(onCreate, propMetadata)
|
334
|
+
* RamAdapter->>Decoration: apply()
|
335
|
+
*
|
336
|
+
* RamAdapter->>Decoration: flavouredAs(RamFlavour)
|
337
|
+
* Decoration-->>RamAdapter: DecoratorBuilder
|
338
|
+
* RamAdapter->>Decoration: for(updatedByKey)
|
339
|
+
* RamAdapter->>Decoration: define(onCreate, propMetadata)
|
340
|
+
* RamAdapter->>Decoration: apply()
|
341
|
+
*/
|
342
|
+
static decoration(): void;
|
41
343
|
}
|