@zenstackhq/runtime 3.0.0-beta.3 → 3.0.0-beta.5

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.
@@ -9,7 +9,7 @@ type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
9
9
  type Simplify<T, D extends number = 6> = D extends 0 ? T : T extends object ? T extends _Preserve ? T : {
10
10
  [K in keyof T]: Simplify<T[K], _Depth[D]>;
11
11
  } & {} : T;
12
- type WrapType<T, Optional = false, Array = false> = Optional extends true ? T | null : Array extends true ? T[] : T;
12
+ type WrapType<T, Optional = false, Array = false> = Array extends true ? Optional extends true ? T[] | null : T[] : Optional extends true ? T | null : T;
13
13
  type TypeMap = {
14
14
  String: string;
15
15
  Boolean: boolean;
@@ -203,15 +203,12 @@ type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
203
203
  };
204
204
  type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean> = {
205
205
  select?: SelectInput<Schema, Model, AllowCount, boolean>;
206
- include?: IncludeInput<Schema, Model>;
206
+ include?: IncludeInput<Schema, Model, AllowCount>;
207
207
  omit?: OmitInput<Schema, Model>;
208
208
  };
209
209
  type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
210
210
  [Key in NonRelationFields<Schema, Model>]?: boolean;
211
- } & (AllowRelation extends true ? IncludeInput<Schema, Model> : {}) & // relation fields
212
- (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
213
- _count?: SelectCount<Schema, Model>;
214
- } : {} : {});
211
+ } & (AllowRelation extends true ? IncludeInput<Schema, Model, AllowCount> : {});
215
212
  type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = boolean | {
216
213
  select: {
217
214
  [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]?: boolean | {
@@ -219,9 +216,11 @@ type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = bo
219
216
  };
220
217
  };
221
218
  };
222
- type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
219
+ type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true> = {
223
220
  [Key in RelationFields<Schema, Model>]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : ModelFieldIsOptional<Schema, Model, Key> extends true ? true : false>;
224
- };
221
+ } & (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
222
+ _count?: SelectCount<Schema, Model>;
223
+ } : {} : {});
225
224
  type Subset<T, U> = {
226
225
  [key in keyof T]: key extends keyof U ? T[key] : never;
227
226
  };
@@ -273,7 +272,7 @@ type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> =
273
272
  } & SelectIncludeOmit<Schema, Model, true>;
274
273
  type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
275
274
  data: CreateInput<Schema, Model>;
276
- select?: SelectInput<Schema, Model, true>;
275
+ select?: SelectInput<Schema, Model>;
277
276
  include?: IncludeInput<Schema, Model>;
278
277
  omit?: OmitInput<Schema, Model>;
279
278
  };
@@ -320,7 +319,7 @@ type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Sch
320
319
  type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
321
320
  data: UpdateInput<Schema, Model>;
322
321
  where: WhereUniqueInput<Schema, Model>;
323
- select?: SelectInput<Schema, Model, true>;
322
+ select?: SelectInput<Schema, Model>;
324
323
  include?: IncludeInput<Schema, Model>;
325
324
  omit?: OmitInput<Schema, Model>;
326
325
  };
@@ -338,7 +337,7 @@ type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
338
337
  create: CreateInput<Schema, Model>;
339
338
  update: UpdateInput<Schema, Model>;
340
339
  where: WhereUniqueInput<Schema, Model>;
341
- select?: SelectInput<Schema, Model, true>;
340
+ select?: SelectInput<Schema, Model>;
342
341
  include?: IncludeInput<Schema, Model>;
343
342
  omit?: OmitInput<Schema, Model>;
344
343
  };
@@ -385,7 +384,7 @@ type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<
385
384
  } : {}), FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'connectOrCreate' | 'upsert' : never>;
386
385
  type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
387
386
  where: WhereUniqueInput<Schema, Model>;
388
- select?: SelectInput<Schema, Model, true>;
387
+ select?: SelectInput<Schema, Model>;
389
388
  include?: IncludeInput<Schema, Model>;
390
389
  omit?: OmitInput<Schema, Model>;
391
390
  };
@@ -536,6 +535,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
536
535
  protected readonly options: ClientOptions<Schema>;
537
536
  constructor(schema: Schema, options: ClientOptions<Schema>);
538
537
  transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
538
+ transformOutput(value: unknown, _type: BuiltinType): unknown;
539
539
  buildSelectModel(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
540
540
  buildFilterSortTake(model: GetModels<Schema>, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
541
541
  buildFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
@@ -567,9 +567,9 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
567
567
  false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
568
568
  isTrue(expression: Expression<SqlBool>): boolean;
569
569
  isFalse(expression: Expression<SqlBool>): boolean;
570
- protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
571
- protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
572
- protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
570
+ and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
571
+ or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
572
+ not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
573
573
  fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
574
574
  protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
575
575
  abstract get provider(): DataSourceProviderType;
@@ -609,6 +609,14 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
609
609
  * Whether the dialect support inserting with `DEFAULT` as field value.
610
610
  */
611
611
  abstract get supportInsertWithDefault(): boolean;
612
+ /**
613
+ * Gets the SQL column type for the given field definition.
614
+ */
615
+ abstract getFieldSqlType(fieldDef: FieldDef): string;
616
+ abstract getStringCasingBehavior(): {
617
+ supportsILike: boolean;
618
+ likeCaseSensitive: boolean;
619
+ };
612
620
  }
613
621
 
614
622
  type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
@@ -630,6 +638,10 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
630
638
  * Plugin description.
631
639
  */
632
640
  description?: string;
641
+ /**
642
+ * Custom function implementations.
643
+ */
644
+ functions?: Record<string, ZModelFunction<Schema>>;
633
645
  /**
634
646
  * Intercepts an ORM query.
635
647
  */
@@ -747,7 +759,6 @@ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs
747
759
  client: ClientContract<Schema>;
748
760
  };
749
761
  type OnKyselyQueryArgs<Schema extends SchemaDef> = {
750
- kysely: ToKysely<Schema>;
751
762
  schema: SchemaDef;
752
763
  client: ClientContract<Schema>;
753
764
  query: RootOperationNode;
@@ -757,8 +768,25 @@ type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryRes
757
768
  type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
758
769
 
759
770
  type ZModelFunctionContext<Schema extends SchemaDef> = {
771
+ /**
772
+ * ZenStack client instance
773
+ */
774
+ client: ClientContract<Schema>;
775
+ /**
776
+ * Database dialect
777
+ */
760
778
  dialect: BaseCrudDialect<Schema>;
779
+ /**
780
+ * The containing model name
781
+ */
761
782
  model: GetModels<Schema>;
783
+ /**
784
+ * The alias name that can be used to refer to the containing model
785
+ */
786
+ modelAlias: string;
787
+ /**
788
+ * The CRUD operation being performed
789
+ */
762
790
  operation: CRUD;
763
791
  };
764
792
  type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
@@ -782,6 +810,15 @@ type ClientOptions<Schema extends SchemaDef> = {
782
810
  * Logging configuration.
783
811
  */
784
812
  log?: KyselyConfig['log'];
813
+ /**
814
+ * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
815
+ * to `true`.
816
+ *
817
+ * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
818
+ * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
819
+ * @see https://github.com/brianc/node-postgres/issues/429
820
+ */
821
+ fixPostgresTimezone?: boolean;
785
822
  } & (HasComputedFields<Schema> extends true ? {
786
823
  /**
787
824
  * Computed field definitions.
@@ -958,6 +995,10 @@ interface ClientConstructor {
958
995
  * CRUD operations.
959
996
  */
960
997
  type CRUD = 'create' | 'read' | 'update' | 'delete';
998
+ /**
999
+ * CRUD operations.
1000
+ */
1001
+ declare const CRUD: readonly ["create", "read", "update", "delete"];
961
1002
  type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
962
1003
  /**
963
1004
  * Returns a list of entities.
@@ -1464,4 +1505,4 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1464
1505
  };
1465
1506
  type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
1466
1507
 
1467
- export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type OnKyselyQueryArgs as V, type WhereInput as W, type ZenStackPromise as Z, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };
1508
+ export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type ZModelFunction as V, type WhereInput as W, type OnKyselyQueryArgs as X, type ZenStackPromise as Z, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };
@@ -9,7 +9,7 @@ type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
9
9
  type Simplify<T, D extends number = 6> = D extends 0 ? T : T extends object ? T extends _Preserve ? T : {
10
10
  [K in keyof T]: Simplify<T[K], _Depth[D]>;
11
11
  } & {} : T;
12
- type WrapType<T, Optional = false, Array = false> = Optional extends true ? T | null : Array extends true ? T[] : T;
12
+ type WrapType<T, Optional = false, Array = false> = Array extends true ? Optional extends true ? T[] | null : T[] : Optional extends true ? T | null : T;
13
13
  type TypeMap = {
14
14
  String: string;
15
15
  Boolean: boolean;
@@ -203,15 +203,12 @@ type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
203
203
  };
204
204
  type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean> = {
205
205
  select?: SelectInput<Schema, Model, AllowCount, boolean>;
206
- include?: IncludeInput<Schema, Model>;
206
+ include?: IncludeInput<Schema, Model, AllowCount>;
207
207
  omit?: OmitInput<Schema, Model>;
208
208
  };
209
209
  type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
210
210
  [Key in NonRelationFields<Schema, Model>]?: boolean;
211
- } & (AllowRelation extends true ? IncludeInput<Schema, Model> : {}) & // relation fields
212
- (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
213
- _count?: SelectCount<Schema, Model>;
214
- } : {} : {});
211
+ } & (AllowRelation extends true ? IncludeInput<Schema, Model, AllowCount> : {});
215
212
  type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = boolean | {
216
213
  select: {
217
214
  [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]?: boolean | {
@@ -219,9 +216,11 @@ type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = bo
219
216
  };
220
217
  };
221
218
  };
222
- type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
219
+ type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true> = {
223
220
  [Key in RelationFields<Schema, Model>]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : ModelFieldIsOptional<Schema, Model, Key> extends true ? true : false>;
224
- };
221
+ } & (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
222
+ _count?: SelectCount<Schema, Model>;
223
+ } : {} : {});
225
224
  type Subset<T, U> = {
226
225
  [key in keyof T]: key extends keyof U ? T[key] : never;
227
226
  };
@@ -273,7 +272,7 @@ type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> =
273
272
  } & SelectIncludeOmit<Schema, Model, true>;
274
273
  type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
275
274
  data: CreateInput<Schema, Model>;
276
- select?: SelectInput<Schema, Model, true>;
275
+ select?: SelectInput<Schema, Model>;
277
276
  include?: IncludeInput<Schema, Model>;
278
277
  omit?: OmitInput<Schema, Model>;
279
278
  };
@@ -320,7 +319,7 @@ type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Sch
320
319
  type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
321
320
  data: UpdateInput<Schema, Model>;
322
321
  where: WhereUniqueInput<Schema, Model>;
323
- select?: SelectInput<Schema, Model, true>;
322
+ select?: SelectInput<Schema, Model>;
324
323
  include?: IncludeInput<Schema, Model>;
325
324
  omit?: OmitInput<Schema, Model>;
326
325
  };
@@ -338,7 +337,7 @@ type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
338
337
  create: CreateInput<Schema, Model>;
339
338
  update: UpdateInput<Schema, Model>;
340
339
  where: WhereUniqueInput<Schema, Model>;
341
- select?: SelectInput<Schema, Model, true>;
340
+ select?: SelectInput<Schema, Model>;
342
341
  include?: IncludeInput<Schema, Model>;
343
342
  omit?: OmitInput<Schema, Model>;
344
343
  };
@@ -385,7 +384,7 @@ type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<
385
384
  } : {}), FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'connectOrCreate' | 'upsert' : never>;
386
385
  type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
387
386
  where: WhereUniqueInput<Schema, Model>;
388
- select?: SelectInput<Schema, Model, true>;
387
+ select?: SelectInput<Schema, Model>;
389
388
  include?: IncludeInput<Schema, Model>;
390
389
  omit?: OmitInput<Schema, Model>;
391
390
  };
@@ -536,6 +535,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
536
535
  protected readonly options: ClientOptions<Schema>;
537
536
  constructor(schema: Schema, options: ClientOptions<Schema>);
538
537
  transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
538
+ transformOutput(value: unknown, _type: BuiltinType): unknown;
539
539
  buildSelectModel(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
540
540
  buildFilterSortTake(model: GetModels<Schema>, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
541
541
  buildFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
@@ -567,9 +567,9 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
567
567
  false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
568
568
  isTrue(expression: Expression<SqlBool>): boolean;
569
569
  isFalse(expression: Expression<SqlBool>): boolean;
570
- protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
571
- protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
572
- protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
570
+ and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
571
+ or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
572
+ not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
573
573
  fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
574
574
  protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
575
575
  abstract get provider(): DataSourceProviderType;
@@ -609,6 +609,14 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
609
609
  * Whether the dialect support inserting with `DEFAULT` as field value.
610
610
  */
611
611
  abstract get supportInsertWithDefault(): boolean;
612
+ /**
613
+ * Gets the SQL column type for the given field definition.
614
+ */
615
+ abstract getFieldSqlType(fieldDef: FieldDef): string;
616
+ abstract getStringCasingBehavior(): {
617
+ supportsILike: boolean;
618
+ likeCaseSensitive: boolean;
619
+ };
612
620
  }
613
621
 
614
622
  type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
@@ -630,6 +638,10 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
630
638
  * Plugin description.
631
639
  */
632
640
  description?: string;
641
+ /**
642
+ * Custom function implementations.
643
+ */
644
+ functions?: Record<string, ZModelFunction<Schema>>;
633
645
  /**
634
646
  * Intercepts an ORM query.
635
647
  */
@@ -747,7 +759,6 @@ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs
747
759
  client: ClientContract<Schema>;
748
760
  };
749
761
  type OnKyselyQueryArgs<Schema extends SchemaDef> = {
750
- kysely: ToKysely<Schema>;
751
762
  schema: SchemaDef;
752
763
  client: ClientContract<Schema>;
753
764
  query: RootOperationNode;
@@ -757,8 +768,25 @@ type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryRes
757
768
  type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
758
769
 
759
770
  type ZModelFunctionContext<Schema extends SchemaDef> = {
771
+ /**
772
+ * ZenStack client instance
773
+ */
774
+ client: ClientContract<Schema>;
775
+ /**
776
+ * Database dialect
777
+ */
760
778
  dialect: BaseCrudDialect<Schema>;
779
+ /**
780
+ * The containing model name
781
+ */
761
782
  model: GetModels<Schema>;
783
+ /**
784
+ * The alias name that can be used to refer to the containing model
785
+ */
786
+ modelAlias: string;
787
+ /**
788
+ * The CRUD operation being performed
789
+ */
762
790
  operation: CRUD;
763
791
  };
764
792
  type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
@@ -782,6 +810,15 @@ type ClientOptions<Schema extends SchemaDef> = {
782
810
  * Logging configuration.
783
811
  */
784
812
  log?: KyselyConfig['log'];
813
+ /**
814
+ * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
815
+ * to `true`.
816
+ *
817
+ * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
818
+ * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
819
+ * @see https://github.com/brianc/node-postgres/issues/429
820
+ */
821
+ fixPostgresTimezone?: boolean;
785
822
  } & (HasComputedFields<Schema> extends true ? {
786
823
  /**
787
824
  * Computed field definitions.
@@ -958,6 +995,10 @@ interface ClientConstructor {
958
995
  * CRUD operations.
959
996
  */
960
997
  type CRUD = 'create' | 'read' | 'update' | 'delete';
998
+ /**
999
+ * CRUD operations.
1000
+ */
1001
+ declare const CRUD: readonly ["create", "read", "update", "delete"];
961
1002
  type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
962
1003
  /**
963
1004
  * Returns a list of entities.
@@ -1464,4 +1505,4 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1464
1505
  };
1465
1506
  type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
1466
1507
 
1467
- export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type OnKyselyQueryArgs as V, type WhereInput as W, type ZenStackPromise as Z, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };
1508
+ export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type ZModelFunction as V, type WhereInput as W, type OnKyselyQueryArgs as X, type ZenStackPromise as Z, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };