@zenstackhq/orm 3.9.8 → 3.10.1

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>;
@@ -960,17 +1006,22 @@ type FuzzyFilterOptions = {
960
1006
  };
961
1007
  //#endregion
962
1008
  //#region src/client/crud/validator/validator.d.ts
963
- type InputValidatorOptions = {
1009
+ type InputValidatorOptions<Schema extends SchemaDef> = {
964
1010
  /**
965
1011
  * Whether validation is enabled. Defaults to `true`.
966
1012
  */
967
1013
  enabled?: boolean;
1014
+ /**
1015
+ * Schema factory to validate with. Defaults to a new factory (and so a new schema cache) bound
1016
+ * to the client.
1017
+ */
1018
+ zodFactory?: ZodSchemaFactory<Schema>;
968
1019
  };
969
1020
  declare class InputValidator<Schema extends SchemaDef> {
970
1021
  private readonly client;
971
1022
  readonly zodFactory: ZodSchemaFactory<Schema>;
972
1023
  private readonly enabled;
973
- constructor(client: ClientContract<Schema>, options?: InputValidatorOptions);
1024
+ constructor(client: ClientContract<Schema>, options?: InputValidatorOptions<Schema>);
974
1025
  validateFindArgs(model: GetModels<Schema>, args: unknown, operation: 'findFirst' | 'findUnique' | 'findMany'): FindArgs<Schema, GetModels<Schema>, any, true> | undefined;
975
1026
  validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>, any> | undefined;
976
1027
  validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>, any>;
@@ -1095,22 +1146,35 @@ DefaultModelResult<Schema, Model, O, Options, false, false> & { [Key in keyof I
1095
1146
  } & 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
1147
  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
1148
  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>);
1149
+ 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
1150
  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
1151
  type BatchResult = {
1101
1152
  count: number;
1102
1153
  };
1154
+ /**
1155
+ * Context object passed to `$expr` filters.
1156
+ */
1157
+ type ExprFilterContext<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1158
+ /**
1159
+ * The alias that can be used to refer to the filtered model. It's the model name for top-level
1160
+ * filters, but relation filters select the model under a generated alias.
1161
+ *
1162
+ * Typed as the model name to match the expression builder's scope, so qualified references
1163
+ * like `` eb.ref(`${modelAlias}.field`) `` type-check.
1164
+ */
1165
+ modelAlias: Model;
1166
+ };
1103
1167
  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
1168
  {
1105
1169
  args: ComputedFieldArgs<Schema, Model, Key>;
1106
1170
  } & FieldFilter<Schema, Model, Key, Options, WithAggregations> : FieldFilter<Schema, Model, Key, Options, WithAggregations> } & {
1107
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1171
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ExprFilterContext<Schema, Model>) => OperandExpression<SqlBool>;
1108
1172
  } & {
1109
1173
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1110
1174
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1111
1175
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1112
1176
  };
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>;
1177
+ 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
1178
  /**
1115
1179
  * Conditionally augments a string-field filter with the `fuzzy` operator when:
1116
1180
  * 1. The `Fuzzy` filter kind is allowed for this field, AND
@@ -1202,7 +1266,8 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1202
1266
  */
1203
1267
  isEmpty?: boolean;
1204
1268
  } : {});
1205
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1269
+ type TypeDefBaseType<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = GetTypeDef<Schema, TypeDef>['base'] extends infer B extends string ? B : never;
1270
+ 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
1271
  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
1272
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1208
1273
  /**
@@ -1421,7 +1486,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1421
1486
  is?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1422
1487
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1423
1488
  } | 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> };
1489
+ 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
1490
  type SortOrder = 'asc' | 'desc';
1426
1491
  type NullsOrder = 'first' | 'last';
1427
1492
  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 +1753,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1688
1753
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1689
1754
  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
1755
  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']>;
1756
+ 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
1757
  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
1758
  type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
1694
1759
  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 +3301,17 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
3236
3301
  private makeFieldArgsSchema;
3237
3302
  private addComputedArgsToFilter;
3238
3303
  private makeEnumSchema;
3304
+ /**
3305
+ * Attributes to validate each value of a scalar field against. For typedef list fields, the
3306
+ * field's own attributes (e.g. `@length`) validate the list rather than its items.
3307
+ */
3308
+ private getItemAttributes;
3239
3309
  private makeTypeDefSchema;
3240
3310
  makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
3241
3311
  private makeTypedJsonFilterSchema;
3242
3312
  private makeNullableTypedJsonMutationSchema;
3243
3313
  private isTypeDefType;
3314
+ private getEffectiveFieldType;
3244
3315
  private makeEnumFilterSchema;
3245
3316
  private makeArrayFilterSchema;
3246
3317
  private internalMakeArrayFilterSchema;
@@ -3438,7 +3509,7 @@ declare class ORMError extends Error {
3438
3509
  sqlParams?: readonly unknown[];
3439
3510
  }
3440
3511
  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 };
3512
+ 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
3513
  }
3443
3514
  declare function hasModel(schema: SchemaDef, model: string): boolean;
3444
3515
  declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
@@ -3491,6 +3562,7 @@ declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstack
3491
3562
  declare function isEnum(schema: SchemaDef, type: string): boolean;
3492
3563
  declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
3493
3564
  declare function isTypeDef(schema: SchemaDef, type: string): boolean;
3565
+ declare function isPrimitiveTypeDef(schema: SchemaDef, type: string): boolean;
3494
3566
  declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
3495
3567
  declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
3496
3568
  readonly [x: string]: "asc";
@@ -3584,5 +3656,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
3584
3656
  };
3585
3657
  }
3586
3658
  //#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 };
3659
+ 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
3660
  //# 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";
5
- import { ZodType, z } from "zod";
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
+ import { ZodType, z as z$1 } 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>;
@@ -960,17 +1006,22 @@ type FuzzyFilterOptions = {
960
1006
  };
961
1007
  //#endregion
962
1008
  //#region src/client/crud/validator/validator.d.ts
963
- type InputValidatorOptions = {
1009
+ type InputValidatorOptions<Schema extends SchemaDef> = {
964
1010
  /**
965
1011
  * Whether validation is enabled. Defaults to `true`.
966
1012
  */
967
1013
  enabled?: boolean;
1014
+ /**
1015
+ * Schema factory to validate with. Defaults to a new factory (and so a new schema cache) bound
1016
+ * to the client.
1017
+ */
1018
+ zodFactory?: ZodSchemaFactory<Schema>;
968
1019
  };
969
1020
  declare class InputValidator<Schema extends SchemaDef> {
970
1021
  private readonly client;
971
1022
  readonly zodFactory: ZodSchemaFactory<Schema>;
972
1023
  private readonly enabled;
973
- constructor(client: ClientContract<Schema>, options?: InputValidatorOptions);
1024
+ constructor(client: ClientContract<Schema>, options?: InputValidatorOptions<Schema>);
974
1025
  validateFindArgs(model: GetModels<Schema>, args: unknown, operation: 'findFirst' | 'findUnique' | 'findMany'): FindArgs<Schema, GetModels<Schema>, any, true> | undefined;
975
1026
  validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>, any> | undefined;
976
1027
  validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>, any>;
@@ -1095,22 +1146,35 @@ DefaultModelResult<Schema, Model, O, Options, false, false> & { [Key in keyof I
1095
1146
  } & 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
1147
  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
1148
  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>);
1149
+ 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
1150
  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
1151
  type BatchResult = {
1101
1152
  count: number;
1102
1153
  };
1154
+ /**
1155
+ * Context object passed to `$expr` filters.
1156
+ */
1157
+ type ExprFilterContext<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1158
+ /**
1159
+ * The alias that can be used to refer to the filtered model. It's the model name for top-level
1160
+ * filters, but relation filters select the model under a generated alias.
1161
+ *
1162
+ * Typed as the model name to match the expression builder's scope, so qualified references
1163
+ * like `` eb.ref(`${modelAlias}.field`) `` type-check.
1164
+ */
1165
+ modelAlias: Model;
1166
+ };
1103
1167
  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
1168
  {
1105
1169
  args: ComputedFieldArgs<Schema, Model, Key>;
1106
1170
  } & FieldFilter<Schema, Model, Key, Options, WithAggregations> : FieldFilter<Schema, Model, Key, Options, WithAggregations> } & {
1107
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1171
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ExprFilterContext<Schema, Model>) => OperandExpression<SqlBool>;
1108
1172
  } & {
1109
1173
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1110
1174
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1111
1175
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1112
1176
  };
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>;
1177
+ 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
1178
  /**
1115
1179
  * Conditionally augments a string-field filter with the `fuzzy` operator when:
1116
1180
  * 1. The `Fuzzy` filter kind is allowed for this field, AND
@@ -1202,7 +1266,8 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1202
1266
  */
1203
1267
  isEmpty?: boolean;
1204
1268
  } : {});
1205
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1269
+ type TypeDefBaseType<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = GetTypeDef<Schema, TypeDef>['base'] extends infer B extends string ? B : never;
1270
+ 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
1271
  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
1272
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1208
1273
  /**
@@ -1421,7 +1486,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1421
1486
  is?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1422
1487
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1423
1488
  } | 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> };
1489
+ 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
1490
  type SortOrder = 'asc' | 'desc';
1426
1491
  type NullsOrder = 'first' | 'last';
1427
1492
  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 +1753,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1688
1753
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1689
1754
  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
1755
  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']>;
1756
+ 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
1757
  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
1758
  type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
1694
1759
  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;
@@ -3220,7 +3285,7 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
3220
3285
  * before serialization.
3221
3286
  */
3222
3287
  toJSONSchema(): {
3223
- schemas: Record<string, z.core.JSONSchema.BaseSchema>;
3288
+ schemas: Record<string, z$1.core.JSONSchema.BaseSchema>;
3224
3289
  };
3225
3290
  get cacheStats(): {
3226
3291
  size: number;
@@ -3236,11 +3301,17 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
3236
3301
  private makeFieldArgsSchema;
3237
3302
  private addComputedArgsToFilter;
3238
3303
  private makeEnumSchema;
3304
+ /**
3305
+ * Attributes to validate each value of a scalar field against. For typedef list fields, the
3306
+ * field's own attributes (e.g. `@length`) validate the list rather than its items.
3307
+ */
3308
+ private getItemAttributes;
3239
3309
  private makeTypeDefSchema;
3240
3310
  makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
3241
3311
  private makeTypedJsonFilterSchema;
3242
3312
  private makeNullableTypedJsonMutationSchema;
3243
3313
  private isTypeDefType;
3314
+ private getEffectiveFieldType;
3244
3315
  private makeEnumFilterSchema;
3245
3316
  private makeArrayFilterSchema;
3246
3317
  private internalMakeArrayFilterSchema;
@@ -3438,7 +3509,7 @@ declare class ORMError extends Error {
3438
3509
  sqlParams?: readonly unknown[];
3439
3510
  }
3440
3511
  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 };
3512
+ 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
3513
  }
3443
3514
  declare function hasModel(schema: SchemaDef, model: string): boolean;
3444
3515
  declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
@@ -3491,6 +3562,7 @@ declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstack
3491
3562
  declare function isEnum(schema: SchemaDef, type: string): boolean;
3492
3563
  declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
3493
3564
  declare function isTypeDef(schema: SchemaDef, type: string): boolean;
3565
+ declare function isPrimitiveTypeDef(schema: SchemaDef, type: string): boolean;
3494
3566
  declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
3495
3567
  declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
3496
3568
  readonly [x: string]: "asc";
@@ -3584,5 +3656,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
3584
3656
  };
3585
3657
  }
3586
3658
  //#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 };
3659
+ 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
3660
  //# sourceMappingURL=index.d.mts.map