hlquery-node-client 1.0.3 → 1.0.4

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.
package/README.md CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  [![Follow hlquery](https://img.shields.io/badge/Follow-%40hlquery-blue?logo=x&logoColor=white&labelColor=000000)](https://x.com/hlquery)
10
10
  [![Node build](https://img.shields.io/badge/Node%20build-passing-brightgreen?logo=node.js&logoColor=white&labelColor=000000)](https://github.com/hlquery/node-api/actions/workflows/ci.yml)
11
- [![node-api](https://img.shields.io/badge/GitHub-node--api-purple?logo=github&logoColor=white&labelColor=000000)](https://github.com/hlquery/node-api/stargazers)
12
- [![hlquery](https://img.shields.io/badge/GitHub-hlquery-blue?logo=github&logoColor=white&labelColor=000000)](https://github.com/hlquery/hlquery/stargazers)
11
+ [![node-api](https://img.shields.io/badge/GitHub-node--api-purple?logo=github&logoColor=white&labelColor=000000)](https://github.com/hlquery/node-api)
12
+ [![hlquery](https://img.shields.io/badge/GitHub-hlquery-blue?logo=github&logoColor=white&labelColor=000000)](https://github.com/hlquery/hlquery)
13
13
  [![License](https://img.shields.io/badge/License-BSD%203--Clause-a35a0f?logo=open-source-initiative&logoColor=white&labelColor=000000)](https://opensource.org/licenses/BSD-3-Clause)
14
14
 
15
15
  </div>
@@ -139,7 +139,7 @@ console.log(results.getBody());
139
139
  ```javascript
140
140
  const rows = await client.sql('SHOW COLLECTIONS;');
141
141
  const execResult = await client.execSql(
142
- "INSERT INTO logs_archive (id, title) VALUES ('row-1', 'warm cache');"
142
+ "INSERT INTO books (id, title) VALUES ('book_4', 'Inserted via SQL');"
143
143
  );
144
144
  const books = await client.sqlSearch(
145
145
  'books',
package/example.js CHANGED
@@ -161,11 +161,6 @@ async function main() {
161
161
  // Create client
162
162
  const client = new Client(baseUrl);
163
163
 
164
- // Optional: Set authentication token if provided
165
- // Uncomment and set token if your server requires authentication:
166
- // const authToken = 'your_token_here';
167
- // client.setAuthToken(authToken, 'bearer');
168
-
169
164
  if (testToken) {
170
165
  client.setAuthToken(testToken, 'bearer');
171
166
  console.log(`Using authentication token: ${testToken.substring(0, 8)}...\n`);
@@ -7,8 +7,15 @@
7
7
  const Client = require('../lib/Client');
8
8
 
9
9
  async function main() {
10
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
11
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
12
+
10
13
  // Initialize client
11
- const client = new Client('http://localhost:9200');
14
+ const client = new Client(baseUrl);
15
+
16
+ if (token) {
17
+ client.setAuthToken(token, 'bearer');
18
+ }
12
19
 
13
20
  // Health check
14
21
  const health = await client.health();
@@ -22,14 +29,7 @@ async function main() {
22
29
  console.log(`Found ${body.collections ? body.collections.length : 0} collections`);
23
30
  }
24
31
 
25
- // With authentication
26
- const authenticatedClient = new Client('http://localhost:9200', {
27
- token: 'your_token_here',
28
- auth_method: 'bearer'
29
- });
30
-
31
- // Or set token dynamically
32
- client.setAuthToken('your_token_here', 'bearer');
32
+ console.log('Base URL:', baseUrl);
33
33
  }
34
34
 
35
35
  main().catch(console.error);
@@ -7,16 +7,19 @@
7
7
  const Client = require('../lib/Client');
8
8
 
9
9
  async function main() {
10
- const client = new Client('http://localhost:9200');
10
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
11
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
12
+ const client = new Client(baseUrl);
13
+ const collectionName = `node_collections_example_${process.pid}`;
14
+
15
+ if (token) {
16
+ client.setAuthToken(token, 'bearer');
17
+ }
11
18
 
12
19
  // List collections
13
20
  const collections = await client.collections().list(0, 10);
14
21
  console.log('Collections:', collections.getBody());
15
22
 
16
- // Get collection
17
- const collection = await client.collections().get('my_collection');
18
- console.log('Collection details:', collection.getBody());
19
-
20
23
  // Create collection
21
24
  const schema = {
22
25
  fields: [
@@ -25,15 +28,19 @@ async function main() {
25
28
  { name: 'embedding', type: 'float[]' }
26
29
  ]
27
30
  };
28
- const createResult = await client.collections().create('new_collection', schema);
31
+ const createResult = await client.collections().create(collectionName, schema);
29
32
  console.log('Create result:', createResult.getBody());
33
+
34
+ // Get collection
35
+ const collection = await client.collections().get(collectionName);
36
+ console.log('Collection details:', collection.getBody());
30
37
 
31
38
  // Get formatted fields
32
- const fields = await client.collections().getFields('my_collection');
39
+ const fields = await client.collections().getFields(collectionName);
33
40
  console.log('Formatted fields:', fields.getBody());
34
41
 
35
42
  // Delete collection
36
- const deleteResult = await client.collections().delete('collection_name');
43
+ const deleteResult = await client.collections().delete(collectionName);
37
44
  console.log('Delete result:', deleteResult.getBody());
38
45
  }
39
46
 
package/examples/csv.js CHANGED
@@ -2,21 +2,23 @@
2
2
  * CSV Parsing Example
3
3
  *
4
4
  * Usage:
5
- * node examples/csv.js <collection> <csv-path> [token]
5
+ * node examples/csv.js <collection> <csv-path> [base-url] [token]
6
6
  */
7
7
 
8
8
  const path = require('path');
9
9
  const Client = require('../lib/Client');
10
10
 
11
11
  async function main() {
12
- const [, , collectionName, csvPath, token] = process.argv;
12
+ const [, , collectionName, csvPath, baseUrlArg, tokenArg] = process.argv;
13
13
 
14
14
  if (!collectionName || !csvPath) {
15
- console.error('Usage: node examples/csv.js <collection> <csv-path> [token]');
15
+ console.error('Usage: node examples/csv.js <collection> <csv-path> [base-url] [token]');
16
16
  process.exit(1);
17
17
  }
18
18
 
19
- const client = new Client('http://localhost:9200');
19
+ const baseUrl = baseUrlArg || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
20
+ const token = tokenArg || process.env.HLQUERY_TOKEN || null;
21
+ const client = new Client(baseUrl);
20
22
 
21
23
  if (token) {
22
24
  client.setAuthToken(token, 'bearer');
@@ -7,38 +7,53 @@
7
7
  const Client = require('../lib/Client');
8
8
 
9
9
  async function main() {
10
- const client = new Client('http://localhost:9200');
10
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
11
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
12
+ const client = new Client(baseUrl);
13
+ const collectionName = `node_documents_example_${process.pid}`;
14
+
15
+ if (token) {
16
+ client.setAuthToken(token, 'bearer');
17
+ }
18
+
19
+ await client.collections().delete(collectionName);
20
+ await client.collections().create(collectionName, {
21
+ fields: [
22
+ { name: 'title', type: 'string' },
23
+ { name: 'content', type: 'string' }
24
+ ]
25
+ });
26
+
27
+ // Add document
28
+ const newDoc = {
29
+ id: 'doc_1',
30
+ title: 'New Document',
31
+ content: 'Document content'
32
+ };
33
+ const addResult = await client.documents().add(collectionName, newDoc);
34
+ console.log('Add result:', addResult.getBody());
11
35
 
12
36
  // List documents
13
- const docs = await client.documents().list('collection', {
37
+ const docs = await client.documents().list(collectionName, {
14
38
  offset: 0,
15
39
  limit: 10
16
40
  });
17
41
  console.log('Documents:', docs.getBody());
18
42
 
19
43
  // Get document
20
- const doc = await client.documents().get('collection', 'doc_id');
44
+ const doc = await client.documents().get(collectionName, 'doc_1');
21
45
  console.log('Document:', doc.getBody());
22
46
 
23
- // Add document
24
- const newDoc = {
25
- id: 'doc_1',
26
- title: 'New Document',
27
- content: 'Document content'
28
- };
29
- const addResult = await client.documents().add('collection', newDoc);
30
- console.log('Add result:', addResult.getBody());
31
-
32
47
  // Update document
33
48
  const updatedDoc = {
34
49
  title: 'Updated Document',
35
50
  content: 'Updated content'
36
51
  };
37
- const updateResult = await client.documents().update('collection', 'doc_id', updatedDoc);
52
+ const updateResult = await client.documents().update(collectionName, 'doc_1', updatedDoc);
38
53
  console.log('Update result:', updateResult.getBody());
39
54
 
40
55
  // Delete document
41
- const deleteResult = await client.documents().delete('collection', 'doc_id');
56
+ const deleteResult = await client.documents().delete(collectionName, 'doc_1');
42
57
  console.log('Delete result:', deleteResult.getBody());
43
58
 
44
59
  // Bulk import
@@ -47,8 +62,11 @@ async function main() {
47
62
  { id: 'doc2', title: 'Doc 2' },
48
63
  { id: 'doc3', title: 'Doc 3' }
49
64
  ];
50
- const importResult = await client.documents().import('collection', bulkDocs);
65
+ const importResult = await client.documents().import(collectionName, bulkDocs);
51
66
  console.log('Import result:', importResult.getBody());
67
+
68
+ const cleanup = await client.collections().delete(collectionName);
69
+ console.log('Cleanup result:', cleanup.getBody());
52
70
  }
53
71
 
54
72
  main().catch(console.error);
package/examples/flush.js CHANGED
@@ -12,7 +12,13 @@
12
12
  const Client = require('../lib/Client');
13
13
 
14
14
  async function main() {
15
- const client = new Client('http://localhost:9200');
15
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
16
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
17
+ const client = new Client(baseUrl);
18
+
19
+ if (token) {
20
+ client.setAuthToken(token, 'bearer');
21
+ }
16
22
 
17
23
  console.log('='.repeat(70));
18
24
  console.log('FLUSH EXAMPLE');
package/examples/keys.js CHANGED
@@ -6,13 +6,15 @@
6
6
 
7
7
  const Client = require('../index');
8
8
 
9
- // Replace with your hlquery master admin token
10
- const ADMIN_TOKEN = 'your_admin_token_here';
11
- const BASE_URL = 'http://localhost:9200';
9
+ const ADMIN_TOKEN = process.argv[2] || process.env.HLQUERY_ADMIN_TOKEN || process.env.HLQUERY_TOKEN || null;
10
+ const BASE_URL = process.argv[3] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
12
11
 
13
12
  async function run() {
14
13
  try {
15
14
  const client = new Client(BASE_URL);
15
+ if (!ADMIN_TOKEN) {
16
+ throw new Error('Admin token required. Pass it as argv[2] or set HLQUERY_ADMIN_TOKEN.');
17
+ }
16
18
  client.setAuthToken(ADMIN_TOKEN);
17
19
 
18
20
  console.log('1. Creating a scoped search key for "products" collection...');
package/examples/pdf.js CHANGED
@@ -3,21 +3,23 @@
3
3
  *
4
4
  * Usage:
5
5
  * npm install
6
- * node examples/pdf.js <collection> <pdf-path> [token]
6
+ * node examples/pdf.js <collection> <pdf-path> [base-url] [token]
7
7
  */
8
8
 
9
9
  const path = require('path');
10
10
  const Client = require('../lib/Client');
11
11
 
12
12
  async function main() {
13
- const [, , collectionName, pdfPath, token] = process.argv;
13
+ const [, , collectionName, pdfPath, baseUrlArg, tokenArg] = process.argv;
14
14
 
15
15
  if (!collectionName || !pdfPath) {
16
- console.error('Usage: node examples/pdf.js <collection> <pdf-path> [token]');
16
+ console.error('Usage: node examples/pdf.js <collection> <pdf-path> [base-url] [token]');
17
17
  process.exit(1);
18
18
  }
19
19
 
20
- const client = new Client('http://localhost:9200');
20
+ const baseUrl = baseUrlArg || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
21
+ const token = tokenArg || process.env.HLQUERY_TOKEN || null;
22
+ const client = new Client(baseUrl);
21
23
 
22
24
  if (token) {
23
25
  client.setAuthToken(token, 'bearer');
@@ -7,18 +7,41 @@
7
7
  const Client = require('../lib/Client');
8
8
 
9
9
  async function main() {
10
- const client = new Client('http://localhost:9200');
10
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
11
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
12
+ const collectionName = process.argv[4] || `node_search_example_${process.pid}`;
13
+ const client = new Client(baseUrl);
11
14
  const search = client.searchApi();
15
+
16
+ if (token) {
17
+ client.setAuthToken(token, 'bearer');
18
+ }
19
+
20
+ await client.collections().delete(collectionName);
21
+ await client.collections().create(collectionName, {
22
+ fields: [
23
+ { name: 'title', type: 'string' },
24
+ { name: 'content', type: 'string' },
25
+ { name: 'category', type: 'string' },
26
+ { name: 'price', type: 'float' },
27
+ { name: 'embedding', type: 'float[]' }
28
+ ]
29
+ });
30
+ await client.documents().import(collectionName, [
31
+ { id: 'prod_laptop_001', title: 'Laptop Computer', content: 'Portable work machine', category: 'electronics', price: 1299.99, embedding: [0.1, 0.2, 0.3, 0.4, 0.5] },
32
+ { id: 'prod_keyboard_001', title: 'Wireless Keyboard', content: 'Compact Bluetooth keyboard', category: 'electronics', price: 49.99, embedding: [0.2, 0.1, 0.4, 0.3, 0.5] },
33
+ { id: 'prod_notebook_001', title: 'Paper Notebook', content: 'Plain paper writing notebook', category: 'office', price: 9.99, embedding: [0.5, 0.4, 0.3, 0.2, 0.1] }
34
+ ]);
12
35
 
13
36
  // Simple search. The SDK uses the canonical /collections/{name}/search route.
14
- const results = await search.search('collection_name', {
37
+ const results = await search.search(collectionName, {
15
38
  q: 'search query',
16
39
  query_by: 'title,content',
17
40
  limit: 10
18
41
  });
19
42
 
20
43
  // Search with filters
21
- const filteredResults = await client.search('collection_name', {
44
+ const filteredResults = await client.search(collectionName, {
22
45
  q: 'query',
23
46
  query_by: 'title',
24
47
  filter_by: 'category:electronics',
@@ -28,49 +51,49 @@ async function main() {
28
51
 
29
52
  // Supported query semantics
30
53
  // Field-specific search
31
- const fieldResults = await client.search('collection_name', {
54
+ const fieldResults = await client.search(collectionName, {
32
55
  q: 'title:laptop',
33
56
  query_by: 'title,content',
34
57
  limit: 10
35
58
  });
36
59
 
37
60
  // Boolean OR query
38
- const orResults = await client.search('collection_name', {
61
+ const orResults = await client.search(collectionName, {
39
62
  q: 'title:laptop OR title:notebook',
40
63
  query_by: 'title,content',
41
64
  limit: 10
42
65
  });
43
66
 
44
67
  // Boolean NOT query
45
- const notResults = await client.search('collection_name', {
68
+ const notResults = await client.search(collectionName, {
46
69
  q: 'title:laptop NOT title:refurbished',
47
70
  query_by: 'title,content',
48
71
  limit: 10
49
72
  });
50
73
 
51
74
  // Phrase search
52
- const phraseResults = await client.search('collection_name', {
75
+ const phraseResults = await client.search(collectionName, {
53
76
  q: '"wireless keyboard"',
54
77
  query_by: 'title',
55
78
  limit: 10
56
79
  });
57
80
 
58
81
  // Wildcard search
59
- const wildcardResults = await client.search('collection_name', {
82
+ const wildcardResults = await client.search(collectionName, {
60
83
  q: 'laptop*',
61
84
  query_by: 'title,content',
62
85
  limit: 10
63
86
  });
64
87
 
65
88
  // query_by restriction
66
- const restrictedResults = await client.search('collection_name', {
89
+ const restrictedResults = await client.search(collectionName, {
67
90
  q: 'laptop',
68
91
  query_by: 'title',
69
92
  limit: 10
70
93
  });
71
94
 
72
95
  // Filter operators belong in filter_by
73
- const combinedResults = await client.search('collection_name', {
96
+ const combinedResults = await client.search(collectionName, {
74
97
  q: '*',
75
98
  query_by: 'title,content',
76
99
  filter_by: 'price:>100&&category:electronics',
@@ -78,7 +101,7 @@ async function main() {
78
101
  });
79
102
 
80
103
  // Vector search
81
- const vectorResults = await client.vectorSearch('collection_name', {
104
+ const vectorResults = await client.vectorSearch(collectionName, {
82
105
  body: {
83
106
  vector: [0.1, 0.2, 0.3, 0.4, 0.5],
84
107
  field_name: 'embedding',
@@ -91,11 +114,23 @@ async function main() {
91
114
 
92
115
  // Multi-search
93
116
  const multiResults = await search.multiSearch([
94
- { collection: 'col1', q: 'query1', query_by: 'title' },
95
- { collection: 'col2', q: 'query2', query_by: 'content' }
117
+ { collection: collectionName, q: 'laptop', query_by: 'title' },
118
+ { collection: collectionName, q: 'keyboard', query_by: 'content' }
96
119
  ]);
97
120
 
98
121
  console.log('Search results:', results.getBody());
122
+ console.log('Filtered results:', filteredResults.getBody());
123
+ console.log('Field results:', fieldResults.getBody());
124
+ console.log('Boolean OR results:', orResults.getBody());
125
+ console.log('Boolean NOT results:', notResults.getBody());
126
+ console.log('Phrase results:', phraseResults.getBody());
127
+ console.log('Wildcard results:', wildcardResults.getBody());
128
+ console.log('Restricted results:', restrictedResults.getBody());
129
+ console.log('Combined results:', combinedResults.getBody());
130
+ console.log('Vector results:', vectorResults.getBody());
131
+ console.log('Multi-search results:', multiResults.getBody());
132
+
133
+ await client.collections().delete(collectionName);
99
134
  }
100
135
 
101
136
  main().catch(console.error);
package/examples/sql.js CHANGED
@@ -7,7 +7,28 @@
7
7
  const Client = require('../lib/Client');
8
8
 
9
9
  async function main() {
10
- const client = new Client('http://localhost:9200');
10
+ const baseUrl = process.argv[2] || process.env.HLQ_BASE_URL || process.env.HLQUERY_BASE_URL || 'http://localhost:9200';
11
+ const token = process.argv[3] || process.env.HLQUERY_TOKEN || null;
12
+ const collectionName = `node_sql_example_${process.pid}`;
13
+ const client = new Client(baseUrl);
14
+
15
+ if (token) {
16
+ client.setAuthToken(token, 'bearer');
17
+ }
18
+
19
+ await client.collections().delete(collectionName);
20
+ await client.collections().create(collectionName, {
21
+ fields: [
22
+ { name: 'title', type: 'string' },
23
+ { name: 'category', type: 'string' },
24
+ { name: 'price', type: 'float' }
25
+ ]
26
+ });
27
+ await client.documents().import(collectionName, [
28
+ { id: 'book_1', title: 'Algebra Basics', category: 'math', price: 19.99 },
29
+ { id: 'book_2', title: 'Geometry Proofs', category: 'math', price: 29.99 },
30
+ { id: 'book_3', title: 'Cooking Basics', category: 'food', price: 14.99 }
31
+ ]);
11
32
 
12
33
  // Top-level SQL through /sql
13
34
  const rows = await client.sql('SHOW COLLECTIONS;');
@@ -15,17 +36,20 @@ async function main() {
15
36
 
16
37
  // Top-level SQL statement execution through POST /sql
17
38
  const execResult = await client.execSql(
18
- "INSERT INTO logs_archive (id, title) VALUES ('row-1', 'warm cache');"
39
+ `INSERT INTO ${collectionName} (id, title, category, price) VALUES ('book_4', 'Inserted via SQL', 'ops', 39.99);`
19
40
  );
20
41
  console.log('Exec result:', execResult.getBody());
21
42
 
22
43
  // Collection-bound SQL SELECT through /collections/{name}/documents/search
23
- const products = await client.sqlSearch(
24
- 'products',
25
- 'SELECT id, title, price FROM products WHERE price > 100 ORDER BY price DESC LIMIT 3;',
44
+ const books = await client.sqlSearch(
45
+ collectionName,
46
+ `SELECT id, title, price FROM ${collectionName} WHERE price > 10 ORDER BY price DESC LIMIT 3;`,
26
47
  { highlight: false }
27
48
  );
28
- console.log('Products SQL results:', products.getBody());
49
+ console.log('Books SQL results:', books.getBody());
50
+
51
+ const cleanup = await client.collections().delete(collectionName);
52
+ console.log('Cleanup:', cleanup.getBody());
29
53
  }
30
54
 
31
55
  main().catch(console.error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hlquery-node-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Node.js client library for hlquery search engine",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",