Skip to content

Commit

Permalink
fix: fix .NET examples (#202)
Browse files Browse the repository at this point in the history
Co-authored-by: ekwuno <[email protected]>
  • Loading branch information
Odonno and Ekwuno authored Apr 23, 2024
1 parent e3a7a24 commit 5a9eb2f
Show file tree
Hide file tree
Showing 37 changed files with 817 additions and 540 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@codemirror/lang-rust": "^6.0.1",
"@codemirror/lang-sql": "^6.6.0",
"@codemirror/language": "^6.10.1",
"@codemirror/legacy-modes": "^6.4.0",
"@codemirror/lint": "^6.5.0",
"@codemirror/search": "^6.5.6",
"@codemirror/state": "^6.4.1",
Expand All @@ -44,6 +45,7 @@
"@types/react-copy-to-clipboard": "^5.0.7",
"ansi-to-html": "^0.7.2",
"clsx": "^2.1.0",
"codemirror": "^6.0.1",
"codemirror-surrealql": "workspace:codemirror-surrealql",
"dagre": "^0.8.5",
"dayjs": "^1.11.9",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 32 additions & 11 deletions src/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,33 @@ import explorerIcon from "~/assets/animation/explorer.json";
import designerIcon from "~/assets/animation/designer.json";
import authIcon from "~/assets/animation/auth.json";

import { AuthMode, CodeLang, DataSet, ValueMode, Protocol, ResultMode, Selectable, ViewInfo, ViewMode } from "./types";
import { iconAPI, iconAuth, iconCombined, iconDataTable, iconDesigner, iconExplorer, iconFunction, iconLive, iconModel, iconQuery } from "./util/icons";
import {
AuthMode,
CodeLang,
DataSet,
ValueMode,
Protocol,
ResultMode,
Selectable,
ViewInfo,
ViewMode,
} from "./types";
import {
iconAPI,
iconAuth,
iconCombined,
iconDataTable,
iconDesigner,
iconExplorer,
iconFunction,
iconLive,
iconModel,
iconQuery,
} from "./util/icons";
import { getConnection } from "./util/connection";

export type StructureTab = "graph" | "builder";
export type ExportType = typeof EXPORT_TYPES[number];
export type ExportType = (typeof EXPORT_TYPES)[number];

export interface ListingItem {
label: string;
Expand All @@ -22,10 +43,10 @@ export const MAX_LIVE_MESSAGES = 50;
export const ML_SUPPORTED = new Set<Protocol>(["ws", "wss", "http", "https"]);

export const DATASETS: Record<string, DataSet> = {
'surreal-deal': {
"surreal-deal": {
name: "Surreal Deal",
url: "https://datasets.surrealdb.com/surreal-deal-mini-v2.surql"
}
url: "https://datasets.surrealdb.com/surreal-deal-mini-v2.surql",
},
};

export const THEMES = [
Expand Down Expand Up @@ -65,7 +86,7 @@ export const CODE_LANGUAGES: Selectable<CodeLang>[] = [
{ label: "JavaScript", value: "js" },
// { label: "Go", value: "go" },
{ label: "Python", value: "py" },
{ label: ".NET", value: "dotnet" },
{ label: ".NET", value: "csharp" },
// { label: "Java", value: "java" },
// { label: "PHP", value: "php" }
];
Expand Down Expand Up @@ -117,7 +138,7 @@ export const VIEW_MODES: Record<ViewMode, ViewInfo> = {
desc: "Upload and manage machine learning models",
disabled: (flags) => {
if (!flags.models_view) return true;
if (flags.models_view === 'force') return false;
if (flags.models_view === "force") return false;

const protocol = getConnection()?.connection?.protocol;
return !protocol || !ML_SUPPORTED.has(protocol);
Expand All @@ -129,7 +150,7 @@ export const VIEW_MODES: Record<ViewMode, ViewInfo> = {
icon: iconAPI,
desc: "View the database schema and documentation",
disabled: (flags) => !flags.apidocs_view,
}
},
};

export const EXPORT_TYPES = [
Expand All @@ -138,7 +159,7 @@ export const EXPORT_TYPES = [
"analyzers",
"functions",
"params",
"scopes"
"scopes",
] as const;

export const SURREAL_KINDS = [
Expand Down Expand Up @@ -185,4 +206,4 @@ export const SURQL_FILTERS = [
name: "SurrealDB Schema",
extensions: ["surql", "sql", "surrealql"],
},
];
];
34 changes: 22 additions & 12 deletions src/docs/components.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import classes from "./style.module.scss";
import { Extension } from "@codemirror/state";
import { Badge, Box, Group, PaperProps, SimpleGrid, Title } from "@mantine/core";
import {
Badge,
Box,
Group,
PaperProps,
SimpleGrid,
Title,
} from "@mantine/core";
import { CodePreview } from "~/components/CodePreview";
import { CodeLang } from "~/types";
import { Snippets } from "./types";
Expand All @@ -9,16 +16,15 @@ import dedent from "dedent";

import { rust } from "@codemirror/lang-rust";
import { javascript } from "@codemirror/lang-javascript";
import { StreamLanguage } from "@codemirror/language";
import { csharp } from "@codemirror/legacy-modes/mode/clike";

export interface ArticleProps {
title?: React.ReactNode;
children: React.ReactNode | [React.ReactNode, React.ReactNode];
}

export function Article({
title,
children,
}: ArticleProps) {
export function Article({ title, children }: ArticleProps) {
return (
<Box className={classes.article}>
{title && (
Expand All @@ -36,16 +42,16 @@ export function Article({
const EXTENSIONS: Partial<Record<CodeLang, Extension>> = {
rust: rust(),
js: javascript(),
csharp: [StreamLanguage.define(csharp)],
};

export interface DocsPreviewProps extends PaperProps{
export interface DocsPreviewProps extends PaperProps {
title: string;
values: Snippets;
language: CodeLang;
}

export function DocsPreview({ title, values, language }: DocsPreviewProps) {

const snippet = useMemo(() => {
const value = values[language];
return value ? dedent(value) : undefined;
Expand All @@ -61,13 +67,17 @@ export function DocsPreview({ title, values, language }: DocsPreviewProps) {
);
}

export function TableTitle({ title, table }: { title: string, table: string|undefined }) {
export function TableTitle({
title,
table,
}: {
title: string;
table: string | undefined;
}) {
return (
<Group>
{title}
<Badge variant="light">
{table}
</Badge>
<Badge variant="light">{table}</Badge>
</Group>
);
}
}
24 changes: 12 additions & 12 deletions src/docs/topics/authentication/access-user-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import { Article, DocsPreview } from "~/docs/components";
import { Snippets, TopicProps } from "~/docs/types";

export function DocsAuthAccessUserData({ language, topic }: TopicProps) {

const snippets = useMemo<Snippets>(() => ({
cli: `
const snippets = useMemo<Snippets>(
() => ({
cli: `
RETURN $auth;
`,
js: `
js: `
await db.info();
`,
dotnet: `
csharp: `
await db.Info<User>();
`,
php: `
php: `
// Connect to a local endpoint
$db = new SurrealDB();
`,

}), []);
}),
[]
);

return (
<Article title="Access user data">
<div>
<p>
You can access information about a user that is currently authenticated with a scope. This information includes the user's name, email, and other details.
</p>
<p>
{topic.extra?.table?.schema?.name}
You can access information about a user that is currently
authenticated with a scope. This information includes the
user's name, email, and other details.
</p>
</div>
<Box>
Expand Down
41 changes: 20 additions & 21 deletions src/docs/topics/authentication/sign-in.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ import { useActiveConnection } from "~/hooks/connection";
import { connectionUri } from "~/util/helpers";

export function DocsAuthSignIn({ language, topic }: TopicProps) {

const { connection } = useActiveConnection();
const endpoint = connectionUri(connection);
const esc_namespace = JSON.stringify(connection.namespace);
const esc_database = JSON.stringify(connection.database);

const descriptions = {
cli: `With the SurrealDB CLI, you can only signin via system(Root, Namespace and Database) users. This example shows a command on how to signin with the username and password left blank.`,
_: `With SurrealDB's SDKs, you can signin both system (Root, Namespace and Database) users and scope users. The example shows how to sigin a new user based on the credentials required for access.`,
};

const snippets = useMemo<Snippets>(() => ({
cli: `
const snippets = useMemo<Snippets>(
() => ({
cli: `
surreal sql -e ${endpoint} --ns ${connection.namespace} --db ${connection.database} --user ... --pass ...
`,
js: `
js: `
// Authenticate with a root user
await db.signin({
username: 'root',
Expand Down Expand Up @@ -54,7 +52,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
pass: '123456',
});
`,
rust: `
rust: `
// Sign in a Root user
db.signin(Root {
params: Credentials {
Expand Down Expand Up @@ -93,7 +91,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
},
}).await?;
`,
py: `
py: `
token = await db.signin({
'user': 'root',
'pass': 'root',
Expand All @@ -106,19 +104,21 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
'scope': 'user',
})
`,
go: `
go: `
db.Signin(map[string]string{
"user": "root",
"pass": "root",
})
`,
dotnet: `
csharp: `
// Sign in as root user
await db.SignIn(new RootAuth
await db.SignIn(
new RootAuth
{
Username = "root",
Password = "root"
});
}
);
// Sign in using namespace auth
await db.SignIn(
Expand All @@ -141,7 +141,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
}
);
// Sign in as a scoped used
// Sign in as a scoped user
var authParams = new AuthParams
{
Namespace = "test",
Expand All @@ -160,25 +160,24 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
public string? Password { get; set; }
}
`,
java:`
java: `
// Connect to a local endpoint
driver.signIn(user, pass)
`,
php: `
php: `
// Connect to a local endpoint
$db = new SurrealDB();
`,

}), []);
}),
[]
);

return (
<Article title="Sign In">
<div>
<p>
{descriptions[language as keyof typeof descriptions] ?? descriptions._}
</p>
<p>
{topic.extra?.table?.schema?.name}
{descriptions[language as keyof typeof descriptions] ??
descriptions._}
</p>
</div>
<Box>
Expand Down
Loading

0 comments on commit 5a9eb2f

Please sign in to comment.