ts-backend-check 1.2.0__py3-none-any.whl → 1.2.2__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.
@@ -29,7 +29,7 @@ class TypeChecker:
29
29
  self.model_fields = extract_model_fields(models_file)
30
30
  self.ts_parser = TypeScriptParser(types_file)
31
31
  self.ts_interfaces = self.ts_parser.parse_interfaces()
32
- self.backend_only = self.ts_parser.get_backend_only_fields()
32
+ self.backend_only = self.ts_parser.get_ignored_fields()
33
33
 
34
34
  def check(self) -> List[str]:
35
35
  """
@@ -177,9 +177,12 @@ class TypeChecker:
177
177
  The message displayed to the user when missing fields are found.
178
178
  """
179
179
  camel_field = snake_to_camel(input_str=field)
180
+ interface_of_interfaces = (
181
+ "interface" if len(interfaces.keys()) == 1 else "interfaces"
182
+ )
183
+
180
184
  return (
181
- f"\nField '{field}' (camelCase: '{camel_field}') from model '{model_name}' is missing in TypeScript types."
182
- f"\nExpected to find in interface(s): {', '.join(interfaces.keys())}"
183
- f"\nTo ignore this field, add a comment that references it like: '// Note: {camel_field} is backend only'"
184
- "\n"
185
+ f"\nField '{field}' (camelCase: '{camel_field}') from model '{model_name}' is missing in the TypeScript interfaces."
186
+ f"\nExpected to find this field in the frontend {interface_of_interfaces}: {', '.join(interfaces.keys())}"
187
+ f"\nTo ignore this field, add the following comment to the TypeScript file: '// ts-backend-check: ignore field {camel_field}'"
185
188
  )
@@ -124,7 +124,7 @@ def main() -> None:
124
124
 
125
125
  if missing := checker.check():
126
126
  rprint(
127
- "\n[red]❌ ts-backend-check error: Missing typescript fields found:[/red]\n"
127
+ "\n[red]❌ ts-backend-check error: There are inconsistencies between the provided backend models and TypeScript interfaces. Please see the output below for details.[/red]"
128
128
  )
129
129
 
130
130
  # Print each error message in red.
@@ -133,12 +133,12 @@ def main() -> None:
133
133
 
134
134
  field_or_fields = "fields" if len(missing) > 1 else "field"
135
135
  rprint(
136
- f"\n[red]Please fix the {len(missing)} {field_or_fields} above to have the backend models synced with the typescript interfaces.[/red]"
136
+ f"[red]\nPlease fix the {len(missing)} {field_or_fields} above to have the backend models of {args.backend_model_file} synced with the typescript interfaces of {(args.typescript_file)}.[/red]"
137
137
  )
138
138
  sys.exit(1)
139
139
 
140
140
  rprint(
141
- "[green]✅ Success: All models are synced with their corresponding TypeScript interfaces.[/green]"
141
+ "[green]✅ Success: All backend models are synced with their corresponding TypeScript interfaces for the provided files.[/green]"
142
142
  )
143
143
 
144
144
 
@@ -60,24 +60,17 @@ class TypeScriptParser:
60
60
 
61
61
  return interfaces
62
62
 
63
- def get_backend_only_fields(self) -> Set[str]:
63
+ def get_ignored_fields(self) -> Set[str]:
64
64
  """
65
- Extract fields marked as backend-only in comments.
65
+ Extract fields marked as ignored in comments.
66
66
 
67
67
  Returns
68
68
  -------
69
69
  Set[str]
70
- The field names that are marked with a backend-only identifier to ignore them.
70
+ The field names that are marked with a ts-backend-check-ignore identifier to ignore them.
71
71
  """
72
- patterns = [
73
- r"//.*?Note:\s*(\w+)\s+is\s+backend\s+only",
74
- r"//.*?(\w+)\s+is\s+backend\s+only",
75
- r"//\s*@backend-only\s+(\w+)",
76
- r"//.*?backend-only:\s*(\w+)",
77
- ]
78
- return {
79
- match for pattern in patterns for match in re.findall(pattern, self.content)
80
- }
72
+ ignore_pattern = r"//.*?ts-backend-check: ignore field\s+(\w+)"
73
+ return set(re.findall(ignore_pattern, self.content))
81
74
 
82
75
  @staticmethod
83
76
  def _extract_fields(interface_body: str) -> Set[str]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ts-backend-check
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Check TypeScript types against their corresponding backend models to assure that all fields have been accounted for.
5
5
  Home-page: https://github.com/activist-org/ts-backend-check
6
6
  Author: ts-backend-check developers
@@ -95,9 +95,25 @@ ts-backend-check --help
95
95
 
96
96
  # Check a TypeScript type against a backend model:
97
97
  ts-backend-check -bmf <backend-model-file> -tsf <typescript-file>
98
+ ```
99
+
100
+ Example success and error outputs for the CLI are:
101
+
102
+ ```
103
+ ts-backend-check -bmf backend/models/user.py -tsf frontend/types/user.ts
104
+ ✅ Success: All backend models are synced with their corresponding TypeScript interfaces for the provided files.
105
+ ```
106
+
107
+ ```
108
+ ts-backend-check -bmf backend/models/user.py -tsf frontend/types/user.ts
109
+
110
+ ❌ ts-backend-check error: There are inconsistencies between the provided backend models and TypeScript interfaces. Please see the output below for details.
111
+
112
+ Field 'user_name' (camelCase: 'userName') from model 'UserModel' is missing in the TypeScript interfaces.
113
+ Expected to find this field in the frontend interface: User
114
+ To ignore this field, add the following comment to the TypeScript interface: '// ts-backend-check: ignore field userName'
98
115
 
99
- # Example command:
100
- ts-backend-check -bmf src/models/user.py -tsf src/types/user.ts
116
+ Please fix the 1 field above to have the backend models of backend/models/user.py synced with the typescript interfaces of frontend/types/user.ts.
101
117
  ```
102
118
 
103
119
  <a id="contributing-"></a>
@@ -1,21 +1,21 @@
1
1
  ts_backend_check/__init__.py,sha256=HSiEqWvU3Q4a6D7tYsoq3-B-g1HdUOGngEeGV45j8ak,172
2
- ts_backend_check/checker.py,sha256=ISPl_1H7dXb7DcOl6erdxEhx61xQBJxtHuYkUuEqrck,5792
2
+ ts_backend_check/checker.py,sha256=4QtPdiEnpRVIO4BpcHeCz-sjG2bqTg43M4gfntRnHj4,5956
3
3
  ts_backend_check/django_parser.py,sha256=CFg4-zV5BsVhuq-nVQEYD9nS25JSaHbIs2Xr3LE3KWY,3241
4
4
  ts_backend_check/typescript_parser.py,sha256=BqBGOjsf-Wlh6ceaK-G2vLm5AMiEiwX-XnJQrr8P-gQ,2885
5
5
  ts_backend_check/utils.py,sha256=N9_25_wW2g3dkmGGLWHQj_AHsXI9Rx2XqRnYxT5i2Rk,897
6
6
  ts_backend_check/cli/__init__.py,sha256=wJK9tO9MtI10L0xRjrk7WP_qZZRBjbFw1U9jJbIbX7I,108
7
7
  ts_backend_check/cli/check_blank.py,sha256=gg6v01UYNmzs8eLasxauCaBCfN9esUtiAwqhqNTzE3w,3377
8
8
  ts_backend_check/cli/config.py,sha256=AgzjY3qbgW4ya5JJEdKaBQ9J8h0Ip-39xJNbAjFpA6s,4463
9
- ts_backend_check/cli/main.py,sha256=6g9Rf_m5H2cWUoPYPU_HEmkoUl6SLLai1Ni2BpgDz6U,4222
9
+ ts_backend_check/cli/main.py,sha256=-MlRG8syI6BMv1CBgXyfenlx6YS0cIKW4vhuQX_C77Q,4405
10
10
  ts_backend_check/cli/upgrade.py,sha256=P2LdIDCLdOFs-fOMuKLQoUMijQIyKEIA5PFZVsAUwDg,2952
11
11
  ts_backend_check/cli/version.py,sha256=lsocMaxAfF-FHW9O-NGH1sAo6svjuLgdGFxaC-XVoZc,2845
12
12
  ts_backend_check/parsers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  ts_backend_check/parsers/django_parser.py,sha256=U5OP6IyrSdwI9rDUGU4GbWTDfozwhretWg7lmF6QGB8,3242
14
- ts_backend_check/parsers/typescript_parser.py,sha256=BqBGOjsf-Wlh6ceaK-G2vLm5AMiEiwX-XnJQrr8P-gQ,2885
15
- ts_backend_check-1.2.0.data/data/requirements.txt,sha256=ixdwNPm86WRSX0oBBaNegCQL7HQP8evsCRAdEFHLxGk,540
16
- ts_backend_check-1.2.0.dist-info/licenses/LICENSE.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
17
- ts_backend_check-1.2.0.dist-info/METADATA,sha256=FDqxUd_nslUpUNEtk5sAHxEkATcDVkUAJkBMVYkf0rA,10416
18
- ts_backend_check-1.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- ts_backend_check-1.2.0.dist-info/entry_points.txt,sha256=QeY7RJu20otBnQlhMMZxPL8nB3mP3M3U3h3nOlSFWSU,68
20
- ts_backend_check-1.2.0.dist-info/top_level.txt,sha256=VzfNWQ3fPNdl-OBdtUKsUWR8Asdd27E3OJNUg2oQU8Y,17
21
- ts_backend_check-1.2.0.dist-info/RECORD,,
14
+ ts_backend_check/parsers/typescript_parser.py,sha256=UAExnEKxuFREFY6bJgQreG0b7SyVhWRaHw5TjN0CSU4,2680
15
+ ts_backend_check-1.2.2.data/data/requirements.txt,sha256=ixdwNPm86WRSX0oBBaNegCQL7HQP8evsCRAdEFHLxGk,540
16
+ ts_backend_check-1.2.2.dist-info/licenses/LICENSE.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
17
+ ts_backend_check-1.2.2.dist-info/METADATA,sha256=oiQpyko2T9eKhHPZlC6GOFFUoYipxqtT6ay-NoltxaM,11258
18
+ ts_backend_check-1.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ ts_backend_check-1.2.2.dist-info/entry_points.txt,sha256=QeY7RJu20otBnQlhMMZxPL8nB3mP3M3U3h3nOlSFWSU,68
20
+ ts_backend_check-1.2.2.dist-info/top_level.txt,sha256=VzfNWQ3fPNdl-OBdtUKsUWR8Asdd27E3OJNUg2oQU8Y,17
21
+ ts_backend_check-1.2.2.dist-info/RECORD,,