@algolia/wizard 0.9.0-rc.79.69 → 0.9.0-rc.82.72
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/dist/main.js
CHANGED
|
@@ -2266,6 +2266,8 @@ function shellQuote(value) {
|
|
|
2266
2266
|
// src/lib/languages.ts
|
|
2267
2267
|
var ENTRYPOINT_TOKEN = "{entrypoint}";
|
|
2268
2268
|
var INGEST_DIR = ".algolia-wizard";
|
|
2269
|
+
var SWIFT_PACKAGE_DIR = `${INGEST_DIR}/Ingest`;
|
|
2270
|
+
var CSHARP_PROJECT = `${INGEST_DIR}/ingest/ingest.csproj`;
|
|
2269
2271
|
var VISIBLE_INGEST_DIR = "algolia-wizard";
|
|
2270
2272
|
var PY_VENV = `${INGEST_DIR}/.venv`;
|
|
2271
2273
|
var PY_VENV_PYTHON = `${PY_VENV}/bin/python`;
|
|
@@ -2638,6 +2640,137 @@ var LANGUAGE_PROFILES = {
|
|
|
2638
2640
|
// that some repos use it for source; scanning it is cheap, missing source
|
|
2639
2641
|
// is not.
|
|
2640
2642
|
skipDirs: ["target"]
|
|
2643
|
+
},
|
|
2644
|
+
csharp: {
|
|
2645
|
+
id: "csharp",
|
|
2646
|
+
displayName: "C#",
|
|
2647
|
+
aliases: ["c#", "csharp", "cs", ".net", "dotnet", "net", "asp.net"],
|
|
2648
|
+
manifests: ["*.csproj", "*.sln", "global.json"],
|
|
2649
|
+
packageManagers: [
|
|
2650
|
+
{
|
|
2651
|
+
id: "dotnet",
|
|
2652
|
+
// A self-contained project under .algolia-wizard keeps the ingest script
|
|
2653
|
+
// out of the repo's own build graph.
|
|
2654
|
+
dependency: { mode: "agent-declares", file: CSHARP_PROJECT },
|
|
2655
|
+
installSteps: [{ argv: ["dotnet", "restore", CSHARP_PROJECT] }],
|
|
2656
|
+
ingest: {
|
|
2657
|
+
kind: "auto",
|
|
2658
|
+
argv: ["dotnet", "run", "--project", ENTRYPOINT_TOKEN],
|
|
2659
|
+
entrypointExtensions: [".csproj"]
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
],
|
|
2663
|
+
sdk: {
|
|
2664
|
+
packageName: "Algolia.Search",
|
|
2665
|
+
versionPin: "7.*",
|
|
2666
|
+
docKey: "csharp"
|
|
2667
|
+
},
|
|
2668
|
+
ingestEntrypointExample: CSHARP_PROJECT,
|
|
2669
|
+
verification: [
|
|
2670
|
+
{
|
|
2671
|
+
label: "dotnet build",
|
|
2672
|
+
argv: ["dotnet", "build", CSHARP_PROJECT, "--nologo"],
|
|
2673
|
+
requiresFile: CSHARP_PROJECT
|
|
2674
|
+
}
|
|
2675
|
+
],
|
|
2676
|
+
envReadInstruction: 'Read them from `Environment.GetEnvironmentVariable("NAME")`.',
|
|
2677
|
+
// Deliberately not `packages`: modern .NET uses PackageReference, and
|
|
2678
|
+
// `packages/` is where pnpm/Lerna/Turborepo monorepos keep all their source —
|
|
2679
|
+
// skipping it would hide the entities the scan is looking for.
|
|
2680
|
+
skipDirs: ["bin", "obj"]
|
|
2681
|
+
},
|
|
2682
|
+
swift: {
|
|
2683
|
+
id: "swift",
|
|
2684
|
+
displayName: "Swift",
|
|
2685
|
+
aliases: ["swift", "swiftui", "ios", "vapor"],
|
|
2686
|
+
manifests: ["Package.swift", "*.xcodeproj", "*.xcworkspace"],
|
|
2687
|
+
packageManagers: [
|
|
2688
|
+
{
|
|
2689
|
+
id: "swiftpm",
|
|
2690
|
+
dependency: {
|
|
2691
|
+
mode: "agent-declares",
|
|
2692
|
+
file: `${SWIFT_PACKAGE_DIR}/Package.swift`
|
|
2693
|
+
},
|
|
2694
|
+
// `swift build` resolves and fetches; a cold build of the client is slow
|
|
2695
|
+
// (minutes), which is why the caller degrades to the manual command when
|
|
2696
|
+
// this fails.
|
|
2697
|
+
installSteps: [
|
|
2698
|
+
{
|
|
2699
|
+
argv: ["swift", "build", "--package-path", SWIFT_PACKAGE_DIR],
|
|
2700
|
+
requiresFile: `${SWIFT_PACKAGE_DIR}/Package.swift`
|
|
2701
|
+
}
|
|
2702
|
+
],
|
|
2703
|
+
ingest: {
|
|
2704
|
+
kind: "auto",
|
|
2705
|
+
argv: ["swift", "run", "--package-path", SWIFT_PACKAGE_DIR],
|
|
2706
|
+
entrypointExtensions: [".swift"]
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
],
|
|
2710
|
+
sdk: {
|
|
2711
|
+
packageName: "algoliasearch-client-swift",
|
|
2712
|
+
// SwiftPM range syntax, not an exact version — a bare "9.0.0" in a
|
|
2713
|
+
// Package.swift dependency pins the patch.
|
|
2714
|
+
versionPin: 'from: "9.0.0"',
|
|
2715
|
+
docKey: "swift"
|
|
2716
|
+
},
|
|
2717
|
+
ingestEntrypointExample: `${SWIFT_PACKAGE_DIR}/Sources/Ingest/main.swift`,
|
|
2718
|
+
verification: [
|
|
2719
|
+
{
|
|
2720
|
+
label: "swift build",
|
|
2721
|
+
argv: ["swift", "build", "--package-path", SWIFT_PACKAGE_DIR],
|
|
2722
|
+
requiresFile: `${SWIFT_PACKAGE_DIR}/Package.swift`
|
|
2723
|
+
}
|
|
2724
|
+
],
|
|
2725
|
+
envReadInstruction: "Read them from `ProcessInfo.processInfo.environment`.",
|
|
2726
|
+
skipDirs: ["Pods", "DerivedData", "Carthage", ".build"]
|
|
2727
|
+
},
|
|
2728
|
+
dart: {
|
|
2729
|
+
id: "dart",
|
|
2730
|
+
displayName: "Dart",
|
|
2731
|
+
aliases: ["dart", "flutter"],
|
|
2732
|
+
manifests: ["pubspec.yaml"],
|
|
2733
|
+
packageManagers: [
|
|
2734
|
+
{
|
|
2735
|
+
id: "flutter-pub",
|
|
2736
|
+
detectFiles: [".metadata"],
|
|
2737
|
+
dependency: { mode: "agent-declares", file: "pubspec.yaml" },
|
|
2738
|
+
installSteps: [{ argv: ["flutter", "pub", "get"] }],
|
|
2739
|
+
ingest: {
|
|
2740
|
+
kind: "auto",
|
|
2741
|
+
argv: ["dart", "run", ENTRYPOINT_TOKEN],
|
|
2742
|
+
entrypointExtensions: [".dart"]
|
|
2743
|
+
}
|
|
2744
|
+
},
|
|
2745
|
+
{
|
|
2746
|
+
id: "pub",
|
|
2747
|
+
dependency: { mode: "agent-declares", file: "pubspec.yaml" },
|
|
2748
|
+
installSteps: [{ argv: ["dart", "pub", "get"] }],
|
|
2749
|
+
ingest: {
|
|
2750
|
+
kind: "auto",
|
|
2751
|
+
argv: ["dart", "run", ENTRYPOINT_TOKEN],
|
|
2752
|
+
entrypointExtensions: [".dart"]
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
],
|
|
2756
|
+
sdk: {
|
|
2757
|
+
packageName: "algolia_client_search",
|
|
2758
|
+
versionPin: "^1.0.0",
|
|
2759
|
+
docKey: "dart"
|
|
2760
|
+
},
|
|
2761
|
+
ingestEntrypointExample: `${INGEST_DIR}/ingest.dart`,
|
|
2762
|
+
verification: [
|
|
2763
|
+
{
|
|
2764
|
+
// Gated on the directory it analyzes, not just pubspec.yaml: a run that
|
|
2765
|
+
// only built a search UI never created it, and `dart analyze` on a
|
|
2766
|
+
// missing path fails the whole verification pass.
|
|
2767
|
+
label: "dart analyze",
|
|
2768
|
+
argv: ["dart", "analyze", INGEST_DIR],
|
|
2769
|
+
requiresFile: INGEST_DIR
|
|
2770
|
+
}
|
|
2771
|
+
],
|
|
2772
|
+
envReadInstruction: "Read them from `Platform.environment`.",
|
|
2773
|
+
skipDirs: ["build"]
|
|
2641
2774
|
}
|
|
2642
2775
|
};
|
|
2643
2776
|
var DEFAULT_LANGUAGE_ID = "javascript";
|
|
@@ -3320,7 +3453,7 @@ var detectLanguageSchema = z16.object({
|
|
|
3320
3453
|
var detectLanguage = () => runAgent({
|
|
3321
3454
|
instructions: [
|
|
3322
3455
|
"Analyze the codebase and determine the programming languages and frameworks used",
|
|
3323
|
-
"Start from the dependency manifests: package.json, pyproject.toml, requirements.txt, Gemfile, composer.json, go.mod, pom.xml, build.gradle(.kts), build.sbt.",
|
|
3456
|
+
"Start from the dependency manifests: package.json, pyproject.toml, requirements.txt, Gemfile, composer.json, go.mod, pom.xml, build.gradle(.kts), *.csproj, build.sbt, Package.swift, pubspec.yaml.",
|
|
3324
3457
|
"List the language that owns the backend/data code first \u2014 that is the one an ingestion script will be written in.",
|
|
3325
3458
|
"If a superset language is found, exclude the subset language. TS-over-JS. Kotlin-over-Java when Kotlin is primary.",
|
|
3326
3459
|
"If a meta-framework is used, exclude the framework. Next-over-React.",
|
|
@@ -3373,7 +3506,7 @@ var MODE_CONFIG = {
|
|
|
3373
3506
|
"Analyze the codebase to find the data entities (models) that should be ingested into Algolia.",
|
|
3374
3507
|
"For each entity, return its name, the file path(s) where it is defined, and its indexable attribute keys (the fields a user would search or filter on).",
|
|
3375
3508
|
"Inspect the source of each entity to extract real field names for attributes \u2014 do not guess or leave attributes empty.",
|
|
3376
|
-
"Entities live wherever the stack keeps them: TypeScript interfaces or a Prisma schema, Django models.py, Rails app/models, Laravel Eloquent models, JPA @Entity classes, Go structs, Pydantic models.",
|
|
3509
|
+
"Entities live wherever the stack keeps them: TypeScript interfaces or a Prisma schema, Django models.py, Rails app/models, Laravel Eloquent models, JPA @Entity classes, Go structs, C# entity classes, Pydantic models.",
|
|
3377
3510
|
"Prefer domain models (e.g. Document, Product, User) over framework or infrastructure types.",
|
|
3378
3511
|
"Use as few tools as possible, but do not guess. If you cannot find any entities, return an empty array.",
|
|
3379
3512
|
"Ignore directories that may be related to testing, like `/fixtures`, `/tests`, etc",
|
|
@@ -3396,7 +3529,7 @@ var MODE_CONFIG = {
|
|
|
3396
3529
|
verification: {
|
|
3397
3530
|
instructions: [
|
|
3398
3531
|
"Analyze the codebase to determine which code-quality tools are available to validate changes.",
|
|
3399
|
-
"Look at the dependency manifest and config files for the project's languages: package.json scripts with tsconfig/eslint/prettier, pyproject.toml or setup.cfg (ruff, mypy, black), Gemfile with .rubocop.yml, composer.json scripts (phpstan, pint), go.mod with a golangci-lint config, Maven/Gradle verification tasks.",
|
|
3532
|
+
"Look at the dependency manifest and config files for the project's languages: package.json scripts with tsconfig/eslint/prettier, pyproject.toml or setup.cfg (ruff, mypy, black), Gemfile with .rubocop.yml, composer.json scripts (phpstan, pint), go.mod with a golangci-lint config, Maven/Gradle verification tasks, .NET analyzers, analysis_options.yaml.",
|
|
3400
3533
|
'Return the tool names as an array, e.g. ["eslint", "prettier", "tsc"] or ["ruff", "mypy"].',
|
|
3401
3534
|
"Use as few tools as possible, but do not guess. If you cannot find any, return an empty array.",
|
|
3402
3535
|
"Ignore directories that may be related to testing, like `/fixtures`, `/tests`, etc",
|
|
@@ -3424,7 +3557,7 @@ async function runAnalysis(mode, extraInstructions = []) {
|
|
|
3424
3557
|
// package.json
|
|
3425
3558
|
var package_default = {
|
|
3426
3559
|
name: "@algolia/wizard",
|
|
3427
|
-
version: "0.9.0-rc.
|
|
3560
|
+
version: "0.9.0-rc.82.72",
|
|
3428
3561
|
description: "Magically implement Algolia functionality in your codebase",
|
|
3429
3562
|
type: "module",
|
|
3430
3563
|
engines: {
|
|
@@ -23,6 +23,9 @@ Install the latest stable within the major; never pin an exact patch.
|
|
|
23
23
|
| Java | `com.algolia:algoliasearch` | `4.+` |
|
|
24
24
|
| Kotlin | `com.algolia:algoliasearch-client-kotlin` | `3.+` |
|
|
25
25
|
| Scala | `com.algolia:algoliasearch-scala_2.13` | `2.+` |
|
|
26
|
+
| C# | `Algolia.Search` | `7.*` |
|
|
27
|
+
| Swift | `algoliasearch-client-swift` | `9.0.0` |
|
|
28
|
+
| Dart | `algolia_client_search` | `^1.0.0` |
|
|
26
29
|
|
|
27
30
|
## Search UI
|
|
28
31
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Save records (Algolia.Search v7)
|
|
2
|
+
|
|
3
|
+
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
+
|
|
5
|
+
The generated script is a self-contained console project at
|
|
6
|
+
`.algolia-wizard/ingest/ingest.csproj` + `Program.cs`, run with
|
|
7
|
+
`dotnet run --project .algolia-wizard/ingest/ingest.csproj`.
|
|
8
|
+
|
|
9
|
+
```xml
|
|
10
|
+
<Project Sdk="Microsoft.NET.Sdk">
|
|
11
|
+
<PropertyGroup>
|
|
12
|
+
<OutputType>Exe</OutputType>
|
|
13
|
+
<TargetFramework>net8.0</TargetFramework>
|
|
14
|
+
<ImplicitUsings>enable</ImplicitUsings>
|
|
15
|
+
<Nullable>enable</Nullable>
|
|
16
|
+
</PropertyGroup>
|
|
17
|
+
<ItemGroup>
|
|
18
|
+
<PackageReference Include="Algolia.Search" Version="7.*" />
|
|
19
|
+
</ItemGroup>
|
|
20
|
+
</Project>
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`<OutputType>Exe</OutputType>` is required — `dotnet run` on a library has no entry
|
|
24
|
+
point. `<TargetFramework>` must match an installed SDK; `net8.0` (LTS) is the safe
|
|
25
|
+
default. Under Central Package Management (`Directory.Packages.props` at the repo
|
|
26
|
+
root) omit `Version` here and pin it there — `Version` on a `PackageReference` is
|
|
27
|
+
an error under CPM (NU1008).
|
|
28
|
+
|
|
29
|
+
```csharp
|
|
30
|
+
using System.Text.Json;
|
|
31
|
+
using Algolia.Search.Clients;
|
|
32
|
+
|
|
33
|
+
var appId = Environment.GetEnvironmentVariable("ALGOLIA_APPLICATION_ID")
|
|
34
|
+
?? throw new InvalidOperationException("ALGOLIA_APPLICATION_ID is not set");
|
|
35
|
+
var writeKey = Environment.GetEnvironmentVariable("ALGOLIA_WRITE_API_KEY")
|
|
36
|
+
?? throw new InvalidOperationException("ALGOLIA_WRITE_API_KEY is not set");
|
|
37
|
+
|
|
38
|
+
var client = new SearchClient(new SearchConfig(appId, writeKey));
|
|
39
|
+
var indexName = "products";
|
|
40
|
+
|
|
41
|
+
var records = new List<Dictionary<string, object>>
|
|
42
|
+
{
|
|
43
|
+
new() { ["objectID"] = "1", ["name"] = "Adam" },
|
|
44
|
+
new() { ["objectID"] = "2", ["name"] = "Benoit" },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
var responses = await client.SaveObjectsAsync(indexName, records, waitForTasks: true);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
```csharp
|
|
51
|
+
Task<List<BatchResponse>> SaveObjectsAsync<T>(
|
|
52
|
+
string indexName, IEnumerable<T> objects, bool waitForTasks = false,
|
|
53
|
+
int batchSize = 1000, RequestOptions options = null,
|
|
54
|
+
CancellationToken cancellationToken = default) where T : class;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Records need an `objectID`; batching in 1,000s is automatic. Returns
|
|
58
|
+
`List<BatchResponse>` — one entry per batch, each `{ TaskID, ObjectIDs }`, never a
|
|
59
|
+
single response. `T` is constrained to `class`, so use `Dictionary<string, object>`
|
|
60
|
+
or a record/class, never a struct.
|
|
61
|
+
|
|
62
|
+
Read records from a JSON file:
|
|
63
|
+
|
|
64
|
+
```csharp
|
|
65
|
+
var json = await File.ReadAllTextAsync("records.json");
|
|
66
|
+
var records = JsonSerializer.Deserialize<List<Dictionary<string, object>>>(json)
|
|
67
|
+
?? new List<Dictionary<string, object>>();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
|
|
71
|
+
stdout line; send all other logging to stderr so nothing follows it on stdout.
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Save records (algolia_client_search v1)
|
|
2
|
+
|
|
3
|
+
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
+
|
|
5
|
+
Use the generated v2 client `algolia_client_search`, never the legacy community
|
|
6
|
+
`algolia` package. The script is run with `dart run .algolia-wizard/ingest.dart`.
|
|
7
|
+
|
|
8
|
+
```yaml
|
|
9
|
+
dependencies:
|
|
10
|
+
algolia_client_search: ^1.0.0
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
This client has **no `saveObjects` helper** (only `saveObjectsWithTransformation`,
|
|
14
|
+
which needs an Ingestion transformation) — use `batch` with `addObject` actions.
|
|
15
|
+
|
|
16
|
+
```dart
|
|
17
|
+
import 'dart:convert';
|
|
18
|
+
import 'dart:io';
|
|
19
|
+
import 'dart:math';
|
|
20
|
+
|
|
21
|
+
import 'package:algolia_client_search/algolia_client_search.dart';
|
|
22
|
+
|
|
23
|
+
Future<void> main() async {
|
|
24
|
+
final appId = Platform.environment['ALGOLIA_APPLICATION_ID'];
|
|
25
|
+
final writeKey = Platform.environment['ALGOLIA_WRITE_API_KEY'];
|
|
26
|
+
if (appId == null || writeKey == null) {
|
|
27
|
+
stderr.writeln('missing Algolia credentials');
|
|
28
|
+
exit(1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const indexName = 'products';
|
|
32
|
+
final client = SearchClient(appId: appId, apiKey: writeKey);
|
|
33
|
+
|
|
34
|
+
final records = <Map<String, dynamic>>[
|
|
35
|
+
{'objectID': '1', 'name': 'Adam'},
|
|
36
|
+
{'objectID': '2', 'name': 'Benoit'},
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
for (var i = 0; i < records.length; i += 1000) {
|
|
41
|
+
final chunk = records.sublist(i, min(i + 1000, records.length));
|
|
42
|
+
final response = await client.batch(
|
|
43
|
+
indexName: indexName,
|
|
44
|
+
batchWriteParams: BatchWriteParams(
|
|
45
|
+
requests: chunk
|
|
46
|
+
.map((r) => BatchRequest(action: Action.addObject, body: r))
|
|
47
|
+
.toList(),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
stderr.writeln('task ${response.taskID}');
|
|
51
|
+
}
|
|
52
|
+
print('ALGOLIA_WIZARD_RECORD_COUNT=${records.length}');
|
|
53
|
+
} finally {
|
|
54
|
+
client.dispose();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`batch` returns a **single** `BatchResponse { int taskID, List<String> objectIDs }`,
|
|
60
|
+
not a list. Gotchas: every record needs an `objectID`; there is no auto-chunking,
|
|
61
|
+
so cap each call at 1,000 records yourself; use the `Action.addObject` enum value
|
|
62
|
+
(`Action.updateObject` replaces instead of adds); and `client.dispose()` is
|
|
63
|
+
mandatory — without it `dart run` never exits.
|
|
64
|
+
|
|
65
|
+
Read records from a JSON file:
|
|
66
|
+
|
|
67
|
+
```dart
|
|
68
|
+
final json = await File('records.json').readAsString();
|
|
69
|
+
final records = (jsonDecode(json) as List).cast<Map<String, dynamic>>();
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
|
|
73
|
+
stdout line (before `dispose()` is fine); send all other logging to stderr so
|
|
74
|
+
nothing follows it on stdout.
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Save records (algoliasearch-client-swift v9)
|
|
2
|
+
|
|
3
|
+
Adds records to an index. Write op — use a **write key**, server-side only.
|
|
4
|
+
|
|
5
|
+
The generated script is a standalone SwiftPM executable package at
|
|
6
|
+
`.algolia-wizard/Ingest` (`Package.swift` + `Sources/Ingest/main.swift`), run with
|
|
7
|
+
`swift run --package-path .algolia-wizard/Ingest`.
|
|
8
|
+
|
|
9
|
+
```swift
|
|
10
|
+
// swift-tools-version: 5.9
|
|
11
|
+
import PackageDescription
|
|
12
|
+
|
|
13
|
+
let package = Package(
|
|
14
|
+
name: "Ingest",
|
|
15
|
+
platforms: [.macOS(.v13)],
|
|
16
|
+
products: [.executable(name: "Ingest", targets: ["Ingest"])],
|
|
17
|
+
dependencies: [
|
|
18
|
+
.package(url: "https://github.com/algolia/algoliasearch-client-swift", from: "9.0.0"),
|
|
19
|
+
],
|
|
20
|
+
targets: [
|
|
21
|
+
.executableTarget(name: "Ingest", dependencies: [
|
|
22
|
+
.product(name: "AlgoliaSearch", package: "algoliasearch-client-swift"),
|
|
23
|
+
.product(name: "AlgoliaCore", package: "algoliasearch-client-swift"),
|
|
24
|
+
]),
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Exactly one executable product, so `swift run --package-path` needs no target name.
|
|
30
|
+
`platforms:` must be declared (the client requires macOS 11+); it is ignored on
|
|
31
|
+
Linux. `package:` is the repo name, not the manifest's `AlgoliaSearchClient`.
|
|
32
|
+
|
|
33
|
+
`main.swift` top-level code can't propagate a thrown error — wrap calls in `do`/`catch`.
|
|
34
|
+
|
|
35
|
+
```swift
|
|
36
|
+
import Foundation
|
|
37
|
+
#if canImport(AlgoliaCore)
|
|
38
|
+
import AlgoliaCore
|
|
39
|
+
#endif
|
|
40
|
+
import AlgoliaSearch
|
|
41
|
+
|
|
42
|
+
let env = ProcessInfo.processInfo.environment
|
|
43
|
+
guard let appID = env["ALGOLIA_APPLICATION_ID"],
|
|
44
|
+
let writeKey = env["ALGOLIA_WRITE_API_KEY"]
|
|
45
|
+
else {
|
|
46
|
+
FileHandle.standardError.write(Data("missing Algolia credentials\n".utf8))
|
|
47
|
+
exit(1)
|
|
48
|
+
}
|
|
49
|
+
let indexName = "products"
|
|
50
|
+
|
|
51
|
+
do {
|
|
52
|
+
let client = try SearchClient(appID: appID, apiKey: writeKey)
|
|
53
|
+
let records: [AnyCodable] = [
|
|
54
|
+
["objectID": "1", "name": "Adam"],
|
|
55
|
+
["objectID": "2", "name": "Benoit"],
|
|
56
|
+
]
|
|
57
|
+
let responses = try await client.saveObjects(
|
|
58
|
+
indexName: indexName, objects: records, waitForTasks: true
|
|
59
|
+
)
|
|
60
|
+
FileHandle.standardError.write(Data("batches: \(responses.count)\n".utf8))
|
|
61
|
+
print("ALGOLIA_WIZARD_RECORD_COUNT=\(records.count)")
|
|
62
|
+
} catch {
|
|
63
|
+
FileHandle.standardError.write(Data("\(error)\n".utf8))
|
|
64
|
+
exit(1)
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```swift
|
|
69
|
+
func saveObjects(
|
|
70
|
+
indexName: String, objects: [some Encodable], waitForTasks: Bool = false,
|
|
71
|
+
batchSize: Int = 1000, requestOptions: RequestOptions? = nil
|
|
72
|
+
) async throws -> [BatchResponse]
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Records need an `objectID`; batching in 1,000s is automatic. Returns an **array**
|
|
76
|
+
of `BatchResponse` (`taskID`, `objectIDs`), one per batch. `objects` is
|
|
77
|
+
`[some Encodable]` — one homogeneous element type, so use `[AnyCodable]` (from
|
|
78
|
+
`AlgoliaCore`) for arbitrary JSON records.
|
|
79
|
+
|
|
80
|
+
Read records from a JSON file:
|
|
81
|
+
|
|
82
|
+
```swift
|
|
83
|
+
let data = try Data(contentsOf: URL(fileURLWithPath: "records.json"))
|
|
84
|
+
let records = try JSONDecoder().decode([AnyCodable].self, from: data)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
After a successful ingest, print `ALGOLIA_WIZARD_RECORD_COUNT=<n>` as the last
|
|
88
|
+
stdout line; send all other logging to stderr so nothing follows it on stdout.
|