From 8512cf927ccc6cee75583831c671c91a0556c877 Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:27:57 +0200 Subject: [PATCH 1/8] new changelog post --- src/pages/changelog/post-16-mdx | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/pages/changelog/post-16-mdx diff --git a/src/pages/changelog/post-16-mdx b/src/pages/changelog/post-16-mdx new file mode 100644 index 00000000..067ae62b --- /dev/null +++ b/src/pages/changelog/post-16-mdx @@ -0,0 +1,92 @@ +--- +title: "Browser SDK & more" +date: "30 Aug 2023" +layout: "@changelogs" +description: "Great improvements for base fans & server haters alike." +--- + +import Image from '@/components/Image.astro' + +VIDEO HERE + +For developers, much of the power of Space and the [personal cloud](https://deta.space/docs/en/learn/what-is-pc) is the [auth model](https://deta.space/docs/en/build/fundamentals/the-space-runtime/authentication). + +You can build a personal app for yourself, assuming you're the only user. As soon as you've done so, you can see it run for just about any user in the world with an internet connection. You don't think about sign-in, sign-up, users, data separation, and the like. The power of auth on the personal cloud is that you *don't* think about auth, it "just works". + +However, in building a personal app that stores data using [Deta Base](https://deta.space/docs/en/build/fundamentals/data-storage#deta-base) or [Deta Drive](https://deta.space/docs/en/build/fundamentals/data-storage#deta-drive), you still need to create an entire backend, writing APIs that route user requests in the browser to the data in Base or Drive. This is a whole lot of drudgery, coming from the client needing to go through a backend [Micro](https://deta.space/docs/en/build/fundamentals/the-space-runtime/micros) to store and retrieve data. It also adds a lot of latency to user actions, as they are waiting on a backend Micro to respond (cough cough, cold starts). + +From today, things will get a whole lot better in this regard (for many applications). That's because *you can now use Deta Base and Deta Drive straight from the browser*, with **version 2.0.0 of the Deta JavaScript SDK**. When you do, you *don't* have to think about backends. + +## Deta JavaScript SDK v2 + +To get started using Deta Base or Drive in the browser, install the latest Deta SDK from npm (or yarn): + +```bash +npm install deta@latest +``` + +Alternatively, import it in your app from Space's CDN: + +```javascript +const deta = await import("https://cdn.deta.space/js/deta@latest/deta.mjs"); +``` + +In either case, your app can start reading and writing data in the browser: + +```JavaScript +const base = deta.Base('random-base'); +const drive = deta.Drive('random-drive'); + +await base.putMany(['a', 'b', 'c', 'd']); +await drive.put('a', {data: 'data'}); +await drive.put('b', {data: 'data'}); +await drive.put('c', {data: 'data'}); +await drive.put('d', {data: 'data'}); + +console.log(await base.fetch()); +console.log(await drive.list()); +``` + +If your app is running on Deta Space it will just work. No need for keys or a backend. Just low latency personal applications. Check out [this repo](https://github.com/deta/todo-app) for an example app that uses the new SDK on the client. + +Maxu, author of [PingBack](https://deta.space/discovery/@maximilianheidenreich/pingback) and Deta Team member, had this to say after getting his hands on an early release: +> *"This client SDK is killer, I don't have to bootstrap API routes anymore. Sooooo buttery. Smokin' fast!"* + +A few notes: +- The Browser SDK supports all the same methods and features as the existing SDK +- The Browser SDK will not work on [public Micros or Public Routes](https://deta.space/docs/en/build/fundamentals/the-space-runtime/authentication#public-micros-and-routes) + +## More Fun Things + +### Base Sort Order + +After many wishes and hacky hacks, we're pleased to share that you can now sort your Base items by `ascending` or `descending` key-order. Simply pass a `desc` value to any Fetch call ([docs](https://deta.space/docs/en/build/reference/sdk/types#fetchoptions)). + +With Python: +```py +db = deta.Base("random-base") + +db.fetch(desc=True) +``` + +With JavaScript: +```js +const db= deta.Base('random-base'); + +db.fetch({desc: true}) +``` +*P.S: this works in the browser with the new SDK ;)* + +If you check the key column in any [Base UI](https://deta.space/docs/en/use/your-data/guis#base-ui) view, you'll also notice a little toggle that gives you the same ability. + +### Python SDK: Async Interactions with Base + +We now have support asynchronous interactions with Deta Base in the Python SDK. See the "Python (async)" tab [in the docs for more](https://deta.space/docs/en/build/reference/sdk). + + +### Even More +- [Removed `detalib` from the JS SDK, which was causing a lot of errors](https://github.com/deta/deta-javascript/pull/63/files) +- [Pushed an error message fix in JS SDK](https://github.com/deta/deta-javascript/pull/64/files) +- [Fixed wrong exit code in the CLI](https://github.com/deta/space-cli/pull/147/files) +- [Fixed build failures when a top level directory conflicts with .spaceignore](https://github.com/deta/space-cli/pull/148) +- [Fixed a bug where you couldn't serve `./` on Micros with a `static` engine](https://github.com/deta/space-cli/pull/149) From eb5a2e94ecb35a0a3d297f16908c3307a82c60da Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:33:13 +0200 Subject: [PATCH 2/8] maxu quote --- src/pages/changelog/post-16-mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/changelog/post-16-mdx b/src/pages/changelog/post-16-mdx index 067ae62b..8f5d5864 100644 --- a/src/pages/changelog/post-16-mdx +++ b/src/pages/changelog/post-16-mdx @@ -34,8 +34,8 @@ const deta = await import("https://cdn.deta.space/js/deta@latest/deta.mjs"); In either case, your app can start reading and writing data in the browser: ```JavaScript -const base = deta.Base('random-base'); -const drive = deta.Drive('random-drive'); +const base = deta.Base('my-base'); +const drive = deta.Drive('my-drive'); await base.putMany(['a', 'b', 'c', 'd']); await drive.put('a', {data: 'data'}); @@ -50,7 +50,7 @@ console.log(await drive.list()); If your app is running on Deta Space it will just work. No need for keys or a backend. Just low latency personal applications. Check out [this repo](https://github.com/deta/todo-app) for an example app that uses the new SDK on the client. Maxu, author of [PingBack](https://deta.space/discovery/@maximilianheidenreich/pingback) and Deta Team member, had this to say after getting his hands on an early release: -> *"This client SDK is killer, I don't have to bootstrap API routes anymore. Sooooo buttery. Smokin' fast!"* +> *"Not needing to manually set up API routes is an instant 10x increase. Some people choose React Server Components to avoid that. I prefer avoiding the server (and Next.js)entirely with the Deta Browser SDK."* A few notes: - The Browser SDK supports all the same methods and features as the existing SDK From 870352d1e81c5c06fd30abb0306acb884ce47c7b Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:39:09 +0200 Subject: [PATCH 3/8] maxu quote --- src/pages/changelog/post-16-mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/changelog/post-16-mdx b/src/pages/changelog/post-16-mdx index 8f5d5864..a6c471e0 100644 --- a/src/pages/changelog/post-16-mdx +++ b/src/pages/changelog/post-16-mdx @@ -50,7 +50,7 @@ console.log(await drive.list()); If your app is running on Deta Space it will just work. No need for keys or a backend. Just low latency personal applications. Check out [this repo](https://github.com/deta/todo-app) for an example app that uses the new SDK on the client. Maxu, author of [PingBack](https://deta.space/discovery/@maximilianheidenreich/pingback) and Deta Team member, had this to say after getting his hands on an early release: -> *"Not needing to manually set up API routes is an instant 10x increase. Some people choose React Server Components to avoid that. I prefer avoiding the server (and Next.js)entirely with the Deta Browser SDK."* +> *"Some ppl. try to avoid writing API routes and use React & Next.JS server components. I avoid both with the Browser SDK. Instant 10x."* A few notes: - The Browser SDK supports all the same methods and features as the existing SDK From e7a32ee168ba42d20ecad53017b5e0de7788c172 Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:42:00 +0200 Subject: [PATCH 4/8] rename --- src/pages/changelog/{post-16-mdx => post-16.mdx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/pages/changelog/{post-16-mdx => post-16.mdx} (100%) diff --git a/src/pages/changelog/post-16-mdx b/src/pages/changelog/post-16.mdx similarity index 100% rename from src/pages/changelog/post-16-mdx rename to src/pages/changelog/post-16.mdx From d3063d4ea687fe1c799ba2633091ea7185406273 Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:47:22 +0200 Subject: [PATCH 5/8] change latest to 2.0.0 --- src/pages/changelog/post-16.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/changelog/post-16.mdx b/src/pages/changelog/post-16.mdx index a6c471e0..4d96d9eb 100644 --- a/src/pages/changelog/post-16.mdx +++ b/src/pages/changelog/post-16.mdx @@ -28,7 +28,7 @@ npm install deta@latest Alternatively, import it in your app from Space's CDN: ```javascript -const deta = await import("https://cdn.deta.space/js/deta@latest/deta.mjs"); +const deta = await import("https://cdn.deta.space/js/deta@2.0.0/deta.mjs"); ``` In either case, your app can start reading and writing data in the browser: From be8c8b4b7be162b4e76a2f69ee0772afa94b0df2 Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 16:50:01 +0200 Subject: [PATCH 6/8] change language to js --- src/pages/changelog/post-16.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/changelog/post-16.mdx b/src/pages/changelog/post-16.mdx index 4d96d9eb..437f9f71 100644 --- a/src/pages/changelog/post-16.mdx +++ b/src/pages/changelog/post-16.mdx @@ -27,13 +27,13 @@ npm install deta@latest Alternatively, import it in your app from Space's CDN: -```javascript +```js const deta = await import("https://cdn.deta.space/js/deta@2.0.0/deta.mjs"); ``` In either case, your app can start reading and writing data in the browser: -```JavaScript +```js const base = deta.Base('my-base'); const drive = deta.Drive('my-drive'); From 5548209958531f972cc6eab69cd011f7a5ca2347 Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 17:20:47 +0200 Subject: [PATCH 7/8] async fix --- src/content/docs/build/reference/sdk/index.mdx | 2 +- src/pages/changelog/post-16.mdx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/content/docs/build/reference/sdk/index.mdx b/src/content/docs/build/reference/sdk/index.mdx index 3b658c9d..b4d09104 100644 --- a/src/content/docs/build/reference/sdk/index.mdx +++ b/src/content/docs/build/reference/sdk/index.mdx @@ -49,7 +49,7 @@ If you're someone who learns by example, there are also extensive [code examples ```shell - pip install deta + pip install 'deta[async]' ``` diff --git a/src/pages/changelog/post-16.mdx b/src/pages/changelog/post-16.mdx index 4876653f..19699af9 100644 --- a/src/pages/changelog/post-16.mdx +++ b/src/pages/changelog/post-16.mdx @@ -84,6 +84,21 @@ If you check the key column in any [Base UI](https://deta.space/docs/en/use/your We now have support asynchronous interactions with Deta Base in the Python SDK. See the "Python (async)" tab [in the docs for more](https://deta.space/docs/en/build/reference/sdk). +```py +from deta import Deta + +deta = Deta() #instantiate with a Data Key, or env DETA_PROJECT_KEY + +db = deta.AsyncBase("my_db") + +await db.put({"name": "alex", "age": 77, "key": "one"}) + +await db.put({"name": "alex", "age": 23}, "alex23", expire_in=300) + +# close db session +await db.close() +``` + ### Even More - [Removed `detalib` from the JS SDK, which was causing a lot of errors](https://github.com/deta/deta-javascript/pull/63/files) From 85b18840ca30aeef0ae6304946bed160787b0f7e Mon Sep 17 00:00:00 2001 From: xeust Date: Wed, 30 Aug 2023 17:52:23 +0200 Subject: [PATCH 8/8] update links --- src/pages/changelog/post-16.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pages/changelog/post-16.mdx b/src/pages/changelog/post-16.mdx index 19699af9..4bed3bfe 100644 --- a/src/pages/changelog/post-16.mdx +++ b/src/pages/changelog/post-16.mdx @@ -101,8 +101,8 @@ await db.close() ### Even More -- [Removed `detalib` from the JS SDK, which was causing a lot of errors](https://github.com/deta/deta-javascript/pull/63/files) -- [Pushed an error message fix in JS SDK](https://github.com/deta/deta-javascript/pull/64/files) -- [Fixed wrong exit code in the CLI](https://github.com/deta/space-cli/pull/147/files) -- [Fixed build failures when a top level directory conflicts with .spaceignore](https://github.com/deta/space-cli/pull/148) -- [Fixed a bug where you couldn't serve `./` on Micros with a `static` engine](https://github.com/deta/space-cli/pull/149) +- Removed `detalib` from the JS SDK, which was causing a lot of errors: [more](https://github.com/deta/deta-javascript/pull/63/files) +- Pushed an error message fix in JS SDK: [more](https://github.com/deta/deta-javascript/pull/64/files) +- Fixed wrong exit code in the CLI: [more](https://github.com/deta/space-cli/pull/147/files) +- Fixed build failures when a top level directory conflicts with .spaceignore: [more](https://github.com/deta/space-cli/pull/148) +- Fixed a bug where you couldn't serve `./` on Micros with a `static` engine: [more](https://github.com/deta/space-cli/pull/149)