Skip to content

Commit 7398541

Browse files
committed
refactor: rename 'kind' to 'qri', drop 'qri:' prefix
using qri as a key makes more sense and takes up just a little less room. closes #45
1 parent d164ef0 commit 7398541

31 files changed

+155
-170
lines changed

commit.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import (
1515
type Commit struct {
1616
path datastore.Key
1717
Author *User `json:"author,omitempty"`
18-
Kind Kind `json:"kind,omitempty"`
1918
// Message is an optional
2019
Message string `json:"message,omitempty"`
20+
// Qri is this commit's qri kind
21+
Qri Kind `json:"qri,omitempty"`
2122
// Signature is a base58 encoded privateKey signing of Title
2223
Signature string `json:"signature,omitempty"`
2324
// Time this dataset was created. Required.
@@ -73,8 +74,8 @@ func (cm *Commit) Assign(msgs ...*Commit) {
7374
if m.Signature != "" {
7475
cm.Signature = m.Signature
7576
}
76-
if m.Kind.String() != "" {
77-
cm.Kind = m.Kind
77+
if m.Qri.String() != "" {
78+
cm.Qri = m.Qri
7879
}
7980
}
8081
}
@@ -87,15 +88,15 @@ func (cm *Commit) MarshalJSON() ([]byte, error) {
8788
return cm.path.MarshalJSON()
8889
}
8990

90-
kind := cm.Kind
91+
kind := cm.Qri
9192
if kind == "" {
9293
kind = KindCommit
9394
}
9495

9596
m := &_commitMsg{
9697
Author: cm.Author,
97-
Kind: kind,
9898
Message: cm.Message,
99+
Qri: kind,
99100
Signature: cm.Signature,
100101
Timestamp: cm.Timestamp,
101102
Title: cm.Title,

commit_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestCommitAssign(t *testing.T) {
2525
doug := &User{ID: "doug_id", Email: "doug@example.com"}
2626
expect := &Commit{
2727
path: datastore.NewKey("a"),
28-
Kind: KindCommit,
28+
Qri: KindCommit,
2929
Author: doug,
3030
Timestamp: t1,
3131
Title: "expect title",
@@ -40,7 +40,7 @@ func TestCommitAssign(t *testing.T) {
4040

4141
got.Assign(&Commit{
4242
Author: doug,
43-
Kind: KindCommit,
43+
Qri: KindCommit,
4444
Title: "expect title",
4545
}, &Commit{
4646
path: datastore.NewKey("a"),
@@ -85,8 +85,8 @@ func TestCommitMarshalJSON(t *testing.T) {
8585
out []byte
8686
err error
8787
}{
88-
{&Commit{Title: "title", Timestamp: ts}, []byte(`{"kind":"qri:cm:0","timestamp":"2001-01-01T01:01:01Z","title":"title"}`), nil},
89-
{&Commit{Author: &User{ID: "foo"}, Timestamp: ts}, []byte(`{"author":{"id":"foo"},"kind":"qri:cm:0","timestamp":"2001-01-01T01:01:01Z","title":""}`), nil},
88+
{&Commit{Title: "title", Timestamp: ts}, []byte(`{"qri":"cm:0","timestamp":"2001-01-01T01:01:01Z","title":"title"}`), nil},
89+
{&Commit{Author: &User{ID: "foo"}, Timestamp: ts}, []byte(`{"author":{"id":"foo"},"qri":"cm:0","timestamp":"2001-01-01T01:01:01Z","title":""}`), nil},
9090
}
9191

9292
for i, c := range cases {
@@ -151,15 +151,15 @@ func TestCommitUnmarshalJSON(t *testing.T) {
151151
}
152152

153153
func TestUnmarshalCommit(t *testing.T) {
154-
cma := Commit{Kind: KindCommit, Message: "foo"}
154+
cma := Commit{Qri: KindCommit, Message: "foo"}
155155
cases := []struct {
156156
value interface{}
157157
out *Commit
158158
err string
159159
}{
160160
{cma, &cma, ""},
161161
{&cma, &cma, ""},
162-
{[]byte("{\"kind\":\"qri:cm:0\"}"), &Commit{Kind: KindCommit}, ""},
162+
{[]byte("{\"qri\":\"cm:0\"}"), &Commit{Qri: KindCommit}, ""},
163163
{5, nil, "couldn't parse commitMsg, value is invalid type"},
164164
}
165165

compare.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ func CompareDatasets(a, b *Dataset) error {
2020
if !a.Path().Equal(b.Path()) {
2121
return fmt.Errorf("Path: %s != %s", a.Path(), b.Path())
2222
}
23-
if a.Kind.String() != b.Kind.String() {
24-
return fmt.Errorf("Kind: %s != %s", a.Kind, b.Kind)
23+
if a.Qri.String() != b.Qri.String() {
24+
return fmt.Errorf("Qri: %s != %s", a.Qri, b.Qri)
2525
}
2626

2727
if a.PreviousPath != b.PreviousPath {
@@ -68,8 +68,8 @@ func CompareMetas(a, b *Meta) error {
6868
if !a.Path().Equal(b.Path()) {
6969
return fmt.Errorf("Path: %s != %s", a.Path(), b.Path())
7070
}
71-
if a.Kind.String() != b.Kind.String() {
72-
return fmt.Errorf("Kind: %s != %s", a.Kind, b.Kind)
71+
if a.Qri.String() != b.Qri.String() {
72+
return fmt.Errorf("Qri: %s != %s", a.Qri, b.Qri)
7373
}
7474
if a.Title != b.Title {
7575
return fmt.Errorf("Title: %s != %s", a.Title, b.Title)
@@ -132,8 +132,8 @@ func CompareStructures(a, b *Structure) error {
132132
return fmt.Errorf("nil: <not nil> != <nil>")
133133
}
134134

135-
if a.Kind != b.Kind {
136-
return fmt.Errorf("Kind: %s != %s", a.Kind, b.Kind)
135+
if a.Qri != b.Qri {
136+
return fmt.Errorf("Qri: %s != %s", a.Qri, b.Qri)
137137
}
138138
if a.Format != b.Format {
139139
return fmt.Errorf("Format: %s != %s", a.Format, b.Format)
@@ -206,8 +206,8 @@ func CompareCommits(a, b *Commit) error {
206206
return fmt.Errorf("nil: <not nil> != <nil>")
207207
}
208208

209-
if a.Kind != b.Kind {
210-
return fmt.Errorf("Kind: %s != %s", a.Kind, b.Kind)
209+
if a.Qri != b.Qri {
210+
return fmt.Errorf("Qri: %s != %s", a.Qri, b.Qri)
211211
}
212212
if a.Title != b.Title {
213213
return fmt.Errorf("Title: %s != %s", a.Title, b.Title)
@@ -239,8 +239,8 @@ func CompareTransforms(a, b *Transform) error {
239239
if !a.Path().Equal(b.Path()) {
240240
return fmt.Errorf("path: %s != %s", a.Path(), b.Path())
241241
}
242-
if a.Kind.String() != b.Kind.String() {
243-
return fmt.Errorf("Kind: %s != %s", a.Kind, b.Kind)
242+
if a.Qri.String() != b.Qri.String() {
243+
return fmt.Errorf("Qri: %s != %s", a.Qri, b.Qri)
244244
}
245245
if a.Syntax != b.Syntax {
246246
return fmt.Errorf("Syntax: %s != %s", a.Syntax, b.Syntax)

compare_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestCompareDatasets(t *testing.T) {
1717
{nil, nil, ""},
1818
{AirportCodes, AirportCodes, ""},
1919
{NewDatasetRef(datastore.NewKey("a")), NewDatasetRef(datastore.NewKey("b")), "Path: /a != /b"},
20-
{&Dataset{Kind: "a"}, &Dataset{Kind: "b"}, "Kind: a != b"},
20+
{&Dataset{Qri: "a"}, &Dataset{Qri: "b"}, "Qri: a != b"},
2121
{&Dataset{PreviousPath: "a"}, &Dataset{PreviousPath: "b"}, "PreviousPath: a != b"},
2222
{&Dataset{DataPath: "a"}, &Dataset{DataPath: "b"}, "DataPath: a != b"},
2323
{&Dataset{}, &Dataset{Structure: &Structure{}}, "Structure: nil: <nil> != <not nil>"},
@@ -42,7 +42,7 @@ func TestCompareMetas(t *testing.T) {
4242
{nil, nil, ""},
4343
{AirportCodes.Meta, AirportCodes.Meta, ""},
4444
{NewMetaRef(datastore.NewKey("a")), NewMetaRef(datastore.NewKey("b")), "Path: /a != /b"},
45-
{&Meta{Kind: "a"}, &Meta{Kind: "b"}, "Kind: a != b"},
45+
{&Meta{Qri: "a"}, &Meta{Qri: "b"}, "Qri: a != b"},
4646
{&Meta{Title: "a"}, &Meta{Title: "b"}, "Title: a != b"},
4747
{&Meta{AccessPath: "a"}, &Meta{AccessPath: "b"}, "AccessPath: a != b"},
4848
{&Meta{DownloadPath: "a"}, &Meta{DownloadPath: "b"}, "DownloadPath: a != b"},
@@ -76,7 +76,7 @@ func TestCompareStructures(t *testing.T) {
7676
{AirportCodes.Structure, AirportCodes.Structure, ""},
7777
{nil, AirportCodes.Structure, "nil: <nil> != <not nil>"},
7878
{AirportCodes.Structure, nil, "nil: <not nil> != <nil>"},
79-
{&Structure{Kind: "a"}, &Structure{Kind: "b"}, "Kind: a != b"},
79+
{&Structure{Qri: "a"}, &Structure{Qri: "b"}, "Qri: a != b"},
8080
{&Structure{Length: 0}, &Structure{Length: 1}, "Length: 0 != 1"},
8181
{&Structure{Entries: 0}, &Structure{Entries: 1}, "Entries: 0 != 1"},
8282
{&Structure{Checksum: "a"}, &Structure{Checksum: "b"}, "Checksum: a != b"},
@@ -151,7 +151,7 @@ func TestCompareCommits(t *testing.T) {
151151
path: datastore.NewKey("/foo"),
152152
Title: "foo",
153153
Message: "message",
154-
Kind: KindCommit,
154+
Qri: KindCommit,
155155
Author: &User{ID: "foo"},
156156
}
157157

@@ -171,7 +171,7 @@ func TestCompareCommits(t *testing.T) {
171171
},
172172
{&Commit{Title: "a"}, &Commit{Title: "b"}, "Title: a != b"},
173173
{&Commit{Message: "a"}, &Commit{Message: "b"}, "Message: a != b"},
174-
{&Commit{Kind: "a"}, &Commit{Kind: "b"}, "Kind: a != b"},
174+
{&Commit{Qri: "a"}, &Commit{Qri: "b"}, "Qri: a != b"},
175175
{&Commit{Signature: "a"}, &Commit{Signature: "b"}, "Signature: a != b"},
176176
}
177177

@@ -185,7 +185,7 @@ func TestCompareCommits(t *testing.T) {
185185

186186
func TestCompareTransforms(t *testing.T) {
187187
t1 := &Transform{
188-
Kind: KindTransform,
188+
Qri: KindTransform,
189189
Syntax: "sql",
190190
AppVersion: "1000.0.0",
191191
Data: "select * from airports limit 10",
@@ -204,7 +204,7 @@ func TestCompareTransforms(t *testing.T) {
204204
{nil, t1, "nil: <nil> != <not nil>"},
205205
{&Transform{}, &Transform{}, ""},
206206
{NewTransformRef(datastore.NewKey("a")), NewTransformRef(datastore.NewKey("b")), "path: /a != /b"},
207-
{&Transform{Kind: "a"}, &Transform{Kind: "b"}, "Kind: a != b"},
207+
{&Transform{Qri: "a"}, &Transform{Qri: "b"}, "Qri: a != b"},
208208
{&Transform{Syntax: "a"}, &Transform{Syntax: "b"}, "Syntax: a != b"},
209209
{&Transform{AppVersion: "a"}, &Transform{AppVersion: "b"}, "AppVersion: a != b"},
210210
{&Transform{Data: "a"}, &Transform{Data: "b"}, "Data: a != b"},

dataset.go

+7-16
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type Dataset struct {
3535
Commit *Commit `json:"commit,omitempty"`
3636
// DataPath is the path to the hash of raw data as it resolves on the network.
3737
DataPath string `json:"dataPath,omitempty"`
38-
// Kind is required, must be qri:ds:[version]
39-
Kind Kind `json:"kind"`
4038
// Meta contains all human-readable meta about this dataset
4139
Meta *Meta `json:"meta,omitempty"`
4240
// PreviousPath connects datasets to form a historical DAG
4341
PreviousPath string `json:"previousPath,omitempty"`
42+
// Qri is required, must be ds:[version]
43+
Qri Kind `json:"qri"`
4444
// Structure of this dataset
4545
Structure *Structure `json:"structure"`
4646
// Transform is a path to the transformation that generated this resource
@@ -74,7 +74,7 @@ func NewDatasetRef(path datastore.Key) *Dataset {
7474
// semantically-identifiable and concrete references replaced with
7575
// uniform values
7676
func Abstract(ds *Dataset) *Dataset {
77-
abs := &Dataset{Kind: ds.Kind}
77+
abs := &Dataset{Qri: ds.Qri}
7878
if ds.Structure != nil {
7979
abs.Structure = &Structure{}
8080
abs.Structure.Assign(ds.Structure.Abstract())
@@ -130,6 +130,7 @@ func (ds *Dataset) Assign(datasets ...*Dataset) {
130130
if d.PreviousPath != "" {
131131
ds.PreviousPath = d.PreviousPath
132132
}
133+
// TODO - wut dis?
133134
ds.Commit.Assign(d.Commit)
134135
}
135136
}
@@ -142,8 +143,8 @@ func (ds *Dataset) MarshalJSON() ([]byte, error) {
142143
if ds.path.String() != "" && ds.IsEmpty() {
143144
return ds.path.MarshalJSON()
144145
}
145-
if ds.Kind == "" {
146-
ds.Kind = KindDataset
146+
if ds.Qri == "" {
147+
ds.Qri = KindDataset
147148
}
148149

149150
return json.Marshal(_dataset(*ds))
@@ -167,17 +168,7 @@ func (ds *Dataset) UnmarshalJSON(data []byte) error {
167168
return fmt.Errorf("error unmarshling dataset: %s", err.Error())
168169
}
169170

170-
*ds = Dataset{
171-
Abstract: d.Abstract,
172-
AbstractTransform: d.AbstractTransform,
173-
Commit: d.Commit,
174-
DataPath: d.DataPath,
175-
Kind: d.Kind,
176-
Meta: d.Meta,
177-
PreviousPath: d.PreviousPath,
178-
Structure: d.Structure,
179-
Transform: d.Transform,
180-
}
171+
*ds = Dataset(d)
181172
return nil
182173
}
183174

dataset_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestDatasetMarshalJSON(t *testing.T) {
6363
out []byte
6464
err error
6565
}{
66-
{&Dataset{}, []byte(`{"kind":"qri:ds:0","structure":null}`), nil},
66+
{&Dataset{}, []byte(`{"qri":"ds:0","structure":null}`), nil},
6767
{AirportCodes, []byte(AirportCodesJSON), nil},
6868
}
6969

@@ -202,15 +202,15 @@ func TestAbstract(t *testing.T) {
202202
}
203203

204204
func TestUnmarshalDataset(t *testing.T) {
205-
dsa := Dataset{Kind: KindDataset}
205+
dsa := Dataset{Qri: KindDataset}
206206
cases := []struct {
207207
value interface{}
208208
out *Dataset
209209
err string
210210
}{
211211
{dsa, &dsa, ""},
212212
{&dsa, &dsa, ""},
213-
{[]byte("{\"kind\":\"qri:ds:0\"}"), &Dataset{Kind: KindDataset}, ""},
213+
{[]byte("{\"qri\":\"ds:0\"}"), &Dataset{Qri: KindDataset}, ""},
214214
{5, nil, "couldn't parse dataset, value is invalid type"},
215215
}
216216

dsfs/dataset_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ func TestCreateDataset(t *testing.T) {
140140
}{
141141
{"testdata/bad/invalid_reference.json", "testdata/cities.csv", "", "", 0, "error loading dataset commit: error loading commit file: datastore: key not found"},
142142
{"testdata/bad/invalid.json", "testdata/cities.csv", "", "", 0, "commit is required"},
143-
{"testdata/cities.json", "testdata/cities.csv", "cities.csv", "/map/QmPQTHtqa759DwXFGeuAr6euhfVqTP93cugC9r7JxAfP2q", 6, ""},
144-
{"testdata/complete.json", "testdata/complete.csv", "complete.csv", "/map/QmTiL676gcpc6yQkumRDkxKGBYdRtaraZ6q5k58B3QgSjq", 13, ""},
143+
{"testdata/cities.json", "testdata/cities.csv", "cities.csv", "/map/QmYsnYBrS6mcga94M792uhaBRvNZSyE9y96p9koxxnPmPo", 6, ""},
144+
{"testdata/complete.json", "testdata/complete.csv", "complete.csv", "/map/QmRsQAKAqPLv5hiCvWKdhHQxPZxzXMc8obbULg8E8zWNqS", 13, ""},
145145
}
146146

147147
for i, c := range cases {

dsfs/testdata/archive.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"title": "example cdxj index archive",
33
"timestamp": "2017-01-01T01:00:00.000Z",
4-
"kind": "qri:ds:0",
4+
"qri": "ds:0",
55
"structure": {
66
"format": "cdxj",
7-
"kind": "qri:st:0",
7+
"qri": "st:0",
88
"schema": {
99
"type": "array",
1010
"items": {

dsfs/testdata/cities.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"meta": {
3-
"kind": "qri:md:0",
3+
"qri": "md:0",
44
"title": "example city data"
55
},
66
"commit": {
7-
"kind": "qri:cm:0",
7+
"qri": "cm:0",
88
"title": "initial commit"
99
},
10-
"kind": "qri:ds:0",
10+
"qri": "ds:0",
1111
"structure": {
12-
"kind": "qri:st:0",
12+
"qri": "st:0",
1313
"format": "csv",
1414
"formatConfig": {
1515
"headerRow": true

dsfs/testdata/complete.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"kind": "qri:ds:0",
2+
"qri": "ds:0",
33
"commit": {
4-
"kind": "qri:cm:0",
4+
"qri": "cm:0",
55
"title": "I'm a commit"
66
},
77
"meta": {
8-
"kind": "qri:md:0",
8+
"qri": "md:0",
99
"title": "dataset with all submodels example"
1010
},
1111
"transform": {
12-
"kind": "qri:tf:0",
12+
"qri": "tf:0",
1313
"syntax": "sql",
1414
"data": "select * from foo",
1515
"structure": {
16-
"kind": "qri:st:0",
16+
"qri": "st:0",
1717
"format": "csv",
1818
"formatConfig": {
1919
"headerRow": true
@@ -40,10 +40,10 @@
4040
}
4141
},
4242
"abstractTransform": {
43-
"kind": "qri:tf:0",
43+
"qri": "tf:0",
4444
"data": "select * from a",
4545
"structure": {
46-
"kind": "qri:st:0",
46+
"qri": "st:0",
4747
"format": "csv",
4848
"formatConfig": {
4949
"headerRow": true
@@ -70,9 +70,9 @@
7070
}
7171
},
7272
"abstract": {
73-
"kind": "qri:ds:0",
73+
"qri": "ds:0",
7474
"structure": {
75-
"kind": "qri:st:0",
75+
"qri": "st:0",
7676
"format": "csv",
7777
"formatConfig": {
7878
"headerRow": true
@@ -96,7 +96,7 @@
9696
}
9797
},
9898
"structure": {
99-
"kind": "qri:st:0",
99+
"qri": "st:0",
100100
"format": "csv",
101101
"formatConfig": {
102102
"headerRow": true

0 commit comments

Comments
 (0)