snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
155
server/pkg/dal/operations.go
Normal file
155
server/pkg/dal/operations.go
Normal file
@@ -0,0 +1,155 @@
|
||||
package dal
|
||||
|
||||
type (
|
||||
Operation string
|
||||
OperationSet []Operation
|
||||
)
|
||||
|
||||
const (
|
||||
Create Operation = "corteza::dal:operation:create"
|
||||
Update Operation = "corteza::dal:operation:update"
|
||||
Delete Operation = "corteza::dal:operation:delete"
|
||||
Search Operation = "corteza::dal:operation:search"
|
||||
Lookup Operation = "corteza::dal:operation:lookup"
|
||||
Paging Operation = "corteza::dal:operation:paging"
|
||||
Sorting Operation = "corteza::dal:operation:sorting"
|
||||
)
|
||||
|
||||
var (
|
||||
full = OperationSet{
|
||||
Create,
|
||||
Update,
|
||||
Delete,
|
||||
Search,
|
||||
Lookup,
|
||||
Paging,
|
||||
Sorting,
|
||||
}
|
||||
|
||||
createOperations = OperationSet{
|
||||
Create,
|
||||
}
|
||||
|
||||
updateOperations = OperationSet{
|
||||
Update,
|
||||
}
|
||||
|
||||
deleteOperations = OperationSet{
|
||||
Update,
|
||||
}
|
||||
|
||||
searchOperations = OperationSet{
|
||||
Search,
|
||||
Paging,
|
||||
Sorting,
|
||||
}
|
||||
|
||||
lookupOperations = OperationSet{
|
||||
Lookup,
|
||||
}
|
||||
)
|
||||
|
||||
// FullOperations returns all base system defined operations
|
||||
func FullOperations() (cc OperationSet) {
|
||||
// Doing an union just to make a fresh copy
|
||||
return full.Union(nil)
|
||||
}
|
||||
|
||||
// CreateOperations returns only requested operations used for Create operations
|
||||
func CreateOperations(requested ...Operation) (required OperationSet) {
|
||||
return common(createOperations, requested)
|
||||
}
|
||||
|
||||
// UpdateOperations returns only requested operations used for Update operations
|
||||
func UpdateOperations(requested ...Operation) (required OperationSet) {
|
||||
return common(updateOperations, requested)
|
||||
}
|
||||
|
||||
// DeleteOperations returns only requested operations used for delete operations
|
||||
func DeleteOperations(requested ...Operation) (required OperationSet) {
|
||||
return common(deleteOperations, requested)
|
||||
}
|
||||
|
||||
// SearchOperations returns only requested operations used for Search operations
|
||||
func SearchOperations(requested ...Operation) (required OperationSet) {
|
||||
return common(searchOperations, requested)
|
||||
}
|
||||
|
||||
// LookupOperations returns only requested operations used for Search operations
|
||||
func LookupOperations(requested ...Operation) (required OperationSet) {
|
||||
return common(lookupOperations, requested)
|
||||
}
|
||||
|
||||
func common(aa, bb OperationSet) OperationSet {
|
||||
return aa.Intersect(bb)
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
// IsSuperset is inverse IsSubset
|
||||
//
|
||||
// IsSuperset checks if all bb operations are inside aa
|
||||
func (aa OperationSet) IsSuperset(bb ...Operation) bool {
|
||||
return OperationSet(bb).IsSubset(aa...)
|
||||
}
|
||||
|
||||
// IsSubset checks if all aa operations are inside bb
|
||||
func (aa OperationSet) IsSubset(bb ...Operation) bool {
|
||||
if len(aa) > len(bb) {
|
||||
return false
|
||||
}
|
||||
|
||||
// When A is subset of B, the difference between the two must be 0
|
||||
return len(aa.Diff(bb)) == 0
|
||||
}
|
||||
|
||||
// Intersect returns the intersection between the two sets
|
||||
func (aa OperationSet) Intersect(bb OperationSet) (cc OperationSet) {
|
||||
cc = make(OperationSet, 0, len(aa))
|
||||
for _, a := range aa {
|
||||
for _, b := range bb {
|
||||
if a == b {
|
||||
cc = append(cc, a)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Intersect returns the union between the two sets
|
||||
//
|
||||
// Duplicates are omitted
|
||||
func (aa OperationSet) Union(bb OperationSet) (cc OperationSet) {
|
||||
ix := make(map[Operation]bool)
|
||||
for _, c := range append(aa, bb...) {
|
||||
if !ix[c] {
|
||||
ix[c] = true
|
||||
cc = append(cc, c)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Diff calculates the difference between the two operation sets
|
||||
//
|
||||
// The diff uses aa as base
|
||||
func (aa OperationSet) Diff(bb OperationSet) (cc OperationSet) {
|
||||
for _, a := range aa {
|
||||
found := false
|
||||
for _, b := range bb {
|
||||
found = a == b
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
cc = append(cc, a)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user