@zenstackhq/orm 3.9.8 → 3.10.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.cts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonArray, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue } from "./common-types.cjs";
2
2
  import { a as CoreCreateOperations, c as CoreReadOperations, d as FilterPropertyToKind, f as LOGICAL_COMBINATORS, i as AllWriteOperations, l as CoreUpdateOperations, n as AllCrudOperations, o as CoreCrudOperations, p as TRANSACTION_UNSUPPORTED_METHODS, r as AllReadOperations, s as CoreDeleteOperations, t as AggregateOperators, u as CoreWriteOperations } from "./constants-lRwcp6Hv.cjs";
3
3
  import * as _$kysely from "kysely";
4
- import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
4
+ import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, Selectable, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
5
5
  import * as _$_zenstackhq_schema0 from "@zenstackhq/schema";
6
- import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
6
+ import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDef, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, TypeDefIsPrimitive, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
7
7
  import { ZodType, z } from "zod";
8
8
  import Decimal from "decimal.js";
9
9
 
@@ -362,7 +362,8 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
362
362
  */
363
363
  client: ClientContract<Schema>;
364
364
  };
365
- type EntityMutationHooksDef<Schema extends SchemaDef> = {
365
+ type EntityMutationHooksDef<Schema extends SchemaDef> = { [M in '$all' | GetModels<Schema>]?: M extends '$all' ? AllEntityMutationHooksDef<Schema> : ModelEntityMutationHooksDef<Schema, M & GetModels<Schema>> };
366
+ type AllEntityMutationHooksDef<Schema extends SchemaDef> = {
366
367
  /**
367
368
  * Called before entities are mutated.
368
369
  */
@@ -433,12 +434,45 @@ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs
433
434
  beforeMutationEntities?: Record<string, unknown>[];
434
435
  /**
435
436
  * The ZenStack client you can use to perform additional operations.
436
- * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
437
+ * See {@link AllEntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
437
438
  *
438
439
  * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
439
440
  */
440
441
  client: ClientContract<Schema>;
441
442
  };
443
+ /**
444
+ * The shape of an entity passed to per-model entity mutation hooks. Entities are
445
+ * loaded directly from the database table (the same way as `$qb` query results),
446
+ * so they contain only physical columns (no relations, no computed fields, and no
447
+ * fields inherited from a delegate base model), and values are in the form returned
448
+ * by the database driver, not post-processed by the ORM.
449
+ *
450
+ * For models using delegate inheritance (`@@delegate`), a mutation fires one event
451
+ * per physical table written, keyed by that table's model. E.g., creating a sub-model
452
+ * entity fires a base-model event followed by a sub-model event; updating only
453
+ * inherited fields fires only a base-model event; deleting a sub-model entity fires
454
+ * only a base-model event (the sub-model row is removed by cascade). Base-model
455
+ * entities carry the discriminator field, which can be used to identify the concrete
456
+ * sub-model. To observe all mutations of a sub-model, register hooks on its base model
457
+ * (or use `$all`).
458
+ */
459
+ type MutationHookEntity<Schema extends SchemaDef, Model extends GetModels<Schema>> = Selectable<ToKyselySchema<Schema>[Model]>;
460
+ type PluginModelBeforeEntityMutationArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<MutationHooksArgs<Schema>, 'model'> & {
461
+ model: Model;
462
+ loadBeforeMutationEntities(): Promise<MutationHookEntity<Schema, Model>[] | undefined>;
463
+ client: ClientContract<Schema>;
464
+ };
465
+ type PluginModelAfterEntityMutationArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<MutationHooksArgs<Schema>, 'model'> & {
466
+ model: Model;
467
+ loadAfterMutationEntities(): Promise<MutationHookEntity<Schema, Model>[] | undefined>;
468
+ beforeMutationEntities?: MutationHookEntity<Schema, Model>[];
469
+ client: ClientContract<Schema>;
470
+ };
471
+ type ModelEntityMutationHooksDef<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
472
+ beforeEntityMutation?: (args: PluginModelBeforeEntityMutationArgs<Schema, Model>) => MaybePromise<void>;
473
+ afterEntityMutation?: (args: PluginModelAfterEntityMutationArgs<Schema, Model>) => MaybePromise<void>;
474
+ runAfterMutationWithinTransaction?: boolean;
475
+ };
442
476
  type OnKyselyQueryArgs<Schema extends SchemaDef> = {
443
477
  schema: SchemaDef;
444
478
  client: ClientContract<Schema>;
@@ -829,7 +863,19 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
829
863
  shouldOmitField(omit: unknown, model: string, field: string): any;
830
864
  protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, any, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
831
865
  buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string, computedArgs?: unknown): SelectQueryBuilder<any, any, any>;
832
- buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
866
+ buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModel: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
867
+ /**
868
+ * Gets the alias under which a delegate base or sub model is joined to a model selected as `modelAlias`.
869
+ * A model selected under its own name (a top-level query) has them joined under their own model names.
870
+ * A model selected under another alias (a relation subquery) has them joined under aliases derived from
871
+ * it, so they never shadow a table of an enclosing query in the same delegate hierarchy.
872
+ */
873
+ delegateJoinAlias(model: string, modelAlias: string, joinedModel: string): string;
874
+ /**
875
+ * Gets the alias of the table holding a field of a model selected as `modelAlias`: the joined base
876
+ * table for a field inherited from a delegate base, otherwise the model's own table.
877
+ */
878
+ delegateFieldAlias(model: string, modelAlias: string, fieldDef: FieldDef): string;
833
879
  buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): AliasableExpression<unknown>;
834
880
  protected negateSort(sort: SortOrder, negated: boolean): SortOrder;
835
881
  true(): Expression<SqlBool>;
@@ -1095,22 +1141,35 @@ DefaultModelResult<Schema, Model, O, Options, false, false> & { [Key in keyof I
1095
1141
  } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>) & SelectAwareExtResult<ExtResult, Model & string, Args>, Optional, Array>;
1096
1142
  type SimplifiedResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false, ExtResult extends ExtResultBase<Schema> = {}> = Simplify<ModelResult<Schema, Model, Args, Options, Optional, Array, ExtResult>>;
1097
1143
  type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ExtResult extends ExtResultBase<Schema> = {}> = Simplify<ModelResult<Schema, Model, Args, Options, false, false, ExtResult>>;
1098
- type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial> }, Partial extends true ? never : keyof { [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true }>, Partial> & (IsTypeDefStrict<Schema, TypeDef> extends true ? {} : Record<string, unknown>);
1144
+ type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef]['base'] extends string ? TypeMap[Schema['typeDefs'][TypeDef]['base']] : PartialIf<Optional<{ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial> }, Partial extends true ? never : keyof { [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true }>, Partial> & (IsTypeDefStrict<Schema, TypeDef> extends true ? {} : Record<string, unknown>) : never;
1099
1145
  type IsTypeDefStrict<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef]['strict'] extends true ? true : false : never;
1100
1146
  type BatchResult = {
1101
1147
  count: number;
1102
1148
  };
1149
+ /**
1150
+ * Context object passed to `$expr` filters.
1151
+ */
1152
+ type ExprFilterContext<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1153
+ /**
1154
+ * The alias that can be used to refer to the filtered model. It's the model name for top-level
1155
+ * filters, but relation filters select the model under a generated alias.
1156
+ *
1157
+ * Typed as the model name to match the expression builder's scope, so qualified references
1158
+ * like `` eb.ref(`${modelAlias}.field`) `` type-check.
1159
+ */
1160
+ modelAlias: Model;
1161
+ };
1103
1162
  type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = { [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: FieldHasComputedArgs<Schema, Model, Key> extends true ? // a parameterized computed field carries its query-time `args` alongside the filter
1104
1163
  {
1105
1164
  args: ComputedFieldArgs<Schema, Model, Key>;
1106
1165
  } & FieldFilter<Schema, Model, Key, Options, WithAggregations> : FieldFilter<Schema, Model, Key, Options, WithAggregations> } & {
1107
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1166
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ExprFilterContext<Schema, Model>) => OperandExpression<SqlBool>;
1108
1167
  } & {
1109
1168
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1110
1169
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1111
1170
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1112
1171
  };
1113
- type FieldFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>, WithAggregations extends boolean, AllowedKinds extends FilterKind = GetSlicedFilterKindsForField<Schema, Model, Field, Options>> = Field extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Field, Options, AllowedKinds> : FieldIsArray<Schema, Model, Field> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Field>, FieldIsArray<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends 'String' ? AddFullTextFilterIfSupported<Schema, Model, Field, AllowedKinds, AddFuzzyFilterIfSupported<Schema, Model, Field, AllowedKinds, PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1172
+ type FieldFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>, WithAggregations extends boolean, AllowedKinds extends FilterKind = GetSlicedFilterKindsForField<Schema, Model, Field, Options>> = Field extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Field, Options, AllowedKinds> : FieldIsArray<Schema, Model, Field> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, GetModelFieldType<Schema, Model, Field>> extends true ? PrimitiveFilter<TypeDefBaseType<Schema, GetModelFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Field>, FieldIsArray<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends 'String' ? AddFullTextFilterIfSupported<Schema, Model, Field, AllowedKinds, AddFuzzyFilterIfSupported<Schema, Model, Field, AllowedKinds, PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1114
1173
  /**
1115
1174
  * Conditionally augments a string-field filter with the `fuzzy` operator when:
1116
1175
  * 1. The `Fuzzy` filter kind is allowed for this field, AND
@@ -1202,7 +1261,8 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1202
1261
  */
1203
1262
  isEmpty?: boolean;
1204
1263
  } : {});
1205
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1264
+ type TypeDefBaseType<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = GetTypeDef<Schema, TypeDef>['base'] extends infer B extends string ? B : never;
1265
+ type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : Type extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, Type> extends true ? MapBaseType$1<TypeDefBaseType<Schema, Type>> : MapBaseType$1<Type> : MapBaseType$1<Type>;
1206
1266
  type PrimitiveFilter<T extends string, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = T extends 'String' ? StringFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations, AllowedKinds> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Json' ? JsonFilter<AllowedKinds> : never;
1207
1267
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1208
1268
  /**
@@ -1421,7 +1481,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1421
1481
  is?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1422
1482
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1423
1483
  } | TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1424
- type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = { [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, AllowedKinds> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> };
1484
+ type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = { [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>> extends true ? TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : PrimitiveFilter<TypeDefBaseType<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, AllowedKinds> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> };
1425
1485
  type SortOrder = 'asc' | 'desc';
1426
1486
  type NullsOrder = 'first' | 'last';
1427
1487
  type StringFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = { [Key in NonRelationFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key> extends string | null ? Key : never }[NonRelationFields<Schema, Model>];
@@ -1688,7 +1748,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1688
1748
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1689
1749
  type RelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>, AllowedKinds extends FilterKind> = 'Relation' extends AllowedKinds ? FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationFilter<Schema, Model, Field, Options> : ToOneRelationFilter<Schema, Model, Field, Options> : never;
1690
1750
  type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
1691
- type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], Partial> & (IsTypeDefStrict<Schema, T['type']> extends true ? {} : Record<string, unknown>) : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1751
+ type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, T['type']> extends true ? TypeDefResult<Schema, T['type']> : TypeDefResult<Schema, T['type'], Partial> & (IsTypeDefStrict<Schema, T['type']> extends true ? {} : Record<string, unknown>) : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1692
1752
  type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof { [Key in GetModelFields<Schema, Model> as ModelFieldIsOptional<Schema, Model, Key> extends true ? Key : FieldHasDefault<Schema, Model, Key> extends true ? Key : FieldIsArray<Schema, Model, Key> extends true ? Key : GetModelField<Schema, Model, Key>['updatedAt'] extends true | UpdatedAtInfo ? Key : never]: GetModelField<Schema, Model, Key> };
1693
1753
  type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
1694
1754
  type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetModelFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
@@ -3236,11 +3296,17 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
3236
3296
  private makeFieldArgsSchema;
3237
3297
  private addComputedArgsToFilter;
3238
3298
  private makeEnumSchema;
3299
+ /**
3300
+ * Attributes to validate each value of a scalar field against. For typedef list fields, the
3301
+ * field's own attributes (e.g. `@length`) validate the list rather than its items.
3302
+ */
3303
+ private getItemAttributes;
3239
3304
  private makeTypeDefSchema;
3240
3305
  makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
3241
3306
  private makeTypedJsonFilterSchema;
3242
3307
  private makeNullableTypedJsonMutationSchema;
3243
3308
  private isTypeDefType;
3309
+ private getEffectiveFieldType;
3244
3310
  private makeEnumFilterSchema;
3245
3311
  private makeArrayFilterSchema;
3246
3312
  private internalMakeArrayFilterSchema;
@@ -3438,7 +3504,7 @@ declare class ORMError extends Error {
3438
3504
  sqlParams?: readonly unknown[];
3439
3505
  }
3440
3506
  declare namespace query_utils_d_exports {
3441
- export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
3507
+ export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isPrimitiveTypeDef, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
3442
3508
  }
3443
3509
  declare function hasModel(schema: SchemaDef, model: string): boolean;
3444
3510
  declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
@@ -3491,6 +3557,7 @@ declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstack
3491
3557
  declare function isEnum(schema: SchemaDef, type: string): boolean;
3492
3558
  declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
3493
3559
  declare function isTypeDef(schema: SchemaDef, type: string): boolean;
3560
+ declare function isPrimitiveTypeDef(schema: SchemaDef, type: string): boolean;
3494
3561
  declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
3495
3562
  declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
3496
3563
  readonly [x: string]: "asc";
@@ -3584,5 +3651,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
3584
3651
  };
3585
3652
  }
3586
3653
  //#endregion
3587
- export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, IsTypeDefStrict, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
3654
+ export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllEntityMutationHooksDef, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExprFilterContext, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, IsTypeDefStrict, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelEntityMutationHooksDef, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, MutationHookEntity, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, PluginModelAfterEntityMutationArgs, PluginModelBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
3588
3655
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonArray, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue } from "./common-types.mjs";
2
2
  import { a as CoreCreateOperations, c as CoreReadOperations, d as FilterPropertyToKind, f as LOGICAL_COMBINATORS, i as AllWriteOperations, l as CoreUpdateOperations, n as AllCrudOperations, o as CoreCrudOperations, p as TRANSACTION_UNSUPPORTED_METHODS, r as AllReadOperations, s as CoreDeleteOperations, t as AggregateOperators, u as CoreWriteOperations } from "./constants-RUWhnVl4.mjs";
3
3
  import * as _$kysely from "kysely";
4
- import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
4
+ import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, Selectable, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
5
5
  import { ZodType, z } from "zod";
6
6
  import * as _$_zenstackhq_schema0 from "@zenstackhq/schema";
7
- import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
7
+ import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDef, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, TypeDefIsPrimitive, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
8
8
  import Decimal from "decimal.js";
9
9
 
10
10
  //#region src/utils/kysely-utils.d.ts
@@ -362,7 +362,8 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
362
362
  */
363
363
  client: ClientContract<Schema>;
364
364
  };
365
- type EntityMutationHooksDef<Schema extends SchemaDef> = {
365
+ type EntityMutationHooksDef<Schema extends SchemaDef> = { [M in '$all' | GetModels<Schema>]?: M extends '$all' ? AllEntityMutationHooksDef<Schema> : ModelEntityMutationHooksDef<Schema, M & GetModels<Schema>> };
366
+ type AllEntityMutationHooksDef<Schema extends SchemaDef> = {
366
367
  /**
367
368
  * Called before entities are mutated.
368
369
  */
@@ -433,12 +434,45 @@ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs
433
434
  beforeMutationEntities?: Record<string, unknown>[];
434
435
  /**
435
436
  * The ZenStack client you can use to perform additional operations.
436
- * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
437
+ * See {@link AllEntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
437
438
  *
438
439
  * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
439
440
  */
440
441
  client: ClientContract<Schema>;
441
442
  };
443
+ /**
444
+ * The shape of an entity passed to per-model entity mutation hooks. Entities are
445
+ * loaded directly from the database table (the same way as `$qb` query results),
446
+ * so they contain only physical columns (no relations, no computed fields, and no
447
+ * fields inherited from a delegate base model), and values are in the form returned
448
+ * by the database driver, not post-processed by the ORM.
449
+ *
450
+ * For models using delegate inheritance (`@@delegate`), a mutation fires one event
451
+ * per physical table written, keyed by that table's model. E.g., creating a sub-model
452
+ * entity fires a base-model event followed by a sub-model event; updating only
453
+ * inherited fields fires only a base-model event; deleting a sub-model entity fires
454
+ * only a base-model event (the sub-model row is removed by cascade). Base-model
455
+ * entities carry the discriminator field, which can be used to identify the concrete
456
+ * sub-model. To observe all mutations of a sub-model, register hooks on its base model
457
+ * (or use `$all`).
458
+ */
459
+ type MutationHookEntity<Schema extends SchemaDef, Model extends GetModels<Schema>> = Selectable<ToKyselySchema<Schema>[Model]>;
460
+ type PluginModelBeforeEntityMutationArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<MutationHooksArgs<Schema>, 'model'> & {
461
+ model: Model;
462
+ loadBeforeMutationEntities(): Promise<MutationHookEntity<Schema, Model>[] | undefined>;
463
+ client: ClientContract<Schema>;
464
+ };
465
+ type PluginModelAfterEntityMutationArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<MutationHooksArgs<Schema>, 'model'> & {
466
+ model: Model;
467
+ loadAfterMutationEntities(): Promise<MutationHookEntity<Schema, Model>[] | undefined>;
468
+ beforeMutationEntities?: MutationHookEntity<Schema, Model>[];
469
+ client: ClientContract<Schema>;
470
+ };
471
+ type ModelEntityMutationHooksDef<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
472
+ beforeEntityMutation?: (args: PluginModelBeforeEntityMutationArgs<Schema, Model>) => MaybePromise<void>;
473
+ afterEntityMutation?: (args: PluginModelAfterEntityMutationArgs<Schema, Model>) => MaybePromise<void>;
474
+ runAfterMutationWithinTransaction?: boolean;
475
+ };
442
476
  type OnKyselyQueryArgs<Schema extends SchemaDef> = {
443
477
  schema: SchemaDef;
444
478
  client: ClientContract<Schema>;
@@ -829,7 +863,19 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
829
863
  shouldOmitField(omit: unknown, model: string, field: string): any;
830
864
  protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, any, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
831
865
  buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string, computedArgs?: unknown): SelectQueryBuilder<any, any, any>;
832
- buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
866
+ buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModel: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
867
+ /**
868
+ * Gets the alias under which a delegate base or sub model is joined to a model selected as `modelAlias`.
869
+ * A model selected under its own name (a top-level query) has them joined under their own model names.
870
+ * A model selected under another alias (a relation subquery) has them joined under aliases derived from
871
+ * it, so they never shadow a table of an enclosing query in the same delegate hierarchy.
872
+ */
873
+ delegateJoinAlias(model: string, modelAlias: string, joinedModel: string): string;
874
+ /**
875
+ * Gets the alias of the table holding a field of a model selected as `modelAlias`: the joined base
876
+ * table for a field inherited from a delegate base, otherwise the model's own table.
877
+ */
878
+ delegateFieldAlias(model: string, modelAlias: string, fieldDef: FieldDef): string;
833
879
  buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): AliasableExpression<unknown>;
834
880
  protected negateSort(sort: SortOrder, negated: boolean): SortOrder;
835
881
  true(): Expression<SqlBool>;
@@ -1095,22 +1141,35 @@ DefaultModelResult<Schema, Model, O, Options, false, false> & { [Key in keyof I
1095
1141
  } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>) & SelectAwareExtResult<ExtResult, Model & string, Args>, Optional, Array>;
1096
1142
  type SimplifiedResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false, ExtResult extends ExtResultBase<Schema> = {}> = Simplify<ModelResult<Schema, Model, Args, Options, Optional, Array, ExtResult>>;
1097
1143
  type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ExtResult extends ExtResultBase<Schema> = {}> = Simplify<ModelResult<Schema, Model, Args, Options, false, false, ExtResult>>;
1098
- type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial> }, Partial extends true ? never : keyof { [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true }>, Partial> & (IsTypeDefStrict<Schema, TypeDef> extends true ? {} : Record<string, unknown>);
1144
+ type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef]['base'] extends string ? TypeMap[Schema['typeDefs'][TypeDef]['base']] : PartialIf<Optional<{ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial> }, Partial extends true ? never : keyof { [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true }>, Partial> & (IsTypeDefStrict<Schema, TypeDef> extends true ? {} : Record<string, unknown>) : never;
1099
1145
  type IsTypeDefStrict<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Schema['typeDefs'] extends Record<string, unknown> ? Schema['typeDefs'][TypeDef]['strict'] extends true ? true : false : never;
1100
1146
  type BatchResult = {
1101
1147
  count: number;
1102
1148
  };
1149
+ /**
1150
+ * Context object passed to `$expr` filters.
1151
+ */
1152
+ type ExprFilterContext<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1153
+ /**
1154
+ * The alias that can be used to refer to the filtered model. It's the model name for top-level
1155
+ * filters, but relation filters select the model under a generated alias.
1156
+ *
1157
+ * Typed as the model name to match the expression builder's scope, so qualified references
1158
+ * like `` eb.ref(`${modelAlias}.field`) `` type-check.
1159
+ */
1160
+ modelAlias: Model;
1161
+ };
1103
1162
  type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = { [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: FieldHasComputedArgs<Schema, Model, Key> extends true ? // a parameterized computed field carries its query-time `args` alongside the filter
1104
1163
  {
1105
1164
  args: ComputedFieldArgs<Schema, Model, Key>;
1106
1165
  } & FieldFilter<Schema, Model, Key, Options, WithAggregations> : FieldFilter<Schema, Model, Key, Options, WithAggregations> } & {
1107
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1166
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ExprFilterContext<Schema, Model>) => OperandExpression<SqlBool>;
1108
1167
  } & {
1109
1168
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1110
1169
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1111
1170
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1112
1171
  };
1113
- type FieldFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>, WithAggregations extends boolean, AllowedKinds extends FilterKind = GetSlicedFilterKindsForField<Schema, Model, Field, Options>> = Field extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Field, Options, AllowedKinds> : FieldIsArray<Schema, Model, Field> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Field>, FieldIsArray<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends 'String' ? AddFullTextFilterIfSupported<Schema, Model, Field, AllowedKinds, AddFuzzyFilterIfSupported<Schema, Model, Field, AllowedKinds, PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1172
+ type FieldFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>, WithAggregations extends boolean, AllowedKinds extends FilterKind = GetSlicedFilterKindsForField<Schema, Model, Field, Options>> = Field extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Field, Options, AllowedKinds> : FieldIsArray<Schema, Model, Field> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, GetModelFieldType<Schema, Model, Field>> extends true ? PrimitiveFilter<TypeDefBaseType<Schema, GetModelFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Field>, FieldIsArray<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends 'String' ? AddFullTextFilterIfSupported<Schema, Model, Field, AllowedKinds, AddFuzzyFilterIfSupported<Schema, Model, Field, AllowedKinds, PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1114
1173
  /**
1115
1174
  * Conditionally augments a string-field filter with the `fuzzy` operator when:
1116
1175
  * 1. The `Fuzzy` filter kind is allowed for this field, AND
@@ -1202,7 +1261,8 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1202
1261
  */
1203
1262
  isEmpty?: boolean;
1204
1263
  } : {});
1205
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1264
+ type TypeDefBaseType<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = GetTypeDef<Schema, TypeDef>['base'] extends infer B extends string ? B : never;
1265
+ type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : Type extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, Type> extends true ? MapBaseType$1<TypeDefBaseType<Schema, Type>> : MapBaseType$1<Type> : MapBaseType$1<Type>;
1206
1266
  type PrimitiveFilter<T extends string, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = T extends 'String' ? StringFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations, AllowedKinds> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Json' ? JsonFilter<AllowedKinds> : never;
1207
1267
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1208
1268
  /**
@@ -1421,7 +1481,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1421
1481
  is?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1422
1482
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1423
1483
  } | TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1424
- type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = { [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, AllowedKinds> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> };
1484
+ type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = { [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>> extends true ? TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : PrimitiveFilter<TypeDefBaseType<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, AllowedKinds> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> };
1425
1485
  type SortOrder = 'asc' | 'desc';
1426
1486
  type NullsOrder = 'first' | 'last';
1427
1487
  type StringFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = { [Key in NonRelationFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key> extends string | null ? Key : never }[NonRelationFields<Schema, Model>];
@@ -1688,7 +1748,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1688
1748
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1689
1749
  type RelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>, AllowedKinds extends FilterKind> = 'Relation' extends AllowedKinds ? FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationFilter<Schema, Model, Field, Options> : ToOneRelationFilter<Schema, Model, Field, Options> : never;
1690
1750
  type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
1691
- type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], Partial> & (IsTypeDefStrict<Schema, T['type']> extends true ? {} : Record<string, unknown>) : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1751
+ type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefIsPrimitive<Schema, T['type']> extends true ? TypeDefResult<Schema, T['type']> : TypeDefResult<Schema, T['type'], Partial> & (IsTypeDefStrict<Schema, T['type']> extends true ? {} : Record<string, unknown>) : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1692
1752
  type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof { [Key in GetModelFields<Schema, Model> as ModelFieldIsOptional<Schema, Model, Key> extends true ? Key : FieldHasDefault<Schema, Model, Key> extends true ? Key : FieldIsArray<Schema, Model, Key> extends true ? Key : GetModelField<Schema, Model, Key>['updatedAt'] extends true | UpdatedAtInfo ? Key : never]: GetModelField<Schema, Model, Key> };
1693
1753
  type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
1694
1754
  type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetModelFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
@@ -3236,11 +3296,17 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
3236
3296
  private makeFieldArgsSchema;
3237
3297
  private addComputedArgsToFilter;
3238
3298
  private makeEnumSchema;
3299
+ /**
3300
+ * Attributes to validate each value of a scalar field against. For typedef list fields, the
3301
+ * field's own attributes (e.g. `@length`) validate the list rather than its items.
3302
+ */
3303
+ private getItemAttributes;
3239
3304
  private makeTypeDefSchema;
3240
3305
  makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
3241
3306
  private makeTypedJsonFilterSchema;
3242
3307
  private makeNullableTypedJsonMutationSchema;
3243
3308
  private isTypeDefType;
3309
+ private getEffectiveFieldType;
3244
3310
  private makeEnumFilterSchema;
3245
3311
  private makeArrayFilterSchema;
3246
3312
  private internalMakeArrayFilterSchema;
@@ -3438,7 +3504,7 @@ declare class ORMError extends Error {
3438
3504
  sqlParams?: readonly unknown[];
3439
3505
  }
3440
3506
  declare namespace query_utils_d_exports {
3441
- export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
3507
+ export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isPrimitiveTypeDef, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
3442
3508
  }
3443
3509
  declare function hasModel(schema: SchemaDef, model: string): boolean;
3444
3510
  declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
@@ -3491,6 +3557,7 @@ declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstack
3491
3557
  declare function isEnum(schema: SchemaDef, type: string): boolean;
3492
3558
  declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
3493
3559
  declare function isTypeDef(schema: SchemaDef, type: string): boolean;
3560
+ declare function isPrimitiveTypeDef(schema: SchemaDef, type: string): boolean;
3494
3561
  declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
3495
3562
  declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
3496
3563
  readonly [x: string]: "asc";
@@ -3584,5 +3651,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
3584
3651
  };
3585
3652
  }
3586
3653
  //#endregion
3587
- export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, IsTypeDefStrict, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
3654
+ export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllEntityMutationHooksDef, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExprFilterContext, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, IsTypeDefStrict, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelEntityMutationHooksDef, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, MutationHookEntity, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, PluginModelAfterEntityMutationArgs, PluginModelBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
3588
3655
  //# sourceMappingURL=index.d.mts.map