Skip to content

Commit

Permalink
refactor: Rename key,id,dockey to docID terminology (#1749)
Browse files Browse the repository at this point in the history
## Relevant issue(s)
- Subtask of #1750 [EPIC]
- [x] Resolves #1752
- [x] Resolves #1272


## BREAKING CHANGE:
- Use of `_key` to access a document's unique id is now deprecated,
instead use `_docID`.
- Use of `dockey`/`id` is now deprecated, instead use `docID`.
- Use of `dockeys`/`ids` is now deprecated, instead use `docIDs`.


## Description
- [x] Rename `_key` to `_docID` everywhere.
- [x] Rename `_keys` to `docIDs` in explain the response.
- [x] Rename `_newKey` to `_docIDNew` in backup/recover functionality.
- [x] Fix `_docID` tests.
- [x] Fix explain and backup/recover functionality tests.
- [x] Fix the collectionID order for a P2P test (leaving a note as order
was reverted).
- [x] Update all cids.
- [x] Rename all files with `key(s)|dockey(s)` in the name to
`doc_id(s)`.
- [x] Document breaking change to pass change detector.

## For Reviewers:
- Main commits to review are the `PR(MAIN)` commits. 
- If you have more time `PR(MINOR) and PR(*TEST)` commits are good to go
over


## Disclaimer / Discussion:
I do not like these non-underscored `docID/docIDs`, would be in favor of
underscoring these :

```
query {
    User(docIDs: ["bae-6a6482a8-24e1-5c73-a237-ca569e41507d"]) {
        _docID
    }
}
```

```
query {
    Users {
        Name
        _docID
        _version {
            docID
        }
    }
}
```

```
Request: ` {
    commits(groupBy: [docID], order: {docID: DESC}) {
        docID
    }
}`,
Results: []map[string]any{
    {
        "docID": "bae-f54b9689-e06e-5e3a-89b3-f3aee8e64ca7",
    },
    {
        "docID": "bae-72f3dc53-1846-55d5-915c-28c4e83cc891",
    },
},

```

EDIT: Above was resolved with #2162, to do out of this PR.


## Limitations (out of scope of this PR):
- #1467
- #1751
- #1550
- #2162
  • Loading branch information
shahzadlone authored Jan 4, 2024
1 parent b774ff1 commit 9da4dab
Show file tree
Hide file tree
Showing 281 changed files with 3,026 additions and 3,212 deletions.
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(),
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 @@ import (
)

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 @@ Example: delete by filter
}

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)
if err != nil {
return err
}
docKeys[i] = docKey
docIDs[i] = docID
}
res, err := col.DeleteWithKeys(cmd.Context(), docKeys)
res, err := col.DeleteWithDocIDs(cmd.Context(), docIDs)
if err != nil {
return err
}
Expand All @@ -68,11 +68,11 @@ Example: delete by filter
}
return writeJSON(cmd, res)
default:
return ErrNoDocKeyOrFilter
return ErrNoDocIDOrFilter
}
},
}
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 @@ import (
"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())
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(),
}
if docKey.Err != nil {
results.Error = docKey.Err.Error()
if docIDResult.Err != nil {
results.Error = docIDResult.Err.Error()
}
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 @@ import (
)

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 @@ Example: update by keys
}

switch {
case len(keys) == 1 && updater != "":
docKey, err := client.NewDocKeyFromString(keys[0])
case len(argDocIDs) == 1 && updater != "":
docID, err := client.NewDocIDFromString(argDocIDs[0])
if err != nil {
return err
}
res, err := col.UpdateWithKey(cmd.Context(), docKey, updater)
res, err := col.UpdateWithDocID(cmd.Context(), docID, updater)
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)
if err != nil {
return err
}
docKeys[i] = docKey
docIDs[i] = docID
}
res, err := col.UpdateWithKeys(cmd.Context(), docKeys, updater)
res, err := col.UpdateWithDocIDs(cmd.Context(), docIDs, updater)
if err != nil {
return err
}
Expand All @@ -74,12 +74,12 @@ Example: update by keys
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 @@ Example: update by keys
}
return col.Update(cmd.Context(), doc)
default:
return ErrNoDocKeyOrFilter
return ErrNoDocIDOrFilter
}
},
}
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": "",
"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

0 comments on commit 9da4dab

Please sign in to comment.