@dbsp/core 1.7.1 → 1.9.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/dist/index.d.ts +92 -4
- package/dist/index.js +67 -36
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -4074,8 +4074,14 @@ interface QueryBuilder<TResult = unknown> {
|
|
|
4074
4074
|
* Check whether any matching rows exist.
|
|
4075
4075
|
*
|
|
4076
4076
|
* Compiles to `SELECT EXISTS(SELECT 1 FROM ... WHERE ...)`.
|
|
4077
|
-
* Strips `orderBy
|
|
4078
|
-
*
|
|
4077
|
+
* Strips `orderBy`; every include is kept and compiled exactly as for the
|
|
4078
|
+
* full query — nothing is pruned. The `SELECT 1` wrap then discards the
|
|
4079
|
+
* target list, so target-list hydration (the default `json_agg`) vanishes
|
|
4080
|
+
* for free while FROM joins (`inner`/`left`/`lateral`/`cte`, incl. recursive)
|
|
4081
|
+
* ride along and filter/multiply the root rows just as they would in the full
|
|
4082
|
+
* query. `groupBy`, `having`, and `offset` are preserved (they affect the
|
|
4083
|
+
* result). A recursive include therefore builds its CTE here (and throws on a
|
|
4084
|
+
* dialect without `supportsRecursiveCTE`) rather than a cheaper shortcut.
|
|
4079
4085
|
*
|
|
4080
4086
|
* Requires `db` to be configured in createOrm() options.
|
|
4081
4087
|
*
|
|
@@ -4461,7 +4467,10 @@ declare class QueryBuilderImpl<TResult = unknown> implements QueryBuilder<TResul
|
|
|
4461
4467
|
private executeWithHooksInner;
|
|
4462
4468
|
/**
|
|
4463
4469
|
* Build an existence-check intent from current state.
|
|
4464
|
-
* Strips orderBy
|
|
4470
|
+
* Strips orderBy (irrelevant once wrapped in EXISTS), sets existsWrap and
|
|
4471
|
+
* limit: 1, and keeps every include unchanged; the compiler decides which
|
|
4472
|
+
* include contributions still need to be emitted (see exists-intent.ts
|
|
4473
|
+
* and shouldEmitInclude() in the pgsql compiler) (#230).
|
|
4465
4474
|
*/
|
|
4466
4475
|
private buildExistsIntent;
|
|
4467
4476
|
/**
|
|
@@ -7455,6 +7464,19 @@ declare function defineModel<DB = Record<string, unknown>>(options: DefineModelO
|
|
|
7455
7464
|
* - Custom logging frameworks (pino, winston, etc.)
|
|
7456
7465
|
* - Structured logging
|
|
7457
7466
|
*/
|
|
7467
|
+
/**
|
|
7468
|
+
* Category of a DX warning, used internally by {@link emitWarning} to decide
|
|
7469
|
+
* env/per-instance suppression (#159). The category is NEVER passed to the
|
|
7470
|
+
* logger sink (see {@link Logger.warn}) — it only drives the suppression
|
|
7471
|
+
* decision inside `emitWarning`.
|
|
7472
|
+
*
|
|
7473
|
+
* - `'dx'`: developer-experience warnings (e.g. reserved word column access).
|
|
7474
|
+
* Suppressible via `DBSP_SUPPRESS_DX_WARNINGS` and per-instance `suppressDxWarnings`.
|
|
7475
|
+
* - `'runtime'`: operational warnings (e.g. raw SQL usage). Suppressible via
|
|
7476
|
+
* its own gate (e.g. `NODE_ENV`) plus the global logger, but NOT via
|
|
7477
|
+
* `DBSP_SUPPRESS_DX_WARNINGS` or per-instance `suppressDxWarnings`.
|
|
7478
|
+
*/
|
|
7479
|
+
type WarningCategory = 'dx' | 'runtime';
|
|
7458
7480
|
/**
|
|
7459
7481
|
* Logger interface for dbsp library code.
|
|
7460
7482
|
*
|
|
@@ -7465,6 +7487,13 @@ interface Logger {
|
|
|
7465
7487
|
/**
|
|
7466
7488
|
* Log a warning message.
|
|
7467
7489
|
* Used for: reserved word usage, raw SQL warnings, deprecation notices.
|
|
7490
|
+
*
|
|
7491
|
+
* @param message - The warning message text (stable across versions —
|
|
7492
|
+
* downstream consumers may parse it). This is the ONLY argument the
|
|
7493
|
+
* sink ever receives — {@link WarningCategory} is internal to
|
|
7494
|
+
* {@link emitWarning}'s suppression decision and is never forwarded
|
|
7495
|
+
* here, so a `{ warn: console.warn }` or rest-arg/pino-style wrapper
|
|
7496
|
+
* never sees an unexpected extra token.
|
|
7468
7497
|
*/
|
|
7469
7498
|
warn(message: string): void;
|
|
7470
7499
|
}
|
|
@@ -7504,8 +7533,49 @@ declare function setLogger(logger: Logger): void;
|
|
|
7504
7533
|
declare function getLogger(): Logger;
|
|
7505
7534
|
/**
|
|
7506
7535
|
* Reset logger to default (for testing).
|
|
7536
|
+
*
|
|
7537
|
+
* Also clears the module-level reserved-word warning dedup (#159) so tests
|
|
7538
|
+
* that install a spy logger and assert on warn call counts stay isolated
|
|
7539
|
+
* from each other.
|
|
7507
7540
|
*/
|
|
7508
7541
|
declare function resetLogger(): void;
|
|
7542
|
+
/**
|
|
7543
|
+
* Options for {@link emitWarning}.
|
|
7544
|
+
*/
|
|
7545
|
+
interface EmitWarningOptions {
|
|
7546
|
+
/**
|
|
7547
|
+
* Categories to suppress for this call site — e.g. an ORM instance's
|
|
7548
|
+
* `suppressDxWarnings` option (passing `['dx']`). Union'd with the env gate: a warning is
|
|
7549
|
+
* suppressed if EITHER applies.
|
|
7550
|
+
*/
|
|
7551
|
+
readonly suppress?: readonly WarningCategory[];
|
|
7552
|
+
}
|
|
7553
|
+
/**
|
|
7554
|
+
* Central warning emission helper (#159).
|
|
7555
|
+
*
|
|
7556
|
+
* Suppression precedence (a warning is suppressed if ANY of the following hold):
|
|
7557
|
+
* 1. `category === 'dx'` AND `DBSP_SUPPRESS_DX_WARNINGS` is enabled per
|
|
7558
|
+
* {@link isEnvFlagEnabled} (read per-call, matching this repo's `NODE_ENV`
|
|
7559
|
+
* gate convention; `'0'`/`'false'` do NOT enable it).
|
|
7560
|
+
* 2. `options.suppress` includes `category`.
|
|
7561
|
+
* 3. The global logger is the exported `silentLogger` singleton (an explicit
|
|
7562
|
+
* global silence — checked by reference, not behavior, so a custom no-op
|
|
7563
|
+
* logger does NOT trigger this branch).
|
|
7564
|
+
*
|
|
7565
|
+
* Default (no env var, no `suppress` option, non-silent logger) → nothing is
|
|
7566
|
+
* suppressed; the message reaches `getLogger().warn(...)`.
|
|
7567
|
+
*
|
|
7568
|
+
* The category is used ONLY for this suppression decision — it is NEVER
|
|
7569
|
+
* passed to `getLogger().warn(...)`, which receives just the message (see
|
|
7570
|
+
* {@link Logger.warn}).
|
|
7571
|
+
*
|
|
7572
|
+
* @returns `true` when the warning was actually emitted, `false` when
|
|
7573
|
+
* suppressed. Callers that dedup (e.g. the reserved-word warning) MUST
|
|
7574
|
+
* only record the dedup key when this returns `true` — recording it
|
|
7575
|
+
* unconditionally would let a suppressed call permanently "poison" the
|
|
7576
|
+
* dedup slot for every later, non-suppressed caller in the same process.
|
|
7577
|
+
*/
|
|
7578
|
+
declare function emitWarning(message: string, category: WarningCategory, options?: EmitWarningOptions): boolean;
|
|
7509
7579
|
|
|
7510
7580
|
/** Error thrown when behavior = 'error' and unsupported feature detected */
|
|
7511
7581
|
declare class UnsupportedFeatureError extends Error {
|
|
@@ -7628,6 +7698,24 @@ interface SimplifiedOrmOptions<T extends SchemaDefinition = SchemaDefinition> {
|
|
|
7628
7698
|
* Pass FeatureBehaviorConfig for per-feature overrides.
|
|
7629
7699
|
*/
|
|
7630
7700
|
readonly unsupportedFeatures?: UnsupportedFeatureBehavior | FeatureBehaviorConfig;
|
|
7701
|
+
/**
|
|
7702
|
+
* Suppress `'dx'` warnings (e.g. reserved-word column access) for this
|
|
7703
|
+
* ORM instance (#159). Union'd with the `DBSP_SUPPRESS_DX_WARNINGS` env
|
|
7704
|
+
* gate — a warning is suppressed if EITHER applies.
|
|
7705
|
+
*
|
|
7706
|
+
* Deliberately DX-only (not `WarningCategory[]`): `'runtime'` warnings
|
|
7707
|
+
* (raw-SQL usage) are emitted by the adapter's compiler, which has no
|
|
7708
|
+
* per-ORM-instance context, so a `'runtime'` entry here would silently
|
|
7709
|
+
* do nothing. `'runtime'` warnings are controlled only by the adapter's
|
|
7710
|
+
* `NODE_ENV` gate and the global logger (e.g. `silentLogger`) — not by
|
|
7711
|
+
* `DBSP_SUPPRESS_DX_WARNINGS` or this option.
|
|
7712
|
+
*
|
|
7713
|
+
* @example
|
|
7714
|
+
* ```typescript
|
|
7715
|
+
* const orm = createOrm({ schema, adapter, suppressDxWarnings: true });
|
|
7716
|
+
* ```
|
|
7717
|
+
*/
|
|
7718
|
+
readonly suppressDxWarnings?: boolean;
|
|
7631
7719
|
}
|
|
7632
7720
|
/**
|
|
7633
7721
|
* Create an ORM instance with the specified configuration.
|
|
@@ -8255,4 +8343,4 @@ declare const assertIntentHasOrderBy: (result: AssertionQueryResult, expected: b
|
|
|
8255
8343
|
*/
|
|
8256
8344
|
declare function runAssertions(blocks: AssertionBlock[], results: AssertionQueryResult[], queries: string[], hasDb?: boolean): AssertionSummary;
|
|
8257
8345
|
|
|
8258
|
-
export { ASSERTION_TYPES, AdapterRequiredError, type AdjacencyOptions, type AfterMutationHook, type AfterQueryHook, type AggregateOptions, type AliasedColumn, type AliasedExprColumn, type AllColumns, AmbiguousPlanError, AmbiguousRelationError, type Assertion, type AssertionBlock, type AssertionOutcome, type AssertionQueryResult, type AssertionSummary, type AssertionType, BRAND, type BatchValuesOptions, type BatchValuesRef, type BeforeMutationHook, type BeforeQueryHook, type BrandKey, COLUMN_META, type CardinalityShorthand, CaseBuilder, type CaseValue, type ColumnDef, type ColumnMetaKey, ColumnNotFoundError, type ColumnRef, type ColumnSpec, type ColumnTypeToTS, CteBuilder, type CteDump, CteQueryBuilder, type CursorPaginateOptions, type CursorPaginatedResult, DEFAULT_CONVENTIONS, DEFAULT_FEATURE_CHECKERS, DUCKDB_CAPABILITIES, type DefaultFilters, type DefineModelOptions, DeleteBuilder, type DistinctField, type DumpMetaInput, type EdgeTableOptions, ErrorCode, type ErrorHookContext, Errors, ExecutionError, type ExprInput, ExpressionRef, type ExpressionSpec, type FeatureChecker, type FeatureUsage, type FilterOperators, type FilterValue, type FullTextSearchField, type FullTextSearchOptions, type GeneratedBelongsTo, type GeneratedColumn, type GeneratedColumnType, type GeneratedConventions, type GeneratedHasMany, type GeneratedHint, type GeneratedManyToMany, type GeneratedRelation, type GeneratedRelationKind, type GeneratedSchema, type GeneratedTable, type GetSchemaFromDbOptions, type HierarchyOptions, type HookErrorHandler, type HookManager, type HookPriority, type HydrateOptions, IRREGULAR_PLURALS, type IncludeOptions, type IncludeOptionsWithRecursive, type InferColumn, type InferColumnType, type InferColumnTypes, type InferDB, type InferDBFromSchema, type InferRefColumn, type InferRow, type InferRowType, type InferSchemaDB, type InferTableRow, type InferTables, type InferredRangeValue, InsertBuilder, IntentBuilder, type IntentBuilderState, type IntentSummary, InvalidOperationError, InvalidRelationDefinitionError, type JoinOptions, type JsonValue, type LightweightRelationsDef, type ListHierarchyOptions, type ListIndexOptions, type Logger, MSSQL_CAPABILITIES, MYSQL_CAPABILITIES, ModelIRImpl, type MutationDump, type MutationHookContext, type MutationOperation, NamingConventionMismatchError, type NegotiationResult, type NestedInclude, type SchemaColumnType$1 as NewSchemaColumnType, NotFoundError, type NqlBuilder, type NqlRawFragment, type NqlTag, type OnErrorHook, type OrderByInput, type OrderByRecord, type OrderBySpec, type OrmInstance, type OrmOf, type OrmOptions, type OrmOptionsWithAdapter, type OrmOptionsWithModel, type OrmOptionsWithSchema, POSTGRESQL_CAPABILITIES, type PaginateOptions, type PaginatedResult, type ParseError, type ParseResult, type ParsedRelationDef, type ParsedRelationKey, type PathOptions, type PrioritizedHook, type QueryAssertionResult, type QueryBuilder, type QueryHookContext, type QueryResultType, RELATION_META, type RangeType, RawCteQueryBuilder, type RecursiveDump, type RecursiveIncludeConfig, type RecursiveOptions, RecursiveShapeMismatchError, type RefDefinition, type RefOptions, type RelationHints, type RelationKey, type RelationMetaKey, RelationNotFoundError, type RelationObjectDef, type RelationPathIncludeNode, type RelationPathUsage, type RelationRef, type RelationShorthand, type RelationTupleDef, type ResolvedSchema, ResolvedSchemaValidation, ResultHydrator, SQLITE_CAPABILITIES, SQL_RAW_MARKER, type Schema, type SchemaBelongsToRelation, type SchemaCardinality, type SchemaColumnDefinition, type SchemaColumnType, type SchemaConfigInput, type SchemaConstraints, type SchemaConventionsDefinition, type SchemaConversionResult, type SchemaDefinition, type SchemaDefinitionInput, SchemaValidationError$1 as SchemaError, type SchemaExtras, type SchemaFilterStrategy, type SchemaForeignKeyReference, type SchemaHasManyRelation, type SchemaHintDefinition, type SchemaHintsDefinition, type SchemaIndexDefinition, type SchemaIndexOptions, type SchemaIndexesDefinition, type SchemaManyToManyRelation, type SchemaOnDeleteAction, type SchemaOptions, type SchemaRelationDefinition, type SchemaRelationKind, type SchemaRelationsDefinition, type SchemaTableDefinition, type SchemaTableOptions, type SchemaTablesDefinition, SchemaValidationError, type SelectField, type SelfRefRoles, type SetOperationBuilder, type SimplifiedOrmOptions, type SqlRawExpression, type StreamOptions, SubqueryBuilder, SubqueryExpression, TABLE_META, type TableAssertionData, type TableDDL, type TableDef, type TableIndexes, type TableMetaKey, TableNotFoundError, type TableRef, type TraversalDirection, UnhandledTypeInDialect, UnknownDialectError, UnsafeOperationError, UnsupportedCapabilityError, UnsupportedFeatureError, UnsupportedStrategyError, UpdateBuilder, UpsertBuilder, type ValidatedResolvedSchema, type WhereFilter, WindowBuilder, aggOrderBy, and, any, array, arrayAgg, assertCapability, assertContains, assertDbColumnExists, assertDbOutput, assertDbRowsEquals, assertDbRowsMax, assertDbRowsMin, assertDbValueEquals, assertEquals, assertIntentHasGroupBy, assertIntentHasOrderBy, assertIntentHasWhere, assertIntentTable, assertIntentType, assertIntentWith, assertMatches, assertParamsEquals, assertParamsLength, assertParamsType, assertParamsValue, assertResolvedSchemaToGeneratedSchema, assertSQLColumn, assertSQLEquals, assertSQLJoin, assertSQLTable, assertSuccess, assertTypeSupported, batchValues, buildModelFromResolvedSchema, buildModelFromSchema, capitalize, caseWhen, cast, coalesce, col, composeAfterMutationHooks, composeAfterQueryHooks, composeBeforeMutationHooks, composeBeforeQueryHooks, composeOnErrorHooks, countDistinctRelationPathsByName, createDialectCapabilities, createHookManager, createNqlTag, createOrm, createPseudoColumnMetadata, createRawCteBuilder, createRecursiveMetadata, decapitalize, defaultLogger, defineModel, defineSchema, denseRank, deriveRelationPathFromIntentPath, detectForeignKeys, detectManyToMany, distinct, eq, every, exists, ref as exprRef, extendDialect, extractPseudoColumnKeywords, findClosestMatch, fn, fullTextSearch, getAvailableDialects, getDialectCapabilities, getLogger, getRelationKind, getSchemaFromDb, gt, gte, inArray, inSubquery, inferForeignKey, inferRelationsFromSchema, isAliasedColumn, isAllColumns, isBatchValuesRef, isBelongsTo, isCardinalityShorthand, isColumnRef, isDistinctField, isDistinctFrom, isExpressionSpec, isGeneratedSchema, isHasMany, isKnownDialect, isManyToMany, isNotNull, isNull, isOverallSuccess, isRecursiveIncludeOptions, isRecursiveRelation, isRef, isRelationObjectDef, isRelationRef, isRelationTupleDef, isResolvedSchema, isSelfReferential, isSqlRaw, isSubqueryExpression, isTableRef, isWhereIntent, lag, lead, like, literal, lt, lte, namedArg, negotiateFeatures, neq, none, normalizeSQL, normalizeSchema, not, notExists, nqlRaw, objectToWhereIntent, op, or, outerRef, param, parseAssertionFile, parseRelationDef, parseRelationKey, pipeAfterMutationHooks, pipeAfterQueryHooks, pipeBeforeMutationHooks, pipeBeforeQueryHooks, pipeOnErrorHooks, plan, planRecursive, pluralize, rangeContainedBy, rangeContains, rangeOverlaps, rank, raw, rawExists, rawNotExists, ref$1 as ref, registerDialect, relationColumn, requiresDatabase, resetLogger, resolveQueryIndex, resolvedSchemaToGeneratedSchema, rowNumber, runAssertions, schema, schemaToModelIR, setLogger, silentLogger, singularize, some, sortByPriority, sql, star, stringAgg, subquery, supportsDDLGeneration, supportsExecution, supportsIntrospection, supportsRawSql, supportsStreaming, supportsTransactions, textScore, unary, validateAssertionBlocks, validateRecursiveInclude, validateRecursiveShape, validateTypeName, wAvg, wCount, wMax, wMin, wSum, withPriority };
|
|
8346
|
+
export { ASSERTION_TYPES, AdapterRequiredError, type AdjacencyOptions, type AfterMutationHook, type AfterQueryHook, type AggregateOptions, type AliasedColumn, type AliasedExprColumn, type AllColumns, AmbiguousPlanError, AmbiguousRelationError, type Assertion, type AssertionBlock, type AssertionOutcome, type AssertionQueryResult, type AssertionSummary, type AssertionType, BRAND, type BatchValuesOptions, type BatchValuesRef, type BeforeMutationHook, type BeforeQueryHook, type BrandKey, COLUMN_META, type CardinalityShorthand, CaseBuilder, type CaseValue, type ColumnDef, type ColumnMetaKey, ColumnNotFoundError, type ColumnRef, type ColumnSpec, type ColumnTypeToTS, CteBuilder, type CteDump, CteQueryBuilder, type CursorPaginateOptions, type CursorPaginatedResult, DEFAULT_CONVENTIONS, DEFAULT_FEATURE_CHECKERS, DUCKDB_CAPABILITIES, type DefaultFilters, type DefineModelOptions, DeleteBuilder, type DistinctField, type DumpMetaInput, type EdgeTableOptions, type EmitWarningOptions, ErrorCode, type ErrorHookContext, Errors, ExecutionError, type ExprInput, ExpressionRef, type ExpressionSpec, type FeatureChecker, type FeatureUsage, type FilterOperators, type FilterValue, type FullTextSearchField, type FullTextSearchOptions, type GeneratedBelongsTo, type GeneratedColumn, type GeneratedColumnType, type GeneratedConventions, type GeneratedHasMany, type GeneratedHint, type GeneratedManyToMany, type GeneratedRelation, type GeneratedRelationKind, type GeneratedSchema, type GeneratedTable, type GetSchemaFromDbOptions, type HierarchyOptions, type HookErrorHandler, type HookManager, type HookPriority, type HydrateOptions, IRREGULAR_PLURALS, type IncludeOptions, type IncludeOptionsWithRecursive, type InferColumn, type InferColumnType, type InferColumnTypes, type InferDB, type InferDBFromSchema, type InferRefColumn, type InferRow, type InferRowType, type InferSchemaDB, type InferTableRow, type InferTables, type InferredRangeValue, InsertBuilder, IntentBuilder, type IntentBuilderState, type IntentSummary, InvalidOperationError, InvalidRelationDefinitionError, type JoinOptions, type JsonValue, type LightweightRelationsDef, type ListHierarchyOptions, type ListIndexOptions, type Logger, MSSQL_CAPABILITIES, MYSQL_CAPABILITIES, ModelIRImpl, type MutationDump, type MutationHookContext, type MutationOperation, NamingConventionMismatchError, type NegotiationResult, type NestedInclude, type SchemaColumnType$1 as NewSchemaColumnType, NotFoundError, type NqlBuilder, type NqlRawFragment, type NqlTag, type OnErrorHook, type OrderByInput, type OrderByRecord, type OrderBySpec, type OrmInstance, type OrmOf, type OrmOptions, type OrmOptionsWithAdapter, type OrmOptionsWithModel, type OrmOptionsWithSchema, POSTGRESQL_CAPABILITIES, type PaginateOptions, type PaginatedResult, type ParseError, type ParseResult, type ParsedRelationDef, type ParsedRelationKey, type PathOptions, type PrioritizedHook, type QueryAssertionResult, type QueryBuilder, type QueryHookContext, type QueryResultType, RELATION_META, type RangeType, RawCteQueryBuilder, type RecursiveDump, type RecursiveIncludeConfig, type RecursiveOptions, RecursiveShapeMismatchError, type RefDefinition, type RefOptions, type RelationHints, type RelationKey, type RelationMetaKey, RelationNotFoundError, type RelationObjectDef, type RelationPathIncludeNode, type RelationPathUsage, type RelationRef, type RelationShorthand, type RelationTupleDef, type ResolvedSchema, ResolvedSchemaValidation, ResultHydrator, SQLITE_CAPABILITIES, SQL_RAW_MARKER, type Schema, type SchemaBelongsToRelation, type SchemaCardinality, type SchemaColumnDefinition, type SchemaColumnType, type SchemaConfigInput, type SchemaConstraints, type SchemaConventionsDefinition, type SchemaConversionResult, type SchemaDefinition, type SchemaDefinitionInput, SchemaValidationError$1 as SchemaError, type SchemaExtras, type SchemaFilterStrategy, type SchemaForeignKeyReference, type SchemaHasManyRelation, type SchemaHintDefinition, type SchemaHintsDefinition, type SchemaIndexDefinition, type SchemaIndexOptions, type SchemaIndexesDefinition, type SchemaManyToManyRelation, type SchemaOnDeleteAction, type SchemaOptions, type SchemaRelationDefinition, type SchemaRelationKind, type SchemaRelationsDefinition, type SchemaTableDefinition, type SchemaTableOptions, type SchemaTablesDefinition, SchemaValidationError, type SelectField, type SelfRefRoles, type SetOperationBuilder, type SimplifiedOrmOptions, type SqlRawExpression, type StreamOptions, SubqueryBuilder, SubqueryExpression, TABLE_META, type TableAssertionData, type TableDDL, type TableDef, type TableIndexes, type TableMetaKey, TableNotFoundError, type TableRef, type TraversalDirection, UnhandledTypeInDialect, UnknownDialectError, UnsafeOperationError, UnsupportedCapabilityError, UnsupportedFeatureError, UnsupportedStrategyError, UpdateBuilder, UpsertBuilder, type ValidatedResolvedSchema, type WarningCategory, type WhereFilter, WindowBuilder, aggOrderBy, and, any, array, arrayAgg, assertCapability, assertContains, assertDbColumnExists, assertDbOutput, assertDbRowsEquals, assertDbRowsMax, assertDbRowsMin, assertDbValueEquals, assertEquals, assertIntentHasGroupBy, assertIntentHasOrderBy, assertIntentHasWhere, assertIntentTable, assertIntentType, assertIntentWith, assertMatches, assertParamsEquals, assertParamsLength, assertParamsType, assertParamsValue, assertResolvedSchemaToGeneratedSchema, assertSQLColumn, assertSQLEquals, assertSQLJoin, assertSQLTable, assertSuccess, assertTypeSupported, batchValues, buildModelFromResolvedSchema, buildModelFromSchema, capitalize, caseWhen, cast, coalesce, col, composeAfterMutationHooks, composeAfterQueryHooks, composeBeforeMutationHooks, composeBeforeQueryHooks, composeOnErrorHooks, countDistinctRelationPathsByName, createDialectCapabilities, createHookManager, createNqlTag, createOrm, createPseudoColumnMetadata, createRawCteBuilder, createRecursiveMetadata, decapitalize, defaultLogger, defineModel, defineSchema, denseRank, deriveRelationPathFromIntentPath, detectForeignKeys, detectManyToMany, distinct, emitWarning, eq, every, exists, ref as exprRef, extendDialect, extractPseudoColumnKeywords, findClosestMatch, fn, fullTextSearch, getAvailableDialects, getDialectCapabilities, getLogger, getRelationKind, getSchemaFromDb, gt, gte, inArray, inSubquery, inferForeignKey, inferRelationsFromSchema, isAliasedColumn, isAllColumns, isBatchValuesRef, isBelongsTo, isCardinalityShorthand, isColumnRef, isDistinctField, isDistinctFrom, isExpressionSpec, isGeneratedSchema, isHasMany, isKnownDialect, isManyToMany, isNotNull, isNull, isOverallSuccess, isRecursiveIncludeOptions, isRecursiveRelation, isRef, isRelationObjectDef, isRelationRef, isRelationTupleDef, isResolvedSchema, isSelfReferential, isSqlRaw, isSubqueryExpression, isTableRef, isWhereIntent, lag, lead, like, literal, lt, lte, namedArg, negotiateFeatures, neq, none, normalizeSQL, normalizeSchema, not, notExists, nqlRaw, objectToWhereIntent, op, or, outerRef, param, parseAssertionFile, parseRelationDef, parseRelationKey, pipeAfterMutationHooks, pipeAfterQueryHooks, pipeBeforeMutationHooks, pipeBeforeQueryHooks, pipeOnErrorHooks, plan, planRecursive, pluralize, rangeContainedBy, rangeContains, rangeOverlaps, rank, raw, rawExists, rawNotExists, ref$1 as ref, registerDialect, relationColumn, requiresDatabase, resetLogger, resolveQueryIndex, resolvedSchemaToGeneratedSchema, rowNumber, runAssertions, schema, schemaToModelIR, setLogger, silentLogger, singularize, some, sortByPriority, sql, star, stringAgg, subquery, supportsDDLGeneration, supportsExecution, supportsIntrospection, supportsRawSql, supportsStreaming, supportsTransactions, textScore, unary, validateAssertionBlocks, validateRecursiveInclude, validateRecursiveShape, validateTypeName, wAvg, wCount, wMax, wMin, wSum, withPriority };
|
package/dist/index.js
CHANGED
|
@@ -247,6 +247,28 @@ function getLogger() {
|
|
|
247
247
|
}
|
|
248
248
|
function resetLogger() {
|
|
249
249
|
globalLogger = defaultLogger;
|
|
250
|
+
resetWarnedReservedWords();
|
|
251
|
+
}
|
|
252
|
+
function isEnvFlagEnabled(value) {
|
|
253
|
+
if (value === void 0) {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
const normalized = value.trim().toLowerCase();
|
|
257
|
+
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
258
|
+
}
|
|
259
|
+
function emitWarning(message, category, options) {
|
|
260
|
+
if (category === "dx" && isEnvFlagEnabled(process.env.DBSP_SUPPRESS_DX_WARNINGS)) {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
if (options?.suppress?.includes(category)) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
const logger = getLogger();
|
|
267
|
+
if (logger === silentLogger) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
logger.warn(message);
|
|
271
|
+
return true;
|
|
250
272
|
}
|
|
251
273
|
|
|
252
274
|
// src/dx/symbols.ts
|
|
@@ -306,10 +328,23 @@ var JS_RESERVED_WORDS = /* @__PURE__ */ new Set([
|
|
|
306
328
|
"throw",
|
|
307
329
|
"typeof"
|
|
308
330
|
]);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
331
|
+
var warnedReservedWords = /* @__PURE__ */ new Set();
|
|
332
|
+
function resetWarnedReservedWords() {
|
|
333
|
+
warnedReservedWords.clear();
|
|
334
|
+
}
|
|
335
|
+
function warnReservedWord(tableName, columnName, suppress) {
|
|
336
|
+
const dedupKey = `${tableName}.${columnName}`;
|
|
337
|
+
if (warnedReservedWords.has(dedupKey)) {
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
const emitted = emitWarning(
|
|
341
|
+
`[dbsp] Warning: Column "${columnName}" in table "${tableName}" is a JavaScript reserved word. Access it via bracket notation: table['${columnName}']`,
|
|
342
|
+
"dx",
|
|
343
|
+
suppress ? { suppress } : void 0
|
|
312
344
|
);
|
|
345
|
+
if (emitted) {
|
|
346
|
+
warnedReservedWords.add(dedupKey);
|
|
347
|
+
}
|
|
313
348
|
}
|
|
314
349
|
function createColumnRef(tableName, columnName, relationPath) {
|
|
315
350
|
const columnRef = {
|
|
@@ -439,7 +474,7 @@ function createRelationRef(targetTable, relationType, model, relationName, paren
|
|
|
439
474
|
}
|
|
440
475
|
});
|
|
441
476
|
}
|
|
442
|
-
function createTableRef(tableName, model) {
|
|
477
|
+
function createTableRef(tableName, model, suppress) {
|
|
443
478
|
const tableIR = model.getTable(tableName);
|
|
444
479
|
if (!tableIR) {
|
|
445
480
|
throw new Error(`Table "${tableName}" not found in model`);
|
|
@@ -463,7 +498,6 @@ function createTableRef(tableName, model) {
|
|
|
463
498
|
relations.set(inverseName, { target: relation.source, type: "hasMany" });
|
|
464
499
|
}
|
|
465
500
|
}
|
|
466
|
-
const warnedReservedWords = /* @__PURE__ */ new Set();
|
|
467
501
|
return new Proxy(base, {
|
|
468
502
|
get(target, prop, receiver) {
|
|
469
503
|
if (typeof prop === "symbol") {
|
|
@@ -478,10 +512,7 @@ function createTableRef(tableName, model) {
|
|
|
478
512
|
const propStr = prop;
|
|
479
513
|
if (JS_RESERVED_WORDS.has(propStr)) {
|
|
480
514
|
if (hasColumn(tableIR.columns, propStr)) {
|
|
481
|
-
|
|
482
|
-
warnReservedWord(tableName, propStr);
|
|
483
|
-
warnedReservedWords.add(propStr);
|
|
484
|
-
}
|
|
515
|
+
warnReservedWord(tableName, propStr, suppress);
|
|
485
516
|
return createColumnRef(tableName, propStr);
|
|
486
517
|
}
|
|
487
518
|
}
|
|
@@ -532,9 +563,10 @@ function createTableRef(tableName, model) {
|
|
|
532
563
|
}
|
|
533
564
|
});
|
|
534
565
|
}
|
|
535
|
-
function createTablesProxy(model, tableNames) {
|
|
566
|
+
function createTablesProxy(model, tableNames, options) {
|
|
536
567
|
const tableSet = new Set(tableNames);
|
|
537
568
|
const cache = /* @__PURE__ */ new Map();
|
|
569
|
+
const suppress = options?.suppressWarnings;
|
|
538
570
|
return new Proxy(
|
|
539
571
|
{},
|
|
540
572
|
{
|
|
@@ -547,7 +579,7 @@ function createTablesProxy(model, tableNames) {
|
|
|
547
579
|
return cache.get(propStr);
|
|
548
580
|
}
|
|
549
581
|
if (tableSet.has(propStr)) {
|
|
550
|
-
const tableRef = createTableRef(propStr, model);
|
|
582
|
+
const tableRef = createTableRef(propStr, model, suppress);
|
|
551
583
|
cache.set(propStr, tableRef);
|
|
552
584
|
return tableRef;
|
|
553
585
|
}
|
|
@@ -566,7 +598,7 @@ function createTablesProxy(model, tableNames) {
|
|
|
566
598
|
if (typeof prop === "string" && tableSet.has(prop)) {
|
|
567
599
|
let tableRef = cache.get(prop);
|
|
568
600
|
if (!tableRef) {
|
|
569
|
-
tableRef = createTableRef(prop, model);
|
|
601
|
+
tableRef = createTableRef(prop, model, suppress);
|
|
570
602
|
cache.set(prop, tableRef);
|
|
571
603
|
}
|
|
572
604
|
return {
|
|
@@ -1234,6 +1266,7 @@ function addCompositeConstraintRelations(relations, tableNames, constraints) {
|
|
|
1234
1266
|
const foreignKey = [...columns];
|
|
1235
1267
|
const referencedKey = [...references];
|
|
1236
1268
|
const belongsToName = deriveCompositeConstraintRelationName(
|
|
1269
|
+
// biome-ignore lint/style/noNonNullAssertion: foreignKey copies columns whose length is guaranteed >= 1 by the "if (!columns?.length) continue;" guard above
|
|
1237
1270
|
foreignKey[0],
|
|
1238
1271
|
fkRef.options
|
|
1239
1272
|
);
|
|
@@ -7735,6 +7768,13 @@ function findSelfRefRelation(model, table, direction) {
|
|
|
7735
7768
|
return null;
|
|
7736
7769
|
}
|
|
7737
7770
|
|
|
7771
|
+
// src/dx/exists-intent.ts
|
|
7772
|
+
function buildExistsIntent(baseIntent) {
|
|
7773
|
+
const { orderBy: _orderBy, ...rest } = baseIntent;
|
|
7774
|
+
const existsLimit = baseIntent.limit === 0 ? 0 : 1;
|
|
7775
|
+
return { ...rest, existsWrap: true, limit: existsLimit };
|
|
7776
|
+
}
|
|
7777
|
+
|
|
7738
7778
|
// src/dx/pagination-impl.ts
|
|
7739
7779
|
function resolveCursorKey(orderBy) {
|
|
7740
7780
|
if (typeof orderBy === "string") return orderBy;
|
|
@@ -9765,36 +9805,20 @@ var QueryBuilderImpl = class _QueryBuilderImpl {
|
|
|
9765
9805
|
}
|
|
9766
9806
|
/**
|
|
9767
9807
|
* Build an existence-check intent from current state.
|
|
9768
|
-
* Strips orderBy
|
|
9808
|
+
* Strips orderBy (irrelevant once wrapped in EXISTS), sets existsWrap and
|
|
9809
|
+
* limit: 1, and keeps every include unchanged; the compiler decides which
|
|
9810
|
+
* include contributions still need to be emitted (see exists-intent.ts
|
|
9811
|
+
* and shouldEmitInclude() in the pgsql compiler) (#230).
|
|
9769
9812
|
*/
|
|
9770
9813
|
buildExistsIntent() {
|
|
9771
|
-
|
|
9772
|
-
const {
|
|
9773
|
-
orderBy: _orderBy,
|
|
9774
|
-
include: _include,
|
|
9775
|
-
...rest
|
|
9776
|
-
} = baseIntent;
|
|
9777
|
-
return {
|
|
9778
|
-
...rest,
|
|
9779
|
-
existsWrap: true,
|
|
9780
|
-
limit: 1
|
|
9781
|
-
};
|
|
9814
|
+
return buildExistsIntent(this.buildIntent());
|
|
9782
9815
|
}
|
|
9783
9816
|
/**
|
|
9784
9817
|
* Build exists-wrapped intent from a pre-built intent (E17b: for hook-aware path).
|
|
9785
9818
|
* @internal
|
|
9786
9819
|
*/
|
|
9787
9820
|
buildExistsIntentFromIntent(baseIntent) {
|
|
9788
|
-
|
|
9789
|
-
orderBy: _orderBy,
|
|
9790
|
-
include: _include,
|
|
9791
|
-
...rest
|
|
9792
|
-
} = baseIntent;
|
|
9793
|
-
return {
|
|
9794
|
-
...rest,
|
|
9795
|
-
existsWrap: true,
|
|
9796
|
-
limit: 1
|
|
9797
|
-
};
|
|
9821
|
+
return buildExistsIntent(baseIntent);
|
|
9798
9822
|
}
|
|
9799
9823
|
/**
|
|
9800
9824
|
* Handle ambiguity based on strict mode setting.
|
|
@@ -10780,8 +10804,10 @@ function createOrm(options) {
|
|
|
10780
10804
|
planOptions: globalPlanOptions,
|
|
10781
10805
|
hooks: hookManager,
|
|
10782
10806
|
onHookError,
|
|
10783
|
-
unsupportedFeatures
|
|
10807
|
+
unsupportedFeatures,
|
|
10808
|
+
suppressDxWarnings
|
|
10784
10809
|
} = options;
|
|
10810
|
+
const suppressWarnings = suppressDxWarnings ? ["dx"] : void 0;
|
|
10785
10811
|
let model;
|
|
10786
10812
|
let schemaDefinition;
|
|
10787
10813
|
let defaultFilters;
|
|
@@ -10815,7 +10841,11 @@ function createOrm(options) {
|
|
|
10815
10841
|
}
|
|
10816
10842
|
}
|
|
10817
10843
|
const frozenHookStore = hookManager ? getHookStore(hookManager.freeze()) : void 0;
|
|
10818
|
-
const tablesProxy = schemaObj && "tables" in schemaObj ? schemaObj.tables : createTablesProxy(
|
|
10844
|
+
const tablesProxy = schemaObj && "tables" in schemaObj && !suppressWarnings ? schemaObj.tables : createTablesProxy(
|
|
10845
|
+
model,
|
|
10846
|
+
model.tables ? [...model.tables.keys()] : [],
|
|
10847
|
+
suppressWarnings ? { suppressWarnings } : void 0
|
|
10848
|
+
);
|
|
10819
10849
|
return createOrmInstance(
|
|
10820
10850
|
model,
|
|
10821
10851
|
strictMode,
|
|
@@ -13071,6 +13101,7 @@ export {
|
|
|
13071
13101
|
detectForeignKeys,
|
|
13072
13102
|
detectManyToMany,
|
|
13073
13103
|
distinct,
|
|
13104
|
+
emitWarning,
|
|
13074
13105
|
eq,
|
|
13075
13106
|
every,
|
|
13076
13107
|
exists,
|