diff --git a/id/bson_test.go b/id/bson_test.go index 952ecf596c23373bd2a7917645b863e03331cc06..c8080b5d7ae12181343a8f6502e76484c414e578 100644 --- a/id/bson_test.go +++ b/id/bson_test.go @@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalBSON(t *testing.T) { name: "FieldID", id: &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}}, }, + { + name: "SystemID", + id: &ID{Descriptor: &SystemID{}}, + }, } type test struct { Text string diff --git a/id/id.go b/id/id.go index d3212dea25ce20057a038d3ff4d6d9281a6e869e..ca75c29f94b6fe9100b435e8f546835991bc9fa3 100644 --- a/id/id.go +++ b/id/id.go @@ -75,6 +75,10 @@ func Parse(s string) (*ID, error) { return &ID{Descriptor: id}, nil } + if id, _ := parseSystemID(parts); id != nil { + return &ID{Descriptor: id}, nil + } + return nil, ErrInvalidID } @@ -125,6 +129,8 @@ func FromMap(m map[string]any) (*ID, error) { v.Descriptor = new(RevisionID) case Field: v.Descriptor = new(FieldID) + case System: + v.Descriptor = new(SystemID) default: return nil, errors.New("unknown type") } diff --git a/id/id_test.go b/id/id_test.go index a5a75cc5f563efaabbe79ddb40b2f770d4afc314..041f1cdc6018e6c84c0c4c6a4be4b3944ef34082 100644 --- a/id/id_test.go +++ b/id/id_test.go @@ -128,6 +128,11 @@ func Test_ParseID(t *testing.T) { FieldName: "<field_name>", }}, }, + { + name: "SystemID", + id: "/system", + result: &ID{Descriptor: &SystemID{}}, + }, { name: "With error #1: no backslash in the beginning of id", id: "spaces/<space_id>", @@ -278,8 +283,12 @@ func Test_Map(t *testing.T) { ItemID: "<item_id>", }, FieldName: "<field_name>", - }, }}, + }, + { + name: "SystemID", + id: &ID{Descriptor: &SystemID{}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/id/json_test.go b/id/json_test.go index 1ab3bb8748bd55e3b3a7ef909466b221567fd0f0..afe831d4ef6038eaa6bc8a565b0623334cdf6bc8 100644 --- a/id/json_test.go +++ b/id/json_test.go @@ -61,6 +61,10 @@ func TestID_MarshalUnmarshalJSON(t *testing.T) { name: "FieldID", id: &ID{Descriptor: &FieldID{FieldName: "1", ItemID: ItemID{ItemID: "1", CollectionID: CollectionID{CollectionID: "1", EnvironmentID: EnvironmentID{EnvironmentID: "1", SpaceID: SpaceID{SpaceID: "1"}}}}}}, }, + { + name: "SystemID", + id: &ID{Descriptor: &SystemID{}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/id/system.go b/id/system.go new file mode 100644 index 0000000000000000000000000000000000000000..0fe640a26fc1936d6414648f282ffa683c59ec9c --- /dev/null +++ b/id/system.go @@ -0,0 +1,33 @@ +package id + +const ( + System = "system" +) + +type SystemID struct{} + +func (t *SystemID) Type() string { return Space } + +func (t *SystemID) String() string { + return "/" + System +} + +func (t *SystemID) ToMap() map[string]any { + return map[string]any{"type": System} +} + +func (t *SystemID) FromMap(m map[string]any) error { + return nil +} + +func (t *SystemID) Validate() error { + return nil +} + +func parseSystemID(parts []string) (*SystemID, error) { + var id SystemID + if len(parts) != 1 || parts[0] != System { + return nil, ErrInvalidID + } + return &id, nil +}