Skip to content
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

State machines, command queues, workflows #86

Merged
merged 95 commits into from
Nov 10, 2023
Merged
Changes from 1 commit
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
eb14817
Thoughts on state machines, command queues, workflows
widmogrod Aug 12, 2023
9155800
Drafting Workflow DSL
widmogrod Aug 12, 2023
38c744f
Simple test that demonstrate that execution work
widmogrod Aug 19, 2023
382adec
Separate workflow and process state machine
widmogrod Aug 22, 2023
be0b5ce
Machine test suite now allows for before and after hooks
widmogrod Aug 23, 2023
6391fa2
Workflow example with as state machine
widmogrod Aug 23, 2023
5dd8404
New test cases covering execution
widmogrod Aug 24, 2023
aae1ea6
Introduce *BaseState, remove Context
widmogrod Aug 26, 2023
787b06a
Flow in *BaseState is not same representation as Run command
widmogrod Aug 26, 2023
9015367
Generate callbackID via dependency
widmogrod Aug 26, 2023
5f49b31
Disable Retry command, since it's not yet implemented
widmogrod Aug 26, 2023
368ad90
Remove Resume state
widmogrod Aug 26, 2023
2027dd8
Rename Status to State
widmogrod Aug 26, 2023
61ed4e3
make BaseState value not pointer in State variants
widmogrod Aug 26, 2023
245d4fc
make StepID part of BaseState
widmogrod Aug 26, 2023
03add43
refactor new BaseState propagation
widmogrod Aug 26, 2023
ba2cce7
implement Choose (if-then-else)
widmogrod Aug 26, 2023
3021af4
remove Fail state, and leave only Done
widmogrod Aug 26, 2023
106164d
change go:generate mkunion to local relative build
widmogrod Aug 26, 2023
2a4f669
refactor position of newContext
widmogrod Aug 27, 2023
702fb06
move workflow x/workflow package
widmogrod Aug 30, 2023
f30f71c
introduce draft of x/shape DSL
widmogrod Aug 30, 2023
1494887
introduce draft of x/storage library that simplify work with schemale…
widmogrod Aug 30, 2023
9480ee0
x/schema: schema.Schema is now serializable and deserilizable
widmogrod Sep 2, 2023
ed9e545
x/schema: schema.Get now support # for union types
widmogrod Sep 10, 2023
63e7979
x/storage: predicate allow for #-union type detection
widmogrod Sep 10, 2023
b9a5ee5
x/schema: Update readme title
widmogrod Sep 10, 2023
71ef985
x/storage: introduce readme and update code to work with x/schema
widmogrod Sep 10, 2023
28392af
x/workflow: example that show how it works with x/storage
widmogrod Sep 10, 2023
437f657
introduce dev/ directory with tools to run integration tests
widmogrod Sep 30, 2023
b0d0c8c
x/localstackutil package helps with integration tests
widmogrod Sep 30, 2023
94c8b8f
x/storage run integration tests on DynamoDB and OpenSearch with # uni…
widmogrod Sep 30, 2023
53ad99a
x/workflow NewMachine constructor + refactoring
widmogrod Sep 30, 2023
72fe0d1
x/schema change map to list in table tests to remove flakiness
widmogrod Sep 30, 2023
f7e30a1
x/taskqueue first implementation draft
widmogrod Sep 30, 2023
aa9ceac
setup CI with localstack
widmogrod Sep 30, 2023
422c009
setup CI with localstack
widmogrod Sep 30, 2023
fa9d00e
use docker compose instead docker-compose
widmogrod Oct 1, 2023
cbaaf0c
use trap to run docker compose down
widmogrod Oct 1, 2023
38c6304
x/shape package provides representation of types.
widmogrod Oct 8, 2023
9dae4e3
infer default can extract gotype information and encode it using x/shape
widmogrod Oct 8, 2023
31f4fcc
mkunion shape-export cli option
widmogrod Oct 8, 2023
4e03e41
use log "github.com/sirupsen/logrus"
widmogrod Oct 8, 2023
3f9dba8
x/shape improve typescript code generation
widmogrod Oct 15, 2023
505ce9d
x/taskqueue make FunctionProcessor.F public
widmogrod Oct 15, 2023
98b54e6
x/schema - check json serialization of recursive Schema types
widmogrod Oct 15, 2023
09f9c84
x/workflow - fix bug with resolving variables
widmogrod Oct 15, 2023
b8c3946
example - React & Go UI, that use workflows
widmogrod Oct 15, 2023
b85fa1c
x/storage/predicate additional test cases for Evaluate
widmogrod Oct 18, 2023
02ff9d4
x/workflow - generation of RunID & dependency injection
widmogrod Oct 18, 2023
17fd082
example/my-app - update UI and server side for x/workflow use cases
widmogrod Oct 18, 2023
b9ab775
x/taskqueue - fix nil pointer
widmogrod Oct 19, 2023
8a87117
CI: try re-run go test few times (fix for flakiness)
widmogrod Oct 19, 2023
b207a44
delete file from old project react-app
widmogrod Oct 19, 2023
b19e098
x/workflow Introduce default max retries, and TryRecover command
widmogrod Oct 22, 2023
19f377e
x/workflow ToStr* for pretty printing workflows
widmogrod Oct 22, 2023
b7e57de
example my-app setup for background recovery tasks
widmogrod Oct 22, 2023
03b1637
x/schema now supports jsonpath like location parser
widmogrod Oct 24, 2023
e2d8cc9
x/storage/predicate now support new jsonpath-like location finding
widmogrod Oct 24, 2023
46cf808
x/storage use json path like implementation (partial)
widmogrod Oct 24, 2023
30abc8f
x/schema ParseLocation
widmogrod Oct 27, 2023
a993d48
x/schema UnionInformationRule to get access about union types outside…
widmogrod Oct 27, 2023
7d75121
x/shape FromGo infers golang types
widmogrod Oct 27, 2023
f85e90a
x/shape ToTypeScript handles more union types
widmogrod Oct 27, 2023
c7f83f6
x/storage now works without "schema.Map" and leverage schema.Location
widmogrod Oct 27, 2023
7a2b62d
infer default for union shapes, now support more union types
widmogrod Oct 27, 2023
1f3a953
x/storage/schemaless/typeful fix nil panic
widmogrod Oct 27, 2023
fdbdeac
x/storage/schemaless s.toKey() normalise records in memory
widmogrod Oct 30, 2023
d8b48bc
x/taskqueue can support CDC
widmogrod Oct 30, 2023
0b918d7
x/workflow supports delayed and scheduled execution
widmogrod Oct 30, 2023
9a148c6
example/my-app now supports scheduled execution
widmogrod Oct 30, 2023
7680c26
x/workflow stop and resume schedule operations
widmogrod Nov 4, 2023
877acad
example/my-app supports for stop/resume schedule
widmogrod Nov 4, 2023
f8fcc56
x/workflow Stop/Resume operate on ParentRunID
widmogrod Nov 4, 2023
42f2f7a
example/my-app use new workflow version
widmogrod Nov 4, 2023
143dee0
x/workflow functionInput has name
widmogrod Nov 10, 2023
da033cf
cmd/mkunion now can generate unions also by providing --input-go-file
widmogrod Nov 10, 2023
74ea347
update README.md + new version 1.19
widmogrod Nov 10, 2023
77d3432
InferredInfo allows to retrieve all possible union types
widmogrod Nov 10, 2023
1ffcef9
example/my-app use OpenAI function calling
widmogrod Nov 10, 2023
904c405
introduce last for breaking change
widmogrod Nov 10, 2023
fbbdc73
introduce new exported types in ts
widmogrod Nov 10, 2023
5edd20c
example/my-app: introduce Chat UI
widmogrod Nov 10, 2023
7029e7c
cmd/mkunion introduce -compact flag
widmogrod Nov 10, 2023
a9956ab
cmd/mkunion refactor reducer_depth_first_generator.go
widmogrod Nov 10, 2023
ca32544
cmd/mkunion refactor visitor_default_generator.go
widmogrod Nov 10, 2023
8bd4b02
cmd/mkunion refactor reducer_default_reduction_generator.go
widmogrod Nov 10, 2023
a760161
cmd/mkunion refactor reducer_breadth_first_generator.go
widmogrod Nov 10, 2023
6f770d3
mkunion now compacts generated files into one
widmogrod Nov 10, 2023
abfe730
mkunion now compacts generated files into one (commit new gen files)
widmogrod Nov 10, 2023
aa3b98e
mkunion now generates files with simpler names _gen.go
widmogrod Nov 10, 2023
9de0bb5
update readme
widmogrod Nov 10, 2023
7e42514
x/schema regenerate schema models
widmogrod Nov 10, 2023
2a304ae
x/shape regenerate shape models
widmogrod Nov 10, 2023
6126829
example/my-app regenerate ts mappings
widmogrod Nov 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
introduce draft of x/storage library that simplify work with schemale…
…ss databases
widmogrod committed Aug 30, 2023

Verified

This commit was signed with the committer’s verified signature.
widmogrod Gabriel Habryn
commit 1494887bdecbabc324012f064d9219ada83ffffa
29 changes: 27 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,22 +3,47 @@ module github.com/widmogrod/mkunion
go 1.18

require (
github.com/alecthomas/participle/v2 v2.0.0
github.com/aws/aws-sdk-go-v2 v1.21.0
github.com/aws/aws-sdk-go-v2/config v1.18.25
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.19
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.6
github.com/aws/aws-sdk-go-v2/service/kinesis v1.18.5
github.com/bxcodec/faker/v3 v3.8.1
github.com/fatih/structtag v1.2.0
github.com/stretchr/testify v1.8.1
github.com/opensearch-project/opensearch-go/v2 v2.3.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.2
github.com/urfave/cli/v2 v2.25.3
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
golang.org/x/sync v0.1.0
)

require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.14.7 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.27 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
github.com/aws/smithy-go v1.14.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.11.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
99 changes: 93 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,55 +1,142 @@
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
github.com/alecthomas/participle/v2 v2.0.0/go.mod h1:rAKZdJldHu8084ojcWevWAL8KmEU+AT+Olodb+WoN2Y=
github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk=
github.com/aws/aws-sdk-go v1.44.263/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v1.17.7/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2 v1.18.0 h1:882kkTpSFhdgYRKVZ/VCgf7sd0ru57p2JCxz4/oN5RY=
github.com/aws/aws-sdk-go-v2 v1.18.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
github.com/aws/aws-sdk-go-v2 v1.21.0 h1:gMT0IW+03wtYJhRqTVYn0wLzwdnK9sRMcxmtfGzRdJc=
github.com/aws/aws-sdk-go-v2 v1.21.0/go.mod h1:/RfNgGmRxI+iFOB1OeJUyxiU+9s88k3pfHvDagGEp0M=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13 h1:OPLEkmhXf6xFPiz0bLeDArZIDx1NNS4oJyG4nv3Gct0=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.13/go.mod h1:gpAbvyDGQFozTEmlTFO8XcQKHzubdq0LzRyJpG6MiXM=
github.com/aws/aws-sdk-go-v2/config v1.18.25 h1:JuYyZcnMPBiFqn87L2cRppo+rNwgah6YwD3VuyvaW6Q=
github.com/aws/aws-sdk-go-v2/config v1.18.25/go.mod h1:dZnYpD5wTW/dQF0rRNLVypB396zWCcPiBIvdvSWHEg4=
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 h1:PjiYyls3QdCrzqUN35jMWtUK1vqVZ+zLfdOa/UPFDp0=
github.com/aws/aws-sdk-go-v2/credentials v1.13.24/go.mod h1:jYPYi99wUOPIFi0rhiOvXeSEReVOzBqFNOX5bXYoG2o=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.19 h1:QBibysVkF3tDBJHuMFKWk3BX+qL+4CG26X2I4K3grXE=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.19/go.mod h1:sMgThC49I+7ud4V7stUsJwaaM6W/KYxRHl2A5pZDrE4=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 h1:jJPgroehGvjrde3XufFIJUZVK5A2L9a3KwSFgKy9n8w=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3/go.mod h1:4Q0UFP0YJf0NrsEuEYHpM9fTSEVnD16Z3uyEF7J9JGM=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.31/go.mod h1:QT0BqUvX1Bh2ABdTGnjqEjvjzrCfIniM9Sc8zn9Yndo=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33/go.mod h1:7i0PF1ME/2eUPFcjkVIwq+DOygHEoK92t5cDqNgYbIw=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41 h1:22dGT7PneFMx4+b3pz7lMTRyN8ZKH7M2cW4GP9yUS2g=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.41/go.mod h1:CrObHAuPneJBlfEJ5T3szXOUkLEThaGfvnhTf33buas=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.25/go.mod h1:zBHOPwhBc3FlQjQJE/D3IfPWiWaQmT06Vq9aNukDo0k=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27/go.mod h1:UrHnn3QV/d0pBZ6QBAEQcqFLf8FAzLmoUfPVIueOvoM=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35 h1:SijA0mgjV8E+8G45ltVHs0fvKpTj8xmZJ3VwhGKtUSI=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.35/go.mod h1:SJC1nEVVva1g3pHAIdCp7QsRIkMmLAgoDquQ9Rr8kYw=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 h1:gGLG7yKaXG02/jBlg210R7VgQIotiQntNhsCFejawx8=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34/go.mod h1:Etz2dj6UHYuw+Xw830KfzCfWGMzqvUTCjUj5b76GVDc=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.2/go.mod h1:KdM++ikeFLtf0RX0WHUdF/nugF8uUntGmJS3Ywo7lVo=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.6 h1:oVgTC5JbRZKT+yBE2Cz5NLXYcfAGsRR6lk/v223Pjko=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.19.6/go.mod h1:1MNss6sqoIsFGisX92do/5doiUCBrN7EjhZCS/8DUjI=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.14.7 h1:ak2304PBjHDV3rLzdbxKavYpXw/clQkeWxXKO/x+Ez8=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.14.7/go.mod h1:eRmcVwDpfeYgamYv+57cqM9hMWw+/TOqwGsbm39JHgc=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 h1:y2+VQzC6Zh2ojtV2LoC0MNwHWc6qXv/j2vrQtlftkdA=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11/go.mod h1:iV4q2hsqtNECrfmlXyord9u4zyuFEJX9eLgLpSPzWA8=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.25/go.mod h1:zrjXfehNxd4la9SByaw7KQk4AmGkdmeASpOJezwed0g=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.27 h1:QmyPCRZNMR1pFbiOi9kBZWZuKrKB9LD4cxltxQk4tNE=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.27/go.mod h1:DfuVY36ixXnsG+uTqnoLWunXAKJ4qjccoFrXUPpj+hs=
github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 h1:0iKliEXAcCa2qVtRs7Ot5hItA2MsufrphbRFlz1Owxo=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27/go.mod h1:EOwBD4J4S5qYszS5/3DpkejfuK+Z5/1uzICfPaZLtqw=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.18.5 h1:naSZmQiFjoTLxNjfDy/KgEnWdG3odkR6gIEgTx21YOM=
github.com/aws/aws-sdk-go-v2/service/kinesis v1.18.5/go.mod h1:0h3hOcyFXyjvI3wGt8C8vk2+II9XxHwFM7zH2KvLHmA=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 h1:UBQjaMTCKwyUYwiVnUt6toEJwGXsLBI6al083tpjJzY=
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10/go.mod h1:ouy2P4z6sJN70fR3ka3wD3Ro3KezSxU6eKGQI2+2fjI=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 h1:PkHIIJs8qvq0e5QybnZoG1K/9QTrLr9OsqCIo59jOBA=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10/go.mod h1:AFvkxc8xfBe8XA+5St5XIHHrQQtkxqrRincx4hmMHOk=
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 h1:2DQLAKDteoEDI8zpCzqBMaZlJuoE9iTYD0gFmXVax9E=
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0/go.mod h1:BgQOMsg8av8jset59jelyPW7NoZcZXLVpDsXunGDrk8=
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ=
github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/bxcodec/faker/v3 v3.8.1 h1:qO/Xq19V6uHt2xujwpaetgKhraGCapqY2CRWGD/SqcM=
github.com/bxcodec/faker/v3 v3.8.1/go.mod h1:DdSDccxF5msjFo5aO4vrobRQ8nIApg8kq3QWPEQD6+o=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/opensearch-project/opensearch-go/v2 v2.3.0 h1:nQIEMr+A92CkhHrZgUhcfsrZjibvB3APXf2a1VwCmMQ=
github.com/opensearch-project/opensearch-go/v2 v2.3.0/go.mod h1:8LDr9FCgUTVoT+5ESjc2+iaZuldqE+23Iq0r1XeNue8=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.25.3 h1:VJkt6wvEBOoSjPFQvOkv6iWIrsJyCrKGtCtxXWwmGeY=
github.com/urfave/cli/v2 v2.25.3/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
69 changes: 69 additions & 0 deletions x/storage/predicate/evaluate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package predicate

import "github.com/widmogrod/mkunion/x/schema"

func Evaluate(predicate Predicate, data schema.Schema, bind ParamBinds) bool {
return MustMatchPredicate(
predicate,
func(x *And) bool {
for _, p := range x.L {
if !Evaluate(p, data, bind) {
return false
}
}
return true

},
func(x *Or) bool {
for _, p := range x.L {
if Evaluate(p, data, bind) {
return true
}
}
return false
},
func(x *Not) bool {
return !Evaluate(x.P, data, bind)
},
func(x *Compare) bool {
value, ok := bind[x.BindValue]
if !ok {
return false
}

// Field value that is not set and equality is not about None is always false.
fieldValue := schema.Get(data, x.Location)
cmp := schema.Compare(fieldValue, value)
switch x.Operation {
case "=":
return cmp == 0
case "<":
return cmp < 0
case ">":
return cmp > 0
case "<=":
return cmp <= 0
case ">=":
return cmp >= 0
case "<>":
return cmp != 0
default:
return false
}
},
)
}

func EvaluateEqual(record schema.Schema, location string, value any) bool {
return Evaluate(
&Compare{
Location: location,
Operation: "=",
BindValue: ":value",
},
record,
map[string]schema.Schema{
":value": schema.FromGo(value),
},
)
}
80 changes: 80 additions & 0 deletions x/storage/predicate/evaluate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package predicate

import (
"github.com/widmogrod/mkunion/x/schema"
"testing"
)

type sampleStruct struct {
ID string
Age int
Friends []sampleStruct
}

func TestEvaluate(t *testing.T) {
defValue := sampleStruct{
ID: "123",
Age: 20,
Friends: []sampleStruct{
{
ID: "53",
Age: 40,
},
{
ID: "54",
Age: 15,
},
},
}

defBind := map[string]any{
":id": "123",
":age": 20,
":firstFriendId": "53",
":secondFriendId": "54",
}

useCases := []struct {
value string
data any
bind map[string]any
result bool
}{
{
value: "ID = :id",
data: defValue,
bind: defBind,
result: true,
},
{
value: "ID = :id AND Age <= :age",
data: defValue,
bind: defBind,
result: true,
},
{
value: "ID = :id AND Age <= :age AND Friends.[0].ID = :firstFriendId",
data: defValue,
bind: defBind,
result: true,
},
}
for _, uc := range useCases {
t.Run(uc.value, func(t *testing.T) {
p, err := Parse(uc.value)
if err != nil {
t.Fatal(err)
}

schemaBind := map[string]schema.Schema{}
for k, v := range uc.bind {
schemaBind[k] = schema.FromGo(v)
}

if result := Evaluate(p, schema.FromGo(uc.data), schemaBind); result != uc.result {
t.Fatalf("expected %v value, got %v value", uc.result, result)
}
})
}

}
33 changes: 33 additions & 0 deletions x/storage/predicate/optimize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package predicate

func Optimize(p Predicate) Predicate {
return MustMatchPredicate(
p,
func(x *And) Predicate {
// flatten nested predicates
if len(x.L) == 1 {
return x.L[0]
}
return x
},
func(x *Or) Predicate {
// flatten nested predicates
if len(x.L) == 1 {
return x.L[0]
}
return x
},
func(x *Not) Predicate {
y, ok := x.P.(*Not)
if ok {
// double negation is the same as the original
// !(!x) == x
return Optimize(y.P)
}
return x
},
func(x *Compare) Predicate {
return x
},
)
}
Loading