Skip to content

Commit

Permalink
Rename (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
kearfy authored Aug 3, 2024
1 parent 041dafa commit b21e4eb
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 169 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<a href="https://www.youtube.com/channel/UCjf2teVEuYVvvVC-gFZNq6w"><img src="https://img.shields.io/badge/youtube-subscribe-fc1c1c.svg?style=flat-square"></a>
</p>

# surrealdb.node
# @surrealdb/node

A Node.js engine for the SurrealDB [JavaScript SDK](https://github.com/surrealdb/surrealdb.js).

Expand All @@ -39,8 +39,8 @@ It enables SurrealDB to be run in-memory, or to persist data by running on top o
## Example usage

```js
import { Surreal } from 'surrealdb.js';
import { surrealdbNodeEngines } from 'surrealdb.node';
import { Surreal } from 'surrealdb';
import { surrealdbNodeEngines } from '@surrealdb/node';

// Enable the WebAssembly engines
const db = new Surreal({
Expand Down
280 changes: 140 additions & 140 deletions __test__/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,165 +1,165 @@
import test from "ava";

import { Surreal } from 'surrealdb.js';
import { surrealdbNodeEngines } from '../lib-src/embedded.ts';
import { Surreal } from "surrealdb";
import { surrealdbNodeEngines } from "../lib-src/embedded.ts";

test("Connect in-memory SurrealDB instance", async (t) => {
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
t.pass();
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
t.pass();
});

test("set ns/db", async (t) => {
{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test" });
}

{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ database: "test" });
}

{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });
}

t.pass();
{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test" });
}

{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ database: "test" });
}

{
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });
}

t.pass();
});

test("test query method", async (t) => {
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

{
const [res] = await db.query("SELECT * FROM person");
t.deepEqual(res, []);
}

{
const [res] = await db.query("CREATE |foo:100|");
t.is(res.length, 100);
}

{
const data = { first_name: "Tobie", projects: ["SurrealDB"] };
const [res] = await db.query("CREATE person:tobie content $data", {
data: data,
});
data.id = "person:tobie";
t.deepEqual(res, [data]);
}
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

{
const [res] = await db.query("SELECT * FROM person");
t.deepEqual(res, []);
}

{
const [res] = await db.query("CREATE |foo:100|");
t.is(res.length, 100);
}

{
const data = { first_name: "Tobie", projects: ["SurrealDB"] };
const [res] = await db.query("CREATE person:tobie content $data", {
data: data,
});
data.id = "person:tobie";
t.deepEqual(res, [data]);
}
});

test("set and and unset", async (t) => {
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

const data = { first: "Tobie", last: "Morgan Hitchcock" };

await db.set("name", data);
{
const [res] = await db.query("RETURN $name");
t.deepEqual(res, [data]);
}

await db.unset("name");

{
const [res] = await db.query("RETURN $name");
t.deepEqual(res, []);
}
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

const data = { first: "Tobie", last: "Morgan Hitchcock" };

await db.set("name", data);
{
const [res] = await db.query("RETURN $name");
t.deepEqual(res, [data]);
}

await db.unset("name");

{
const [res] = await db.query("RETURN $name");
t.deepEqual(res, []);
}
});

test("auth", async (t) => {
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({
namespace: "test",
database: "test"
});

const scope = /* surql */ `DEFINE SCOPE user SESSION 5s SIGNUP (CREATE type::thing('user', $username) SET email = $email, pass = crypto::argon2::generate($pass)) SIGNIN (SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(pass, $pass))`;
const [_, [{ scopes }]] = await db.query(/* surql */ `
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({
namespace: "test",
database: "test",
});

const scope = /* surql */ `DEFINE SCOPE user SESSION 5s SIGNUP (CREATE type::thing('user', $username) SET email = $email, pass = crypto::argon2::generate($pass)) SIGNIN (SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(pass, $pass))`;
const [_, [{ scopes }]] = await db.query(/* surql */ `
${scope};
INFO FOR DB;
`);
t.is(scopes.user, scope);

{
const token = await db.signup({
namespace: "test",
database: "test",
scope: "user",

username: 'john',
email: "[email protected]",
pass: "password123",
});
t.is(typeof token, 'string');

const [[user_id]] = await db.query(/* surql */ `$auth`);
t.is(user_id, 'user:john');
}

{
const token = await db.signin({
namespace: "test",
database: "test",
scope: "user",

email: "[email protected]",
pass: "password123",
});
t.is(typeof token, 'string');

const [[user_id]] = await db.query(/* surql */ `$auth`);
t.is(user_id, 'user:john');
}
t.is(scopes.user, scope);

{
const token = await db.signup({
namespace: "test",
database: "test",
scope: "user",

username: "john",
email: "[email protected]",
pass: "password123",
});
t.is(typeof token, "string");

const [[user_id]] = await db.query(/* surql */ `$auth`);
t.is(user_id, "user:john");
}

{
const token = await db.signin({
namespace: "test",
database: "test",
scope: "user",

email: "[email protected]",
pass: "password123",
});
t.is(typeof token, "string");

const [[user_id]] = await db.query(/* surql */ `$auth`);
t.is(user_id, "user:john");
}
});

test("test select method", async (t) => {
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

const jason = { id: "person:jason" };
const john = { id: "person:john" };
const jaime = { id: "person:jaime" };
const people = [jaime, jason, john];

await db.create(jason.id);
await db.create(john.id);
await db.create(jaime.id);

{
const res = await db.select("person");
t.deepEqual(new Set(res), new Set(people));
const person = await db.select("person:jason");
t.deepEqual(person, [jason]);
}
const db = new Surreal({
engines: surrealdbNodeEngines(),
});
await db.connect("memory");
await db.use({ namespace: "test", database: "test" });

const jason = { id: "person:jason" };
const john = { id: "person:john" };
const jaime = { id: "person:jaime" };
const people = [jaime, jason, john];

await db.create(jason.id);
await db.create(john.id);
await db.create(jaime.id);

{
const res = await db.select("person");
t.deepEqual(new Set(res), new Set(people));
const person = await db.select("person:jason");
t.deepEqual(person, [jason]);
}
});

// test('examples', async t => {
Expand Down
2 changes: 1 addition & 1 deletion lib-src/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type RpcRequest,
type RpcResponse,
UnexpectedConnectionError,
} from "surrealdb.js";
} from "surrealdb";

export function surrealdbNodeEngines(opts?: ConnectionOptions) {
class NodeEmbeddedEngine extends AbstractEngine {
Expand Down
2 changes: 1 addition & 1 deletion npm/android-arm-eabi/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-android-arm-eabi`

This is the **armv7-linux-androideabi** binary for `surrealdb.node`
This is the **armv7-linux-androideabi** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/android-arm64/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-android-arm64`

This is the **aarch64-linux-android** binary for `surrealdb.node`
This is the **aarch64-linux-android** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/darwin-arm64/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-darwin-arm64`

This is the **aarch64-apple-darwin** binary for `surrealdb.node`
This is the **aarch64-apple-darwin** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/darwin-universal/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-darwin-universal`

This is the **universal-apple-darwin** binary for `surrealdb.node`
This is the **universal-apple-darwin** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/darwin-x64/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-darwin-x64`

This is the **x86_64-apple-darwin** binary for `surrealdb.node`
This is the **x86_64-apple-darwin** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/freebsd-x64/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-freebsd-x64`

This is the **x86_64-unknown-freebsd** binary for `surrealdb.node`
This is the **x86_64-unknown-freebsd** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/linux-arm-gnueabihf/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-linux-arm-gnueabihf`

This is the **armv7-unknown-linux-gnueabihf** binary for `surrealdb.node`
This is the **armv7-unknown-linux-gnueabihf** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/linux-arm64-gnu/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-linux-arm64-gnu`

This is the **aarch64-unknown-linux-gnu** binary for `surrealdb.node`
This is the **aarch64-unknown-linux-gnu** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/linux-arm64-musl/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-linux-arm64-musl`

This is the **aarch64-unknown-linux-musl** binary for `surrealdb.node`
This is the **aarch64-unknown-linux-musl** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-linux-x64-gnu`

This is the **x86_64-unknown-linux-gnu** binary for `surrealdb.node`
This is the **x86_64-unknown-linux-gnu** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/linux-x64-musl/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-linux-x64-musl`

This is the **x86_64-unknown-linux-musl** binary for `surrealdb.node`
This is the **x86_64-unknown-linux-musl** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/win32-arm64-msvc/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-win32-arm64-msvc`

This is the **aarch64-pc-windows-msvc** binary for `surrealdb.node`
This is the **aarch64-pc-windows-msvc** binary for `@surrealdb/node`
2 changes: 1 addition & 1 deletion npm/win32-ia32-msvc/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# `surrealdb.node-win32-ia32-msvc`

This is the **i686-pc-windows-msvc** binary for `surrealdb.node`
This is the **i686-pc-windows-msvc** binary for `@surrealdb/node`
Loading

0 comments on commit b21e4eb

Please sign in to comment.