@zenstackhq/orm 3.9.0 → 3.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +81 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -10
- package/dist/index.d.mts +51 -10
- package/dist/index.mjs +81 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -2,7 +2,7 @@ import { AnyNull, AnyNullClass, DbNull, DbNullClass, JsonArray, JsonNull, JsonNu
|
|
|
2
2
|
import * as _$kysely from "kysely";
|
|
3
3
|
import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
|
|
4
4
|
import * as _$_zenstackhq_schema0 from "@zenstackhq/schema";
|
|
5
|
-
import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
|
|
5
|
+
import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
|
|
6
6
|
import { ZodType, z } from "zod";
|
|
7
7
|
import Decimal from "decimal.js";
|
|
8
8
|
|
|
@@ -719,7 +719,21 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
|
|
|
719
719
|
* Config for omitting fields in ORM query results.
|
|
720
720
|
*/
|
|
721
721
|
type OmitConfig<Schema extends SchemaDef> = { [Model in GetModels<Schema> as Uncapitalize<Model>]?: { [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean } };
|
|
722
|
-
|
|
722
|
+
/**
|
|
723
|
+
* Context object passed to computed field implementations.
|
|
724
|
+
*/
|
|
725
|
+
type ComputedFieldContext<Schema extends SchemaDef> = {
|
|
726
|
+
/**
|
|
727
|
+
* The alias name that can be used to refer to the containing model
|
|
728
|
+
*/
|
|
729
|
+
modelAlias: string;
|
|
730
|
+
/**
|
|
731
|
+
* The ZenStack client executing the query. Useful for reading per-client state,
|
|
732
|
+
* e.g. the auth context set via `$setAuth`.
|
|
733
|
+
*/
|
|
734
|
+
client: ClientContract<Schema>;
|
|
735
|
+
};
|
|
736
|
+
type ComputedFieldsOptions<Schema extends SchemaDef> = { [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Uncapitalize<Model> : never]: { [Field in keyof Schema['models'][Model]['computedFields']]: Schema['models'][Model]['computedFields'][Field] extends infer Func ? Func extends ((...args: infer Params) => infer R) ? (p: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ComputedFieldContext<Schema>, ...args: Params extends [any, ...infer Rest] ? Rest : []) => OperandExpression<R> : never : never } };
|
|
723
737
|
type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
|
|
724
738
|
type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
|
|
725
739
|
procedures: Record<string, ProcedureDef>;
|
|
@@ -735,11 +749,22 @@ type GetQueryOptions<T extends {
|
|
|
735
749
|
}> = T['$options'];
|
|
736
750
|
//#endregion
|
|
737
751
|
//#region src/client/crud/dialects/base-dialect.d.ts
|
|
752
|
+
/**
|
|
753
|
+
* Arguments for constructing a CRUD dialect: either the client executing the queries — schema
|
|
754
|
+
* and options are derived from it, and it's handed to computed field implementations — or a
|
|
755
|
+
* standalone schema/options pair for uses that have no client (e.g. output transformation).
|
|
756
|
+
*/
|
|
757
|
+
type CrudDialectArgs<Schema extends SchemaDef> = [client: ClientContract<Schema>] | [schema: Schema, options: ClientOptions<Schema>];
|
|
738
758
|
declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
759
|
+
protected eb: ExpressionBuilder<any, any>;
|
|
739
760
|
protected readonly schema: Schema;
|
|
740
761
|
protected readonly options: ClientOptions<Schema>;
|
|
741
|
-
|
|
742
|
-
|
|
762
|
+
/**
|
|
763
|
+
* The client executing the query. Unset only when the dialect was constructed from a
|
|
764
|
+
* standalone schema/options pair, in which case it cannot evaluate computed fields.
|
|
765
|
+
*/
|
|
766
|
+
protected readonly client: ClientContract<Schema> | undefined;
|
|
767
|
+
constructor(...args: CrudDialectArgs<Schema>);
|
|
743
768
|
/**
|
|
744
769
|
* Whether the dialect supports updating with a limit on the number of updated rows.
|
|
745
770
|
*/
|
|
@@ -831,7 +856,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
831
856
|
and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
832
857
|
or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
833
858
|
not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
834
|
-
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean, computedArgs?: unknown): any
|
|
859
|
+
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean, computedArgs?: unknown): ExpressionWrapper<any, any, any>;
|
|
835
860
|
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, any, true>): boolean;
|
|
836
861
|
/**
|
|
837
862
|
* Builds an EXISTS expression from an inner SELECT query.
|
|
@@ -3402,6 +3427,16 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
|
|
|
3402
3427
|
declare const ZenStackClient: ClientConstructor;
|
|
3403
3428
|
//#endregion
|
|
3404
3429
|
//#region src/client/crud/dialects/index.d.ts
|
|
3430
|
+
/**
|
|
3431
|
+
* Creates a CRUD dialect for the client's provider. Schema and options are taken from the
|
|
3432
|
+
* client, which is also handed to computed field implementations, so prefer this overload
|
|
3433
|
+
* whenever a client is available.
|
|
3434
|
+
*/
|
|
3435
|
+
declare function getCrudDialect<Schema extends SchemaDef>(client: ClientContract<Schema>): BaseCrudDialect<Schema>;
|
|
3436
|
+
/**
|
|
3437
|
+
* Creates a CRUD dialect from a standalone schema/options pair, for uses that have no client
|
|
3438
|
+
* (e.g. output transformation). Such a dialect cannot evaluate computed fields.
|
|
3439
|
+
*/
|
|
3405
3440
|
declare function getCrudDialect<Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): BaseCrudDialect<Schema>;
|
|
3406
3441
|
//#endregion
|
|
3407
3442
|
//#region src/client/errors.d.ts
|
|
@@ -3487,13 +3522,19 @@ declare class ORMError extends Error {
|
|
|
3487
3522
|
sqlParams?: readonly unknown[];
|
|
3488
3523
|
}
|
|
3489
3524
|
declare namespace query_utils_d_exports {
|
|
3490
|
-
export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, stripAlias, tmpAlias };
|
|
3525
|
+
export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
|
|
3491
3526
|
}
|
|
3492
3527
|
declare function hasModel(schema: SchemaDef, model: string): boolean;
|
|
3493
3528
|
declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
|
|
3494
|
-
declare function getTypeDef(schema: SchemaDef, type: string):
|
|
3529
|
+
declare function getTypeDef(schema: SchemaDef, type: string): TypeDefDef | undefined;
|
|
3530
|
+
/**
|
|
3531
|
+
* Whether any model, type def, or field in the schema carries `@@map`/`@map`. Answering it walks
|
|
3532
|
+
* every model and field, and it is asked once per query-executor construction, so the (immutable)
|
|
3533
|
+
* answer is memoized per schema alongside the other structural lookups. See issue #2773.
|
|
3534
|
+
*/
|
|
3535
|
+
declare function schemaHasMappedNames(schema: SchemaDef): boolean;
|
|
3495
3536
|
declare function requireModel(schema: SchemaDef, model: string): ModelDef;
|
|
3496
|
-
declare function requireTypeDef(schema: SchemaDef, type: string):
|
|
3537
|
+
declare function requireTypeDef(schema: SchemaDef, type: string): TypeDefDef;
|
|
3497
3538
|
declare function getField(schema: SchemaDef, model: string, field: string): FieldDef | undefined;
|
|
3498
3539
|
declare function requireField(schema: SchemaDef, modelOrType: string, field: string): FieldDef;
|
|
3499
3540
|
/**
|
|
@@ -3532,7 +3573,7 @@ declare function getUniqueFields(schema: SchemaDef, model: string): ({
|
|
|
3532
3573
|
declare function getIdValues(schema: SchemaDef, model: string, data: any): Record<string, any>;
|
|
3533
3574
|
declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstackhq_schema0.UpdatedAtInfo | undefined;
|
|
3534
3575
|
declare function isEnum(schema: SchemaDef, type: string): boolean;
|
|
3535
|
-
declare function getEnum(schema: SchemaDef, type: string):
|
|
3576
|
+
declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
|
|
3536
3577
|
declare function isTypeDef(schema: SchemaDef, type: string): boolean;
|
|
3537
3578
|
declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
|
|
3538
3579
|
declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
|
|
@@ -3627,5 +3668,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
|
|
|
3627
3668
|
};
|
|
3628
3669
|
}
|
|
3629
3670
|
//#endregion
|
|
3630
|
-
export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
3671
|
+
export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
3631
3672
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -3,7 +3,7 @@ import * as _$kysely from "kysely";
|
|
|
3
3
|
import { AddColumnNode, AddConstraintNode, AddIndexNode, AddValueNode, AggregateFunctionNode, AliasNode, AliasableExpression, AlterColumnNode, AlterTableNode, AlterTypeNode, AndNode, BinaryOperationNode, CaseNode, CastNode, CheckConstraintNode, CollateNode, ColumnDefinitionNode, ColumnNode, ColumnUpdateNode, CommonTableExpressionNameNode, CommonTableExpressionNode, CreateIndexNode, CreateSchemaNode, CreateTableNode, CreateTypeNode, CreateViewNode, DataTypeNode, DefaultInsertValueNode, DefaultValueNode, DeleteQueryNode, Dialect, DropColumnNode, DropConstraintNode, DropIndexNode, DropSchemaNode, DropTableNode, DropTypeNode, DropViewNode, ExplainNode, Expression, ExpressionBuilder, ExpressionWrapper, FetchNode, ForeignKeyConstraintNode, FromNode, FunctionNode, Generated, GeneratedNode, GroupByItemNode, GroupByNode, HavingNode, IdentifierNode, InsertQueryNode, JSONOperatorChainNode, JSONPathLegNode, JSONPathNode, JSONReferenceNode, JoinNode, Kysely, KyselyConfig, LimitNode, ListNode, MatchedNode, MergeQueryNode, ModifyColumnNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, OnNode, OperandExpression, OperationNode, OperationNodeVisitor, OperatorNode, OrActionNode, OrNode, OrderByItemNode, OrderByNode, OutputNode, OverNode, ParensNode, PartitionByItemNode, PartitionByNode, PrimaryKeyConstraintNode, PrimitiveValueListNode, QueryId, QueryResult, RawNode, ReferenceNode, ReferencesNode, RefreshMaterializedViewNode, RenameColumnNode, RenameConstraintNode, RenameValueNode, ReturningNode, RootOperationNode, SchemableIdentifierNode, SelectAllNode, SelectModifierNode, SelectQueryBuilder, SelectQueryNode, SelectionNode, SetOperationNode, SqlBool, TableNode, TopNode, TupleNode, UnaryOperationNode, UniqueConstraintNode, UnknownRow, UpdateQueryNode, UsingNode, ValueListNode, ValueNode, ValuesNode, WhenNode, WhereNode, WithNode } from "kysely";
|
|
4
4
|
import { ZodType, z as z$1 } from "zod";
|
|
5
5
|
import * as _$_zenstackhq_schema0 from "@zenstackhq/schema";
|
|
6
|
-
import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
|
|
6
|
+
import { ArrayExpression, BinaryExpression, BindingExpression, BuiltinType, CallExpression, DataSourceProviderType, EnumDef, Expression as Expression$1, FieldDef, FieldExpression, FieldHasDefault, FieldIsArray, FieldIsDelegateDiscriminator, FieldIsRelation, FieldType, ForeignKeyFields, GetEnum, GetEnums, GetModel, GetModelDelegateMapValue, GetModelDiscriminator, GetModelField, GetModelFieldType, GetModelFields, GetModels, GetSubModels, GetTypeDefField, GetTypeDefFieldType, GetTypeDefFields, GetTypeDefs, IsDelegateModel, LiteralExpression, MemberExpression, ModelDef, ModelFieldIsOptional, NonRelationFields, NullExpression, ProcedureDef, RelationFieldType, RelationFields, RelationInfo, ScalarFields, SchemaDef, ThisExpression, TypeDefDef, TypeDefFieldIsArray, TypeDefFieldIsOptional, UnaryExpression, UpdatedAtInfo } from "@zenstackhq/schema";
|
|
7
7
|
import Decimal from "decimal.js";
|
|
8
8
|
|
|
9
9
|
//#region src/utils/kysely-utils.d.ts
|
|
@@ -719,7 +719,21 @@ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
|
|
|
719
719
|
* Config for omitting fields in ORM query results.
|
|
720
720
|
*/
|
|
721
721
|
type OmitConfig<Schema extends SchemaDef> = { [Model in GetModels<Schema> as Uncapitalize<Model>]?: { [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean } };
|
|
722
|
-
|
|
722
|
+
/**
|
|
723
|
+
* Context object passed to computed field implementations.
|
|
724
|
+
*/
|
|
725
|
+
type ComputedFieldContext<Schema extends SchemaDef> = {
|
|
726
|
+
/**
|
|
727
|
+
* The alias name that can be used to refer to the containing model
|
|
728
|
+
*/
|
|
729
|
+
modelAlias: string;
|
|
730
|
+
/**
|
|
731
|
+
* The ZenStack client executing the query. Useful for reading per-client state,
|
|
732
|
+
* e.g. the auth context set via `$setAuth`.
|
|
733
|
+
*/
|
|
734
|
+
client: ClientContract<Schema>;
|
|
735
|
+
};
|
|
736
|
+
type ComputedFieldsOptions<Schema extends SchemaDef> = { [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Uncapitalize<Model> : never]: { [Field in keyof Schema['models'][Model]['computedFields']]: Schema['models'][Model]['computedFields'][Field] extends infer Func ? Func extends ((...args: infer Params) => infer R) ? (p: ExpressionBuilder<ToKyselySchema<Schema>, Model>, context: ComputedFieldContext<Schema>, ...args: Params extends [any, ...infer Rest] ? Rest : []) => OperandExpression<R> : never : never } };
|
|
723
737
|
type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
|
|
724
738
|
type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
|
|
725
739
|
procedures: Record<string, ProcedureDef>;
|
|
@@ -735,11 +749,22 @@ type GetQueryOptions<T extends {
|
|
|
735
749
|
}> = T['$options'];
|
|
736
750
|
//#endregion
|
|
737
751
|
//#region src/client/crud/dialects/base-dialect.d.ts
|
|
752
|
+
/**
|
|
753
|
+
* Arguments for constructing a CRUD dialect: either the client executing the queries — schema
|
|
754
|
+
* and options are derived from it, and it's handed to computed field implementations — or a
|
|
755
|
+
* standalone schema/options pair for uses that have no client (e.g. output transformation).
|
|
756
|
+
*/
|
|
757
|
+
type CrudDialectArgs<Schema extends SchemaDef> = [client: ClientContract<Schema>] | [schema: Schema, options: ClientOptions<Schema>];
|
|
738
758
|
declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
759
|
+
protected eb: ExpressionBuilder<any, any>;
|
|
739
760
|
protected readonly schema: Schema;
|
|
740
761
|
protected readonly options: ClientOptions<Schema>;
|
|
741
|
-
|
|
742
|
-
|
|
762
|
+
/**
|
|
763
|
+
* The client executing the query. Unset only when the dialect was constructed from a
|
|
764
|
+
* standalone schema/options pair, in which case it cannot evaluate computed fields.
|
|
765
|
+
*/
|
|
766
|
+
protected readonly client: ClientContract<Schema> | undefined;
|
|
767
|
+
constructor(...args: CrudDialectArgs<Schema>);
|
|
743
768
|
/**
|
|
744
769
|
* Whether the dialect supports updating with a limit on the number of updated rows.
|
|
745
770
|
*/
|
|
@@ -831,7 +856,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
831
856
|
and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
832
857
|
or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
833
858
|
not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
834
|
-
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean, computedArgs?: unknown): any
|
|
859
|
+
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean, computedArgs?: unknown): ExpressionWrapper<any, any, any>;
|
|
835
860
|
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, any, true>): boolean;
|
|
836
861
|
/**
|
|
837
862
|
* Builds an EXISTS expression from an inner SELECT query.
|
|
@@ -3402,6 +3427,16 @@ declare class ZodSchemaFactory<in out Schema extends SchemaDef, in out Options e
|
|
|
3402
3427
|
declare const ZenStackClient: ClientConstructor;
|
|
3403
3428
|
//#endregion
|
|
3404
3429
|
//#region src/client/crud/dialects/index.d.ts
|
|
3430
|
+
/**
|
|
3431
|
+
* Creates a CRUD dialect for the client's provider. Schema and options are taken from the
|
|
3432
|
+
* client, which is also handed to computed field implementations, so prefer this overload
|
|
3433
|
+
* whenever a client is available.
|
|
3434
|
+
*/
|
|
3435
|
+
declare function getCrudDialect<Schema extends SchemaDef>(client: ClientContract<Schema>): BaseCrudDialect<Schema>;
|
|
3436
|
+
/**
|
|
3437
|
+
* Creates a CRUD dialect from a standalone schema/options pair, for uses that have no client
|
|
3438
|
+
* (e.g. output transformation). Such a dialect cannot evaluate computed fields.
|
|
3439
|
+
*/
|
|
3405
3440
|
declare function getCrudDialect<Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): BaseCrudDialect<Schema>;
|
|
3406
3441
|
//#endregion
|
|
3407
3442
|
//#region src/client/errors.d.ts
|
|
@@ -3487,13 +3522,19 @@ declare class ORMError extends Error {
|
|
|
3487
3522
|
sqlParams?: readonly unknown[];
|
|
3488
3523
|
}
|
|
3489
3524
|
declare namespace query_utils_d_exports {
|
|
3490
|
-
export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, stripAlias, tmpAlias };
|
|
3525
|
+
export { ManyToManyJoinTableEndpoints, TEMP_ALIAS_PREFIX, aggregate, buildJoinPairs, ensureArray, extractFieldName, extractIdFields, extractModelName, fieldHasDefaultValue, flattenCompoundUniqueFilters, getDelegateDescendantModels, getDelegateDiscriminatorValue, getDiscriminatorField, getEnum, getField, getIdFields, getIdValues, getManyToManyJoinTable, getManyToManyRelation, getModel, getModelFields, getRelationForeignKeyFieldPairs, getTypeDef, getUniqueFields, hasModel, isEnum, isForeignKeyField, isInheritedField, isRelationField, isScalarField, isTypeDef, isUnsupportedField, makeDefaultOrderBy, requireField, requireIdFields, requireModel, requireTypeDef, schemaHasMappedNames, stripAlias, tmpAlias };
|
|
3491
3526
|
}
|
|
3492
3527
|
declare function hasModel(schema: SchemaDef, model: string): boolean;
|
|
3493
3528
|
declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
|
|
3494
|
-
declare function getTypeDef(schema: SchemaDef, type: string):
|
|
3529
|
+
declare function getTypeDef(schema: SchemaDef, type: string): TypeDefDef | undefined;
|
|
3530
|
+
/**
|
|
3531
|
+
* Whether any model, type def, or field in the schema carries `@@map`/`@map`. Answering it walks
|
|
3532
|
+
* every model and field, and it is asked once per query-executor construction, so the (immutable)
|
|
3533
|
+
* answer is memoized per schema alongside the other structural lookups. See issue #2773.
|
|
3534
|
+
*/
|
|
3535
|
+
declare function schemaHasMappedNames(schema: SchemaDef): boolean;
|
|
3495
3536
|
declare function requireModel(schema: SchemaDef, model: string): ModelDef;
|
|
3496
|
-
declare function requireTypeDef(schema: SchemaDef, type: string):
|
|
3537
|
+
declare function requireTypeDef(schema: SchemaDef, type: string): TypeDefDef;
|
|
3497
3538
|
declare function getField(schema: SchemaDef, model: string, field: string): FieldDef | undefined;
|
|
3498
3539
|
declare function requireField(schema: SchemaDef, modelOrType: string, field: string): FieldDef;
|
|
3499
3540
|
/**
|
|
@@ -3532,7 +3573,7 @@ declare function getUniqueFields(schema: SchemaDef, model: string): ({
|
|
|
3532
3573
|
declare function getIdValues(schema: SchemaDef, model: string, data: any): Record<string, any>;
|
|
3533
3574
|
declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | _$_zenstackhq_schema0.UpdatedAtInfo | undefined;
|
|
3534
3575
|
declare function isEnum(schema: SchemaDef, type: string): boolean;
|
|
3535
|
-
declare function getEnum(schema: SchemaDef, type: string):
|
|
3576
|
+
declare function getEnum(schema: SchemaDef, type: string): EnumDef | undefined;
|
|
3536
3577
|
declare function isTypeDef(schema: SchemaDef, type: string): boolean;
|
|
3537
3578
|
declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
|
|
3538
3579
|
declare function makeDefaultOrderBy(schema: SchemaDef, model: string): {
|
|
@@ -3627,5 +3668,5 @@ declare class MatchingExpressionVisitor extends ExpressionVisitor {
|
|
|
3627
3668
|
};
|
|
3628
3669
|
}
|
|
3629
3670
|
//#endregion
|
|
3630
|
-
export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
3671
|
+
export { AfterEntityMutationCallback, AggregateArgs, AggregateResult, AllCrudOperations, AllModelOperations, AllReadOperations, AllWriteOperations, AnyNull, AnyNullClass, AnyPlugin, AuthType, BaseCrudDialect, BatchResult, BeforeEntityMutationCallback, BooleanFilter, BytesFilter, CRUD, CRUD_EXT, CheckedCreateInput, CheckedUpdateInput, ClientConstructor, ClientContract, ClientOptions, ComputedFieldArgs, ComputedFieldContext, ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, CountArgs, CountResult, CreateArgs, CreateInput, CreateManyAndReturnArgs, CreateManyArgs, CreateManyInput, CrudArgsMap, CrudArgsType, CrudReturnMap, CrudReturnType, DateTimeFilter, DbNull, DbNullClass, DefaultModelResult, DeleteArgs, DeleteManyArgs, EntityMutationHooksDef, ExistsArgs, ExtClientMembersBase, ExtQueryArgsBase, ExtQueryArgsMarker, ExtResultBase, ExtResultInferenceArgs, ExtResultMarker, ExtResultSelectOmitFields, ExtractExtResult, FieldHasComputedArgs, FilterKind, FindArgs, FindFirstArgs, FindManyArgs, FindUniqueArgs, FtsRelevanceOrderBy, FullTextFilterPayload, FuzzyFilterPayload, FuzzyRelevanceOrderBy, GetAllIncludedOperations, GetIncludedOperations, GetProcedure, GetProcedureNames, GetProcedureParams, GetQueryOptions, GetSlicedFilterKindsForField, GetSlicedModels, GetSlicedOperations, GetSlicedProcedures, GroupByArgs, GroupByResult, HasComputedFields, HasProcedures, IncludeInput, InputValidator, JsonArray, JsonFilter, JsonNull, JsonNullClass, JsonNullValues, JsonObject, JsonValue, kysely_utils_d_exports as KyselyUtils, MapModelFieldType, ModelAllowsCreate, ModelHasRequiredUnsupportedField, ModelOperations, ModelResult, ModelSlicingOptions, NonParamComputedNonRelationFields, NullsOrder, NumberFilter, ORMError, ORMErrorReason, OmitConfig, OmitInput, OnKyselyQueryArgs, OnKyselyQueryCallback, OnProcedureHookContext, OperationsRequiringCreate, OrderBy, PluginAfterEntityMutationArgs, PluginBeforeEntityMutationArgs, ProcedureEnvelope, ProcedureFunc, ProcedureHandlerFunc, ProcedureOperations, ProceduresOptions, ProceedKyselyQueryFunction, QueryOptions, QueryRelevantOptions, query_utils_d_exports as QueryUtils, RejectedByPolicyReason, RuntimePlugin, schema_utils_d_exports as SchemaUtils, SelectAwareExtResult, SelectIncludeOmit, SelectInput, SelectSubset, SimplifiedPlainResult, SimplifiedResult, SlicingOptions, SortOrder, StringFilter, Subset, type ToKysely, TransactionClientContract, TransactionIsolationLevel, TypeDefResult, TypedJsonFilter, UncheckedCreateInput, UncheckedUpdateInput, UpdateArgs, UpdateInput, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, WhereInput, WhereUniqueInput, ZModelFunction, ZModelFunctionContext, ZenStackClient, type ZenStackPromise, type ZodSchemaFactory, createQuerySchemaFactory, definePlugin, getCrudDialect };
|
|
3631
3672
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -215,6 +215,7 @@ var query_utils_exports = /* @__PURE__ */ __exportAll({
|
|
|
215
215
|
requireIdFields: () => requireIdFields,
|
|
216
216
|
requireModel: () => requireModel,
|
|
217
217
|
requireTypeDef: () => requireTypeDef,
|
|
218
|
+
schemaHasMappedNames: () => schemaHasMappedNames,
|
|
218
219
|
stripAlias: () => stripAlias,
|
|
219
220
|
tmpAlias: () => tmpAlias
|
|
220
221
|
});
|
|
@@ -244,6 +245,22 @@ function getModel(schema, model) {
|
|
|
244
245
|
function getTypeDef(schema, type) {
|
|
245
246
|
return schema.typeDefs?.[type];
|
|
246
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Whether any model, type def, or field in the schema carries `@@map`/`@map`. Answering it walks
|
|
250
|
+
* every model and field, and it is asked once per query-executor construction, so the (immutable)
|
|
251
|
+
* answer is memoized per schema alongside the other structural lookups. See issue #2773.
|
|
252
|
+
*/
|
|
253
|
+
function schemaHasMappedNames(schema) {
|
|
254
|
+
const cache = getSchemaLookupCache(schema);
|
|
255
|
+
if (cache.hasMappedNames === void 0) {
|
|
256
|
+
const hasMapAttr = (decl) => {
|
|
257
|
+
if (decl.attributes?.some((attr) => attr.name === "@@map")) return true;
|
|
258
|
+
return Object.values(decl.fields ?? {}).some((field) => field.attributes?.some((attr) => attr.name === "@map"));
|
|
259
|
+
};
|
|
260
|
+
cache.hasMappedNames = Object.values(schema.models).some(hasMapAttr) || Object.values(schema.typeDefs ?? {}).some(hasMapAttr) || Object.values(schema.enums ?? {}).some(hasMapAttr);
|
|
261
|
+
}
|
|
262
|
+
return cache.hasMappedNames;
|
|
263
|
+
}
|
|
247
264
|
function requireModel(schema, model) {
|
|
248
265
|
const modelDef = getModel(schema, model);
|
|
249
266
|
if (!modelDef) throw createInternalError(`Model "${model}" not found in schema`, model);
|
|
@@ -635,9 +652,23 @@ const CRUD_EXT = [...CRUD, "post-update"];
|
|
|
635
652
|
//#region src/client/crud/dialects/base-dialect.ts
|
|
636
653
|
var BaseCrudDialect = class {
|
|
637
654
|
eb = expressionBuilder();
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
655
|
+
schema;
|
|
656
|
+
options;
|
|
657
|
+
/**
|
|
658
|
+
* The client executing the query. Unset only when the dialect was constructed from a
|
|
659
|
+
* standalone schema/options pair, in which case it cannot evaluate computed fields.
|
|
660
|
+
*/
|
|
661
|
+
client;
|
|
662
|
+
constructor(...args) {
|
|
663
|
+
if (args.length === 1) {
|
|
664
|
+
const [client] = args;
|
|
665
|
+
this.client = client;
|
|
666
|
+
this.schema = client.$schema;
|
|
667
|
+
this.options = client.$options;
|
|
668
|
+
} else {
|
|
669
|
+
[this.schema, this.options] = args;
|
|
670
|
+
this.client = void 0;
|
|
671
|
+
}
|
|
641
672
|
}
|
|
642
673
|
/**
|
|
643
674
|
* Transforms input value before sending to database.
|
|
@@ -1355,7 +1386,11 @@ var BaseCrudDialect = class {
|
|
|
1355
1386
|
computer = computedFields?.[lowerCaseFirst(computedModel)]?.[field] ?? computedFields?.[computedModel]?.[field];
|
|
1356
1387
|
}
|
|
1357
1388
|
if (!computer) throw createConfigError(`Computed field "${field}" implementation not provided for model "${model}"`);
|
|
1358
|
-
|
|
1389
|
+
invariant(this.client, `computed field "${field}" of model "${model}" needs a client to be evaluated`);
|
|
1390
|
+
return this.eb.parens(computer(this.eb, {
|
|
1391
|
+
modelAlias,
|
|
1392
|
+
client: this.client
|
|
1393
|
+
}, computedArgs));
|
|
1359
1394
|
}
|
|
1360
1395
|
}
|
|
1361
1396
|
canJoinWithoutNestedSelect(modelDef, payload) {
|
|
@@ -1524,9 +1559,6 @@ var LateralJoinDialectBase = class extends BaseCrudDialect {
|
|
|
1524
1559
|
//#endregion
|
|
1525
1560
|
//#region src/client/crud/dialects/mysql.ts
|
|
1526
1561
|
var MySqlCrudDialect = class extends LateralJoinDialectBase {
|
|
1527
|
-
constructor(schema, options) {
|
|
1528
|
-
super(schema, options);
|
|
1529
|
-
}
|
|
1530
1562
|
get provider() {
|
|
1531
1563
|
return "mysql";
|
|
1532
1564
|
}
|
|
@@ -1754,8 +1786,8 @@ var PostgresCrudDialect = class PostgresCrudDialect extends LateralJoinDialectBa
|
|
|
1754
1786
|
"@db.Decimal": "decimal",
|
|
1755
1787
|
"@db.Boolean": "boolean"
|
|
1756
1788
|
};
|
|
1757
|
-
constructor(
|
|
1758
|
-
super(
|
|
1789
|
+
constructor(...args) {
|
|
1790
|
+
super(...args);
|
|
1759
1791
|
this.overrideTypeParsers();
|
|
1760
1792
|
}
|
|
1761
1793
|
get provider() {
|
|
@@ -2304,8 +2336,8 @@ var SqliteCrudDialect = class extends BaseCrudDialect {
|
|
|
2304
2336
|
};
|
|
2305
2337
|
//#endregion
|
|
2306
2338
|
//#region src/client/crud/dialects/index.ts
|
|
2307
|
-
function getCrudDialect(
|
|
2308
|
-
return match(schema.provider.type).with("sqlite", () => new SqliteCrudDialect(
|
|
2339
|
+
function getCrudDialect(...args) {
|
|
2340
|
+
return match((args.length === 1 ? args[0].$schema : args[0]).provider.type).with("sqlite", () => new SqliteCrudDialect(...args)).with("postgresql", () => new PostgresCrudDialect(...args)).with("mysql", () => new MySqlCrudDialect(...args)).exhaustive();
|
|
2309
2341
|
}
|
|
2310
2342
|
//#endregion
|
|
2311
2343
|
//#region src/client/zod/cache-decorator.ts
|
|
@@ -4311,7 +4343,7 @@ var BaseOperationHandler = class {
|
|
|
4311
4343
|
this.client = client;
|
|
4312
4344
|
this.model = model;
|
|
4313
4345
|
this.inputValidator = inputValidator;
|
|
4314
|
-
this.dialect = getCrudDialect(this.
|
|
4346
|
+
this.dialect = getCrudDialect(this.client);
|
|
4315
4347
|
}
|
|
4316
4348
|
get schema() {
|
|
4317
4349
|
return this.client.$schema;
|
|
@@ -5944,7 +5976,7 @@ var QueryNameMapper = class extends OperationNodeTransformer {
|
|
|
5944
5976
|
constructor(client) {
|
|
5945
5977
|
super();
|
|
5946
5978
|
this.client = client;
|
|
5947
|
-
this.dialect = getCrudDialect(client
|
|
5979
|
+
this.dialect = getCrudDialect(client);
|
|
5948
5980
|
for (const [modelName, modelDef] of Object.entries(client.$schema.models)) {
|
|
5949
5981
|
const mappedName = this.getMappedName(modelDef);
|
|
5950
5982
|
if (mappedName) this.modelToTableMap.set(modelName, mappedName);
|
|
@@ -6407,22 +6439,22 @@ const DEFAULT_MAX_SLOW_RECORDS = 100;
|
|
|
6407
6439
|
var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExecutor {
|
|
6408
6440
|
nameMapper;
|
|
6409
6441
|
dialect;
|
|
6410
|
-
constructor(client, driver, compiler, adapter, connectionProvider, plugins = [], suppressMutationHooks = false) {
|
|
6442
|
+
constructor(client, driver, compiler, adapter, connectionProvider, plugins = [], suppressMutationHooks = false, nameMapper) {
|
|
6411
6443
|
super(compiler, adapter, connectionProvider, plugins);
|
|
6412
6444
|
this.client = client;
|
|
6413
6445
|
this.driver = driver;
|
|
6414
6446
|
this.compiler = compiler;
|
|
6415
6447
|
this.connectionProvider = connectionProvider;
|
|
6416
6448
|
this.suppressMutationHooks = suppressMutationHooks;
|
|
6417
|
-
|
|
6418
|
-
this.dialect = getCrudDialect(client.$
|
|
6449
|
+
this.nameMapper = nameMapper ?? (client.$schema.provider.type === "postgresql" || schemaHasMappedNames(client.$schema) ? new QueryNameMapper(client.$contract) : void 0);
|
|
6450
|
+
this.dialect = getCrudDialect(client.$contract);
|
|
6419
6451
|
}
|
|
6420
|
-
|
|
6421
|
-
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
return
|
|
6452
|
+
/**
|
|
6453
|
+
* The name mapper built for this executor's schema, if the schema needs one. Exposed so that
|
|
6454
|
+
* derived clients built from the same schema and options can reuse it instead of rebuilding it.
|
|
6455
|
+
*/
|
|
6456
|
+
getNameMapper() {
|
|
6457
|
+
return this.nameMapper;
|
|
6426
6458
|
}
|
|
6427
6459
|
get kysely() {
|
|
6428
6460
|
return this.client.$qb;
|
|
@@ -6469,7 +6501,7 @@ var ZenStackQueryExecutor = class ZenStackQueryExecutor extends DefaultQueryExec
|
|
|
6469
6501
|
proceed = async (query) => {
|
|
6470
6502
|
const _p = (q) => _proceed(q);
|
|
6471
6503
|
return await hook({
|
|
6472
|
-
client: this.client,
|
|
6504
|
+
client: this.client.$contract,
|
|
6473
6505
|
schema: this.client.$schema,
|
|
6474
6506
|
query,
|
|
6475
6507
|
proceed: _p
|
|
@@ -6707,7 +6739,7 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
6707
6739
|
innerExecutor.suppressMutationHooks = true;
|
|
6708
6740
|
const innerClient = this.client.withExecutor(innerExecutor);
|
|
6709
6741
|
if (inTx) innerClient.forceTransaction();
|
|
6710
|
-
return innerClient;
|
|
6742
|
+
return innerClient.$contract;
|
|
6711
6743
|
}
|
|
6712
6744
|
andNodes(condition1, condition2) {
|
|
6713
6745
|
if (condition1 && condition2) return WhereNode.create(AndNode.create(condition1, condition2));
|
|
@@ -6759,19 +6791,19 @@ In such cases, ZenStack cannot reliably determine the IDs of the mutated entitie
|
|
|
6759
6791
|
return finalResult;
|
|
6760
6792
|
}
|
|
6761
6793
|
withPlugin(plugin) {
|
|
6762
|
-
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [...this.plugins, plugin], this.suppressMutationHooks);
|
|
6794
|
+
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [...this.plugins, plugin], this.suppressMutationHooks, this.nameMapper);
|
|
6763
6795
|
}
|
|
6764
6796
|
withPlugins(plugins) {
|
|
6765
|
-
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [...this.plugins, ...plugins], this.suppressMutationHooks);
|
|
6797
|
+
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [...this.plugins, ...plugins], this.suppressMutationHooks, this.nameMapper);
|
|
6766
6798
|
}
|
|
6767
6799
|
withPluginAtFront(plugin) {
|
|
6768
|
-
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [plugin, ...this.plugins], this.suppressMutationHooks);
|
|
6800
|
+
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [plugin, ...this.plugins], this.suppressMutationHooks, this.nameMapper);
|
|
6769
6801
|
}
|
|
6770
6802
|
withoutPlugins() {
|
|
6771
|
-
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [], this.suppressMutationHooks);
|
|
6803
|
+
return new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, this.connectionProvider, [], this.suppressMutationHooks, this.nameMapper);
|
|
6772
6804
|
}
|
|
6773
6805
|
withConnectionProvider(connectionProvider) {
|
|
6774
|
-
const newExecutor = new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, connectionProvider, this.plugins, this.suppressMutationHooks);
|
|
6806
|
+
const newExecutor = new ZenStackQueryExecutor(this.client, this.driver, this.compiler, this.adapter, connectionProvider, this.plugins, this.suppressMutationHooks, this.nameMapper);
|
|
6775
6807
|
newExecutor.client = this.client.withExecutor(newExecutor);
|
|
6776
6808
|
return newExecutor;
|
|
6777
6809
|
}
|
|
@@ -7227,6 +7259,12 @@ var ResultProcessor = class {
|
|
|
7227
7259
|
//#endregion
|
|
7228
7260
|
//#region src/client/client-impl.ts
|
|
7229
7261
|
/**
|
|
7262
|
+
* Returns the name mapper held by a ZenStack executor, or undefined for a plain kysely one.
|
|
7263
|
+
*/
|
|
7264
|
+
function getExecutorNameMapper(executor) {
|
|
7265
|
+
return executor instanceof ZenStackQueryExecutor ? executor.getNameMapper() : void 0;
|
|
7266
|
+
}
|
|
7267
|
+
/**
|
|
7230
7268
|
* ZenStack ORM client.
|
|
7231
7269
|
*/
|
|
7232
7270
|
const ZenStackClient = function(schema, options) {
|
|
@@ -7254,7 +7292,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7254
7292
|
if (baseClient) {
|
|
7255
7293
|
this.kyselyProps = {
|
|
7256
7294
|
...baseClient.kyselyProps,
|
|
7257
|
-
executor: executor ?? new ZenStackQueryExecutor(this, baseClient.kyselyProps.driver, baseClient.kyselyProps.dialect.createQueryCompiler(), baseClient.kyselyProps.dialect.createAdapter(), new DefaultConnectionProvider(baseClient.kyselyProps.driver))
|
|
7295
|
+
executor: executor ?? new ZenStackQueryExecutor(this, baseClient.kyselyProps.driver, baseClient.kyselyProps.dialect.createQueryCompiler(), baseClient.kyselyProps.dialect.createAdapter(), new DefaultConnectionProvider(baseClient.kyselyProps.driver), [], false, baseClient.$schema === schema && baseClient.$options === options ? getExecutorNameMapper(baseClient.kyselyProps.executor) : void 0)
|
|
7258
7296
|
};
|
|
7259
7297
|
this.kyselyRaw = baseClient.kyselyRaw;
|
|
7260
7298
|
this.auth = baseClient.auth;
|
|
@@ -7331,14 +7369,14 @@ var ClientImpl = class ClientImpl {
|
|
|
7331
7369
|
if (!this.kysely.isTransaction) this.kysely = new Transaction(this.kyselyProps);
|
|
7332
7370
|
}
|
|
7333
7371
|
async interactiveTransaction(callback, options) {
|
|
7334
|
-
if (this.kysely.isTransaction) return callback(this);
|
|
7372
|
+
if (this.kysely.isTransaction) return callback(this.$contract);
|
|
7335
7373
|
else {
|
|
7336
7374
|
let txBuilder = this.kysely.transaction();
|
|
7337
7375
|
if (options?.isolationLevel) txBuilder = txBuilder.setIsolationLevel(options.isolationLevel);
|
|
7338
7376
|
return txBuilder.execute((tx) => {
|
|
7339
7377
|
const txClient = new ClientImpl(this.schema, this.$options, this);
|
|
7340
7378
|
txClient.kysely = tx;
|
|
7341
|
-
return callback(txClient);
|
|
7379
|
+
return callback(txClient.$contract);
|
|
7342
7380
|
});
|
|
7343
7381
|
}
|
|
7344
7382
|
}
|
|
@@ -7355,7 +7393,7 @@ var ClientImpl = class ClientImpl {
|
|
|
7355
7393
|
const result = [];
|
|
7356
7394
|
for (const promise of arg) {
|
|
7357
7395
|
const cb = this.getPromiseCallback(promise);
|
|
7358
|
-
result.push(await cb(txClient));
|
|
7396
|
+
result.push(await cb(txClient.$contract));
|
|
7359
7397
|
}
|
|
7360
7398
|
return result;
|
|
7361
7399
|
};
|
|
@@ -7456,6 +7494,16 @@ var ClientImpl = class ClientImpl {
|
|
|
7456
7494
|
get $auth() {
|
|
7457
7495
|
return this.auth;
|
|
7458
7496
|
}
|
|
7497
|
+
/**
|
|
7498
|
+
* This client viewed through its public typed contract. `ClientImpl` is intentionally
|
|
7499
|
+
* untyped internally — the model accessors are added by the runtime proxy — so this
|
|
7500
|
+
* getter is the single sanctioned bridge to `ClientContract`. The proxy invokes it
|
|
7501
|
+
* with the proxy as `this` (`Reflect.get` with receiver), so the returned reference
|
|
7502
|
+
* keeps the model accessors.
|
|
7503
|
+
*/
|
|
7504
|
+
get $contract() {
|
|
7505
|
+
return this;
|
|
7506
|
+
}
|
|
7459
7507
|
$setOptions(options) {
|
|
7460
7508
|
const newClient = new ClientImpl(this.schema, options, this);
|
|
7461
7509
|
newClient.inputValidator = new InputValidator(newClient, { enabled: newClient.$options.validateInput !== false });
|