@zenstackhq/orm 3.3.0-beta.1 → 3.3.0-beta.2
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 +78 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +58 -21
- package/dist/index.d.ts +58 -21
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, F
|
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
4
|
import { 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, Kysely, Generated, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
|
-
import { z,
|
|
6
|
+
import { z, ZodType } from 'zod';
|
|
7
7
|
|
|
8
8
|
type JsonValue = string | number | boolean | JsonObject | JsonArray;
|
|
9
9
|
type JsonObject = {
|
|
@@ -343,6 +343,10 @@ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boo
|
|
|
343
343
|
* Checks if the value is greater than or equal to the specified value.
|
|
344
344
|
*/
|
|
345
345
|
gte?: DataType;
|
|
346
|
+
/**
|
|
347
|
+
* Checks if the value is between the specified values (inclusive).
|
|
348
|
+
*/
|
|
349
|
+
between?: [start: DataType, end: DataType];
|
|
346
350
|
/**
|
|
347
351
|
* Builds a negated filter.
|
|
348
352
|
*/
|
|
@@ -1354,6 +1358,7 @@ declare class InputValidator<Schema extends SchemaDef> {
|
|
|
1354
1358
|
private setSchemaCache;
|
|
1355
1359
|
private validate;
|
|
1356
1360
|
private mergePluginArgsSchema;
|
|
1361
|
+
private getPluginExtQueryArgsSchema;
|
|
1357
1362
|
private makeFindSchema;
|
|
1358
1363
|
private makeExistsSchema;
|
|
1359
1364
|
private makeScalarSchema;
|
|
@@ -1445,6 +1450,30 @@ declare const CoreWriteOperations: readonly ["create", "createMany", "createMany
|
|
|
1445
1450
|
* List of core write operations.
|
|
1446
1451
|
*/
|
|
1447
1452
|
type CoreWriteOperations = (typeof CoreWriteOperations)[number];
|
|
1453
|
+
/**
|
|
1454
|
+
* List of core create operations.
|
|
1455
|
+
*/
|
|
1456
|
+
declare const CoreCreateOperations: readonly ["create", "createMany", "createManyAndReturn", "upsert"];
|
|
1457
|
+
/**
|
|
1458
|
+
* List of core create operations.
|
|
1459
|
+
*/
|
|
1460
|
+
type CoreCreateOperations = (typeof CoreCreateOperations)[number];
|
|
1461
|
+
/**
|
|
1462
|
+
* List of core update operations.
|
|
1463
|
+
*/
|
|
1464
|
+
declare const CoreUpdateOperations: readonly ["update", "updateMany", "updateManyAndReturn", "upsert"];
|
|
1465
|
+
/**
|
|
1466
|
+
* List of core update operations.
|
|
1467
|
+
*/
|
|
1468
|
+
type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
|
|
1469
|
+
/**
|
|
1470
|
+
* List of core delete operations.
|
|
1471
|
+
*/
|
|
1472
|
+
declare const CoreDeleteOperations: readonly ["delete", "deleteMany"];
|
|
1473
|
+
/**
|
|
1474
|
+
* List of core delete operations.
|
|
1475
|
+
*/
|
|
1476
|
+
type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
|
|
1448
1477
|
/**
|
|
1449
1478
|
* List of all CRUD operations, including 'orThrow' variants.
|
|
1450
1479
|
*/
|
|
@@ -1462,16 +1491,22 @@ declare const AllReadOperations: readonly ["findMany", "findUnique", "findFirst"
|
|
|
1462
1491
|
*/
|
|
1463
1492
|
type AllReadOperations = (typeof AllReadOperations)[number];
|
|
1464
1493
|
|
|
1494
|
+
type AllowedExtQueryArgKeys = CoreCrudOperations | '$create' | '$read' | '$update' | '$delete' | '$all';
|
|
1465
1495
|
/**
|
|
1466
1496
|
* Base shape of plugin-extended query args.
|
|
1467
1497
|
*/
|
|
1468
1498
|
type ExtQueryArgsBase = {
|
|
1469
|
-
[K in
|
|
1499
|
+
[K in AllowedExtQueryArgKeys]?: object;
|
|
1470
1500
|
};
|
|
1501
|
+
/**
|
|
1502
|
+
* Base type for plugin-extended client members (methods and properties).
|
|
1503
|
+
* Member names should start with '$' to avoid model name conflicts.
|
|
1504
|
+
*/
|
|
1505
|
+
type ExtClientMembersBase = Record<string, unknown>;
|
|
1471
1506
|
/**
|
|
1472
1507
|
* ZenStack runtime plugin.
|
|
1473
1508
|
*/
|
|
1474
|
-
interface RuntimePlugin<Schema extends SchemaDef
|
|
1509
|
+
interface RuntimePlugin<Schema extends SchemaDef, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends Record<string, unknown>> {
|
|
1475
1510
|
/**
|
|
1476
1511
|
* Plugin ID.
|
|
1477
1512
|
*/
|
|
@@ -1508,17 +1543,19 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef, _ExtQueryArgs exte
|
|
|
1508
1543
|
/**
|
|
1509
1544
|
* Extended query args configuration.
|
|
1510
1545
|
*/
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
* Callback for getting a Zod schema to validate the extended query args for the given operation.
|
|
1514
|
-
*/
|
|
1515
|
-
getValidationSchema: (operation: CoreCrudOperations) => ZodObject | undefined;
|
|
1546
|
+
queryArgs?: {
|
|
1547
|
+
[K in keyof ExtQueryArgs]: ZodType<ExtQueryArgs[K]>;
|
|
1516
1548
|
};
|
|
1549
|
+
/**
|
|
1550
|
+
* Extended client members (methods and properties).
|
|
1551
|
+
*/
|
|
1552
|
+
client?: ExtClientMembers;
|
|
1517
1553
|
}
|
|
1554
|
+
type AnyPlugin = RuntimePlugin<any, any, any>;
|
|
1518
1555
|
/**
|
|
1519
1556
|
* Defines a ZenStack runtime plugin.
|
|
1520
1557
|
*/
|
|
1521
|
-
declare function definePlugin<Schema extends SchemaDef =
|
|
1558
|
+
declare function definePlugin<Schema extends SchemaDef, const ExtQueryArgs extends ExtQueryArgsBase = {}, const ExtClientMembers extends Record<string, unknown> = {}>(plugin: RuntimePlugin<Schema, ExtQueryArgs, ExtClientMembers>): RuntimePlugin<any, ExtQueryArgs, ExtClientMembers>;
|
|
1522
1559
|
type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
|
|
1523
1560
|
type OnProcedureHookContext<Schema extends SchemaDef> = {
|
|
1524
1561
|
/**
|
|
@@ -1667,7 +1704,7 @@ type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[nu
|
|
|
1667
1704
|
/**
|
|
1668
1705
|
* Extracts extended query args for a specific operation.
|
|
1669
1706
|
*/
|
|
1670
|
-
type ExtractExtQueryArgs<ExtQueryArgs, Operation extends CoreCrudOperations> = Operation extends keyof ExtQueryArgs ?
|
|
1707
|
+
type ExtractExtQueryArgs<ExtQueryArgs, Operation extends CoreCrudOperations> = (Operation extends keyof ExtQueryArgs ? ExtQueryArgs[Operation] : {}) & ('$create' extends keyof ExtQueryArgs ? Operation extends CoreCreateOperations ? ExtQueryArgs['$create'] : {} : {}) & ('$read' extends keyof ExtQueryArgs ? (Operation extends CoreReadOperations ? ExtQueryArgs['$read'] : {}) : {}) & ('$update' extends keyof ExtQueryArgs ? Operation extends CoreUpdateOperations ? ExtQueryArgs['$update'] : {} : {}) & ('$delete' extends keyof ExtQueryArgs ? Operation extends CoreDeleteOperations ? ExtQueryArgs['$delete'] : {} : {}) & ('$all' extends keyof ExtQueryArgs ? ExtQueryArgs['$all'] : {});
|
|
1671
1708
|
/**
|
|
1672
1709
|
* Transaction isolation levels.
|
|
1673
1710
|
*/
|
|
@@ -1681,7 +1718,7 @@ declare enum TransactionIsolationLevel {
|
|
|
1681
1718
|
/**
|
|
1682
1719
|
* ZenStack client interface.
|
|
1683
1720
|
*/
|
|
1684
|
-
type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}> = {
|
|
1721
|
+
type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}, ExtClientMembers extends ExtClientMembersBase = {}> = {
|
|
1685
1722
|
/**
|
|
1686
1723
|
* The schema definition.
|
|
1687
1724
|
*/
|
|
@@ -1731,7 +1768,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1731
1768
|
/**
|
|
1732
1769
|
* Sets the current user identity.
|
|
1733
1770
|
*/
|
|
1734
|
-
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1771
|
+
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1735
1772
|
/**
|
|
1736
1773
|
* Returns a new client with new options applied.
|
|
1737
1774
|
* @example
|
|
@@ -1739,14 +1776,14 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1739
1776
|
* const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
|
|
1740
1777
|
* ```
|
|
1741
1778
|
*/
|
|
1742
|
-
$setOptions<
|
|
1779
|
+
$setOptions<NewOptions extends ClientOptions<Schema>>(options: NewOptions): ClientContract<Schema, NewOptions, ExtQueryArgs, ExtClientMembers>;
|
|
1743
1780
|
/**
|
|
1744
1781
|
* Returns a new client enabling/disabling input validations expressed with attributes like
|
|
1745
1782
|
* `@email`, `@regex`, `@@validate`, etc.
|
|
1746
1783
|
*
|
|
1747
1784
|
* @deprecated Use {@link $setOptions} instead.
|
|
1748
1785
|
*/
|
|
1749
|
-
$setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1786
|
+
$setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1750
1787
|
/**
|
|
1751
1788
|
* The Kysely query builder instance.
|
|
1752
1789
|
*/
|
|
@@ -1758,7 +1795,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1758
1795
|
/**
|
|
1759
1796
|
* Starts an interactive transaction.
|
|
1760
1797
|
*/
|
|
1761
|
-
$transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs>) => Promise<T>, options?: {
|
|
1798
|
+
$transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>) => Promise<T>, options?: {
|
|
1762
1799
|
isolationLevel?: TransactionIsolationLevel;
|
|
1763
1800
|
}): Promise<T>;
|
|
1764
1801
|
/**
|
|
@@ -1770,11 +1807,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1770
1807
|
/**
|
|
1771
1808
|
* Returns a new client with the specified plugin installed.
|
|
1772
1809
|
*/
|
|
1773
|
-
$use<PluginSchema extends SchemaDef = Schema, PluginExtQueryArgs extends ExtQueryArgsBase = {}>(plugin: RuntimePlugin<PluginSchema, PluginExtQueryArgs>): ClientContract<Schema, Options, ExtQueryArgs & PluginExtQueryArgs>;
|
|
1810
|
+
$use<PluginSchema extends SchemaDef = Schema, PluginExtQueryArgs extends ExtQueryArgsBase = {}, PluginExtClientMembers extends ExtClientMembersBase = {}>(plugin: RuntimePlugin<PluginSchema, PluginExtQueryArgs, PluginExtClientMembers>): ClientContract<Schema, Options, ExtQueryArgs & PluginExtQueryArgs, ExtClientMembers & PluginExtClientMembers>;
|
|
1774
1811
|
/**
|
|
1775
1812
|
* Returns a new client with the specified plugin removed.
|
|
1776
1813
|
*/
|
|
1777
|
-
$unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1814
|
+
$unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1778
1815
|
/**
|
|
1779
1816
|
* Returns a new client with all plugins removed.
|
|
1780
1817
|
*/
|
|
@@ -1794,11 +1831,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1794
1831
|
$pushSchema(): Promise<void>;
|
|
1795
1832
|
} & {
|
|
1796
1833
|
[Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>, ExtQueryArgs>;
|
|
1797
|
-
} & ProcedureOperations<Schema
|
|
1834
|
+
} & ProcedureOperations<Schema> & ExtClientMembers;
|
|
1798
1835
|
/**
|
|
1799
1836
|
* The contract for a client in a transaction.
|
|
1800
1837
|
*/
|
|
1801
|
-
type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs>, TransactionUnsupportedMethods>;
|
|
1838
|
+
type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends ExtClientMembersBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>, TransactionUnsupportedMethods>;
|
|
1802
1839
|
type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
|
|
1803
1840
|
/**
|
|
1804
1841
|
* Custom procedures.
|
|
@@ -2402,7 +2439,7 @@ type ClientOptions<Schema extends SchemaDef> = {
|
|
|
2402
2439
|
/**
|
|
2403
2440
|
* Plugins.
|
|
2404
2441
|
*/
|
|
2405
|
-
plugins?:
|
|
2442
|
+
plugins?: AnyPlugin[];
|
|
2406
2443
|
/**
|
|
2407
2444
|
* Logging configuration.
|
|
2408
2445
|
*/
|
|
@@ -2705,4 +2742,4 @@ declare namespace schemaUtils {
|
|
|
2705
2742
|
export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
|
|
2706
2743
|
}
|
|
2707
2744
|
|
|
2708
|
-
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCrudOperations, CoreReadOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtQueryArgsBase, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
|
|
2745
|
+
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, F
|
|
|
3
3
|
import * as kysely from 'kysely';
|
|
4
4
|
import { 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, Kysely, Generated, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
5
5
|
import Decimal from 'decimal.js';
|
|
6
|
-
import { z,
|
|
6
|
+
import { z, ZodType } from 'zod';
|
|
7
7
|
|
|
8
8
|
type JsonValue = string | number | boolean | JsonObject | JsonArray;
|
|
9
9
|
type JsonObject = {
|
|
@@ -343,6 +343,10 @@ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boo
|
|
|
343
343
|
* Checks if the value is greater than or equal to the specified value.
|
|
344
344
|
*/
|
|
345
345
|
gte?: DataType;
|
|
346
|
+
/**
|
|
347
|
+
* Checks if the value is between the specified values (inclusive).
|
|
348
|
+
*/
|
|
349
|
+
between?: [start: DataType, end: DataType];
|
|
346
350
|
/**
|
|
347
351
|
* Builds a negated filter.
|
|
348
352
|
*/
|
|
@@ -1354,6 +1358,7 @@ declare class InputValidator<Schema extends SchemaDef> {
|
|
|
1354
1358
|
private setSchemaCache;
|
|
1355
1359
|
private validate;
|
|
1356
1360
|
private mergePluginArgsSchema;
|
|
1361
|
+
private getPluginExtQueryArgsSchema;
|
|
1357
1362
|
private makeFindSchema;
|
|
1358
1363
|
private makeExistsSchema;
|
|
1359
1364
|
private makeScalarSchema;
|
|
@@ -1445,6 +1450,30 @@ declare const CoreWriteOperations: readonly ["create", "createMany", "createMany
|
|
|
1445
1450
|
* List of core write operations.
|
|
1446
1451
|
*/
|
|
1447
1452
|
type CoreWriteOperations = (typeof CoreWriteOperations)[number];
|
|
1453
|
+
/**
|
|
1454
|
+
* List of core create operations.
|
|
1455
|
+
*/
|
|
1456
|
+
declare const CoreCreateOperations: readonly ["create", "createMany", "createManyAndReturn", "upsert"];
|
|
1457
|
+
/**
|
|
1458
|
+
* List of core create operations.
|
|
1459
|
+
*/
|
|
1460
|
+
type CoreCreateOperations = (typeof CoreCreateOperations)[number];
|
|
1461
|
+
/**
|
|
1462
|
+
* List of core update operations.
|
|
1463
|
+
*/
|
|
1464
|
+
declare const CoreUpdateOperations: readonly ["update", "updateMany", "updateManyAndReturn", "upsert"];
|
|
1465
|
+
/**
|
|
1466
|
+
* List of core update operations.
|
|
1467
|
+
*/
|
|
1468
|
+
type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
|
|
1469
|
+
/**
|
|
1470
|
+
* List of core delete operations.
|
|
1471
|
+
*/
|
|
1472
|
+
declare const CoreDeleteOperations: readonly ["delete", "deleteMany"];
|
|
1473
|
+
/**
|
|
1474
|
+
* List of core delete operations.
|
|
1475
|
+
*/
|
|
1476
|
+
type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
|
|
1448
1477
|
/**
|
|
1449
1478
|
* List of all CRUD operations, including 'orThrow' variants.
|
|
1450
1479
|
*/
|
|
@@ -1462,16 +1491,22 @@ declare const AllReadOperations: readonly ["findMany", "findUnique", "findFirst"
|
|
|
1462
1491
|
*/
|
|
1463
1492
|
type AllReadOperations = (typeof AllReadOperations)[number];
|
|
1464
1493
|
|
|
1494
|
+
type AllowedExtQueryArgKeys = CoreCrudOperations | '$create' | '$read' | '$update' | '$delete' | '$all';
|
|
1465
1495
|
/**
|
|
1466
1496
|
* Base shape of plugin-extended query args.
|
|
1467
1497
|
*/
|
|
1468
1498
|
type ExtQueryArgsBase = {
|
|
1469
|
-
[K in
|
|
1499
|
+
[K in AllowedExtQueryArgKeys]?: object;
|
|
1470
1500
|
};
|
|
1501
|
+
/**
|
|
1502
|
+
* Base type for plugin-extended client members (methods and properties).
|
|
1503
|
+
* Member names should start with '$' to avoid model name conflicts.
|
|
1504
|
+
*/
|
|
1505
|
+
type ExtClientMembersBase = Record<string, unknown>;
|
|
1471
1506
|
/**
|
|
1472
1507
|
* ZenStack runtime plugin.
|
|
1473
1508
|
*/
|
|
1474
|
-
interface RuntimePlugin<Schema extends SchemaDef
|
|
1509
|
+
interface RuntimePlugin<Schema extends SchemaDef, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends Record<string, unknown>> {
|
|
1475
1510
|
/**
|
|
1476
1511
|
* Plugin ID.
|
|
1477
1512
|
*/
|
|
@@ -1508,17 +1543,19 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef, _ExtQueryArgs exte
|
|
|
1508
1543
|
/**
|
|
1509
1544
|
* Extended query args configuration.
|
|
1510
1545
|
*/
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
* Callback for getting a Zod schema to validate the extended query args for the given operation.
|
|
1514
|
-
*/
|
|
1515
|
-
getValidationSchema: (operation: CoreCrudOperations) => ZodObject | undefined;
|
|
1546
|
+
queryArgs?: {
|
|
1547
|
+
[K in keyof ExtQueryArgs]: ZodType<ExtQueryArgs[K]>;
|
|
1516
1548
|
};
|
|
1549
|
+
/**
|
|
1550
|
+
* Extended client members (methods and properties).
|
|
1551
|
+
*/
|
|
1552
|
+
client?: ExtClientMembers;
|
|
1517
1553
|
}
|
|
1554
|
+
type AnyPlugin = RuntimePlugin<any, any, any>;
|
|
1518
1555
|
/**
|
|
1519
1556
|
* Defines a ZenStack runtime plugin.
|
|
1520
1557
|
*/
|
|
1521
|
-
declare function definePlugin<Schema extends SchemaDef =
|
|
1558
|
+
declare function definePlugin<Schema extends SchemaDef, const ExtQueryArgs extends ExtQueryArgsBase = {}, const ExtClientMembers extends Record<string, unknown> = {}>(plugin: RuntimePlugin<Schema, ExtQueryArgs, ExtClientMembers>): RuntimePlugin<any, ExtQueryArgs, ExtClientMembers>;
|
|
1522
1559
|
type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
|
|
1523
1560
|
type OnProcedureHookContext<Schema extends SchemaDef> = {
|
|
1524
1561
|
/**
|
|
@@ -1667,7 +1704,7 @@ type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[nu
|
|
|
1667
1704
|
/**
|
|
1668
1705
|
* Extracts extended query args for a specific operation.
|
|
1669
1706
|
*/
|
|
1670
|
-
type ExtractExtQueryArgs<ExtQueryArgs, Operation extends CoreCrudOperations> = Operation extends keyof ExtQueryArgs ?
|
|
1707
|
+
type ExtractExtQueryArgs<ExtQueryArgs, Operation extends CoreCrudOperations> = (Operation extends keyof ExtQueryArgs ? ExtQueryArgs[Operation] : {}) & ('$create' extends keyof ExtQueryArgs ? Operation extends CoreCreateOperations ? ExtQueryArgs['$create'] : {} : {}) & ('$read' extends keyof ExtQueryArgs ? (Operation extends CoreReadOperations ? ExtQueryArgs['$read'] : {}) : {}) & ('$update' extends keyof ExtQueryArgs ? Operation extends CoreUpdateOperations ? ExtQueryArgs['$update'] : {} : {}) & ('$delete' extends keyof ExtQueryArgs ? Operation extends CoreDeleteOperations ? ExtQueryArgs['$delete'] : {} : {}) & ('$all' extends keyof ExtQueryArgs ? ExtQueryArgs['$all'] : {});
|
|
1671
1708
|
/**
|
|
1672
1709
|
* Transaction isolation levels.
|
|
1673
1710
|
*/
|
|
@@ -1681,7 +1718,7 @@ declare enum TransactionIsolationLevel {
|
|
|
1681
1718
|
/**
|
|
1682
1719
|
* ZenStack client interface.
|
|
1683
1720
|
*/
|
|
1684
|
-
type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}> = {
|
|
1721
|
+
type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}, ExtClientMembers extends ExtClientMembersBase = {}> = {
|
|
1685
1722
|
/**
|
|
1686
1723
|
* The schema definition.
|
|
1687
1724
|
*/
|
|
@@ -1731,7 +1768,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1731
1768
|
/**
|
|
1732
1769
|
* Sets the current user identity.
|
|
1733
1770
|
*/
|
|
1734
|
-
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1771
|
+
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1735
1772
|
/**
|
|
1736
1773
|
* Returns a new client with new options applied.
|
|
1737
1774
|
* @example
|
|
@@ -1739,14 +1776,14 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1739
1776
|
* const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
|
|
1740
1777
|
* ```
|
|
1741
1778
|
*/
|
|
1742
|
-
$setOptions<
|
|
1779
|
+
$setOptions<NewOptions extends ClientOptions<Schema>>(options: NewOptions): ClientContract<Schema, NewOptions, ExtQueryArgs, ExtClientMembers>;
|
|
1743
1780
|
/**
|
|
1744
1781
|
* Returns a new client enabling/disabling input validations expressed with attributes like
|
|
1745
1782
|
* `@email`, `@regex`, `@@validate`, etc.
|
|
1746
1783
|
*
|
|
1747
1784
|
* @deprecated Use {@link $setOptions} instead.
|
|
1748
1785
|
*/
|
|
1749
|
-
$setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1786
|
+
$setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1750
1787
|
/**
|
|
1751
1788
|
* The Kysely query builder instance.
|
|
1752
1789
|
*/
|
|
@@ -1758,7 +1795,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1758
1795
|
/**
|
|
1759
1796
|
* Starts an interactive transaction.
|
|
1760
1797
|
*/
|
|
1761
|
-
$transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs>) => Promise<T>, options?: {
|
|
1798
|
+
$transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>) => Promise<T>, options?: {
|
|
1762
1799
|
isolationLevel?: TransactionIsolationLevel;
|
|
1763
1800
|
}): Promise<T>;
|
|
1764
1801
|
/**
|
|
@@ -1770,11 +1807,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1770
1807
|
/**
|
|
1771
1808
|
* Returns a new client with the specified plugin installed.
|
|
1772
1809
|
*/
|
|
1773
|
-
$use<PluginSchema extends SchemaDef = Schema, PluginExtQueryArgs extends ExtQueryArgsBase = {}>(plugin: RuntimePlugin<PluginSchema, PluginExtQueryArgs>): ClientContract<Schema, Options, ExtQueryArgs & PluginExtQueryArgs>;
|
|
1810
|
+
$use<PluginSchema extends SchemaDef = Schema, PluginExtQueryArgs extends ExtQueryArgsBase = {}, PluginExtClientMembers extends ExtClientMembersBase = {}>(plugin: RuntimePlugin<PluginSchema, PluginExtQueryArgs, PluginExtClientMembers>): ClientContract<Schema, Options, ExtQueryArgs & PluginExtQueryArgs, ExtClientMembers & PluginExtClientMembers>;
|
|
1774
1811
|
/**
|
|
1775
1812
|
* Returns a new client with the specified plugin removed.
|
|
1776
1813
|
*/
|
|
1777
|
-
$unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs>;
|
|
1814
|
+
$unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>;
|
|
1778
1815
|
/**
|
|
1779
1816
|
* Returns a new client with all plugins removed.
|
|
1780
1817
|
*/
|
|
@@ -1794,11 +1831,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1794
1831
|
$pushSchema(): Promise<void>;
|
|
1795
1832
|
} & {
|
|
1796
1833
|
[Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>, ExtQueryArgs>;
|
|
1797
|
-
} & ProcedureOperations<Schema
|
|
1834
|
+
} & ProcedureOperations<Schema> & ExtClientMembers;
|
|
1798
1835
|
/**
|
|
1799
1836
|
* The contract for a client in a transaction.
|
|
1800
1837
|
*/
|
|
1801
|
-
type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs>, TransactionUnsupportedMethods>;
|
|
1838
|
+
type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends ExtClientMembersBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>, TransactionUnsupportedMethods>;
|
|
1802
1839
|
type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
|
|
1803
1840
|
/**
|
|
1804
1841
|
* Custom procedures.
|
|
@@ -2402,7 +2439,7 @@ type ClientOptions<Schema extends SchemaDef> = {
|
|
|
2402
2439
|
/**
|
|
2403
2440
|
* Plugins.
|
|
2404
2441
|
*/
|
|
2405
|
-
plugins?:
|
|
2442
|
+
plugins?: AnyPlugin[];
|
|
2406
2443
|
/**
|
|
2407
2444
|
* Logging configuration.
|
|
2408
2445
|
*/
|
|
@@ -2705,4 +2742,4 @@ declare namespace schemaUtils {
|
|
|
2705
2742
|
export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
|
|
2706
2743
|
}
|
|
2707
2744
|
|
|
2708
|
-
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCrudOperations, CoreReadOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtQueryArgsBase, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
|
|
2745
|
+
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtClientMembersBase, type ExtQueryArgsBase, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
|
package/dist/index.js
CHANGED
|
@@ -1122,7 +1122,15 @@ var BaseCrudDialect = class {
|
|
|
1122
1122
|
} else {
|
|
1123
1123
|
return this.eb.not(this.eb(lhs, "in", rhs));
|
|
1124
1124
|
}
|
|
1125
|
-
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("
|
|
1125
|
+
}).with("lt", () => this.eb(lhs, "<", rhs)).with("lte", () => this.eb(lhs, "<=", rhs)).with("gt", () => this.eb(lhs, ">", rhs)).with("gte", () => this.eb(lhs, ">=", rhs)).with("between", () => {
|
|
1126
|
+
invariant2(Array.isArray(rhs), "right hand side must be an array");
|
|
1127
|
+
invariant2(rhs.length === 2, "right hand side must have a length of 2");
|
|
1128
|
+
const [start, end] = rhs;
|
|
1129
|
+
return this.eb.and([
|
|
1130
|
+
this.eb(lhs, ">=", start),
|
|
1131
|
+
this.eb(lhs, "<=", end)
|
|
1132
|
+
]);
|
|
1133
|
+
}).with("not", () => this.eb.not(recurse(value))).with(P.union(...AGGREGATE_OPERATORS), (op2) => {
|
|
1126
1134
|
const innerResult = this.buildStandardFilter(type, value, aggregate(this.eb, lhs, op2), getRhs, recurse, throwIfInvalid);
|
|
1127
1135
|
consumedKeys.push(...innerResult.consumedKeys);
|
|
1128
1136
|
return this.and(...innerResult.conditions);
|
|
@@ -2108,6 +2116,22 @@ var CoreWriteOperations = [
|
|
|
2108
2116
|
"delete",
|
|
2109
2117
|
"deleteMany"
|
|
2110
2118
|
];
|
|
2119
|
+
var CoreCreateOperations = [
|
|
2120
|
+
"create",
|
|
2121
|
+
"createMany",
|
|
2122
|
+
"createManyAndReturn",
|
|
2123
|
+
"upsert"
|
|
2124
|
+
];
|
|
2125
|
+
var CoreUpdateOperations = [
|
|
2126
|
+
"update",
|
|
2127
|
+
"updateMany",
|
|
2128
|
+
"updateManyAndReturn",
|
|
2129
|
+
"upsert"
|
|
2130
|
+
];
|
|
2131
|
+
var CoreDeleteOperations = [
|
|
2132
|
+
"delete",
|
|
2133
|
+
"deleteMany"
|
|
2134
|
+
];
|
|
2111
2135
|
var AllCrudOperations = [
|
|
2112
2136
|
...CoreCrudOperations,
|
|
2113
2137
|
"findUniqueOrThrow",
|
|
@@ -4572,8 +4596,8 @@ var InputValidator = class {
|
|
|
4572
4596
|
mergePluginArgsSchema(schema, operation) {
|
|
4573
4597
|
let result = schema;
|
|
4574
4598
|
for (const plugin of this.options.plugins ?? []) {
|
|
4575
|
-
if (plugin.
|
|
4576
|
-
const pluginSchema =
|
|
4599
|
+
if (plugin.queryArgs) {
|
|
4600
|
+
const pluginSchema = this.getPluginExtQueryArgsSchema(plugin, operation);
|
|
4577
4601
|
if (pluginSchema) {
|
|
4578
4602
|
result = result.extend(pluginSchema.shape);
|
|
4579
4603
|
}
|
|
@@ -4581,6 +4605,42 @@ var InputValidator = class {
|
|
|
4581
4605
|
}
|
|
4582
4606
|
return result.strict();
|
|
4583
4607
|
}
|
|
4608
|
+
getPluginExtQueryArgsSchema(plugin, operation) {
|
|
4609
|
+
if (!plugin.queryArgs) {
|
|
4610
|
+
return void 0;
|
|
4611
|
+
}
|
|
4612
|
+
let result;
|
|
4613
|
+
if (operation in plugin.queryArgs && plugin.queryArgs[operation]) {
|
|
4614
|
+
result = plugin.queryArgs[operation];
|
|
4615
|
+
} else if (operation === "upsert") {
|
|
4616
|
+
const createSchema = "$create" in plugin.queryArgs && plugin.queryArgs["$create"] ? plugin.queryArgs["$create"] : void 0;
|
|
4617
|
+
const updateSchema = "$update" in plugin.queryArgs && plugin.queryArgs["$update"] ? plugin.queryArgs["$update"] : void 0;
|
|
4618
|
+
if (createSchema && updateSchema) {
|
|
4619
|
+
invariant7(createSchema instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4620
|
+
invariant7(updateSchema instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4621
|
+
result = createSchema.extend(updateSchema.shape);
|
|
4622
|
+
} else if (createSchema) {
|
|
4623
|
+
result = createSchema;
|
|
4624
|
+
} else if (updateSchema) {
|
|
4625
|
+
result = updateSchema;
|
|
4626
|
+
}
|
|
4627
|
+
} else if (
|
|
4628
|
+
// then comes grouped operations: $create, $read, $update, $delete
|
|
4629
|
+
CoreCreateOperations.includes(operation) && "$create" in plugin.queryArgs && plugin.queryArgs["$create"]
|
|
4630
|
+
) {
|
|
4631
|
+
result = plugin.queryArgs["$create"];
|
|
4632
|
+
} else if (CoreReadOperations.includes(operation) && "$read" in plugin.queryArgs && plugin.queryArgs["$read"]) {
|
|
4633
|
+
result = plugin.queryArgs["$read"];
|
|
4634
|
+
} else if (CoreUpdateOperations.includes(operation) && "$update" in plugin.queryArgs && plugin.queryArgs["$update"]) {
|
|
4635
|
+
result = plugin.queryArgs["$update"];
|
|
4636
|
+
} else if (CoreDeleteOperations.includes(operation) && "$delete" in plugin.queryArgs && plugin.queryArgs["$delete"]) {
|
|
4637
|
+
result = plugin.queryArgs["$delete"];
|
|
4638
|
+
} else if ("$all" in plugin.queryArgs && plugin.queryArgs["$all"]) {
|
|
4639
|
+
result = plugin.queryArgs["$all"];
|
|
4640
|
+
}
|
|
4641
|
+
invariant7(result === void 0 || result instanceof z3.ZodObject, "Plugin extended query args schema must be a Zod object");
|
|
4642
|
+
return result;
|
|
4643
|
+
}
|
|
4584
4644
|
// #region Find
|
|
4585
4645
|
makeFindSchema(model, operation) {
|
|
4586
4646
|
const fields = {};
|
|
@@ -4965,6 +5025,7 @@ var InputValidator = class {
|
|
|
4965
5025
|
lte: baseSchema.optional(),
|
|
4966
5026
|
gt: baseSchema.optional(),
|
|
4967
5027
|
gte: baseSchema.optional(),
|
|
5028
|
+
between: baseSchema.array().length(2).optional(),
|
|
4968
5029
|
not: makeThis().optional(),
|
|
4969
5030
|
...withAggregations?.includes("_count") ? {
|
|
4970
5031
|
_count: this.makeNumberFilterSchema(z3.number().int(), false, false).optional()
|
|
@@ -7577,6 +7638,14 @@ function createClientProxy(client) {
|
|
|
7577
7638
|
return new Proxy(client, {
|
|
7578
7639
|
get: /* @__PURE__ */ __name((target, prop, receiver) => {
|
|
7579
7640
|
if (typeof prop === "string" && prop.startsWith("$")) {
|
|
7641
|
+
const plugins = target.$options.plugins ?? [];
|
|
7642
|
+
for (let i = plugins.length - 1; i >= 0; i--) {
|
|
7643
|
+
const plugin = plugins[i];
|
|
7644
|
+
const clientMembers = plugin?.client;
|
|
7645
|
+
if (clientMembers && prop in clientMembers) {
|
|
7646
|
+
return clientMembers[prop];
|
|
7647
|
+
}
|
|
7648
|
+
}
|
|
7580
7649
|
return Reflect.get(target, prop, receiver);
|
|
7581
7650
|
}
|
|
7582
7651
|
if (typeof prop === "string") {
|
|
@@ -8116,8 +8185,11 @@ export {
|
|
|
8116
8185
|
BaseCrudDialect,
|
|
8117
8186
|
CRUD,
|
|
8118
8187
|
CRUD_EXT,
|
|
8188
|
+
CoreCreateOperations,
|
|
8119
8189
|
CoreCrudOperations,
|
|
8190
|
+
CoreDeleteOperations,
|
|
8120
8191
|
CoreReadOperations,
|
|
8192
|
+
CoreUpdateOperations,
|
|
8121
8193
|
CoreWriteOperations,
|
|
8122
8194
|
DbNull,
|
|
8123
8195
|
DbNullClass,
|