Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC-179: Improve API Docs #670

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,18 @@ export const DRIVERS: Driver[] = [
icon: PhpIcon,
link: "https://surrealdb.com/docs/sdk/php",
},
{
id: "java",
name: "Java",
icon: JavaIcon,
link: "https://surrealdb.com/docs/sdk/java",
},
{
id: "go",
name: "GoLang",
icon: GoLangIcon,
link: "https://surrealdb.com/docs/sdk/golang",
},
{
id: "java",
name: "Java",
icon: JavaIcon,
link: "https://surrealdb.com/docs/sdk/java",
},
{
id: "c",
name: "C",
Expand Down
2 changes: 2 additions & 0 deletions src/screens/surrealist/cloud-panel/modals/connect-sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ function ConnectSdkModal({ instance }: ConnectSdkModalProps) {

# Authenticate
await db.sign_in(username="${username}", password="${password}")


`,
php: `
$db = new \\Surreal\\Surreal();
Expand Down
18 changes: 9 additions & 9 deletions src/screens/surrealist/docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: "Initialising",
component: DocsGlobalInit,
excludeLanguages: ["cli", "go", "java", "c"],
excludeLanguages: ["cli", "java", "c"],
},
{
id: newId(),
title: "Connecting",
component: DocsGlobalConnecting,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
},
// {
// id: newId(),
Expand All @@ -66,19 +66,19 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: "Namespaces",
component: DocsGlobalNamespaces,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
},
{
id: newId(),
title: "Databases",
component: DocsGlobalDatabases,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
},
{
id: newId(),
title: "Authentication",
icon: iconAuth,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
topics: [
// {
// id: newId(),
Expand Down Expand Up @@ -120,7 +120,7 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: "Schema",
icon: iconDesigner,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
topics: [
// {
// id: newId(),
Expand Down Expand Up @@ -167,7 +167,7 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: `Tables`,
icon: iconTable,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
component: DocsTablesSelector,
topics: [
{
Expand Down Expand Up @@ -236,7 +236,7 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: "Concepts",
icon: iconStar,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
topics: [
{
id: newId(),
Expand All @@ -259,7 +259,7 @@ export function buildDocumentation(schema: ConnectionSchema): DocsTopic[] {
id: newId(),
title: "Learn more",
icon: iconBook,
excludeLanguages: ["go", "java", "c"],
excludeLanguages: ["java", "c"],
topics: [
{
id: newId(),
Expand Down
96 changes: 80 additions & 16 deletions src/screens/surrealist/docs/topics/authentication/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,88 @@ export function DocsAuthSignIn({ language }: TopicProps) {
}).await?;
`,
py: `
token = await db.signin({
'user': 'root',
'pass': 'root',
})
token = await db.signin({
'user': 'root',
'pass': 'root',
'namespace': 'test',
'database': 'test',
'scope': 'user',
})
# Authenticate with a root user
db.signin({
"database": 'root',
"password": 'surrealdb',
})

# Authenticate with a Namespace user
db.signin({
"namespace": 'surrealdb',
"username": 'tobie',
"password": 'surrealdb',
})

# Authenticate with a Database user
db.signin({
"namespace": 'surrealdb',
"database": 'docs',
"username": 'tobie',
"password": 'surrealdb',
})

# Authenticate with a Access method
db.signin({
"namespace": 'surrealdb',
"database": 'docs',
"access": 'user',
# Also pass any properties required by the access definition
"variables": {
"email": '[email protected]',
"password": '123456'
}
})
`,
go: `
db.Signin(map[string]string{
"user": "root",
"pass": "root",
})
`,
// Sign in as a root user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}

// Sign in to authentication db using the namespace user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}

// Sign in to authentication db using the database user
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
Database = "test",
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}

// Sign in to authentication db using the record accessmethod
authData := &surrealdb.Auth{
Username: "root", // use your setup username
Password: "root", // use your setup password
Namespace = "test",
Database = "test",
Access = "user",
Email = "[email protected]",
Password = "123456"
}
token, err := db.SignIn(authData)
if err != nil {
panic(err)
}
`,
csharp: `
// Sign in as root user
await db.SignIn(
Expand Down
81 changes: 64 additions & 17 deletions src/screens/surrealist/docs/topics/authentication/sign-up.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,30 @@ export function DocsAuthSignUp({ language }: TopicProps) {
const snippets = useMemo<Snippets>(
() => ({
js: `
// Sign up with a Scope user in version < 2.0
await db.signup({
namespace: ${esc_namespace},
database: ${esc_database},
scope: "user",
email: "[email protected]",
pass: "123456",
variables: {
email: '[email protected]',
pass: '123456',
},
});
`,

// With Record Access
await db.signup({
namespace: 'surrealdb',
database: 'docs',
access: 'user',

// Also pass any properties required by the scope definition
variables: {
email: '[email protected]',
pass: '123456',
},
});
`,
rust: `
use serde::Serialize;
use surrealdb::opt::auth::Record;
Expand All @@ -47,24 +63,55 @@ export function DocsAuthSignUp({ language }: TopicProps) {
let token = jwt.as_insecure_token();
`,
py: `
token = await db.signup({
'NS': 'test',
'DB': 'test',
'SC': 'user',
'email': '[email protected]',
'pass': '123456',
# With Record Access
db.signup({
"namespace": ${esc_namespace},
"database": ${esc_database},
"access": 'account',

# Also pass any properties required by the access definition
"variables": {
"email": '[email protected]',
"password": '123456'
}
})
`,
go: `
db.Signup(map[string]string{
"NS": "clear-crocodile-production",
"DB": "web-scraping-application",
"SC": "user",
"email": "[email protected]",
"pass": "123456",
})
authData := &surrealdb.Auth{
Username: "root",
Password: "root",
Namespace = "test",
Database = "test",
Access = "user",
Email = "[email protected]",
Password = "123456"
}
token, err := db.SignUp(authData)
if err != nil {
panic(err)
}
`,
csharp: `
csharp: `
// With Record Access
var authParams = new AuthParams
{
Namespace = "test",
Database = "test",
Access = "user",
Email = "[email protected]",
Password = "123456"
};

Jwt jwt = await db.SignUp(authParams);

public class AuthParams : ScopeAuth
{
public string? Username { get; set; }
public string? Email { get; set; }
public string? Password { get; set; }
}

// Sign up with a Scope user in version < 2.0
var authParams = new AuthParams
{
Namespace = "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ export function DocsAuthTokens({ language, topic }: TopicProps) {
db.authenticate(jwt).await?;
`,
py: `
# Connect to a local endpoint
db = Surreal()
await db.connect('http://127.0.0.1:8000/rpc')
# Connect to a remote endpoint
db = Surreal()
await db.connect('https://cloud.surrealdb.com/rpc')
db.authenticate("jwt")
`,
go: `
db.Authenticate("jwt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ export function DocsConceptsFullTextSearch({ language }: TopicProps) {
DEFINE INDEX page_date_indexed ON page FIELDS date;');
`,
go: `
// Connect to a local endpoint
surrealdb.New("ws://localhost:8000/rpc");
// Connect to a remote endpoint
surrealdb.New("ws://cloud.surrealdb.com/rpc");
await db.RawQuery(
"
DEFINE TABLE page SCHEMALESS PERMISSIONS FOR select FULL;
DEFINE ANALYZER simple TOKENIZERS blank,class,camel,punct FILTERS snowball(english);
DEFINE INDEX page_hostname ON page FIELDS hostname;
DEFINE INDEX page_date_indexed ON page FIELDS date;
"
);
`,
csharp: `
await db.RawQuery(
Expand Down
Loading