Skip to content

Commit

Permalink
Merge branch 'main' into feat/list-faceting
Browse files Browse the repository at this point in the history
  • Loading branch information
davenewza authored Feb 17, 2025
2 parents 5b2df06 + f0f059d commit 22b9c89
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 71 deletions.
36 changes: 18 additions & 18 deletions packages/wasm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,24 @@ test("validate - multi file", async () => {
expect(errors.length).toEqual(0);
});

test("validate - warnings", async () => {
const schema = `model Person {
fields {
name Text
}
@on([create], createPersonSubscriber
)
}`;
const { errors, warnings } = await validate({
schemaFiles: [{ filename: "schema.keel", contents: schema }],
config: configFile,
includeWarnings: true,
});

expect(errors.length).toEqual(0);
expect(warnings?.length).toEqual(1);
});
// test("validate - warnings", async () => {
// const schema = `model Person {
// fields {
// name Text
// }

// @on([create], createPersonSubscriber
// )
// }`;
// const { errors, warnings } = await validate({
// schemaFiles: [{ filename: "schema.keel", contents: schema }],
// config: configFile,
// includeWarnings: true,
// });

// expect(errors.length).toEqual(0);
// expect(warnings?.length).toEqual(1);
// });

test("validate - ignore warnings", async () => {
const schema = `model Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
model Post {
fields {
name Text
another Text
votes Vote[]
category Category?
}

actions {
create createPost1() with (name, another, votes.score)
//expect-error:51:59:ActionInputError:Cannot provide the id of nested records which do not exist yet
create createPost2() with (name, another, votes.id)
//expect-error:38:49:ActionInputError:Update actions cannot perform field updates on nested models.
update updatePost1(id) with (votes.score)
update updatePost2(id) with (votes.id)
update updatePost3(id) with (category.id)
//expect-error:38:51:ActionInputError:Update actions cannot perform field updates on nested models.
update updatePost4(id) with (category.name)
}
}

model Vote {
fields {
score Number
post Post?
}

actions {
create createVote1() with (score, post.id)
create createVote2() with (score, post.name, post.another)
update updateVote1(id) with (score)
update updateVote2(id) with (post.id)
//expect-error:47:57:ActionInputError:Update actions cannot perform field updates on nested models.
update updateVote3(id) with (post.id, post.name?)
//expect-error:38:48:ActionInputError:Update actions cannot perform field updates on nested models.
update updateVote4(id) with (post.name?)
//expect-error:38:47:ActionInputError:Update actions cannot perform field updates on nested models.
//expect-error:49:61:ActionInputError:Update actions cannot perform field updates on nested models.
update updateVote5(id) with (post.name, post.another)
update updateVote6(id) with (score, post.id)
}
}

model Category {
fields {
name Text
posts Post[]
}

actions {
update updateCategory1(id) with (name)
update updateCategory2(id) with (posts.id)
//expect-error:42:52:ActionInputError:Update actions cannot perform field updates on nested models.
update updateCategory3(id) with (posts.name)
}
}
1 change: 1 addition & 0 deletions schema/testdata/errors/set_attribute_built_in_fields.keel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ model Post {
//expect-error:18:32:AttributeExpressionError:Cannot set the field 'updatedAt' as it is a built-in field and can only be mutated internally
@set(post.updatedAt = ctx.now)
}
//expect-error:44:58:ActionInputError:Update actions cannot perform field updates on nested models.
update updatePost2(id) with (name, publisher.name) {
//expect-error:18:42:AttributeExpressionError:Cannot set the field 'createdAt' as it is a built-in field and can only be mutated internally
@set(post.publisher.createdAt = ctx.now)
Expand Down
104 changes: 67 additions & 37 deletions schema/testdata/proto/action_inputs_in_both_query_and_with/proto.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@
"type": "TYPE_STRING"
},
"optional": true,
"uniqueWith": ["issuer"]
"uniqueWith": [
"issuer"
]
},
{
"modelName": "Identity",
Expand Down Expand Up @@ -173,7 +175,9 @@
"type": "TYPE_STRING"
},
"optional": true,
"uniqueWith": ["email"]
"uniqueWith": [
"email"
]
},
{
"modelName": "Identity",
Expand Down Expand Up @@ -423,7 +427,9 @@
"modelName": "Account",
"fieldName": "username"
},
"target": ["username"]
"target": [
"username"
]
}
]
},
Expand All @@ -438,7 +444,9 @@
"modelName": "Account",
"fieldName": "name"
},
"target": ["name"]
"target": [
"name"
]
},
{
"messageName": "UpdateAccountValues",
Expand All @@ -448,7 +456,9 @@
"modelName": "Account",
"fieldName": "username"
},
"target": ["username"]
"target": [
"username"
]
},
{
"messageName": "UpdateAccountValues",
Expand All @@ -458,7 +468,9 @@
"modelName": "Account",
"fieldName": "isActive"
},
"target": ["isActive"]
"target": [
"isActive"
]
}
]
},
Expand Down Expand Up @@ -494,7 +506,9 @@
"modelName": "Account",
"fieldName": "username"
},
"target": ["username"]
"target": [
"username"
]
},
{
"messageName": "UpdateAccount2Where",
Expand All @@ -504,7 +518,9 @@
"modelName": "Account",
"fieldName": "isActive"
},
"target": ["isActive"]
"target": [
"isActive"
]
}
]
},
Expand All @@ -519,7 +535,9 @@
"modelName": "Account",
"fieldName": "name"
},
"target": ["name"]
"target": [
"name"
]
},
{
"messageName": "UpdateAccount2Values",
Expand All @@ -529,7 +547,9 @@
"modelName": "Account",
"fieldName": "username"
},
"target": ["username"]
"target": [
"username"
]
},
{
"messageName": "UpdateAccount2Values",
Expand All @@ -539,7 +559,9 @@
"modelName": "Account",
"fieldName": "isActive"
},
"target": ["isActive"]
"target": [
"isActive"
]
}
]
},
Expand Down Expand Up @@ -575,7 +597,10 @@
"modelName": "Identity",
"fieldName": "id"
},
"target": ["identity", "id"]
"target": [
"identity",
"id"
]
}
]
},
Expand Down Expand Up @@ -603,7 +628,10 @@
"modelName": "Identity",
"fieldName": "id"
},
"target": ["identity", "id"]
"target": [
"identity",
"id"
]
}
]
},
Expand Down Expand Up @@ -640,7 +668,10 @@
"fieldName": "email"
},
"nullable": true,
"target": ["identity", "email"]
"target": [
"identity",
"email"
]
},
{
"messageName": "UpdateAccount4Where",
Expand All @@ -651,7 +682,10 @@
"fieldName": "issuer"
},
"nullable": true,
"target": ["identity", "issuer"]
"target": [
"identity",
"issuer"
]
}
]
},
Expand All @@ -666,7 +700,9 @@
"modelName": "Account",
"fieldName": "email"
},
"target": ["email"]
"target": [
"email"
]
}
]
},
Expand Down Expand Up @@ -703,7 +739,10 @@
"fieldName": "email"
},
"nullable": true,
"target": ["identity", "email"]
"target": [
"identity",
"email"
]
},
{
"messageName": "UpdateAccount5Where",
Expand All @@ -714,7 +753,10 @@
"fieldName": "issuer"
},
"nullable": true,
"target": ["identity", "issuer"]
"target": [
"identity",
"issuer"
]
}
]
},
Expand All @@ -723,27 +765,15 @@
"fields": [
{
"messageName": "UpdateAccount5Values",
"name": "identity",
"type": {
"type": "TYPE_MESSAGE",
"messageName": "UpdateAccount5IdentityInput"
}
}
]
},
{
"name": "UpdateAccount5IdentityInput",
"fields": [
{
"messageName": "UpdateAccount5IdentityInput",
"name": "email",
"name": "name",
"type": {
"type": "TYPE_STRING",
"modelName": "Identity",
"fieldName": "email"
"modelName": "Account",
"fieldName": "name"
},
"nullable": true,
"target": ["identity", "email"]
"target": [
"name"
]
}
]
},
Expand All @@ -769,4 +799,4 @@
]
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ model Account {

update updateAccount4(identity.email, identity.issuer) with (email)

update updateAccount5(identity.email, identity.issuer) with (identity.email)
update updateAccount5(identity.email, identity.issuer) with (name)
}
}
}
26 changes: 12 additions & 14 deletions schema/validation/unique_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,20 @@ func UniqueAttributeRule(asts []*parser.AST, errs *errorhandling.ValidationError

idents, err := resolve.AsIdentArray(expression)
if err != nil {
if err != nil {
errs.AppendError(
errorhandling.NewValidationErrorWithDetails(
errorhandling.ActionInputError,
errorhandling.ErrorDetails{
Message: "@unique argument must be an array of field names",
Hint: "For example, @unique([sku, supplierCode])",
},
expression,
),
)
return
}
errs.AppendError(
errorhandling.NewValidationErrorWithDetails(
errorhandling.ActionInputError,
errorhandling.ErrorDetails{
Message: "@unique argument must be an array of field names",
Hint: "For example, @unique([sku, supplierCode])",
},
expression,
),
)
return
}

if len(idents) < 2 || err != nil {
if len(idents) < 2 {
errs.AppendError(
errorhandling.NewValidationErrorWithDetails(
errorhandling.AttributeArgumentError,
Expand Down
Loading

0 comments on commit 22b9c89

Please sign in to comment.