@getstrata/core 2.2.59 → 3.0.3
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/CHANGELOG.md +27 -0
- package/dist/core/audit/exportAuditLogs.d.ts +12 -3
- package/dist/core/audit/exportStore.d.ts +6 -2
- package/dist/core/audit/siemFormatter.d.ts +2 -2
- package/dist/core/auth/abilityCatalog.d.ts +1 -9
- package/dist/core/auth/authContext.d.ts +2 -0
- package/dist/core/auth/authOutcome.d.ts +32 -0
- package/dist/core/auth/authReader.d.ts +22 -0
- package/dist/core/auth/basicAuthGuard.d.ts +19 -3
- package/dist/core/auth/emailVerification.d.ts +1 -1
- package/dist/core/auth/guard.d.ts +27 -6
- package/dist/core/auth/intendedUrlCookie.d.ts +13 -7
- package/dist/core/auth/jwt.d.ts +5 -4
- package/dist/core/auth/jwtGuard.d.ts +7 -6
- package/dist/core/auth/membershipContext.d.ts +10 -7
- package/dist/core/auth/membershipContextMiddleware.d.ts +3 -3
- package/dist/core/auth/membershipMiddleware.d.ts +1 -2
- package/dist/core/auth/membershipServiceImplementation.d.ts +1 -1
- package/dist/core/auth/oauth/oidcIdToken.d.ts +25 -16
- package/dist/core/auth/oauth/oidcProvider.d.ts +6 -4
- package/dist/core/auth/oauth/providers.d.ts +3 -1
- package/dist/core/auth/oneTimeToken.d.ts +2 -3
- package/dist/core/auth/passwordConfirmCookie.d.ts +15 -6
- package/dist/core/auth/passwordLogin.d.ts +5 -5
- package/dist/core/auth/pendingMfaCookie.d.ts +2 -2
- package/dist/core/auth/policy.d.ts +23 -10
- package/dist/core/auth/requireAuthCapability.d.ts +3 -0
- package/dist/core/auth/resolveMembershipService.d.ts +3 -2
- package/dist/core/auth/saml/samlAssertionReplay.d.ts +4 -4
- package/dist/core/auth/saml/samlServiceProvider.d.ts +11 -7
- package/dist/core/auth/scimAuthMiddleware.d.ts +10 -3
- package/dist/core/auth/sessionCookie.d.ts +20 -9
- package/dist/core/auth/sessionGuard.d.ts +14 -3
- package/dist/core/cache/createCacheStore.d.ts +6 -3
- package/dist/core/cache/redisCacheStore.d.ts +5 -1
- package/dist/core/cache/repository.d.ts +5 -1
- package/dist/core/cache/simpleCache.d.ts +2 -1
- package/dist/core/cache/tokens.d.ts +8 -0
- package/dist/core/config/applicationConfig.d.ts +21 -0
- package/dist/core/config/configSnapshot.d.ts +3 -0
- package/dist/core/config/envSchema.d.ts +3 -2
- package/dist/core/contracts/application.d.ts +153 -0
- package/dist/core/contracts/authUserDirectory.d.ts +24 -7
- package/dist/core/contracts/container.d.ts +20 -23
- package/dist/core/contracts/di.d.ts +4 -2
- package/dist/core/contracts/executionContext.d.ts +5 -0
- package/dist/core/contracts/executionOperations.d.ts +10 -0
- package/dist/core/contracts/executionOwnership.d.ts +38 -0
- package/dist/core/contracts/persistence.d.ts +20 -0
- package/dist/core/contracts/serviceTokens.d.ts +32 -18
- package/dist/core/contracts/services.d.ts +63 -0
- package/dist/core/contracts/token.d.ts +19 -0
- package/dist/core/crypto/fieldEncryption.d.ts +19 -7
- package/dist/core/crypto/fieldEncryptionRotation.d.ts +21 -5
- package/dist/core/crypto/mfaSecret.d.ts +10 -3
- package/dist/core/database/baseRepository.d.ts +14 -10
- package/dist/core/database/bindings.d.ts +6 -0
- package/dist/core/database/bunSql.d.ts +3 -12
- package/dist/core/database/definitions.d.ts +209 -0
- package/dist/core/database/dialect.d.ts +5 -24
- package/dist/core/database/driverPorts.d.ts +116 -0
- package/dist/core/database/errors.d.ts +47 -7
- package/dist/core/database/factory.d.ts +51 -31
- package/dist/core/database/index.d.ts +9 -10
- package/dist/core/database/keyset.d.ts +2 -1
- package/dist/core/database/legacyNativeTransaction.d.ts +5 -0
- package/dist/core/database/manager.d.ts +12 -0
- package/dist/core/database/model.d.ts +91 -97
- package/dist/core/database/modelQuery.d.ts +9 -5
- package/dist/core/database/modelRegistry.d.ts +52 -33
- package/dist/core/database/mysqlConnection.d.ts +1 -19
- package/dist/core/database/mysqlNative.d.ts +38 -0
- package/dist/core/database/nativeTransactions.d.ts +16 -0
- package/dist/core/database/ormInternal.d.ts +85 -0
- package/dist/core/database/ormRuntime.d.ts +4 -0
- package/dist/core/database/ownedReadOnlyObservation.d.ts +16 -0
- package/dist/core/database/postgresNative.d.ts +11 -0
- package/dist/core/database/query.d.ts +24 -23
- package/dist/core/database/queryPlanSnapshot.d.ts +7 -0
- package/dist/core/database/rawMysql.d.ts +7 -0
- package/dist/core/database/rawPostgres.d.ts +23 -0
- package/dist/core/database/rawSqlite.d.ts +6 -0
- package/dist/core/database/relationQueries.d.ts +3 -2
- package/dist/core/database/relationQuery.d.ts +24 -6
- package/dist/core/database/repositoryQuery.d.ts +6 -1
- package/dist/core/database/schema/driver.d.ts +1 -1
- package/dist/core/database/seeders/types.d.ts +1 -1
- package/dist/core/database/session.d.ts +13 -0
- package/dist/core/database/sessionFactory.d.ts +9 -0
- package/dist/core/database/sqlDialects.d.ts +22 -0
- package/dist/core/database/tokens.d.ts +7 -0
- package/dist/core/database/transactionSession.d.ts +43 -0
- package/dist/core/errors/http.d.ts +4 -1
- package/dist/core/events/{eventBus.d.ts → eventBusClass.d.ts} +1 -3
- package/dist/core/events/index.d.ts +2 -3
- package/dist/core/events/outbox/index.d.ts +44 -13
- package/dist/core/events/outbox/metrics.d.ts +4 -4
- package/dist/core/events/outbox/workerTransport.d.ts +17 -0
- package/dist/core/http/authMiddleware.d.ts +2 -2
- package/dist/core/http/authorizeMiddleware.d.ts +2 -2
- package/dist/core/http/bodySizeLimitMiddleware.d.ts +1 -1
- package/dist/core/http/conditionalResponse.d.ts +7 -2
- package/dist/core/http/contentSecurityPolicy.d.ts +4 -3
- package/dist/core/http/corsMiddleware.d.ts +2 -1
- package/dist/core/http/csrfMiddleware.d.ts +6 -1
- package/dist/core/http/csrfToken.d.ts +17 -7
- package/dist/core/http/databaseError.d.ts +4 -0
- package/dist/core/http/etag.d.ts +5 -2
- package/dist/core/http/flashMiddleware.d.ts +1 -1
- package/dist/core/http/flashSession.d.ts +13 -7
- package/dist/core/http/index.d.ts +1 -1
- package/dist/core/http/loginThrottleMiddleware.d.ts +3 -3
- package/dist/core/http/memoryThrottleMiddleware.d.ts +2 -2
- package/dist/core/http/parseMultipartUpload.d.ts +3 -2
- package/dist/core/http/requestMetaContext.d.ts +5 -0
- package/dist/core/http/requireAbilityMiddleware.d.ts +1 -1
- package/dist/core/http/requireAuthMiddleware.d.ts +2 -2
- package/dist/core/http/requirePasswordConfirmMiddleware.d.ts +2 -1
- package/dist/core/http/requireVerifiedMiddleware.d.ts +2 -2
- package/dist/core/http/requireWebAuthMiddleware.d.ts +2 -2
- package/dist/core/http/response.d.ts +4 -3
- package/dist/core/http/scimThrottleMiddleware.d.ts +4 -3
- package/dist/core/http/securedRouteModelBinding.d.ts +10 -3
- package/dist/core/http/securityHeadersMiddleware.d.ts +1 -2
- package/dist/core/http/signedUrl.d.ts +8 -6
- package/dist/core/http/throttleMiddleware.d.ts +9 -5
- package/dist/core/http/uploads.d.ts +9 -3
- package/dist/core/http/webErrorResponse.d.ts +8 -2
- package/dist/core/jobs/exportAuditLogsJob.d.ts +5 -2
- package/dist/core/jobs/invalidateCacheTagsJob.d.ts +5 -4
- package/dist/core/lifecycle/gracefulShutdown.d.ts +2 -5
- package/dist/core/logging/requestLoggingMiddleware.d.ts +1 -1
- package/dist/core/mail/mailer.d.ts +7 -5
- package/dist/core/openapi/generator.d.ts +12 -4
- package/dist/core/openapi/registeredRoute.d.ts +4 -4
- package/dist/core/queue/createAppQueue.d.ts +9 -4
- package/dist/core/queue/failedJobMetrics.d.ts +11 -2
- package/dist/core/queue/failedJobRepository.d.ts +6 -3
- package/dist/core/queue/failedJobService.d.ts +1 -0
- package/dist/core/queue/index.d.ts +16 -6
- package/dist/core/queue/jobRegistry.d.ts +3 -2
- package/dist/core/queue/jobRunner.d.ts +10 -4
- package/dist/core/queue/publicQueue.d.ts +18 -9
- package/dist/core/queue/queueConfig.d.ts +20 -10
- package/dist/core/queue/queueHandoff.d.ts +31 -0
- package/dist/core/queue/queueMetrics.d.ts +10 -3
- package/dist/core/queue/queueServices.d.ts +28 -0
- package/dist/core/queue/queueWorkerTransport.d.ts +28 -0
- package/dist/core/queue/redisQueue.d.ts +19 -10
- package/dist/core/queue/redisQueueKeys.d.ts +5 -5
- package/dist/core/queue/redisStreams.d.ts +17 -10
- package/dist/core/queue/resilientQueue.d.ts +10 -4
- package/dist/core/queue/types.d.ts +1 -0
- package/dist/core/runtime/appKeyPrefix.d.ts +5 -5
- package/dist/core/runtime/application.d.ts +7 -0
- package/dist/core/runtime/executionContext.d.ts +9 -0
- package/dist/core/runtime/executionTasks.d.ts +49 -0
- package/dist/core/runtime/resourceJournal.d.ts +67 -0
- package/dist/core/runtime/serviceGraph.d.ts +14 -0
- package/dist/core/security/oauthState.d.ts +13 -9
- package/dist/core/security/publicReads.d.ts +2 -2
- package/dist/core/security/safeFetch.d.ts +1 -0
- package/dist/core/security/safeUrl.d.ts +3 -0
- package/dist/core/security/scimTenantTokens.d.ts +1 -1
- package/dist/core/security/tokenExpiry.d.ts +1 -1
- package/dist/core/security/webhookSignature.d.ts +1 -1
- package/dist/core/storage/storage.d.ts +24 -16
- package/dist/core/tenant/databaseTenantContext.d.ts +5 -7
- package/dist/core/tenant/resolveTenant.d.ts +2 -2
- package/dist/core/tenant/scopedDatabasePolicy.d.ts +8 -0
- package/dist/core/tenant/tenantDatabaseScope.d.ts +3 -7
- package/dist/core/tenant/tenantMiddleware.d.ts +15 -4
- package/dist/core/tracing/otel.d.ts +4 -6
- package/dist/core/tracing/tracingMiddleware.d.ts +3 -3
- package/dist/core/view/etaViewEngine.d.ts +1 -1
- package/dist/core/view/index.d.ts +5 -4
- package/dist/core/view/tokens.d.ts +8 -0
- package/dist/core/view/viewRenderer.d.ts +2 -2
- package/dist/core/view/webErrorView.d.ts +8 -7
- package/dist/core/view/webLayoutData.d.ts +6 -4
- package/dist/entries/audit/exportAuditLogs.js +87 -1024
- package/dist/entries/audit/siemFormatter.js +4 -90
- package/dist/entries/auth/abilityCatalog.js +28 -0
- package/dist/entries/auth/accessControl.js +5 -16
- package/dist/entries/auth/accountStateMigration.js +216 -236
- package/dist/entries/auth/authOutcome.js +80 -0
- package/dist/entries/auth/authReader.js +68 -0
- package/dist/entries/auth/basicAuthGuard.js +144 -1249
- package/dist/entries/auth/emailVerification.js +2 -2
- package/dist/entries/auth/intendedUrlCookie.js +35 -59
- package/dist/entries/auth/jwt.js +22 -47
- package/dist/entries/auth/jwtGuard.js +99 -231
- package/dist/entries/auth/membershipMiddleware.js +71 -10
- package/dist/entries/auth/membershipScope.js +16 -22
- package/dist/entries/auth/membershipService.js +11 -28
- package/dist/entries/auth/oauth/oidcProvider.js +59 -64
- package/dist/entries/auth/oauth/providers.js +12 -95
- package/dist/entries/auth/oauth/samlProvider.js +53 -1080
- package/dist/entries/auth/oneTimeToken.js +27 -289
- package/dist/entries/auth/passwordConfirmCookie.js +40 -63
- package/dist/entries/auth/passwordLogin.js +94 -399
- package/dist/entries/auth/pendingMfaCookie.js +6 -6
- package/dist/entries/auth/policy.js +22 -56
- package/dist/entries/auth/saml/samlServiceProvider.js +55 -1084
- package/dist/entries/auth/scimAuthMiddleware.js +16 -3358
- package/dist/entries/auth/sessionCookie.js +58 -73
- package/dist/entries/auth/sessionGuard.js +95 -248
- package/dist/entries/auth/tokenHash.js +11 -43
- package/dist/entries/cache/createCacheStore.js +126 -117
- package/dist/entries/cache/repository.js +25 -0
- package/dist/entries/cache/simpleCache.js +12 -7
- package/dist/entries/cache/tokens.js +9 -0
- package/dist/entries/config/applicationConfig.js +163 -0
- package/dist/entries/config/envSchema.js +21 -4
- package/dist/entries/contracts/application.js +1 -0
- package/dist/entries/contracts/authUserDirectory.js +10 -0
- package/dist/entries/contracts/container.js +99 -26
- package/dist/entries/contracts/di.js +3 -0
- package/dist/entries/contracts/executionContext.js +7 -0
- package/dist/entries/contracts/executionOperations.js +7 -0
- package/dist/entries/contracts/executionOwnership.js +7 -0
- package/dist/entries/contracts/membership.js +1 -0
- package/dist/entries/contracts/persistence.js +1 -0
- package/dist/entries/contracts/serviceTokens.js +26 -116
- package/dist/entries/contracts/services.js +98 -0
- package/dist/entries/contracts/token.js +41 -0
- package/dist/entries/crypto/fieldEncryption.js +49 -50
- package/dist/entries/crypto/mfaSecret.js +86 -82
- package/dist/entries/database/acquisitionMetrics.js +107 -0
- package/dist/entries/database/baseRepository.d.ts +2 -0
- package/dist/entries/database/bindings.js +2082 -0
- package/dist/entries/database/definitions.js +175 -0
- package/dist/entries/database/errors.js +114 -89
- package/dist/entries/database/factory.js +67 -28
- package/dist/entries/database/migrations.js +172 -224
- package/dist/entries/database/model.d.ts +1 -0
- package/dist/entries/database/ownedReadOnlyObservation.js +1282 -0
- package/dist/entries/database/query.js +159 -161
- package/dist/entries/database/repositoryQuery.d.ts +1 -0
- package/dist/entries/database/repositoryQuery.js +1 -1373
- package/dist/entries/database/schema.js +216 -236
- package/dist/entries/database/session.js +1 -0
- package/dist/entries/database/sqliteConnection.js +525 -83
- package/dist/entries/database/tokens.js +9 -0
- package/dist/entries/errors/http.js +118 -1
- package/dist/entries/http/authMiddleware.js +8 -5
- package/dist/entries/http/authorizeMiddleware.js +1 -1
- package/dist/entries/http/bodySizeLimitMiddleware.js +2 -2
- package/dist/entries/http/clientIp.js +2 -2
- package/dist/entries/http/conditionalResponse.js +19 -7
- package/dist/entries/http/corsMiddleware.js +6 -101
- package/dist/entries/http/csrfMiddleware.js +92 -106
- package/dist/entries/http/csrfToken.js +58 -94
- package/dist/entries/http/etag.js +7 -4
- package/dist/entries/http/flashMiddleware.js +57 -99
- package/dist/entries/http/flashSession.js +41 -68
- package/dist/entries/http/memoryThrottleMiddleware.js +43 -186
- package/dist/entries/http/metricsMiddleware.js +2 -16
- package/dist/entries/http/parseMultipartUpload.js +15 -29
- package/dist/entries/http/requireAbilityMiddleware.js +2 -2
- package/dist/entries/http/requirePasswordConfirmMiddleware.js +19 -31
- package/dist/entries/http/requireVerifiedMiddleware.js +4 -7
- package/dist/entries/http/requireWebAuthMiddleware.js +2 -2
- package/dist/entries/http/response.js +67 -233
- package/dist/entries/http/routeMiddleware.js +0 -14
- package/dist/entries/http/scimThrottleMiddleware.js +43 -237
- package/dist/entries/http/securedRouteModelBinding.js +37 -25
- package/dist/entries/http/securityHeadersMiddleware.js +8 -25
- package/dist/entries/http/signedUrl.js +20 -110
- package/dist/entries/http/throttleMiddleware.js +41 -185
- package/dist/entries/http/uploads.js +9 -24
- package/dist/entries/jobs/exportAuditLogsJob.js +17 -1498
- package/dist/entries/jobs/invalidateCacheTagsJob.js +12 -47
- package/dist/entries/logging/requestLoggingMiddleware.js +4 -4
- package/dist/entries/mail/mailer.js +68 -78
- package/dist/entries/openapi/generator.js +33 -100
- package/dist/entries/queue/createAppQueue.js +416 -254
- package/dist/entries/queue/failedJobRepository.js +19 -8
- package/dist/entries/queue/failedJobService.js +1 -0
- package/dist/entries/queue/jobRunner.js +141 -66
- package/dist/entries/queue/publicQueue.js +411 -255
- package/dist/entries/queue/queueConfig.js +61 -0
- package/dist/entries/queue/queueHandoff.js +318 -0
- package/dist/entries/queue/queueMetrics.js +989 -1384
- package/dist/entries/queue/queueServices.js +133 -0
- package/dist/entries/queue/queueWorkerTransport.js +1703 -0
- package/dist/entries/queue/redisQueue.js +282 -180
- package/dist/entries/queue.js +6 -45
- package/dist/entries/runtime/application.js +1585 -0
- package/dist/entries/runtime/asyncContextStore.js +0 -16
- package/dist/entries/security/oauthState.js +35 -67
- package/dist/entries/security/publicReads.js +4 -4
- package/dist/entries/security/safeFetch.js +1 -0
- package/dist/entries/security/scimTenantTokens.js +3 -3
- package/dist/entries/security/tokenExpiry.js +2 -2
- package/dist/entries/security/totp.js +1 -87
- package/dist/entries/security/webhookSignature.js +2 -90
- package/dist/entries/storage/storage.js +120 -45
- package/dist/entries/tenant/databaseTenantContext.js +6 -907
- package/dist/entries/tenant/publicTenantHost.js +78 -0
- package/dist/entries/tenant/resolveTenant.js +14 -0
- package/dist/entries/tenant/scopedDatabasePolicy.js +75 -0
- package/dist/entries/tenant/tenancyConfig.js +1 -19
- package/dist/entries/tenant/tenantDatabaseScope.js +3 -892
- package/dist/entries/tracing/tracingMiddleware.js +104 -173
- package/dist/entries/view/tokens.js +11 -0
- package/dist/framework/public-api.d.ts +62 -44
- package/dist/index.js +10433 -11347
- package/dist/internal/ormInternal.js +117 -0
- package/dist/internal/ormRuntime.js +5000 -0
- package/package.json +158 -46
- package/dist/core/database/bindConnection.d.ts +0 -1
- package/dist/core/database/boundConnection.d.ts +0 -5
- package/dist/core/database/defaultConnection.d.ts +0 -7
- package/dist/core/database/namedConnections.d.ts +0 -15
- package/dist/core/database/readOnlyCollector.d.ts +0 -7
- package/dist/core/database/repositoryConnection.d.ts +0 -4
- package/dist/core/database/transaction.d.ts +0 -23
- package/dist/core/database/transactionControl.d.ts +0 -6
- package/dist/core/events/deferredModelEvents.d.ts +0 -7
- package/dist/core/facades/index.d.ts +0 -10
- package/dist/core/runtime/applicationRegistry.d.ts +0 -18
- package/dist/entries/database/bindConnection.js +0 -1
- package/dist/entries/database/boundConnection.js +0 -1
- package/dist/entries/database/defaultConnection.js +0 -1
- package/dist/entries/database/namedConnections.js +0 -1
- package/dist/entries/database/repositoryConnection.js +0 -1
- package/dist/entries/database/transaction.js +0 -1
- package/dist/entries/facades.js +0 -711
- package/dist/entries/runtime/applicationRegistry.js +0 -1
|
@@ -1,46 +1,23 @@
|
|
|
1
|
+
import type { AnyModelDefinition, ModelBinding, ModelDefinition, ModelObserver, ModelState } from "@getstrata/core/database/definitions";
|
|
1
2
|
import type { KeysetOptions } from "../pagination/index.ts";
|
|
2
|
-
import BaseRepository from "./baseRepository.ts";
|
|
3
|
+
import type BaseRepository from "./baseRepository.ts";
|
|
3
4
|
import { applyCasts, type CastType, dehydrateValue, filterMassAssignable, hydrateValue, type LoadedAttributes, type ModelCasts } from "./modelAttributes.ts";
|
|
4
|
-
import { type ModelAttributes, type ModelIdentifier, type ModelProjection, ModelQuery, type RelationNameInput } from "./modelQuery.ts";
|
|
5
|
-
import { type GlobalScopeFn, type ModelObserver, registerModelClass } from "./modelRegistry.ts";
|
|
5
|
+
import { type AnyModel, type ModelAttributes, type ModelIdentifier, type ModelProjection, ModelQuery, type RelationNameInput } from "./modelQuery.ts";
|
|
6
6
|
import type { AnyRelationQuery, RelatedModelClass } from "./relationQuery.ts";
|
|
7
7
|
import { BelongsToManyRelationQuery, BelongsToRelationQuery, HasManyRelationQuery, HasManyThroughRelationQuery, HasOneRelationQuery, MorphManyRelationQuery, MorphOneRelationQuery, MorphToRelationQuery } from "./relationQuery.ts";
|
|
8
8
|
import type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasOneRelation } from "./relationships.ts";
|
|
9
9
|
import type { RepositoryQuery } from "./repositoryQuery.ts";
|
|
10
|
-
import type { TableDefinition } from "./table.ts";
|
|
11
10
|
import type { ModelWhere, ModelWriteValues, QueryOptions } from "./types.ts";
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
/** Retain the declared table as repository() defaults without narrowing legacy explicit calls. */
|
|
18
|
-
type DefinedModel<TEntity extends object, PrimaryKey extends keyof TEntity & string> = {
|
|
19
|
-
repository<TRecord extends object = TEntity, TKey extends keyof TRecord & string = PrimaryKey & keyof TRecord & string>(this: object): BaseRepository<TRecord, TKey>;
|
|
20
|
-
} & typeof Model<TEntity, PrimaryKey>;
|
|
21
|
-
/** Typed model base with a lazily created framework repository and active connection. */
|
|
22
|
-
declare function defineModel<TEntity extends object, PrimaryKey extends keyof TEntity & string>(table: TableDefinition<TEntity, PrimaryKey>): DefinedModel<TEntity, PrimaryKey>;
|
|
23
|
-
/** Register all relationship names before initializing any model's boot hooks. */
|
|
24
|
-
declare function bootModels(models: readonly object[]): void;
|
|
11
|
+
type RelatedRef<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey> = Model<TRelated, RelatedKey>> = ModelDefinition<TRelated, RelatedKey, M> | string | (() => ModelDefinition<TRelated, RelatedKey, M>);
|
|
12
|
+
declare let saveRelatedModel: (entity: AnyModel, forced: LoadedAttributes) => Promise<AnyModel>;
|
|
13
|
+
declare function getModelBinding<R extends object, K extends keyof R & string>(entity: Model<R, K>): ModelBinding<R, K, BaseRepository<R, K>>;
|
|
14
|
+
declare function modelFacade(entity: object): BoundModelFacade<Record<string, unknown>, "id", AnyModel>;
|
|
15
|
+
declare function runObservers(entity: AnyModel, event: keyof ModelObserver<unknown>): Promise<boolean>;
|
|
25
16
|
declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & string> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
static $casts: ModelCasts;
|
|
31
|
-
static $timestamps: boolean;
|
|
32
|
-
static $hidden?: readonly string[];
|
|
33
|
-
static $visible?: readonly string[];
|
|
34
|
-
static $appends?: readonly string[];
|
|
35
|
-
static $morphClass?: string;
|
|
36
|
-
private _exists;
|
|
37
|
-
private originalAttributes;
|
|
38
|
-
private readonly loadedRelations;
|
|
39
|
-
private hiddenOverrides;
|
|
40
|
-
private visibleOverrides;
|
|
41
|
-
private appended;
|
|
42
|
-
constructor(attributes: TEntity, repository: BaseRepository<TEntity, PrimaryKey>, exists?: boolean);
|
|
43
|
-
private acceptPersistedAttributes;
|
|
17
|
+
#private;
|
|
18
|
+
constructor(state: ModelState<TEntity>, binding: ModelBinding<TEntity, PrimaryKey, BaseRepository<TEntity, PrimaryKey>>);
|
|
19
|
+
protected get attributes(): TEntity;
|
|
20
|
+
protected get repository(): BaseRepository<TEntity, PrimaryKey>;
|
|
44
21
|
getRepository(): BaseRepository<TEntity, PrimaryKey>;
|
|
45
22
|
get $exists(): boolean;
|
|
46
23
|
get<K extends keyof TEntity>(key: K): TEntity[K];
|
|
@@ -52,51 +29,89 @@ declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & s
|
|
|
52
29
|
makeVisible(...keys: string[]): this;
|
|
53
30
|
append(...keys: string[]): this;
|
|
54
31
|
protected primaryKey(): PrimaryKey;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
save(): Promise<this>;
|
|
33
|
+
update(changes: Partial<TEntity>): Promise<this>;
|
|
34
|
+
delete(): Promise<boolean>;
|
|
35
|
+
forceDelete(): Promise<boolean>;
|
|
36
|
+
restore(): Promise<this | null>;
|
|
37
|
+
loadHasMany<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasManyRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild[]>>;
|
|
38
|
+
loadHasOne<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasOneRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild | undefined>>;
|
|
39
|
+
loadBelongsTo<TParent extends object, ForeignKey extends keyof TEntity & string, OwnerKey extends keyof TParent & string, Alias extends string>(as: Alias, relation: BelongsToRelation<TEntity, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): Promise<this & Record<Alias, TParent | undefined>>;
|
|
40
|
+
loadBelongsToMany<TRelated extends object, Pivot extends object, ParentKey extends keyof TEntity & string, RelatedKey extends keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string, Alias extends string>(as: Alias, relation: BelongsToManyRelation<TEntity, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>, relatedRepository: BaseRepository<TRelated, RelatedKey>, options?: Omit<QueryOptions<TRelated>, "where">): Promise<this & Record<Alias, TRelated[]>>;
|
|
41
|
+
hasMany<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
42
|
+
hasOne<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasOneRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
43
|
+
belongsTo<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, foreignKey?: keyof TEntity & string, ownerKey?: RelatedKey): BelongsToRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
44
|
+
hasManyThrough<TRelated extends object, TThrough extends object, RelatedKey extends keyof TRelated & string, ThroughKey extends keyof TThrough & string, M extends Model<TRelated, RelatedKey>, ThroughM extends Model<TThrough, ThroughKey>>(related: RelatedRef<TRelated, RelatedKey, M>, through: RelatedRef<TThrough, ThroughKey, ThroughM>, firstKey?: string, secondKey?: keyof TRelated & string, localKey?: PrimaryKey, secondLocalKey?: ThroughKey): HasManyThroughRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
45
|
+
belongsToMany<TRelated extends object, RelatedKey extends keyof TRelated & string, Pivot extends object = Record<string, unknown>, M extends Model<TRelated, RelatedKey> = Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, pivotTable?: string, foreignPivotKey?: keyof Pivot & string, relatedPivotKey?: keyof Pivot & string): BelongsToManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey, Pivot>;
|
|
46
|
+
morphMany<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
47
|
+
morphOne<TRelated extends object, RelatedKey extends keyof TRelated & string, M extends Model<TRelated, RelatedKey>>(related: RelatedRef<TRelated, RelatedKey, M>, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphOneRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
48
|
+
morphTo(relatedByType: Record<string, AnyModelDefinition | string | (() => AnyModelDefinition)>, morphName?: string, typeKey?: keyof TEntity & string, idKey?: keyof TEntity & string): MorphToRelationQuery<TEntity, PrimaryKey>;
|
|
49
|
+
load(...names: RelationNameInput[]): Promise<this>;
|
|
50
|
+
loaded<T = unknown>(name: string): T | undefined;
|
|
51
|
+
setLoaded(name: string, value: unknown): this;
|
|
52
|
+
set<K extends keyof TEntity>(key: K, value: TEntity[K]): this;
|
|
53
|
+
fill(values: Partial<TEntity>): this;
|
|
54
|
+
mergeAttributes(patch: Partial<TEntity>): this;
|
|
55
|
+
}
|
|
56
|
+
declare class BoundModelFacade<R extends object, K extends keyof R & string, M extends Model<R, K>> {
|
|
57
|
+
#private;
|
|
58
|
+
readonly prototype: M;
|
|
59
|
+
constructor(binding: ModelBinding<R, K, BaseRepository<R, K>>);
|
|
60
|
+
get binding(): ModelBinding<R, K, BaseRepository<R, K>>;
|
|
61
|
+
get definition(): ModelDefinition<R, K, M>;
|
|
62
|
+
get name(): string;
|
|
63
|
+
get $fillable(): readonly string[] | undefined;
|
|
64
|
+
get $guarded(): readonly string[] | true | undefined;
|
|
65
|
+
get $casts(): ModelCasts;
|
|
66
|
+
get $timestamps(): boolean;
|
|
67
|
+
get $hidden(): readonly string[] | undefined;
|
|
68
|
+
get $visible(): readonly string[] | undefined;
|
|
69
|
+
get $appends(): readonly string[] | undefined;
|
|
70
|
+
repository(): BaseRepository<R, K>;
|
|
71
|
+
scopeQuery<A extends object, B extends keyof A & string>(query: RepositoryQuery<A, B>): RepositoryQuery<A, B>;
|
|
72
|
+
hydrateAttributes<A extends object>(values: A): A;
|
|
73
|
+
dehydrateAttributes(values: LoadedAttributes): Promise<LoadedAttributes>;
|
|
74
|
+
hydrate(values: R, exists?: boolean): M;
|
|
75
|
+
newRecord(values: Partial<R>): M;
|
|
76
|
+
bind(source: NoInfer<M>): M;
|
|
77
|
+
resolveRelated<A extends object, B extends keyof A & string, Related extends Model<A, B>>(reference: RelatedRef<A, B, Related>): RelatedModelClass<A, B>;
|
|
78
|
+
private terminal;
|
|
79
|
+
createOwned(values: Partial<R>, forced?: Partial<R>): Promise<M>;
|
|
80
|
+
query<TModel extends object>(this: {
|
|
66
81
|
prototype: TModel;
|
|
67
82
|
}): ModelQuery<TModel>;
|
|
68
|
-
|
|
83
|
+
newFromRecord<TModel extends object>(this: {
|
|
69
84
|
prototype: TModel;
|
|
70
85
|
}, record: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>, exists: false): TModel;
|
|
71
|
-
|
|
86
|
+
newFromRecord<TModel extends object>(this: {
|
|
72
87
|
prototype: TModel;
|
|
73
88
|
}, record: NoInfer<ModelAttributes<TModel>>, exists?: boolean): TModel;
|
|
74
89
|
/** Trusted SQL/driver/partial-record hydration. Callers own shape and completeness. */
|
|
75
|
-
|
|
90
|
+
newFromTrustedRecord<TModel extends object>(this: {
|
|
76
91
|
prototype: TModel;
|
|
77
92
|
}, record: object, exists?: boolean): TModel;
|
|
78
|
-
|
|
93
|
+
create<TModel extends object>(this: {
|
|
79
94
|
prototype: TModel;
|
|
80
95
|
}, attributes: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>, forced?: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>): Promise<TModel>;
|
|
81
|
-
|
|
96
|
+
with<TModel extends object>(this: {
|
|
82
97
|
prototype: TModel;
|
|
83
98
|
}, ...relations: RelationNameInput[]): ModelQuery<TModel>;
|
|
84
|
-
|
|
99
|
+
withTrashed<TModel extends object>(this: {
|
|
85
100
|
prototype: TModel;
|
|
86
101
|
}): ModelQuery<TModel>;
|
|
87
|
-
|
|
102
|
+
onlyTrashed<TModel extends object>(this: {
|
|
88
103
|
prototype: TModel;
|
|
89
104
|
}): ModelQuery<TModel>;
|
|
90
|
-
|
|
105
|
+
chunk<TModel extends object>(this: {
|
|
91
106
|
prototype: TModel;
|
|
92
107
|
}, count: number, callback: (models: TModel[]) => Promise<boolean | void>): Promise<void>;
|
|
93
|
-
|
|
108
|
+
keysetPaginate<TModel extends object>(this: {
|
|
94
109
|
prototype: TModel;
|
|
95
110
|
}, options: KeysetOptions<ModelAttributes<TModel>>): Promise<{
|
|
96
111
|
meta: import("../pagination/index.ts").CursorPaginationMeta<import("../pagination/index.ts").KeysetCursor>;
|
|
97
112
|
data: TModel[];
|
|
98
113
|
}>;
|
|
99
|
-
|
|
114
|
+
cursorPaginate<TModel extends object>(this: {
|
|
100
115
|
prototype: TModel;
|
|
101
116
|
}, options: {
|
|
102
117
|
perPage: number;
|
|
@@ -110,70 +125,49 @@ declare class Model<TEntity extends object, PrimaryKey extends keyof TEntity & s
|
|
|
110
125
|
has_more: boolean;
|
|
111
126
|
};
|
|
112
127
|
}>;
|
|
113
|
-
|
|
128
|
+
whereHas<TModel extends object>(this: {
|
|
114
129
|
prototype: TModel;
|
|
115
130
|
}, name: string, constrain?: (query: AnyRelationQuery) => void): ModelQuery<TModel>;
|
|
116
|
-
|
|
131
|
+
has<TModel extends object>(this: {
|
|
117
132
|
prototype: TModel;
|
|
118
133
|
}, name: string): ModelQuery<TModel>;
|
|
119
|
-
|
|
134
|
+
doesntHave<TModel extends object>(this: {
|
|
120
135
|
prototype: TModel;
|
|
121
136
|
}, name: string): ModelQuery<TModel>;
|
|
122
|
-
|
|
137
|
+
whereDoesntHave<TModel extends object>(this: {
|
|
123
138
|
prototype: TModel;
|
|
124
139
|
}, name: string, constrain?: (query: AnyRelationQuery) => void): ModelQuery<TModel>;
|
|
125
|
-
|
|
140
|
+
find<TModel extends object>(this: {
|
|
126
141
|
prototype: TModel;
|
|
127
142
|
}, id: NoInfer<ModelIdentifier<TModel>>): Promise<TModel | null>;
|
|
128
|
-
|
|
143
|
+
findOrFail<TModel extends object>(this: {
|
|
129
144
|
prototype: TModel;
|
|
130
145
|
}, id: NoInfer<ModelIdentifier<TModel>>, errorFactory?: (id: unknown) => Error): Promise<TModel>;
|
|
131
|
-
|
|
146
|
+
all<TModel extends object>(this: {
|
|
132
147
|
prototype: TModel;
|
|
133
148
|
}, options?: Omit<QueryOptions<ModelAttributes<TModel>>, "where" | "select">): Promise<TModel[]>;
|
|
134
|
-
|
|
149
|
+
where<TModel extends object>(this: {
|
|
135
150
|
prototype: TModel;
|
|
136
151
|
}, where: NoInfer<ModelWhere<ModelAttributes<TModel>>>): ModelQuery<TModel>;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
count(this: object): Promise<number>;
|
|
153
|
+
pluck(this: object, column: string): Promise<unknown[]>;
|
|
154
|
+
pluck(this: object, column: string, keyBy: string): Promise<Map<unknown, unknown>>;
|
|
155
|
+
value(this: object, column: string): Promise<unknown>;
|
|
156
|
+
firstWhere<TModel extends object>(this: {
|
|
142
157
|
prototype: TModel;
|
|
143
158
|
}, where: NoInfer<ModelWhere<ModelAttributes<TModel>>>, options?: Omit<QueryOptions<ModelAttributes<TModel>>, "where" | "select">): Promise<TModel | null>;
|
|
144
|
-
|
|
159
|
+
firstOrNew<TModel extends object>(this: {
|
|
145
160
|
prototype: TModel;
|
|
146
161
|
}, where: NoInfer<ModelWhere<ModelAttributes<TModel>>>, values?: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>): Promise<TModel>;
|
|
147
|
-
|
|
162
|
+
firstOrCreate<TModel extends object>(this: {
|
|
148
163
|
prototype: TModel;
|
|
149
164
|
}, where: NoInfer<ModelWhere<ModelAttributes<TModel>>>, values?: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>): Promise<TModel>;
|
|
150
|
-
|
|
165
|
+
updateOrCreate<TModel extends object>(this: {
|
|
151
166
|
prototype: TModel;
|
|
152
167
|
}, where: NoInfer<ModelWhere<ModelAttributes<TModel>>>, values?: NoInfer<ModelWriteValues<ModelAttributes<TModel>>>): Promise<TModel>;
|
|
153
|
-
save(): Promise<this>;
|
|
154
|
-
update(changes: Partial<TEntity>): Promise<this>;
|
|
155
|
-
delete(): Promise<boolean>;
|
|
156
|
-
forceDelete(): Promise<boolean>;
|
|
157
|
-
restore(): Promise<this | null>;
|
|
158
|
-
loadHasMany<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasManyRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild[]>>;
|
|
159
|
-
loadHasOne<TChild extends object, LocalKey extends keyof TEntity & string, ForeignKey extends keyof TChild & string, Alias extends string>(as: Alias, relation: HasOneRelation<TEntity, TChild, LocalKey, ForeignKey>, childRepository: BaseRepository<TChild, keyof TChild & string>, options?: Omit<QueryOptions<TChild>, "where">): Promise<this & Record<Alias, TChild | undefined>>;
|
|
160
|
-
loadBelongsTo<TParent extends object, ForeignKey extends keyof TEntity & string, OwnerKey extends keyof TParent & string, Alias extends string>(as: Alias, relation: BelongsToRelation<TEntity, TParent, ForeignKey, OwnerKey>, parentRepository: BaseRepository<TParent, OwnerKey>, options?: Omit<QueryOptions<TParent>, "where">): Promise<this & Record<Alias, TParent | undefined>>;
|
|
161
|
-
loadBelongsToMany<TRelated extends object, Pivot extends object, ParentKey extends keyof TEntity & string, RelatedKey extends keyof TRelated & string, ForeignPivotKey extends keyof Pivot & string, RelatedPivotKey extends keyof Pivot & string, Alias extends string>(as: Alias, relation: BelongsToManyRelation<TEntity, TRelated, Pivot, ParentKey, RelatedKey, ForeignPivotKey, RelatedPivotKey>, relatedRepository: BaseRepository<TRelated, RelatedKey>, options?: Omit<QueryOptions<TRelated>, "where">): Promise<this & Record<Alias, TRelated[]>>;
|
|
162
|
-
hasMany<TRelated extends object, RelatedKey extends keyof TRelated & string>(related: RelatedRef<TRelated, RelatedKey>, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
163
|
-
hasOne<TRelated extends object, RelatedKey extends keyof TRelated & string>(related: RelatedRef<TRelated, RelatedKey>, foreignKey?: keyof TRelated & string, localKey?: PrimaryKey): HasOneRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
164
|
-
belongsTo<TRelated extends object, RelatedKey extends keyof TRelated & string>(related: RelatedRef<TRelated, RelatedKey>, foreignKey?: keyof TEntity & string, ownerKey?: RelatedKey): BelongsToRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
165
|
-
hasManyThrough<TRelated extends object, TThrough extends object, RelatedKey extends keyof TRelated & string, ThroughKey extends keyof TThrough & string>(related: RelatedRef<TRelated, RelatedKey>, through: RelatedRef<TThrough, ThroughKey>, firstKey?: string, secondKey?: keyof TRelated & string, localKey?: PrimaryKey, secondLocalKey?: ThroughKey): HasManyThroughRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
166
|
-
belongsToMany<TRelated extends object, RelatedKey extends keyof TRelated & string, Pivot extends object = Record<string, unknown>>(related: RelatedRef<TRelated, RelatedKey>, pivotTable?: string, foreignPivotKey?: keyof Pivot & string, relatedPivotKey?: keyof Pivot & string): BelongsToManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey, Pivot>;
|
|
167
|
-
morphMany<TRelated extends object, RelatedKey extends keyof TRelated & string>(related: RelatedRef<TRelated, RelatedKey>, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphManyRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
168
|
-
morphOne<TRelated extends object, RelatedKey extends keyof TRelated & string>(related: RelatedRef<TRelated, RelatedKey>, morphName: string, typeKey?: keyof TRelated & string, idKey?: keyof TRelated & string, morphType?: string): MorphOneRelationQuery<TEntity, PrimaryKey, TRelated, RelatedKey>;
|
|
169
|
-
morphTo(relatedByType: Record<string, RelatedRef<Record<string, unknown>, "id">>, morphName?: string, typeKey?: keyof TEntity & string, idKey?: keyof TEntity & string): MorphToRelationQuery<TEntity, PrimaryKey>;
|
|
170
|
-
load(...names: RelationNameInput[]): Promise<this>;
|
|
171
|
-
loaded<T = unknown>(name: string): T | undefined;
|
|
172
|
-
setLoaded(name: string, value: unknown): this;
|
|
173
|
-
mergeAttributes(patch: Partial<TEntity>): this;
|
|
174
168
|
}
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
declare function createBoundModel<R extends object, K extends keyof R & string, M extends Model<R, K>>(binding: ModelBinding<R, K, BaseRepository<R, K>>): BoundModelFacade<R, K, M>;
|
|
170
|
+
export { defineModel } from "@getstrata/core/database/definitions";
|
|
177
171
|
export { BelongsToManyRelationQuery, BelongsToRelationQuery, HasManyRelationQuery, HasManyThroughRelationQuery, HasOneRelationQuery, MorphManyRelationQuery, MorphOneRelationQuery, MorphToRelationQuery, } from "./relationQuery.ts";
|
|
178
|
-
export type { CastType,
|
|
179
|
-
export { applyCasts,
|
|
172
|
+
export type { CastType, ModelAttributes, ModelProjection, RelatedRef };
|
|
173
|
+
export { applyCasts, BoundModelFacade, createBoundModel, dehydrateValue, filterMassAssignable, getModelBinding, hydrateValue, Model, ModelQuery, modelFacade, runObservers, saveRelatedModel, };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { CursorPaginatedResult, KeysetCursor, KeysetOptions } from "../pagination/index.ts";
|
|
2
2
|
import type BaseRepository from "./baseRepository.ts";
|
|
3
|
-
import type
|
|
3
|
+
import { type Model } from "./model.ts";
|
|
4
4
|
import type { AnyRelationQuery } from "./relationQuery.ts";
|
|
5
5
|
import type { BelongsToManyRelation, BelongsToRelation, HasManyRelation, HasManyThroughRelation, MorphManyRelation, MorphOneRelation, MorphToRelation } from "./relationships.ts";
|
|
6
|
-
import type
|
|
6
|
+
import { type RepositoryQuery } from "./repositoryQuery.ts";
|
|
7
7
|
import type { ModelWhere, QueryLockOptions, QueryOptions, QueryWhere } from "./types.ts";
|
|
8
8
|
type AnyModel = Model<Record<string, unknown>, "id">;
|
|
9
9
|
type ModelAttributes<TModel> = TModel extends {
|
|
@@ -26,21 +26,25 @@ declare function loadNested(model: {
|
|
|
26
26
|
getRepository: () => BaseRepository<Record<string, unknown>, "id">;
|
|
27
27
|
toObject: () => object;
|
|
28
28
|
setLoaded: (name: string, value: unknown) => unknown;
|
|
29
|
-
}, path: string): Promise<void>;
|
|
29
|
+
}, path: string, preparedRoot?: AnyRelationQuery): Promise<void>;
|
|
30
30
|
/** Read-only plain records; partial selection never acquires model mutation methods. */
|
|
31
31
|
declare class ModelProjection<TEntity extends object, K extends keyof TEntity & string> {
|
|
32
32
|
private readonly load;
|
|
33
33
|
private readonly page;
|
|
34
|
-
|
|
34
|
+
private readonly firstValue;
|
|
35
|
+
constructor(load: (limit?: number) => Promise<Array<Pick<TEntity, K>>>, page: (options: KeysetOptions<TEntity>) => Promise<CursorPaginatedResult<Pick<TEntity, K>, KeysetCursor>>, firstValue: () => Promise<Pick<TEntity, K> | null>);
|
|
35
36
|
keysetPaginate(options: KeysetOptions<TEntity>): Promise<CursorPaginatedResult<Pick<TEntity, K>, KeysetCursor>>;
|
|
36
37
|
get(): Promise<Array<Pick<TEntity, K>>>;
|
|
37
38
|
first(): Promise<Pick<TEntity, K> | null>;
|
|
38
39
|
}
|
|
40
|
+
declare let snapshotModelQuery: <M extends object, C extends string>(query: ModelQuery<M, C>) => ModelQuery<M, C>;
|
|
39
41
|
declare class ModelQuery<TModel extends object = AnyModel, TCounts extends string = never> {
|
|
40
42
|
private readonly modelClass;
|
|
41
43
|
readonly query: RepositoryQuery<Record<string, unknown>, "id">;
|
|
42
44
|
private readonly eager;
|
|
43
45
|
constructor(modelClass: object, query: RepositoryQuery<Record<string, unknown>, "id">);
|
|
46
|
+
private snapshot;
|
|
47
|
+
private terminal;
|
|
44
48
|
with(...relations: RelationNameInput[]): this;
|
|
45
49
|
where(input: ModelWhere<ModelAttributes<TModel>> | ((builder: import("./whereBuilder.ts").WhereBuilder<ModelAttributes<TModel>, ModelWhere<ModelAttributes<TModel>>>) => void)): this;
|
|
46
50
|
orWhere(input: ModelWhere<ModelAttributes<TModel>> | ((builder: import("./whereBuilder.ts").WhereBuilder<ModelAttributes<TModel>, ModelWhere<ModelAttributes<TModel>>>) => void)): this;
|
|
@@ -136,4 +140,4 @@ declare class ModelQuery<TModel extends object = AnyModel, TCounts extends strin
|
|
|
136
140
|
private constrainExists;
|
|
137
141
|
}
|
|
138
142
|
export type { AnyModel, ModelAttributes, ModelIdentifier, RelationNameInput };
|
|
139
|
-
export { flattenRelationNames, loadNested, ModelProjection, ModelQuery };
|
|
143
|
+
export { flattenRelationNames, loadNested, ModelProjection, ModelQuery, snapshotModelQuery };
|
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import type { AnyServiceToken } from "@getstrata/core/contracts/token";
|
|
2
|
+
import type { AnyModelDefinition, AnyRepositoryDefinition, BoundModel, ModelDefinition, ModelObserver, RepositoryDefinition, RepositoryEffectsDeclaration } from "@getstrata/core/database/definitions";
|
|
3
|
+
import { type Session } from "#strata-orm-internal";
|
|
4
|
+
import { BaseRepository, Model } from "#strata-orm-runtime";
|
|
5
|
+
import type { ExecutionContext } from "../contracts/application";
|
|
6
|
+
import type { OwnedExecution } from "../contracts/executionOwnership";
|
|
7
|
+
import { EventBus } from "../events/eventBusClass";
|
|
8
|
+
import type { RawPool } from "./driverPorts";
|
|
9
|
+
import type { DatabaseSession } from "./session";
|
|
10
|
+
interface PreparedRepository {
|
|
11
|
+
readonly definition: AnyRepositoryDefinition;
|
|
12
|
+
readonly dependencies: readonly unknown[];
|
|
13
|
+
readonly bus: EventBus;
|
|
14
|
+
}
|
|
15
|
+
interface PreparedModel {
|
|
16
|
+
readonly definition: AnyModelDefinition;
|
|
17
|
+
readonly dependencies: readonly unknown[];
|
|
18
|
+
readonly observers: readonly ModelObserver<unknown>[];
|
|
19
|
+
}
|
|
20
|
+
interface PreparedRegistry {
|
|
21
|
+
readonly app: object;
|
|
22
|
+
readonly repositories: ReadonlyMap<AnyRepositoryDefinition, PreparedRepository>;
|
|
23
|
+
readonly models: ReadonlyMap<AnyModelDefinition, PreparedModel>;
|
|
24
|
+
readonly names: ReadonlyMap<string, AnyModelDefinition>;
|
|
25
|
+
}
|
|
26
|
+
interface RegistrySnapshot {
|
|
27
|
+
readonly repositories: readonly AnyRepositoryDefinition[];
|
|
28
|
+
readonly models: readonly AnyModelDefinition[];
|
|
29
|
+
readonly dependencies: readonly AnyServiceToken[];
|
|
30
|
+
readonly repositoryEffects: readonly RepositoryEffectsDeclaration[];
|
|
31
|
+
}
|
|
32
|
+
declare function snapshotRegistry(repositories?: readonly AnyRepositoryDefinition[], models?: readonly AnyModelDefinition[], repositoryEffects?: readonly RepositoryEffectsDeclaration[]): RegistrySnapshot;
|
|
33
|
+
declare function prepareRegistry(snapshot: RegistrySnapshot, values: readonly unknown[], app: object): PreparedRegistry;
|
|
34
|
+
interface SessionAuthority {
|
|
35
|
+
readonly pool: RawPool;
|
|
36
|
+
readonly branch: object;
|
|
37
|
+
readonly transactional: boolean;
|
|
38
|
+
readonly assertActive: () => void;
|
|
39
|
+
readonly run: <T>(work: () => T | Promise<T>) => Promise<T>;
|
|
40
|
+
readonly registerRestore: (restore: () => undefined) => void;
|
|
41
|
+
readonly root: () => DatabaseSession;
|
|
42
|
+
}
|
|
43
|
+
interface BoundRegistry {
|
|
44
|
+
repository<R extends object, K extends keyof R & string, T extends BaseRepository<R, K>>(definition: RepositoryDefinition<R, K, T>): T;
|
|
45
|
+
model<R extends object, K extends keyof R & string, M extends Model<R, K>>(definition: ModelDefinition<R, K, M>): BoundModel<R, K, M>;
|
|
46
|
+
}
|
|
47
|
+
/** One closure per execution; every facade attaches exactly one constructor cache. */
|
|
48
|
+
declare function createBoundRegistryFactory(prepared: PreparedRegistry, context: ExecutionContext, ownership: OwnedExecution, configuredPool: (pool: RawPool) => object): {
|
|
49
|
+
attach(session: Session, authority: SessionAuthority): BoundRegistry;
|
|
16
50
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** Alias for `hasMany("Name")` when `Name` is not `constructor.name` or `$morphClass`. */
|
|
21
|
-
declare function registerModelClass(name: string, model: object): void;
|
|
22
|
-
declare function registerModelRepositoryFactory(model: object, factory: () => object): void;
|
|
23
|
-
declare function bindModelRepository(model: object, repository: BaseRepository<Record<string, unknown>, "id">): void;
|
|
24
|
-
declare function findNamedModel(name: string): object | undefined;
|
|
25
|
-
declare function getModelObservers(model: object): ModelObserver[] | undefined;
|
|
26
|
-
declare function restoreModelObservers(model: object, observers: ModelObserver[] | undefined): void;
|
|
27
|
-
declare function observeModel(model: object, observer: ModelObserver): void;
|
|
28
|
-
export type { ModelObserver };
|
|
29
|
-
export { bindModelRepository, findNamedModel, getModelObservers, nameModel, observeModel, registerModelClass, registerModelRepositoryFactory, resolveModelRepository, restoreModelObservers, runObservers, };
|
|
30
|
-
declare function ensureBooted(model: object): void;
|
|
31
|
-
declare function getGlobalScopes(model: object): GlobalScopeFn<Record<string, unknown>, "id">[];
|
|
32
|
-
declare function addModelGlobalScope<TEntity extends object, PrimaryKey extends keyof TEntity & string>(model: object, scope: GlobalScopeFn<TEntity, PrimaryKey>): void;
|
|
33
|
-
export type { GlobalScopeFn };
|
|
34
|
-
export { addModelGlobalScope, ensureBooted, getGlobalScopes };
|
|
51
|
+
export type { ModelObserver } from "@getstrata/core/database/definitions";
|
|
52
|
+
export type { BoundRegistry, PreparedRegistry, RegistrySnapshot, SessionAuthority };
|
|
53
|
+
export { createBoundRegistryFactory, prepareRegistry, snapshotRegistry };
|
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
import { type ActiveDatabaseHandle } from "./connectionContext.ts";
|
|
2
2
|
import type { DatabaseConnection } from "./connectionContracts.ts";
|
|
3
3
|
import { type ReadOnlyObservationOptions } from "./isolatedReadOnlyObservation.ts";
|
|
4
|
-
type MysqlExecutable
|
|
5
|
-
execute: (sql: string, params?: unknown[]) => Promise<[unknown, unknown]>;
|
|
6
|
-
query?: (sql: string) => Promise<[unknown, unknown]>;
|
|
7
|
-
end?: () => Promise<void>;
|
|
8
|
-
getConnection?: () => Promise<MysqlPoolConnection>;
|
|
9
|
-
};
|
|
10
|
-
type MysqlPool = MysqlExecutable & {
|
|
11
|
-
end(): Promise<void>;
|
|
12
|
-
on(event: "connection", listener: (connection: unknown) => void): void;
|
|
13
|
-
};
|
|
14
|
-
type MysqlPoolConnection = MysqlExecutable & {
|
|
15
|
-
beginTransaction(): Promise<void>;
|
|
16
|
-
commit(): Promise<void>;
|
|
17
|
-
rollback(): Promise<void>;
|
|
18
|
-
release(): void;
|
|
19
|
-
destroy(): void;
|
|
20
|
-
};
|
|
4
|
+
import { createMysqlPool, type MysqlExecutable, type MysqlPool, type MysqlPoolConnection, resetMysqlLoaderForTests } from "./mysqlNative";
|
|
21
5
|
type MysqlConnection = ActiveDatabaseHandle & {
|
|
22
6
|
begin<T>(callback: (transaction: ActiveDatabaseHandle) => Promise<T>): Promise<T>;
|
|
23
7
|
close(): Promise<void>;
|
|
24
8
|
observeReadOnly<T>(operation: (connection: DatabaseConnection) => Promise<T>, options: ReadOnlyObservationOptions): Promise<T>;
|
|
25
9
|
};
|
|
26
|
-
declare function resetMysqlLoaderForTests(importer?: () => Promise<unknown>): void;
|
|
27
10
|
declare function createMysqlConnectionFromPool(pool: MysqlExecutable): MysqlConnection;
|
|
28
|
-
declare function createMysqlPool(url: string): Promise<MysqlPool>;
|
|
29
11
|
declare function createMysqlConnection(url: string): MysqlConnection;
|
|
30
12
|
export type { MysqlConnection, MysqlExecutable, MysqlPool, MysqlPoolConnection };
|
|
31
13
|
export { createMysqlConnection, createMysqlConnectionFromPool, createMysqlPool, resetMysqlLoaderForTests, };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type MysqlPromiseModule = {
|
|
2
|
+
createPool: (config: {
|
|
3
|
+
uri: string;
|
|
4
|
+
timezone: string;
|
|
5
|
+
connectionLimit?: number;
|
|
6
|
+
}) => MysqlPool;
|
|
7
|
+
};
|
|
8
|
+
type MysqlExecutable = {
|
|
9
|
+
execute: (sql: string, params?: unknown[]) => Promise<[unknown, unknown]>;
|
|
10
|
+
query?: (sql: string) => Promise<[unknown, unknown]>;
|
|
11
|
+
end?: () => Promise<void>;
|
|
12
|
+
getConnection?: () => Promise<MysqlPoolConnection>;
|
|
13
|
+
};
|
|
14
|
+
type MysqlPool = MysqlExecutable & {
|
|
15
|
+
end(): Promise<void>;
|
|
16
|
+
on(event: "connection", listener: (connection: unknown) => void): void;
|
|
17
|
+
};
|
|
18
|
+
type MysqlSocket = {
|
|
19
|
+
readonly closed?: boolean;
|
|
20
|
+
once(event: "close", listener: () => void): unknown;
|
|
21
|
+
removeListener(event: "close", listener: () => void): unknown;
|
|
22
|
+
};
|
|
23
|
+
type MysqlPoolConnection = MysqlExecutable & {
|
|
24
|
+
readonly connection?: {
|
|
25
|
+
readonly stream?: MysqlSocket;
|
|
26
|
+
};
|
|
27
|
+
beginTransaction(): Promise<void>;
|
|
28
|
+
commit(): Promise<void>;
|
|
29
|
+
rollback(): Promise<void>;
|
|
30
|
+
release(): void;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
};
|
|
33
|
+
declare function resetMysqlLoaderForTests(importer?: () => Promise<unknown>): void;
|
|
34
|
+
declare function loadMysql(): Promise<MysqlPromiseModule>;
|
|
35
|
+
declare function executeMysql<T>(target: MysqlExecutable, query: string, params: readonly unknown[]): Promise<T[]>;
|
|
36
|
+
declare function createMysqlPool(url: string, max?: number): Promise<MysqlPool>;
|
|
37
|
+
export type { MysqlExecutable, MysqlPool, MysqlPoolConnection, MysqlSocket };
|
|
38
|
+
export { createMysqlPool, executeMysql, loadMysql, resetMysqlLoaderForTests };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Decision, NativeState, RawTransaction, SqlStatement, Terminal } from "./driverPorts";
|
|
2
|
+
type NativeControl = {
|
|
3
|
+
execute<Row>(statement: SqlStatement): Promise<readonly Row[]>;
|
|
4
|
+
control(sql: string): Promise<{
|
|
5
|
+
command?: string | null;
|
|
6
|
+
}>;
|
|
7
|
+
/** Local native evidence only; never derive this from an error's payload. */
|
|
8
|
+
state?(): NativeState;
|
|
9
|
+
beginSql?: string;
|
|
10
|
+
};
|
|
11
|
+
declare function nativeTransaction(control: NativeControl): {
|
|
12
|
+
readonly state: NativeState;
|
|
13
|
+
begin<R>(work: (tx: RawTransaction) => Promise<Decision<R>>): Promise<Terminal<R>>;
|
|
14
|
+
};
|
|
15
|
+
export type { NativeControl };
|
|
16
|
+
export { nativeTransaction };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Source-private ORM capability transport. Never re-export from a package. */
|
|
2
|
+
import type { OwnedExecution } from "../contracts/executionOwnership";
|
|
3
|
+
import type { BaseRepository } from "./baseRepository";
|
|
4
|
+
import type { AnyModelDefinition, AnyRepositoryDefinition, BoundModel, ModelBinding, ModelDefinition, ModelObserver, ModelState, RepositoryAction, RepositoryBinding, RepositoryDefinition, RepositoryHooks } from "./definitions";
|
|
5
|
+
import type { DatabaseConnectionOptions, DatabaseDriver } from "./driverPorts";
|
|
6
|
+
import type { Model } from "./model";
|
|
7
|
+
import type { DatabaseSession } from "./session";
|
|
8
|
+
import type { TransactionSession } from "./transactionSession";
|
|
9
|
+
type Session = DatabaseSession | TransactionSession;
|
|
10
|
+
interface BindingPorts<R extends object, K extends keyof R & string> {
|
|
11
|
+
readonly app: object;
|
|
12
|
+
readonly pool: object;
|
|
13
|
+
readonly branch: object;
|
|
14
|
+
readonly tenant: unknown;
|
|
15
|
+
readonly definition: AnyRepositoryDefinition;
|
|
16
|
+
readonly hooks: RepositoryHooks<R, K> | undefined;
|
|
17
|
+
readonly assertActive: () => void;
|
|
18
|
+
readonly repository: <A extends object, B extends keyof A & string, T extends BaseRepository<A, B>>(definition: RepositoryDefinition<A, B, T>) => T;
|
|
19
|
+
readonly model: <A extends object, B extends keyof A & string, M extends Model<A, B>>(definition: ModelDefinition<A, B, M> | string) => BoundModel<A, B, M>;
|
|
20
|
+
readonly reselect: <T extends BaseRepository<R, K>>(session: Session) => T;
|
|
21
|
+
readonly assertMutation: (action: RepositoryAction) => void;
|
|
22
|
+
readonly mutation: <V>(action: RepositoryAction, work: (repository: BaseRepository<R, K>) => V | Promise<V>) => Promise<V>;
|
|
23
|
+
readonly publish: (action: RepositoryAction, row: Readonly<R>) => Promise<void>;
|
|
24
|
+
readonly registerRestore: (restore: () => undefined) => void;
|
|
25
|
+
readonly mutate: <V>(entity: object, work: () => V | Promise<V>) => Promise<V>;
|
|
26
|
+
readonly assertEditable: (entity: object) => void;
|
|
27
|
+
readonly assertBindable: (entity: object) => void;
|
|
28
|
+
readonly dehydrate: ((values: Readonly<Partial<R>>) => Partial<R> | Promise<Partial<R>>) | undefined;
|
|
29
|
+
readonly observers: readonly ModelObserver<unknown>[];
|
|
30
|
+
readonly scopes: readonly ((query: unknown) => unknown)[];
|
|
31
|
+
readonly construct: ((state: ModelState<R>, source: Model<R, K> | undefined) => Model<R, K>) | undefined;
|
|
32
|
+
readonly modelDefinition: AnyModelDefinition | undefined;
|
|
33
|
+
}
|
|
34
|
+
declare function attachBindingPorts<R extends object, K extends keyof R & string, B extends RepositoryBinding<R, K>>(binding: B, ports: BindingPorts<R, K>): B;
|
|
35
|
+
declare function getBindingPorts<R extends object, K extends keyof R & string>(binding: RepositoryBinding<R, K>): BindingPorts<R, K>;
|
|
36
|
+
/** Per-attached-binding state, not a mutable per-class or app-global association. */
|
|
37
|
+
declare function createMutationPorts(ownership: OwnedExecution, assertActive: () => void): {
|
|
38
|
+
assertBindable(entity: object): void;
|
|
39
|
+
assertEditable(entity: object): void;
|
|
40
|
+
mutate<V>(entity: object, run: <T>(work: () => T | Promise<T>) => Promise<T>, work: () => V | Promise<V>): Promise<V>;
|
|
41
|
+
};
|
|
42
|
+
export type { BindingPorts, ModelBinding, Session };
|
|
43
|
+
export { attachBindingPorts, createMutationPorts, getBindingPorts };
|
|
44
|
+
interface SessionIdentity {
|
|
45
|
+
readonly self: Session;
|
|
46
|
+
readonly configuredPool: object;
|
|
47
|
+
readonly transactional: boolean;
|
|
48
|
+
readonly tenant: unknown;
|
|
49
|
+
readonly signal: AbortSignal;
|
|
50
|
+
readonly assertActive: () => void;
|
|
51
|
+
readonly run: <T>(work: () => T | Promise<T>) => Promise<T>;
|
|
52
|
+
readonly app: object;
|
|
53
|
+
readonly execution: object;
|
|
54
|
+
readonly pool: object;
|
|
55
|
+
}
|
|
56
|
+
declare function attachSessionIdentity(session: Session, identity: Omit<SessionIdentity, "self">): void;
|
|
57
|
+
declare function assertSameSessionSelection(expected: Session, selected: Session): void;
|
|
58
|
+
export { assertSameSessionSelection, attachSessionIdentity };
|
|
59
|
+
interface SessionOwnerIdentity {
|
|
60
|
+
readonly app: object;
|
|
61
|
+
readonly configuredPool: object;
|
|
62
|
+
}
|
|
63
|
+
declare function assertOwnedSession(owner: SessionOwnerIdentity, selected: Session, requireTransaction?: boolean): Readonly<{
|
|
64
|
+
signal: AbortSignal;
|
|
65
|
+
tenant: unknown;
|
|
66
|
+
}>;
|
|
67
|
+
export type { SessionOwnerIdentity };
|
|
68
|
+
export { assertOwnedSession };
|
|
69
|
+
interface ConfiguredPoolIdentity {
|
|
70
|
+
readonly driver: DatabaseDriver;
|
|
71
|
+
readonly max: number | undefined;
|
|
72
|
+
}
|
|
73
|
+
interface DatabaseOwnership {
|
|
74
|
+
readonly app: object;
|
|
75
|
+
readonly connections: Readonly<Record<string, ConfiguredPoolIdentity>>;
|
|
76
|
+
}
|
|
77
|
+
declare const DATABASE_OWNERSHIP_TOKEN: import("@getstrata/core/contracts/token").ServiceToken<DatabaseOwnership>;
|
|
78
|
+
declare function createDatabaseOwnership(config: Readonly<Record<string, DatabaseConnectionOptions>>): DatabaseOwnership;
|
|
79
|
+
export type { ConfiguredPoolIdentity, DatabaseOwnership };
|
|
80
|
+
export { createDatabaseOwnership, DATABASE_OWNERSHIP_TOKEN };
|
|
81
|
+
/** Diagnostic denial only; this store never selects or revives persistence authority. */
|
|
82
|
+
declare function runWithTransactionLineage<T>(owner: SessionOwnerIdentity, live: () => boolean, invoke: () => T): T;
|
|
83
|
+
declare function assertNoOwnedTransaction(owner: SessionOwnerIdentity, message?: "Outbox coordination must run outside business transactions." | "SQL observations require an independent transaction."): void;
|
|
84
|
+
declare function runOwnedSession<T>(owner: SessionOwnerIdentity, selected: Session, work: () => T | Promise<T>): Promise<T>;
|
|
85
|
+
export { assertNoOwnedTransaction, runOwnedSession, runWithTransactionLineage };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Canonical ORM classes and private construction accessors; package-private entry. */
|
|
2
|
+
export { default as BaseRepository, getRepositoryBinding } from "./baseRepository";
|
|
3
|
+
export { BelongsToManyRelationQuery, BelongsToRelationQuery, BoundModelFacade, createBoundModel, getModelBinding, HasManyRelationQuery, HasManyThroughRelationQuery, HasOneRelationQuery, Model, ModelQuery, MorphManyRelationQuery, MorphOneRelationQuery, MorphToRelationQuery, modelFacade, runObservers, } from "./model";
|
|
4
|
+
export { RepositoryQuery, snapshotRepositoryQuery } from "./repositoryQuery";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Application } from "../contracts/application";
|
|
2
|
+
import type { DatabaseConnectionOptions, SqlStatement } from "./driverPorts";
|
|
3
|
+
import { type SqlDialect } from "./sqlDialects";
|
|
4
|
+
interface ReadOnlyObservationExecutor {
|
|
5
|
+
readonly dialect: SqlDialect;
|
|
6
|
+
execute<Row>(statement: SqlStatement): Promise<readonly Row[]>;
|
|
7
|
+
}
|
|
8
|
+
type ReadOnlyObservation = <T>(timeoutMs: number, work: (database: ReadOnlyObservationExecutor, remaining: () => number) => Promise<T>) => Promise<T>;
|
|
9
|
+
interface ReadOnlyObservationOptions {
|
|
10
|
+
/** Trusted platform collector admission; never derived from request input. */
|
|
11
|
+
readonly postgresPolicy?: "bypass";
|
|
12
|
+
}
|
|
13
|
+
/** Compose from the same immutable connection selection as the application's bindings. */
|
|
14
|
+
declare function createOwnedReadOnlyObservation(application: Application, connection: string, options: DatabaseConnectionOptions, observationOptions?: ReadOnlyObservationOptions): ReadOnlyObservation;
|
|
15
|
+
export type { ReadOnlyObservation, ReadOnlyObservationExecutor, ReadOnlyObservationOptions };
|
|
16
|
+
export { createOwnedReadOnlyObservation };
|