Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
af187e7
feat(guides): add pushSetup for ingestion API
shortcuts Nov 18, 2024
2ec3de2
fix(generators): only add lambda if guide exists
shortcuts Nov 18, 2024
716d628
feat: go
shortcuts Nov 18, 2024
49aee0d
feat: python
shortcuts Nov 18, 2024
65b5285
feat: java
shortcuts Nov 18, 2024
63273df
feat: ruby
shortcuts Nov 18, 2024
b77c688
feat: php
shortcuts Nov 18, 2024
55482e9
feat: kotlin
shortcuts Nov 18, 2024
f2dd927
feat: kotlin
shortcuts Nov 18, 2024
07080d9
feat: scala
shortcuts Nov 18, 2024
df57942
feat: swift
shortcuts Nov 18, 2024
fda46db
feat: sicharpe
shortcuts Nov 18, 2024
73aacf8
fix: go
shortcuts Nov 18, 2024
d074de8
fix: partially fixy swift nifty
shortcuts Nov 18, 2024
1dfc709
fix: java and maybe swift
shortcuts Nov 18, 2024
aa4f964
fix kt
millotp Nov 18, 2024
f97e2d3
fix: scala
shortcuts Nov 18, 2024
c5e7bcc
kt playground
millotp Nov 18, 2024
71e7e3a
fix: csharp but still doesn't work
shortcuts Nov 18, 2024
af6612a
fix: CSHARP YES
shortcuts Nov 18, 2024
d213466
fix: csproj for csharp
shortcuts Nov 18, 2024
ca9c2fb
fix: upgrade csharpier thanks https://github.com/belav/csharpier/issu…
shortcuts Nov 18, 2024
7db1e82
fix: here too
shortcuts Nov 18, 2024
2f88d00
fix: upgrade csharpier correctly
shortcuts Nov 18, 2024
ac72f95
swift magic
millotp Nov 19, 2024
146454f
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
7efc765
chore: review
shortcuts Nov 19, 2024
6b0e133
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
fe786ef
chore: review
shortcuts Nov 19, 2024
e68a2ef
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
c76b97a
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
01c2b60
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
d9377a2
Merge branch 'main' into feat/guides-for-push
shortcuts Nov 19, 2024
8882dc8
Update templates/csharp/guides/ingestion/pushSetup.mustache
shortcuts Nov 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/generation.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const patterns = [
'!clients/algoliasearch-client-csharp/algoliasearch/Transport/**',
'!clients/algoliasearch-client-csharp/algoliasearch/Models/Common/**',

'!docs/guides/csharp/src/program.cs',

'tests/output/csharp/global.json',

// Dart
Expand All @@ -49,6 +51,8 @@ export const patterns = [
'!clients/algoliasearch-client-go/algolia/debug/*',
'!clients/algoliasearch-client-go/algolia/utils/*',

'!docs/guides/go/src/main.go',

'!tests/output/go/go.*',

// Java
Expand Down
4 changes: 4 additions & 0 deletions docs/guides/csharp/src/program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public class Program
{
public static void Main() { }
}
7 changes: 7 additions & 0 deletions docs/guides/go/src/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("wow nice")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.algolia.codegen.utils.*;
import com.google.common.collect.ImmutableMap.Builder;
import com.samskivert.mustache.Mustache.Lambda;
import java.io.File;
import java.util.*;
import java.util.Map.Entry;
import java.util.TreeMap;
Expand Down Expand Up @@ -159,7 +160,9 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
bundle.put("isSyncClient", false);
// special lambda for dynamic templates
bundle.put("dynamicTemplate", new DynamicTemplateLambda(this));
bundle.put("dynamicSnippet", new DynamicSnippetLambda(this, models, operations, language, client));
if (new File("tests/CTS/guides/" + client + ".json").exists()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be done inside of the lambda directly to avoid leaking the internal logic here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's always called I wanted to avoid no-op as it's less explicit when looking at this file, idk what you prefer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this files makes it harder since now the path is in multiple files rather than just the lambda, this file should be more generic IMO

bundle.put("dynamicSnippet", new DynamicSnippetLambda(this, models, operations, language, client));
}
bundle.put("lambda", lambda);

String languageVersion = ctsManager.getLanguageVersion((String) additionalProperties.getOrDefault("languageVersion", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public DynamicSnippetLambda(
this.operations = operations;
this.paramsType = new ParametersWithDataType(models, language, client, true);

JsonNode snippetsFile = Helpers.readJsonFile("tests/CTS/guides/search.json");
JsonNode snippetsFile = Helpers.readJsonFile("tests/CTS/guides/" + client + ".json");
this.snippets = Json.mapper().convertValue(snippetsFile, new TypeReference<Map<String, Snippet>>() {});

// we can't access the default template manager, so we have to create our own
Expand Down
2 changes: 1 addition & 1 deletion playground/csharp/Performances/Performances.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Performances</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion playground/csharp/Playground/Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>12</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
27 changes: 3 additions & 24 deletions playground/go/ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"time"

"github.com/algolia/algoliasearch-client-go/v4/algolia/ingestion"
)
Expand All @@ -14,34 +13,14 @@ func testIngestion(appID, apiKey string) int {
}

// another example to generate payload for a request.
createAuthenticationResponse, err := ingestionClient.CreateAuthentication(ingestionClient.NewApiCreateAuthenticationRequest(
&ingestion.AuthenticationCreate{
Type: ingestion.AUTHENTICATION_TYPE_BASIC,
Name: fmt.Sprintf("my-authentication-%d", time.Now().Unix()),
Input: ingestion.AuthInput{
AuthBasic: &ingestion.AuthBasic{
Username: "username",
Password: "password",
},
},
}))

_, payload, err := ingestionClient.ListTasksWithHTTPInfo(ingestionClient.NewApiListTasksRequest())
if err != nil {
fmt.Printf("request error with CreateAuthentication: %v\n", err)
return 1
}
fmt.Printf("request error: %v\n", err)

printResponse(createAuthenticationResponse)

listAuthenticationsResponse, err := ingestionClient.ListAuthentications(
ingestionClient.NewApiListAuthenticationsRequest().WithItemsPerPage(2),
)
if err != nil {
fmt.Printf("request error with GetAuthentications: %v\n", err)
return 1
}

printResponse(listAuthenticationsResponse)
fmt.Println(string(payload))

return 0
}
7 changes: 6 additions & 1 deletion playground/kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm") version "2.0.21"
kotlin("plugin.serialization") version "2.0.21"
id("application")
}

repositories {
Expand All @@ -16,4 +17,8 @@ dependencies {

tasks.test {
useJUnitPlatform()
}
}

application {
mainClass.set("com.algolia.playground.${property("client")}Kt")
}
3 changes: 2 additions & 1 deletion scripts/buildLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ async function buildLanguage(language: Language, gens: Generator[], buildType: B
break;
case 'java':
case 'kotlin':
// the playground specify search but it will still build everything
await run(
`./gradle/gradlew -p ${cwd} ${buildType === 'client' || buildType === 'playground' ? 'assemble' : 'build'}`,
`./gradle/gradlew -p ${cwd} ${buildType === 'client' || buildType === 'playground' ? 'assemble -Pclient=Search' : 'build'}`,
{ language },
);
break;
Expand Down
2 changes: 1 addition & 1 deletion scripts/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export async function formatter(language: string, cwd: string): Promise<void> {
const spinner = createSpinner(`running formatter for '${language}' in '${cwd}'`);
switch (language) {
case 'csharp':
if (cwd.includes('tests') || cwd.includes('snippets')) {
if (cwd.includes('tests') || cwd.includes('snippets') || cwd.includes('guides')) {
await run('dotnet format --no-restore && dotnet tool restore && dotnet dotnet-csharpier .', {
cwd,
language,
Expand Down
10 changes: 3 additions & 7 deletions scripts/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ export async function playground({ language, client }: { language: AllLanguage;
);
break;
case 'kotlin':
await run(
`./gradle/gradlew -p playground/kotlin -PmainClass=com.algolia.playground.${createClientName(
client,
'kotlin',
)}Kt run`,
{ language },
);
await run(`./gradle/gradlew -p playground/kotlin run -Pclient=${createClientName(client, 'kotlin')}`, {
language,
});
break;
case 'php':
await runComposerInstall();
Expand Down
31 changes: 31 additions & 0 deletions templates/csharp/guides/ingestion/pushSetup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Text.Json;
using System.Collections.Generic;

{{> snippets/import}}

using Action = Algolia.Search.Models.Ingestion.Action;
using Algolia.Search.Models.Ingestion.PushTaskRecords;

class PushSetup
{
public static async Task Main(string[] args)
{
string jsonContent = File.ReadAllText("/my-raw-records.json");
var records = JsonSerializer.Deserialize<List<PushTaskRecords>>(jsonContent);
// use the region matching your applicationID
{{> snippets/init}}

try
{
var run = {{#dynamicSnippet}}pushSetup{{/dynamicSnippet}};
Console.WriteLine(run.RunID);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using System.Collections.Generic;

{{> snippets/import}}

class Program
class SaveObjectsMovies
{
public static async Task Main(string[] args)
{
Expand Down
4 changes: 2 additions & 2 deletions templates/csharp/snippets/dotnet-tools.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.29.2",
"version": "0.30.1",
"commands": [
"dotnet-csharpier"
]
}
}
}
}
2 changes: 1 addition & 1 deletion templates/csharp/snippets/src.csproj.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Algolia</RootNamespace>
Expand Down
36 changes: 36 additions & 0 deletions templates/go/guides/ingestion/pushSetup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"os"
"encoding/json"
"fmt"
"net/http"
)


{{> snippets/import}}

func push() {
// use the region matching your applicationID
{{> snippets/init}}

content, err := os.ReadFile("/my-raw-records.json")
if err != nil {
panic(err)
}

var records []ingestion.PushTaskRecords

err = json.Unmarshal(content, &records)
if err != nil {
panic(err)
}

run, err := {{#dynamicSnippet}}pushSetup{{/dynamicSnippet}}
if err != nil {
panic(err)
}

// use runID in the Observability debugger
fmt.Println("run", run.RunID)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or main run id soon !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😶 shhhhh

}
2 changes: 1 addition & 1 deletion templates/go/guides/search/saveObjectsMovies.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

{{> snippets/import}}

func main() {
func saveObjectsMovies() {
// read json file
url := "https://dashboard.algolia.com/sample_datasets/movie.json"
response, err := http.Get(url)
Expand Down
3 changes: 2 additions & 1 deletion templates/go/snippets/.golangci.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ linters:
disable:
- ineffassign
- staticcheck
- unused

issues:
exclude-generated: disable

run:
concurrency: 2
timeout: 10m
timeout: 10m
23 changes: 23 additions & 0 deletions templates/java/guides/ingestion/pushSetup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.fasterxml.jackson.databind.*;
import java.io.File;
import java.util.List;
import java.util.Map;

{{> snippets/import}}

public class pushSetup {
public static void main(String[] args) throws Exception {
JsonNode content = new ObjectMapper().readTree(new File("/my-raw-records.json"));
List<PushTaskRecords> records = new ObjectMapper().readerForListOf(Map.class).readValue(content);

// use the region matching your applicationID
{{> snippets/init}}

RunResponse run = {{#dynamicSnippet}}pushSetup{{/dynamicSnippet}};

// use runID in the Observability debugger
System.out.println(run.getRunID());

client.close();
}
}
20 changes: 20 additions & 0 deletions templates/javascript/guides/ingestion/pushSetup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fs from 'node:fs';
import type { PushTaskRecords } from 'algoliasearch';

{{> snippets/import}}

// use the region matching your applicationID
{{> snippets/init}}

try {
// read local JSON file containing array of records
const records = JSON.parse(fs.readFileSync('/my-raw-records.json', 'utf8')) as PushTaskRecords[];

// push records to the API
const run = {{#dynamicSnippet}}pushSetup{{/dynamicSnippet}}

// use runID in the Observability debugger
console.log(run.runID);
} catch (err) {
console.error(err);
}
1 change: 1 addition & 0 deletions templates/javascript/snippets/package.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "javascript-{{mode}}",
"version": "1.0.0",
"type": "module",
"dependencies": {
"typescript": "5.6.3",
"@algolia/client-common": "link:../../../clients/algoliasearch-client-javascript/packages/client-common",
Expand Down
28 changes: 28 additions & 0 deletions templates/kotlin/guides/ingestion/pushSetup.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.example
{{> snippets/import}}
{{#isSearchClient}}
import com.algolia.client.extensions.*
{{/isSearchClient}}
import com.algolia.client.model.ingestion.*

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import java.io.File

suspend fun main() {
val json = File("/my-raw-records.json").readText()
val records: List<PushTaskRecords> = Json.decodeFromString(ListSerializer(PushTaskRecords.serializer()), json)

// use the region matching your applicationID
{{> snippets/init}}

try {
val run = client.{{#dynamicSnippet}}pushSetup{{/dynamicSnippet}}

// use runID in the Observability debugger
println(run)
} catch(e: Exception) {
println(e.message)
}
}
Loading
Loading