ts-prorm-orm 1.2.3 → 2.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/CHANGELOG.md +331 -1
- package/README.md +32 -24
- package/dist/compliance/data-classifier.d.ts +6 -0
- package/dist/compliance/data-classifier.js +6 -0
- package/dist/compliance/data-lineage.d.ts +4 -0
- package/dist/compliance/data-lineage.js +4 -0
- package/dist/compliance/data-masker.d.ts +4 -0
- package/dist/compliance/data-masker.js +4 -0
- package/dist/compliance/index.d.ts +4 -0
- package/dist/compliance/index.js +15 -1
- package/dist/compliance/pseudonymization.d.ts +4 -0
- package/dist/compliance/pseudonymization.js +4 -0
- package/dist/compliance/query-firewall.d.ts +9 -9
- package/dist/compliance/query-firewall.js +9 -9
- package/dist/compliance/rate-limiter.d.ts +4 -0
- package/dist/compliance/rate-limiter.js +4 -0
- package/dist/compliance/row-level-security.d.ts +2 -0
- package/dist/compliance/row-level-security.js +2 -0
- package/dist/compliance/security-decorator.d.ts +8 -0
- package/dist/compliance/security-decorator.js +8 -0
- package/dist/compliance/session-isolation.d.ts +4 -0
- package/dist/compliance/session-isolation.js +4 -0
- package/dist/compliance/worm-storage.d.ts +4 -0
- package/dist/compliance/worm-storage.js +4 -0
- package/dist/connection-manager.js +13 -1
- package/dist/core/expressions.d.ts +58 -0
- package/dist/core/expressions.js +83 -0
- package/dist/core/hooks-manager.d.ts +179 -0
- package/dist/core/hooks-manager.js +291 -0
- package/dist/core/types.d.ts +235 -0
- package/dist/core/types.js +9 -0
- package/dist/decorators/audit.d.ts +3 -1
- package/dist/decorators/audit.js +3 -1
- package/dist/decorators/check.d.ts +15 -15
- package/dist/decorators/check.js +15 -15
- package/dist/decorators/collate.d.ts +16 -0
- package/dist/decorators/collate.js +16 -0
- package/dist/decorators/comment.d.ts +3 -1
- package/dist/decorators/comment.js +3 -1
- package/dist/decorators/database-settings.d.ts +6 -0
- package/dist/decorators/database-settings.js +6 -0
- package/dist/decorators/default.d.ts +2 -0
- package/dist/decorators/default.js +2 -0
- package/dist/decorators/encryption.d.ts +7 -1
- package/dist/decorators/encryption.js +7 -1
- package/dist/decorators/engine.d.ts +4 -0
- package/dist/decorators/engine.js +4 -0
- package/dist/decorators/fk-constraints.d.ts +32 -32
- package/dist/decorators/fk-constraints.js +32 -32
- package/dist/decorators/foreign-table.d.ts +1 -1
- package/dist/decorators/generated.d.ts +8 -0
- package/dist/decorators/generated.js +8 -0
- package/dist/decorators/hstore.d.ts +6 -0
- package/dist/decorators/hstore.js +6 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.js +11 -1
- package/dist/decorators/json-column.d.ts +2 -0
- package/dist/decorators/json-column.js +2 -0
- package/dist/decorators/jsonb.d.ts +6 -0
- package/dist/decorators/jsonb.js +6 -0
- package/dist/decorators/permissions.d.ts +12 -0
- package/dist/decorators/permissions.js +12 -0
- package/dist/decorators/procedure.d.ts +4 -2
- package/dist/decorators/procedure.js +4 -2
- package/dist/decorators/query-options.d.ts +24 -0
- package/dist/decorators/query-options.js +24 -0
- package/dist/decorators/range.d.ts +8 -0
- package/dist/decorators/range.js +8 -0
- package/dist/decorators/set-column.d.ts +2 -0
- package/dist/decorators/set-column.js +2 -0
- package/dist/decorators/spatial.d.ts +2 -0
- package/dist/decorators/spatial.js +2 -0
- package/dist/decorators/storage.d.ts +24 -0
- package/dist/decorators/storage.js +24 -0
- package/dist/decorators/timezone.d.ts +7 -7
- package/dist/decorators/timezone.js +7 -7
- package/dist/decorators/trigger.d.ts +3 -1
- package/dist/decorators/trigger.js +3 -1
- package/dist/decorators/uuid.d.ts +6 -0
- package/dist/decorators/uuid.js +6 -0
- package/dist/decorators/view.d.ts +7 -1
- package/dist/decorators/view.js +7 -1
- package/dist/diagrams/chen-diagram.d.ts +15 -12
- package/dist/diagrams/chen-diagram.js +76 -85
- package/dist/diagrams/class-diagram.d.ts +9 -8
- package/dist/diagrams/class-diagram.js +60 -82
- package/dist/diagrams/core/index.d.ts +13 -0
- package/dist/diagrams/core/index.js +33 -0
- package/dist/diagrams/core/layout.d.ts +104 -0
- package/dist/diagrams/core/layout.js +223 -0
- package/dist/diagrams/{svg-dom.d.ts → core/svg.d.ts} +8 -20
- package/dist/diagrams/{svg-dom.js → core/svg.js} +21 -29
- package/dist/diagrams/core/theme.d.ts +84 -0
- package/dist/diagrams/core/theme.js +62 -0
- package/dist/diagrams/dependency-diagram.d.ts +15 -14
- package/dist/diagrams/dependency-diagram.js +71 -105
- package/dist/diagrams/er-diagram.d.ts +13 -26
- package/dist/diagrams/er-diagram.js +180 -259
- package/dist/diagrams/flow-diagram.d.ts +16 -11
- package/dist/diagrams/flow-diagram.js +96 -91
- package/dist/diagrams/gantt-diagram.d.ts +10 -5
- package/dist/diagrams/gantt-diagram.js +77 -103
- package/dist/diagrams/index-diagram.d.ts +10 -10
- package/dist/diagrams/index-diagram.js +106 -116
- package/dist/diagrams/index.d.ts +6 -9
- package/dist/diagrams/index.js +9 -24
- package/dist/diagrams/migration-diagram.d.ts +8 -4
- package/dist/diagrams/migration-diagram.js +189 -161
- package/dist/diagrams/model-diagram.d.ts +34 -34
- package/dist/diagrams/model-diagram.js +106 -485
- package/dist/diagrams/package-diagram.d.ts +9 -6
- package/dist/diagrams/package-diagram.js +64 -101
- package/dist/diagrams/relational-diagram.d.ts +12 -10
- package/dist/diagrams/relational-diagram.js +87 -114
- package/dist/diagrams/schemadoc-diagram.d.ts +8 -8
- package/dist/diagrams/schemadoc-diagram.js +71 -93
- package/dist/diagrams/sequence-diagram.d.ts +10 -10
- package/dist/diagrams/sequence-diagram.js +64 -89
- package/dist/diagrams/state-diagram.d.ts +10 -9
- package/dist/diagrams/state-diagram.js +69 -92
- package/dist/diagrams/tree-diagram.d.ts +11 -5
- package/dist/diagrams/tree-diagram.js +41 -65
- package/dist/dialects/clickhouse/index.js +15 -0
- package/dist/dialects/cockroachdb/index.d.ts +1 -1
- package/dist/dialects/cockroachdb/index.js +32 -63
- package/dist/dialects/db2/index.js +23 -8
- package/dist/dialects/dialect.d.ts +141 -5
- package/dist/dialects/duckdb/index.js +9 -2
- package/dist/dialects/hana/index.js +22 -5
- package/dist/dialects/lock-clause-helper.d.ts +167 -0
- package/dist/dialects/lock-clause-helper.js +316 -0
- package/dist/dialects/mariadb/index.d.ts +7 -4
- package/dist/dialects/mariadb/index.js +36 -60
- package/dist/dialects/mssql/index.js +34 -3
- package/dist/dialects/mysql/index.d.ts +1 -1
- package/dist/dialects/mysql/index.js +17 -45
- package/dist/dialects/oracle/index.d.ts +14 -3
- package/dist/dialects/oracle/index.js +66 -36
- package/dist/dialects/order-expression-helper.d.ts +72 -0
- package/dist/dialects/order-expression-helper.js +154 -0
- package/dist/dialects/partial-index.d.ts +52 -0
- package/dist/dialects/partial-index.js +251 -0
- package/dist/dialects/postgres/index.d.ts +1 -1
- package/dist/dialects/postgres/index.js +43 -68
- package/dist/dialects/redshift/index.js +9 -2
- package/dist/dialects/snowflake/index.js +17 -0
- package/dist/dialects/spanner/index.js +7 -2
- package/dist/dialects/sqlite/driver.d.ts +55 -0
- package/dist/dialects/sqlite/driver.js +102 -0
- package/dist/dialects/sqlite/index.d.ts +1 -1
- package/dist/dialects/sqlite/index.js +49 -27
- package/dist/external-fields/decorator.d.ts +2 -0
- package/dist/external-fields/decorator.js +2 -0
- package/dist/graph/base-graph-dialect.d.ts +24 -3
- package/dist/graph/base-graph-dialect.js +43 -2
- package/dist/graph/dgraph/index.js +6 -0
- package/dist/graph/gremlin/index.d.ts +6 -0
- package/dist/graph/gremlin/index.js +12 -1
- package/dist/graph/index.d.ts +1 -1
- package/dist/graph/neo4j/index.d.ts +2 -0
- package/dist/graph/neo4j/index.js +6 -1
- package/dist/graph/types.d.ts +12 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +53 -7
- package/dist/logging/index.d.ts +10 -0
- package/dist/logging/index.js +23 -0
- package/dist/logging/query-logging.d.ts +82 -0
- package/dist/logging/query-logging.js +102 -0
- package/dist/models/associations.d.ts +38 -0
- package/dist/models/associations.js +16 -0
- package/dist/models/decorators.d.ts +55 -19
- package/dist/models/decorators.js +95 -19
- package/dist/models/eager-load.d.ts +99 -0
- package/dist/models/eager-load.js +348 -5
- package/dist/models/indexes.d.ts +3 -2
- package/dist/models/indexes.js +7 -1
- package/dist/models/model.js +69 -43
- package/dist/prorm.d.ts +175 -409
- package/dist/prorm.js +1132 -553
- package/dist/query-builders/order-limit-builder.js +12 -10
- package/dist/query-builders/sql-compiler.d.ts +10 -3
- package/dist/query-builders/sql-compiler.js +14 -43
- package/dist/query-interface.d.ts +2 -1
- package/dist/schema-objects.d.ts +42 -0
- package/dist/schema-objects.js +28 -0
- package/dist/sql-constants.d.ts +44 -0
- package/dist/sql-constants.js +138 -1
- package/dist/types/index.d.ts +387 -17
- package/dist/types/index.js +10 -15
- package/dist/types/query-types.d.ts +26 -0
- package/dist/types/query-types.js +30 -0
- package/package.json +39 -8
- package/dist/decorators/belongs-to-many.js +0 -115
- package/dist/decorators/belongs-to.js +0 -115
- package/dist/decorators/has-many.js +0 -127
- package/dist/decorators/has-one.js +0 -116
- package/dist/diagrams/palette.d.ts +0 -138
- package/dist/diagrams/palette.js +0 -194
- package/dist/hooks/hooks-manager.d.ts +0 -189
- package/dist/hooks/hooks-manager.js +0 -350
- package/dist/hooks/index.d.ts +0 -8
- package/dist/hooks/index.js +0 -37
- /package/dist/{logging.d.ts → logging/logger.d.ts} +0 -0
- /package/dist/{logging.js → logging/logger.js} +0 -0
package/dist/graph/types.d.ts
CHANGED
|
@@ -142,6 +142,17 @@ export interface GraphTraversalSpec {
|
|
|
142
142
|
targetWhere?: WhereOptions;
|
|
143
143
|
limit?: number;
|
|
144
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Direction of one normalized order term.
|
|
147
|
+
*
|
|
148
|
+
* `'RANDOM'` comes from the `random()` order helper (`src/operators.ts`) and
|
|
149
|
+
* carries no field — the engines that can shuffle express it as a whole term
|
|
150
|
+
* of their own (Cypher `rand()`, Gremlin `order().by(shuffle)`), and the ones
|
|
151
|
+
* that cannot raise a {@link GraphCapabilityError}.
|
|
152
|
+
*/
|
|
153
|
+
export type GraphOrderDirection = 'ASC' | 'DESC' | 'RANDOM';
|
|
154
|
+
/** One normalized order term: the property to sort on and its direction. */
|
|
155
|
+
export type GraphOrderTerm = [string, GraphOrderDirection];
|
|
145
156
|
/** Options for a node find/match. */
|
|
146
157
|
export interface NodeMatchSpec {
|
|
147
158
|
label: string;
|
|
@@ -150,7 +161,7 @@ export interface NodeMatchSpec {
|
|
|
150
161
|
include?: string[];
|
|
151
162
|
exclude?: string[];
|
|
152
163
|
};
|
|
153
|
-
order?:
|
|
164
|
+
order?: GraphOrderTerm[] | string[];
|
|
154
165
|
limit?: number | string;
|
|
155
166
|
offset?: number | string;
|
|
156
167
|
/** Associations to co-fetch as graph walks. */
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { ConnectionManager, createConnectionManager, NamedConnectionOptions } fr
|
|
|
8
8
|
export { DataTypes, AbstractDataType } from './models/data-types';
|
|
9
9
|
export { CreationOptional, NonAttribute, ForeignKey, InferAttributes, InferCreationAttributes, PartialBy, RequiredBy, ModelStatic, ModelOptions, } from './models/typescript-types';
|
|
10
10
|
export { Model } from './models';
|
|
11
|
-
export { Table, Attribute, Column, AllowNull, PrimaryKey, AutoIncrement, NotNull, Default, Unique, Comment, getModelMetadata, getAttributeMetadata, getModelAttributes, clearMetadata, HasOneOptions, HasManyOptions, BelongsToOptions, BelongsToManyOptions, HasOne, HasMany, BelongsTo, BelongsToMany, } from './models/decorators';
|
|
11
|
+
export { Table, AbstractModel, isAbstractModel, getInheritedAttributeMetadata, Attribute, Column, AllowNull, PrimaryKey, AutoIncrement, NotNull, Default, Unique, Comment, getModelMetadata, getAttributeMetadata, getModelAttributes, clearMetadata, HasOneOptions, HasManyOptions, BelongsToOptions, BelongsToManyOptions, HasOne, HasMany, BelongsTo, BelongsToMany, } from './models/decorators';
|
|
12
12
|
export * from './compliance';
|
|
13
13
|
export * from './extensions';
|
|
14
14
|
export declare const STRING: ((...args: any[]) => import("./models").STRING) & {
|
|
@@ -172,6 +172,8 @@ export { ReplicaManager } from './replica-manager';
|
|
|
172
172
|
export type { ReplicaStatus, ReplicaConnectionConfig, LagDetectionConfig, ReplicationOptions, RoutingStrategy, } from './replica-manager';
|
|
173
173
|
export { Dialect, BaseDialect, DialectRegistry } from './dialects/dialect';
|
|
174
174
|
export { BaseGraphDialect, Neo4jGraphDialect, GremlinGraphDialect, DgraphGraphDialect, GRAPH_DIALECTS, registerGraphDialects, } from './graph';
|
|
175
|
+
export { GraphCapabilityError, ParamBag, normalizeWhere, deriveAssociationEdge, defaultEdgeLabel, safeIdent, } from './graph';
|
|
176
|
+
export type { GraphConnectionOptions, GraphStatement, GraphPredicate, CanonOp, GraphAssociationType, GraphAssociationSpec, GraphPropertyDefinition, NodeModelDefinition, EdgeModelDefinition, GraphTraversalDirection, GraphTraversalStep, GraphTraversalSpec, NodeMatchSpec, WhereRenderContext, EdgeCreateSpec, NodeConstraintKind, DialectRegistryLike, } from './graph';
|
|
175
177
|
export type { DialectOptions, ColumnDefinition, TableOptions, DropTableOptions, TableDescription, IndexOptions, BuildOptions, InsertOptions, UpdateOptions as DialectUpdateOptions, DeleteOptions, SelectOptions, CTEOption, CreateExtensionOptions, DropExtensionOptions, ExtensionInfo, } from './dialects/dialect';
|
|
176
178
|
export { SQLiteDialect } from './dialects/sqlite';
|
|
177
179
|
export { OracleDialect, createOracleDialect } from './dialects/oracle';
|
|
@@ -210,11 +212,18 @@ export { UserManager, PRIVILEGE_LEVELS } from './user-management';
|
|
|
210
212
|
export type { PrivilegeType, PrivilegeScope, CreateUserOptions, AlterUserOptions, GrantOptions, RevokeOptions, RoleOptions, UserInfo, PrivilegeInfo, } from './user-management';
|
|
211
213
|
export { SQLiteAdvanced, createSQLiteAdvanced } from './sqlite-advanced';
|
|
212
214
|
export type { TriggerTiming, TriggerEvent, FTS5Tokenizer, GeneratedStorageType, ConflictAlgorithm, } from './sqlite-advanced';
|
|
213
|
-
export { SQL, MYSQL, MARIADB, POSTGRES, SQLITE, getConstantsForDialect, IsolationLevelEnum, IsolationLevelValue, } from './sql-constants';
|
|
214
|
-
export type { SQLConstants, MySQLConstants, PostgresConstants, SQLiteConstants, IsolationLevel, ForeignKeyChecks, UniqueKeyChecks, Autocommit, Cache, SqlMode, PragmaSettings, ConstraintDeferral, SearchPath, } from './sql-constants';
|
|
215
|
+
export { SQL, MYSQL, MARIADB, POSTGRES, SQLITE, getConstantsForDialect, getForeignKeyChecksSQL, UnsupportedForeignKeyChecksError, IsolationLevelEnum, IsolationLevelValue, } from './sql-constants';
|
|
216
|
+
export type { ForeignKeyChecksMode, SQLConstants, MySQLConstants, PostgresConstants, SQLiteConstants, IsolationLevel, ForeignKeyChecks, UniqueKeyChecks, Autocommit, Cache, SqlMode, PragmaSettings, ConstraintDeferral, SearchPath, } from './sql-constants';
|
|
215
217
|
export * from './nosql';
|
|
216
218
|
export { count, countDistinct, avg, min, max, stringAgg, arrayAgg, CaseBuilder, SimpleCaseBuilder, caseWhen, caseOf, dateTrunc, dateAdd, dateSub, dateDiff, currentDate, currentTimestamp, fullTextMatch, fullTextRank, jsonExtract, jsonKeys, jsonTypeOf, round, ceil, floor, power, sqrt, abs, sign, mod, greatest, least, concat, upper, lower, length, replace, lpad, rpad, split, WindowFunctionBuilder, rowNumber, rank, denseRank, percentRank, cumeDist, ntile, lag, lead, firstValue, lastValue, nthValue, sumOver, avgOver, countOver, minOver, maxOver, windowFn, NullsOrder, } from './query-builders/functions';
|
|
217
219
|
export { random as sqlRandom, truncate as sqlTruncate, substring as sqlSubstring, trim as sqlTrim, ltrim as sqlLtrim, rtrim as sqlRtrim, jsonContains as sqlJsonContains, jsonHasKey as sqlJsonHasKey, formatDate as sqlFormatDate, now as sqlNow, repeat as sqlRepeat, reverse as sqlReverse, sum as sqlSum, } from './query-builders/functions';
|
|
220
|
+
export { AbstractCacheManager, RedisClusterCache, createRedisClusterCache } from './cache';
|
|
221
|
+
export type { CacheBackend, L2CacheOptions, CacheKeyOptions, CacheStats, CacheBackendFactory, RedisClusterOptions, RedisClusterNodeConfig, } from './cache';
|
|
222
|
+
export type { CacheEntry as CacheManagerEntry, CacheManagerOptions as CacheManagerConfig, L1CacheOptions as CacheManagerL1Options, RedisClusterCacheOptions as RedisClusterCacheConfig, RedisClusterNode as RedisClusterCacheNode, } from './cache';
|
|
223
|
+
export { AuditLogger, setAuditLogger, getAuditLogger, addAuditHistoryToModel, addAuditHistoryToInstance, } from './audit';
|
|
224
|
+
export type { AuditLog, AuditLoggerOptions } from './audit';
|
|
225
|
+
export { convertPrismaSchema, parsePrismaSchema, resolveRelations } from './prisma-migrate';
|
|
226
|
+
export type { ConversionResult, PrismaSchema, PrismaModel, PrismaEnum, PrismaField, PrormRelation, } from './prisma-migrate';
|
|
218
227
|
import { Prorm } from './prorm';
|
|
219
228
|
import { Transaction } from './types';
|
|
220
229
|
declare const ORM: {
|
package/dist/index.js
CHANGED
|
@@ -40,13 +40,13 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
40
40
|
};
|
|
41
41
|
})();
|
|
42
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
-
exports.
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
exports.
|
|
47
|
-
exports.
|
|
48
|
-
exports.
|
|
49
|
-
exports.sqlSum = exports.sqlReverse = exports.sqlRepeat = void 0;
|
|
43
|
+
exports.JSONB = exports.JSON = exports.UUIDV4 = exports.UUID = exports.TIME = exports.NOW = exports.DATEONLY = exports.DATE = exports.BOOLEAN = exports.DECIMAL = exports.DOUBLE = exports.FLOAT = exports.BIGINT = exports.INTEGER = exports.TEXT = exports.CHAR = exports.VARCHAR = exports.STRING = exports.BelongsToMany = exports.BelongsTo = exports.HasMany = exports.HasOne = exports.clearMetadata = exports.getModelAttributes = exports.getAttributeMetadata = exports.getModelMetadata = exports.Comment = exports.Unique = exports.Default = exports.NotNull = exports.AutoIncrement = exports.PrimaryKey = exports.AllowNull = exports.Column = exports.Attribute = exports.getInheritedAttributeMetadata = exports.isAbstractModel = exports.AbstractModel = exports.Table = exports.Model = exports.AbstractDataType = exports.DataTypes = exports.createConnectionManager = exports.ConnectionManager = exports.StreamIterator = exports.BatchTransform = exports.FilterTransform = exports.MapTransform = exports.QueryTypes = exports.Prorm = void 0;
|
|
44
|
+
exports.random = exports.desc = exports.asc = exports.overlap = exports.contains = exports.isNotNull = exports.isNull = exports.notBetween = exports.between = exports.notIn = exports.inOp = exports.in = exports.notIRegexp = exports.iRegexp = exports.notRegexp = exports.regexp = exports.match = exports.notSubstring = exports.substring = exports.notEndsWith = exports.endsWith = exports.notStartsWith = exports.startsWith = exports.notILike = exports.iLike = exports.notLike = exports.like = exports.lte = exports.lt = exports.gte = exports.gt = exports.ne = exports.eq = exports.not = exports.or = exports.and = exports.where = exports.normalizeOperatorKeys = exports.operatorToWhereKey = exports.getOperatorString = exports.OpAliases = exports.Operators = exports.Op = exports.GEOGRAPHY = exports.GEOMETRY = exports.ARRAY = exports.ENUM = exports.VARBINARY = exports.BINARY = exports.BLOB = void 0;
|
|
45
|
+
exports.coalesce = exports.isEmpty = exports.formatWhere = exports.escapeId = exports.escapeString = exports.formatValue = exports.formatValues = exports.isValidUUID = exports.generateShortUUID = exports.generateUUID = exports.omit = exports.pick = exports.merge = exports.cloneDeep = exports.singularize = exports.pluralize = exports.snakeCase = exports.camelize = exports.kebabToCamel = exports.camelToKebab = exports.snakeToCamel = exports.camelToSnake = exports.ModelManager = exports.ScopeManager = exports.createPool = exports.PooledConnection = exports.DatabaseConnectionPool = exports.ConnectionPool = exports.createMSSQLDialect = exports.MSSQLDialect = exports.createOracleDialect = exports.OracleDialect = exports.SQLiteDialect = exports.safeIdent = exports.defaultEdgeLabel = exports.deriveAssociationEdge = exports.normalizeWhere = exports.ParamBag = exports.GraphCapabilityError = exports.registerGraphDialects = exports.GRAPH_DIALECTS = exports.DgraphGraphDialect = exports.GremlinGraphDialect = exports.Neo4jGraphDialect = exports.BaseGraphDialect = exports.DialectRegistry = exports.BaseDialect = exports.ReplicaManager = exports.Transaction = exports.isOrderExpression = void 0;
|
|
46
|
+
exports.isEmptyResultError = exports.isConstraintError = exports.isConnectionError = exports.isValidationError = exports.isPrormError = exports.ErrorCodes = exports.EmptyResultError = exports.EagerLoadError = exports.AssociationError = exports.BulkRecordError = exports.ResourceLockedError = exports.TimeoutError = exports.ExclusionConstraintError = exports.ForeignKeyConstraintError = exports.UniqueConstraintError = exports.ValidationError = exports.DatabaseError = exports.ConnectionError = exports.PrormError = exports.setDefaultLogger = exports.getDefaultLogger = exports.createSilentLogger = exports.createLogger = exports.LogLevelStrings = exports.LogLevel = exports.Logger = exports.createQueryInterface = exports.CreateQueryInterface = exports.stringUtils = exports.regex = exports.truncateStr = exports.padEnd = exports.padStart = exports.trimEnd = exports.trimStart = exports.rtrim = exports.ltrim = exports.trim = exports.capitalizeWords = exports.capitalize = exports.lowerCase = exports.upperCase = exports.spliceStr = exports.formatDefaultValue = exports.toDefaultValue = exports.removeTicks = exports.addTicks = exports.escapeLike = exports.pad = exports.truncate = void 0;
|
|
47
|
+
exports.CaseBuilder = exports.arrayAgg = exports.stringAgg = exports.max = exports.min = exports.avg = exports.countDistinct = exports.count = exports.IsolationLevelEnum = exports.UnsupportedForeignKeyChecksError = exports.getForeignKeyChecksSQL = exports.getConstantsForDialect = exports.SQLITE = exports.POSTGRES = exports.MARIADB = exports.MYSQL = exports.SQL = exports.createSQLiteAdvanced = exports.SQLiteAdvanced = exports.PRIVILEGE_LEVELS = exports.UserManager = exports.DatabaseSecurityDecorator = exports.Database = exports.buildCreateFullTextIndexSQL = exports.buildDropPolicySQL = exports.buildCreatePolicySQL = exports.buildEnableRowLevelSecuritySQL = exports.buildDropTriggerSQL = exports.buildCreateTriggerStatements = exports.buildDropSequenceSQL = exports.buildCreateSequenceSQL = exports.UnsupportedSchemaObjectError = exports.buildOptionsClause = exports.KNOWN_FDWS = exports.ForeignDataManager = exports.generateERDiagramFromFile = exports.generateModelDiagramFromFile = exports.generateERDiagram = exports.generateModelDiagram = exports.ERDiagram = exports.ModelDiagram = exports.removeGeneratedModel = exports.listModels = exports.setOutputDir = exports.getOutputDir = exports.configureCLI = exports.generateModels = exports.model = exports.CLI = exports.utils = void 0;
|
|
48
|
+
exports.windowFn = exports.maxOver = exports.minOver = exports.countOver = exports.avgOver = exports.sumOver = exports.nthValue = exports.lastValue = exports.firstValue = exports.lead = exports.lag = exports.ntile = exports.cumeDist = exports.percentRank = exports.denseRank = exports.rank = exports.rowNumber = exports.WindowFunctionBuilder = exports.split = exports.rpad = exports.lpad = exports.replace = exports.length = exports.lower = exports.upper = exports.concat = exports.least = exports.greatest = exports.mod = exports.sign = exports.abs = exports.sqrt = exports.power = exports.floor = exports.ceil = exports.round = exports.jsonTypeOf = exports.jsonKeys = exports.jsonExtract = exports.fullTextRank = exports.fullTextMatch = exports.currentTimestamp = exports.currentDate = exports.dateDiff = exports.dateSub = exports.dateAdd = exports.dateTrunc = exports.caseOf = exports.caseWhen = exports.SimpleCaseBuilder = void 0;
|
|
49
|
+
exports.resolveRelations = exports.parsePrismaSchema = exports.convertPrismaSchema = exports.addAuditHistoryToInstance = exports.addAuditHistoryToModel = exports.getAuditLogger = exports.setAuditLogger = exports.AuditLogger = exports.createRedisClusterCache = exports.RedisClusterCache = exports.AbstractCacheManager = exports.sqlSum = exports.sqlReverse = exports.sqlRepeat = exports.sqlNow = exports.sqlFormatDate = exports.sqlJsonHasKey = exports.sqlJsonContains = exports.sqlRtrim = exports.sqlLtrim = exports.sqlTrim = exports.sqlSubstring = exports.sqlTruncate = exports.sqlRandom = exports.NullsOrder = void 0;
|
|
50
50
|
// Re-export Prorm class and query types
|
|
51
51
|
var prorm_1 = require("./prorm");
|
|
52
52
|
Object.defineProperty(exports, "Prorm", { enumerable: true, get: function () { return prorm_1.Prorm; } });
|
|
@@ -73,6 +73,9 @@ Object.defineProperty(exports, "Model", { enumerable: true, get: function () { r
|
|
|
73
73
|
// Export decorators
|
|
74
74
|
var decorators_1 = require("./models/decorators");
|
|
75
75
|
Object.defineProperty(exports, "Table", { enumerable: true, get: function () { return decorators_1.Table; } });
|
|
76
|
+
Object.defineProperty(exports, "AbstractModel", { enumerable: true, get: function () { return decorators_1.AbstractModel; } });
|
|
77
|
+
Object.defineProperty(exports, "isAbstractModel", { enumerable: true, get: function () { return decorators_1.isAbstractModel; } });
|
|
78
|
+
Object.defineProperty(exports, "getInheritedAttributeMetadata", { enumerable: true, get: function () { return decorators_1.getInheritedAttributeMetadata; } });
|
|
76
79
|
Object.defineProperty(exports, "Attribute", { enumerable: true, get: function () { return decorators_1.Attribute; } });
|
|
77
80
|
Object.defineProperty(exports, "Column", { enumerable: true, get: function () { return decorators_1.Column; } });
|
|
78
81
|
Object.defineProperty(exports, "AllowNull", { enumerable: true, get: function () { return decorators_1.AllowNull; } });
|
|
@@ -212,6 +215,16 @@ Object.defineProperty(exports, "registerGraphDialects", { enumerable: true, get:
|
|
|
212
215
|
const dialect_2 = require("./dialects/dialect");
|
|
213
216
|
const graph_2 = require("./graph");
|
|
214
217
|
(0, graph_2.registerGraphDialects)(dialect_2.DialectRegistry);
|
|
218
|
+
// The rest of './graph': the typed error thrown for relational-only features
|
|
219
|
+
// on a graph backend, plus the where/edge helpers a custom graph dialect needs.
|
|
220
|
+
// None of these names collide with the SQL-side exports above.
|
|
221
|
+
var graph_3 = require("./graph");
|
|
222
|
+
Object.defineProperty(exports, "GraphCapabilityError", { enumerable: true, get: function () { return graph_3.GraphCapabilityError; } });
|
|
223
|
+
Object.defineProperty(exports, "ParamBag", { enumerable: true, get: function () { return graph_3.ParamBag; } });
|
|
224
|
+
Object.defineProperty(exports, "normalizeWhere", { enumerable: true, get: function () { return graph_3.normalizeWhere; } });
|
|
225
|
+
Object.defineProperty(exports, "deriveAssociationEdge", { enumerable: true, get: function () { return graph_3.deriveAssociationEdge; } });
|
|
226
|
+
Object.defineProperty(exports, "defaultEdgeLabel", { enumerable: true, get: function () { return graph_3.defaultEdgeLabel; } });
|
|
227
|
+
Object.defineProperty(exports, "safeIdent", { enumerable: true, get: function () { return graph_3.safeIdent; } });
|
|
215
228
|
// Re-export SQLite dialect
|
|
216
229
|
var sqlite_1 = require("./dialects/sqlite");
|
|
217
230
|
Object.defineProperty(exports, "SQLiteDialect", { enumerable: true, get: function () { return sqlite_1.SQLiteDialect; } });
|
|
@@ -394,6 +407,8 @@ Object.defineProperty(exports, "MARIADB", { enumerable: true, get: function () {
|
|
|
394
407
|
Object.defineProperty(exports, "POSTGRES", { enumerable: true, get: function () { return sql_constants_1.POSTGRES; } });
|
|
395
408
|
Object.defineProperty(exports, "SQLITE", { enumerable: true, get: function () { return sql_constants_1.SQLITE; } });
|
|
396
409
|
Object.defineProperty(exports, "getConstantsForDialect", { enumerable: true, get: function () { return sql_constants_1.getConstantsForDialect; } });
|
|
410
|
+
Object.defineProperty(exports, "getForeignKeyChecksSQL", { enumerable: true, get: function () { return sql_constants_1.getForeignKeyChecksSQL; } });
|
|
411
|
+
Object.defineProperty(exports, "UnsupportedForeignKeyChecksError", { enumerable: true, get: function () { return sql_constants_1.UnsupportedForeignKeyChecksError; } });
|
|
397
412
|
Object.defineProperty(exports, "IsolationLevelEnum", { enumerable: true, get: function () { return sql_constants_1.IsolationLevelEnum; } });
|
|
398
413
|
// Re-export NoSQL stores (MongoDB, Redis, DynamoDB) — separate from the SQL
|
|
399
414
|
// dialects since they don't share the SQL-shaped Dialect interface
|
|
@@ -482,6 +497,37 @@ Object.defineProperty(exports, "sqlNow", { enumerable: true, get: function () {
|
|
|
482
497
|
Object.defineProperty(exports, "sqlRepeat", { enumerable: true, get: function () { return functions_2.repeat; } });
|
|
483
498
|
Object.defineProperty(exports, "sqlReverse", { enumerable: true, get: function () { return functions_2.reverse; } });
|
|
484
499
|
Object.defineProperty(exports, "sqlSum", { enumerable: true, get: function () { return functions_2.sum; } });
|
|
500
|
+
// Re-export the query-result cache (L1 in-memory + L2 Redis Cluster).
|
|
501
|
+
// Five of this module's type names are already taken at the package root by
|
|
502
|
+
// unrelated declarations that consumers may import today, so those five keep
|
|
503
|
+
// their existing meaning and the cache module's versions are aliased:
|
|
504
|
+
// CacheEntry -> ./query-optimizers' prepared-statement entry
|
|
505
|
+
// CacheManagerOptions, -> ./types' (older, flatter) cache option shapes
|
|
506
|
+
// L1CacheOptions,
|
|
507
|
+
// RedisClusterCacheOptions,
|
|
508
|
+
// RedisClusterNode
|
|
509
|
+
// The remaining names don't collide and are exported unchanged.
|
|
510
|
+
var cache_1 = require("./cache");
|
|
511
|
+
Object.defineProperty(exports, "AbstractCacheManager", { enumerable: true, get: function () { return cache_1.AbstractCacheManager; } });
|
|
512
|
+
Object.defineProperty(exports, "RedisClusterCache", { enumerable: true, get: function () { return cache_1.RedisClusterCache; } });
|
|
513
|
+
Object.defineProperty(exports, "createRedisClusterCache", { enumerable: true, get: function () { return cache_1.createRedisClusterCache; } });
|
|
514
|
+
// Re-export the audit log (persists model changes to a database table).
|
|
515
|
+
// Note the neighbours: `Audit`/`getAuditLog`/`AuditEntry` (the in-memory
|
|
516
|
+
// decorator, from './decorators') and `ComplianceAuditTrail` (from
|
|
517
|
+
// './compliance') are different features that happen to share the prefix.
|
|
518
|
+
// No name here collides with either, so all are exported as-is.
|
|
519
|
+
var audit_1 = require("./audit");
|
|
520
|
+
Object.defineProperty(exports, "AuditLogger", { enumerable: true, get: function () { return audit_1.AuditLogger; } });
|
|
521
|
+
Object.defineProperty(exports, "setAuditLogger", { enumerable: true, get: function () { return audit_1.setAuditLogger; } });
|
|
522
|
+
Object.defineProperty(exports, "getAuditLogger", { enumerable: true, get: function () { return audit_1.getAuditLogger; } });
|
|
523
|
+
Object.defineProperty(exports, "addAuditHistoryToModel", { enumerable: true, get: function () { return audit_1.addAuditHistoryToModel; } });
|
|
524
|
+
Object.defineProperty(exports, "addAuditHistoryToInstance", { enumerable: true, get: function () { return audit_1.addAuditHistoryToInstance; } });
|
|
525
|
+
// Re-export the Prisma schema converter (pure functions; the CLI's
|
|
526
|
+
// `prisma:import` command owns the filesystem side).
|
|
527
|
+
var prisma_migrate_1 = require("./prisma-migrate");
|
|
528
|
+
Object.defineProperty(exports, "convertPrismaSchema", { enumerable: true, get: function () { return prisma_migrate_1.convertPrismaSchema; } });
|
|
529
|
+
Object.defineProperty(exports, "parsePrismaSchema", { enumerable: true, get: function () { return prisma_migrate_1.parsePrismaSchema; } });
|
|
530
|
+
Object.defineProperty(exports, "resolveRelations", { enumerable: true, get: function () { return prisma_migrate_1.resolveRelations; } });
|
|
485
531
|
// Export default ORM configuration
|
|
486
532
|
const prorm_2 = require("./prorm");
|
|
487
533
|
const data_types_3 = require("./models/data-types");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging.
|
|
3
|
+
*
|
|
4
|
+
* - `logger` the general-purpose levelled Logger (debug/info/warn/error)
|
|
5
|
+
* - `query-logging` query logging in the shape of Sequelize's `logging` option
|
|
6
|
+
*/
|
|
7
|
+
export { LogLevel, LogLevelStrings, Logger, createLogger, createSilentLogger, getDefaultLogger, setDefaultLogger, resetDefaultLogger, } from './logger';
|
|
8
|
+
export type { LoggerOptions, LogEntry, LoggerEvents } from './logger';
|
|
9
|
+
export { logQuery, resolveQueryLogger, formatQueryLog, defaultQueryLogger, } from './query-logging';
|
|
10
|
+
export type { LoggingOption, QueryLogFunction, QueryLogContext, QueryLogOptions, } from './query-logging';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logging.
|
|
4
|
+
*
|
|
5
|
+
* - `logger` the general-purpose levelled Logger (debug/info/warn/error)
|
|
6
|
+
* - `query-logging` query logging in the shape of Sequelize's `logging` option
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.defaultQueryLogger = exports.formatQueryLog = exports.resolveQueryLogger = exports.logQuery = exports.resetDefaultLogger = exports.setDefaultLogger = exports.getDefaultLogger = exports.createSilentLogger = exports.createLogger = exports.Logger = exports.LogLevelStrings = exports.LogLevel = void 0;
|
|
10
|
+
var logger_1 = require("./logger");
|
|
11
|
+
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
|
|
12
|
+
Object.defineProperty(exports, "LogLevelStrings", { enumerable: true, get: function () { return logger_1.LogLevelStrings; } });
|
|
13
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
|
14
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return logger_1.createLogger; } });
|
|
15
|
+
Object.defineProperty(exports, "createSilentLogger", { enumerable: true, get: function () { return logger_1.createSilentLogger; } });
|
|
16
|
+
Object.defineProperty(exports, "getDefaultLogger", { enumerable: true, get: function () { return logger_1.getDefaultLogger; } });
|
|
17
|
+
Object.defineProperty(exports, "setDefaultLogger", { enumerable: true, get: function () { return logger_1.setDefaultLogger; } });
|
|
18
|
+
Object.defineProperty(exports, "resetDefaultLogger", { enumerable: true, get: function () { return logger_1.resetDefaultLogger; } });
|
|
19
|
+
var query_logging_1 = require("./query-logging");
|
|
20
|
+
Object.defineProperty(exports, "logQuery", { enumerable: true, get: function () { return query_logging_1.logQuery; } });
|
|
21
|
+
Object.defineProperty(exports, "resolveQueryLogger", { enumerable: true, get: function () { return query_logging_1.resolveQueryLogger; } });
|
|
22
|
+
Object.defineProperty(exports, "formatQueryLog", { enumerable: true, get: function () { return query_logging_1.formatQueryLog; } });
|
|
23
|
+
Object.defineProperty(exports, "defaultQueryLogger", { enumerable: true, get: function () { return query_logging_1.defaultQueryLogger; } });
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query logging, following the Sequelize logger's shape.
|
|
3
|
+
*
|
|
4
|
+
* Sequelize's contract is small and widely known, so this matches it rather
|
|
5
|
+
* than inventing another:
|
|
6
|
+
*
|
|
7
|
+
* logging: false no output
|
|
8
|
+
* logging: true console.log
|
|
9
|
+
* logging: console.log any function, called as (sql, timing)
|
|
10
|
+
* benchmark: true append the elapsed time
|
|
11
|
+
* logQueryParameters: true append the bound values
|
|
12
|
+
*
|
|
13
|
+
* A per-query `logging` overrides the instance-level one, so a single noisy
|
|
14
|
+
* call can be traced without turning logging on globally - and, symmetrically,
|
|
15
|
+
* one call can be silenced with `logging: false`.
|
|
16
|
+
*
|
|
17
|
+
* This module exists because the resolution logic was previously inlined at
|
|
18
|
+
* four call sites and only some of them ran it: `count`, `bulkCreate`,
|
|
19
|
+
* `increment` and the aggregates emitted nothing at all, so turning logging on
|
|
20
|
+
* showed an incomplete picture of what the ORM was doing.
|
|
21
|
+
*/
|
|
22
|
+
/** What `logging` accepts, at instance or query level. */
|
|
23
|
+
export type LoggingOption = boolean | QueryLogFunction | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* A logging callback.
|
|
26
|
+
*
|
|
27
|
+
* `timing` is the elapsed milliseconds; it is passed whenever the caller
|
|
28
|
+
* measured the query, which is always here. Sequelize only guarantees it under
|
|
29
|
+
* `benchmark: true`, so treat it as optional for compatibility.
|
|
30
|
+
*/
|
|
31
|
+
export type QueryLogFunction = (sql: string, timing?: number) => void;
|
|
32
|
+
/** Everything that shapes one log line. */
|
|
33
|
+
export interface QueryLogContext {
|
|
34
|
+
/** The SQL that was executed. */
|
|
35
|
+
sql: string;
|
|
36
|
+
/** Elapsed milliseconds. */
|
|
37
|
+
duration: number;
|
|
38
|
+
/** Values bound to the statement, when known. */
|
|
39
|
+
parameters?: unknown[];
|
|
40
|
+
/** The model this query was issued for, when applicable. */
|
|
41
|
+
model?: string;
|
|
42
|
+
/** The kind of statement, e.g. SELECT or INSERT. */
|
|
43
|
+
type?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Options controlling how a query is logged. */
|
|
46
|
+
export interface QueryLogOptions {
|
|
47
|
+
/** Instance-level `logging`. */
|
|
48
|
+
instanceLogging?: LoggingOption;
|
|
49
|
+
/** Per-query `logging`, which wins when present. */
|
|
50
|
+
queryLogging?: LoggingOption;
|
|
51
|
+
/** Append `Elapsed time: Nms`. */
|
|
52
|
+
benchmark?: boolean;
|
|
53
|
+
/** Append the bound parameters. */
|
|
54
|
+
logQueryParameters?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the effective logging function for one query.
|
|
58
|
+
*
|
|
59
|
+
* Returns null when logging is off. Precedence is query-level, then
|
|
60
|
+
* instance-level; `false` at either level wins over a function at the other,
|
|
61
|
+
* because silencing is the more specific intent.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveQueryLogger(options: QueryLogOptions): QueryLogFunction | null;
|
|
64
|
+
/** The built-in logger used for `logging: true`. */
|
|
65
|
+
export declare const defaultQueryLogger: QueryLogFunction;
|
|
66
|
+
/**
|
|
67
|
+
* Render one log line.
|
|
68
|
+
*
|
|
69
|
+
* Mirrors Sequelize's `Executed (default): <sql>` prefix so existing log
|
|
70
|
+
* parsers and eyeballs both keep working.
|
|
71
|
+
*/
|
|
72
|
+
export declare function formatQueryLog(context: QueryLogContext, options?: QueryLogOptions): string;
|
|
73
|
+
/**
|
|
74
|
+
* Log one query, if logging is enabled for it.
|
|
75
|
+
*
|
|
76
|
+
* A user-supplied function receives the raw SQL and the timing, exactly as
|
|
77
|
+
* Sequelize does, so callbacks written against that API work unchanged. The
|
|
78
|
+
* built-in logger gets the formatted line instead.
|
|
79
|
+
*
|
|
80
|
+
* @returns whether anything was logged
|
|
81
|
+
*/
|
|
82
|
+
export declare function logQuery(context: QueryLogContext, options?: QueryLogOptions): boolean;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query logging, following the Sequelize logger's shape.
|
|
4
|
+
*
|
|
5
|
+
* Sequelize's contract is small and widely known, so this matches it rather
|
|
6
|
+
* than inventing another:
|
|
7
|
+
*
|
|
8
|
+
* logging: false no output
|
|
9
|
+
* logging: true console.log
|
|
10
|
+
* logging: console.log any function, called as (sql, timing)
|
|
11
|
+
* benchmark: true append the elapsed time
|
|
12
|
+
* logQueryParameters: true append the bound values
|
|
13
|
+
*
|
|
14
|
+
* A per-query `logging` overrides the instance-level one, so a single noisy
|
|
15
|
+
* call can be traced without turning logging on globally - and, symmetrically,
|
|
16
|
+
* one call can be silenced with `logging: false`.
|
|
17
|
+
*
|
|
18
|
+
* This module exists because the resolution logic was previously inlined at
|
|
19
|
+
* four call sites and only some of them ran it: `count`, `bulkCreate`,
|
|
20
|
+
* `increment` and the aggregates emitted nothing at all, so turning logging on
|
|
21
|
+
* showed an incomplete picture of what the ORM was doing.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.defaultQueryLogger = void 0;
|
|
25
|
+
exports.resolveQueryLogger = resolveQueryLogger;
|
|
26
|
+
exports.formatQueryLog = formatQueryLog;
|
|
27
|
+
exports.logQuery = logQuery;
|
|
28
|
+
/**
|
|
29
|
+
* Resolve the effective logging function for one query.
|
|
30
|
+
*
|
|
31
|
+
* Returns null when logging is off. Precedence is query-level, then
|
|
32
|
+
* instance-level; `false` at either level wins over a function at the other,
|
|
33
|
+
* because silencing is the more specific intent.
|
|
34
|
+
*/
|
|
35
|
+
function resolveQueryLogger(options) {
|
|
36
|
+
const { queryLogging, instanceLogging } = options;
|
|
37
|
+
// An explicit per-query setting decides on its own.
|
|
38
|
+
if (queryLogging === false)
|
|
39
|
+
return null;
|
|
40
|
+
if (typeof queryLogging === 'function')
|
|
41
|
+
return queryLogging;
|
|
42
|
+
if (queryLogging === true)
|
|
43
|
+
return exports.defaultQueryLogger;
|
|
44
|
+
if (instanceLogging === false)
|
|
45
|
+
return null;
|
|
46
|
+
if (typeof instanceLogging === 'function')
|
|
47
|
+
return instanceLogging;
|
|
48
|
+
if (instanceLogging === true)
|
|
49
|
+
return exports.defaultQueryLogger;
|
|
50
|
+
// Unset at both levels: quiet, matching Sequelize's `logging: false` default
|
|
51
|
+
// in recent versions, unless benchmarking was explicitly asked for.
|
|
52
|
+
return options.benchmark ? exports.defaultQueryLogger : null;
|
|
53
|
+
}
|
|
54
|
+
/** The built-in logger used for `logging: true`. */
|
|
55
|
+
const defaultQueryLogger = (sql, timing) => {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.log(timing === undefined ? sql : `${sql} Elapsed time: ${timing}ms`);
|
|
58
|
+
};
|
|
59
|
+
exports.defaultQueryLogger = defaultQueryLogger;
|
|
60
|
+
/**
|
|
61
|
+
* Render one log line.
|
|
62
|
+
*
|
|
63
|
+
* Mirrors Sequelize's `Executed (default): <sql>` prefix so existing log
|
|
64
|
+
* parsers and eyeballs both keep working.
|
|
65
|
+
*/
|
|
66
|
+
function formatQueryLog(context, options = {}) {
|
|
67
|
+
const label = context.model ? `Executed (${context.model})` : 'Executed (default)';
|
|
68
|
+
let line = `${label}: ${context.sql}`;
|
|
69
|
+
if (options.logQueryParameters && context.parameters?.length) {
|
|
70
|
+
line += `; ${JSON.stringify(context.parameters)}`;
|
|
71
|
+
}
|
|
72
|
+
if (options.benchmark) {
|
|
73
|
+
line += ` Elapsed time: ${context.duration}ms`;
|
|
74
|
+
}
|
|
75
|
+
return line;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Log one query, if logging is enabled for it.
|
|
79
|
+
*
|
|
80
|
+
* A user-supplied function receives the raw SQL and the timing, exactly as
|
|
81
|
+
* Sequelize does, so callbacks written against that API work unchanged. The
|
|
82
|
+
* built-in logger gets the formatted line instead.
|
|
83
|
+
*
|
|
84
|
+
* @returns whether anything was logged
|
|
85
|
+
*/
|
|
86
|
+
function logQuery(context, options = {}) {
|
|
87
|
+
const logger = resolveQueryLogger(options);
|
|
88
|
+
if (!logger)
|
|
89
|
+
return false;
|
|
90
|
+
if (logger === exports.defaultQueryLogger) {
|
|
91
|
+
// eslint-disable-next-line no-console
|
|
92
|
+
console.log(formatQueryLog(context, options));
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Custom loggers get the SQL unadorned; decorating it would break anyone
|
|
96
|
+
// parsing it or forwarding it to a structured log.
|
|
97
|
+
logger(options.logQueryParameters && context.parameters?.length
|
|
98
|
+
? `${context.sql}; ${JSON.stringify(context.parameters)}`
|
|
99
|
+
: context.sql, context.duration);
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
@@ -18,6 +18,10 @@ declare abstract class BaseAssociation {
|
|
|
18
18
|
*/
|
|
19
19
|
getAssociationConfig(): AssociationConfig;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* The resolved shape of a declared association: the two models, the foreign
|
|
23
|
+
* key, the alias, and any join table.
|
|
24
|
+
*/
|
|
21
25
|
export interface AssociationConfig {
|
|
22
26
|
model: ModelStatic<any>;
|
|
23
27
|
as: string;
|
|
@@ -28,6 +32,9 @@ export interface AssociationConfig {
|
|
|
28
32
|
onDelete?: string;
|
|
29
33
|
onUpdate?: string;
|
|
30
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* An eager-load nested inside another, for traversing more than one hop.
|
|
37
|
+
*/
|
|
31
38
|
export interface NestedIncludeOptions extends IncludeOptions {
|
|
32
39
|
/**
|
|
33
40
|
* Nested includes - support for multi-level eager loading
|
|
@@ -59,6 +66,10 @@ export declare class HasOneAssociation extends BaseAssociation {
|
|
|
59
66
|
*/
|
|
60
67
|
getConstraintSql(tableName: string): string;
|
|
61
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* A one-to-many relationship. The foreign key lives on the **target**, so the
|
|
71
|
+
* child rows are what get written when the association changes.
|
|
72
|
+
*/
|
|
62
73
|
export declare class HasManyAssociation extends BaseAssociation {
|
|
63
74
|
constructor(source: ModelStatic<any>, target: ModelStatic<any>, options?: AssociationOptions);
|
|
64
75
|
inferForeignKey(): string;
|
|
@@ -68,6 +79,10 @@ export declare class HasManyAssociation extends BaseAssociation {
|
|
|
68
79
|
*/
|
|
69
80
|
getConstraintSql(tableName: string): string;
|
|
70
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* A many-to-one relationship. The foreign key lives on the **source**, so the
|
|
84
|
+
* row you called it on is what gets written.
|
|
85
|
+
*/
|
|
71
86
|
export declare class BelongsToAssociation extends BaseAssociation {
|
|
72
87
|
constructor(source: ModelStatic<any>, target: ModelStatic<any>, options?: AssociationOptions);
|
|
73
88
|
inferForeignKey(): string;
|
|
@@ -81,6 +96,10 @@ export declare class BelongsToAssociation extends BaseAssociation {
|
|
|
81
96
|
*/
|
|
82
97
|
getForeignKeyOptions(): AssociationForeignKeyOptions | undefined;
|
|
83
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* A many-to-many relationship through a join table. Neither side holds a
|
|
101
|
+
* foreign key; the join table holds both.
|
|
102
|
+
*/
|
|
84
103
|
export declare class BelongsToManyAssociation extends BaseAssociation {
|
|
85
104
|
private through;
|
|
86
105
|
private throughModel;
|
|
@@ -93,18 +112,37 @@ export declare class BelongsToManyAssociation extends BaseAssociation {
|
|
|
93
112
|
setThroughModel(model: ModelStatic<any>): void;
|
|
94
113
|
getThroughModel(): ModelStatic<any> | null;
|
|
95
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* The instance methods a `hasOne` adds — get, set and create the related row.
|
|
117
|
+
*/
|
|
96
118
|
export interface HasOneMixin {
|
|
97
119
|
(target: ModelStatic<any>, options?: AssociationOptions): HasOneAssociation;
|
|
98
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* The instance methods a `hasMany` adds — get, set, add, remove, count and
|
|
123
|
+
* create related rows.
|
|
124
|
+
*/
|
|
99
125
|
export interface HasManyMixin {
|
|
100
126
|
(target: ModelStatic<any>, options?: AssociationOptions): HasManyAssociation;
|
|
101
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* The instance methods a `belongsTo` adds — get, set, unset and create the
|
|
130
|
+
* parent row.
|
|
131
|
+
*/
|
|
102
132
|
export interface BelongsToMixin {
|
|
103
133
|
(target: ModelStatic<any>, options?: AssociationOptions): BelongsToAssociation;
|
|
104
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* The instance methods a `belongsToMany` adds, including the join-table
|
|
137
|
+
* operations for adding and removing links.
|
|
138
|
+
*/
|
|
105
139
|
export interface BelongsToManyMixin {
|
|
106
140
|
(target: ModelStatic<any>, options?: AssociationOptions): BelongsToManyAssociation;
|
|
107
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Attaches the association helper methods to a model, named after the alias
|
|
144
|
+
* so `User.hasMany(Post)` yields `getPosts`, `addPost` and the rest.
|
|
145
|
+
*/
|
|
108
146
|
export declare function createAssociationMixins(source: ModelStatic<any>, sourceModelName: string, instancePrototype?: any): {
|
|
109
147
|
hasOne: HasOneMixin;
|
|
110
148
|
hasMany: HasManyMixin;
|
|
@@ -130,6 +130,10 @@ class HasOneAssociation extends BaseAssociation {
|
|
|
130
130
|
}
|
|
131
131
|
exports.HasOneAssociation = HasOneAssociation;
|
|
132
132
|
// HasMany Association - one-to-many where source has many targets
|
|
133
|
+
/**
|
|
134
|
+
* A one-to-many relationship. The foreign key lives on the **target**, so the
|
|
135
|
+
* child rows are what get written when the association changes.
|
|
136
|
+
*/
|
|
133
137
|
class HasManyAssociation extends BaseAssociation {
|
|
134
138
|
constructor(source, target, options = {}) {
|
|
135
139
|
super(source, target, options);
|
|
@@ -163,6 +167,10 @@ class HasManyAssociation extends BaseAssociation {
|
|
|
163
167
|
}
|
|
164
168
|
exports.HasManyAssociation = HasManyAssociation;
|
|
165
169
|
// BelongsTo Association - one-to-one where source belongs to target
|
|
170
|
+
/**
|
|
171
|
+
* A many-to-one relationship. The foreign key lives on the **source**, so the
|
|
172
|
+
* row you called it on is what gets written.
|
|
173
|
+
*/
|
|
166
174
|
class BelongsToAssociation extends BaseAssociation {
|
|
167
175
|
constructor(source, target, options = {}) {
|
|
168
176
|
super(source, target, options);
|
|
@@ -203,6 +211,10 @@ class BelongsToAssociation extends BaseAssociation {
|
|
|
203
211
|
}
|
|
204
212
|
exports.BelongsToAssociation = BelongsToAssociation;
|
|
205
213
|
// BelongsToMany Association - many-to-many through a junction table
|
|
214
|
+
/**
|
|
215
|
+
* A many-to-many relationship through a join table. Neither side holds a
|
|
216
|
+
* foreign key; the join table holds both.
|
|
217
|
+
*/
|
|
206
218
|
class BelongsToManyAssociation extends BaseAssociation {
|
|
207
219
|
constructor(source, target, options = {}) {
|
|
208
220
|
super(source, target, options);
|
|
@@ -278,6 +290,10 @@ class BelongsToManyAssociation extends BaseAssociation {
|
|
|
278
290
|
}
|
|
279
291
|
exports.BelongsToManyAssociation = BelongsToManyAssociation;
|
|
280
292
|
// Factory function to create association mixin methods
|
|
293
|
+
/**
|
|
294
|
+
* Attaches the association helper methods to a model, named after the alias
|
|
295
|
+
* so `User.hasMany(Post)` yields `getPosts`, `addPost` and the rest.
|
|
296
|
+
*/
|
|
281
297
|
function createAssociationMixins(source, sourceModelName, instancePrototype) {
|
|
282
298
|
// Use provided instance prototype, or fall back to source.prototype, or source itself
|
|
283
299
|
const prototypeTarget = instancePrototype || source.prototype || source;
|