@decaf-ts/core 0.19.0 → 0.20.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/cjs/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/index.d.cts +1 -1
- package/lib/types/index.d.mts +1 -1
- package/package.json +1 -1
- package/lib/types/auth/constants.d.ts +0 -5
- package/lib/types/auth/decorators.d.ts +0 -5
- package/lib/types/auth/index.d.ts +0 -2
- package/lib/types/fs/FilesystemAdapter.d.ts +0 -70
- package/lib/types/fs/FsDispatch.d.ts +0 -7
- package/lib/types/fs/helpers.d.ts +0 -17
- package/lib/types/fs/index.d.ts +0 -4
- package/lib/types/fs/indexStore.d.ts +0 -28
- package/lib/types/fs/locks/FilesystemLock.d.ts +0 -13
- package/lib/types/fs/locks/FilesystemMultiLock.d.ts +0 -8
- package/lib/types/fs/types.d.ts +0 -40
- package/lib/types/identity/decorators.d.ts +0 -72
- package/lib/types/identity/index.d.ts +0 -6
- package/lib/types/index.d.ts +0 -34
- package/lib/types/interfaces/ContextuallyLogged.d.ts +0 -8
- package/lib/types/interfaces/ErrorParser.d.ts +0 -16
- package/lib/types/interfaces/Executor.d.ts +0 -16
- package/lib/types/interfaces/Observable.d.ts +0 -33
- package/lib/types/interfaces/Observer.d.ts +0 -15
- package/lib/types/interfaces/Paginatable.d.ts +0 -20
- package/lib/types/interfaces/Queriable.d.ts +0 -47
- package/lib/types/interfaces/RawExecutor.d.ts +0 -28
- package/lib/types/interfaces/SequenceOptions.d.ts +0 -79
- package/lib/types/interfaces/index.d.ts +0 -12
- package/lib/types/migrations/Migration.d.ts +0 -19
- package/lib/types/migrations/MigrationService.d.ts +0 -63
- package/lib/types/migrations/MigrationTaskBuilder.d.ts +0 -10
- package/lib/types/migrations/MigrationTasks.d.ts +0 -9
- package/lib/types/migrations/MigrationVersioning.d.ts +0 -7
- package/lib/types/migrations/SemverMigrationVersioning.d.ts +0 -10
- package/lib/types/migrations/StandardMigrationVersioning.d.ts +0 -12
- package/lib/types/migrations/constants.d.ts +0 -2
- package/lib/types/migrations/decorators.d.ts +0 -12
- package/lib/types/migrations/index.d.ts +0 -15
- package/lib/types/migrations/types.d.ts +0 -46
- package/lib/types/model/BaseModel.d.ts +0 -37
- package/lib/types/model/SequenceModel.d.ts +0 -32
- package/lib/types/model/construction.d.ts +0 -455
- package/lib/types/model/decorators.d.ts +0 -237
- package/lib/types/model/index.d.ts +0 -11
- package/lib/types/model/indexing.d.ts +0 -20
- package/lib/types/model/types.d.ts +0 -60
- package/lib/types/overrides/Metadata.d.ts +0 -22
- package/lib/types/overrides/Model.d.ts +0 -94
- package/lib/types/overrides/ModelBuilder.d.ts +0 -31
- package/lib/types/overrides/index.d.ts +0 -11
- package/lib/types/overrides/injectables.d.ts +0 -10
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/persistence/Adapter.d.ts +0 -469
- package/lib/types/persistence/Context.d.ts +0 -16
- package/lib/types/persistence/ContextLock.d.ts +0 -18
- package/lib/types/persistence/Dispatch.d.ts +0 -128
- package/lib/types/persistence/ObserverHandler.d.ts +0 -111
- package/lib/types/persistence/Sequence.d.ts +0 -126
- package/lib/types/persistence/constants.d.ts +0 -74
- package/lib/types/persistence/decorators.d.ts +0 -28
- package/lib/types/persistence/errors.d.ts +0 -33
- package/lib/types/persistence/event-filters.d.ts +0 -20
- package/lib/types/persistence/generators.d.ts +0 -14
- package/lib/types/persistence/index.d.ts +0 -18
- package/lib/types/persistence/transactions.d.ts +0 -4
- package/lib/types/persistence/types.d.ts +0 -86
- package/lib/types/query/Condition.d.ts +0 -131
- package/lib/types/query/MethodQueryBuilder.d.ts +0 -185
- package/lib/types/query/Paginator.d.ts +0 -105
- package/lib/types/query/Statement.d.ts +0 -136
- package/lib/types/query/constants.d.ts +0 -69
- package/lib/types/query/decorators.d.ts +0 -8
- package/lib/types/query/errors.d.ts +0 -21
- package/lib/types/query/index.d.ts +0 -16
- package/lib/types/query/options.d.ts +0 -393
- package/lib/types/query/selectors.d.ts +0 -39
- package/lib/types/query/types.d.ts +0 -158
- package/lib/types/query/utils.d.ts +0 -40
- package/lib/types/ram/RamAdapter.d.ts +0 -341
- package/lib/types/ram/RamPaginator.d.ts +0 -54
- package/lib/types/ram/RamStatement.d.ts +0 -92
- package/lib/types/ram/constants.d.ts +0 -8
- package/lib/types/ram/handlers.d.ts +0 -24
- package/lib/types/ram/index.d.ts +0 -12
- package/lib/types/ram/types.d.ts +0 -50
- package/lib/types/repository/Repository.d.ts +0 -501
- package/lib/types/repository/constants.d.ts +0 -36
- package/lib/types/repository/decorators.d.ts +0 -30
- package/lib/types/repository/errors.d.ts +0 -19
- package/lib/types/repository/index.d.ts +0 -12
- package/lib/types/repository/injectables.d.ts +0 -95
- package/lib/types/repository/types.d.ts +0 -28
- package/lib/types/repository/utils.d.ts +0 -36
- package/lib/types/services/ModelService.d.ts +0 -45
- package/lib/types/services/PersistenceService.d.ts +0 -17
- package/lib/types/services/index.d.ts +0 -8
- package/lib/types/services/services.d.ts +0 -96
- package/lib/types/tasks/CleanUpTask.d.ts +0 -15
- package/lib/types/tasks/TaskContext.d.ts +0 -30
- package/lib/types/tasks/TaskEngine.d.ts +0 -97
- package/lib/types/tasks/TaskErrors.d.ts +0 -65
- package/lib/types/tasks/TaskEventBus.d.ts +0 -17
- package/lib/types/tasks/TaskEventService.d.ts +0 -7
- package/lib/types/tasks/TaskHandler.d.ts +0 -12
- package/lib/types/tasks/TaskHandlerRegistry.d.ts +0 -8
- package/lib/types/tasks/TaskService.d.ts +0 -65
- package/lib/types/tasks/TaskStateChangeError.d.ts +0 -11
- package/lib/types/tasks/TaskTracker.d.ts +0 -47
- package/lib/types/tasks/builder.d.ts +0 -72
- package/lib/types/tasks/constants.d.ts +0 -31
- package/lib/types/tasks/decorators.d.ts +0 -4
- package/lib/types/tasks/index.d.ts +0 -23
- package/lib/types/tasks/logging.d.ts +0 -31
- package/lib/types/tasks/models/TaskBackoffModel.d.ts +0 -9
- package/lib/types/tasks/models/TaskErrorModel.d.ts +0 -8
- package/lib/types/tasks/models/TaskEventModel.d.ts +0 -11
- package/lib/types/tasks/models/TaskIOSerializer.d.ts +0 -33
- package/lib/types/tasks/models/TaskLogEntryModel.d.ts +0 -10
- package/lib/types/tasks/models/TaskModel.d.ts +0 -43
- package/lib/types/tasks/models/TaskStepResultModel.d.ts +0 -9
- package/lib/types/tasks/models/TaskStepSpecModel.d.ts +0 -9
- package/lib/types/tasks/models/index.d.ts +0 -8
- package/lib/types/tasks/types.d.ts +0 -71
- package/lib/types/tasks/utils.d.ts +0 -5
- package/lib/types/utils/ContextualLoggedClass.d.ts +0 -37
- package/lib/types/utils/decorators.d.ts +0 -27
- package/lib/types/utils/errors.d.ts +0 -56
- package/lib/types/utils/index.d.ts +0 -11
- package/lib/types/utils/throttling.d.ts +0 -9
- package/lib/types/utils/types.d.ts +0 -23
- package/lib/types/utils/utils.d.ts +0 -22
- package/lib/types/workers/TaskEngine.d.ts +0 -40
- package/lib/types/workers/WorkThreadEnvironment.d.ts +0 -35
- package/lib/types/workers/index.d.ts +0 -5
- package/lib/types/workers/messages.d.ts +0 -69
- package/lib/types/workers/types.d.ts +0 -41
- package/lib/types/workers/workerThread.d.ts +0 -1
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Observer } from "../interfaces";
|
|
2
|
-
import { EventIds, ObserverFilter, PersistenceObservable } from "./types";
|
|
3
|
-
import { BulkCrudOperationKeys, OperationKeys } from "@decaf-ts/db-decorators";
|
|
4
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
5
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
-
import { ContextualArgs } from "../utils/ContextualLoggedClass";
|
|
7
|
-
import { Context } from "./Context";
|
|
8
|
-
/**
|
|
9
|
-
* @description Manages a collection of observers for database events
|
|
10
|
-
* @summary The ObserverHandler class implements the Observable interface and provides a centralized
|
|
11
|
-
* way to manage multiple observers. It allows registering observers with optional filters to control
|
|
12
|
-
* which events they receive notifications for, and handles the process of notifying all relevant
|
|
13
|
-
* observers when database events occur.
|
|
14
|
-
* @class ObserverHandler
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Create an observer handler
|
|
18
|
-
* const handler = new ObserverHandler();
|
|
19
|
-
*
|
|
20
|
-
* // Register an observer
|
|
21
|
-
* const myObserver = {
|
|
22
|
-
* refresh: async (table, event, id) => {
|
|
23
|
-
* console.log(`Change in ${table}: ${event} for ID ${id}`);
|
|
24
|
-
* }
|
|
25
|
-
* };
|
|
26
|
-
*
|
|
27
|
-
* // Add observer with a filter for only user table events
|
|
28
|
-
* handler.observe(myObserver, (table, event, id) => table === 'users');
|
|
29
|
-
*
|
|
30
|
-
* // Notify observers about an event
|
|
31
|
-
* await handler.updateObservers(logger, 'users', 'CREATE', 123);
|
|
32
|
-
*
|
|
33
|
-
* // Remove an observer when no longer needed
|
|
34
|
-
* handler.unObserve(myObserver);
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export declare class ObserverHandler<C extends Context<any> = Context> implements PersistenceObservable<C> {
|
|
38
|
-
/**
|
|
39
|
-
* @description Collection of registered observers
|
|
40
|
-
* @summary Array of observer objects along with their optional filters
|
|
41
|
-
*/
|
|
42
|
-
protected readonly observers: {
|
|
43
|
-
observer: Observer;
|
|
44
|
-
filter?: ObserverFilter;
|
|
45
|
-
}[];
|
|
46
|
-
/**
|
|
47
|
-
* @description Gets the number of registered observers
|
|
48
|
-
* @summary Returns the count of observers currently registered with this handler
|
|
49
|
-
* @return {number} The number of registered observers
|
|
50
|
-
*/
|
|
51
|
-
count(): number;
|
|
52
|
-
/**
|
|
53
|
-
* @description Registers a new observer
|
|
54
|
-
* @summary Adds an observer to the collection with an optional filter function
|
|
55
|
-
* @param {Observer} observer - The observer to register
|
|
56
|
-
* @param {ObserverFilter} [filter] - Optional filter function to determine which events the observer receives
|
|
57
|
-
* @return {void}
|
|
58
|
-
*/
|
|
59
|
-
observe(observer: Observer, filter?: ObserverFilter): () => void;
|
|
60
|
-
/**
|
|
61
|
-
* @description Unregisters an observer
|
|
62
|
-
* @summary Removes an observer from the collection
|
|
63
|
-
* @param {Observer} observer - The observer to unregister
|
|
64
|
-
* @return {void}
|
|
65
|
-
*/
|
|
66
|
-
unObserve(observer: Observer): void;
|
|
67
|
-
/**
|
|
68
|
-
* @description Notifies all relevant observers about a database event
|
|
69
|
-
* @summary Filters observers based on their filter functions and calls refresh on each matching observer
|
|
70
|
-
* @param {string} table - The name of the table where the event occurred
|
|
71
|
-
* @param {OperationKeys|BulkCrudOperationKeys|string} event - The type of operation that occurred
|
|
72
|
-
* @param {EventIds} id - The identifier(s) of the affected record(s)
|
|
73
|
-
* @param {...any[]} args - Additional arguments to pass to the observers
|
|
74
|
-
* @return {Promise<void>} A promise that resolves when all observers have been notified
|
|
75
|
-
* @mermaid
|
|
76
|
-
* sequenceDiagram
|
|
77
|
-
* participant Client
|
|
78
|
-
* participant ObserverHandler
|
|
79
|
-
* participant Observer
|
|
80
|
-
*
|
|
81
|
-
* Client->>ObserverHandler: updateObservers(log, table, event, id, ...args)
|
|
82
|
-
*
|
|
83
|
-
* ObserverHandler->>ObserverHandler: Filter observers
|
|
84
|
-
*
|
|
85
|
-
* loop For each observer with matching filter
|
|
86
|
-
* alt Observer has filter
|
|
87
|
-
* ObserverHandler->>Observer: Apply filter(table, event, id)
|
|
88
|
-
* alt Filter throws error
|
|
89
|
-
* ObserverHandler->>Logger: Log error
|
|
90
|
-
* ObserverHandler-->>ObserverHandler: Skip observer
|
|
91
|
-
* else Filter returns true
|
|
92
|
-
* ObserverHandler->>Observer: refresh(table, event, id, ...args)
|
|
93
|
-
* else Filter returns false
|
|
94
|
-
* ObserverHandler-->>ObserverHandler: Skip observer
|
|
95
|
-
* end
|
|
96
|
-
* else No filter
|
|
97
|
-
* ObserverHandler->>Observer: refresh(table, event, id, ...args)
|
|
98
|
-
* end
|
|
99
|
-
* end
|
|
100
|
-
*
|
|
101
|
-
* ObserverHandler->>ObserverHandler: Process results
|
|
102
|
-
* loop For each result
|
|
103
|
-
* alt Result is rejected
|
|
104
|
-
* ObserverHandler->>Logger: Log error
|
|
105
|
-
* end
|
|
106
|
-
* end
|
|
107
|
-
*
|
|
108
|
-
* ObserverHandler-->>Client: Return
|
|
109
|
-
*/
|
|
110
|
-
updateObservers<M extends Model>(model: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<any>): Promise<void>;
|
|
111
|
-
}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { SequenceOptions, SequenceOptionsType } from "../interfaces/SequenceOptions";
|
|
3
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
-
import { ContextualizedArgs, ContextualLoggedClass, MaybeContextualArg, MethodOrOperation } from "../utils/ContextualLoggedClass";
|
|
5
|
-
import { Adapter } from "./Adapter";
|
|
6
|
-
import { Repo } from "../repository/Repository";
|
|
7
|
-
import { SequenceModel } from "../model/SequenceModel";
|
|
8
|
-
import { Context } from "./Context";
|
|
9
|
-
import { MultiLock } from "@decaf-ts/transactional-decorators";
|
|
10
|
-
import type { ContextOf, FlagsOf } from "./types";
|
|
11
|
-
/**
|
|
12
|
-
* @description Abstract base class for sequence generation
|
|
13
|
-
* @summary Provides a framework for generating sequential values (like primary keys) in the persistence layer.
|
|
14
|
-
* Implementations of this class handle the specifics of how sequences are stored and incremented in different
|
|
15
|
-
* database systems.
|
|
16
|
-
* @param {SequenceOptions} options - Configuration options for the sequence generator
|
|
17
|
-
* @class Sequence
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* // Example implementation for a specific database
|
|
21
|
-
* class PostgresSequence extends Sequence {
|
|
22
|
-
* constructor(options: SequenceOptions) {
|
|
23
|
-
* super(options);
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
* async next(): Promise<number> {
|
|
27
|
-
* // Implementation to get next value from PostgreSQL sequence
|
|
28
|
-
* const result = await this.options.executor.raw(`SELECT nextval('${this.options.name}')`);
|
|
29
|
-
* return parseInt(result.rows[0].nextval);
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* async current(): Promise<number> {
|
|
33
|
-
* // Implementation to get current value from PostgreSQL sequence
|
|
34
|
-
* const result = await this.options.executor.raw(`SELECT currval('${this.options.name}')`);
|
|
35
|
-
* return parseInt(result.rows[0].currval);
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
* async range(count: number): Promise<number[]> {
|
|
39
|
-
* // Implementation to get a range of values
|
|
40
|
-
* const values: number[] = [];
|
|
41
|
-
* for (let i = 0; i < count; i++) {
|
|
42
|
-
* values.push(await this.next());
|
|
43
|
-
* }
|
|
44
|
-
* return values;
|
|
45
|
-
* }
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* // Usage
|
|
49
|
-
* const sequence = new PostgresSequence({
|
|
50
|
-
* name: 'user_id_seq',
|
|
51
|
-
* executor: dbExecutor
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* const nextId = await sequence.next();
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare class Sequence<A extends Adapter<any, any, any, any> = Adapter<any, any, any, any>> extends ContextualLoggedClass<any> {
|
|
58
|
-
protected readonly options: SequenceOptions;
|
|
59
|
-
protected readonly adapter: A;
|
|
60
|
-
protected repo: Repo<SequenceModel>;
|
|
61
|
-
protected static readonly lock: MultiLock;
|
|
62
|
-
/**
|
|
63
|
-
* @description Creates a new sequence instance
|
|
64
|
-
* @summary Protected constructor that initializes the sequence with the provided options
|
|
65
|
-
*/
|
|
66
|
-
constructor(options: SequenceOptions, adapter: A, overrides?: Partial<FlagsOf<A>>);
|
|
67
|
-
/**
|
|
68
|
-
* @description Retrieves the current value of the sequence
|
|
69
|
-
* @summary Gets the current value of the sequence from storage. If the sequence
|
|
70
|
-
* doesn't exist yet, it returns the configured starting value.
|
|
71
|
-
* @return A promise that resolves to the current sequence value
|
|
72
|
-
*/
|
|
73
|
-
current(...args: MaybeContextualArg<any>): Promise<string | number | bigint>;
|
|
74
|
-
/**
|
|
75
|
-
* @description Increments the sequence value
|
|
76
|
-
* @summary Increases the current sequence value by the specified amount and persists
|
|
77
|
-
* the new value to storage. This method handles both numeric and BigInt sequence types.
|
|
78
|
-
* @param {string | number | bigint} current - The current value of the sequence
|
|
79
|
-
* @param {number} [count] - Optional amount to increment by, defaults to the sequence's incrementBy value
|
|
80
|
-
* @return A promise that resolves to the new sequence value after incrementing
|
|
81
|
-
*/
|
|
82
|
-
protected increment(count: number | undefined, context: Context<any>): Promise<string | number | bigint>;
|
|
83
|
-
/**
|
|
84
|
-
* @description Gets the next value in the sequence
|
|
85
|
-
* @summary Retrieves the current value of the sequence and increments it by the
|
|
86
|
-
* configured increment amount. This is the main method used to get a new sequential value.
|
|
87
|
-
* @return A promise that resolves to the next value in the sequence
|
|
88
|
-
*/
|
|
89
|
-
next(...argz: MaybeContextualArg<any>): Promise<number | string | bigint>;
|
|
90
|
-
/**
|
|
91
|
-
* @description Generates a range of sequential values
|
|
92
|
-
* @summary Retrieves a specified number of sequential values from the sequence.
|
|
93
|
-
* This is useful when you need to allocate multiple IDs at once.
|
|
94
|
-
* The method increments the sequence by the total amount needed and returns all values in the range.
|
|
95
|
-
* @param {number} count - The number of sequential values to generate
|
|
96
|
-
* @return A promise that resolves to an array of sequential values
|
|
97
|
-
*/
|
|
98
|
-
range(count: number, ...argz: MaybeContextualArg<any>): Promise<(number | string | bigint)[]>;
|
|
99
|
-
/**
|
|
100
|
-
* @description Ensures the sequence exists and is at least a given value
|
|
101
|
-
* @summary Upserts the sequence record to the provided value when missing, and optionally only when the
|
|
102
|
-
* provided value is greater than the persisted one. This is used by decorators that want to "seed" a
|
|
103
|
-
* sequence based on an existing model value (for example when overriding/bootstrapping sequences).
|
|
104
|
-
*/
|
|
105
|
-
ensureAtLeast(value: string | number | bigint, ...argz: MaybeContextualArg<any>): Promise<string | number | bigint>;
|
|
106
|
-
protected parse(value: string | number | bigint): string | number | bigint;
|
|
107
|
-
protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<typeof this.adapter>, ARGS>, operation: METHOD): ContextualizedArgs<ContextOf<typeof this.adapter>, ARGS, METHOD extends string ? true : false>;
|
|
108
|
-
protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<typeof this.adapter>, ARGS>, operation: METHOD, allowCreate: false): ContextualizedArgs<ContextOf<typeof this.adapter>, ARGS, METHOD extends string ? true : false>;
|
|
109
|
-
protected logCtx<ARGS extends any[] = any[], METHOD extends MethodOrOperation = MethodOrOperation>(args: MaybeContextualArg<ContextOf<typeof this.adapter>, ARGS>, operation: METHOD, allowCreate: true): Promise<ContextualizedArgs<ContextOf<typeof this.adapter>, ARGS, METHOD extends string ? true : false>>;
|
|
110
|
-
/**
|
|
111
|
-
* @description Gets the primary key sequence name for a model
|
|
112
|
-
* @summary Utility method that returns the standardized sequence name for a model's primary key
|
|
113
|
-
* @template M - The model type
|
|
114
|
-
* @param {M|Constructor<M>} model - The model instance or constructor
|
|
115
|
-
* @return {string} The sequence name for the model's primary key
|
|
116
|
-
*/
|
|
117
|
-
static pk<M extends Model>(model: M | Constructor<M>): string;
|
|
118
|
-
/**
|
|
119
|
-
* @description Parses a sequence value to the appropriate type
|
|
120
|
-
* @summary Converts a sequence value to the specified type (Number or BigInt)
|
|
121
|
-
* @param {"Number"|"BigInt"|undefined} type - The target type to convert to
|
|
122
|
-
* @param {string|number|bigint} value - The value to convert
|
|
123
|
-
* @return {string|number|bigint} The converted value
|
|
124
|
-
*/
|
|
125
|
-
static parseValue(type: SequenceOptionsType, value: string | number | bigint): string | number | bigint;
|
|
126
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { BulkCrudOperationKeys, OperationKeys } from "@decaf-ts/db-decorators";
|
|
2
|
-
import { AdapterFlags, ContextFlags } from "./types";
|
|
3
|
-
import { PreparedStatementKeys } from "../query/constants";
|
|
4
|
-
/**
|
|
5
|
-
* @description Persistence-related constant keys
|
|
6
|
-
* @summary Enum containing string constants used throughout the persistence layer for metadata, relations, and other persistence-related operations
|
|
7
|
-
* @enum {string}
|
|
8
|
-
* @readonly
|
|
9
|
-
* @memberOf module:core
|
|
10
|
-
*/
|
|
11
|
-
export declare enum PersistenceKeys {
|
|
12
|
-
PERSISTENCE = "persistence",
|
|
13
|
-
/** @description Key for index metadata */
|
|
14
|
-
INDEX = "index",
|
|
15
|
-
/** @description Key for sequence metadata */
|
|
16
|
-
SEQUENCE = "sequence",
|
|
17
|
-
/** @description Key for unique constraint metadata */
|
|
18
|
-
UNIQUE = "unique",
|
|
19
|
-
/** @description Key for adapter metadata */
|
|
20
|
-
ADAPTER = "adapter",
|
|
21
|
-
/** @description Template for injectable adapter names */
|
|
22
|
-
INJECTABLE = "decaf_{0}_adapter_for_{1}",
|
|
23
|
-
SERVICE = "service",
|
|
24
|
-
/** @description Key for table name metadata */
|
|
25
|
-
TABLE = "table",
|
|
26
|
-
/** @description Key for column name metadata */
|
|
27
|
-
COLUMN = "column",
|
|
28
|
-
/** @description Key for general metadata storage */
|
|
29
|
-
METADATA = "__metadata",
|
|
30
|
-
/** @description Key for created-by ownership metadata */
|
|
31
|
-
OWNERSHIP = "ownership",
|
|
32
|
-
/** @description Key for created-by ownership metadata */
|
|
33
|
-
CREATED_BY = "ownership.created-by",
|
|
34
|
-
/** @description Key for updated-by ownership metadata */
|
|
35
|
-
UPDATED_BY = "ownership.updated-by",
|
|
36
|
-
/** @description Key for relations metadata storage */
|
|
37
|
-
RELATIONS = "__relations",
|
|
38
|
-
/** @description Key for relations metadata storage */
|
|
39
|
-
RELATION = "relation",
|
|
40
|
-
/** @description Key for one-to-one relation metadata */
|
|
41
|
-
ONE_TO_ONE = "relation.one-to-one",
|
|
42
|
-
/** @description Key for one-to-many relation metadata */
|
|
43
|
-
ONE_TO_MANY = "relation.one-to-many",
|
|
44
|
-
/** @description Key for many-to-one relation metadata */
|
|
45
|
-
MANY_TO_ONE = "relation.many-to-one",
|
|
46
|
-
/** @description Key for many-to-one relation metadata */
|
|
47
|
-
MANY_TO_MANY = "relation.many-to-many",
|
|
48
|
-
/** @description Key for populate metadata */
|
|
49
|
-
POPULATE = "populate",
|
|
50
|
-
/** @description Key for populate metadata */
|
|
51
|
-
NO_VALIDATE = "no-validate",
|
|
52
|
-
/** @description Key for migration classes */
|
|
53
|
-
MIGRATION = "migration",
|
|
54
|
-
STATEMENT = "statement",
|
|
55
|
-
QUERY = "query",
|
|
56
|
-
UUID = "uuid",
|
|
57
|
-
TAG_FOR_DELETION = "tag_for_deletion",
|
|
58
|
-
INITIALIZATION = "initialization",
|
|
59
|
-
SHUTDOWN = "shutdown",
|
|
60
|
-
BY_KEY = "by-key",
|
|
61
|
-
AUTH = "auth",
|
|
62
|
-
AUTH_ROLE = "auth-role",
|
|
63
|
-
DECAF_ROUTE = "DecafRoute",
|
|
64
|
-
THROTTLE = "throttle",
|
|
65
|
-
PERSISTENT_VERSION = "persistent-version",
|
|
66
|
-
DEFAULT_QUERY_ATTR = "default-query-attr"
|
|
67
|
-
}
|
|
68
|
-
export declare const DefaultContextFlags: ContextFlags<any>;
|
|
69
|
-
export declare const DefaultAdapterFlags: AdapterFlags;
|
|
70
|
-
export declare const TransactionOperationKeys: (string | OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys)[];
|
|
71
|
-
export declare const NonTransactionOperationKeys: (string | OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys)[];
|
|
72
|
-
export declare const SelectOperationKeys: (string | OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys)[];
|
|
73
|
-
export declare const MultipleSelectOperationKeys: (string | OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys)[];
|
|
74
|
-
export declare const PaginationOperationKeys: (string | OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys)[];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
2
|
-
import { ContextOf } from "./types";
|
|
3
|
-
import { Repo } from "../repository/Repository";
|
|
4
|
-
import { ContextualArgs } from "../utils/ContextualLoggedClass";
|
|
5
|
-
/**
|
|
6
|
-
* @description Handler function that sets a timestamp property to the current timestamp.
|
|
7
|
-
* @summary Updates a model property with the current timestamp from the repository context.
|
|
8
|
-
* @template M - The model type extending Model
|
|
9
|
-
* @template R - The repository type extending IRepository
|
|
10
|
-
* @template V - The data type for the operation
|
|
11
|
-
* @template F - The repository flags type
|
|
12
|
-
* @template C - The context type
|
|
13
|
-
* @param {C} context - The repository context containing the current timestamp
|
|
14
|
-
* @param {V} data - The data being processed
|
|
15
|
-
* @param key - The property key to update
|
|
16
|
-
* @param {M} model - The model instance being updated
|
|
17
|
-
* @return {Promise<void>} A promise that resolves when the timestamp has been set
|
|
18
|
-
* @function uuidCreateUpdateHandler
|
|
19
|
-
*/
|
|
20
|
-
export declare function uuidCreateUpdateHandler<M extends Model<boolean>, R extends Repo<M>>(this: R, context: ContextOf<R>, data: UUIDMetadata, key: keyof M, model: M): Promise<void>;
|
|
21
|
-
export type UUIDMetadata = {
|
|
22
|
-
update: boolean;
|
|
23
|
-
seed?: string | (<M extends Model>(model: M, ...args: ContextualArgs<any>) => string);
|
|
24
|
-
args?: any[];
|
|
25
|
-
};
|
|
26
|
-
export declare function uuid(...args: any[]): (target: any, propertyKey?: any) => void;
|
|
27
|
-
export declare function uuid(update: boolean, ...args: any[]): (target: any, propertyKey?: any) => void;
|
|
28
|
-
export declare function uuid(seed: string | (<M extends Model>(model: M, ...args: ContextualArgs<any>) => string), ...args: any[]): (target: any, propertyKey?: any) => void;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { InternalError } from "@decaf-ts/db-decorators";
|
|
2
|
-
/**
|
|
3
|
-
* @description Error thrown when an unsupported operation is attempted
|
|
4
|
-
* @summary This error is thrown when an operation is requested that is not supported by the current
|
|
5
|
-
* persistence adapter or configuration. It extends the BaseError class and sets a 500 status code.
|
|
6
|
-
* @param {string|Error} msg - The error message or an Error object to wrap
|
|
7
|
-
* @class UnsupportedError
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // Throwing an UnsupportedError
|
|
11
|
-
* if (!adapter.supportsTransactions()) {
|
|
12
|
-
* throw new UnsupportedError('Transactions are not supported by this adapter');
|
|
13
|
-
* }
|
|
14
|
-
*
|
|
15
|
-
* // Catching an UnsupportedError
|
|
16
|
-
* try {
|
|
17
|
-
* await adapter.beginTransaction();
|
|
18
|
-
* } catch (error) {
|
|
19
|
-
* if (error instanceof UnsupportedError) {
|
|
20
|
-
* console.error('Operation not supported:', error.message);
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
export declare class UnsupportedError extends InternalError {
|
|
26
|
-
constructor(msg: string | Error | unknown);
|
|
27
|
-
}
|
|
28
|
-
export declare class MigrationError extends InternalError {
|
|
29
|
-
constructor(msg: string | Error | unknown, name?: string);
|
|
30
|
-
}
|
|
31
|
-
export declare class MigrationRuleError extends MigrationError {
|
|
32
|
-
constructor(msg: string | Error | unknown);
|
|
33
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { AllOperationKeys, ObserverFilter } from "./types";
|
|
2
|
-
import { Model, ModelConstructor } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import type { Repo } from "../repository/Repository";
|
|
4
|
-
export declare function onlyOnCreate(clazz: ModelConstructor<any>): ObserverFilter;
|
|
5
|
-
export declare function onlyOnUpdate(clazz: ModelConstructor<any>): ObserverFilter;
|
|
6
|
-
export declare function onlyOnDelete(clazz: ModelConstructor<any>): ObserverFilter;
|
|
7
|
-
export declare function onlyOnTransactional(clazz: ModelConstructor<any>): ObserverFilter;
|
|
8
|
-
export declare function onlyOnSingle(clazz: ModelConstructor<any>): ObserverFilter;
|
|
9
|
-
export declare function onlyOnBulk(clazz: ModelConstructor<any>): ObserverFilter;
|
|
10
|
-
export declare function onlyOnFilter(clazz: ModelConstructor<any>, ops: AllOperationKeys[]): ObserverFilter;
|
|
11
|
-
export type AvailableFilters = typeof DefaultRepositoryFilters;
|
|
12
|
-
export declare const DefaultRepositoryFilters: {
|
|
13
|
-
onlyOnCreate: typeof onlyOnCreate;
|
|
14
|
-
onlyOnUpdate: typeof onlyOnUpdate;
|
|
15
|
-
onlyOnDelete: typeof onlyOnDelete;
|
|
16
|
-
onlyOnTransactional: typeof onlyOnTransactional;
|
|
17
|
-
onlyOnSingle: typeof onlyOnSingle;
|
|
18
|
-
onlyOnBulk: typeof onlyOnBulk;
|
|
19
|
-
};
|
|
20
|
-
export declare function getFilters<M extends Model>(repo: Repo<M>): Record<keyof typeof DefaultRepositoryFilters, ObserverFilter>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface Generator<OUT extends string | number = string> {
|
|
2
|
-
generate(prev?: OUT): OUT | Promise<OUT>;
|
|
3
|
-
}
|
|
4
|
-
export declare class UUID implements Generator {
|
|
5
|
-
private static _instance;
|
|
6
|
-
generate(prev?: string): string | Promise<string>;
|
|
7
|
-
static get instance(): UUID;
|
|
8
|
-
}
|
|
9
|
-
export declare class Serial implements Generator {
|
|
10
|
-
private static _instance;
|
|
11
|
-
private count;
|
|
12
|
-
generate(prev?: string): string | Promise<string>;
|
|
13
|
-
static get instance(): Serial;
|
|
14
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description Exports for the persistence module.
|
|
3
|
-
* @summary This file exports all the necessary components for the persistence functionality, including Dispatch, constants, and more.
|
|
4
|
-
* @module core/persistence
|
|
5
|
-
*/
|
|
6
|
-
export * from "./Dispatch";
|
|
7
|
-
export * from "./constants";
|
|
8
|
-
export * from "./Context";
|
|
9
|
-
export * from "./ContextLock";
|
|
10
|
-
export * from "./decorators";
|
|
11
|
-
export * from "./errors";
|
|
12
|
-
export * from "./generators";
|
|
13
|
-
export * from "./event-filters";
|
|
14
|
-
export * from "./ObserverHandler";
|
|
15
|
-
export * from "./Sequence";
|
|
16
|
-
export * from "./types";
|
|
17
|
-
export * from "./transactions";
|
|
18
|
-
export * from "./Adapter";
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Adapter } from "../persistence/Adapter";
|
|
2
|
-
import { ContextLock } from "../persistence/ContextLock";
|
|
3
|
-
export declare function getAdapterTransaction(obj: any, ...args: any[]): import(".").AdapterTransaction<Adapter<any, any, any, any>>;
|
|
4
|
-
export declare function getContextLock(obj: any, ...args: any[]): ContextLock;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { BulkCrudOperationKeys, LoggerOfFlags, OperationKeys, RepositoryFlags, ContextFlags as CtxFlags } from "@decaf-ts/db-decorators";
|
|
2
|
-
import { Adapter } from "./Adapter";
|
|
3
|
-
import { Observable, type Observer } from "../interfaces/index";
|
|
4
|
-
import { Logger } from "@decaf-ts/logging";
|
|
5
|
-
import { Constructor } from "@decaf-ts/decoration";
|
|
6
|
-
import { Model } from "@decaf-ts/decorator-validation";
|
|
7
|
-
import { ContextualArgs, ContextualLoggedClass } from "../utils/ContextualLoggedClass";
|
|
8
|
-
import { Context } from "./Context";
|
|
9
|
-
import { Repository } from "../repository/Repository";
|
|
10
|
-
import { PersistenceKeys } from "./constants";
|
|
11
|
-
import { PreparedStatementKeys } from "../query/constants";
|
|
12
|
-
import { ContextLock } from "./ContextLock";
|
|
13
|
-
export type FlagsOfContext<C extends Context<any>> = C extends Context<infer F> ? F : never;
|
|
14
|
-
export type LoggerOfContext<C extends Context<any>> = LoggerOfFlags<FlagsOfContext<C>>;
|
|
15
|
-
export type ContextOfRepository<R extends Repository<any, any>> = R extends Repository<any, infer A> ? ContextOf<A> : never;
|
|
16
|
-
export type FlagsOfRepository<R extends Repository<any, any>> = FlagsOfContext<ContextOfRepository<R>>;
|
|
17
|
-
export type LoggerOfRepository<R extends Repository<any, any>> = LoggerOfContext<ContextOfRepository<R>>;
|
|
18
|
-
export type ContextOf<OBJ extends Repository<any, any> | Adapter<any, any, any, any> | ContextualLoggedClass<any>> = OBJ extends Adapter<any, any, any, infer C> ? C : OBJ extends Repository<any, any> ? ContextOfRepository<OBJ> : OBJ extends ContextualLoggedClass<infer C> ? C : never;
|
|
19
|
-
export type ConfigOf<OBJ extends Adapter<any, any, any, any>> = OBJ extends Adapter<infer C, any, any, any> ? C : never;
|
|
20
|
-
export type LoggerOfAdapter<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, infer C> ? LoggerOfContext<C> : never;
|
|
21
|
-
export type FlagsOfAdapter<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, infer C> ? FlagsOfContext<C> : never;
|
|
22
|
-
export type LoggerOf<OBJ extends AdapterFlags<any> | Context<any> | Adapter<any, any, any> | Repository<any, any>> = OBJ extends AdapterFlags<any> ? LoggerOfFlags<OBJ> : OBJ extends Context<any> ? LoggerOfContext<OBJ> : OBJ extends Repository<any, any> ? LoggerOfRepository<OBJ> : OBJ extends Adapter<any, any, any> ? LoggerOfAdapter<OBJ> : Logger;
|
|
23
|
-
export type ConfOf<A extends Adapter<any, any, any, any>> = A extends Adapter<infer C, any, any> ? C : never;
|
|
24
|
-
export type FlagsOf<OBJ extends Repository<any, any> | Adapter<any, any, any, any> | Context<any>> = OBJ extends Context<any> ? FlagsOfContext<OBJ> : OBJ extends Repository<any, any> ? FlagsOfRepository<OBJ> : OBJ extends Adapter<any, any, any, any> ? FlagsOfAdapter<OBJ> : never;
|
|
25
|
-
export type PersistenceObservable<CONTEXT extends Context<any>> = Observable<[
|
|
26
|
-
Observer,
|
|
27
|
-
ObserverFilter?
|
|
28
|
-
], [
|
|
29
|
-
Constructor | string,
|
|
30
|
-
OperationKeys | BulkCrudOperationKeys | string,
|
|
31
|
-
EventIds,
|
|
32
|
-
...ContextualArgs<CONTEXT>
|
|
33
|
-
]>;
|
|
34
|
-
export type PersistenceObserver<CONTEXT extends Context<any>> = Observer<[
|
|
35
|
-
Constructor | string,
|
|
36
|
-
OperationKeys | BulkCrudOperationKeys | string,
|
|
37
|
-
EventIds,
|
|
38
|
-
...ContextualArgs<CONTEXT>
|
|
39
|
-
]>;
|
|
40
|
-
/**
|
|
41
|
-
* @description Type representing possible ID formats for database events
|
|
42
|
-
* @summary A union type that defines the possible formats for event identifiers in the persistence layer.
|
|
43
|
-
* These can be single values (string, number, bigint) or arrays of these types.
|
|
44
|
-
* @typedef {(string|number|bigint|string[]|number[]|bigint[])} EventIds
|
|
45
|
-
* @memberOf module:core
|
|
46
|
-
*/
|
|
47
|
-
export type EventIds = string | number | bigint | string[] | number[] | bigint[];
|
|
48
|
-
export type ObserverFilter = (table: Constructor | string, event: AllOperationKeys, id: EventIds, ...args: ContextualArgs<any>) => boolean;
|
|
49
|
-
export type InferredAdapterConfig<A> = A extends Adapter<infer CONF, any, any> ? CONF : never;
|
|
50
|
-
export interface AdapterDispatch<A extends Adapter<any, any, any, any>> extends PersistenceObservable<ContextOf<A>> {
|
|
51
|
-
close(...args: ContextualArgs<ContextOf<A>>): Promise<void>;
|
|
52
|
-
updateObservers<M extends Model>(table: Constructor<M> | string, event: OperationKeys | BulkCrudOperationKeys | string, id: EventIds, ...args: ContextualArgs<ContextOf<A>>): Promise<void>;
|
|
53
|
-
}
|
|
54
|
-
export type RepositoryFor<A extends Adapter<any, any, any, any>> = A extends Adapter<any, any, any, any> ? ReturnType<A["repository"]> : never;
|
|
55
|
-
export type PreparedModel = {
|
|
56
|
-
record: Record<string, any>;
|
|
57
|
-
id: string;
|
|
58
|
-
transient?: Record<string, any>;
|
|
59
|
-
};
|
|
60
|
-
export type ContextFlags<LOG extends Logger> = CtxFlags<LOG> & Pick<RepositoryFlags<LOG>, "operation" | "correlationId" | "ignoreDevSafeGuards" | "parentContext" | "childContexts"> & {
|
|
61
|
-
pending?: Record<string, string[]>;
|
|
62
|
-
transactionLock?: ContextLock;
|
|
63
|
-
};
|
|
64
|
-
export type AdapterFlags<LOG extends Logger = Logger> = RepositoryFlags<LOG> & ContextFlags<LOG> & {
|
|
65
|
-
allowGenerationOverride: boolean;
|
|
66
|
-
afterQueryHandlers: boolean;
|
|
67
|
-
enforceUpdateValidation: boolean;
|
|
68
|
-
allowRawStatements: boolean;
|
|
69
|
-
forcePrepareSimpleQueries: boolean;
|
|
70
|
-
forcePrepareComplexQueries: boolean;
|
|
71
|
-
cacheForPopulate: Record<string, any>;
|
|
72
|
-
preferFromCache: boolean;
|
|
73
|
-
noEmit: boolean;
|
|
74
|
-
noEmitSingle: boolean;
|
|
75
|
-
noEmitBulk: boolean;
|
|
76
|
-
breakOnSingleFailureInBulk: boolean;
|
|
77
|
-
observeFullResult: boolean;
|
|
78
|
-
paginateByBookmark: boolean;
|
|
79
|
-
dryRun: boolean;
|
|
80
|
-
lock?: ContextLock;
|
|
81
|
-
};
|
|
82
|
-
export type RawResult<R, D extends boolean> = D extends true ? R : {
|
|
83
|
-
data: R;
|
|
84
|
-
count?: number;
|
|
85
|
-
};
|
|
86
|
-
export type AllOperationKeys = OperationKeys | BulkCrudOperationKeys | PersistenceKeys | PreparedStatementKeys | string;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { AttributeOption, ConditionBuilderOption } from "./options";
|
|
2
|
-
import { ConditionalAsync, Model, ModelArg, ModelErrorDefinition } from "@decaf-ts/decorator-validation";
|
|
3
|
-
import { GroupOperator, Operator } from "./constants";
|
|
4
|
-
type InferAsync<M> = M extends Model<infer A> ? A : false;
|
|
5
|
-
/**
|
|
6
|
-
* @description Represents a logical condition for database queries
|
|
7
|
-
* @summary A class that encapsulates query conditions with support for complex logical operations.
|
|
8
|
-
* This class allows for building and combining query conditions using logical operators (AND, OR, NOT)
|
|
9
|
-
* and comparison operators (equals, not equals, greater than, etc.).
|
|
10
|
-
* @template M - The model type this condition operates on
|
|
11
|
-
* @param {string | Condition<M>} attr1 - The attribute name or a nested condition
|
|
12
|
-
* @param {Operator | GroupOperator} operator - The operator to use for the condition
|
|
13
|
-
* @param {any} comparison - The value to compare against or another condition
|
|
14
|
-
* @class Condition
|
|
15
|
-
* @example
|
|
16
|
-
* // Create a simple condition
|
|
17
|
-
* const nameCondition = Condition.attribute("name").eq("John");
|
|
18
|
-
*
|
|
19
|
-
* // Create a complex condition
|
|
20
|
-
* const complexCondition = Condition.attribute("age").gt(18)
|
|
21
|
-
* .and(Condition.attribute("status").eq("active"));
|
|
22
|
-
*
|
|
23
|
-
* // Use the builder pattern
|
|
24
|
-
* const userQuery = Condition.builder()
|
|
25
|
-
* .attribute("email").regexp(".*@example.com")
|
|
26
|
-
* .and(Condition.attribute("lastLogin").gt(new Date("2023-01-01")));
|
|
27
|
-
* @mermaid
|
|
28
|
-
* sequenceDiagram
|
|
29
|
-
* participant Dev
|
|
30
|
-
* participant Condition
|
|
31
|
-
* Dev->>Condition: builder().attribute("age").gt(18)
|
|
32
|
-
* Condition-->>Dev: Condition(age > 18)
|
|
33
|
-
* Dev->>Condition: .and(attribute("status").eq("active"))
|
|
34
|
-
* Condition-->>Dev: Condition((age > 18) AND (status = "active"))
|
|
35
|
-
*/
|
|
36
|
-
export declare class Condition<M extends Model<any>> extends Model<InferAsync<M>> {
|
|
37
|
-
protected attr1?: string | Condition<M>;
|
|
38
|
-
protected operator?: Operator | GroupOperator;
|
|
39
|
-
protected comparison?: any;
|
|
40
|
-
private constructor();
|
|
41
|
-
private constructor();
|
|
42
|
-
/**
|
|
43
|
-
* @description Combines this condition with another using logical AND
|
|
44
|
-
* @summary Joins two conditions with an AND operator, requiring both to be true
|
|
45
|
-
* @param {Condition<M>} condition - The condition to combine with this one
|
|
46
|
-
* @return {Condition<M>} A new condition representing the AND operation
|
|
47
|
-
*/
|
|
48
|
-
and(condition: Condition<M>): Condition<M>;
|
|
49
|
-
/**
|
|
50
|
-
* @description Combines this condition with another using logical OR
|
|
51
|
-
* @summary Joins two conditions with an OR operator, requiring at least one to be true
|
|
52
|
-
* @param {Condition<M>} condition - The condition to combine with this one
|
|
53
|
-
* @return {Condition<M>} A new condition representing the OR operation
|
|
54
|
-
*/
|
|
55
|
-
or(condition: Condition<M>): Condition<M>;
|
|
56
|
-
/**
|
|
57
|
-
* @description Creates a negation condition
|
|
58
|
-
* @summary Excludes a value from the result by applying a NOT operator
|
|
59
|
-
* @param {any} val - The value to negate
|
|
60
|
-
* @return {Condition<M>} A new condition representing the NOT operation
|
|
61
|
-
*/
|
|
62
|
-
not(val: any): Condition<M>;
|
|
63
|
-
/**
|
|
64
|
-
* @description Validates the condition and checks for errors
|
|
65
|
-
* @summary Extends the base validation to ensure the condition is properly formed
|
|
66
|
-
* @param {...string[]} exceptions - Fields to exclude from validation
|
|
67
|
-
* @return {ModelErrorDefinition | undefined} Error definition if validation fails, undefined otherwise
|
|
68
|
-
*/
|
|
69
|
-
hasErrors(...exceptions: string[]): ConditionalAsync<InferAsync<M>, ModelErrorDefinition | undefined>;
|
|
70
|
-
/**
|
|
71
|
-
* @description Creates a new condition that combines two conditions with logical AND
|
|
72
|
-
* @summary Static method that joins two conditions with an AND operator, requiring both to be true
|
|
73
|
-
* @template M - The model type this condition operates on
|
|
74
|
-
* @param {Condition<M>} condition1 - The first condition
|
|
75
|
-
* @param {Condition<M>} condition2 - The second condition
|
|
76
|
-
* @return {Condition<M>} A new condition representing the AND operation
|
|
77
|
-
*/
|
|
78
|
-
static and<M extends Model>(condition1: Condition<M>, condition2: Condition<M>): Condition<M>;
|
|
79
|
-
/**
|
|
80
|
-
* @description Creates a new condition that combines two conditions with logical OR
|
|
81
|
-
* @summary Static method that joins two conditions with an OR operator, requiring at least one to be true
|
|
82
|
-
* @template M - The model type this condition operates on
|
|
83
|
-
* @param {Condition<M>} condition1 - The first condition
|
|
84
|
-
* @param {Condition<M>} condition2 - The second condition
|
|
85
|
-
* @return {Condition<M>} A new condition representing the OR operation
|
|
86
|
-
*/
|
|
87
|
-
static or<M extends Model>(condition1: Condition<M>, condition2: Condition<M>): Condition<M>;
|
|
88
|
-
/**
|
|
89
|
-
* @description Creates a new condition that groups two conditions with a specified operator
|
|
90
|
-
* @summary Private static method that combines two conditions using the specified group operator
|
|
91
|
-
* @template M - The model type this condition operates on
|
|
92
|
-
* @param {Condition<M>} condition1 - The first condition
|
|
93
|
-
* @param {GroupOperator} operator - The group operator to use (AND, OR)
|
|
94
|
-
* @param {Condition<M>} condition2 - The second condition
|
|
95
|
-
* @return {Condition<M>} A new condition representing the grouped operation
|
|
96
|
-
*/
|
|
97
|
-
private static group;
|
|
98
|
-
/**
|
|
99
|
-
* @description Creates a condition builder for a specific model attribute
|
|
100
|
-
* @summary Static method that initializes a condition builder with the specified attribute
|
|
101
|
-
* @template M - The model type this condition operates on
|
|
102
|
-
* @param attr - The model attribute to build a condition for
|
|
103
|
-
* @return {AttributeOption<M>} A condition builder initialized with the attribute
|
|
104
|
-
*/
|
|
105
|
-
static attribute<M extends Model>(attr: keyof M): AttributeOption<M>;
|
|
106
|
-
/**
|
|
107
|
-
* @description Alias for the attribute method
|
|
108
|
-
* @summary Shorthand method that initializes a condition builder with the specified attribute
|
|
109
|
-
* @template M - The model type this condition operates on
|
|
110
|
-
* @param attr - The model attribute to build a condition for
|
|
111
|
-
* @return {AttributeOption<M>} A condition builder initialized with the attribute
|
|
112
|
-
*/
|
|
113
|
-
static attr<M extends Model>(attr: keyof M): AttributeOption<M>;
|
|
114
|
-
/**
|
|
115
|
-
* @description Provides a fluent API to build query conditions
|
|
116
|
-
* @summary A builder class that simplifies the creation of database query conditions
|
|
117
|
-
* with a chainable interface for setting attributes and operators
|
|
118
|
-
* @template M - The model type this condition builder operates on
|
|
119
|
-
* @class ConditionBuilder
|
|
120
|
-
*/
|
|
121
|
-
private static Builder;
|
|
122
|
-
/**
|
|
123
|
-
* @description Creates a new condition builder
|
|
124
|
-
* @summary Factory method that returns a new instance of the condition builder
|
|
125
|
-
* @template M - The model type this condition builder will operate on
|
|
126
|
-
* @return {ConditionBuilderOption<M>} A new condition builder instance
|
|
127
|
-
*/
|
|
128
|
-
static builder<M extends Model>(): ConditionBuilderOption<M>;
|
|
129
|
-
static from(obj: ModelArg<Condition<any>>): Condition<Model<any>>;
|
|
130
|
-
}
|
|
131
|
-
export {};
|