@zenstackhq/runtime 3.0.0-alpha.25 → 3.0.0-alpha.26
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-BOWN0dwS.d.cts → contract-BF6mvhVn.d.cts} +5 -4
- package/dist/{contract-BOWN0dwS.d.ts → contract-BF6mvhVn.d.ts} +5 -4
- package/dist/index.cjs +28 -25
- 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 +28 -25
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +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,
|
|
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, FieldIsRelationArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, 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>>;
|
|
@@ -259,9 +259,9 @@ type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collect
|
|
|
259
259
|
skip?: number;
|
|
260
260
|
take?: number;
|
|
261
261
|
orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
|
|
262
|
-
} : {}) & (AllowFilter extends true ? {
|
|
262
|
+
} & Distinct<Schema, Model> & Cursor<Schema, Model> : {}) & (AllowFilter extends true ? {
|
|
263
263
|
where?: WhereInput<Schema, Model>;
|
|
264
|
-
} : {}) & SelectIncludeOmit<Schema, Model, Collection
|
|
264
|
+
} : {}) & SelectIncludeOmit<Schema, Model, Collection>;
|
|
265
265
|
type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
|
|
266
266
|
type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, false>;
|
|
267
267
|
type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
@@ -603,6 +603,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
|
|
606
|
+
type AllCrudOperation = CrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
|
|
606
607
|
|
|
607
608
|
/**
|
|
608
609
|
* ZenStack runtime plugin.
|
|
@@ -647,7 +648,7 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
647
648
|
/**
|
|
648
649
|
* The operation that is being performed.
|
|
649
650
|
*/
|
|
650
|
-
operation:
|
|
651
|
+
operation: AllCrudOperation;
|
|
651
652
|
/**
|
|
652
653
|
* The query arguments.
|
|
653
654
|
*/
|
|
@@ -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,
|
|
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, FieldIsRelationArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, 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>>;
|
|
@@ -259,9 +259,9 @@ type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collect
|
|
|
259
259
|
skip?: number;
|
|
260
260
|
take?: number;
|
|
261
261
|
orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
|
|
262
|
-
} : {}) & (AllowFilter extends true ? {
|
|
262
|
+
} & Distinct<Schema, Model> & Cursor<Schema, Model> : {}) & (AllowFilter extends true ? {
|
|
263
263
|
where?: WhereInput<Schema, Model>;
|
|
264
|
-
} : {}) & SelectIncludeOmit<Schema, Model, Collection
|
|
264
|
+
} : {}) & SelectIncludeOmit<Schema, Model, Collection>;
|
|
265
265
|
type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
|
|
266
266
|
type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, false>;
|
|
267
267
|
type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
@@ -603,6 +603,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
603
603
|
}
|
|
604
604
|
|
|
605
605
|
type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
|
|
606
|
+
type AllCrudOperation = CrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
|
|
606
607
|
|
|
607
608
|
/**
|
|
608
609
|
* ZenStack runtime plugin.
|
|
@@ -647,7 +648,7 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
647
648
|
/**
|
|
648
649
|
* The operation that is being performed.
|
|
649
650
|
*/
|
|
650
|
-
operation:
|
|
651
|
+
operation: AllCrudOperation;
|
|
651
652
|
/**
|
|
652
653
|
* The query arguments.
|
|
653
654
|
*/
|
package/dist/index.cjs
CHANGED
|
@@ -4506,8 +4506,7 @@ var InputValidator = class {
|
|
|
4506
4506
|
}
|
|
4507
4507
|
validateFindArgs(model, unique, args) {
|
|
4508
4508
|
return this.validate(model, "find", {
|
|
4509
|
-
unique
|
|
4510
|
-
collection: true
|
|
4509
|
+
unique
|
|
4511
4510
|
}, (model2, options) => this.makeFindSchema(model2, options), args);
|
|
4512
4511
|
}
|
|
4513
4512
|
validateCreateArgs(model, args) {
|
|
@@ -4575,12 +4574,12 @@ var InputValidator = class {
|
|
|
4575
4574
|
fields["select"] = this.makeSelectSchema(model).optional();
|
|
4576
4575
|
fields["include"] = this.makeIncludeSchema(model).optional();
|
|
4577
4576
|
fields["omit"] = this.makeOmitSchema(model).optional();
|
|
4578
|
-
|
|
4579
|
-
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4580
|
-
if (options.collection) {
|
|
4577
|
+
if (!options.unique) {
|
|
4581
4578
|
fields["skip"] = this.makeSkipSchema().optional();
|
|
4582
4579
|
fields["take"] = this.makeTakeSchema().optional();
|
|
4583
4580
|
fields["orderBy"] = this.orArray(this.makeOrderBySchema(model, true, false), true).optional();
|
|
4581
|
+
fields["cursor"] = this.makeCursorSchema(model).optional();
|
|
4582
|
+
fields["distinct"] = this.makeDistinctSchema(model).optional();
|
|
4584
4583
|
}
|
|
4585
4584
|
let result = import_zod.z.strictObject(fields);
|
|
4586
4585
|
result = this.refineForSelectIncludeMutuallyExclusive(result);
|
|
@@ -4886,13 +4885,7 @@ var InputValidator = class {
|
|
|
4886
4885
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4887
4886
|
const fieldDef = requireField(this.schema, model, field);
|
|
4888
4887
|
if (fieldDef.relation) {
|
|
4889
|
-
fields[field] =
|
|
4890
|
-
import_zod.z.literal(true),
|
|
4891
|
-
import_zod.z.strictObject({
|
|
4892
|
-
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4893
|
-
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional()
|
|
4894
|
-
})
|
|
4895
|
-
]).optional();
|
|
4888
|
+
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4896
4889
|
} else {
|
|
4897
4890
|
fields[field] = import_zod.z.boolean().optional();
|
|
4898
4891
|
}
|
|
@@ -4916,6 +4909,28 @@ var InputValidator = class {
|
|
|
4916
4909
|
}
|
|
4917
4910
|
return import_zod.z.strictObject(fields);
|
|
4918
4911
|
}
|
|
4912
|
+
makeRelationSelectIncludeSchema(fieldDef) {
|
|
4913
|
+
return import_zod.z.union([
|
|
4914
|
+
import_zod.z.boolean(),
|
|
4915
|
+
import_zod.z.strictObject({
|
|
4916
|
+
...fieldDef.array || fieldDef.optional ? {
|
|
4917
|
+
// to-many relations and optional to-one relations are filterable
|
|
4918
|
+
where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional()
|
|
4919
|
+
} : {},
|
|
4920
|
+
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4921
|
+
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4922
|
+
omit: import_zod.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4923
|
+
...fieldDef.array ? {
|
|
4924
|
+
// to-many relations can be ordered, skipped, taken, and cursor-located
|
|
4925
|
+
orderBy: import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4926
|
+
skip: this.makeSkipSchema().optional(),
|
|
4927
|
+
take: this.makeTakeSchema().optional(),
|
|
4928
|
+
cursor: this.makeCursorSchema(fieldDef.type).optional(),
|
|
4929
|
+
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4930
|
+
} : {}
|
|
4931
|
+
})
|
|
4932
|
+
]);
|
|
4933
|
+
}
|
|
4919
4934
|
makeOmitSchema(model) {
|
|
4920
4935
|
const modelDef = requireModel(this.schema, model);
|
|
4921
4936
|
const fields = {};
|
|
@@ -4933,19 +4948,7 @@ var InputValidator = class {
|
|
|
4933
4948
|
for (const field of Object.keys(modelDef.fields)) {
|
|
4934
4949
|
const fieldDef = requireField(this.schema, model, field);
|
|
4935
4950
|
if (fieldDef.relation) {
|
|
4936
|
-
fields[field] =
|
|
4937
|
-
import_zod.z.literal(true),
|
|
4938
|
-
import_zod.z.strictObject({
|
|
4939
|
-
select: import_zod.z.lazy(() => this.makeSelectSchema(fieldDef.type)).optional(),
|
|
4940
|
-
include: import_zod.z.lazy(() => this.makeIncludeSchema(fieldDef.type)).optional(),
|
|
4941
|
-
omit: import_zod.z.lazy(() => this.makeOmitSchema(fieldDef.type)).optional(),
|
|
4942
|
-
where: import_zod.z.lazy(() => this.makeWhereSchema(fieldDef.type, false)).optional(),
|
|
4943
|
-
orderBy: import_zod.z.lazy(() => this.makeOrderBySchema(fieldDef.type, true, false)).optional(),
|
|
4944
|
-
skip: this.makeSkipSchema().optional(),
|
|
4945
|
-
take: this.makeTakeSchema().optional(),
|
|
4946
|
-
distinct: this.makeDistinctSchema(fieldDef.type).optional()
|
|
4947
|
-
})
|
|
4948
|
-
]).optional();
|
|
4951
|
+
fields[field] = this.makeRelationSelectIncludeSchema(fieldDef).optional();
|
|
4949
4952
|
}
|
|
4950
4953
|
}
|
|
4951
4954
|
return import_zod.z.strictObject(fields);
|