@gravito/echo 3.0.0 → 3.1.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/README.md +211 -0
- package/dist/atlas/src/DB.d.ts +301 -0
- package/dist/atlas/src/OrbitAtlas.d.ts +9 -0
- package/dist/atlas/src/config/defineConfig.d.ts +14 -0
- package/dist/atlas/src/config/index.d.ts +7 -0
- package/dist/atlas/src/config/loadConfig.d.ts +48 -0
- package/dist/atlas/src/connection/Connection.d.ts +108 -0
- package/dist/atlas/src/connection/ConnectionManager.d.ts +111 -0
- package/dist/atlas/src/drivers/BunSQLDriver.d.ts +32 -0
- package/dist/atlas/src/drivers/BunSQLPreparedStatement.d.ts +118 -0
- package/dist/atlas/src/drivers/MongoDBDriver.d.ts +36 -0
- package/dist/atlas/src/drivers/MySQLDriver.d.ts +66 -0
- package/dist/atlas/src/drivers/PostgresDriver.d.ts +83 -0
- package/dist/atlas/src/drivers/RedisDriver.d.ts +43 -0
- package/dist/atlas/src/drivers/SQLiteDriver.d.ts +45 -0
- package/dist/atlas/src/drivers/types.d.ts +260 -0
- package/dist/atlas/src/errors/index.d.ts +45 -0
- package/dist/atlas/src/grammar/Grammar.d.ts +342 -0
- package/dist/atlas/src/grammar/MongoGrammar.d.ts +47 -0
- package/dist/atlas/src/grammar/MySQLGrammar.d.ts +54 -0
- package/dist/atlas/src/grammar/NullGrammar.d.ts +35 -0
- package/dist/atlas/src/grammar/PostgresGrammar.d.ts +62 -0
- package/dist/atlas/src/grammar/SQLiteGrammar.d.ts +32 -0
- package/dist/atlas/src/index.d.ts +67 -0
- package/dist/atlas/src/migration/Migration.d.ts +64 -0
- package/dist/atlas/src/migration/MigrationRepository.d.ts +65 -0
- package/dist/atlas/src/migration/Migrator.d.ts +110 -0
- package/dist/atlas/src/migration/index.d.ts +6 -0
- package/dist/atlas/src/observability/AtlasMetrics.d.ts +11 -0
- package/dist/atlas/src/observability/AtlasObservability.d.ts +15 -0
- package/dist/atlas/src/observability/AtlasTracer.d.ts +12 -0
- package/dist/atlas/src/observability/index.d.ts +9 -0
- package/dist/atlas/src/orm/index.d.ts +5 -0
- package/dist/atlas/src/orm/model/DirtyTracker.d.ts +121 -0
- package/dist/atlas/src/orm/model/Model.d.ts +449 -0
- package/dist/atlas/src/orm/model/ModelRegistry.d.ts +20 -0
- package/dist/atlas/src/orm/model/concerns/HasAttributes.d.ts +136 -0
- package/dist/atlas/src/orm/model/concerns/HasEvents.d.ts +36 -0
- package/dist/atlas/src/orm/model/concerns/HasPersistence.d.ts +87 -0
- package/dist/atlas/src/orm/model/concerns/HasRelationships.d.ts +117 -0
- package/dist/atlas/src/orm/model/concerns/HasSerialization.d.ts +64 -0
- package/dist/atlas/src/orm/model/concerns/applyMixins.d.ts +15 -0
- package/dist/atlas/src/orm/model/concerns/index.d.ts +12 -0
- package/dist/atlas/src/orm/model/decorators.d.ts +109 -0
- package/dist/atlas/src/orm/model/errors.d.ts +52 -0
- package/dist/atlas/src/orm/model/index.d.ts +10 -0
- package/dist/atlas/src/orm/model/relationships.d.ts +207 -0
- package/dist/atlas/src/orm/model/types.d.ts +12 -0
- package/dist/atlas/src/orm/schema/SchemaRegistry.d.ts +123 -0
- package/dist/atlas/src/orm/schema/SchemaSniffer.d.ts +54 -0
- package/dist/atlas/src/orm/schema/index.d.ts +6 -0
- package/dist/atlas/src/orm/schema/types.d.ts +85 -0
- package/dist/atlas/src/query/Expression.d.ts +60 -0
- package/dist/atlas/src/query/NPlusOneDetector.d.ts +10 -0
- package/dist/atlas/src/query/QueryBuilder.d.ts +573 -0
- package/dist/atlas/src/query/clauses/GroupByClause.d.ts +51 -0
- package/dist/atlas/src/query/clauses/HavingClause.d.ts +70 -0
- package/dist/atlas/src/query/clauses/JoinClause.d.ts +87 -0
- package/dist/atlas/src/query/clauses/LimitClause.d.ts +82 -0
- package/dist/atlas/src/query/clauses/OrderByClause.d.ts +69 -0
- package/dist/atlas/src/query/clauses/SelectClause.d.ts +71 -0
- package/dist/atlas/src/query/clauses/WhereClause.d.ts +167 -0
- package/dist/atlas/src/query/clauses/index.d.ts +11 -0
- package/dist/atlas/src/schema/Blueprint.d.ts +276 -0
- package/dist/atlas/src/schema/ColumnDefinition.d.ts +154 -0
- package/dist/atlas/src/schema/ForeignKeyDefinition.d.ts +37 -0
- package/dist/atlas/src/schema/Schema.d.ts +131 -0
- package/dist/atlas/src/schema/grammars/MySQLSchemaGrammar.d.ts +23 -0
- package/dist/atlas/src/schema/grammars/PostgresSchemaGrammar.d.ts +26 -0
- package/dist/atlas/src/schema/grammars/SQLiteSchemaGrammar.d.ts +28 -0
- package/dist/atlas/src/schema/grammars/SchemaGrammar.d.ts +97 -0
- package/dist/atlas/src/schema/grammars/index.d.ts +7 -0
- package/dist/atlas/src/schema/index.d.ts +8 -0
- package/dist/atlas/src/seed/Factory.d.ts +90 -0
- package/dist/atlas/src/seed/Seeder.d.ts +28 -0
- package/dist/atlas/src/seed/SeederRunner.d.ts +74 -0
- package/dist/atlas/src/seed/index.d.ts +6 -0
- package/dist/atlas/src/types/index.d.ts +1100 -0
- package/dist/atlas/src/utils/levenshtein.d.ts +9 -0
- package/dist/core/src/Application.d.ts +215 -0
- package/dist/core/src/CommandKernel.d.ts +33 -0
- package/dist/core/src/ConfigManager.d.ts +26 -0
- package/dist/core/src/Container.d.ts +108 -0
- package/dist/core/src/ErrorHandler.d.ts +63 -0
- package/dist/core/src/Event.d.ts +5 -0
- package/dist/core/src/EventManager.d.ts +123 -0
- package/dist/core/src/GlobalErrorHandlers.d.ts +47 -0
- package/dist/core/src/GravitoServer.d.ts +28 -0
- package/dist/core/src/HookManager.d.ts +496 -0
- package/dist/core/src/Listener.d.ts +4 -0
- package/dist/core/src/Logger.d.ts +20 -0
- package/dist/core/src/PlanetCore.d.ts +289 -0
- package/dist/core/src/Route.d.ts +36 -0
- package/dist/core/src/Router.d.ts +284 -0
- package/dist/core/src/ServiceProvider.d.ts +156 -0
- package/dist/core/src/adapters/GravitoEngineAdapter.d.ts +27 -0
- package/dist/core/src/adapters/PhotonAdapter.d.ts +171 -0
- package/dist/core/src/adapters/bun/BunContext.d.ts +45 -0
- package/dist/core/src/adapters/bun/BunNativeAdapter.d.ts +31 -0
- package/dist/core/src/adapters/bun/BunRequest.d.ts +31 -0
- package/dist/core/src/adapters/bun/RadixNode.d.ts +19 -0
- package/dist/core/src/adapters/bun/RadixRouter.d.ts +31 -0
- package/dist/core/src/adapters/bun/types.d.ts +20 -0
- package/dist/core/src/adapters/photon-types.d.ts +73 -0
- package/dist/core/src/adapters/types.d.ts +235 -0
- package/dist/core/src/engine/AOTRouter.d.ts +124 -0
- package/dist/core/src/engine/FastContext.d.ts +100 -0
- package/dist/core/src/engine/Gravito.d.ts +137 -0
- package/dist/core/src/engine/MinimalContext.d.ts +79 -0
- package/dist/core/src/engine/analyzer.d.ts +27 -0
- package/dist/core/src/engine/constants.d.ts +23 -0
- package/dist/core/src/engine/index.d.ts +26 -0
- package/dist/core/src/engine/path.d.ts +26 -0
- package/dist/core/src/engine/pool.d.ts +83 -0
- package/dist/core/src/engine/types.d.ts +143 -0
- package/dist/core/src/events/CircuitBreaker.d.ts +229 -0
- package/dist/core/src/events/DeadLetterQueue.d.ts +145 -0
- package/dist/core/src/events/EventBackend.d.ts +11 -0
- package/dist/core/src/events/EventOptions.d.ts +109 -0
- package/dist/core/src/events/EventPriorityQueue.d.ts +202 -0
- package/dist/core/src/events/IdempotencyCache.d.ts +60 -0
- package/dist/core/src/events/index.d.ts +14 -0
- package/dist/core/src/events/observability/EventMetrics.d.ts +132 -0
- package/dist/core/src/events/observability/EventTracer.d.ts +68 -0
- package/dist/core/src/events/observability/EventTracing.d.ts +161 -0
- package/dist/core/src/events/observability/OTelEventMetrics.d.ts +240 -0
- package/dist/core/src/events/observability/ObservableHookManager.d.ts +108 -0
- package/dist/core/src/events/observability/index.d.ts +20 -0
- package/dist/core/src/events/observability/metrics-types.d.ts +16 -0
- package/dist/core/src/events/types.d.ts +75 -0
- package/dist/core/src/exceptions/AuthenticationException.d.ts +8 -0
- package/dist/core/src/exceptions/AuthorizationException.d.ts +8 -0
- package/dist/core/src/exceptions/CircularDependencyException.d.ts +9 -0
- package/dist/core/src/exceptions/GravitoException.d.ts +23 -0
- package/dist/core/src/exceptions/HttpException.d.ts +9 -0
- package/dist/core/src/exceptions/ModelNotFoundException.d.ts +10 -0
- package/dist/core/src/exceptions/ValidationException.d.ts +22 -0
- package/dist/core/src/exceptions/index.d.ts +7 -0
- package/dist/core/src/helpers/Arr.d.ts +19 -0
- package/dist/core/src/helpers/Str.d.ts +23 -0
- package/dist/core/src/helpers/data.d.ts +25 -0
- package/dist/core/src/helpers/errors.d.ts +34 -0
- package/dist/core/src/helpers/response.d.ts +41 -0
- package/dist/core/src/helpers.d.ts +338 -0
- package/dist/core/src/http/CookieJar.d.ts +51 -0
- package/dist/core/src/http/cookie.d.ts +29 -0
- package/dist/core/src/http/middleware/BodySizeLimit.d.ts +16 -0
- package/dist/core/src/http/middleware/Cors.d.ts +24 -0
- package/dist/core/src/http/middleware/Csrf.d.ts +23 -0
- package/dist/core/src/http/middleware/HeaderTokenGate.d.ts +28 -0
- package/dist/core/src/http/middleware/SecurityHeaders.d.ts +29 -0
- package/dist/core/src/http/middleware/ThrottleRequests.d.ts +18 -0
- package/dist/core/src/http/types.d.ts +355 -0
- package/dist/core/src/index.d.ts +76 -0
- package/dist/core/src/instrumentation/index.d.ts +35 -0
- package/dist/core/src/instrumentation/opentelemetry.d.ts +178 -0
- package/dist/core/src/instrumentation/types.d.ts +182 -0
- package/dist/core/src/reliability/DeadLetterQueueManager.d.ts +316 -0
- package/dist/core/src/reliability/RetryPolicy.d.ts +217 -0
- package/dist/core/src/reliability/index.d.ts +6 -0
- package/dist/core/src/router/ControllerDispatcher.d.ts +12 -0
- package/dist/core/src/router/RequestValidator.d.ts +20 -0
- package/dist/core/src/runtime.d.ts +119 -0
- package/dist/core/src/security/Encrypter.d.ts +33 -0
- package/dist/core/src/security/Hasher.d.ts +29 -0
- package/dist/core/src/testing/HttpTester.d.ts +39 -0
- package/dist/core/src/testing/TestResponse.d.ts +78 -0
- package/dist/core/src/testing/index.d.ts +2 -0
- package/dist/core/src/types/events.d.ts +94 -0
- package/dist/echo/src/OrbitEcho.d.ts +115 -0
- package/dist/echo/src/dlq/DeadLetterQueue.d.ts +94 -0
- package/dist/echo/src/dlq/MemoryDeadLetterQueue.d.ts +36 -0
- package/dist/echo/src/dlq/index.d.ts +2 -0
- package/dist/echo/src/index.d.ts +64 -0
- package/dist/echo/src/middleware/RequestBufferMiddleware.d.ts +62 -0
- package/dist/echo/src/middleware/index.d.ts +8 -0
- package/dist/echo/src/observability/index.d.ts +3 -0
- package/dist/echo/src/observability/logging/ConsoleEchoLogger.d.ts +37 -0
- package/dist/echo/src/observability/logging/EchoLogger.d.ts +38 -0
- package/dist/echo/src/observability/logging/index.d.ts +2 -0
- package/dist/echo/src/observability/metrics/MetricsProvider.d.ts +69 -0
- package/dist/echo/src/observability/metrics/NoopMetricsProvider.d.ts +17 -0
- package/dist/echo/src/observability/metrics/PrometheusMetricsProvider.d.ts +39 -0
- package/dist/echo/src/observability/metrics/index.d.ts +3 -0
- package/dist/echo/src/observability/tracing/NoopTracer.d.ts +33 -0
- package/dist/echo/src/observability/tracing/Tracer.d.ts +75 -0
- package/dist/echo/src/observability/tracing/index.d.ts +2 -0
- package/dist/echo/src/providers/GenericProvider.d.ts +53 -0
- package/dist/echo/src/providers/GitHubProvider.d.ts +35 -0
- package/dist/echo/src/providers/LinearProvider.d.ts +27 -0
- package/dist/echo/src/providers/PaddleProvider.d.ts +31 -0
- package/dist/echo/src/providers/ShopifyProvider.d.ts +27 -0
- package/dist/echo/src/providers/SlackProvider.d.ts +27 -0
- package/dist/echo/src/providers/StripeProvider.d.ts +38 -0
- package/dist/echo/src/providers/TwilioProvider.d.ts +31 -0
- package/dist/echo/src/providers/base/BaseProvider.d.ts +87 -0
- package/dist/echo/src/providers/base/HeaderUtils.d.ts +34 -0
- package/dist/echo/src/providers/index.d.ts +14 -0
- package/dist/echo/src/receive/SignatureValidator.d.ts +67 -0
- package/dist/echo/src/receive/WebhookReceiver.d.ts +185 -0
- package/dist/echo/src/receive/index.d.ts +2 -0
- package/dist/echo/src/replay/WebhookReplayService.d.ts +35 -0
- package/dist/echo/src/replay/index.d.ts +1 -0
- package/dist/echo/src/resilience/CircuitBreaker.d.ts +117 -0
- package/dist/echo/src/resilience/index.d.ts +10 -0
- package/dist/echo/src/rotation/KeyRotationManager.d.ts +127 -0
- package/dist/echo/src/rotation/index.d.ts +10 -0
- package/dist/echo/src/send/WebhookDispatcher.d.ts +198 -0
- package/dist/echo/src/send/index.d.ts +1 -0
- package/dist/echo/src/storage/MemoryWebhookStore.d.ts +14 -0
- package/dist/echo/src/storage/WebhookStore.d.ts +236 -0
- package/dist/echo/src/storage/index.d.ts +2 -0
- package/dist/echo/src/types.d.ts +756 -0
- package/dist/index.js +1332 -190
- package/dist/index.js.map +28 -10
- package/dist/photon/src/index.d.ts +84 -0
- package/dist/photon/src/middleware/binary.d.ts +31 -0
- package/dist/photon/src/middleware/htmx.d.ts +39 -0
- package/dist/photon/src/middleware/ratelimit.d.ts +157 -0
- package/dist/photon/src/openapi.d.ts +19 -0
- package/package.json +7 -5
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HasPersistence Concern
|
|
3
|
+
* @description Provides database persistence functionality including saving, deleting, and refreshing.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HasPersistence {
|
|
6
|
+
/**
|
|
7
|
+
* Indicates if the model exists in the database.
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
protected _exists: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if the model instance exists in the database.
|
|
13
|
+
*
|
|
14
|
+
* @returns True if the model has been persisted
|
|
15
|
+
*/
|
|
16
|
+
get exists(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Save the model instance to the database (insert or update).
|
|
19
|
+
*
|
|
20
|
+
* @returns A promise that resolves to the model instance
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* await user.save()
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
save(): Promise<this>;
|
|
28
|
+
/**
|
|
29
|
+
* Perform an insert operation for a new model instance.
|
|
30
|
+
*
|
|
31
|
+
* @returns A promise that resolves to the model instance
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
protected _performInsert(): Promise<this>;
|
|
35
|
+
/**
|
|
36
|
+
* Perform an update operation for an existing model instance.
|
|
37
|
+
*
|
|
38
|
+
* @returns A promise that resolves to the model instance
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
protected _performUpdate(): Promise<this>;
|
|
42
|
+
/**
|
|
43
|
+
* Delete the model instance from the database.
|
|
44
|
+
* Supports soft deletes if configured on the model.
|
|
45
|
+
*
|
|
46
|
+
* @returns A promise that resolves to true if deleted successfully
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* await user.delete()
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
delete(): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Restore a soft-deleted model instance.
|
|
56
|
+
*
|
|
57
|
+
* @returns A promise that resolves to true
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* await user.restore()
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
restore(): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Force a hard delete even if soft deletes are enabled.
|
|
67
|
+
*
|
|
68
|
+
* @returns A promise that resolves to true
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* await user.forceDelete()
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
forceDelete(): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* Refresh the model instance with fresh data from the database.
|
|
78
|
+
*
|
|
79
|
+
* @returns A promise that resolves to the model instance
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await user.refresh()
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
refresh(): Promise<this>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Model, ModelConstructor } from '../Model';
|
|
2
|
+
/**
|
|
3
|
+
* HasRelationships Concern
|
|
4
|
+
* @description Provides relationship management functionality including defining and loading relationships.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HasRelationships {
|
|
7
|
+
/**
|
|
8
|
+
* Define a one-to-many relationship.
|
|
9
|
+
* Returns a QueryBuilder scoped to the related records.
|
|
10
|
+
*
|
|
11
|
+
* @template R - The related model type.
|
|
12
|
+
* @param related - The related model constructor.
|
|
13
|
+
* @param foreignKey - The foreign key on the related table.
|
|
14
|
+
* @param localKey - The local key on this table.
|
|
15
|
+
* @returns A QueryBuilder for the related model.
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const posts = await user.hasMany(Post).where('published', true).get()
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
hasMany<R extends Model>(related: ModelConstructor<R> & typeof Model, foreignKey?: string, localKey?: string): any;
|
|
22
|
+
/**
|
|
23
|
+
* Define a one-to-one relationship.
|
|
24
|
+
*
|
|
25
|
+
* @template R - The related model type.
|
|
26
|
+
* @param related - The related model constructor.
|
|
27
|
+
* @param foreignKey - The foreign key on the related table.
|
|
28
|
+
* @param localKey - The local key on this table.
|
|
29
|
+
* @returns A QueryBuilder for the related model, limited to 1 result.
|
|
30
|
+
*/
|
|
31
|
+
hasOne<R extends Model>(related: ModelConstructor<R> & typeof Model, foreignKey?: string, localKey?: string): any;
|
|
32
|
+
/**
|
|
33
|
+
* Define an inverse one-to-one or one-to-many relationship.
|
|
34
|
+
*
|
|
35
|
+
* @template R - The related model type.
|
|
36
|
+
* @param related - The related model constructor.
|
|
37
|
+
* @param foreignKey - The foreign key on this table.
|
|
38
|
+
* @param ownerKey - The owner key on the related table.
|
|
39
|
+
* @returns A QueryBuilder for the related model.
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const user = await post.belongsTo(User).first()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
belongsTo<R extends Model>(related: ModelConstructor<R> & typeof Model, foreignKey?: string, ownerKey?: string): any;
|
|
46
|
+
/**
|
|
47
|
+
* Define a many-to-many relationship through a pivot table.
|
|
48
|
+
*
|
|
49
|
+
* @template R - The related model type.
|
|
50
|
+
* @param related - The related model constructor.
|
|
51
|
+
* @param pivotTable - The name of the join table.
|
|
52
|
+
* @param foreignPivotKey - The key on the pivot table pointing to this model.
|
|
53
|
+
* @param relatedPivotKey - The key on the pivot table pointing to the related model.
|
|
54
|
+
* @param localKey - The local key on this table.
|
|
55
|
+
* @param relatedKey - The related key on the related table.
|
|
56
|
+
* @returns Promise resolving to an array of related models.
|
|
57
|
+
*/
|
|
58
|
+
belongsToMany<R extends Model>(related: ModelConstructor<R> & typeof Model, pivotTable: string, foreignPivotKey?: string, relatedPivotKey?: string, localKey?: string, relatedKey?: string): Promise<R[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Stream hasMany relationship with cursor-based iteration
|
|
61
|
+
* Memory-safe for large relationship sets
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* for await (const posts of user.hasManyStream(Post, 'user_id', 100)) {
|
|
66
|
+
* for (const post of posts) {
|
|
67
|
+
* await processPost(post)
|
|
68
|
+
* }
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
hasManyStream<R extends Model>(related: ModelConstructor<R> & typeof Model, foreignKey?: string, chunkSize?: number, localKey?: string): AsyncGenerator<R[], void, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* Define a polymorphic one-to-one relationship.
|
|
75
|
+
*
|
|
76
|
+
* @template R - The related model type.
|
|
77
|
+
* @param related - The related model constructor.
|
|
78
|
+
* @param name - The polymorphic relationship name (used to derive type and id fields).
|
|
79
|
+
* @param foreignKey - Optional explicit foreign key.
|
|
80
|
+
* @param localKey - Optional explicit local key.
|
|
81
|
+
* @returns A QueryBuilder for the related model.
|
|
82
|
+
*/
|
|
83
|
+
morphOne<R extends Model>(related: ModelConstructor<R> & typeof Model, name: string, foreignKey?: string, localKey?: string): any;
|
|
84
|
+
/**
|
|
85
|
+
* Define a polymorphic one-to-many relationship.
|
|
86
|
+
*
|
|
87
|
+
* @template R - The related model type.
|
|
88
|
+
* @param related - The related model constructor.
|
|
89
|
+
* @param name - The polymorphic relationship name.
|
|
90
|
+
* @param foreignKey - Optional explicit foreign key.
|
|
91
|
+
* @param localKey - Optional explicit local key.
|
|
92
|
+
* @returns A QueryBuilder for the related model.
|
|
93
|
+
*/
|
|
94
|
+
morphMany<R extends Model>(related: ModelConstructor<R> & typeof Model, name: string, foreignKey?: string, localKey?: string): any;
|
|
95
|
+
/**
|
|
96
|
+
* Define a polymorphic inverse relationship.
|
|
97
|
+
*
|
|
98
|
+
* @template R - The related model type.
|
|
99
|
+
* @param name - The polymorphic relationship name.
|
|
100
|
+
* @param typeField - Optional explicit type field name.
|
|
101
|
+
* @param idField - Optional explicit ID field name.
|
|
102
|
+
* @returns A QueryBuilder for the resolved related model, or null if not resolvable.
|
|
103
|
+
*/
|
|
104
|
+
morphTo<R extends Model>(name: string, typeField?: string, idField?: string): any;
|
|
105
|
+
/**
|
|
106
|
+
* Lazy load relationships for the current model
|
|
107
|
+
* @example await user.load('posts')
|
|
108
|
+
*/
|
|
109
|
+
load(relation: string | string[]): Promise<this>;
|
|
110
|
+
/**
|
|
111
|
+
* Alias for load(), used for fluent eager loading on an instance.
|
|
112
|
+
*
|
|
113
|
+
* @param relation - The relationship name or an array of names
|
|
114
|
+
* @returns A promise that resolves to the model instance
|
|
115
|
+
*/
|
|
116
|
+
with(relation: string | string[]): Promise<this>;
|
|
117
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HasSerialization Concern
|
|
3
|
+
* @description Provides serialization functionality including converting to JSON, array/object, and handling hidden/appended attributes.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HasSerialization {
|
|
6
|
+
/**
|
|
7
|
+
* Fill the model instance with an object of attributes.
|
|
8
|
+
*
|
|
9
|
+
* @param attributes - Key-value pairs of attributes to set
|
|
10
|
+
* @returns The model instance
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* user.fill({ name: 'Carl', email: 'carl@example.com' })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
fill(attributes: Record<string, unknown>): this;
|
|
18
|
+
/**
|
|
19
|
+
* Convert the model instance to a JSON string.
|
|
20
|
+
*
|
|
21
|
+
* @returns A JSON string representation of the model
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const json = user.toJSON()
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
toJSON(): unknown;
|
|
29
|
+
/**
|
|
30
|
+
* Convert the model instance to a plain JavaScript object.
|
|
31
|
+
* Alias for `toJSON()`.
|
|
32
|
+
*
|
|
33
|
+
* @returns A plain object representation of the model
|
|
34
|
+
*/
|
|
35
|
+
toObject(): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Convert the model instance to a plain JavaScript object.
|
|
38
|
+
* Alias for `toJSON()`.
|
|
39
|
+
*
|
|
40
|
+
* @returns A plain object representation of the model
|
|
41
|
+
*/
|
|
42
|
+
toArray(): Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Get all attributes currently set on the model.
|
|
45
|
+
*
|
|
46
|
+
* @returns An object containing all model attributes
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
getAttributes(): Record<string, unknown>;
|
|
50
|
+
/**
|
|
51
|
+
* Get a specific attribute value.
|
|
52
|
+
*
|
|
53
|
+
* @param key - The attribute name
|
|
54
|
+
* @returns The attribute value
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
getAttribute(key: string): unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Get the string representation of the model.
|
|
60
|
+
*
|
|
61
|
+
* @returns A JSON string representation of the model
|
|
62
|
+
*/
|
|
63
|
+
toString(): string;
|
|
64
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mixin utility for composing classes with multiple concerns.
|
|
3
|
+
* @description Utility function to copy properties from mixin prototypes to a base class prototype.
|
|
4
|
+
*
|
|
5
|
+
* @param base - Base class to extend
|
|
6
|
+
* @param mixins - Mixin classes to apply
|
|
7
|
+
* @returns Combined class with all mixin properties
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* class MyModel extends Model {}
|
|
12
|
+
* applyMixins(MyModel, [HasAttributes, HasEvents])
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyMixins<T extends new (...args: unknown[]) => unknown, U extends (new (...args: unknown[]) => unknown)[]>(base: T, mixins: U): T & U[number];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concerns Index
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all model concerns for easier importing.
|
|
5
|
+
*/
|
|
6
|
+
export { applyMixins } from './applyMixins';
|
|
7
|
+
export type { ModelAttributes } from './HasAttributes';
|
|
8
|
+
export { HasAttributes } from './HasAttributes';
|
|
9
|
+
export { HasEvents } from './HasEvents';
|
|
10
|
+
export { HasPersistence } from './HasPersistence';
|
|
11
|
+
export { HasRelationships } from './HasRelationships';
|
|
12
|
+
export { HasSerialization } from './HasSerialization';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the SoftDeletes decorator.
|
|
3
|
+
*/
|
|
4
|
+
export interface SoftDeletesOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The name of the column used to store the deletion timestamp.
|
|
7
|
+
* @default 'deleted_at'
|
|
8
|
+
*/
|
|
9
|
+
column?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Meta keys for decorators
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Metadata key for Soft Deletes configuration.
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const SOFT_DELETES_KEY: unique symbol;
|
|
19
|
+
/**
|
|
20
|
+
* Metadata key for Column definitions.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare const COLUMN_KEY: unique symbol;
|
|
24
|
+
/**
|
|
25
|
+
* Metadata key for Version column.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare const VERSION_KEY: unique symbol;
|
|
29
|
+
/**
|
|
30
|
+
* Soft Deletes Decorator
|
|
31
|
+
*
|
|
32
|
+
* Automatically adds a global scope to filter out deleted records.
|
|
33
|
+
* When applied to a Model class, it ensures that queries only return records
|
|
34
|
+
* where the deletion column (default 'deleted_at') is null.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Configuration for soft deletes
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* @SoftDeletes({ column: 'deleted_at' })
|
|
41
|
+
* class User extends Model {
|
|
42
|
+
* @column()
|
|
43
|
+
* declare deletedAt: Date | null
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function SoftDeletes(options?: SoftDeletesOptions): ClassDecorator;
|
|
48
|
+
/**
|
|
49
|
+
* Options for the Column decorator.
|
|
50
|
+
*/
|
|
51
|
+
export interface ColumnOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Whether the column is a primary key.
|
|
54
|
+
* @default false
|
|
55
|
+
*/
|
|
56
|
+
isPrimary?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the column should be automatically populated with a timestamp on creation.
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
autoCreate?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the column should be automatically updated with a timestamp on every update.
|
|
64
|
+
* @default false
|
|
65
|
+
*/
|
|
66
|
+
autoUpdate?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* The name of the column in the database.
|
|
69
|
+
* If not provided, the property name will be used.
|
|
70
|
+
*/
|
|
71
|
+
name?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The name to use when serializing the model to JSON.
|
|
74
|
+
* Set to null to hide the column from JSON output.
|
|
75
|
+
*/
|
|
76
|
+
serializeAs?: string | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Column Decorator
|
|
80
|
+
*
|
|
81
|
+
* Marks a property as a database column. This decorator also triggers
|
|
82
|
+
* the registration of the model in the global ModelRegistry.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Configuration for the column
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* class User extends Model {
|
|
89
|
+
* @column({ isPrimary: true })
|
|
90
|
+
* declare id: number
|
|
91
|
+
*
|
|
92
|
+
* @column({ name: 'email_address' })
|
|
93
|
+
* declare email: string
|
|
94
|
+
*
|
|
95
|
+
* @column.dateTime({ autoCreate: true })
|
|
96
|
+
* declare createdAt: Date
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function column(options?: ColumnOptions): PropertyDecorator;
|
|
101
|
+
/**
|
|
102
|
+
* Version Decorator for Optimistic Locking
|
|
103
|
+
*
|
|
104
|
+
* Marks a property as a version column for optimistic locking.
|
|
105
|
+
* When a model updates, it checks if the version matches the one in the database.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Configuration for the column (same as @column)
|
|
108
|
+
*/
|
|
109
|
+
export declare function version(options?: ColumnOptions): PropertyDecorator;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Errors
|
|
3
|
+
* @description Custom error types for ORM model operations
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Column Not Found Error
|
|
7
|
+
* Thrown when accessing/setting a column that doesn't exist in schema
|
|
8
|
+
*/
|
|
9
|
+
export declare class ColumnNotFoundError extends Error {
|
|
10
|
+
readonly table: string;
|
|
11
|
+
readonly column: string;
|
|
12
|
+
constructor(table: string, column: string, availableColumns?: string[]);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Type Mismatch Error
|
|
16
|
+
* Thrown when setting a value with incompatible type
|
|
17
|
+
*/
|
|
18
|
+
export declare class TypeMismatchError extends Error {
|
|
19
|
+
readonly table: string;
|
|
20
|
+
readonly column: string;
|
|
21
|
+
readonly expectedType: string;
|
|
22
|
+
readonly actualType: string;
|
|
23
|
+
readonly value?: unknown | undefined;
|
|
24
|
+
constructor(table: string, column: string, expectedType: string, actualType: string, value?: unknown | undefined);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Nullable Constraint Error
|
|
28
|
+
* Thrown when setting null on a non-nullable column
|
|
29
|
+
*/
|
|
30
|
+
export declare class NullableConstraintError extends Error {
|
|
31
|
+
readonly table: string;
|
|
32
|
+
readonly column: string;
|
|
33
|
+
constructor(table: string, column: string);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Model Not Found Error
|
|
37
|
+
* Thrown when a model is not found in the database
|
|
38
|
+
*/
|
|
39
|
+
export declare class ModelNotFoundError extends Error {
|
|
40
|
+
readonly model: string;
|
|
41
|
+
readonly key: unknown;
|
|
42
|
+
constructor(model: string, key: unknown);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Stale Model Error
|
|
46
|
+
* Thrown when an optimistic lock check fails (concurrent update)
|
|
47
|
+
*/
|
|
48
|
+
export declare class StaleModelError extends Error {
|
|
49
|
+
readonly model: string;
|
|
50
|
+
readonly key: unknown;
|
|
51
|
+
constructor(model: string, key: unknown);
|
|
52
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Module Index
|
|
3
|
+
*/
|
|
4
|
+
export { applyMixins, HasAttributes, HasEvents, HasPersistence, HasRelationships, HasSerialization, } from './concerns';
|
|
5
|
+
export { DirtyTracker } from './DirtyTracker';
|
|
6
|
+
export { column, SoftDeletes, version } from './decorators';
|
|
7
|
+
export { ColumnNotFoundError, ModelNotFoundError, NullableConstraintError, TypeMismatchError, } from './errors';
|
|
8
|
+
export { Model, type ModelAttributes, type ModelConstructor, type ModelStatic } from './Model';
|
|
9
|
+
export { ModelRegistry } from './ModelRegistry';
|
|
10
|
+
export { BelongsTo, BelongsToMany, eagerLoad, eagerLoadMany, getRelationships, HasMany, HasOne, MorphMany, MorphOne, MorphTo, type RelationshipMeta, type RelationshipOptions, type RelationType, } from './relationships';
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relationship Types and Base Classes
|
|
3
|
+
* @description Declarative relationship definitions for ORM
|
|
4
|
+
*/
|
|
5
|
+
import type { QueryBuilderContract } from '../../types';
|
|
6
|
+
import type { Model, ModelConstructor } from './Model';
|
|
7
|
+
/**
|
|
8
|
+
* Relationship Type
|
|
9
|
+
*/
|
|
10
|
+
export type RelationType = 'hasOne' | 'hasMany' | 'belongsTo' | 'belongsToMany' | 'morphOne' | 'morphMany' | 'morphTo';
|
|
11
|
+
/**
|
|
12
|
+
* Options for defining relationships between models.
|
|
13
|
+
*/
|
|
14
|
+
export interface RelationshipOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The foreign key column name.
|
|
17
|
+
* - For `HasOne`/`HasMany`: Defaults to `parent_table_id` on the related table.
|
|
18
|
+
* - For `BelongsTo`: Defaults to `related_table_id` on the local table.
|
|
19
|
+
* - For `BelongsToMany`: Defaults to `parent_table_id` on the pivot table.
|
|
20
|
+
*/
|
|
21
|
+
foreignKey?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The local key column name.
|
|
24
|
+
* - For `HasOne`/`HasMany`: Defaults to the primary key of the local table.
|
|
25
|
+
* - For `BelongsTo`: Defaults to the primary key of the related table.
|
|
26
|
+
*/
|
|
27
|
+
localKey?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The name of the pivot table for many-to-many relationships.
|
|
30
|
+
* Defaults to an alphabetical concatenation of the two table names (e.g., `roles_users`).
|
|
31
|
+
*/
|
|
32
|
+
pivotTable?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The related key column name in the pivot table.
|
|
35
|
+
* Defaults to `related_table_id`.
|
|
36
|
+
*/
|
|
37
|
+
relatedKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Additional columns to select from the pivot table.
|
|
40
|
+
*/
|
|
41
|
+
pivotColumns?: string[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Relationship Metadata
|
|
45
|
+
*/
|
|
46
|
+
export interface RelationshipMeta {
|
|
47
|
+
type: RelationType;
|
|
48
|
+
related?: () => ModelConstructor<Model> & typeof Model;
|
|
49
|
+
foreignKey?: string;
|
|
50
|
+
localKey?: string;
|
|
51
|
+
pivotTable?: string | undefined;
|
|
52
|
+
relatedKey?: string | undefined;
|
|
53
|
+
pivotColumns?: string[] | undefined;
|
|
54
|
+
morphName?: string;
|
|
55
|
+
morphTypeField?: string;
|
|
56
|
+
morphIdField?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get relationships for a model
|
|
60
|
+
*/
|
|
61
|
+
export declare function getRelationships(model: typeof Model): Map<string, RelationshipMeta>;
|
|
62
|
+
/**
|
|
63
|
+
* Define a relationship on a model
|
|
64
|
+
*/
|
|
65
|
+
export declare function defineRelationship(model: typeof Model, name: string, meta: RelationshipMeta): void;
|
|
66
|
+
/**
|
|
67
|
+
* HasOne Relationship Decorator
|
|
68
|
+
*
|
|
69
|
+
* Defines a one-to-one relationship where the related model's table
|
|
70
|
+
* contains the foreign key.
|
|
71
|
+
*
|
|
72
|
+
* @param related - A factory function that returns the related Model class.
|
|
73
|
+
* @param options - Configuration for the relationship.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* class User extends Model {
|
|
78
|
+
* @HasOne(() => Profile)
|
|
79
|
+
* declare profile: Profile
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function HasOne(related: () => ModelConstructor<Model> & typeof Model, options?: Omit<RelationshipOptions, 'pivotTable'>): PropertyDecorator;
|
|
84
|
+
/**
|
|
85
|
+
* HasMany Relationship Decorator
|
|
86
|
+
*
|
|
87
|
+
* Defines a one-to-many relationship where the related model's table
|
|
88
|
+
* contains the foreign key.
|
|
89
|
+
*
|
|
90
|
+
* @param related - A factory function that returns the related Model class.
|
|
91
|
+
* @param options - Configuration for the relationship.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* class User extends Model {
|
|
96
|
+
* @HasMany(() => Post)
|
|
97
|
+
* declare posts: Post[]
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function HasMany(related: () => ModelConstructor<Model> & typeof Model, options?: Omit<RelationshipOptions, 'pivotTable'>): PropertyDecorator;
|
|
102
|
+
/**
|
|
103
|
+
* BelongsTo Relationship Decorator
|
|
104
|
+
*
|
|
105
|
+
* Defines an inverse relationship where the local model's table
|
|
106
|
+
* contains the foreign key.
|
|
107
|
+
*
|
|
108
|
+
* @param related - A factory function that returns the related Model class.
|
|
109
|
+
* @param options - Configuration for the relationship.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* class Post extends Model {
|
|
114
|
+
* @BelongsTo(() => User)
|
|
115
|
+
* declare author: User
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function BelongsTo(related: () => ModelConstructor<Model> & typeof Model, options?: Omit<RelationshipOptions, 'pivotTable'>): PropertyDecorator;
|
|
120
|
+
/**
|
|
121
|
+
* BelongsToMany Relationship Decorator
|
|
122
|
+
*
|
|
123
|
+
* Defines a many-to-many relationship using a pivot table.
|
|
124
|
+
*
|
|
125
|
+
* @param related - A factory function that returns the related Model class.
|
|
126
|
+
* @param options - Configuration for the relationship, including pivot table details.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* class User extends Model {
|
|
131
|
+
* @BelongsToMany(() => Role, { pivotTable: 'user_roles' })
|
|
132
|
+
* declare roles: Role[]
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export declare function BelongsToMany(related: () => ModelConstructor<Model> & typeof Model, options?: RelationshipOptions): PropertyDecorator;
|
|
137
|
+
/**
|
|
138
|
+
* MorphOne Relationship Decorator
|
|
139
|
+
*
|
|
140
|
+
* Defines a polymorphic one-to-one relationship.
|
|
141
|
+
*
|
|
142
|
+
* @param related - A factory function that returns the related Model class.
|
|
143
|
+
* @param name - The name of the polymorphic relationship (e.g., 'imageable').
|
|
144
|
+
* @param options - Configuration for the relationship.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* class Post extends Model {
|
|
149
|
+
* @MorphOne(() => Image, 'imageable')
|
|
150
|
+
* declare image: Image
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function MorphOne(related: () => ModelConstructor<Model> & typeof Model, name: string, options?: {
|
|
155
|
+
foreignKey?: string;
|
|
156
|
+
localKey?: string;
|
|
157
|
+
}): PropertyDecorator;
|
|
158
|
+
/**
|
|
159
|
+
* MorphMany Relationship Decorator
|
|
160
|
+
*
|
|
161
|
+
* Defines a polymorphic one-to-many relationship.
|
|
162
|
+
*
|
|
163
|
+
* @param related - A factory function that returns the related Model class.
|
|
164
|
+
* @param name - The name of the polymorphic relationship (e.g., 'commentable').
|
|
165
|
+
* @param options - Configuration for the relationship.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```typescript
|
|
169
|
+
* class Post extends Model {
|
|
170
|
+
* @MorphMany(() => Comment, 'commentable')
|
|
171
|
+
* declare comments: Comment[]
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare function MorphMany(related: () => ModelConstructor<Model> & typeof Model, name: string, options?: {
|
|
176
|
+
foreignKey?: string;
|
|
177
|
+
localKey?: string;
|
|
178
|
+
}): PropertyDecorator;
|
|
179
|
+
/**
|
|
180
|
+
* MorphTo Relationship Decorator
|
|
181
|
+
*
|
|
182
|
+
* Defines the inverse of a polymorphic relationship.
|
|
183
|
+
*
|
|
184
|
+
* @param options - Configuration for the polymorphic relationship.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* class Comment extends Model {
|
|
189
|
+
* @MorphTo()
|
|
190
|
+
* declare commentable: Post | Video
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function MorphTo(options?: {
|
|
195
|
+
name?: string;
|
|
196
|
+
typeField?: string;
|
|
197
|
+
idField?: string;
|
|
198
|
+
}): PropertyDecorator;
|
|
199
|
+
/**
|
|
200
|
+
* Load related models for a collection of parent models
|
|
201
|
+
* Uses batch queries to avoid N+1 problem
|
|
202
|
+
*/
|
|
203
|
+
export declare function eagerLoad<T extends Model, R extends Model = Model>(parents: T[], relationName: string, callback?: (query: QueryBuilderContract<R>) => void): Promise<void>;
|
|
204
|
+
/**
|
|
205
|
+
* Load multiple relationships
|
|
206
|
+
*/
|
|
207
|
+
export declare function eagerLoadMany<T extends Model, R extends Model = Model>(parents: T[], relations: string[] | Record<string, unknown> | Map<string, (query: QueryBuilderContract<R>) => void>): Promise<void>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Model } from './Model';
|
|
2
|
+
export interface ModelObserver<T extends Model> {
|
|
3
|
+
creating?(model: T): void | Promise<void>;
|
|
4
|
+
created?(model: T): void | Promise<void>;
|
|
5
|
+
updating?(model: T): void | Promise<void>;
|
|
6
|
+
updated?(model: T): void | Promise<void>;
|
|
7
|
+
deleting?(model: T): void | Promise<void>;
|
|
8
|
+
deleted?(model: T): void | Promise<void>;
|
|
9
|
+
saving?(model: T): void | Promise<void>;
|
|
10
|
+
saved?(model: T): void | Promise<void>;
|
|
11
|
+
retrieved?(model: T): void | Promise<void>;
|
|
12
|
+
}
|