Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 11 additions & 12 deletions scripts/fixup_firestore_admin_v1_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
raise ImportError('Run `python -m pip install "libcst >= 0.2.5"` to install libcst.')



import pathlib
import sys
from typing import (Any, Callable, Dict, List, Sequence, Tuple)
Expand All @@ -45,15 +44,15 @@ def partition(
class firestore_adminCallTransformer(cst.CSTTransformer):
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'create_index': ('parent', 'index', ),
'delete_index': ('name', ),
'export_documents': ('name', 'collection_ids', 'output_uri_prefix', ),
'get_field': ('name', ),
'get_index': ('name', ),
'import_documents': ('name', 'collection_ids', 'input_uri_prefix', ),
'list_fields': ('parent', 'filter', 'page_size', 'page_token', ),
'list_indexes': ('parent', 'filter', 'page_size', 'page_token', ),
'update_field': ('field', 'update_mask', ),
'create_index': ('parent', 'index', ),
'delete_index': ('name', ),
'export_documents': ('name', 'collection_ids', 'output_uri_prefix', ),
'get_field': ('name', ),
'get_index': ('name', ),
'import_documents': ('name', 'collection_ids', 'input_uri_prefix', ),
'list_fields': ('parent', 'filter', 'page_size', 'page_token', ),
'list_indexes': ('parent', 'filter', 'page_size', 'page_token', ),
'update_field': ('field', 'update_mask', ),
}

def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
Expand All @@ -72,7 +71,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
return updated

kwargs, ctrl_kwargs = partition(
lambda a: not a.keyword.value in self.CTRL_PARAMS,
lambda a: a.keyword.value not in self.CTRL_PARAMS,
kwargs
)

Expand All @@ -84,7 +83,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
value=cst.Dict([
cst.DictElement(
cst.SimpleString("'{}'".format(name)),
cst.Element(value=arg.value)
cst.Element(value=arg.value)
)
# Note: the args + kwargs looks silly, but keep in mind that
# the control parameters had to be stripped out, and that
Expand Down
35 changes: 17 additions & 18 deletions scripts/fixup_firestore_v1_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
raise ImportError('Run `python -m pip install "libcst >= 0.2.5"` to install libcst.')



import pathlib
import sys
from typing import (Any, Callable, Dict, List, Sequence, Tuple)
Expand All @@ -45,21 +44,21 @@ def partition(
class firestoreCallTransformer(cst.CSTTransformer):
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'batch_get_documents': ('database', 'documents', 'mask', 'transaction', 'new_transaction', 'read_time', ),
'batch_write': ('database', 'writes', 'labels', ),
'begin_transaction': ('database', 'options', ),
'commit': ('database', 'writes', 'transaction', ),
'create_document': ('parent', 'collection_id', 'document', 'document_id', 'mask', ),
'delete_document': ('name', 'current_document', ),
'get_document': ('name', 'mask', 'transaction', 'read_time', ),
'list_collection_ids': ('parent', 'page_size', 'page_token', ),
'list_documents': ('parent', 'collection_id', 'page_size', 'page_token', 'order_by', 'mask', 'transaction', 'read_time', 'show_missing', ),
'listen': ('database', 'add_target', 'remove_target', 'labels', ),
'partition_query': ('parent', 'structured_query', 'partition_count', 'page_token', 'page_size', ),
'rollback': ('database', 'transaction', ),
'run_query': ('parent', 'structured_query', 'transaction', 'new_transaction', 'read_time', ),
'update_document': ('document', 'update_mask', 'mask', 'current_document', ),
'write': ('database', 'stream_id', 'writes', 'stream_token', 'labels', ),
'batch_get_documents': ('database', 'documents', 'mask', 'transaction', 'new_transaction', 'read_time', ),
'batch_write': ('database', 'writes', 'labels', ),
'begin_transaction': ('database', 'options', ),
'commit': ('database', 'writes', 'transaction', ),
'create_document': ('parent', 'collection_id', 'document', 'document_id', 'mask', ),
'delete_document': ('name', 'current_document', ),
'get_document': ('name', 'mask', 'transaction', 'read_time', ),
'list_collection_ids': ('parent', 'page_size', 'page_token', ),
'list_documents': ('parent', 'collection_id', 'page_size', 'page_token', 'order_by', 'mask', 'transaction', 'read_time', 'show_missing', ),
'listen': ('database', 'add_target', 'remove_target', 'labels', ),
'partition_query': ('parent', 'structured_query', 'partition_count', 'page_token', 'page_size', ),
'rollback': ('database', 'transaction', ),
'run_query': ('parent', 'structured_query', 'transaction', 'new_transaction', 'read_time', ),
'update_document': ('document', 'update_mask', 'mask', 'current_document', ),
'write': ('database', 'stream_id', 'writes', 'stream_token', 'labels', ),
}

def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
Expand All @@ -78,7 +77,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
return updated

kwargs, ctrl_kwargs = partition(
lambda a: not a.keyword.value in self.CTRL_PARAMS,
lambda a: a.keyword.value not in self.CTRL_PARAMS,
kwargs
)

Expand All @@ -90,7 +89,7 @@ def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:
value=cst.Dict([
cst.DictElement(
cst.SimpleString("'{}'".format(name)),
cst.Element(value=arg.value)
cst.Element(value=arg.value)
)
# Note: the args + kwargs looks silly, but keep in mind that
# the control parameters had to be stripped out, and that
Expand Down