@zenstackhq/orm 3.5.3 → 3.5.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.
- package/dist/index.cjs +228 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -6
- package/dist/index.d.ts +21 -6
- package/dist/index.js +107 -20
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zenstackhq_schema from '@zenstackhq/schema';
|
|
2
|
-
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, IsDelegateModel, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
2
|
+
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, IsDelegateModel, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, GetModelDiscriminator, GetSubModels, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
4
|
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool, AliasableExpression, ExpressionWrapper } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
@@ -1103,13 +1103,26 @@ type GetAllFieldsExcludedFilterKinds<FieldsConfig> = '$all' extends keyof Fields
|
|
|
1103
1103
|
excludedFilterKinds: readonly (infer EFK)[];
|
|
1104
1104
|
} ? EFK : never : never;
|
|
1105
1105
|
|
|
1106
|
-
type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<
|
|
1107
|
-
[Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
|
|
1108
|
-
}, Optional, Array>;
|
|
1106
|
+
type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false, IsGenericModel = [string] extends [Model] ? true : false> = WrapType<IsGenericModel extends true ? FlatModelResult<Schema, Model, Omit, Options> : IsDelegateModel<Schema, Model> extends true ? DelegateUnionResult<Schema, Model, Options, GetSubModels<Schema, Model>, Omit> : FlatModelResult<Schema, Model, Omit, Options>, Optional, Array>;
|
|
1109
1107
|
type ShouldOmitField<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = QueryLevelOmit<Schema, Model, Field, Omit> extends boolean ? QueryLevelOmit<Schema, Model, Field, Omit> : OptionsLevelOmit<Schema, Model, Field, Options> extends boolean ? OptionsLevelOmit<Schema, Model, Field, Options> : SchemaLevelOmit<Schema, Model, Field>;
|
|
1110
1108
|
type QueryLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = Field extends keyof Omit ? (Omit[Field] extends boolean ? Omit[Field] : undefined) : undefined;
|
|
1111
1109
|
type OptionsLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>> = Uncapitalize<Model> extends keyof Options['omit'] ? Field extends keyof Options['omit'][Uncapitalize<Model>] ? Options['omit'][Uncapitalize<Model>][Field] extends boolean ? Options['omit'][Uncapitalize<Model>][Field] : undefined : undefined : undefined;
|
|
1112
1110
|
type SchemaLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['omit'] extends true ? true : false;
|
|
1111
|
+
type FlatModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit, Options extends QueryOptions<Schema>> = {
|
|
1112
|
+
[Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
|
|
1113
|
+
};
|
|
1114
|
+
type DelegateUnionResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, SubModel extends GetModels<Schema>, Omit = undefined, Depth extends readonly 0[] = []> = Depth['length'] extends 10 ? SubModel extends string ? FlatModelResult<Schema, SubModel, Omit, Options> & {
|
|
1115
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1116
|
+
} : never : SubModel extends string ? IsDelegateModel<Schema, SubModel> extends true ? // sub-model is itself a delegate — recurse into its own sub-models so all
|
|
1117
|
+
DelegateUnionResult<Schema, SubModel, Options, GetSubModels<Schema, SubModel>, Omit, [
|
|
1118
|
+
...Depth,
|
|
1119
|
+
0
|
|
1120
|
+
]> & {
|
|
1121
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1122
|
+
} : // leaf model — produce a flat scalar result and fix the discriminator
|
|
1123
|
+
FlatModelResult<Schema, SubModel, Omit, Options> & {
|
|
1124
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1125
|
+
} : never;
|
|
1113
1126
|
type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit, Options extends QueryOptions<Schema>, ExtResult extends ExtResultBase<Schema> = {}> = {
|
|
1114
1127
|
[Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends keyof ExtractExtResult<ExtResult, Model & string> ? never : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model, Options> ? Key : never : Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: Key extends '_count' ? SelectCountResult<Schema, Model, Select[Key]> : Key extends NonRelationFields<Schema, Model> ? MapModelFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Select[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, ExtResult> : never;
|
|
1115
1128
|
};
|
|
@@ -1418,7 +1431,7 @@ type JsonFilter<AllowedKinds extends FilterKind = FilterKind> = ('Equality' exte
|
|
|
1418
1431
|
array_ends_with?: JsonValue;
|
|
1419
1432
|
} : {});
|
|
1420
1433
|
type TypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = XOR<JsonFilter<AllowedKinds>, TypedJsonTypedFilter<Schema, TypeDefName, Array, Optional, AllowedKinds>>;
|
|
1421
|
-
type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = 'Json' extends AllowedKinds ? (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds> : NonArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds>) | (Optional extends true ? null : never) : {};
|
|
1434
|
+
type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = 'Json' extends AllowedKinds ? (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds> : NonArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds>) | (Optional extends true ? null | JsonNullValues : never) : {};
|
|
1422
1435
|
type ArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
|
|
1423
1436
|
some?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
|
|
1424
1437
|
every?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
|
|
@@ -1597,8 +1610,9 @@ type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schem
|
|
|
1597
1610
|
type ScalarCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends ScalarFields<Schema, Model, false>> = ScalarFieldMutationPayload<Schema, Model, Field> | (FieldIsArray<Schema, Model, Field> extends true ? {
|
|
1598
1611
|
set?: MapModelFieldType<Schema, Model, Field>;
|
|
1599
1612
|
} : never);
|
|
1600
|
-
type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : MapModelFieldType<Schema, Model, Field>;
|
|
1613
|
+
type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : IsTypedJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? MapModelFieldType<Schema, Model, Field> | JsonNull | DbNull : MapModelFieldType<Schema, Model, Field> : MapModelFieldType<Schema, Model, Field>;
|
|
1601
1614
|
type IsJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends 'Json' ? true : false;
|
|
1615
|
+
type IsTypedJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? true : false;
|
|
1602
1616
|
type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
|
|
1603
1617
|
[Key in ForeignKeyFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key>;
|
|
1604
1618
|
}>;
|
|
@@ -3000,6 +3014,7 @@ declare class ZodSchemaFactory<Schema extends SchemaDef, Options extends ClientO
|
|
|
3000
3014
|
private makeTypeDefSchema;
|
|
3001
3015
|
makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
|
|
3002
3016
|
private makeTypedJsonFilterSchema;
|
|
3017
|
+
private makeNullableTypedJsonMutationSchema;
|
|
3003
3018
|
private isTypeDefType;
|
|
3004
3019
|
private makeEnumFilterSchema;
|
|
3005
3020
|
private makeArrayFilterSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _zenstackhq_schema from '@zenstackhq/schema';
|
|
2
|
-
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, IsDelegateModel, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
2
|
+
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, GetModel, ProcedureDef, BuiltinType, FieldDef, ModelDef, DataSourceProviderType, IsDelegateModel, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, GetTypeDefFieldType, TypeDefFieldIsArray, GetModelDiscriminator, GetSubModels, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
4
|
import { Kysely, OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, ExpressionBuilder, Expression, KyselyConfig, OperandExpression, SelectQueryBuilder, SqlBool, AliasableExpression, ExpressionWrapper } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
@@ -1103,13 +1103,26 @@ type GetAllFieldsExcludedFilterKinds<FieldsConfig> = '$all' extends keyof Fields
|
|
|
1103
1103
|
excludedFilterKinds: readonly (infer EFK)[];
|
|
1104
1104
|
} ? EFK : never : never;
|
|
1105
1105
|
|
|
1106
|
-
type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<
|
|
1107
|
-
[Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
|
|
1108
|
-
}, Optional, Array>;
|
|
1106
|
+
type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false, IsGenericModel = [string] extends [Model] ? true : false> = WrapType<IsGenericModel extends true ? FlatModelResult<Schema, Model, Omit, Options> : IsDelegateModel<Schema, Model> extends true ? DelegateUnionResult<Schema, Model, Options, GetSubModels<Schema, Model>, Omit> : FlatModelResult<Schema, Model, Omit, Options>, Optional, Array>;
|
|
1109
1107
|
type ShouldOmitField<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = QueryLevelOmit<Schema, Model, Field, Omit> extends boolean ? QueryLevelOmit<Schema, Model, Field, Omit> : OptionsLevelOmit<Schema, Model, Field, Options> extends boolean ? OptionsLevelOmit<Schema, Model, Field, Options> : SchemaLevelOmit<Schema, Model, Field>;
|
|
1110
1108
|
type QueryLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = Field extends keyof Omit ? (Omit[Field] extends boolean ? Omit[Field] : undefined) : undefined;
|
|
1111
1109
|
type OptionsLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>> = Uncapitalize<Model> extends keyof Options['omit'] ? Field extends keyof Options['omit'][Uncapitalize<Model>] ? Options['omit'][Uncapitalize<Model>][Field] extends boolean ? Options['omit'][Uncapitalize<Model>][Field] : undefined : undefined : undefined;
|
|
1112
1110
|
type SchemaLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['omit'] extends true ? true : false;
|
|
1111
|
+
type FlatModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit, Options extends QueryOptions<Schema>> = {
|
|
1112
|
+
[Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
|
|
1113
|
+
};
|
|
1114
|
+
type DelegateUnionResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, SubModel extends GetModels<Schema>, Omit = undefined, Depth extends readonly 0[] = []> = Depth['length'] extends 10 ? SubModel extends string ? FlatModelResult<Schema, SubModel, Omit, Options> & {
|
|
1115
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1116
|
+
} : never : SubModel extends string ? IsDelegateModel<Schema, SubModel> extends true ? // sub-model is itself a delegate — recurse into its own sub-models so all
|
|
1117
|
+
DelegateUnionResult<Schema, SubModel, Options, GetSubModels<Schema, SubModel>, Omit, [
|
|
1118
|
+
...Depth,
|
|
1119
|
+
0
|
|
1120
|
+
]> & {
|
|
1121
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1122
|
+
} : // leaf model — produce a flat scalar result and fix the discriminator
|
|
1123
|
+
FlatModelResult<Schema, SubModel, Omit, Options> & {
|
|
1124
|
+
[K in GetModelDiscriminator<Schema, Model>]: SubModel;
|
|
1125
|
+
} : never;
|
|
1113
1126
|
type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit, Options extends QueryOptions<Schema>, ExtResult extends ExtResultBase<Schema> = {}> = {
|
|
1114
1127
|
[Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends keyof ExtractExtResult<ExtResult, Model & string> ? never : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model, Options> ? Key : never : Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: Key extends '_count' ? SelectCountResult<Schema, Model, Select[Key]> : Key extends NonRelationFields<Schema, Model> ? MapModelFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Select[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, ExtResult> : never;
|
|
1115
1128
|
};
|
|
@@ -1418,7 +1431,7 @@ type JsonFilter<AllowedKinds extends FilterKind = FilterKind> = ('Equality' exte
|
|
|
1418
1431
|
array_ends_with?: JsonValue;
|
|
1419
1432
|
} : {});
|
|
1420
1433
|
type TypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = XOR<JsonFilter<AllowedKinds>, TypedJsonTypedFilter<Schema, TypeDefName, Array, Optional, AllowedKinds>>;
|
|
1421
|
-
type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = 'Json' extends AllowedKinds ? (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds> : NonArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds>) | (Optional extends true ? null : never) : {};
|
|
1434
|
+
type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = 'Json' extends AllowedKinds ? (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds> : NonArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds>) | (Optional extends true ? null | JsonNullValues : never) : {};
|
|
1422
1435
|
type ArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
|
|
1423
1436
|
some?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
|
|
1424
1437
|
every?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
|
|
@@ -1597,8 +1610,9 @@ type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schem
|
|
|
1597
1610
|
type ScalarCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends ScalarFields<Schema, Model, false>> = ScalarFieldMutationPayload<Schema, Model, Field> | (FieldIsArray<Schema, Model, Field> extends true ? {
|
|
1598
1611
|
set?: MapModelFieldType<Schema, Model, Field>;
|
|
1599
1612
|
} : never);
|
|
1600
|
-
type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : MapModelFieldType<Schema, Model, Field>;
|
|
1613
|
+
type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : IsTypedJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? MapModelFieldType<Schema, Model, Field> | JsonNull | DbNull : MapModelFieldType<Schema, Model, Field> : MapModelFieldType<Schema, Model, Field>;
|
|
1601
1614
|
type IsJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends 'Json' ? true : false;
|
|
1615
|
+
type IsTypedJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? true : false;
|
|
1602
1616
|
type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
|
|
1603
1617
|
[Key in ForeignKeyFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key>;
|
|
1604
1618
|
}>;
|
|
@@ -3000,6 +3014,7 @@ declare class ZodSchemaFactory<Schema extends SchemaDef, Options extends ClientO
|
|
|
3000
3014
|
private makeTypeDefSchema;
|
|
3001
3015
|
makeWhereSchema(model: string, unique: boolean, withoutRelationFields?: boolean, withAggregations?: boolean, options?: CreateSchemaOptions): ZodType;
|
|
3002
3016
|
private makeTypedJsonFilterSchema;
|
|
3017
|
+
private makeNullableTypedJsonMutationSchema;
|
|
3003
3018
|
private isTypeDefType;
|
|
3004
3019
|
private makeEnumFilterSchema;
|
|
3005
3020
|
private makeArrayFilterSchema;
|
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ __reExport(schema_exports, schema_star);
|
|
|
82
82
|
import * as schema_star from "@zenstackhq/schema";
|
|
83
83
|
|
|
84
84
|
// src/utils/object-utils.ts
|
|
85
|
+
import { isPlainObject } from "@zenstackhq/common-helpers";
|
|
85
86
|
function extractFields(obj, fields) {
|
|
86
87
|
return Object.fromEntries(Object.entries(obj).filter(([key]) => fields.includes(key)));
|
|
87
88
|
}
|
|
@@ -93,6 +94,10 @@ function fieldsToSelectObject(fields) {
|
|
|
93
94
|
]));
|
|
94
95
|
}
|
|
95
96
|
__name(fieldsToSelectObject, "fieldsToSelectObject");
|
|
97
|
+
function isEmptyObject(x) {
|
|
98
|
+
return isPlainObject(x) && Object.keys(x).length === 0;
|
|
99
|
+
}
|
|
100
|
+
__name(isEmptyObject, "isEmptyObject");
|
|
96
101
|
|
|
97
102
|
// src/client/executor/error-processor.ts
|
|
98
103
|
function getDbErrorCode(error) {
|
|
@@ -605,7 +610,7 @@ __name(tmpAlias, "tmpAlias");
|
|
|
605
610
|
|
|
606
611
|
// src/client/crud/operations/base.ts
|
|
607
612
|
import { createId as cuid2 } from "@paralleldrive/cuid2";
|
|
608
|
-
import { clone, enumerate as enumerate2, invariant as invariant7, isPlainObject as
|
|
613
|
+
import { clone, enumerate as enumerate2, invariant as invariant7, isPlainObject as isPlainObject3 } from "@zenstackhq/common-helpers";
|
|
609
614
|
import { default as cuid1 } from "cuid";
|
|
610
615
|
import { createQueryId, expressionBuilder as expressionBuilder5, sql as sql5 } from "kysely";
|
|
611
616
|
import { nanoid } from "nanoid";
|
|
@@ -729,7 +734,7 @@ var AnyNull = new AnyNullClass();
|
|
|
729
734
|
import { invariant as invariant3 } from "@zenstackhq/common-helpers";
|
|
730
735
|
|
|
731
736
|
// src/client/crud/dialects/base-dialect.ts
|
|
732
|
-
import { enumerate, invariant as invariant2, isPlainObject, lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
737
|
+
import { enumerate, invariant as invariant2, isPlainObject as isPlainObject2, lowerCaseFirst } from "@zenstackhq/common-helpers";
|
|
733
738
|
import { expressionBuilder, sql } from "kysely";
|
|
734
739
|
import { match as match2, P } from "ts-pattern";
|
|
735
740
|
var BaseCrudDialect = class {
|
|
@@ -857,7 +862,31 @@ var BaseCrudDialect = class {
|
|
|
857
862
|
return LOGICAL_COMBINATORS.includes(key);
|
|
858
863
|
}
|
|
859
864
|
buildCompositeFilter(model, modelAlias, key, payload) {
|
|
860
|
-
|
|
865
|
+
const normalizedPayload = enumerate(payload).filter((el) => {
|
|
866
|
+
if (typeof el === "object" && el !== null && !Array.isArray(el)) {
|
|
867
|
+
const entries = Object.entries(el);
|
|
868
|
+
return entries.some(([, v]) => v !== void 0);
|
|
869
|
+
} else {
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
});
|
|
873
|
+
const normalizedFilters = normalizedPayload.map((el) => this.buildFilter(model, modelAlias, el));
|
|
874
|
+
return match2(key).with("AND", () => {
|
|
875
|
+
if (normalizedFilters.length === 0) {
|
|
876
|
+
return this.true();
|
|
877
|
+
}
|
|
878
|
+
return this.and(...normalizedFilters);
|
|
879
|
+
}).with("OR", () => {
|
|
880
|
+
if (normalizedFilters.length === 0) {
|
|
881
|
+
return this.false();
|
|
882
|
+
}
|
|
883
|
+
return this.or(...normalizedFilters);
|
|
884
|
+
}).with("NOT", () => {
|
|
885
|
+
if (normalizedFilters.length === 0) {
|
|
886
|
+
return this.true();
|
|
887
|
+
}
|
|
888
|
+
return this.not(...normalizedFilters);
|
|
889
|
+
}).exhaustive();
|
|
861
890
|
}
|
|
862
891
|
buildRelationFilter(model, modelAlias, field, fieldDef, payload) {
|
|
863
892
|
if (!fieldDef.array) {
|
|
@@ -1021,6 +1050,9 @@ var BaseCrudDialect = class {
|
|
|
1021
1050
|
return this.buildEnumFilter(fieldRef, fieldDef, payload);
|
|
1022
1051
|
}
|
|
1023
1052
|
if (isTypeDef(this.schema, fieldDef.type)) {
|
|
1053
|
+
if (payload instanceof DbNullClass || payload instanceof JsonNullClass || payload instanceof AnyNullClass) {
|
|
1054
|
+
return this.buildJsonValueFilterClause(fieldRef, payload);
|
|
1055
|
+
}
|
|
1024
1056
|
return this.buildJsonFilter(fieldRef, payload, fieldDef);
|
|
1025
1057
|
}
|
|
1026
1058
|
return match2(fieldDef.type).with("String", () => this.buildStringFilter(fieldRef, payload)).with(P.union("Int", "Float", "Decimal", "BigInt"), (type) => this.buildNumberFilter(fieldRef, type, payload)).with("Boolean", () => this.buildBooleanFilter(fieldRef, payload)).with("DateTime", () => this.buildDateTimeFilter(fieldRef, payload)).with("Bytes", () => this.buildBytesFilter(fieldRef, payload)).with("Json", () => this.buildJsonFilter(fieldRef, payload, fieldDef)).with("Unsupported", () => {
|
|
@@ -1198,7 +1230,7 @@ var BaseCrudDialect = class {
|
|
|
1198
1230
|
return this.eb(lhs, "=", this.transformInput(rhs, type, false));
|
|
1199
1231
|
}
|
|
1200
1232
|
buildStandardFilter(type, payload, lhs, getRhs, recurse, throwIfInvalid = false, onlyForKeys = void 0, excludeKeys = []) {
|
|
1201
|
-
if (payload === null || !
|
|
1233
|
+
if (payload === null || !isPlainObject2(payload)) {
|
|
1202
1234
|
return {
|
|
1203
1235
|
conditions: [
|
|
1204
1236
|
this.buildValueFilter(lhs, type, payload)
|
|
@@ -1215,6 +1247,9 @@ var BaseCrudDialect = class {
|
|
|
1215
1247
|
if (excludeKeys.includes(op)) {
|
|
1216
1248
|
continue;
|
|
1217
1249
|
}
|
|
1250
|
+
if (value === void 0) {
|
|
1251
|
+
continue;
|
|
1252
|
+
}
|
|
1218
1253
|
const rhs = Array.isArray(value) ? value.map(getRhs) : getRhs(value);
|
|
1219
1254
|
const condition = match2(op).with("equals", () => rhs === null ? this.eb(lhs, "is", null) : this.eb(lhs, "=", rhs)).with("in", () => {
|
|
1220
1255
|
invariant2(Array.isArray(rhs), "right hand side must be an array");
|
|
@@ -1272,6 +1307,9 @@ var BaseCrudDialect = class {
|
|
|
1272
1307
|
if (key === "mode" || consumedKeys.includes(key)) {
|
|
1273
1308
|
continue;
|
|
1274
1309
|
}
|
|
1310
|
+
if (value === void 0) {
|
|
1311
|
+
continue;
|
|
1312
|
+
}
|
|
1275
1313
|
invariant2(typeof value === "string", `${key} value must be a string`);
|
|
1276
1314
|
const escapedValue = this.escapeLikePattern(value);
|
|
1277
1315
|
const condition = match2(key).with("contains", () => this.buildStringLike(fieldRef, `%${escapedValue}%`, mode === "insensitive")).with("startsWith", () => this.buildStringLike(fieldRef, `${escapedValue}%`, mode === "insensitive")).with("endsWith", () => this.buildStringLike(fieldRef, `%${escapedValue}`, mode === "insensitive")).otherwise(() => {
|
|
@@ -1492,12 +1530,13 @@ var BaseCrudDialect = class {
|
|
|
1492
1530
|
const fieldDef = requireField(this.schema, model, field);
|
|
1493
1531
|
const fieldModel = fieldDef.type;
|
|
1494
1532
|
let fieldCountQuery;
|
|
1533
|
+
const subQueryAlias = tmpAlias(`${parentAlias}$_${field}$count`);
|
|
1495
1534
|
const m2m = getManyToManyRelation(this.schema, model, field);
|
|
1496
1535
|
if (m2m) {
|
|
1497
|
-
fieldCountQuery = this.buildModelSelect(fieldModel,
|
|
1536
|
+
fieldCountQuery = this.buildModelSelect(fieldModel, subQueryAlias, value, false).innerJoin(m2m.joinTable, (join) => join.onRef(`${m2m.joinTable}.${m2m.otherFkName}`, "=", `${subQueryAlias}.${m2m.otherPKName}`).onRef(`${m2m.joinTable}.${m2m.parentFkName}`, "=", `${parentAlias}.${m2m.parentPKName}`)).select(eb.fn.countAll().as(`_count$${field}`));
|
|
1498
1537
|
} else {
|
|
1499
|
-
fieldCountQuery = this.buildModelSelect(fieldModel,
|
|
1500
|
-
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field,
|
|
1538
|
+
fieldCountQuery = this.buildModelSelect(fieldModel, subQueryAlias, value, false).select(eb.fn.countAll().as(`_count$${field}`));
|
|
1539
|
+
const joinPairs = buildJoinPairs(this.schema, model, parentAlias, field, subQueryAlias);
|
|
1501
1540
|
for (const [left, right] of joinPairs) {
|
|
1502
1541
|
fieldCountQuery = fieldCountQuery.whereRef(left, "=", right);
|
|
1503
1542
|
}
|
|
@@ -2250,10 +2289,20 @@ var PostgresCrudDialect = class _PostgresCrudDialect extends LateralJoinDialectB
|
|
|
2250
2289
|
return query;
|
|
2251
2290
|
}
|
|
2252
2291
|
buildJsonObject(value) {
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2292
|
+
const entries = Object.entries(value);
|
|
2293
|
+
const MAX_PAIRS = 50;
|
|
2294
|
+
const buildChunk = /* @__PURE__ */ __name((chunk) => this.eb.fn("jsonb_build_object", chunk.flatMap(([k, v]) => [
|
|
2295
|
+
sql3.lit(k),
|
|
2296
|
+
v
|
|
2297
|
+
])), "buildChunk");
|
|
2298
|
+
if (entries.length <= MAX_PAIRS) {
|
|
2299
|
+
return buildChunk(entries);
|
|
2300
|
+
}
|
|
2301
|
+
const chunks = [];
|
|
2302
|
+
for (let i = 0; i < entries.length; i += MAX_PAIRS) {
|
|
2303
|
+
chunks.push(buildChunk(entries.slice(i, i + MAX_PAIRS)));
|
|
2304
|
+
}
|
|
2305
|
+
return chunks.reduce((acc, chunk) => sql3`${acc} || ${chunk}`);
|
|
2257
2306
|
}
|
|
2258
2307
|
castInt(expression) {
|
|
2259
2308
|
return this.eb.cast(expression, "integer");
|
|
@@ -3426,7 +3475,7 @@ var BaseOperationHandler = class {
|
|
|
3426
3475
|
throw createInvalidInputError("data must be an object");
|
|
3427
3476
|
}
|
|
3428
3477
|
const parentWhere = await this.buildUpdateParentRelationFilter(kysely, fromRelation);
|
|
3429
|
-
let combinedWhere = where ??
|
|
3478
|
+
let combinedWhere = where ?? true;
|
|
3430
3479
|
if (Object.keys(parentWhere).length > 0) {
|
|
3431
3480
|
combinedWhere = Object.keys(combinedWhere).length > 0 ? {
|
|
3432
3481
|
AND: [
|
|
@@ -3699,7 +3748,7 @@ var BaseOperationHandler = class {
|
|
|
3699
3748
|
throw createNotSupportedError("Updating with a limit is not supported for polymorphic models");
|
|
3700
3749
|
}
|
|
3701
3750
|
const parentWhere = await this.buildUpdateParentRelationFilter(kysely, fromRelation);
|
|
3702
|
-
let combinedWhere = where ??
|
|
3751
|
+
let combinedWhere = where ?? true;
|
|
3703
3752
|
if (Object.keys(parentWhere).length > 0) {
|
|
3704
3753
|
combinedWhere = Object.keys(combinedWhere).length > 0 ? {
|
|
3705
3754
|
AND: [
|
|
@@ -3891,11 +3940,11 @@ var BaseOperationHandler = class {
|
|
|
3891
3940
|
break;
|
|
3892
3941
|
}
|
|
3893
3942
|
case "delete": {
|
|
3894
|
-
await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, true);
|
|
3943
|
+
await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, true, true);
|
|
3895
3944
|
break;
|
|
3896
3945
|
}
|
|
3897
3946
|
case "deleteMany": {
|
|
3898
|
-
await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, false);
|
|
3947
|
+
await this.deleteRelation(kysely, fieldModel, value, fromRelationContext, false, false);
|
|
3899
3948
|
break;
|
|
3900
3949
|
}
|
|
3901
3950
|
default: {
|
|
@@ -3983,6 +4032,10 @@ var BaseOperationHandler = class {
|
|
|
3983
4032
|
true
|
|
3984
4033
|
];
|
|
3985
4034
|
}
|
|
4035
|
+
} else if (isEmptyObject(data)) {
|
|
4036
|
+
disconnectConditions = [
|
|
4037
|
+
true
|
|
4038
|
+
];
|
|
3986
4039
|
} else {
|
|
3987
4040
|
disconnectConditions = this.normalizeRelationManipulationInput(model, data);
|
|
3988
4041
|
if (disconnectConditions.length === 0) {
|
|
@@ -4105,9 +4158,9 @@ var BaseOperationHandler = class {
|
|
|
4105
4158
|
}
|
|
4106
4159
|
}
|
|
4107
4160
|
}
|
|
4108
|
-
async deleteRelation(kysely, model, data, fromRelation, throwForNotFound) {
|
|
4161
|
+
async deleteRelation(kysely, model, data, fromRelation, uniqueDelete, throwForNotFound) {
|
|
4109
4162
|
let deleteConditions = [];
|
|
4110
|
-
let expectedDeleteCount;
|
|
4163
|
+
let expectedDeleteCount = -1;
|
|
4111
4164
|
if (typeof data === "boolean") {
|
|
4112
4165
|
if (data === false) {
|
|
4113
4166
|
return;
|
|
@@ -4115,6 +4168,15 @@ var BaseOperationHandler = class {
|
|
|
4115
4168
|
deleteConditions = [
|
|
4116
4169
|
true
|
|
4117
4170
|
];
|
|
4171
|
+
if (uniqueDelete) {
|
|
4172
|
+
expectedDeleteCount = 1;
|
|
4173
|
+
}
|
|
4174
|
+
}
|
|
4175
|
+
} else if (isEmptyObject(data)) {
|
|
4176
|
+
deleteConditions = [
|
|
4177
|
+
true
|
|
4178
|
+
];
|
|
4179
|
+
if (uniqueDelete) {
|
|
4118
4180
|
expectedDeleteCount = 1;
|
|
4119
4181
|
}
|
|
4120
4182
|
} else {
|
|
@@ -4122,7 +4184,9 @@ var BaseOperationHandler = class {
|
|
|
4122
4184
|
if (deleteConditions.length === 0) {
|
|
4123
4185
|
return;
|
|
4124
4186
|
}
|
|
4125
|
-
|
|
4187
|
+
if (uniqueDelete) {
|
|
4188
|
+
expectedDeleteCount = deleteConditions.length;
|
|
4189
|
+
}
|
|
4126
4190
|
}
|
|
4127
4191
|
let deleteResult;
|
|
4128
4192
|
let deleteFromModel;
|
|
@@ -4182,7 +4246,7 @@ var BaseOperationHandler = class {
|
|
|
4182
4246
|
});
|
|
4183
4247
|
}
|
|
4184
4248
|
}
|
|
4185
|
-
if (throwForNotFound && expectedDeleteCount > (deleteResult.numAffectedRows ?? 0)) {
|
|
4249
|
+
if (throwForNotFound && expectedDeleteCount >= 0 && expectedDeleteCount > (deleteResult.numAffectedRows ?? 0)) {
|
|
4186
4250
|
throw createNotFoundError(deleteFromModel);
|
|
4187
4251
|
}
|
|
4188
4252
|
}
|
|
@@ -4317,7 +4381,7 @@ var BaseOperationHandler = class {
|
|
|
4317
4381
|
for (const [key, value] of Object.entries(args)) {
|
|
4318
4382
|
if (value === void 0) {
|
|
4319
4383
|
delete args[key];
|
|
4320
|
-
} else if (value &&
|
|
4384
|
+
} else if (value && isPlainObject3(value)) {
|
|
4321
4385
|
this.doNormalizeArgs(value);
|
|
4322
4386
|
}
|
|
4323
4387
|
}
|
|
@@ -5331,9 +5395,28 @@ var ZodSchemaFactory = class {
|
|
|
5331
5395
|
candidates.push(this.makeJsonFilterSchema(contextModel, field, optional));
|
|
5332
5396
|
if (optional) {
|
|
5333
5397
|
candidates.push(z.null());
|
|
5398
|
+
candidates.push(z.instanceof(DbNullClass));
|
|
5399
|
+
candidates.push(z.instanceof(JsonNullClass));
|
|
5400
|
+
candidates.push(z.instanceof(AnyNullClass));
|
|
5334
5401
|
}
|
|
5335
5402
|
return z.union(candidates);
|
|
5336
5403
|
}
|
|
5404
|
+
// For optional typed JSON fields, allow DbNull, JsonNull, and null.
|
|
5405
|
+
// z.union doesn't work here because `z.any()` (returned by `makeScalarSchema`)
|
|
5406
|
+
// always wins, so we create a wrapper superRefine instead.
|
|
5407
|
+
// The caller must pass the already-built fieldSchema so that array/list
|
|
5408
|
+
// mutation shapes (set, push, etc.) are preserved.
|
|
5409
|
+
makeNullableTypedJsonMutationSchema(fieldSchema) {
|
|
5410
|
+
return z.any().superRefine((value, ctx) => {
|
|
5411
|
+
if (value instanceof DbNullClass || value instanceof JsonNullClass || value === null || value === void 0) {
|
|
5412
|
+
return;
|
|
5413
|
+
}
|
|
5414
|
+
const parseResult = fieldSchema.safeParse(value);
|
|
5415
|
+
if (!parseResult.success) {
|
|
5416
|
+
parseResult.error.issues.forEach((issue) => ctx.addIssue(issue));
|
|
5417
|
+
}
|
|
5418
|
+
}).optional();
|
|
5419
|
+
}
|
|
5337
5420
|
isTypeDefType(type) {
|
|
5338
5421
|
return this.schema.typeDefs && type in this.schema.typeDefs;
|
|
5339
5422
|
}
|
|
@@ -5825,6 +5908,8 @@ var ZodSchemaFactory = class {
|
|
|
5825
5908
|
fieldSchema,
|
|
5826
5909
|
z.instanceof(DbNullClass)
|
|
5827
5910
|
]);
|
|
5911
|
+
} else if (this.isTypeDefType(fieldDef.type)) {
|
|
5912
|
+
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
5828
5913
|
} else {
|
|
5829
5914
|
fieldSchema = fieldSchema.nullable();
|
|
5830
5915
|
}
|
|
@@ -6061,6 +6146,8 @@ var ZodSchemaFactory = class {
|
|
|
6061
6146
|
fieldSchema,
|
|
6062
6147
|
z.instanceof(DbNullClass)
|
|
6063
6148
|
]);
|
|
6149
|
+
} else if (this.isTypeDefType(fieldDef.type)) {
|
|
6150
|
+
fieldSchema = this.makeNullableTypedJsonMutationSchema(fieldSchema);
|
|
6064
6151
|
} else {
|
|
6065
6152
|
fieldSchema = fieldSchema.nullable();
|
|
6066
6153
|
}
|