@zenstackhq/runtime 3.0.0-alpha.31 → 3.0.0-alpha.33
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/{contract-5Wcmlo5v.d.cts → contract-CusA0mQO.d.cts} +39 -39
- package/dist/{contract-5Wcmlo5v.d.ts → contract-CusA0mQO.d.ts} +39 -39
- package/dist/index.cjs +543 -433
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +499 -389
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +109 -70
- package/dist/plugins/policy/index.cjs.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/dist/plugins/policy/index.js +109 -70
- package/dist/plugins/policy/index.js.map +1 -1
- package/dist/schema.cjs +4 -1
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +1 -0
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +4 -1
- package/dist/schema.js.map +1 -1
- package/package.json +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
|
|
2
|
-
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, BuiltinType, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
2
|
+
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, BuiltinType, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, ModelDef, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
3
3
|
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
4
4
|
|
|
5
5
|
type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -558,6 +558,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
558
558
|
private buildEnumFilter;
|
|
559
559
|
buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, useDefaultIfEmpty: boolean, negated: boolean): SelectQueryBuilder<any, any, any>;
|
|
560
560
|
buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined, modelAlias: string): SelectQueryBuilder<any, any, any>;
|
|
561
|
+
protected buildModelSelect(eb: ExpressionBuilder<any, any>, model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
|
|
561
562
|
buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
|
|
562
563
|
buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
|
|
563
564
|
buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
|
|
@@ -570,6 +571,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
570
571
|
protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
571
572
|
protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
572
573
|
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
|
|
574
|
+
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
|
|
573
575
|
abstract get provider(): DataSourceProviderType;
|
|
574
576
|
/**
|
|
575
577
|
* Builds selection for a relation field.
|
|
@@ -674,24 +676,26 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
674
676
|
};
|
|
675
677
|
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
676
678
|
/**
|
|
677
|
-
*
|
|
678
|
-
* what data should be loaded before and after the mutation.
|
|
679
|
-
*/
|
|
680
|
-
mutationInterceptionFilter?: MutationInterceptionFilter<Schema>;
|
|
681
|
-
/**
|
|
682
|
-
* Called before an entity is mutated.
|
|
683
|
-
* @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
684
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
679
|
+
* Called before entities are mutated.
|
|
685
680
|
*/
|
|
686
681
|
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
|
|
687
682
|
/**
|
|
688
|
-
* Called after
|
|
689
|
-
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
690
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
691
|
-
* @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the
|
|
692
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
683
|
+
* Called after entities are mutated.
|
|
693
684
|
*/
|
|
694
685
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
686
|
+
/**
|
|
687
|
+
* Whether to run after-mutation hooks within the transaction that performs the mutation.
|
|
688
|
+
*
|
|
689
|
+
* If set to `true`, if the mutation already runs inside a transaction, the callbacks are
|
|
690
|
+
* executed immediately after the mutation within the transaction boundary. If the mutation
|
|
691
|
+
* is not running inside a transaction, a new transaction is created to run both the mutation
|
|
692
|
+
* and the callbacks.
|
|
693
|
+
*
|
|
694
|
+
* If set to `false`, the callbacks are executed after the mutation transaction is committed.
|
|
695
|
+
*
|
|
696
|
+
* Defaults to `false`.
|
|
697
|
+
*/
|
|
698
|
+
runAfterMutationWithinTransaction?: boolean;
|
|
695
699
|
};
|
|
696
700
|
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
697
701
|
/**
|
|
@@ -706,45 +710,41 @@ type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
|
706
710
|
* The mutation data. Only available for create and update actions.
|
|
707
711
|
*/
|
|
708
712
|
queryNode: OperationNode;
|
|
709
|
-
};
|
|
710
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
711
|
-
/**
|
|
712
|
-
* The result of the hooks interception filter.
|
|
713
|
-
*/
|
|
714
|
-
type MutationInterceptionFilterResult = {
|
|
715
713
|
/**
|
|
716
|
-
*
|
|
714
|
+
* A query ID that uniquely identifies the mutation operation. You can use it to correlate
|
|
715
|
+
* data between the before and after mutation hooks.
|
|
717
716
|
*/
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Whether entities should be loaded before the mutation.
|
|
721
|
-
*/
|
|
722
|
-
loadBeforeMutationEntities?: boolean;
|
|
723
|
-
/**
|
|
724
|
-
* Whether entities should be loaded after the mutation.
|
|
725
|
-
*/
|
|
726
|
-
loadAfterMutationEntities?: boolean;
|
|
717
|
+
queryId: string;
|
|
727
718
|
};
|
|
728
719
|
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
729
720
|
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
730
721
|
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
731
722
|
/**
|
|
732
|
-
*
|
|
733
|
-
*
|
|
723
|
+
* Loads the entities that are about to be mutated. The db operation that loads the entities is executed
|
|
724
|
+
* within the same transaction context as the mutation.
|
|
725
|
+
*/
|
|
726
|
+
loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
727
|
+
/**
|
|
728
|
+
* The ZenStack client you can use to perform additional operations. The database operations initiated
|
|
729
|
+
* from this client are executed within the same transaction as the mutation if the mutation is running
|
|
730
|
+
* inside a transaction.
|
|
731
|
+
*
|
|
732
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
734
733
|
*/
|
|
735
|
-
|
|
734
|
+
client: ClientContract<Schema>;
|
|
736
735
|
};
|
|
737
736
|
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
738
737
|
/**
|
|
739
|
-
*
|
|
740
|
-
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
738
|
+
* Loads the entities that have been mutated.
|
|
741
739
|
*/
|
|
742
|
-
|
|
740
|
+
loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
743
741
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
742
|
+
* The ZenStack client you can use to perform additional operations.
|
|
743
|
+
* See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
|
|
744
|
+
*
|
|
745
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
746
746
|
*/
|
|
747
|
-
|
|
747
|
+
client: ClientContract<Schema>;
|
|
748
748
|
};
|
|
749
749
|
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
750
750
|
kysely: ToKysely<Schema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
|
|
2
|
-
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, BuiltinType, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
2
|
+
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, BuiltinType, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, ModelDef, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
3
3
|
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
4
4
|
|
|
5
5
|
type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
@@ -558,6 +558,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
558
558
|
private buildEnumFilter;
|
|
559
559
|
buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, useDefaultIfEmpty: boolean, negated: boolean): SelectQueryBuilder<any, any, any>;
|
|
560
560
|
buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined, modelAlias: string): SelectQueryBuilder<any, any, any>;
|
|
561
|
+
protected buildModelSelect(eb: ExpressionBuilder<any, any>, model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
|
|
561
562
|
buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
|
|
562
563
|
buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
|
|
563
564
|
buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
|
|
@@ -570,6 +571,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
570
571
|
protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
571
572
|
protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
572
573
|
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
|
|
574
|
+
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
|
|
573
575
|
abstract get provider(): DataSourceProviderType;
|
|
574
576
|
/**
|
|
575
577
|
* Builds selection for a relation field.
|
|
@@ -674,24 +676,26 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
674
676
|
};
|
|
675
677
|
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
676
678
|
/**
|
|
677
|
-
*
|
|
678
|
-
* what data should be loaded before and after the mutation.
|
|
679
|
-
*/
|
|
680
|
-
mutationInterceptionFilter?: MutationInterceptionFilter<Schema>;
|
|
681
|
-
/**
|
|
682
|
-
* Called before an entity is mutated.
|
|
683
|
-
* @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
684
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
679
|
+
* Called before entities are mutated.
|
|
685
680
|
*/
|
|
686
681
|
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
|
|
687
682
|
/**
|
|
688
|
-
* Called after
|
|
689
|
-
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
690
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
691
|
-
* @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the
|
|
692
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
683
|
+
* Called after entities are mutated.
|
|
693
684
|
*/
|
|
694
685
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
686
|
+
/**
|
|
687
|
+
* Whether to run after-mutation hooks within the transaction that performs the mutation.
|
|
688
|
+
*
|
|
689
|
+
* If set to `true`, if the mutation already runs inside a transaction, the callbacks are
|
|
690
|
+
* executed immediately after the mutation within the transaction boundary. If the mutation
|
|
691
|
+
* is not running inside a transaction, a new transaction is created to run both the mutation
|
|
692
|
+
* and the callbacks.
|
|
693
|
+
*
|
|
694
|
+
* If set to `false`, the callbacks are executed after the mutation transaction is committed.
|
|
695
|
+
*
|
|
696
|
+
* Defaults to `false`.
|
|
697
|
+
*/
|
|
698
|
+
runAfterMutationWithinTransaction?: boolean;
|
|
695
699
|
};
|
|
696
700
|
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
697
701
|
/**
|
|
@@ -706,45 +710,41 @@ type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
|
706
710
|
* The mutation data. Only available for create and update actions.
|
|
707
711
|
*/
|
|
708
712
|
queryNode: OperationNode;
|
|
709
|
-
};
|
|
710
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
711
|
-
/**
|
|
712
|
-
* The result of the hooks interception filter.
|
|
713
|
-
*/
|
|
714
|
-
type MutationInterceptionFilterResult = {
|
|
715
713
|
/**
|
|
716
|
-
*
|
|
714
|
+
* A query ID that uniquely identifies the mutation operation. You can use it to correlate
|
|
715
|
+
* data between the before and after mutation hooks.
|
|
717
716
|
*/
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Whether entities should be loaded before the mutation.
|
|
721
|
-
*/
|
|
722
|
-
loadBeforeMutationEntities?: boolean;
|
|
723
|
-
/**
|
|
724
|
-
* Whether entities should be loaded after the mutation.
|
|
725
|
-
*/
|
|
726
|
-
loadAfterMutationEntities?: boolean;
|
|
717
|
+
queryId: string;
|
|
727
718
|
};
|
|
728
719
|
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
729
720
|
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
730
721
|
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
731
722
|
/**
|
|
732
|
-
*
|
|
733
|
-
*
|
|
723
|
+
* Loads the entities that are about to be mutated. The db operation that loads the entities is executed
|
|
724
|
+
* within the same transaction context as the mutation.
|
|
725
|
+
*/
|
|
726
|
+
loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
727
|
+
/**
|
|
728
|
+
* The ZenStack client you can use to perform additional operations. The database operations initiated
|
|
729
|
+
* from this client are executed within the same transaction as the mutation if the mutation is running
|
|
730
|
+
* inside a transaction.
|
|
731
|
+
*
|
|
732
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
734
733
|
*/
|
|
735
|
-
|
|
734
|
+
client: ClientContract<Schema>;
|
|
736
735
|
};
|
|
737
736
|
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
738
737
|
/**
|
|
739
|
-
*
|
|
740
|
-
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
738
|
+
* Loads the entities that have been mutated.
|
|
741
739
|
*/
|
|
742
|
-
|
|
740
|
+
loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
743
741
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
742
|
+
* The ZenStack client you can use to perform additional operations.
|
|
743
|
+
* See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
|
|
744
|
+
*
|
|
745
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
746
746
|
*/
|
|
747
|
-
|
|
747
|
+
client: ClientContract<Schema>;
|
|
748
748
|
};
|
|
749
749
|
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
750
750
|
kysely: ToKysely<Schema>;
|