Skip to content

Commit 5a9eb2f

Browse files
OdonnoEkwuno
andauthored
fix: fix .NET examples (#202)
Co-authored-by: ekwuno <[email protected]>
1 parent e3a7a24 commit 5a9eb2f

37 files changed

+817
-540
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@codemirror/lang-rust": "^6.0.1",
2626
"@codemirror/lang-sql": "^6.6.0",
2727
"@codemirror/language": "^6.10.1",
28+
"@codemirror/legacy-modes": "^6.4.0",
2829
"@codemirror/lint": "^6.5.0",
2930
"@codemirror/search": "^6.5.6",
3031
"@codemirror/state": "^6.4.1",
@@ -44,6 +45,7 @@
4445
"@types/react-copy-to-clipboard": "^5.0.7",
4546
"ansi-to-html": "^0.7.2",
4647
"clsx": "^2.1.0",
48+
"codemirror": "^6.0.1",
4749
"codemirror-surrealql": "workspace:codemirror-surrealql",
4850
"dagre": "^0.8.5",
4951
"dayjs": "^1.11.9",

pnpm-lock.yaml

+26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/constants.tsx

+32-11
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,33 @@ import explorerIcon from "~/assets/animation/explorer.json";
33
import designerIcon from "~/assets/animation/designer.json";
44
import authIcon from "~/assets/animation/auth.json";
55

6-
import { AuthMode, CodeLang, DataSet, ValueMode, Protocol, ResultMode, Selectable, ViewInfo, ViewMode } from "./types";
7-
import { iconAPI, iconAuth, iconCombined, iconDataTable, iconDesigner, iconExplorer, iconFunction, iconLive, iconModel, iconQuery } from "./util/icons";
6+
import {
7+
AuthMode,
8+
CodeLang,
9+
DataSet,
10+
ValueMode,
11+
Protocol,
12+
ResultMode,
13+
Selectable,
14+
ViewInfo,
15+
ViewMode,
16+
} from "./types";
17+
import {
18+
iconAPI,
19+
iconAuth,
20+
iconCombined,
21+
iconDataTable,
22+
iconDesigner,
23+
iconExplorer,
24+
iconFunction,
25+
iconLive,
26+
iconModel,
27+
iconQuery,
28+
} from "./util/icons";
829
import { getConnection } from "./util/connection";
930

1031
export type StructureTab = "graph" | "builder";
11-
export type ExportType = typeof EXPORT_TYPES[number];
32+
export type ExportType = (typeof EXPORT_TYPES)[number];
1233

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

2445
export const DATASETS: Record<string, DataSet> = {
25-
'surreal-deal': {
46+
"surreal-deal": {
2647
name: "Surreal Deal",
27-
url: "https://datasets.surrealdb.com/surreal-deal-mini-v2.surql"
28-
}
48+
url: "https://datasets.surrealdb.com/surreal-deal-mini-v2.surql",
49+
},
2950
};
3051

3152
export const THEMES = [
@@ -65,7 +86,7 @@ export const CODE_LANGUAGES: Selectable<CodeLang>[] = [
6586
{ label: "JavaScript", value: "js" },
6687
// { label: "Go", value: "go" },
6788
{ label: "Python", value: "py" },
68-
{ label: ".NET", value: "dotnet" },
89+
{ label: ".NET", value: "csharp" },
6990
// { label: "Java", value: "java" },
7091
// { label: "PHP", value: "php" }
7192
];
@@ -117,7 +138,7 @@ export const VIEW_MODES: Record<ViewMode, ViewInfo> = {
117138
desc: "Upload and manage machine learning models",
118139
disabled: (flags) => {
119140
if (!flags.models_view) return true;
120-
if (flags.models_view === 'force') return false;
141+
if (flags.models_view === "force") return false;
121142

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

135156
export const EXPORT_TYPES = [
@@ -138,7 +159,7 @@ export const EXPORT_TYPES = [
138159
"analyzers",
139160
"functions",
140161
"params",
141-
"scopes"
162+
"scopes",
142163
] as const;
143164

144165
export const SURREAL_KINDS = [
@@ -185,4 +206,4 @@ export const SURQL_FILTERS = [
185206
name: "SurrealDB Schema",
186207
extensions: ["surql", "sql", "surrealql"],
187208
},
188-
];
209+
];

src/docs/components.tsx

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import classes from "./style.module.scss";
22
import { Extension } from "@codemirror/state";
3-
import { Badge, Box, Group, PaperProps, SimpleGrid, Title } from "@mantine/core";
3+
import {
4+
Badge,
5+
Box,
6+
Group,
7+
PaperProps,
8+
SimpleGrid,
9+
Title,
10+
} from "@mantine/core";
411
import { CodePreview } from "~/components/CodePreview";
512
import { CodeLang } from "~/types";
613
import { Snippets } from "./types";
@@ -9,16 +16,15 @@ import dedent from "dedent";
916

1017
import { rust } from "@codemirror/lang-rust";
1118
import { javascript } from "@codemirror/lang-javascript";
19+
import { StreamLanguage } from "@codemirror/language";
20+
import { csharp } from "@codemirror/legacy-modes/mode/clike";
1221

1322
export interface ArticleProps {
1423
title?: React.ReactNode;
1524
children: React.ReactNode | [React.ReactNode, React.ReactNode];
1625
}
1726

18-
export function Article({
19-
title,
20-
children,
21-
}: ArticleProps) {
27+
export function Article({ title, children }: ArticleProps) {
2228
return (
2329
<Box className={classes.article}>
2430
{title && (
@@ -36,16 +42,16 @@ export function Article({
3642
const EXTENSIONS: Partial<Record<CodeLang, Extension>> = {
3743
rust: rust(),
3844
js: javascript(),
45+
csharp: [StreamLanguage.define(csharp)],
3946
};
4047

41-
export interface DocsPreviewProps extends PaperProps{
48+
export interface DocsPreviewProps extends PaperProps {
4249
title: string;
4350
values: Snippets;
4451
language: CodeLang;
4552
}
4653

4754
export function DocsPreview({ title, values, language }: DocsPreviewProps) {
48-
4955
const snippet = useMemo(() => {
5056
const value = values[language];
5157
return value ? dedent(value) : undefined;
@@ -61,13 +67,17 @@ export function DocsPreview({ title, values, language }: DocsPreviewProps) {
6167
);
6268
}
6369

64-
export function TableTitle({ title, table }: { title: string, table: string|undefined }) {
70+
export function TableTitle({
71+
title,
72+
table,
73+
}: {
74+
title: string;
75+
table: string | undefined;
76+
}) {
6577
return (
6678
<Group>
6779
{title}
68-
<Badge variant="light">
69-
{table}
70-
</Badge>
80+
<Badge variant="light">{table}</Badge>
7181
</Group>
7282
);
73-
}
83+
}

src/docs/topics/authentication/access-user-data.tsx

+12-12
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@ import { Article, DocsPreview } from "~/docs/components";
44
import { Snippets, TopicProps } from "~/docs/types";
55

66
export function DocsAuthAccessUserData({ language, topic }: TopicProps) {
7-
8-
const snippets = useMemo<Snippets>(() => ({
9-
cli: `
7+
const snippets = useMemo<Snippets>(
8+
() => ({
9+
cli: `
1010
RETURN $auth;
1111
`,
12-
js: `
12+
js: `
1313
await db.info();
1414
`,
15-
dotnet: `
15+
csharp: `
1616
await db.Info<User>();
1717
`,
18-
php: `
18+
php: `
1919
// Connect to a local endpoint
2020
$db = new SurrealDB();
2121
`,
22-
23-
}), []);
22+
}),
23+
[]
24+
);
2425

2526
return (
2627
<Article title="Access user data">
2728
<div>
2829
<p>
29-
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.
30-
</p>
31-
<p>
32-
{topic.extra?.table?.schema?.name}
30+
You can access information about a user that is currently
31+
authenticated with a scope. This information includes the
32+
user's name, email, and other details.
3333
</p>
3434
</div>
3535
<Box>

src/docs/topics/authentication/sign-in.tsx

+20-21
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import { useActiveConnection } from "~/hooks/connection";
66
import { connectionUri } from "~/util/helpers";
77

88
export function DocsAuthSignIn({ language, topic }: TopicProps) {
9-
109
const { connection } = useActiveConnection();
1110
const endpoint = connectionUri(connection);
12-
const esc_namespace = JSON.stringify(connection.namespace);
13-
const esc_database = JSON.stringify(connection.database);
1411

1512
const descriptions = {
1613
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.`,
1714
_: `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.`,
1815
};
1916

20-
const snippets = useMemo<Snippets>(() => ({
21-
cli: `
17+
const snippets = useMemo<Snippets>(
18+
() => ({
19+
cli: `
2220
surreal sql -e ${endpoint} --ns ${connection.namespace} --db ${connection.database} --user ... --pass ...
2321
`,
24-
js: `
22+
js: `
2523
// Authenticate with a root user
2624
await db.signin({
2725
username: 'root',
@@ -54,7 +52,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
5452
pass: '123456',
5553
});
5654
`,
57-
rust: `
55+
rust: `
5856
// Sign in a Root user
5957
db.signin(Root {
6058
params: Credentials {
@@ -93,7 +91,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
9391
},
9492
}).await?;
9593
`,
96-
py: `
94+
py: `
9795
token = await db.signin({
9896
'user': 'root',
9997
'pass': 'root',
@@ -106,19 +104,21 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
106104
'scope': 'user',
107105
})
108106
`,
109-
go: `
107+
go: `
110108
db.Signin(map[string]string{
111109
"user": "root",
112110
"pass": "root",
113111
})
114112
`,
115-
dotnet: `
113+
csharp: `
116114
// Sign in as root user
117-
await db.SignIn(new RootAuth
115+
await db.SignIn(
116+
new RootAuth
118117
{
119118
Username = "root",
120119
Password = "root"
121-
});
120+
}
121+
);
122122
123123
// Sign in using namespace auth
124124
await db.SignIn(
@@ -141,7 +141,7 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
141141
}
142142
);
143143
144-
// Sign in as a scoped used
144+
// Sign in as a scoped user
145145
var authParams = new AuthParams
146146
{
147147
Namespace = "test",
@@ -160,25 +160,24 @@ export function DocsAuthSignIn({ language, topic }: TopicProps) {
160160
public string? Password { get; set; }
161161
}
162162
`,
163-
java:`
163+
java: `
164164
// Connect to a local endpoint
165165
driver.signIn(user, pass)
166166
`,
167-
php: `
167+
php: `
168168
// Connect to a local endpoint
169169
$db = new SurrealDB();
170170
`,
171-
172-
}), []);
171+
}),
172+
[]
173+
);
173174

174175
return (
175176
<Article title="Sign In">
176177
<div>
177178
<p>
178-
{descriptions[language as keyof typeof descriptions] ?? descriptions._}
179-
</p>
180-
<p>
181-
{topic.extra?.table?.schema?.name}
179+
{descriptions[language as keyof typeof descriptions] ??
180+
descriptions._}
182181
</p>
183182
</div>
184183
<Box>

0 commit comments

Comments
 (0)