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

refactor: Rename key,id,dockey to docID terminology #1749

Merged
merged 35 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c16cac8
PR(UNRELATED): Add rules to quickly run sub-tests
shahzadlone Oct 5, 2023
027b221
PR(UNRELATED): Remove unused http errors
shahzadlone Oct 5, 2023
9839ee4
PR(MAIN): Rename `_key` to `_docID`
shahzadlone Dec 21, 2023
81c3a73
PR(TEST): Apply renaming within unit tests
shahzadlone Oct 19, 2023
9908bf9
PR(DOCS): Apply renaming in GQL examples
shahzadlone Aug 1, 2023
e450339
PR(DOCS): Apply renaming in markdown documents
shahzadlone Aug 1, 2023
5a836a0
PR(INT-TEST): Apply renaming to framework utils2
shahzadlone Sep 7, 2023
2c808d1
PR(INT-TEST): Rename events,net,subscription tests
shahzadlone Oct 19, 2023
0391537
PR(INT-TEST): Apply renaming of schema intg. tests
shahzadlone Aug 1, 2023
50d04bc
PR(TEST): Apply renaming to bench tests.
shahzadlone Aug 1, 2023
ca62a88
PR(INT-TEST): Rename in query, mutation tests
shahzadlone Oct 19, 2023
2c2f8c5
PR(MAIN): Rename in backup/recover & rename tests
shahzadlone Dec 18, 2023
3f69cec
PR(INT-TEST): Apply renaming on explain int tests
shahzadlone Sep 28, 2023
26a1b3c
PR(MAIN): Rename `id/ids` to `docID/docIDs`
shahzadlone Oct 5, 2023
ea69e41
PR(MAIN): Rename `dockey/dockeys` to `docID(s)`
shahzadlone Dec 18, 2023
b858b6e
PR(MAIN): Rename explain's `docKeys` attribute
shahzadlone Dec 18, 2023
23a3065
PR(FIX): Update test because collection id changed
shahzadlone Aug 3, 2023
b9d0c22
PR(FIX-CIDs): Changed order in get_schema_test.go
shahzadlone Dec 18, 2023
28218e6
PR(FIX-CIDs): Update all non-lens cids
shahzadlone Dec 18, 2023
5d6abe9
PR(FIX-CIDs): Update all lens(migrations) cids
shahzadlone Dec 20, 2023
c1eef20
PR(MAIN): Rename all other dockey terminology
shahzadlone Dec 21, 2023
b300c78
PR(MAIN): Update net dockey naming, gen proto code
shahzadlone Dec 21, 2023
698ff8c
PR(RENAME-CONST): Rename const to `DocIDFieldName`
shahzadlone Dec 21, 2023
e964ced
PR(MAIN): Rename cli version information
shahzadlone Dec 21, 2023
e4d49b9
PR(TESTS): Rename test, utility dockey terms
shahzadlone Dec 21, 2023
fb63501
PR(TESTS): Rename tests with `key|Key` terms
shahzadlone Jan 3, 2024
eef9261
PR(RESOLVE-CONFLICT): Fix conflict from views PR
shahzadlone Dec 21, 2023
4721944
PR(MOCKS): Update mocks according to the renaming
shahzadlone Dec 21, 2023
aaea6f1
PR(GEN-DOC): Generate documentation after renaming
shahzadlone Dec 21, 2023
cb6e81b
PR(MAIN): Rename the delta arg. cids to be updated
shahzadlone Dec 21, 2023
0b6a4a0
PR(FIX-CID): Fix CIDs post Delta Arg. renaming
shahzadlone Jan 2, 2024
7ee100f
PR(MINOR): Rename filenames, `dockey` to `doc_id`
shahzadlone Jan 3, 2024
87301f4
PR(MINOR): Rename filenames, `key` to `doc_id`
shahzadlone Jan 3, 2024
1ca4954
PR(CHANGE-DETECTOR): Document BREAKING CHANGES
shahzadlone Jan 2, 2024
958d215
PR(ADHERE-FEEDBACK): Make review suggestions.
shahzadlone Jan 4, 2024
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
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,26 @@ test\:cli:
test\:names:
gotestsum --format testname -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)

.PHONY: test\:lens
test\:lens:
@$(MAKE) deps:lens
gotestsum --format testname -- ./$(LENS_TEST_DIRECTORY)/... $(TEST_FLAGS)

.PHONY: test\:lens-quick
test\:lens-quick:
@$(MAKE) deps:lens
gotestsum --format testname -- ./$(LENS_TEST_DIRECTORY)/...

.PHONY: test\:all
test\:all:
@$(MAKE) test:names
@$(MAKE) test:lens

.PHONY: test\:all-quick
test\:all-quick:
@$(MAKE) test:quick
@$(MAKE) test:lens-quick

.PHONY: test\:verbose
test\:verbose:
gotestsum --format standard-verbose -- $(DEFAULT_TEST_DIRECTORIES) $(TEST_FLAGS)
Expand All @@ -246,11 +261,6 @@ test\:bench-short:
test\:scripts:
@$(MAKE) -C ./tools/scripts/ test

.PHONY: test\:lens
test\:lens:
@$(MAKE) deps:lens
gotestsum --format testname -- ./$(LENS_TEST_DIRECTORY)/... $(TEST_FLAGS)

.PHONY: test\:coverage
test\:coverage:
@$(MAKE) deps:lens
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Submit a `mutation` request to create a document of the `User` type:
defradb client query '
mutation {
create_User(data: "{\"age\": 31, \"verified\": true, \"points\": 90, \"name\": \"Bob\"}") {
_key
_docID
}
}
'
Expand All @@ -113,13 +113,13 @@ Expected response:
{
"data": [
{
"_key": "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab",
"_docID": "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab",
}
]
}
```

`_key` is the document's key, a unique identifier of the document, determined by its schema and initial data.
`_docID` is the document's unique identifier determined by its schema and initial data.

## Query documents

Expand All @@ -129,7 +129,7 @@ Once you have populated your node with data, you can query it:
defradb client query '
query {
User {
_key
_docID
age
name
points
Expand All @@ -138,15 +138,15 @@ defradb client query '
'
```

This query obtains *all* users and returns their fields `_key, age, name, points`. GraphQL queries only return the exact fields requested.
This query obtains *all* users and returns their fields `_docID, age, name, points`. GraphQL queries only return the exact fields requested.

You can further filter results with the `filter` argument.

```shell
defradb client query '
query {
User(filter: {points: {_ge: 50}}) {
_key
_docID
age
name
points
Expand All @@ -166,7 +166,7 @@ To get the most recent commit in the MerkleDAG for the document identified as `b
```shell
defradb client query '
query {
latestCommits(dockey: "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab") {
latestCommits(docID: "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab") {
cid
delta
height
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewDefraCommand(cfg *config.Config) *cobra.Command {
collection := MakeCollectionCommand(cfg)
collection.AddCommand(
MakeCollectionGetCommand(),
MakeCollectionKeysCommand(),
MakeCollectionListDocIDsCommand(),
shahzadlone marked this conversation as resolved.
Show resolved Hide resolved
MakeCollectionDeleteCommand(),
MakeCollectionUpdateCommand(),
MakeCollectionCreateCommand(),
Expand Down
34 changes: 17 additions & 17 deletions cli/collection_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
)

func MakeCollectionDeleteCommand() *cobra.Command {
var keys []string
var argDocIDs []string
var filter string
var cmd = &cobra.Command{
Use: "delete [--filter <filter> --key <key>]",
Short: "Delete documents by key or filter.",
Long: `Delete documents by key or filter and lists the number of documents deleted.
Use: "delete [--filter <filter> --docID <docID>]",
Short: "Delete documents by docID or filter.",
Long: `Delete documents by docID or filter and lists the number of documents deleted.

Example: delete by key(s)
defradb client collection delete --name User --key bae-123,bae-456
Example: delete by docID(s)
defradb client collection delete --name User --docID bae-123,bae-456

Example: delete by filter
defradb client collection delete --name User --filter '{ "_gte": { "points": 100 } }'
Expand All @@ -37,26 +37,26 @@
}

switch {
case len(keys) == 1:
docKey, err := client.NewDocKeyFromString(keys[0])
case len(argDocIDs) == 1:
docID, err := client.NewDocIDFromString(argDocIDs[0])
if err != nil {
return err
}
res, err := col.DeleteWithKey(cmd.Context(), docKey)
res, err := col.DeleteWithDocID(cmd.Context(), docID)
if err != nil {
return err
}
return writeJSON(cmd, res)
case len(keys) > 1:
docKeys := make([]client.DocKey, len(keys))
for i, v := range keys {
docKey, err := client.NewDocKeyFromString(v)
case len(argDocIDs) > 1:
docIDs := make([]client.DocID, len(argDocIDs))
for i, v := range argDocIDs {
docID, err := client.NewDocIDFromString(v)

Check warning on line 53 in cli/collection_delete.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_delete.go#L50-L53

Added lines #L50 - L53 were not covered by tests
if err != nil {
return err
}
docKeys[i] = docKey
docIDs[i] = docID

Check warning on line 57 in cli/collection_delete.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_delete.go#L57

Added line #L57 was not covered by tests
}
res, err := col.DeleteWithKeys(cmd.Context(), docKeys)
res, err := col.DeleteWithDocIDs(cmd.Context(), docIDs)

Check warning on line 59 in cli/collection_delete.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_delete.go#L59

Added line #L59 was not covered by tests
if err != nil {
return err
}
Expand All @@ -68,11 +68,11 @@
}
return writeJSON(cmd, res)
default:
return ErrNoDocKeyOrFilter
return ErrNoDocIDOrFilter

Check warning on line 71 in cli/collection_delete.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_delete.go#L71

Added line #L71 was not covered by tests
}
},
}
cmd.Flags().StringSliceVar(&keys, "key", nil, "Document key")
cmd.Flags().StringSliceVar(&argDocIDs, "docID", nil, "Document ID")
cmd.Flags().StringVar(&filter, "filter", "", "Document filter")
return cmd
}
6 changes: 3 additions & 3 deletions cli/collection_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func MakeCollectionGetCommand() *cobra.Command {
var showDeleted bool
var cmd = &cobra.Command{
Use: "get <docKey> [--show-deleted]",
Use: "get <docID> [--show-deleted]",
Short: "View document fields.",
Long: `View document fields.

Expand All @@ -33,11 +33,11 @@ Example:
return cmd.Usage()
}

docKey, err := client.NewDocKeyFromString(args[0])
docID, err := client.NewDocIDFromString(args[0])
if err != nil {
return err
}
doc, err := col.Get(cmd.Context(), docKey, showDeleted)
doc, err := col.Get(cmd.Context(), docID, showDeleted)
if err != nil {
return err
}
Expand Down
22 changes: 11 additions & 11 deletions cli/collection_keys.go → cli/collection_list_doc_ids.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
"github.com/sourcenetwork/defradb/http"
)

func MakeCollectionKeysCommand() *cobra.Command {
func MakeCollectionListDocIDsCommand() *cobra.Command {
var cmd = &cobra.Command{
Use: "keys",
Short: "List all document keys.",
Long: `List all document keys.
Use: "docIDs",
Short: "List all document IDs (docIDs).",
Long: `List all document IDs (docIDs).

Example:
defradb client collection keys --name User
defradb client collection docIDs --name User
`,
RunE: func(cmd *cobra.Command, args []string) error {
col, ok := tryGetCollectionContext(cmd)
if !ok {
return cmd.Usage()
}

docCh, err := col.GetAllDocKeys(cmd.Context())
docCh, err := col.GetAllDocIDs(cmd.Context())

Check warning on line 34 in cli/collection_list_doc_ids.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_list_doc_ids.go#L34

Added line #L34 was not covered by tests
if err != nil {
return err
}
for docKey := range docCh {
results := &http.DocKeyResult{
Key: docKey.Key.String(),
for docIDResult := range docCh {
results := &http.DocIDResult{
DocID: docIDResult.ID.String(),

Check warning on line 40 in cli/collection_list_doc_ids.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_list_doc_ids.go#L38-L40

Added lines #L38 - L40 were not covered by tests
}
if docKey.Err != nil {
results.Error = docKey.Err.Error()
if docIDResult.Err != nil {
results.Error = docIDResult.Err.Error()

Check warning on line 43 in cli/collection_list_doc_ids.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_list_doc_ids.go#L42-L43

Added lines #L42 - L43 were not covered by tests
}
if err := writeJSON(cmd, results); err != nil {
return err
Expand Down
42 changes: 21 additions & 21 deletions cli/collection_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@
)

func MakeCollectionUpdateCommand() *cobra.Command {
var keys []string
var argDocIDs []string
var filter string
var updater string
var cmd = &cobra.Command{
Use: "update [--filter <filter> --key <key> --updater <updater>] <document>",
Short: "Update documents by key or filter.",
Long: `Update documents by key or filter.
Use: "update [--filter <filter> --docID <docID> --updater <updater>] <document>",
Short: "Update documents by docID or filter.",
Long: `Update documents by docID or filter.

Example: update from string
defradb client collection update --name User --key bae-123 '{ "name": "Bob" }'
defradb client collection update --name User --docID bae-123 '{ "name": "Bob" }'

Example: update by filter
defradb client collection update --name User \
--filter '{ "_gte": { "points": 100 } }' --updater '{ "verified": true }'

Example: update by keys
Example: update by docIDs
defradb client collection update --name User \
--key bae-123,bae-456 --updater '{ "verified": true }'
--docID bae-123,bae-456 --updater '{ "verified": true }'
`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -44,26 +44,26 @@
}

switch {
case len(keys) == 1 && updater != "":
docKey, err := client.NewDocKeyFromString(keys[0])
case len(argDocIDs) == 1 && updater != "":
docID, err := client.NewDocIDFromString(argDocIDs[0])

Check warning on line 48 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L47-L48

Added lines #L47 - L48 were not covered by tests
if err != nil {
return err
}
res, err := col.UpdateWithKey(cmd.Context(), docKey, updater)
res, err := col.UpdateWithDocID(cmd.Context(), docID, updater)

Check warning on line 52 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L52

Added line #L52 was not covered by tests
if err != nil {
return err
}
return writeJSON(cmd, res)
case len(keys) > 1 && updater != "":
docKeys := make([]client.DocKey, len(keys))
for i, v := range keys {
docKey, err := client.NewDocKeyFromString(v)
case len(argDocIDs) > 1 && updater != "":
docIDs := make([]client.DocID, len(argDocIDs))
for i, v := range argDocIDs {
docID, err := client.NewDocIDFromString(v)

Check warning on line 60 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L57-L60

Added lines #L57 - L60 were not covered by tests
if err != nil {
return err
}
docKeys[i] = docKey
docIDs[i] = docID

Check warning on line 64 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L64

Added line #L64 was not covered by tests
}
res, err := col.UpdateWithKeys(cmd.Context(), docKeys, updater)
res, err := col.UpdateWithDocIDs(cmd.Context(), docIDs, updater)

Check warning on line 66 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L66

Added line #L66 was not covered by tests
if err != nil {
return err
}
Expand All @@ -74,12 +74,12 @@
return err
}
return writeJSON(cmd, res)
case len(keys) == 1 && len(args) == 1:
docKey, err := client.NewDocKeyFromString(keys[0])
case len(argDocIDs) == 1 && len(args) == 1:
docID, err := client.NewDocIDFromString(argDocIDs[0])
if err != nil {
return err
}
doc, err := col.Get(cmd.Context(), docKey, true)
doc, err := col.Get(cmd.Context(), docID, true)
if err != nil {
return err
}
Expand All @@ -88,11 +88,11 @@
}
return col.Update(cmd.Context(), doc)
default:
return ErrNoDocKeyOrFilter
return ErrNoDocIDOrFilter

Check warning on line 91 in cli/collection_update.go

View check run for this annotation

Codecov / codecov/patch

cli/collection_update.go#L91

Added line #L91 was not covered by tests
}
},
}
cmd.Flags().StringSliceVar(&keys, "key", nil, "Document key")
cmd.Flags().StringSliceVar(&argDocIDs, "docID", nil, "Document ID")
cmd.Flags().StringVar(&filter, "filter", "", "Document filter")
cmd.Flags().StringVar(&updater, "updater", "", "Document updater")
return cmd
Expand Down
2 changes: 1 addition & 1 deletion cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
var (
ErrNoDocOrFile = errors.New("document or file must be defined")
ErrInvalidDocument = errors.New("invalid document")
ErrNoDocKeyOrFilter = errors.New("document key or filter must be defined")
ErrNoDocIDOrFilter = errors.New("docID or filter must be defined")
ErrInvalidExportFormat = errors.New("invalid export format")
ErrNoLensConfig = errors.New("lens config cannot be empty")
ErrInvalidLensConfig = errors.New("invalid lens configuration")
Expand Down
18 changes: 9 additions & 9 deletions cli/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestVersionFull(t *testing.T) {
assert.NoError(t, err)
t.Log(buf.String())
assert.Contains(t, buf.String(), "* HTTP API")
assert.Contains(t, buf.String(), "* DocKey versions")
assert.Contains(t, buf.String(), "* DocID versions")
assert.Contains(t, buf.String(), "* P2P multicodec")
}

Expand All @@ -59,11 +59,11 @@ func TestVersionJSON(t *testing.T) {
{
"release": "",
"commit": "",
"commitdate": "",
shahzadlone marked this conversation as resolved.
Show resolved Hide resolved
"commitDate": "",
"go": "",
"httpapi": "v0",
"dockeyversions": "1",
"netprotocol": "/defra/0.0.1"
"httpAPI": "v0",
"docIDVersions": "1",
"netProtocol": "/defra/0.0.1"
}`)
}

Expand All @@ -80,10 +80,10 @@ func TestVersionJSONFull(t *testing.T) {
{
"release": "",
"commit": "",
"commitdate": "",
"commitDate": "",
"go": "",
"httpapi": "v0",
"dockeyversions": "1",
"netprotocol": "/defra/0.0.1"
"httpAPI": "v0",
"docIDVersions": "1",
"netProtocol": "/defra/0.0.1"
}`)
}
Loading
Loading