@danielhritcu/zenstack-orm 3.5.6 → 3.5.8

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
@@ -689,6 +689,10 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
689
689
  * for request-scoped values.
690
690
  */
691
691
  where?: DefaultWhereConfig | (() => DefaultWhereConfig);
692
+ /**
693
+ * Default page size for .paginate() calls. Defaults to 20 if not set.
694
+ */
695
+ pageSize?: number;
692
696
  };
693
697
  /**
694
698
  * Kysely dialect.
@@ -1185,7 +1189,7 @@ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Optio
1185
1189
  [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: FieldFilter<Schema, Model, Key, Options, WithAggregations>;
1186
1190
  } & {
1187
1191
  $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1188
- search?: SearchPayload;
1192
+ search?: string | SearchPayload;
1189
1193
  } & {
1190
1194
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1191
1195
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
@@ -2238,6 +2242,47 @@ interface Diagnostics {
2238
2242
  slowQueries: QueryInfo[];
2239
2243
  }
2240
2244
 
2245
+ /**
2246
+ * Offset pagination result.
2247
+ */
2248
+ interface PaginatedOffset<T> {
2249
+ items: T[];
2250
+ pagination: {
2251
+ count: number;
2252
+ page: {
2253
+ size: number;
2254
+ current: number;
2255
+ next: number | null;
2256
+ prev: number | null;
2257
+ total: number;
2258
+ };
2259
+ has: {
2260
+ next: boolean;
2261
+ prev: boolean;
2262
+ };
2263
+ };
2264
+ }
2265
+ /**
2266
+ * Cursor pagination result.
2267
+ */
2268
+ interface PaginatedCursor<T> {
2269
+ items: T[];
2270
+ pagination: {
2271
+ count: number;
2272
+ page: {
2273
+ size: number;
2274
+ };
2275
+ has: {
2276
+ next: boolean;
2277
+ prev: boolean;
2278
+ };
2279
+ cursor: {
2280
+ next: string | null;
2281
+ prev: string | null;
2282
+ };
2283
+ };
2284
+ }
2285
+
2241
2286
  /**
2242
2287
  * A promise that only executes when it's awaited or .then() is called.
2243
2288
  */
@@ -2998,6 +3043,29 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2998
3043
  * }); // result: `boolean`
2999
3044
  */
3000
3045
  exists<T extends ExistsArgs<Schema, Model, Options, ExtQueryArgs>>(args?: Subset<T, ExistsArgs<Schema, Model, Options, ExtQueryArgs>>): ZenStackPromise<Schema, boolean>;
3046
+ /**
3047
+ * Returns paginated results with metadata.
3048
+ *
3049
+ * Offset mode (pass `page`):
3050
+ * ```ts
3051
+ * const result = await db.user.paginate({ page: 1, pageSize: 20 });
3052
+ * // result.items, result.pagination.page.current, result.pagination.has.next
3053
+ * ```
3054
+ *
3055
+ * Cursor mode (pass `cursor`):
3056
+ * ```ts
3057
+ * const result = await db.user.paginate({ cursor: lastId, pageSize: 20 });
3058
+ * // result.items, result.pagination.cursor.next, result.pagination.has.next
3059
+ * ```
3060
+ */
3061
+ paginate<T extends FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>(args: Omit<SelectSubset<T, FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>, 'skip' | 'take' | 'cursor'> & {
3062
+ page: number;
3063
+ pageSize?: number;
3064
+ }): ZenStackPromise<Schema, PaginatedOffset<SimplifiedPlainResult<Schema, Model, T, Options, ExtResult>>>;
3065
+ paginate<T extends FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>(args: Omit<SelectSubset<T, FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>, 'skip' | 'take' | 'cursor'> & {
3066
+ cursor: string;
3067
+ pageSize?: number;
3068
+ }): ZenStackPromise<Schema, PaginatedCursor<SimplifiedPlainResult<Schema, Model, T, Options, ExtResult>>>;
3001
3069
  };
3002
3070
  type OperationsRequiringCreate = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
3003
3071
  type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}, ExtResult extends ExtResultBase<Schema> = {}> = SliceOperations<AllModelOperations<Schema, Model, Options, ExtQueryArgs, ExtResult>, Schema, Model, Options>;
@@ -3406,4 +3474,4 @@ declare namespace schemaUtils {
3406
3474
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
3407
3475
  }
3408
3476
 
3409
- 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 PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, 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 };
3477
+ 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, 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
@@ -689,6 +689,10 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
689
689
  * for request-scoped values.
690
690
  */
691
691
  where?: DefaultWhereConfig | (() => DefaultWhereConfig);
692
+ /**
693
+ * Default page size for .paginate() calls. Defaults to 20 if not set.
694
+ */
695
+ pageSize?: number;
692
696
  };
693
697
  /**
694
698
  * Kysely dialect.
@@ -1185,7 +1189,7 @@ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Optio
1185
1189
  [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: FieldFilter<Schema, Model, Key, Options, WithAggregations>;
1186
1190
  } & {
1187
1191
  $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1188
- search?: SearchPayload;
1192
+ search?: string | SearchPayload;
1189
1193
  } & {
1190
1194
  AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1191
1195
  OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
@@ -2238,6 +2242,47 @@ interface Diagnostics {
2238
2242
  slowQueries: QueryInfo[];
2239
2243
  }
2240
2244
 
2245
+ /**
2246
+ * Offset pagination result.
2247
+ */
2248
+ interface PaginatedOffset<T> {
2249
+ items: T[];
2250
+ pagination: {
2251
+ count: number;
2252
+ page: {
2253
+ size: number;
2254
+ current: number;
2255
+ next: number | null;
2256
+ prev: number | null;
2257
+ total: number;
2258
+ };
2259
+ has: {
2260
+ next: boolean;
2261
+ prev: boolean;
2262
+ };
2263
+ };
2264
+ }
2265
+ /**
2266
+ * Cursor pagination result.
2267
+ */
2268
+ interface PaginatedCursor<T> {
2269
+ items: T[];
2270
+ pagination: {
2271
+ count: number;
2272
+ page: {
2273
+ size: number;
2274
+ };
2275
+ has: {
2276
+ next: boolean;
2277
+ prev: boolean;
2278
+ };
2279
+ cursor: {
2280
+ next: string | null;
2281
+ prev: string | null;
2282
+ };
2283
+ };
2284
+ }
2285
+
2241
2286
  /**
2242
2287
  * A promise that only executes when it's awaited or .then() is called.
2243
2288
  */
@@ -2998,6 +3043,29 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2998
3043
  * }); // result: `boolean`
2999
3044
  */
3000
3045
  exists<T extends ExistsArgs<Schema, Model, Options, ExtQueryArgs>>(args?: Subset<T, ExistsArgs<Schema, Model, Options, ExtQueryArgs>>): ZenStackPromise<Schema, boolean>;
3046
+ /**
3047
+ * Returns paginated results with metadata.
3048
+ *
3049
+ * Offset mode (pass `page`):
3050
+ * ```ts
3051
+ * const result = await db.user.paginate({ page: 1, pageSize: 20 });
3052
+ * // result.items, result.pagination.page.current, result.pagination.has.next
3053
+ * ```
3054
+ *
3055
+ * Cursor mode (pass `cursor`):
3056
+ * ```ts
3057
+ * const result = await db.user.paginate({ cursor: lastId, pageSize: 20 });
3058
+ * // result.items, result.pagination.cursor.next, result.pagination.has.next
3059
+ * ```
3060
+ */
3061
+ paginate<T extends FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>(args: Omit<SelectSubset<T, FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>, 'skip' | 'take' | 'cursor'> & {
3062
+ page: number;
3063
+ pageSize?: number;
3064
+ }): ZenStackPromise<Schema, PaginatedOffset<SimplifiedPlainResult<Schema, Model, T, Options, ExtResult>>>;
3065
+ paginate<T extends FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>(args: Omit<SelectSubset<T, FindManyArgs<Schema, Model, Options, ExtQueryArgs, ExtResult>>, 'skip' | 'take' | 'cursor'> & {
3066
+ cursor: string;
3067
+ pageSize?: number;
3068
+ }): ZenStackPromise<Schema, PaginatedCursor<SimplifiedPlainResult<Schema, Model, T, Options, ExtResult>>>;
3001
3069
  };
3002
3070
  type OperationsRequiringCreate = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
3003
3071
  type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}, ExtResult extends ExtResultBase<Schema> = {}> = SliceOperations<AllModelOperations<Schema, Model, Options, ExtQueryArgs, ExtResult>, Schema, Model, Options>;
@@ -3406,4 +3474,4 @@ declare namespace schemaUtils {
3406
3474
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
3407
3475
  }
3408
3476
 
3409
- 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 PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, 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 };
3477
+ 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, 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
@@ -2825,9 +2825,18 @@ function extractSearch(where) {
2825
2825
  let found;
2826
2826
  const cleaned = {};
2827
2827
  for (const [key, value] of Object.entries(obj)) {
2828
- if (key === "search" && isSearchPayload(value)) {
2829
- found = value;
2830
- continue;
2828
+ if (key === "search") {
2829
+ if (typeof value === "string") {
2830
+ found = {
2831
+ q: value,
2832
+ profile: "default"
2833
+ };
2834
+ continue;
2835
+ }
2836
+ if (isSearchPayload(value)) {
2837
+ found = value;
2838
+ continue;
2839
+ }
2831
2840
  }
2832
2841
  if (key === "AND" || key === "OR") {
2833
2842
  const result = extractSearch(value);
@@ -2959,9 +2968,9 @@ function expandSearch(model, where, searchDefaults, schemaModels, virtualRelatio
2959
2968
  };
2960
2969
  const profile = search2.profile ? searchDefaults?.[model]?.[search2.profile] : void 0;
2961
2970
  const fields = search2.fields ?? profile?.fields;
2962
- if (!fields) return {
2963
- where: remaining
2964
- };
2971
+ if (!fields) {
2972
+ throw new Error(`Search on "${model}" requires a "default" search profile or explicit fields.`);
2973
+ }
2965
2974
  const mode = search2.mode ?? profile?.mode ?? "contains";
2966
2975
  const strategy = search2.strategy ?? profile?.strategy ?? "all";
2967
2976
  const tokens = unique(search2.q.trim().split(/\s+/).map((t) => t.toLowerCase()).filter(Boolean));
@@ -5790,7 +5799,28 @@ var ZodSchemaFactory = class {
5790
5799
  }).optional();
5791
5800
  const searchDefaults = this.schema.plugins?.searchDefaults?.[model];
5792
5801
  if (searchDefaults) {
5793
- fields["search"] = z.any().optional();
5802
+ const searchFieldMapSchema = z.lazy(() => z.record(z.string(), z.union([
5803
+ z.literal(true),
5804
+ searchFieldMapSchema
5805
+ ])));
5806
+ const searchPayloadSchema = zLooseObject({
5807
+ q: z.string(),
5808
+ fields: searchFieldMapSchema.optional(),
5809
+ profile: z.string().optional(),
5810
+ mode: z.enum([
5811
+ "contains",
5812
+ "startsWith",
5813
+ "equals"
5814
+ ]).optional(),
5815
+ strategy: z.enum([
5816
+ "all",
5817
+ "any"
5818
+ ]).optional()
5819
+ });
5820
+ fields["search"] = z.union([
5821
+ z.string(),
5822
+ searchPayloadSchema
5823
+ ]).optional();
5794
5824
  }
5795
5825
  fields["AND"] = this.orArray(z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)), true).optional();
5796
5826
  fields["OR"] = z.lazy(() => this.makeWhereSchema(model, false, withoutRelationFields, false, options)).array().optional();
@@ -10126,7 +10156,87 @@ function createModelCrudHandler(client, model, inputValidator, resultProcessor)
10126
10156
  }, "groupBy"),
10127
10157
  exists: /* @__PURE__ */ __name((args) => {
10128
10158
  return createPromise("exists", "exists", args, new ExistsOperationHandler(client, model, inputValidator), false);
10129
- }, "exists")
10159
+ }, "exists"),
10160
+ paginate: /* @__PURE__ */ __name((args) => {
10161
+ return createZenStackPromise(async () => {
10162
+ const rawArgs = args ?? {};
10163
+ const pageSize = rawArgs["pageSize"] ?? client.$options?.default?.pageSize ?? 20;
10164
+ const page = rawArgs["page"];
10165
+ const cursorId = rawArgs["cursor"];
10166
+ const findBaseArgs = {};
10167
+ for (const [k, v] of Object.entries(rawArgs)) {
10168
+ if (k !== "page" && k !== "cursor" && k !== "pageSize") {
10169
+ findBaseArgs[k] = v;
10170
+ }
10171
+ }
10172
+ const countResult = await operations.count({
10173
+ where: findBaseArgs["where"]
10174
+ });
10175
+ let items;
10176
+ if (page !== void 0) {
10177
+ items = await operations.findMany({
10178
+ ...findBaseArgs,
10179
+ skip: (page - 1) * pageSize,
10180
+ take: pageSize
10181
+ });
10182
+ } else {
10183
+ items = await operations.findMany({
10184
+ ...findBaseArgs,
10185
+ ...cursorId ? {
10186
+ cursor: {
10187
+ id: cursorId
10188
+ },
10189
+ skip: 1
10190
+ } : {},
10191
+ take: pageSize + 1
10192
+ });
10193
+ }
10194
+ const count = countResult;
10195
+ if (page !== void 0) {
10196
+ const total = Math.ceil(count / pageSize);
10197
+ const hasNext = page < total;
10198
+ const hasPrev = page > 1;
10199
+ return {
10200
+ items,
10201
+ pagination: {
10202
+ count,
10203
+ page: {
10204
+ size: pageSize,
10205
+ current: page,
10206
+ next: hasNext ? page + 1 : null,
10207
+ prev: hasPrev ? page - 1 : null,
10208
+ total
10209
+ },
10210
+ has: {
10211
+ next: hasNext,
10212
+ prev: hasPrev
10213
+ }
10214
+ }
10215
+ };
10216
+ } else {
10217
+ const hasNext = items.length > pageSize;
10218
+ if (hasNext) items = items.slice(0, pageSize);
10219
+ const hasPrev = cursorId != null;
10220
+ return {
10221
+ items,
10222
+ pagination: {
10223
+ count,
10224
+ page: {
10225
+ size: pageSize
10226
+ },
10227
+ has: {
10228
+ next: hasNext,
10229
+ prev: hasPrev
10230
+ },
10231
+ cursor: {
10232
+ next: hasNext && items.length > 0 ? items[items.length - 1].id : null,
10233
+ prev: hasPrev && items.length > 0 ? items[0].id : null
10234
+ }
10235
+ }
10236
+ };
10237
+ }
10238
+ });
10239
+ }, "paginate")
10130
10240
  };
10131
10241
  const slicing = client.$options.slicing;
10132
10242
  if (slicing?.models) {