From b21e4eb55eedbdfbb7ccc1ebeb5c5f2fe002c70d Mon Sep 17 00:00:00 2001 From: Micha de Vries Date: Sat, 3 Aug 2024 17:57:14 +0200 Subject: [PATCH] Rename (#42) --- README.md | 6 +- __test__/index.spec.mjs | 280 +++++++++++++++--------------- lib-src/embedded.ts | 2 +- npm/android-arm-eabi/README.md | 2 +- npm/android-arm64/README.md | 2 +- npm/darwin-arm64/README.md | 2 +- npm/darwin-universal/README.md | 2 +- npm/darwin-x64/README.md | 2 +- npm/freebsd-x64/README.md | 2 +- npm/linux-arm-gnueabihf/README.md | 2 +- npm/linux-arm64-gnu/README.md | 2 +- npm/linux-arm64-musl/README.md | 2 +- npm/linux-x64-gnu/README.md | 2 +- npm/linux-x64-musl/README.md | 2 +- npm/win32-arm64-msvc/README.md | 2 +- npm/win32-ia32-msvc/README.md | 2 +- npm/win32-x64-msvc/README.md | 2 +- package.json | 7 +- pnpm-lock.yaml | 12 +- test.ts | 2 +- 20 files changed, 168 insertions(+), 169 deletions(-) diff --git a/README.md b/README.md index a61e9db..93f3cf2 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@

-# surrealdb.node +# @surrealdb/node A Node.js engine for the SurrealDB [JavaScript SDK](https://github.com/surrealdb/surrealdb.js). @@ -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({ diff --git a/__test__/index.spec.mjs b/__test__/index.spec.mjs index 742ccb3..de0e18d 100644 --- a/__test__/index.spec.mjs +++ b/__test__/index.spec.mjs @@ -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: "john.doe@example.com", - 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: "john.doe@example.com", - 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: "john.doe@example.com", + 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: "john.doe@example.com", + 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 => { diff --git a/lib-src/embedded.ts b/lib-src/embedded.ts index 0aa3b07..9e9d58e 100644 --- a/lib-src/embedded.ts +++ b/lib-src/embedded.ts @@ -8,7 +8,7 @@ import { type RpcRequest, type RpcResponse, UnexpectedConnectionError, -} from "surrealdb.js"; +} from "surrealdb"; export function surrealdbNodeEngines(opts?: ConnectionOptions) { class NodeEmbeddedEngine extends AbstractEngine { diff --git a/npm/android-arm-eabi/README.md b/npm/android-arm-eabi/README.md index 5a1bd29..87339ba 100644 --- a/npm/android-arm-eabi/README.md +++ b/npm/android-arm-eabi/README.md @@ -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` diff --git a/npm/android-arm64/README.md b/npm/android-arm64/README.md index 0af43a7..ef21ac1 100644 --- a/npm/android-arm64/README.md +++ b/npm/android-arm64/README.md @@ -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` diff --git a/npm/darwin-arm64/README.md b/npm/darwin-arm64/README.md index ac7ed70..3ba24b0 100644 --- a/npm/darwin-arm64/README.md +++ b/npm/darwin-arm64/README.md @@ -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` diff --git a/npm/darwin-universal/README.md b/npm/darwin-universal/README.md index 63557a1..88e5867 100644 --- a/npm/darwin-universal/README.md +++ b/npm/darwin-universal/README.md @@ -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` diff --git a/npm/darwin-x64/README.md b/npm/darwin-x64/README.md index 56e8182..2aa118e 100644 --- a/npm/darwin-x64/README.md +++ b/npm/darwin-x64/README.md @@ -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` diff --git a/npm/freebsd-x64/README.md b/npm/freebsd-x64/README.md index a939ec1..176bd82 100644 --- a/npm/freebsd-x64/README.md +++ b/npm/freebsd-x64/README.md @@ -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` diff --git a/npm/linux-arm-gnueabihf/README.md b/npm/linux-arm-gnueabihf/README.md index 7b33634..2535511 100644 --- a/npm/linux-arm-gnueabihf/README.md +++ b/npm/linux-arm-gnueabihf/README.md @@ -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` diff --git a/npm/linux-arm64-gnu/README.md b/npm/linux-arm64-gnu/README.md index cb9dba8..3722729 100644 --- a/npm/linux-arm64-gnu/README.md +++ b/npm/linux-arm64-gnu/README.md @@ -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` diff --git a/npm/linux-arm64-musl/README.md b/npm/linux-arm64-musl/README.md index d214e0f..c6b73f2 100644 --- a/npm/linux-arm64-musl/README.md +++ b/npm/linux-arm64-musl/README.md @@ -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` diff --git a/npm/linux-x64-gnu/README.md b/npm/linux-x64-gnu/README.md index 0152322..f58cc57 100644 --- a/npm/linux-x64-gnu/README.md +++ b/npm/linux-x64-gnu/README.md @@ -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` diff --git a/npm/linux-x64-musl/README.md b/npm/linux-x64-musl/README.md index fa19cb6..916abf4 100644 --- a/npm/linux-x64-musl/README.md +++ b/npm/linux-x64-musl/README.md @@ -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` diff --git a/npm/win32-arm64-msvc/README.md b/npm/win32-arm64-msvc/README.md index ea8e444..9193390 100644 --- a/npm/win32-arm64-msvc/README.md +++ b/npm/win32-arm64-msvc/README.md @@ -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` diff --git a/npm/win32-ia32-msvc/README.md b/npm/win32-ia32-msvc/README.md index 7087a61..0410ef2 100644 --- a/npm/win32-ia32-msvc/README.md +++ b/npm/win32-ia32-msvc/README.md @@ -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` diff --git a/npm/win32-x64-msvc/README.md b/npm/win32-x64-msvc/README.md index 625547f..c6e9e27 100644 --- a/npm/win32-x64-msvc/README.md +++ b/npm/win32-x64-msvc/README.md @@ -1,3 +1,3 @@ # `surrealdb.node-win32-x64-msvc` -This is the **x86_64-pc-windows-msvc** binary for `surrealdb.node` +This is the **x86_64-pc-windows-msvc** binary for `@surrealdb/node` diff --git a/package.json b/package.json index 129cd58..662525e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "surrealdb.node", + "name": "@surrealdb/node", "version": "1.0.0-beta.1", "author": { "name": "Raphael Darley", @@ -42,11 +42,10 @@ "ava": "^5.1.1" }, "dependencies": { - "surrealdb.js": "^1.0.0-beta.12", - "typescript": "^5.5.4" + "surrealdb": "^1.0.0-beta.19" }, "peerDependencies": { - "surrealdb.js": "^1.0.0-beta.12" + "typescript": "^5.5.4" }, "ava": { "timeout": "3m" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 60c6ca1..28ef892 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,9 @@ importers: .: dependencies: - surrealdb.js: - specifier: ^1.0.0-beta.12 - version: 1.0.0-beta.12(tslib@2.6.3)(typescript@5.5.4)(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)) + surrealdb: + specifier: ^1.0.0-beta.19 + version: 1.0.0-beta.19(tslib@2.6.3)(typescript@5.5.4)(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)) typescript: specifier: ^5.5.4 version: 5.5.4 @@ -526,8 +526,8 @@ packages: resolution: {integrity: sha512-u1ZpIBCawJnO+0QePsEiOknOfCRq0yERxiAchT0i4li0WHNUJbf0evXXSXOcCAR4M8iMDoajXYmstm/qO81Isw==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - surrealdb.js@1.0.0-beta.12: - resolution: {integrity: sha512-spIR6cXOTkB45Hi206afzE/+JdqS2kMe6/qxfcTtdkE4apARCNc5BEgi7o206r0auBRm4yP6pEfm6zXxCpeUsA==} + surrealdb@1.0.0-beta.19: + resolution: {integrity: sha512-MfUhFTt/H2ppxFW9zs47NR8brwaDCD7M2uYbWpgo9LaRPNDIHk+PN1RgsVH6Z9+NSdefhS53BkOihtclJU19jQ==} engines: {node: '>=18.0.0'} peerDependencies: tslib: ^2.6.3 @@ -1064,7 +1064,7 @@ snapshots: serialize-error: 7.0.1 strip-ansi: 7.1.0 - surrealdb.js@1.0.0-beta.12(tslib@2.6.3)(typescript@5.5.4)(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)): + surrealdb@1.0.0-beta.19(tslib@2.6.3)(typescript@5.5.4)(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)): dependencies: isows: 1.0.4(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)) tslib: 2.6.3 diff --git a/test.ts b/test.ts index 6e92306..6964ae3 100644 --- a/test.ts +++ b/test.ts @@ -1,4 +1,4 @@ -import Surreal from "surrealdb.js"; +import Surreal from "surrealdb"; import { surrealdbNodeEngines } from "./lib-src/embedded.ts"; async function run(endpoint) {