-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
168 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
Oops, something went wrong.