polyapi-python 0.3.11.dev2__py3-none-any.whl → 0.3.11.dev4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
polyapi/cli.py CHANGED
@@ -42,13 +42,15 @@ def execute_from_cli():
42
42
 
43
43
  ###########################################################################
44
44
  # Setup command
45
+
45
46
  setup_parser = subparsers.add_parser("setup", help="Setup your Poly connection")
46
- setup_parser.add_argument("api_key", nargs="?", help="API key for Poly API")
47
47
  setup_parser.add_argument("url", nargs="?", help="URL for the Poly API")
48
+ setup_parser.add_argument("api_key", nargs="?", help="API key for Poly API")
49
+
48
50
 
49
51
  def setup(args):
50
- api_key = args.api_key or os.getenv("POLY_API_KEY")
51
52
  url = args.url or os.getenv("POLY_API_BASE_URL")
53
+ api_key = args.api_key or os.getenv("POLY_API_KEY")
52
54
 
53
55
  if api_key and url:
54
56
  set_api_key_and_url(url, api_key)
@@ -56,7 +58,7 @@ def execute_from_cli():
56
58
  initialize_config(force=True)
57
59
  # setup command should have default cache values
58
60
  from .config import cache_generate_args
59
- cache_generate_args(contexts=None, names=None, function_ids=None, no_types=False)
61
+ cache_generate_args(contexts=None, names=None, ids=None, no_types=False)
60
62
  generate()
61
63
 
62
64
  setup_parser.set_defaults(command=setup)
@@ -68,7 +70,7 @@ def execute_from_cli():
68
70
  generate_parser.add_argument("--no-types", action="store_true", help="Generate SDK without type definitions")
69
71
  generate_parser.add_argument("--contexts", type=str, required=False, help="Contexts to generate")
70
72
  generate_parser.add_argument("--names", type=str, required=False, help="Resource names to generate (comma-separated)")
71
- generate_parser.add_argument("--function-ids", type=str, required=False, help="Function IDs to generate (comma-separated)")
73
+ generate_parser.add_argument("--ids", "--function-ids", type=str, required=False, help="Resource IDs to generate (comma-separated)")
72
74
 
73
75
  def generate_command(args):
74
76
  from .config import cache_generate_args
@@ -77,24 +79,24 @@ def execute_from_cli():
77
79
 
78
80
  contexts = args.contexts.split(",") if args.contexts else None
79
81
  names = args.names.split(",") if args.names else None
80
- function_ids = args.function_ids.split(",") if args.function_ids else None
82
+ ids = args.ids.split(",") if args.ids else None
81
83
  no_types = args.no_types
82
84
 
83
85
  # overwrite all cached values with the values passed in from the command line
84
86
  final_contexts = contexts
85
87
  final_names = names
86
- final_function_ids = function_ids
88
+ final_ids = ids
87
89
  final_no_types = no_types
88
90
 
89
91
  # cache the values used for this explicit generate command
90
92
  cache_generate_args(
91
93
  contexts=final_contexts,
92
94
  names=final_names,
93
- function_ids=final_function_ids,
95
+ ids=ids,
94
96
  no_types=final_no_types
95
97
  )
96
98
 
97
- generate(contexts=final_contexts, names=final_names, function_ids=final_function_ids, no_types=final_no_types)
99
+ generate(contexts=final_contexts, names=final_names, ids=ids, no_types=final_no_types)
98
100
 
99
101
  generate_parser.set_defaults(command=generate_command)
100
102
 
polyapi/config.py CHANGED
@@ -14,7 +14,7 @@ MTLS_KEY_PATH = None
14
14
  MTLS_CA_PATH = None
15
15
  LAST_GENERATE_CONTEXTS = None
16
16
  LAST_GENERATE_NAMES = None
17
- LAST_GENERATE_FUNCTION_IDS = None
17
+ LAST_GENERATE_IDS = None
18
18
  LAST_GENERATE_NO_TYPES = None
19
19
 
20
20
 
@@ -61,13 +61,13 @@ def get_api_key_and_url() -> Tuple[str | None, str | None]:
61
61
  MTLS_CA_PATH = config.get("polyapi", "mtls_ca_path", fallback=None)
62
62
 
63
63
  # Read and cache generate command arguments
64
- global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
64
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_IDS, LAST_GENERATE_NO_TYPES
65
65
  contexts_str = config.get("polyapi", "last_generate_contexts_used", fallback=None)
66
66
  LAST_GENERATE_CONTEXTS = contexts_str.split(",") if contexts_str else None
67
67
  names_str = config.get("polyapi", "last_generate_names_used", fallback=None)
68
68
  LAST_GENERATE_NAMES = names_str.split(",") if names_str else None
69
- function_ids_str = config.get("polyapi", "last_generate_function_ids_used", fallback=None)
70
- LAST_GENERATE_FUNCTION_IDS = function_ids_str.split(",") if function_ids_str else None
69
+ ids_str = config.get("polyapi", "last_generate_ids_used", fallback=None)
70
+ LAST_GENERATE_IDS = ids_str.split(",") if ids_str else None
71
71
  LAST_GENERATE_NO_TYPES = config.get("polyapi", "last_generate_no_types_used", fallback="false").lower() == "true"
72
72
 
73
73
  return key, url
@@ -152,14 +152,14 @@ def get_direct_execute_config() -> bool:
152
152
 
153
153
  def get_cached_generate_args() -> Tuple[list | None, list | None, list | None, bool]:
154
154
  """Return cached generate command arguments"""
155
- global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
156
- if LAST_GENERATE_CONTEXTS is None and LAST_GENERATE_NAMES is None and LAST_GENERATE_FUNCTION_IDS is None and LAST_GENERATE_NO_TYPES is None:
155
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_IDS, LAST_GENERATE_NO_TYPES
156
+ if LAST_GENERATE_CONTEXTS is None and LAST_GENERATE_NAMES is None and LAST_GENERATE_IDS is None and LAST_GENERATE_NO_TYPES is None:
157
157
  # Force a config read if values aren't cached
158
158
  get_api_key_and_url()
159
- return LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, bool(LAST_GENERATE_NO_TYPES)
159
+ return LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_IDS, bool(LAST_GENERATE_NO_TYPES)
160
160
 
161
161
 
162
- def cache_generate_args(contexts: list | None = None, names: list | None = None, function_ids: list | None = None, no_types: bool = False):
162
+ def cache_generate_args(contexts: list | None = None, names: list | None = None, ids: list | None = None, no_types: bool = False):
163
163
  """Cache generate command arguments to config file"""
164
164
  from typing import List
165
165
 
@@ -176,10 +176,10 @@ def cache_generate_args(contexts: list | None = None, names: list | None = None,
176
176
  config["polyapi"] = {}
177
177
 
178
178
  # Update cached values
179
- global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_FUNCTION_IDS, LAST_GENERATE_NO_TYPES
179
+ global LAST_GENERATE_CONTEXTS, LAST_GENERATE_NAMES, LAST_GENERATE_IDS, LAST_GENERATE_NO_TYPES
180
180
  LAST_GENERATE_CONTEXTS = contexts
181
181
  LAST_GENERATE_NAMES = names
182
- LAST_GENERATE_FUNCTION_IDS = function_ids
182
+ LAST_GENERATE_IDS = ids
183
183
  LAST_GENERATE_NO_TYPES = no_types
184
184
 
185
185
  # Write values to config
@@ -193,10 +193,10 @@ def cache_generate_args(contexts: list | None = None, names: list | None = None,
193
193
  elif config.has_option("polyapi", "last_generate_names_used"):
194
194
  config.remove_option("polyapi", "last_generate_names_used")
195
195
 
196
- if function_ids is not None:
197
- config.set("polyapi", "last_generate_function_ids_used", ",".join(function_ids))
198
- elif config.has_option("polyapi", "last_generate_function_ids_used"):
199
- config.remove_option("polyapi", "last_generate_function_ids_used")
196
+ if ids is not None:
197
+ config.set("polyapi", "last_generate_ids_used", ",".join(ids))
198
+ elif config.has_option("polyapi", "last_generate_ids_used"):
199
+ config.remove_option("polyapi", "last_generate_ids_used")
200
200
 
201
201
  config.set("polyapi", "last_generate_no_types_used", str(no_types).lower())
202
202
 
polyapi/generate.py CHANGED
@@ -42,7 +42,7 @@ Unresolved schema, please add the following schema to complete it:
42
42
  path:'''
43
43
 
44
44
 
45
- def get_specs(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, function_ids: Optional[List[str]] = None, no_types: bool = False) -> List:
45
+ def get_specs(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, ids: Optional[List[str]] = None, no_types: bool = False) -> List:
46
46
  api_key, api_url = get_api_key_and_url()
47
47
  assert api_key
48
48
  headers = get_auth_headers(api_key)
@@ -55,8 +55,8 @@ def get_specs(contexts: Optional[List[str]] = None, names: Optional[List[str]] =
55
55
  if names:
56
56
  params["names"] = names
57
57
 
58
- if function_ids:
59
- params["functionIds"] = function_ids
58
+ if ids:
59
+ params["ids"] = ids
60
60
 
61
61
  # Add apiFunctionDirectExecute parameter if direct execute is enabled
62
62
  if get_direct_execute_config():
@@ -297,12 +297,12 @@ def generate_from_cache() -> None:
297
297
  """
298
298
  Generate using cached values after non-explicit call.
299
299
  """
300
- cached_contexts, cached_names, cached_function_ids, cached_no_types = get_cached_generate_args()
300
+ cached_contexts, cached_names, cached_ids, cached_no_types = get_cached_generate_args()
301
301
 
302
302
  generate(
303
303
  contexts=cached_contexts,
304
304
  names=cached_names,
305
- function_ids=cached_function_ids,
305
+ ids=cached_ids,
306
306
  no_types=cached_no_types
307
307
  )
308
308
 
@@ -338,12 +338,12 @@ def normalize_args_schema(
338
338
  return spec
339
339
 
340
340
 
341
- def generate(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, function_ids: Optional[List[str]] = None, no_types: bool = False) -> None:
341
+ def generate(contexts: Optional[List[str]] = None, names: Optional[List[str]] = None, ids: Optional[List[str]] = None, no_types: bool = False) -> None:
342
342
  generate_msg = f"Generating Poly Python SDK for contexts ${contexts}..." if contexts else "Generating Poly Python SDK..."
343
343
  print(generate_msg, end="", flush=True)
344
344
  remove_old_library()
345
345
 
346
- specs = get_specs(contexts=contexts, names=names, function_ids=function_ids, no_types=no_types)
346
+ specs = get_specs(contexts=contexts, names=names, ids=ids, no_types=no_types)
347
347
  cache_specs(specs)
348
348
 
349
349
  limit_ids: List[str] = [] # useful for narrowing down generation to a single function to debug
polyapi/poly_tables.py CHANGED
@@ -55,6 +55,10 @@ def first_result(rsp):
55
55
  return rsp['results'][0] if rsp['results'] else None
56
56
  return rsp
57
57
 
58
+ def delete_one_response(rsp):
59
+ if isinstance(rsp, dict) and isinstance(rsp.get('deleted'), int):
60
+ return { 'deleted': bool(rsp.get('deleted')) }
61
+ return { 'deleted': false }
58
62
 
59
63
  _key_transform_map = {
60
64
  "not_": "not",
@@ -301,6 +305,30 @@ class {table_name}:{table_description}
301
305
  query = kwargs
302
306
  return execute_query({table_name}.table_id, "update", transform_query(query))
303
307
 
308
+ @overload
309
+ @staticmethod
310
+ def update_one(id: str, query: {table_name}UpdateManyQuery) -> {table_name}Row: ...
311
+ @overload
312
+ @staticmethod
313
+ def update_one(*, id: str, where: Optional[{table_name}WhereFilter], data: {table_name}Subset) -> {table_name}Row: ...
314
+
315
+ @staticmethod
316
+ def update_one(*args, **kwargs) -> {table_name}Row:
317
+ if args:
318
+ if len(args) != 2 or or not isinstance(args[0], str) not isinstance(args[1], dict):
319
+ raise TypeError("Expected id and query as arguments or as kwargs")
320
+ query = args[1]
321
+ if not isinstance(query["where"], dict):
322
+ query["where"] = {{}}
323
+ query["where"]["id"] = args[0]
324
+ else:
325
+ query = kwargs
326
+ if not isinstance(query["where"], dict):
327
+ query["where"] = {{}}
328
+ query["where"]["id"] = kwargs["id"]
329
+ query.pop("id", None)
330
+ return first_result(execute_query({table_name}.table_id, "update", transform_query(query)))
331
+
304
332
  @overload
305
333
  @staticmethod
306
334
  def delete_many(query: {table_name}DeleteQuery) -> PolyDeleteResults: ...
@@ -316,7 +344,31 @@ class {table_name}:{table_description}
316
344
  query = args[0]
317
345
  else:
318
346
  query = kwargs
319
- return execute_query({table_name}.table_id, "delete", query)
347
+ return execute_query({table_name}.table_id, "delete", transform_query(query))
348
+
349
+ @overload
350
+ @staticmethod
351
+ def delete_one(query: {table_name}DeleteQuery) -> PolyDeleteResult: ...
352
+ @overload
353
+ @staticmethod
354
+ def delete_one(*, where: Optional[{table_name}WhereFilter]) -> PolyDeleteResult: ...
355
+
356
+ @staticmethod
357
+ def delete_one(*args, **kwargs) -> PolyDeleteResult:
358
+ if args:
359
+ if len(args) != 2 or or not isinstance(args[0], str) not isinstance(args[1], dict):
360
+ raise TypeError("Expected id and query as arguments or as kwargs")
361
+ query = args[1]
362
+ if not isinstance(query["where"], dict):
363
+ query["where"] = {{}}
364
+ query["where"]["id"] = args[0]
365
+ else:
366
+ query = kwargs
367
+ if not isinstance(query["where"], dict):
368
+ query["where"] = {{}}
369
+ query["where"]["id"] = kwargs["id"]
370
+ query.pop("id", None)
371
+ return delete_one_response(execute_query({table_name}.table_id, "delete", transform_query(query)))
320
372
  '''
321
373
 
322
374
 
polyapi/typedefs.py CHANGED
@@ -118,6 +118,10 @@ class PolyDeleteResults(TypedDict):
118
118
  deleted: int
119
119
 
120
120
 
121
+ class PolyDeleteResult(TypedDict):
122
+ deleted: bool
123
+
124
+
121
125
 
122
126
  QueryMode = Literal["default", "insensitive"]
123
127
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polyapi-python
3
- Version: 0.3.11.dev2
3
+ Version: 0.3.11.dev4
4
4
  Summary: The Python Client for PolyAPI, the IPaaS by Developers for Developers
5
5
  Author-email: Dan Fellin <dan@polyapi.io>
6
6
  License: MIT License
@@ -2,31 +2,31 @@ polyapi/__init__.py,sha256=hw7x4j9JNJfPdkIOZqV0X9pbYcw3_5AH1iQFdSogH-c,3235
2
2
  polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
3
3
  polyapi/api.py,sha256=2nds6ZdNe9OHvCba4IjOPga0CAYIsib2SbhEyDDCmd8,2188
4
4
  polyapi/auth.py,sha256=EGstBjTSdAydI5hGAHeRRc1GcmHshogudb3sxCgO6zA,5341
5
- polyapi/cli.py,sha256=KvDd6C3UbHCRI1vR8m5Usx3Sv_-bBI7LPqU_FLFsMLI,11198
5
+ polyapi/cli.py,sha256=3M6XpMhpvQSHq4X8tBsq7N93YEwyVIqNFkz1tx_6aSs,11107
6
6
  polyapi/client.py,sha256=DW6ljG_xCwAo2yz23A9QfLooE6ZUDvSpdA4e_dCQjiQ,1418
7
- polyapi/config.py,sha256=LgkZXG1DspNxIwukpcFTbsj46YyN5lQjmlvdVby87uQ,7638
7
+ polyapi/config.py,sha256=k4UgczUTEabOjQPMSCoZtSkICymAKVWRIRWAyZKO2iA,7467
8
8
  polyapi/constants.py,sha256=sc-FnS0SngBLvSu1ZWMs0UCf9EYD1u1Yhfr-sZXGLns,607
9
9
  polyapi/deployables.py,sha256=6R7XSgpTohZBcqoGd7GioQdXXKuvbBsdq_cAJ1p8jfQ,12184
10
10
  polyapi/error_handler.py,sha256=I_e0iz6VM23FLVQWJljxs2NGcl_OODbi43OcbnqBlp8,2398
11
11
  polyapi/exceptions.py,sha256=Zh7i7eCUhDuXEdUYjatkLFTeZkrx1BJ1P5ePgbJ9eIY,89
12
12
  polyapi/execute.py,sha256=q4xtV6rYO8f-8hULlFTlVgoTVQSahvlMu3FHkFzYpMs,4423
13
13
  polyapi/function_cli.py,sha256=W30yL2i152iZCr6zAU1CHKlDp_tt7kB2cGIXIxmWumk,4302
14
- polyapi/generate.py,sha256=W-6kSoP-nDRc85cSAkiFTwS99dF_H4Ded0mPHGNVy5w,21135
14
+ polyapi/generate.py,sha256=0zVDEnKVZnbMNZ6O0SWAuDLHrBrkW01vFkjpf9wrQZo,21046
15
15
  polyapi/parser.py,sha256=IVSJGT6wcxpXUHmhx4DVhOGL1XY_MBaf5aw3Pd2DVcI,20935
16
16
  polyapi/poly_schemas.py,sha256=fZ6AGvHcOKQJtlrzSuzeBNed5DxPMA2dJGdJvuFCHWM,9066
17
- polyapi/poly_tables.py,sha256=0wFZODu7ULWC4qwAiX6ffA0e5OrOcm6uodSwmMkTa_Q,16571
17
+ polyapi/poly_tables.py,sha256=JCUxyQCsFeo3ZQNL3b3jh097ewad0la3JxkGGbnAkho,18783
18
18
  polyapi/prepare.py,sha256=NQzpMIoakNovStvOGOmqSYIpTwiWXaweNSE9se10A2E,7420
19
19
  polyapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  polyapi/rendered_spec.py,sha256=nJEj2vRgG3N20fU4s-ThRtOIwAuTzXwXuOBIkXljDVc,2240
21
21
  polyapi/schema.py,sha256=-mtRV5iL3CV0X3phXhGYFV8sLz0KouTACOKWyGO9Pwc,5309
22
22
  polyapi/server.py,sha256=YXWxhYBx-hluwDQ8Jvfpy2s8ogz0GsNTMcZVNcP5ca8,2147
23
23
  polyapi/sync.py,sha256=52ODc82jBJpbNYTB9zXlrVZLR39iwDPW3cuIC3P8dbM,6742
24
- polyapi/typedefs.py,sha256=VEaYODLm-3a26_cK1uSRoYwenmprLOQQdoKFz4gqK_0,5587
24
+ polyapi/typedefs.py,sha256=mfll-KrngOW0wzbvDNiIDaDkFMwbsT-MY5y5hzWj9RE,5642
25
25
  polyapi/utils.py,sha256=Ca189i4PM4TpwvpzwF3T8MfQsOPD45b_falXjjgYCyI,12603
26
26
  polyapi/variables.py,sha256=SJv106ePpQP5mx7Iiafl_shtFlE8FoaO9Q8lvw-3IRg,7270
27
27
  polyapi/webhook.py,sha256=I3_uOl4f4L2-2WehzRLMVMRrB-76EiXCPA9Vzoaj30I,5326
28
- polyapi_python-0.3.11.dev2.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
29
- polyapi_python-0.3.11.dev2.dist-info/METADATA,sha256=jhbcFxknorQvZTBNK8395spXQyJyS9H2B6NUtLqZ338,5318
30
- polyapi_python-0.3.11.dev2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
- polyapi_python-0.3.11.dev2.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
32
- polyapi_python-0.3.11.dev2.dist-info/RECORD,,
28
+ polyapi_python-0.3.11.dev4.dist-info/licenses/LICENSE,sha256=6b_I7aPVp8JXhqQwdw7_B84Ca0S4JGjHj0sr_1VOdB4,1068
29
+ polyapi_python-0.3.11.dev4.dist-info/METADATA,sha256=vmuuWa1eUGWCEI2T5ptklEbX_8VJMT-pF9eaKKYiWXE,5318
30
+ polyapi_python-0.3.11.dev4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
31
+ polyapi_python-0.3.11.dev4.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
32
+ polyapi_python-0.3.11.dev4.dist-info/RECORD,,