@zenstackhq/orm 3.4.4 → 3.4.6
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.cjs +65 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -4
- package/dist/index.d.ts +13 -4
- package/dist/index.js +65 -19
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _zenstackhq_schema from '@zenstackhq/schema';
|
|
2
2
|
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
|
-
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool,
|
|
4
|
+
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool, AliasableExpression, ExpressionWrapper } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
6
|
import { ZodType } from 'zod';
|
|
7
7
|
|
|
@@ -604,8 +604,11 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
|
|
|
604
604
|
*/
|
|
605
605
|
validateInput?: boolean;
|
|
606
606
|
/**
|
|
607
|
-
* Whether to use compact alias names (e.g., "
|
|
607
|
+
* Whether to use compact alias names (e.g., "$$t1", "$$t2") when transforming ORM queries to SQL.
|
|
608
608
|
* Defaults to `true`.
|
|
609
|
+
*
|
|
610
|
+
* When set to `false`, original aliases are kept unless temporary aliases become too long for
|
|
611
|
+
* safe SQL identifier handling, in which case compact aliases are used as a fallback.
|
|
609
612
|
*/
|
|
610
613
|
useCompactAliasNames?: boolean;
|
|
611
614
|
/**
|
|
@@ -710,8 +713,8 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
710
713
|
private buildTypedJsonArrayFilter;
|
|
711
714
|
private buildTypeJsonNonArrayFilter;
|
|
712
715
|
private buildJsonValueFilterClause;
|
|
713
|
-
protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown):
|
|
714
|
-
private
|
|
716
|
+
protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown): Expression<SqlBool>;
|
|
717
|
+
private buildValueFilter;
|
|
715
718
|
private buildStandardFilter;
|
|
716
719
|
private buildStringFilter;
|
|
717
720
|
private buildJsonStringFilter;
|
|
@@ -740,6 +743,12 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
740
743
|
not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
741
744
|
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
|
|
742
745
|
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, any, true>): boolean;
|
|
746
|
+
/**
|
|
747
|
+
* Builds an EXISTS expression from an inner SELECT query.
|
|
748
|
+
* Can be overridden by dialects that need special handling (e.g., MySQL wraps
|
|
749
|
+
* in a derived table to avoid "can't specify target table for update in FROM clause").
|
|
750
|
+
*/
|
|
751
|
+
protected buildExistsExpression(innerQuery: SelectQueryBuilder<any, any, any>): Expression<SqlBool>;
|
|
743
752
|
abstract get provider(): DataSourceProviderType;
|
|
744
753
|
/**
|
|
745
754
|
* Builds selection for a relation field.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _zenstackhq_schema from '@zenstackhq/schema';
|
|
2
2
|
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
|
-
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool,
|
|
4
|
+
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool, AliasableExpression, ExpressionWrapper } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
6
|
import { ZodType } from 'zod';
|
|
7
7
|
|
|
@@ -604,8 +604,11 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
|
|
|
604
604
|
*/
|
|
605
605
|
validateInput?: boolean;
|
|
606
606
|
/**
|
|
607
|
-
* Whether to use compact alias names (e.g., "
|
|
607
|
+
* Whether to use compact alias names (e.g., "$$t1", "$$t2") when transforming ORM queries to SQL.
|
|
608
608
|
* Defaults to `true`.
|
|
609
|
+
*
|
|
610
|
+
* When set to `false`, original aliases are kept unless temporary aliases become too long for
|
|
611
|
+
* safe SQL identifier handling, in which case compact aliases are used as a fallback.
|
|
609
612
|
*/
|
|
610
613
|
useCompactAliasNames?: boolean;
|
|
611
614
|
/**
|
|
@@ -710,8 +713,8 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
710
713
|
private buildTypedJsonArrayFilter;
|
|
711
714
|
private buildTypeJsonNonArrayFilter;
|
|
712
715
|
private buildJsonValueFilterClause;
|
|
713
|
-
protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown):
|
|
714
|
-
private
|
|
716
|
+
protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown): Expression<SqlBool>;
|
|
717
|
+
private buildValueFilter;
|
|
715
718
|
private buildStandardFilter;
|
|
716
719
|
private buildStringFilter;
|
|
717
720
|
private buildJsonStringFilter;
|
|
@@ -740,6 +743,12 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
740
743
|
not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
741
744
|
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
|
|
742
745
|
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, any, true>): boolean;
|
|
746
|
+
/**
|
|
747
|
+
* Builds an EXISTS expression from an inner SELECT query.
|
|
748
|
+
* Can be overridden by dialects that need special handling (e.g., MySQL wraps
|
|
749
|
+
* in a derived table to avoid "can't specify target table for update in FROM clause").
|
|
750
|
+
*/
|
|
751
|
+
protected buildExistsExpression(innerQuery: SelectQueryBuilder<any, any, any>): Expression<SqlBool>;
|
|
743
752
|
abstract get provider(): DataSourceProviderType;
|
|
744
753
|
/**
|
|
745
754
|
* Builds selection for a relation field.
|
package/dist/index.js
CHANGED
|
@@ -931,21 +931,22 @@ var BaseCrudDialect = class {
|
|
|
931
931
|
if (!subPayload) {
|
|
932
932
|
continue;
|
|
933
933
|
}
|
|
934
|
-
const
|
|
934
|
+
const existsSelect = /* @__PURE__ */ __name((negate) => {
|
|
935
935
|
const filter = this.buildFilter(relationModel, relationFilterSelectAlias, subPayload);
|
|
936
|
-
|
|
937
|
-
|
|
936
|
+
const innerQuery = this.buildSelectModel(relationModel, relationFilterSelectAlias).select(this.eb.lit(1).as("_")).where(buildPkFkWhereRefs(this.eb)).where(() => negate ? this.eb.not(filter) : filter);
|
|
937
|
+
return this.buildExistsExpression(innerQuery);
|
|
938
|
+
}, "existsSelect");
|
|
938
939
|
switch (key) {
|
|
939
940
|
case "some": {
|
|
940
|
-
result = this.and(result,
|
|
941
|
+
result = this.and(result, existsSelect(false));
|
|
941
942
|
break;
|
|
942
943
|
}
|
|
943
944
|
case "every": {
|
|
944
|
-
result = this.and(result, this.eb(
|
|
945
|
+
result = this.and(result, this.eb.not(existsSelect(true)));
|
|
945
946
|
break;
|
|
946
947
|
}
|
|
947
948
|
case "none": {
|
|
948
|
-
result = this.and(result, this.eb(
|
|
949
|
+
result = this.and(result, this.eb.not(existsSelect(false)));
|
|
949
950
|
break;
|
|
950
951
|
}
|
|
951
952
|
}
|
|
@@ -1170,16 +1171,22 @@ var BaseCrudDialect = class {
|
|
|
1170
1171
|
}
|
|
1171
1172
|
}
|
|
1172
1173
|
buildJsonEqualityFilter(lhs, rhs) {
|
|
1173
|
-
return this.
|
|
1174
|
+
return this.buildValueFilter(lhs, "Json", rhs);
|
|
1174
1175
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1176
|
+
buildValueFilter(lhs, type, rhs) {
|
|
1177
|
+
if (rhs === void 0) {
|
|
1178
|
+
return this.true();
|
|
1179
|
+
}
|
|
1180
|
+
if (rhs === null) {
|
|
1181
|
+
return this.eb(lhs, "is", null);
|
|
1182
|
+
}
|
|
1183
|
+
return this.eb(lhs, "=", this.transformInput(rhs, type, false));
|
|
1177
1184
|
}
|
|
1178
1185
|
buildStandardFilter(type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0, excludeKeys = []) {
|
|
1179
1186
|
if (payload === null || !isPlainObject(payload)) {
|
|
1180
1187
|
return {
|
|
1181
1188
|
conditions: [
|
|
1182
|
-
this.
|
|
1189
|
+
this.buildValueFilter(lhs, type, payload)
|
|
1183
1190
|
],
|
|
1184
1191
|
consumedKeys: []
|
|
1185
1192
|
};
|
|
@@ -1562,6 +1569,15 @@ var BaseCrudDialect = class {
|
|
|
1562
1569
|
}
|
|
1563
1570
|
return true;
|
|
1564
1571
|
}
|
|
1572
|
+
// #endregion
|
|
1573
|
+
/**
|
|
1574
|
+
* Builds an EXISTS expression from an inner SELECT query.
|
|
1575
|
+
* Can be overridden by dialects that need special handling (e.g., MySQL wraps
|
|
1576
|
+
* in a derived table to avoid "can't specify target table for update in FROM clause").
|
|
1577
|
+
*/
|
|
1578
|
+
buildExistsExpression(innerQuery) {
|
|
1579
|
+
return this.eb.exists(innerQuery);
|
|
1580
|
+
}
|
|
1565
1581
|
};
|
|
1566
1582
|
|
|
1567
1583
|
// src/client/crud/dialects/lateral-join-dialect-base.ts
|
|
@@ -1784,6 +1800,9 @@ var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
|
1784
1800
|
}
|
|
1785
1801
|
// #endregion
|
|
1786
1802
|
// #region other overrides
|
|
1803
|
+
buildExistsExpression(innerQuery) {
|
|
1804
|
+
return this.eb.exists(this.eb.selectFrom(innerQuery.as("$exists_sub")).select(this.eb.lit(1).as("_")));
|
|
1805
|
+
}
|
|
1787
1806
|
buildArrayAgg(arg) {
|
|
1788
1807
|
return this.eb.fn.coalesce(sql2`JSON_ARRAYAGG(${arg})`, sql2`JSON_ARRAY()`);
|
|
1789
1808
|
}
|
|
@@ -1921,7 +1940,10 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
1921
1940
|
overrideTypeParsers() {
|
|
1922
1941
|
if (this.options.fixPostgresTimezone !== false && !_PostgresCrudDialect.typeParserOverrideApplied) {
|
|
1923
1942
|
_PostgresCrudDialect.typeParserOverrideApplied = true;
|
|
1924
|
-
import(
|
|
1943
|
+
import(
|
|
1944
|
+
/* webpackIgnore: true */
|
|
1945
|
+
"pg"
|
|
1946
|
+
).then((pg) => {
|
|
1925
1947
|
pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (value) => {
|
|
1926
1948
|
if (typeof value !== "string") {
|
|
1927
1949
|
return value;
|
|
@@ -3124,7 +3146,7 @@ var BaseOperationHandler = class {
|
|
|
3124
3146
|
const length = firstArgVal;
|
|
3125
3147
|
const generated = typeof length === "number" ? nanoid(length) : nanoid();
|
|
3126
3148
|
return this.formatGeneratedValue(generated, defaultValue.args?.[1]);
|
|
3127
|
-
}).with("ulid", () => this.formatGeneratedValue(ulid(), defaultValue.args?.[0])).otherwise(() => void 0);
|
|
3149
|
+
}).with("ulid", () => this.formatGeneratedValue(ulid(), defaultValue.args?.[0])).with("now", () => /* @__PURE__ */ new Date()).otherwise(() => void 0);
|
|
3128
3150
|
} else if (schema_exports.ExpressionUtils.isMember(defaultValue) && schema_exports.ExpressionUtils.isCall(defaultValue.receiver) && defaultValue.receiver.function === "auth") {
|
|
3129
3151
|
let val = this.client.$auth;
|
|
3130
3152
|
for (const member of defaultValue.members) {
|
|
@@ -7439,20 +7461,45 @@ var TempAliasTransformer = class extends OperationNodeTransformer2 {
|
|
|
7439
7461
|
__name(this, "TempAliasTransformer");
|
|
7440
7462
|
}
|
|
7441
7463
|
aliasMap = /* @__PURE__ */ new Map();
|
|
7464
|
+
textEncoder = new TextEncoder();
|
|
7465
|
+
mode;
|
|
7466
|
+
maxIdentifierLength;
|
|
7467
|
+
constructor(options = {}) {
|
|
7468
|
+
super();
|
|
7469
|
+
this.mode = options.mode ?? "alwaysCompact";
|
|
7470
|
+
const maxIdentifierLength = options.maxIdentifierLength ?? 63;
|
|
7471
|
+
if (!Number.isFinite(maxIdentifierLength) || !Number.isInteger(maxIdentifierLength) || maxIdentifierLength <= 0) {
|
|
7472
|
+
throw new RangeError("maxIdentifierLength must be a positive integer");
|
|
7473
|
+
}
|
|
7474
|
+
this.maxIdentifierLength = maxIdentifierLength;
|
|
7475
|
+
}
|
|
7442
7476
|
run(node) {
|
|
7443
7477
|
this.aliasMap.clear();
|
|
7444
7478
|
return this.transformNode(node);
|
|
7445
7479
|
}
|
|
7446
7480
|
transformIdentifier(node, queryId) {
|
|
7447
|
-
if (node.name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
7481
|
+
if (!node.name.startsWith(TEMP_ALIAS_PREFIX)) {
|
|
7482
|
+
return super.transformIdentifier(node, queryId);
|
|
7483
|
+
}
|
|
7484
|
+
let shouldCompact = false;
|
|
7485
|
+
if (this.mode === "alwaysCompact") {
|
|
7486
|
+
shouldCompact = true;
|
|
7487
|
+
} else {
|
|
7488
|
+
const aliasByteLength = this.textEncoder.encode(node.name).length;
|
|
7489
|
+
if (aliasByteLength > this.maxIdentifierLength) {
|
|
7490
|
+
shouldCompact = true;
|
|
7491
|
+
}
|
|
7492
|
+
}
|
|
7493
|
+
if (shouldCompact) {
|
|
7448
7494
|
let mapped = this.aliasMap.get(node.name);
|
|
7449
7495
|
if (!mapped) {
|
|
7450
7496
|
mapped = `$$t${this.aliasMap.size + 1}`;
|
|
7451
7497
|
this.aliasMap.set(node.name, mapped);
|
|
7452
7498
|
}
|
|
7453
7499
|
return IdentifierNode2.create(mapped);
|
|
7500
|
+
} else {
|
|
7501
|
+
return super.transformIdentifier(node, queryId);
|
|
7454
7502
|
}
|
|
7455
|
-
return super.transformIdentifier(node, queryId);
|
|
7456
7503
|
}
|
|
7457
7504
|
};
|
|
7458
7505
|
|
|
@@ -7842,10 +7889,9 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
7842
7889
|
return this.nameMapper?.transformNode(query) ?? query;
|
|
7843
7890
|
}
|
|
7844
7891
|
processTempAlias(query) {
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
}
|
|
7848
|
-
return new TempAliasTransformer().run(query);
|
|
7892
|
+
return new TempAliasTransformer({
|
|
7893
|
+
mode: this.options.useCompactAliasNames === false ? "compactLongNames" : "alwaysCompact"
|
|
7894
|
+
}).run(query);
|
|
7849
7895
|
}
|
|
7850
7896
|
createClientForConnection(connection, inTx) {
|
|
7851
7897
|
const innerExecutor = this.withConnectionProvider(new SingleConnectionProvider(connection));
|
|
@@ -8027,7 +8073,7 @@ var isEmpty = /* @__PURE__ */ __name((eb, args, { dialect }) => {
|
|
|
8027
8073
|
}
|
|
8028
8074
|
return eb(dialect.buildArrayLength(field), "=", sql6.lit(0));
|
|
8029
8075
|
}, "isEmpty");
|
|
8030
|
-
var now = /* @__PURE__ */ __name(() => sql6.raw("CURRENT_TIMESTAMP"), "now");
|
|
8076
|
+
var now = /* @__PURE__ */ __name((_eb, _args, context) => match16(context.dialect.provider).with("sqlite", () => sql6.raw("strftime('%Y-%m-%dT%H:%M:%fZ')")).with("mysql", () => sql6.raw("CONCAT(SUBSTRING(DATE_FORMAT(UTC_TIMESTAMP(3), '%Y-%m-%dT%H:%i:%s.%f'), 1, 23), '+00:00')")).with("postgresql", () => sql6.raw("CURRENT_TIMESTAMP")).exhaustive(), "now");
|
|
8031
8077
|
var currentModel = /* @__PURE__ */ __name((_eb, args, { model }) => {
|
|
8032
8078
|
let result = model;
|
|
8033
8079
|
const [casing] = args;
|