Skip to content

Revert "feat: pull Python types into TypeScript (#126)"#135

Closed
gjreda wants to merge 1 commit into
mainfrom
revert-126-api-types
Closed

Revert "feat: pull Python types into TypeScript (#126)"#135
gjreda wants to merge 1 commit into
mainfrom
revert-126-api-types

Conversation

@gjreda

@gjreda gjreda commented Jun 10, 2023

Copy link
Copy Markdown
Collaborator

This reverts commit 6c02266.

Reverting this because it's spitting errors that are unclear and is preventing me from pushing up changes. Since this PR is not a "must have" right now and @danvk spends Thursdays on this project, I didn't want to be blocked on pushing changes for several days.

It's also quite possible I'm doing something wrong here.

Here is what happened when I first tried to push my changes, with all tests for both JS and python passing:

Details
+ poetry run python python/generate_schema.py
/Users/greg/Library/Caches/pypoetry/virtualenvs/refstudio-iTeERiwC-py3.10/lib/python3.10/site-packages/dataclasses_jsonschema/__init__.py:850: UserWarning: Unable to create schema for 'str | None'
  warnings.warn(f"Unable to create schema for '{field_type_name}'")
/Users/greg/Library/Caches/pypoetry/virtualenvs/refstudio-iTeERiwC-py3.10/lib/python3.10/site-packages/dataclasses_jsonschema/__init__.py:850: UserWarning: Unable to create schema for 'Author'
  warnings.warn(f"Unable to create schema for '{field_type_name}'")
/Users/greg/Library/Caches/pypoetry/virtualenvs/refstudio-iTeERiwC-py3.10/lib/python3.10/site-packages/dataclasses_jsonschema/__init__.py:850: UserWarning: Unable to create schema for 'Chunk'
  warnings.warn(f"Unable to create schema for '{field_type_name}'")
+ yarn run json2ts python/cli.schema.json --no-additionalProperties
+ git diff --exit-code python/cli.schema.json src/api/types.ts
diff --git a/python/cli.schema.json b/python/cli.schema.json
index a8f5083..55bab1d 100644
--- a/python/cli.schema.json
+++ b/python/cli.schema.json
@@ -50,27 +50,17 @@
         "filename_md5": {
           "type": "string"
         },
-        "title": {
-          "type": "string"
-        },
-        "abstract": {
-          "type": "string"
-        },
-        "contents": {
-          "type": "string"
-        },
+        "title": {},
+        "abstract": {},
+        "contents": {},
         "authors": {
           "type": "array",
-          "items": {
-            "$ref": "#/definitions/Author"
-          },
+          "items": {},
           "default": []
         },
         "chunks": {
           "type": "array",
-          "items": {
-            "$ref": "#/definitions/Chunk"
-          },
+          "items": {},
           "default": []
         },
         "metadata": {
@@ -80,53 +70,6 @@
       },
       "description": "A reference for an academic paper / PDF"
     },
-    "Author": {
-      "type": "object",
-      "required": [
-        "full_name",
-        "given_name",
-        "surname",
-        "email"
-      ],
-      "properties": {
-        "full_name": {
-          "type": "string"
-        },
-        "given_name": {
-          "type": "string"
-        },
-        "surname": {
-          "type": "string"
-        },
-        "email": {
-          "type": "string"
-        }
-      },
-      "description": "Author(full_name: str, given_name: str, surname: str, email: str)"
-    },
-    "Chunk": {
-      "type": "object",
-      "required": [
-        "text"
-      ],
-      "properties": {
-        "text": {
-          "type": "string"
-        },
-        "vector": {
-          "type": "array",
-          "items": {
-            "type": "number"
-          },
-          "default": []
-        },
-        "metadata": {
-          "type": "object",
-          "default": {}
-        }
-      },
-      "description": "Chunk(text: str, vector: List[float] = <factory>, metadata: Dict[str, Any] = <factory>)"
-    },
     "RewriteChoice": {
       "type": "object",
       "required": [
diff --git a/src/api/types.ts b/src/api/types.ts
index eead71c..65d4744 100644
--- a/src/api/types.ts
+++ b/src/api/types.ts
@@ -25,28 +25,11 @@ export interface IngestResponse {
 export interface Reference {
   source_filename: string;
   filename_md5: string;
-  title?: string;
-  abstract?: string;
-  contents?: string;
-  authors?: Author[];
-  chunks?: Chunk[];
-  metadata?: {};
-}
-/**
- * Author(full_name: str, given_name: str, surname: str, email: str)
- */
-export interface Author {
-  full_name: string;
-  given_name: string;
-  surname: string;
-  email: string;
-}
-/**
- * Chunk(text: str, vector: List[float] = <factory>, metadata: Dict[str, Any] = <factory>)
- */
-export interface Chunk {
-  text: string;
-  vector?: number[];
+  title?: unknown;
+  abstract?: unknown;
+  contents?: unknown;
+  authors?: unknown[];
+  chunks?: unknown[];
   metadata?: {};
 }
 /**
husky - pre-push hook exited with code 1 (error)
error: failed to push some refs to 'https://github.com/refstudio/refstudio'

It wasn't obvious to me what the actual error was, so I committed the generated schemas and tried to push again, which resulted in the below:

❯ git push origin 102-backend-data-storage-for-reference-content
Checking formatting...
All matched files use Prettier code style!

/Users/greg/Dropbox/refstudio/src/api/ingestion.ts
  10:59  error  Unsafe assignment of an `any` value  @typescript-eslint/no-unsafe-assignment
  10:87  error  Unsafe assignment of an `any` value  @typescript-eslint/no-unsafe-assignment

✖ 2 problems (2 errors, 0 warnings)

husky - pre-push hook exited with code 1 (error)
error: failed to push some refs to 'https://github.com/refstudio/refstudio'

@gjreda gjreda marked this pull request as ready for review June 10, 2023 00:07
@gjreda gjreda closed this Jun 10, 2023
@cguedes cguedes deleted the revert-126-api-types branch September 20, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant