elasticlink 1.0.0-beta.1 → 1.0.0

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.
Files changed (64) hide show
  1. package/README.md +74 -31
  2. package/dist/index.cjs +1528 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1890 -0
  5. package/dist/index.d.cts.map +1 -0
  6. package/dist/index.d.ts +1889 -20
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1474 -18
  9. package/dist/index.js.map +1 -0
  10. package/package.json +27 -21
  11. package/dist/aggregation.builder.d.ts +0 -6
  12. package/dist/aggregation.builder.d.ts.map +0 -1
  13. package/dist/aggregation.builder.js +0 -81
  14. package/dist/aggregation.types.d.ts +0 -258
  15. package/dist/aggregation.types.d.ts.map +0 -1
  16. package/dist/aggregation.types.js +0 -6
  17. package/dist/bulk.builder.d.ts +0 -29
  18. package/dist/bulk.builder.d.ts.map +0 -1
  19. package/dist/bulk.builder.js +0 -51
  20. package/dist/bulk.types.d.ts +0 -47
  21. package/dist/bulk.types.d.ts.map +0 -1
  22. package/dist/bulk.types.js +0 -6
  23. package/dist/field.helpers.d.ts +0 -241
  24. package/dist/field.helpers.d.ts.map +0 -1
  25. package/dist/field.helpers.js +0 -333
  26. package/dist/field.types.d.ts +0 -348
  27. package/dist/field.types.d.ts.map +0 -1
  28. package/dist/field.types.js +0 -6
  29. package/dist/index-management.builder.d.ts +0 -38
  30. package/dist/index-management.builder.d.ts.map +0 -1
  31. package/dist/index-management.builder.js +0 -69
  32. package/dist/index-management.types.d.ts +0 -136
  33. package/dist/index-management.types.d.ts.map +0 -1
  34. package/dist/index-management.types.js +0 -6
  35. package/dist/mapping.builder.d.ts +0 -53
  36. package/dist/mapping.builder.d.ts.map +0 -1
  37. package/dist/mapping.builder.js +0 -39
  38. package/dist/mapping.types.d.ts +0 -200
  39. package/dist/mapping.types.d.ts.map +0 -1
  40. package/dist/mapping.types.js +0 -6
  41. package/dist/multi-search.builder.d.ts +0 -23
  42. package/dist/multi-search.builder.d.ts.map +0 -1
  43. package/dist/multi-search.builder.js +0 -48
  44. package/dist/multi-search.types.d.ts +0 -50
  45. package/dist/multi-search.types.d.ts.map +0 -1
  46. package/dist/multi-search.types.js +0 -6
  47. package/dist/query.builder.d.ts +0 -4
  48. package/dist/query.builder.d.ts.map +0 -1
  49. package/dist/query.builder.js +0 -329
  50. package/dist/query.types.d.ts +0 -468
  51. package/dist/query.types.d.ts.map +0 -1
  52. package/dist/query.types.js +0 -7
  53. package/dist/settings.presets.d.ts +0 -117
  54. package/dist/settings.presets.d.ts.map +0 -1
  55. package/dist/settings.presets.js +0 -137
  56. package/dist/suggester.builder.d.ts +0 -23
  57. package/dist/suggester.builder.d.ts.map +0 -1
  58. package/dist/suggester.builder.js +0 -51
  59. package/dist/suggester.types.d.ts +0 -90
  60. package/dist/suggester.types.d.ts.map +0 -1
  61. package/dist/suggester.types.js +0 -6
  62. package/dist/vector.types.d.ts +0 -17
  63. package/dist/vector.types.d.ts.map +0 -1
  64. package/dist/vector.types.js +0 -6
package/README.md CHANGED
@@ -71,15 +71,7 @@ const facetedSearch = queryBuilder(productMappings)
71
71
  .build();
72
72
  ```
73
73
 
74
- Type safety in actionwrong field types are caught at compile time:
75
-
76
- ```typescript
77
- queryBuilder(productMappings).match('category', 'electronics');
78
- // ^^^^^^^^^^
79
- // TypeScript error: 'category' is a keyword field — use term(), not match()
80
-
81
- queryBuilder(productMappings).term('category', 'electronics'); // ✅ Correct
82
- ```
74
+ Wrong field types are caught at compile time `.match()` on a keyword field is a TypeScript error, use `.term()`. See [TypeScript Support](#typescript-support) for a worked example.
83
75
 
84
76
  ## Examples
85
77
 
@@ -171,25 +163,6 @@ const result = queryBuilder(ecommerceMappings)
171
163
 
172
164
  </details>
173
165
 
174
- ### Dynamic Search with Conditional Filters
175
-
176
- Build queries dynamically based on runtime values. `.when(condition, fn)` — when the condition is falsy, the builder is returned unchanged.
177
-
178
- ```typescript
179
- const buildDynamicQuery = (filters: SearchFilters) => {
180
- return queryBuilder(productMappings)
181
- .bool()
182
- .when(filters.searchTerm, (q) => q.must((q2) => q2.match('name', filters.searchTerm!, { boost: 2 })))
183
- .when(filters.category, (q) => q.filter((q2) => q2.term('category', filters.category!)))
184
- .when(filters.minPrice != null && filters.maxPrice != null, (q) =>
185
- q.filter((q2) => q2.range('price', { gte: filters.minPrice!, lte: filters.maxPrice! }))
186
- )
187
- .from(filters.offset || 0)
188
- .size(filters.limit || 20)
189
- .build();
190
- };
191
- ```
192
-
193
166
  ### Aggregations — Portfolio Analytics
194
167
 
195
168
  Terms + sub-aggregation + date histogram in one request.
@@ -304,6 +277,76 @@ const q2 = queryBuilder(userMappings).match('email', 'john@example.com').build()
304
277
  const q3 = queryBuilder(userMappings).term('email', 'john@example.com').build();
305
278
  ```
306
279
 
280
+ ## Vanilla JavaScript
281
+
282
+ elasticlink works in vanilla JavaScript with full IntelliSense — no TypeScript required. The library ships both ESM and CommonJS builds, so `import` and `require()` both work.
283
+
284
+ ### Setup
285
+
286
+ For project-wide type checking, add a `jsconfig.json` to your project root:
287
+
288
+ ```json
289
+ {
290
+ "compilerOptions": {
291
+ "checkJs": true,
292
+ "strict": true,
293
+ "module": "commonjs",
294
+ "moduleResolution": "node10",
295
+ "target": "ES2022"
296
+ }
297
+ }
298
+ ```
299
+
300
+ Or enable per-file with `// @ts-check` at the top of any `.js` file.
301
+
302
+ ### Usage
303
+
304
+ Query builder methods provide field-name autocomplete and type constraints in VS Code even without any configuration:
305
+
306
+ ```js
307
+ const { mappings, text, keyword, float, queryBuilder } = require('elasticlink');
308
+
309
+ const productSchema = mappings({
310
+ name: text(),
311
+ price: float(),
312
+ category: keyword()
313
+ });
314
+
315
+ // Field names autocomplete, and are constrained by type:
316
+ const query = queryBuilder(productSchema)
317
+ .match('name', 'laptop') // 'name' is text — allowed in match()
318
+ .range('price', { gte: 500 }) // 'price' is numeric — allowed in range()
319
+ .term('category', 'electronics') // 'category' is keyword — allowed in term()
320
+ .build();
321
+ ```
322
+
323
+ ### Deriving Document Types
324
+
325
+ In TypeScript you'd use `type Product = Infer<typeof schema>`. In JavaScript, use the `inferType()` helper:
326
+
327
+ > ⚠️ **Type-only helper.** `inferType()` always returns `undefined`. It exists so you can write `typeof _Product` in a JSDoc `@type` annotation. Never use the returned value at runtime — accessing a property on it (e.g. `_Product.name`) will throw `TypeError`.
328
+
329
+ ```js
330
+ const { mappings, text, keyword, float, inferType } = require('elasticlink');
331
+
332
+ const schema = mappings({ name: text(), price: float(), category: keyword() });
333
+
334
+ const _Product = inferType(schema); // undefined at runtime; only the type matters
335
+
336
+ /** @type {typeof _Product} */
337
+ const doc = { name: 'Laptop', price: 999, category: 'electronics' };
338
+ // ^ full autocomplete on all properties
339
+ ```
340
+
341
+ Alternatively, use the JSDoc import syntax directly:
342
+
343
+ ```js
344
+ /** @type {import('elasticlink').Infer<typeof schema>} */
345
+ const doc = { name: 'Laptop', price: 999, category: 'electronics' };
346
+ ```
347
+
348
+ See [`examples/vanilla-js/`](examples/vanilla-js/) for a complete working example.
349
+
307
350
  ## Settings Presets
308
351
 
309
352
  Ready-made index settings for common lifecycle stages. Use with `.settings()` on `indexBuilder()` or pass directly to the ES `_settings` API.
@@ -901,9 +944,9 @@ const alerts = queryBuilder(alertRuleMappings)
901
944
 
902
945
  ## Compatibility
903
946
 
904
- | elasticlink | Node.js | Elasticsearch |
905
- | ------------ | ---------- | ------------- |
906
- | 1.0.0-beta.1 | 20, 22, 24 | 9.x (≥9.0.0) |
947
+ | elasticlink | Node.js | Elasticsearch |
948
+ | ----------- | ---------- | ---------------------- |
949
+ | 1.0.0 | 20, 22, 24 | 9.x (≥9.0.0), tested against 9.4.2 |
907
950
 
908
951
  Tested against the versions listed. Peer dependency is `@elastic/elasticsearch >=9.0.0`.
909
952