-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Struct search (where clauses) #1078
Open
ssanjay1
wants to merge
20
commits into
main
Choose a base branch
from
ssanjay/structSearch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+294
−30
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5adc1cb
update platform deps
ssanjay1 2cdfe7c
add changeset
ssanjay1 853681d
starting structs searches
ssanjay1 0eadd3b
fix types
ssanjay1 561c9e0
more fixes
ssanjay1 6cd1e2b
fix broken behavior with namespaces
ssanjay1 3528c14
add more e2e test
ssanjay1 716d0b7
fix merge conflicts
ssanjay1 be33857
add more tests
ssanjay1 c593728
fix null checks
ssanjay1 51e0c6a
actually fix null checks
ssanjay1 12c72f1
fix fqn interface struct props
ssanjay1 234223d
add a couple more type tests
ssanjay1 cec52e3
add more tests
ssanjay1 41a5590
clean up
ssanjay1 46f1f77
add changeset
ssanjay1 4fe5132
fix return type
ssanjay1 72a37b4
add comment
ssanjay1 809fbe9
Merge branch 'main' into ssanjay/structSearch
ssanjay1 5d03a55
Merge branch 'main' into ssanjay/structSearch
ssanjay1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@osdk/client": patch | ||
"@osdk/api": patch | ||
--- | ||
|
||
Add support for search on struct properties. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,17 @@ | |
*/ | ||
|
||
import type { ObjectOrInterfaceDefinition, WhereClause } from "@osdk/api"; | ||
import { objectTypeWithAllPropertyTypes } from "@osdk/client.test.ontology"; | ||
import { | ||
BgaoNflPlayer, | ||
objectTypeWithAllPropertyTypes, | ||
} from "@osdk/client.test.ontology"; | ||
import type { Point } from "geojson"; | ||
import { expectType } from "ts-expect"; | ||
import { describe, expect, it } from "vitest"; | ||
import { modernToLegacyWhereClause } from "./modernToLegacyWhereClause.js"; | ||
|
||
type ObjAllProps = objectTypeWithAllPropertyTypes; | ||
type structObj = BgaoNflPlayer; | ||
describe(modernToLegacyWhereClause, () => { | ||
describe("api namespaces", () => { | ||
describe("interfaces", () => { | ||
|
@@ -31,7 +35,12 @@ describe(modernToLegacyWhereClause, () => { | |
apiName: "a.Foo", | ||
__DefinitionMetadata: { | ||
type: "interface", | ||
properties: { "prop": { type: "integer" } }, | ||
properties: { | ||
"prop": { type: "integer" }, | ||
"prop2": { | ||
type: { "innerProp1": "string", "innerProp2": "float" }, | ||
}, | ||
}, | ||
apiName: "a.Foo", | ||
displayName: "", | ||
links: {}, | ||
|
@@ -40,14 +49,32 @@ describe(modernToLegacyWhereClause, () => { | |
} as const satisfies ObjectOrInterfaceDefinition; | ||
|
||
const r = modernToLegacyWhereClause({ | ||
prop: 5, | ||
$and: [ | ||
{ prop: { $eq: 5 } }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to a $ filter, because this broke the old code, so want to make sure we can handle that case |
||
{ prop2: { innerProp1: { $eq: "myProp" } } }, | ||
], | ||
}, T); | ||
|
||
expect(r).toMatchInlineSnapshot(` | ||
{ | ||
"field": "a.prop", | ||
"type": "eq", | ||
"value": 5, | ||
"type": "and", | ||
"value": [ | ||
{ | ||
"field": "a.prop", | ||
"type": "eq", | ||
"value": 5, | ||
}, | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "a.prop2", | ||
"structFieldApiName": "innerProp1", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "myProp", | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
|
@@ -62,6 +89,9 @@ describe(modernToLegacyWhereClause, () => { | |
"foo": { type: "integer" }, | ||
"b.prop": { type: "integer" }, | ||
"prop": { type: "integer" }, | ||
"c.prop2": { | ||
type: { "innerProp1": "string", "innerProp2": "float" }, | ||
}, | ||
}, | ||
apiName: "Foo", | ||
displayName: "", | ||
|
@@ -73,6 +103,7 @@ describe(modernToLegacyWhereClause, () => { | |
const r = modernToLegacyWhereClause({ | ||
"b.prop": 5, | ||
foo: 6, | ||
"c.prop2": { innerProp1: { $eq: "myProp" } }, | ||
}, T); | ||
|
||
expect(r).toMatchInlineSnapshot(` | ||
|
@@ -89,6 +120,16 @@ describe(modernToLegacyWhereClause, () => { | |
"type": "eq", | ||
"value": 6, | ||
}, | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "c.prop2", | ||
"structFieldApiName": "innerProp1", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "myProp", | ||
}, | ||
], | ||
} | ||
`); | ||
|
@@ -104,6 +145,9 @@ describe(modernToLegacyWhereClause, () => { | |
"a.foo": { type: "integer" }, | ||
"b.prop": { type: "integer" }, | ||
"prop": { type: "integer" }, | ||
"c.prop2": { | ||
type: { "innerProp1": "string", "innerProp2": "float" }, | ||
}, | ||
}, | ||
apiName: "a.Foo", | ||
displayName: "", | ||
|
@@ -115,6 +159,7 @@ describe(modernToLegacyWhereClause, () => { | |
const r = modernToLegacyWhereClause({ | ||
"b.prop": 5, | ||
"a.foo": 6, | ||
"c.prop2": { innerProp1: { $eq: "myProp" } }, | ||
}, T); | ||
|
||
expect(r).toMatchInlineSnapshot(` | ||
|
@@ -131,6 +176,16 @@ describe(modernToLegacyWhereClause, () => { | |
"type": "eq", | ||
"value": 6, | ||
}, | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "c.prop2", | ||
"structFieldApiName": "innerProp1", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "myProp", | ||
}, | ||
], | ||
} | ||
`); | ||
|
@@ -705,6 +760,96 @@ describe(modernToLegacyWhereClause, () => { | |
} | ||
`); | ||
}); | ||
it("converts struct where clauses correctly", () => { | ||
expect(modernToLegacyWhereClause<structObj>({ | ||
address: { state: { $eq: "NJ" } }, | ||
}, BgaoNflPlayer)).toMatchInlineSnapshot(` | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "address", | ||
"structFieldApiName": "state", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "NJ", | ||
} | ||
`); | ||
|
||
expect(modernToLegacyWhereClause<structObj>({ | ||
$and: [ | ||
{ address: { state: { $eq: "NJ" } } }, | ||
{ address: { city: { $containsAnyTerm: "N" } } }, | ||
], | ||
}, BgaoNflPlayer)).toMatchInlineSnapshot(` | ||
{ | ||
"type": "and", | ||
"value": [ | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "address", | ||
"structFieldApiName": "state", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "NJ", | ||
}, | ||
{ | ||
"field": undefined, | ||
"fuzzy": false, | ||
"propertyIdentifier": { | ||
"propertyApiName": "address", | ||
"structFieldApiName": "city", | ||
"type": "structField", | ||
}, | ||
"type": "containsAnyTerm", | ||
"value": "N", | ||
}, | ||
], | ||
} | ||
`); | ||
|
||
expect(modernToLegacyWhereClause<structObj>({ | ||
$or: [ | ||
{ address: { state: { $eq: "NJ" } } }, | ||
{ address: { city: { $containsAnyTerm: "N" } } }, | ||
{ gamesPlayed: { $gt: 5 } }, | ||
], | ||
}, BgaoNflPlayer)).toMatchInlineSnapshot(` | ||
{ | ||
"type": "or", | ||
"value": [ | ||
{ | ||
"field": undefined, | ||
"propertyIdentifier": { | ||
"propertyApiName": "address", | ||
"structFieldApiName": "state", | ||
"type": "structField", | ||
}, | ||
"type": "eq", | ||
"value": "NJ", | ||
}, | ||
{ | ||
"field": undefined, | ||
"fuzzy": false, | ||
"propertyIdentifier": { | ||
"propertyApiName": "address", | ||
"structFieldApiName": "city", | ||
"type": "structField", | ||
}, | ||
"type": "containsAnyTerm", | ||
"value": "N", | ||
}, | ||
{ | ||
"field": "gamesPlayed", | ||
"type": "gt", | ||
"value": 5, | ||
}, | ||
], | ||
} | ||
`); | ||
}); | ||
}); | ||
|
||
describe("multiple checks", () => { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defined a struct prop on interface