supabase_typegen 3.0.0a1__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.
@@ -0,0 +1,17 @@
1
+ """Generates the typed tables and functions of a Supabase database for the
2
+ typed API of supabase-py, from the `GeneratorMetadata` document that
3
+ `supabase gen types --lang python` pipes in."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from ._generator import generate
8
+ from ._metadata import GeneratorMetadata, MetadataError, parse_generator_metadata
9
+ from .version import __version__
10
+
11
+ __all__ = [
12
+ "GeneratorMetadata",
13
+ "MetadataError",
14
+ "__version__",
15
+ "generate",
16
+ "parse_generator_metadata",
17
+ ]
@@ -0,0 +1,68 @@
1
+ """`python -m supabase_typegen`: reads a `GeneratorMetadata` document on
2
+ standard input and writes the generated module to standard output.
3
+
4
+ Exits with 64 when standard input is a terminal and with 65 when the
5
+ document is not one this version reads, or describes nothing to generate.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import argparse
11
+ import sys
12
+ from typing import Final
13
+
14
+ from ._generator import describes_nothing, generate
15
+ from ._metadata import MetadataError, parse_generator_metadata
16
+ from .version import __version__
17
+
18
+ EXIT_USAGE: Final = 64
19
+ EXIT_DATA_ERROR: Final = 65
20
+
21
+
22
+ def main(arguments: list[str] | None = None) -> int:
23
+ parser = argparse.ArgumentParser(
24
+ prog="python -m supabase_typegen",
25
+ description=(
26
+ "Generates the typed tables and functions of a Supabase database "
27
+ "from the GeneratorMetadata document that `supabase gen types "
28
+ "--lang python` pipes in on standard input, and writes the module "
29
+ "to standard output."
30
+ ),
31
+ )
32
+ parser.add_argument(
33
+ "--version", action="version", version=f"supabase_typegen {__version__}"
34
+ )
35
+ parser.parse_args(arguments)
36
+
37
+ if sys.stdin.isatty():
38
+ return _fail(
39
+ EXIT_USAGE,
40
+ "Expected a GeneratorMetadata document on standard input. Run "
41
+ "`supabase gen types --lang python` to generate types.",
42
+ )
43
+ try:
44
+ metadata = parse_generator_metadata(sys.stdin.buffer.read())
45
+ except MetadataError as error:
46
+ return _fail(EXIT_DATA_ERROR, str(error))
47
+ if metadata.rpc_functions is None and metadata.functions:
48
+ sys.stderr.write(
49
+ 'The document has no "rpcFunctions" collection, so no function '
50
+ "calls are generated. Upgrade the Supabase CLI to generate them.\n"
51
+ )
52
+ if describes_nothing(metadata):
53
+ return _fail(
54
+ EXIT_DATA_ERROR,
55
+ "The document describes no tables, views, enums or functions, so "
56
+ "there is nothing to generate.",
57
+ )
58
+ sys.stdout.write(generate(metadata))
59
+ return 0
60
+
61
+
62
+ def _fail(exit_code: int, message: str) -> int:
63
+ sys.stderr.write(f"{message}\n")
64
+ return exit_code
65
+
66
+
67
+ if __name__ == "__main__":
68
+ sys.exit(main())