Skip to content

Commit 9aec69a

Browse files
authored
Develop->Main (#19)
1 parent 465ddea commit 9aec69a

File tree

475 files changed

+50796
-9596
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

475 files changed

+50796
-9596
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
3131
- name: "Run tests"
3232
env:
33-
VECTORIZE_TOKEN: ${{ secrets.VECTORIZE_TOKEN }}
34-
VECTORIZE_ORG: ${{ secrets.VECTORIZE_ORG }}
33+
VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_TOKEN }}
34+
VECTORIZE_ORGANIZATION_ID: ${{ secrets.VECTORIZE_ORG }}
3535
VECTORIZE_ENV: dev
3636
run: |
3737
cd tests/ts
@@ -65,8 +65,8 @@ jobs:
6565
6666
- name: Tests
6767
env:
68-
VECTORIZE_TOKEN: ${{ secrets.VECTORIZE_TOKEN }}
69-
VECTORIZE_ORG: ${{ secrets.VECTORIZE_ORG }}
68+
VECTORIZE_API_KEY: ${{ secrets.VECTORIZE_TOKEN }}
69+
VECTORIZE_ORGANIZATION_ID: ${{ secrets.VECTORIZE_ORG }}
7070
VECTORIZE_ENV: dev
7171
run: |
7272
cd tests/python

.gitleaksignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
38b2cbb260f769b31c59f3e7b4d0a2dc4a37f2ac:src/python/vectorize_client/models/source_connector_input_config.py:dropbox-api-token:44

scripts/fix-ts-unions.js

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/env node
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
// Function to extract imported types from the file
6+
function extractImportedTypes(content) {
7+
const typeImports = [];
8+
const importRegex = /import type \{ (\w+) \} from '\.\/\w+';/g;
9+
let match;
10+
11+
while ((match = importRegex.exec(content)) !== null) {
12+
typeImports.push(match[1]);
13+
}
14+
15+
return typeImports;
16+
}
17+
18+
function fixJsonValueBug(content) {
19+
// Fix the specific pattern in ToJSONTyped functions where 'value' is the parameter
20+
content = content.replace(
21+
/export function (\w+)ToJSONTyped\(value\?: ([^,]+) \| null, ignoreDiscriminator: boolean = false\): any \{[\s\S]*?return json;/g,
22+
(match) => match.replace('return json;', 'return value;')
23+
);
24+
25+
return content;
26+
}
27+
28+
// Update both functions to use this more precise fix:
29+
30+
// Function to extract imported types from the file
31+
function extractImportedTypes(content) {
32+
const typeImports = [];
33+
// Match both single-line and multi-line imports
34+
const importRegex = /import type \{ (\w+) \} from ['"]\.\/\w+['"];/g;
35+
let match;
36+
37+
while ((match = importRegex.exec(content)) !== null) {
38+
typeImports.push(match[1]);
39+
}
40+
41+
console.log(` Found imported types: ${typeImports.join(', ')}`);
42+
return typeImports;
43+
}
44+
45+
// Function to fix union type definitions
46+
function fixUnionTypes(filePath) {
47+
let content = fs.readFileSync(filePath, 'utf8');
48+
const originalContent = content;
49+
50+
// Pattern to match empty type definitions
51+
const emptyTypePattern = /export type (\w+) = ;/;
52+
53+
const match = emptyTypePattern.exec(content);
54+
if (match) {
55+
const typeName = match[1];
56+
console.log(`Fixing empty type: ${typeName}`);
57+
58+
// Extract imported types from this file
59+
const importedTypes = extractImportedTypes(content);
60+
61+
// Filter imported types that are likely part of this union
62+
const unionTypes = importedTypes.filter(t => {
63+
const isUsed = content.includes(`instanceof${t}`) ||
64+
content.includes(`${t}FromJSON`) ||
65+
content.includes(`${t}ToJSON`);
66+
if (isUsed) {
67+
console.log(` Type ${t} is part of the union`);
68+
}
69+
return isUsed;
70+
});
71+
72+
if (unionTypes.length > 0) {
73+
// Create the union type
74+
const unionTypeDefinition = `export type ${typeName} = ${unionTypes.join(' | ')};`;
75+
76+
// Replace the empty type definition
77+
content = content.replace(
78+
`export type ${typeName} = ;`,
79+
unionTypeDefinition
80+
);
81+
82+
console.log(` Replaced with: ${unionTypeDefinition}`);
83+
} else {
84+
console.log(` WARNING: No union types found for ${typeName}`);
85+
}
86+
}
87+
88+
// Only write if we made changes
89+
if (content !== originalContent) {
90+
fs.writeFileSync(filePath, content, 'utf8');
91+
console.log(`✅ Fixed ${filePath}`);
92+
}
93+
}
94+
95+
function fixAnyTypeImports(filePath) {
96+
let content = fs.readFileSync(filePath, 'utf8');
97+
const originalContent = content;
98+
99+
// Remove AnyType imports
100+
content = content.replace(/import type \{ AnyType \} from '\.\/AnyType';\n/g, '');
101+
content = content.replace(/import \{\s*[^}]*\s*\} from '\.\/AnyType';\n/g, '');
102+
103+
// Replace AnyType with any
104+
content = content.replace(/: AnyType/g, ': any');
105+
106+
// Fix the json/value bug with the more precise function
107+
content = fixJsonValueBug(content);
108+
109+
// Only write if we made changes
110+
if (content !== originalContent) {
111+
fs.writeFileSync(filePath, content, 'utf8');
112+
}
113+
}
114+
115+
// Main function to process all TypeScript files
116+
function processTypeScriptFiles(directory) {
117+
const modelsDir = path.join(directory, 'src', 'models');
118+
119+
if (!fs.existsSync(modelsDir)) {
120+
console.error(`Models directory not found: ${modelsDir}`);
121+
process.exit(1);
122+
}
123+
124+
// Files that typically have union type issues
125+
const filesToFix = [
126+
'CreateAIPlatformConnectorRequest.ts',
127+
'CreateSourceConnectorRequest.ts',
128+
'CreateDestinationConnectorRequest.ts'
129+
];
130+
131+
filesToFix.forEach(fileName => {
132+
const filePath = path.join(modelsDir, fileName);
133+
if (fs.existsSync(filePath)) {
134+
fixUnionTypes(filePath);
135+
} else {
136+
console.log(`⚠️ File not found: ${fileName}`);
137+
}
138+
});
139+
140+
const files = fs.readdirSync(modelsDir);
141+
files.forEach(file => {
142+
if (file.endsWith('.ts')) {
143+
const filePath = path.join(modelsDir, file);
144+
fixAnyTypeImports(filePath);
145+
}
146+
});
147+
}
148+
149+
// Get the directory from command line argument
150+
const tsDirectory = process.argv[2];
151+
152+
if (!tsDirectory) {
153+
console.error('Usage: node fix-ts-unions.js <typescript-output-directory>');
154+
process.exit(1);
155+
}
156+
157+
console.log('🔧 Fixing TypeScript union types...');
158+
processTypeScriptFiles(tsDirectory);
159+
console.log('✨ Done!');

scripts/generate-python.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
44
SRC_DIR=$ROOT_DIR/src
55

66
PYPROJECT=$SRC_DIR/python/pyproject.toml
7-
current_version=$(npm run read-toml $PYPROJECT tool.poetry version | tail -n 1 | tr -d '[:space:]')
7+
current_version=$(node -p "require('./package.json').version")
88

99
rm -rf $SRC_DIR/python
1010
openapi-generator-cli generate -i $ROOT_DIR/vectorize_api.json -g python -o $SRC_DIR/python \
1111
--additional-properties=packageName=vectorize_client \
1212
--additional-properties=generateSourceCodeOnly=false
1313

14-
15-
1614
npm run edit-toml $PYPROJECT tool.poetry version $current_version
1715
npm run edit-toml $PYPROJECT tool.poetry name vectorize-client
1816
npm run edit-toml $PYPROJECT tool.poetry description "Python client for the Vectorize API"

scripts/generate-ts.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
44
SRC_DIR=$ROOT_DIR/src
55

66
PACKAGE_JSON=$SRC_DIR/ts/package.json
7-
cd $SRC_DIR/ts
8-
current_version=$(npm pkg get version | tr -d '"')
9-
cd ../../
7+
8+
# Try to get current version if the directory exists
9+
if [ -d "$SRC_DIR/ts" ] && [ -f "$PACKAGE_JSON" ]; then
10+
cd $SRC_DIR/ts
11+
current_version=$(npm pkg get version | tr -d '"')
12+
cd ../../
13+
else
14+
# Use version from root package.json as fallback
15+
current_version=$(node -p "require('./package.json').version")
16+
fi
1017

1118
rm -rf $SRC_DIR/ts
19+
20+
# Generate the client
1221
openapi-generator-cli generate -i $ROOT_DIR/vectorize_api.json -g typescript-fetch -o $SRC_DIR/ts \
1322
--additional-properties=npmName=@vectorize-io/vectorize-client \
1423
--additional-properties=licenseName=MIT \
1524
--additional-properties=npmRepository="https://github.com/vectorize-io/vectorize-clients" \
1625
--additional-properties=snapshot=true \
1726
--additional-properties=generateSourceCodeOnly=false
1827

28+
# Fix the union types
29+
node $ROOT_DIR/scripts/fix-ts-unions.js $SRC_DIR/ts
30+
1931
edit_field() {
2032
local field=$1
2133
local value=$2

src/python/README.md

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from dataclasses import field
2-
31
# Vectorize Client
4-
Python Api Client for Vectorize
5-
For more information, please visit [https://vectorize.io](https://vectorize.io)
6-
7-
## Requirements.
2+
Python Api Client for [Vectorize](https://vectorize.io).
3+
For the full documentation, please visit [docs.vectorize.io](https://docs.vectorize.io/api/api-getting-started).
84

9-
Python 3.8+
105

11-
## Installation & Usage
6+
## Installation
127
```sh
138
pip install vectorize-client
149
```
@@ -20,8 +15,7 @@ import vectorize_client
2015

2116
## Getting Started
2217

23-
Please follow the [installation procedure](#installation--usage) and then run the following:
24-
18+
List all your pipelines:
2519
```python
2620
import vectorize_client as v
2721

@@ -34,62 +28,5 @@ with v.ApiClient(v.Configuration(access_token=TOKEN)) as api:
3428
print("Found" + str(len(response.data)) + " pipelines")
3529
```
3630

37-
## Documentation for API Endpoints
38-
39-
All URIs are relative to *https://api.vectorize.io/v1*
40-
41-
See the full [reference](https://vectorize.readme.io/reference) for more information.
42-
43-
## Usage
44-
45-
First, export your token and org id as environment variables:
46-
47-
```sh
48-
export VECTORIZE_TOKEN=<your-token>
49-
export VECTORIZE_ORG=<your-org-id>
50-
```
51-
Then, initialize the client with your token and org id:
52-
53-
```python
54-
import os
55-
TOKEN = os.environ['VECTORIZE_TOKEN']
56-
ORG = os.environ['VECTORIZE_ORG']
57-
```
58-
59-
### Extraction
60-
61-
Set the file you want to extract data from:
62-
63-
```sh
64-
export FILE=<path-to-file>
65-
```
66-
67-
Then, run the following code:
68-
```python
69-
import os
70-
import vectorize_client as v
71-
import time, logging
72-
73-
TOKEN = os.environ['VECTORIZE_TOKEN']
74-
ORG = os.environ['VECTORIZE_ORG']
75-
FILE = os.environ['FILE']
76-
77-
with v.ApiClient(v.Configuration(access_token=TOKEN)) as api:
78-
with open(FILE, 'rb') as file:
79-
data = file.read()
80-
extraction_id = v.ExtractionApi(api).start_extraction(ORG, data).extraction_id
81-
print(f"Extraction started with id {extraction_id}")
82-
while True:
83-
extraction = v.ExtractionApi(api).get_extraction_result(ORG, extraction_id)
84-
if extraction.ready:
85-
extracted_data = extraction.data
86-
if extracted_data.success:
87-
print(extracted_data)
88-
break
89-
else:
90-
raise Exception(extracted_data.error)
91-
print("Waiting for extraction to complete...")
92-
time.sleep(1)
93-
```
94-
31+
Visit [docs.vectorize.io](https://docs.vectorize.io/api/api-getting-started) to learn more about the API.
9532

src/python/pyproject.toml

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,35 @@
1-
[project]
2-
name = "vectorize_client"
3-
version = "1.0.0"
4-
description = "Vectorize API (Beta)"
5-
license = "NoLicense"
6-
readme = "README.md"
7-
keywords = [ "OpenAPI", "OpenAPI-Generator", "Vectorize API (Beta)" ]
8-
requires-python = ">=3.9"
9-
dependencies = [
10-
"urllib3 (>=2.1.0,<3.0.0)",
11-
"python-dateutil (>=2.8.2)",
12-
"pydantic (>=2)",
13-
"typing-extensions (>=4.7.1)"
14-
]
15-
16-
[[project.authors]]
17-
name = "Vectorize"
18-
email = "team@openapitools.org"
19-
20-
[project.urls]
21-
Repository = "https://github.com/GIT_USER_ID/GIT_REPO_ID"
22-
231
[tool.poetry]
24-
requires-poetry = ">=2.0"
25-
version = "0.3.0"
262
name = "vectorize-client"
3+
version = "0.1.0"
274
description = "Python client for the Vectorize API"
285
authors = [ "Vectorize <contact@vectorize.io>" ]
296
license = "MIT"
7+
readme = "README.md"
308
repository = "https://github.com/vectorize-io/vectorize-clients"
31-
homepage = "https://vectorize.io"
329
keywords = [
3310
"vectorize",
3411
"vectorize.io",
3512
"generative-ai",
3613
"embeddings",
3714
"rag"
3815
]
16+
include = [ "vectorize_client/py.typed" ]
17+
homepage = "https://vectorize.io"
18+
19+
[tool.poetry.dependencies]
20+
python = "^3.9"
21+
urllib3 = ">= 2.1.0, < 3.0.0"
22+
python-dateutil = ">= 2.8.2"
23+
pydantic = ">= 2"
24+
typing-extensions = ">= 4.7.1"
3925

40-
[tool.poetry.group.dev.dependencies]
41-
pytest = ">= 7.2.1"
42-
pytest-cov = ">= 2.8.1"
43-
tox = ">= 3.9.0"
44-
flake8 = ">= 4.0.0"
45-
types-python-dateutil = ">= 2.8.19.14"
46-
mypy = ">= 1.5"
26+
[tool.poetry.dev-dependencies]
27+
pytest = ">= 7.2.1"
28+
pytest-cov = ">= 2.8.1"
29+
tox = ">= 3.9.0"
30+
flake8 = ">= 4.0.0"
31+
types-python-dateutil = ">= 2.8.19.14"
32+
mypy = ">= 1.5"
4733

4834
[tool.pylint."MESSAGES CONTROL"]
4935
extension-pkg-whitelist = "pydantic"

0 commit comments

Comments
 (0)