mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-01-05 23:23:10 +00:00
more cleanup
This commit is contained in:
parent
437ae2e035
commit
24d161d4b4
@ -22,8 +22,8 @@ type
|
|||||||
namespaces*: seq[Namespace]
|
namespaces*: seq[Namespace]
|
||||||
|
|
||||||
const
|
const
|
||||||
delimiter = ":"
|
Delimiter* = ":"
|
||||||
separator = "/"
|
Separator* = "/"
|
||||||
|
|
||||||
# TODO: operator/s for combining string|Namespace,string|Namespace
|
# TODO: operator/s for combining string|Namespace,string|Namespace
|
||||||
# TODO: lifting from ?![Namespace|Key] for various ops
|
# TODO: lifting from ?![Namespace|Key] for various ops
|
||||||
@ -35,25 +35,25 @@ func init*(
|
|||||||
if value.strip == "":
|
if value.strip == "":
|
||||||
return failure "value string must not be all whitespace or empty"
|
return failure "value string must not be all whitespace or empty"
|
||||||
|
|
||||||
if value.contains(delimiter):
|
if value.contains(Delimiter):
|
||||||
return failure "value string must not contain delimiter \"" &
|
return failure "value string must not contain Delimiter \"" &
|
||||||
delimiter & "\""
|
Delimiter & "\""
|
||||||
|
|
||||||
if value.contains(separator):
|
if value.contains(Separator):
|
||||||
return failure "value string must not contain separator \"" &
|
return failure "value string must not contain Separator \"" &
|
||||||
separator & "\""
|
Separator & "\""
|
||||||
|
|
||||||
if field != "":
|
if field != "":
|
||||||
if field.strip == "":
|
if field.strip == "":
|
||||||
return failure "field string must not be all whitespace"
|
return failure "field string must not be all whitespace"
|
||||||
|
|
||||||
if field.contains(delimiter):
|
if field.contains(Delimiter):
|
||||||
return failure "field string must not contain delimiter \"" &
|
return failure "field string must not contain Delimiter \"" &
|
||||||
delimiter & "\""
|
Delimiter & "\""
|
||||||
|
|
||||||
if field.contains(separator):
|
if field.contains(Separator):
|
||||||
return failure "field string must not contain separator \"" &
|
return failure "field string must not contain Separator \"" &
|
||||||
separator & "\""
|
Separator & "\""
|
||||||
|
|
||||||
success T(field: field, value: value)
|
success T(field: field, value: value)
|
||||||
|
|
||||||
@ -61,20 +61,20 @@ func init*(T: type Namespace, id: string): ?!T =
|
|||||||
if id.strip == "":
|
if id.strip == "":
|
||||||
return failure "id string must not be all whitespace or empty"
|
return failure "id string must not be all whitespace or empty"
|
||||||
|
|
||||||
if id.contains(separator):
|
if id.contains(Separator):
|
||||||
return failure "id string must not contain separator \"" & separator & "\""
|
return failure "id string must not contain Separator \"" & Separator & "\""
|
||||||
|
|
||||||
if id == delimiter:
|
if id == Delimiter:
|
||||||
return failure "value in id string \"[field]" & delimiter &
|
return failure "value in id string \"[field]" & Delimiter &
|
||||||
"[value]\" must not be empty"
|
"[value]\" must not be empty"
|
||||||
|
|
||||||
if id.count(delimiter) > 1:
|
if id.count(Delimiter) > 1:
|
||||||
return failure "id string must not contain more than one delimiter \"" &
|
return failure "id string must not contain more than one Delimiter \"" &
|
||||||
delimiter & "\""
|
Delimiter & "\""
|
||||||
|
|
||||||
let
|
let
|
||||||
(field, value) = block:
|
(field, value) = block:
|
||||||
let parts = id.split(delimiter)
|
let parts = id.split(Delimiter)
|
||||||
if parts.len > 1:
|
if parts.len > 1:
|
||||||
(parts[0], parts[^1])
|
(parts[0], parts[^1])
|
||||||
else:
|
else:
|
||||||
@ -84,7 +84,7 @@ func init*(T: type Namespace, id: string): ?!T =
|
|||||||
|
|
||||||
func id*(self: Namespace): string =
|
func id*(self: Namespace): string =
|
||||||
if self.field.len > 0:
|
if self.field.len > 0:
|
||||||
self.field & delimiter & self.value
|
self.field & Delimiter & self.value
|
||||||
else:
|
else:
|
||||||
self.value
|
self.value
|
||||||
|
|
||||||
@ -117,11 +117,11 @@ func init*(T: type Key, id: string): ?!T =
|
|||||||
return failure "id string must not be all whitespace"
|
return failure "id string must not be all whitespace"
|
||||||
|
|
||||||
let
|
let
|
||||||
nsStrs = id.split(separator).filterIt(it != "")
|
nsStrs = id.split(Separator).filterIt(it != "")
|
||||||
|
|
||||||
if nsStrs.len == 0:
|
if nsStrs.len == 0:
|
||||||
return failure "id string must not contain only one or more separator " &
|
return failure "id string must not contain more than one Separator " &
|
||||||
"\"" & separator & "\""
|
"\"" & Separator & "\""
|
||||||
|
|
||||||
Key.init(nsStrs)
|
Key.init(nsStrs)
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ func `type`*(self: Key): string =
|
|||||||
return self[^1].field
|
return self[^1].field
|
||||||
|
|
||||||
func id*(self: Key): string =
|
func id*(self: Key): string =
|
||||||
separator & self.namespaces.mapIt(it.id).join(separator)
|
Separator & self.namespaces.mapIt(it.id).join(Separator)
|
||||||
|
|
||||||
func root*(self: Key): bool =
|
func root*(self: Key): bool =
|
||||||
self.len == 1
|
self.len == 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user