@danielhritcu/zenstack-orm 3.5.16 → 3.5.18

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
@@ -120,6 +120,10 @@ type JsonObject = {
120
120
  };
121
121
  type JsonArray = ReadonlyArray<JsonValue | null>;
122
122
  type JsonNullValues = DbNull | JsonNull | AnyNull;
123
+ declare const __zenstackBrand: unique symbol;
124
+ type Brand<T extends string> = string & {
125
+ [__zenstackBrand]: T;
126
+ };
123
127
  declare class DbNullClass {
124
128
  private __brand;
125
129
  }
@@ -1201,7 +1205,7 @@ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Optio
1201
1205
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1202
1206
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1203
1207
  };
1204
- 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> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1208
+ 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> : PrimitiveFilter<MapModelFieldType<Schema, Model, Field>, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1205
1209
  type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<keyof GetEnum<Schema, T>, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1206
1210
  /**
1207
1211
  * Checks for equality with the specified enum value.
@@ -1258,7 +1262,7 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1258
1262
  isEmpty?: boolean;
1259
1263
  } : {});
1260
1264
  type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1261
- 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;
1265
+ type PrimitiveFilter<DataType, T extends string, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = T extends 'String' ? StringFilter<Nullable, WithAggregations, AllowedKinds, DataType & string> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations, AllowedKinds, DataType & (number | bigint)> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations, AllowedKinds, DataType & boolean> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations, AllowedKinds, DataType & (Date | string)> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations, AllowedKinds, DataType & (Uint8Array | Buffer)> : T extends 'Json' ? JsonFilter<AllowedKinds> : never;
1262
1266
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1263
1267
  /**
1264
1268
  * Checks for equality with the specified value.
@@ -1297,9 +1301,9 @@ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boo
1297
1301
  /**
1298
1302
  * Builds a negated filter.
1299
1303
  */
1300
- not?: PrimitiveFilter<T, Nullable, WithAggregations, AllowedKinds>;
1304
+ not?: PrimitiveFilter<DataType, T, Nullable, WithAggregations, AllowedKinds>;
1301
1305
  };
1302
- type StringFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<string, Nullable> : never) | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations, AllowedKinds> & ('Like' extends AllowedKinds ? {
1306
+ type StringFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends string = string> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, 'String', Nullable, WithAggregations, AllowedKinds> & ('Like' extends AllowedKinds ? {
1303
1307
  /**
1304
1308
  * Checks if the string contains the specified substring.
1305
1309
  */
@@ -1330,7 +1334,7 @@ type StringFilter<Nullable extends boolean, WithAggregations extends boolean, Al
1330
1334
  */
1331
1335
  _max?: StringFilter<false, false, AllowedKinds>;
1332
1336
  } : {}));
1333
- type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<number | bigint, Nullable> : never) | (CommonPrimitiveFilter<number, T, Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1337
+ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends number | bigint = number | bigint> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, T, Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1334
1338
  /**
1335
1339
  * Filters against the count of records.
1336
1340
  */
@@ -1338,21 +1342,21 @@ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable ext
1338
1342
  /**
1339
1343
  * Filters against the average value.
1340
1344
  */
1341
- _avg?: NumberFilter<T, false, false, AllowedKinds>;
1345
+ _avg?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1342
1346
  /**
1343
1347
  * Filters against the sum value.
1344
1348
  */
1345
- _sum?: NumberFilter<T, false, false, AllowedKinds>;
1349
+ _sum?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1346
1350
  /**
1347
1351
  * Filters against the minimum value.
1348
1352
  */
1349
- _min?: NumberFilter<T, false, false, AllowedKinds>;
1353
+ _min?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1350
1354
  /**
1351
1355
  * Filters against the maximum value.
1352
1356
  */
1353
- _max?: NumberFilter<T, false, false, AllowedKinds>;
1357
+ _max?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1354
1358
  } : {}));
1355
- type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Date | string, Nullable> : never) | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1359
+ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends Date | string = Date | string> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, 'DateTime', Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1356
1360
  /**
1357
1361
  * Filters against the count of records.
1358
1362
  */
@@ -1366,24 +1370,24 @@ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean,
1366
1370
  */
1367
1371
  _max?: DateTimeFilter<false, false, AllowedKinds>;
1368
1372
  } : {}));
1369
- type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Uint8Array | Buffer, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1373
+ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends Uint8Array | Buffer = Uint8Array | Buffer> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1370
1374
  /**
1371
1375
  * Checks for equality with the specified value.
1372
1376
  */
1373
- equals?: NullableIf<Uint8Array, Nullable>;
1377
+ equals?: NullableIf<DataType, Nullable>;
1374
1378
  /**
1375
1379
  * Checks if the value is in the specified list of values.
1376
1380
  */
1377
- in?: Uint8Array[];
1381
+ in?: DataType[];
1378
1382
  /**
1379
1383
  * Checks if the value is not in the specified list of values.
1380
1384
  */
1381
- notIn?: Uint8Array[];
1385
+ notIn?: DataType[];
1382
1386
  } : {}) & {
1383
1387
  /**
1384
1388
  * Builds a negated filter.
1385
1389
  */
1386
- not?: BytesFilter<Nullable, WithAggregations, AllowedKinds>;
1390
+ not?: BytesFilter<Nullable, WithAggregations, AllowedKinds, DataType>;
1387
1391
  } & (WithAggregations extends true ? {
1388
1392
  /**
1389
1393
  * Filters against the count of records.
@@ -1398,16 +1402,16 @@ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, All
1398
1402
  */
1399
1403
  _max?: BytesFilter<false, false, AllowedKinds>;
1400
1404
  } : {}));
1401
- type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<boolean, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1405
+ type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends boolean = boolean> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1402
1406
  /**
1403
1407
  * Checks for equality with the specified value.
1404
1408
  */
1405
- equals?: NullableIf<boolean, Nullable>;
1409
+ equals?: NullableIf<DataType, Nullable>;
1406
1410
  } : {}) & {
1407
1411
  /**
1408
1412
  * Builds a negated filter.
1409
1413
  */
1410
- not?: BooleanFilter<Nullable, WithAggregations, AllowedKinds>;
1414
+ not?: BooleanFilter<Nullable, WithAggregations, AllowedKinds, DataType>;
1411
1415
  } & (WithAggregations extends true ? {
1412
1416
  /**
1413
1417
  * Filters against the count of records.
@@ -1477,7 +1481,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1477
1481
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1478
1482
  } | TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1479
1483
  type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
1480
- [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
+ [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<MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDefName, Key>>, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds>;
1481
1485
  };
1482
1486
  type SortOrder = 'asc' | 'desc';
1483
1487
  type NullsOrder = 'first' | 'last';
@@ -1523,8 +1527,8 @@ type OrderBy<Schema extends SchemaDef, Model extends GetModels<Schema>, WithRela
1523
1527
  _sum?: SumAvgInput<Schema, Model, SortOrder>;
1524
1528
  }) : {});
1525
1529
  type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = AtLeast<{
1526
- [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
1527
- [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
1530
+ [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type' | 'brand'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
1531
+ [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type' | 'brand'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
1528
1532
  };
1529
1533
  } & WhereInput<Schema, Model, Options>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
1530
1534
  type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
@@ -1589,7 +1593,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1589
1593
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1590
1594
  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;
1591
1595
  type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
1592
- 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> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1596
+ type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'> & globalThis.Partial<Pick<FieldDef, 'brand'>>, IsPartial extends boolean = false> = WrapType<T['brand'] extends string ? Brand<T['brand']> : T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], IsPartial> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1593
1597
  type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1594
1598
  [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>;
1595
1599
  };
@@ -3482,4 +3486,4 @@ declare namespace schemaUtils {
3482
3486
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
3483
3487
  }
3484
3488
 
3485
- export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DefaultWhereConfig, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type ExtResultBase, type ExtResultInferenceArgs, type ExtResultSelectOmitFields, type ExtractExtResult, type FilterKind, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetAllIncludedOperations, type GetIncludedOperations, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GetQueryOptions, type GetSlicedFilterKindsForField, type GetSlicedModels, type GetSlicedOperations, type GetSlicedProcedures, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, LOGICAL_COMBINATORS, type MapModelFieldType, type ModelAllowsCreate, type ModelHasRequiredUnsupportedField, type ModelOperations, type ModelResult, type ModelSlicingOptions, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsRequiringCreate, type OrderBy, type PaginatedCursor, type PaginatedOffset, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, type SchemaExtResult, schemaUtils as SchemaUtils, type SearchFieldMap, type SearchMode, type SearchPayload, type SearchStrategy, type SelectAwareExtResult, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SlicingOptions, type SortOrder, type StringFilter, type Subset, type ToKysely, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, ZENSTACK_QUERY_KIND_SYMBOL, ZENSTACK_QUERY_SYMBOL, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZenStackQueryKind, createQuerySchemaFactory, definePlugin, getCrudDialect };
3489
+ export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type Brand, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DefaultWhereConfig, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type ExtResultBase, type ExtResultInferenceArgs, type ExtResultSelectOmitFields, type ExtractExtResult, type FilterKind, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetAllIncludedOperations, type GetIncludedOperations, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GetQueryOptions, type GetSlicedFilterKindsForField, type GetSlicedModels, type GetSlicedOperations, type GetSlicedProcedures, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, LOGICAL_COMBINATORS, type MapModelFieldType, type ModelAllowsCreate, type ModelHasRequiredUnsupportedField, type ModelOperations, type ModelResult, type ModelSlicingOptions, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsRequiringCreate, type OrderBy, type PaginatedCursor, type PaginatedOffset, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, type SchemaExtResult, schemaUtils as SchemaUtils, type SearchFieldMap, type SearchMode, type SearchPayload, type SearchStrategy, type SelectAwareExtResult, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SlicingOptions, type SortOrder, type StringFilter, type Subset, type ToKysely, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, ZENSTACK_QUERY_KIND_SYMBOL, ZENSTACK_QUERY_SYMBOL, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZenStackQueryKind, createQuerySchemaFactory, definePlugin, getCrudDialect };
package/dist/index.d.ts CHANGED
@@ -120,6 +120,10 @@ type JsonObject = {
120
120
  };
121
121
  type JsonArray = ReadonlyArray<JsonValue | null>;
122
122
  type JsonNullValues = DbNull | JsonNull | AnyNull;
123
+ declare const __zenstackBrand: unique symbol;
124
+ type Brand<T extends string> = string & {
125
+ [__zenstackBrand]: T;
126
+ };
123
127
  declare class DbNullClass {
124
128
  private __brand;
125
129
  }
@@ -1201,7 +1205,7 @@ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Optio
1201
1205
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1202
1206
  NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1203
1207
  };
1204
- 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> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1208
+ 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> : PrimitiveFilter<MapModelFieldType<Schema, Model, Field>, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1205
1209
  type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<keyof GetEnum<Schema, T>, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1206
1210
  /**
1207
1211
  * Checks for equality with the specified enum value.
@@ -1258,7 +1262,7 @@ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds ext
1258
1262
  isEmpty?: boolean;
1259
1263
  } : {});
1260
1264
  type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1261
- 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;
1265
+ type PrimitiveFilter<DataType, T extends string, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = T extends 'String' ? StringFilter<Nullable, WithAggregations, AllowedKinds, DataType & string> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations, AllowedKinds, DataType & (number | bigint)> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations, AllowedKinds, DataType & boolean> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations, AllowedKinds, DataType & (Date | string)> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations, AllowedKinds, DataType & (Uint8Array | Buffer)> : T extends 'Json' ? JsonFilter<AllowedKinds> : never;
1262
1266
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1263
1267
  /**
1264
1268
  * Checks for equality with the specified value.
@@ -1297,9 +1301,9 @@ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boo
1297
1301
  /**
1298
1302
  * Builds a negated filter.
1299
1303
  */
1300
- not?: PrimitiveFilter<T, Nullable, WithAggregations, AllowedKinds>;
1304
+ not?: PrimitiveFilter<DataType, T, Nullable, WithAggregations, AllowedKinds>;
1301
1305
  };
1302
- type StringFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<string, Nullable> : never) | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations, AllowedKinds> & ('Like' extends AllowedKinds ? {
1306
+ type StringFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends string = string> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, 'String', Nullable, WithAggregations, AllowedKinds> & ('Like' extends AllowedKinds ? {
1303
1307
  /**
1304
1308
  * Checks if the string contains the specified substring.
1305
1309
  */
@@ -1330,7 +1334,7 @@ type StringFilter<Nullable extends boolean, WithAggregations extends boolean, Al
1330
1334
  */
1331
1335
  _max?: StringFilter<false, false, AllowedKinds>;
1332
1336
  } : {}));
1333
- type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<number | bigint, Nullable> : never) | (CommonPrimitiveFilter<number, T, Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1337
+ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends number | bigint = number | bigint> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, T, Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1334
1338
  /**
1335
1339
  * Filters against the count of records.
1336
1340
  */
@@ -1338,21 +1342,21 @@ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable ext
1338
1342
  /**
1339
1343
  * Filters against the average value.
1340
1344
  */
1341
- _avg?: NumberFilter<T, false, false, AllowedKinds>;
1345
+ _avg?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1342
1346
  /**
1343
1347
  * Filters against the sum value.
1344
1348
  */
1345
- _sum?: NumberFilter<T, false, false, AllowedKinds>;
1349
+ _sum?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1346
1350
  /**
1347
1351
  * Filters against the minimum value.
1348
1352
  */
1349
- _min?: NumberFilter<T, false, false, AllowedKinds>;
1353
+ _min?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1350
1354
  /**
1351
1355
  * Filters against the maximum value.
1352
1356
  */
1353
- _max?: NumberFilter<T, false, false, AllowedKinds>;
1357
+ _max?: NumberFilter<T, false, false, AllowedKinds, DataType>;
1354
1358
  } : {}));
1355
- type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Date | string, Nullable> : never) | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1359
+ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends Date | string = Date | string> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (CommonPrimitiveFilter<DataType, 'DateTime', Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1356
1360
  /**
1357
1361
  * Filters against the count of records.
1358
1362
  */
@@ -1366,24 +1370,24 @@ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean,
1366
1370
  */
1367
1371
  _max?: DateTimeFilter<false, false, AllowedKinds>;
1368
1372
  } : {}));
1369
- type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Uint8Array | Buffer, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1373
+ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends Uint8Array | Buffer = Uint8Array | Buffer> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1370
1374
  /**
1371
1375
  * Checks for equality with the specified value.
1372
1376
  */
1373
- equals?: NullableIf<Uint8Array, Nullable>;
1377
+ equals?: NullableIf<DataType, Nullable>;
1374
1378
  /**
1375
1379
  * Checks if the value is in the specified list of values.
1376
1380
  */
1377
- in?: Uint8Array[];
1381
+ in?: DataType[];
1378
1382
  /**
1379
1383
  * Checks if the value is not in the specified list of values.
1380
1384
  */
1381
- notIn?: Uint8Array[];
1385
+ notIn?: DataType[];
1382
1386
  } : {}) & {
1383
1387
  /**
1384
1388
  * Builds a negated filter.
1385
1389
  */
1386
- not?: BytesFilter<Nullable, WithAggregations, AllowedKinds>;
1390
+ not?: BytesFilter<Nullable, WithAggregations, AllowedKinds, DataType>;
1387
1391
  } & (WithAggregations extends true ? {
1388
1392
  /**
1389
1393
  * Filters against the count of records.
@@ -1398,16 +1402,16 @@ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, All
1398
1402
  */
1399
1403
  _max?: BytesFilter<false, false, AllowedKinds>;
1400
1404
  } : {}));
1401
- type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<boolean, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1405
+ type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind, DataType extends boolean = boolean> = ('Equality' extends AllowedKinds ? NullableIf<DataType, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1402
1406
  /**
1403
1407
  * Checks for equality with the specified value.
1404
1408
  */
1405
- equals?: NullableIf<boolean, Nullable>;
1409
+ equals?: NullableIf<DataType, Nullable>;
1406
1410
  } : {}) & {
1407
1411
  /**
1408
1412
  * Builds a negated filter.
1409
1413
  */
1410
- not?: BooleanFilter<Nullable, WithAggregations, AllowedKinds>;
1414
+ not?: BooleanFilter<Nullable, WithAggregations, AllowedKinds, DataType>;
1411
1415
  } & (WithAggregations extends true ? {
1412
1416
  /**
1413
1417
  * Filters against the count of records.
@@ -1477,7 +1481,7 @@ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTy
1477
1481
  isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1478
1482
  } | TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1479
1483
  type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
1480
- [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
+ [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<MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDefName, Key>>, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds>;
1481
1485
  };
1482
1486
  type SortOrder = 'asc' | 'desc';
1483
1487
  type NullsOrder = 'first' | 'last';
@@ -1523,8 +1527,8 @@ type OrderBy<Schema extends SchemaDef, Model extends GetModels<Schema>, WithRela
1523
1527
  _sum?: SumAvgInput<Schema, Model, SortOrder>;
1524
1528
  }) : {});
1525
1529
  type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = AtLeast<{
1526
- [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
1527
- [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
1530
+ [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type' | 'brand'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
1531
+ [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type' | 'brand'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
1528
1532
  };
1529
1533
  } & WhereInput<Schema, Model, Options>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
1530
1534
  type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
@@ -1589,7 +1593,7 @@ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schem
1589
1593
  }, ModelFieldIsOptional<Schema, Model, Field>>;
1590
1594
  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;
1591
1595
  type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
1592
- 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> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1596
+ type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'> & globalThis.Partial<Pick<FieldDef, 'brand'>>, IsPartial extends boolean = false> = WrapType<T['brand'] extends string ? Brand<T['brand']> : T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], IsPartial> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1593
1597
  type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1594
1598
  [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>;
1595
1599
  };
@@ -3482,4 +3486,4 @@ declare namespace schemaUtils {
3482
3486
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
3483
3487
  }
3484
3488
 
3485
- export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DefaultWhereConfig, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type ExtResultBase, type ExtResultInferenceArgs, type ExtResultSelectOmitFields, type ExtractExtResult, type FilterKind, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetAllIncludedOperations, type GetIncludedOperations, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GetQueryOptions, type GetSlicedFilterKindsForField, type GetSlicedModels, type GetSlicedOperations, type GetSlicedProcedures, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, LOGICAL_COMBINATORS, type MapModelFieldType, type ModelAllowsCreate, type ModelHasRequiredUnsupportedField, type ModelOperations, type ModelResult, type ModelSlicingOptions, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsRequiringCreate, type OrderBy, type PaginatedCursor, type PaginatedOffset, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, type SchemaExtResult, schemaUtils as SchemaUtils, type SearchFieldMap, type SearchMode, type SearchPayload, type SearchStrategy, type SelectAwareExtResult, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SlicingOptions, type SortOrder, type StringFilter, type Subset, type ToKysely, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, ZENSTACK_QUERY_KIND_SYMBOL, ZENSTACK_QUERY_SYMBOL, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZenStackQueryKind, createQuerySchemaFactory, definePlugin, getCrudDialect };
3489
+ export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type Brand, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DefaultWhereConfig, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type ExtResultBase, type ExtResultInferenceArgs, type ExtResultSelectOmitFields, type ExtractExtResult, type FilterKind, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetAllIncludedOperations, type GetIncludedOperations, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GetQueryOptions, type GetSlicedFilterKindsForField, type GetSlicedModels, type GetSlicedOperations, type GetSlicedProcedures, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, LOGICAL_COMBINATORS, type MapModelFieldType, type ModelAllowsCreate, type ModelHasRequiredUnsupportedField, type ModelOperations, type ModelResult, type ModelSlicingOptions, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsRequiringCreate, type OrderBy, type PaginatedCursor, type PaginatedOffset, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, type SchemaExtResult, schemaUtils as SchemaUtils, type SearchFieldMap, type SearchMode, type SearchPayload, type SearchStrategy, type SelectAwareExtResult, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SlicingOptions, type SortOrder, type StringFilter, type Subset, type ToKysely, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, ZENSTACK_QUERY_KIND_SYMBOL, ZENSTACK_QUERY_SYMBOL, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZenStackQueryKind, createQuerySchemaFactory, definePlugin, getCrudDialect };
package/dist/index.js CHANGED
@@ -5327,6 +5327,27 @@ var FindOperationHandler = class extends BaseOperationHandler {
5327
5327
  static {
5328
5328
  __name(this, "FindOperationHandler");
5329
5329
  }
5330
+ buildBatchQuery(operation, args, validateArgs = true) {
5331
+ const normalizedArgs = this.normalizeArgs(args);
5332
+ const findOne = operation === "findFirst" || operation === "findUnique";
5333
+ let parsedArgs = validateArgs ? this.inputValidator.validateFindArgs(this.model, normalizedArgs, operation) : normalizedArgs;
5334
+ if (findOne) {
5335
+ parsedArgs = parsedArgs ?? {};
5336
+ parsedArgs.take = 1;
5337
+ }
5338
+ const defaultWhereArgs = this.applyDefaultWhere(this.model, parsedArgs);
5339
+ const defaultedArgs = this.applySchemaPluginDefaults(this.model, defaultWhereArgs);
5340
+ const searchExpandedArgs = this.applySearchExpansion(this.model, defaultedArgs);
5341
+ const { args: rewrittenArgs, plan } = this.rewriteVirtualRelations(this.model, searchExpandedArgs);
5342
+ return {
5343
+ query: this.buildReadQuery(this.model, rewrittenArgs),
5344
+ args: parsedArgs,
5345
+ plan
5346
+ };
5347
+ }
5348
+ applyBatchVirtualRelationPlan(data, plan) {
5349
+ return plan ? this.applyVirtualRelationPlan(data, plan) : data;
5350
+ }
5330
5351
  buildQuery(operation, args, validateArgs = true) {
5331
5352
  const normalizedArgs = this.normalizeArgs(args);
5332
5353
  const findOne = operation === "findFirst" || operation === "findUnique";
@@ -10066,20 +10087,26 @@ var ClientImpl = class _ClientImpl {
10066
10087
  return {};
10067
10088
  }
10068
10089
  const { jsonArrayFrom, jsonObjectFrom } = await import("kysely/helpers/postgres");
10090
+ const postProcessors = /* @__PURE__ */ new Map();
10069
10091
  const selections = await Promise.all(flat.map(async ([name, value]) => {
10070
- const query = await value[ZENSTACK_QUERY_SYMBOL](this);
10092
+ const built = await value[ZENSTACK_QUERY_SYMBOL](this);
10093
+ const query = built && typeof built === "object" && "query" in built ? built.query : built;
10094
+ if (built && typeof built === "object" && "postProcess" in built && typeof built.postProcess === "function") {
10095
+ postProcessors.set(name, built.postProcess);
10096
+ }
10071
10097
  const kind = value[ZENSTACK_QUERY_KIND_SYMBOL];
10072
10098
  return kind === "many" ? jsonArrayFrom(query).as(name) : jsonObjectFrom(query).as(name);
10073
10099
  }));
10074
10100
  const row = await this.$qb.selectNoFrom(selections).executeTakeFirstOrThrow();
10075
10101
  const result = {};
10076
10102
  for (const [name, value] of Object.entries(row)) {
10103
+ const processedValue = postProcessors.get(name)?.(value) ?? value;
10077
10104
  const path = name.split("__");
10078
10105
  let current = result;
10079
10106
  for (const key of path.slice(0, -1)) {
10080
10107
  current = current[key] ??= {};
10081
10108
  }
10082
- current[path[path.length - 1]] = value;
10109
+ current[path[path.length - 1]] = processedValue;
10083
10110
  }
10084
10111
  return result;
10085
10112
  });
@@ -10205,35 +10232,127 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
10205
10232
  findUnique: /* @__PURE__ */ __name((args) => {
10206
10233
  const handler = new FindOperationHandler(client, model, inputValidator);
10207
10234
  return createPromise("findUnique", "findUnique", args, handler, true, false, {
10208
- [ZENSTACK_QUERY_SYMBOL]: () => handler.buildQuery("findUnique", args),
10235
+ [ZENSTACK_QUERY_SYMBOL]: () => {
10236
+ const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has("findUnique");
10237
+ const processedArgs = shouldApplyExtResult ? prepareArgsForExtResult(args, model, schema, plugins) : args;
10238
+ const batchHandler = handler;
10239
+ const { query, args: batchArgs, plan } = batchHandler.buildBatchQuery("findUnique", processedArgs);
10240
+ return {
10241
+ query,
10242
+ postProcess: /* @__PURE__ */ __name((value) => {
10243
+ let result = value;
10244
+ if (result) {
10245
+ result = batchHandler.applyBatchVirtualRelationPlan(result, plan);
10246
+ result = resultProcessor.processResult(result, model, batchArgs);
10247
+ }
10248
+ if (result && shouldApplyExtResult) {
10249
+ result = applyExtResult(result, model, args, schema, plugins);
10250
+ }
10251
+ return result ?? null;
10252
+ }, "postProcess")
10253
+ };
10254
+ },
10209
10255
  [ZENSTACK_QUERY_KIND_SYMBOL]: "maybeOne"
10210
10256
  });
10211
10257
  }, "findUnique"),
10212
10258
  findUniqueOrThrow: /* @__PURE__ */ __name((args) => {
10213
10259
  const handler = new FindOperationHandler(client, model, inputValidator);
10214
10260
  return createPromise("findUnique", "findUniqueOrThrow", args, handler, true, true, {
10215
- [ZENSTACK_QUERY_SYMBOL]: () => handler.buildQuery("findUnique", args),
10261
+ [ZENSTACK_QUERY_SYMBOL]: () => {
10262
+ const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has("findUnique");
10263
+ const processedArgs = shouldApplyExtResult ? prepareArgsForExtResult(args, model, schema, plugins) : args;
10264
+ const batchHandler = handler;
10265
+ const { query, args: batchArgs, plan } = batchHandler.buildBatchQuery("findUnique", processedArgs);
10266
+ return {
10267
+ query,
10268
+ postProcess: /* @__PURE__ */ __name((value) => {
10269
+ if (!value) {
10270
+ throw createNotFoundError(model);
10271
+ }
10272
+ let result = batchHandler.applyBatchVirtualRelationPlan(value, plan);
10273
+ result = resultProcessor.processResult(result, model, batchArgs);
10274
+ if (shouldApplyExtResult) {
10275
+ result = applyExtResult(result, model, args, schema, plugins);
10276
+ }
10277
+ return result;
10278
+ }, "postProcess")
10279
+ };
10280
+ },
10216
10281
  [ZENSTACK_QUERY_KIND_SYMBOL]: "one"
10217
10282
  });
10218
10283
  }, "findUniqueOrThrow"),
10219
10284
  findFirst: /* @__PURE__ */ __name((args) => {
10220
10285
  const handler = new FindOperationHandler(client, model, inputValidator);
10221
10286
  return createPromise("findFirst", "findFirst", args, handler, true, false, {
10222
- [ZENSTACK_QUERY_SYMBOL]: () => handler.buildQuery("findFirst", args),
10287
+ [ZENSTACK_QUERY_SYMBOL]: () => {
10288
+ const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has("findFirst");
10289
+ const processedArgs = shouldApplyExtResult ? prepareArgsForExtResult(args, model, schema, plugins) : args;
10290
+ const batchHandler = handler;
10291
+ const { query, args: batchArgs, plan } = batchHandler.buildBatchQuery("findFirst", processedArgs);
10292
+ return {
10293
+ query,
10294
+ postProcess: /* @__PURE__ */ __name((value) => {
10295
+ let result = value;
10296
+ if (result) {
10297
+ result = batchHandler.applyBatchVirtualRelationPlan(result, plan);
10298
+ result = resultProcessor.processResult(result, model, batchArgs);
10299
+ }
10300
+ if (result && shouldApplyExtResult) {
10301
+ result = applyExtResult(result, model, args, schema, plugins);
10302
+ }
10303
+ return result ?? null;
10304
+ }, "postProcess")
10305
+ };
10306
+ },
10223
10307
  [ZENSTACK_QUERY_KIND_SYMBOL]: "maybeOne"
10224
10308
  });
10225
10309
  }, "findFirst"),
10226
10310
  findFirstOrThrow: /* @__PURE__ */ __name((args) => {
10227
10311
  const handler = new FindOperationHandler(client, model, inputValidator);
10228
10312
  return createPromise("findFirst", "findFirstOrThrow", args, handler, true, true, {
10229
- [ZENSTACK_QUERY_SYMBOL]: () => handler.buildQuery("findFirst", args),
10313
+ [ZENSTACK_QUERY_SYMBOL]: () => {
10314
+ const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has("findFirst");
10315
+ const processedArgs = shouldApplyExtResult ? prepareArgsForExtResult(args, model, schema, plugins) : args;
10316
+ const batchHandler = handler;
10317
+ const { query, args: batchArgs, plan } = batchHandler.buildBatchQuery("findFirst", processedArgs);
10318
+ return {
10319
+ query,
10320
+ postProcess: /* @__PURE__ */ __name((value) => {
10321
+ if (!value) {
10322
+ throw createNotFoundError(model);
10323
+ }
10324
+ let result = batchHandler.applyBatchVirtualRelationPlan(value, plan);
10325
+ result = resultProcessor.processResult(result, model, batchArgs);
10326
+ if (shouldApplyExtResult) {
10327
+ result = applyExtResult(result, model, args, schema, plugins);
10328
+ }
10329
+ return result;
10330
+ }, "postProcess")
10331
+ };
10332
+ },
10230
10333
  [ZENSTACK_QUERY_KIND_SYMBOL]: "one"
10231
10334
  });
10232
10335
  }, "findFirstOrThrow"),
10233
10336
  findMany: /* @__PURE__ */ __name((args) => {
10234
10337
  const handler = new FindOperationHandler(client, model, inputValidator);
10235
10338
  return createPromise("findMany", "findMany", args, handler, true, false, {
10236
- [ZENSTACK_QUERY_SYMBOL]: () => handler.buildQuery("findMany", args),
10339
+ [ZENSTACK_QUERY_SYMBOL]: () => {
10340
+ const shouldApplyExtResult = hasAnyExtResult && EXT_RESULT_OPERATIONS.has("findMany");
10341
+ const processedArgs = shouldApplyExtResult ? prepareArgsForExtResult(args, model, schema, plugins) : args;
10342
+ const batchHandler = handler;
10343
+ const { query, args: batchArgs, plan } = batchHandler.buildBatchQuery("findMany", processedArgs);
10344
+ return {
10345
+ query,
10346
+ postProcess: /* @__PURE__ */ __name((value) => {
10347
+ let result = batchHandler.applyBatchVirtualRelationPlan(value, plan);
10348
+ result = resultProcessor.processResult(result, model, batchArgs);
10349
+ if (shouldApplyExtResult) {
10350
+ result = applyExtResult(result, model, args, schema, plugins);
10351
+ }
10352
+ return result;
10353
+ }, "postProcess")
10354
+ };
10355
+ },
10237
10356
  [ZENSTACK_QUERY_KIND_SYMBOL]: "many"
10238
10357
  });
10239
10358
  }, "findMany"),