mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-03 18:01:39 +00:00
refactor: update devbox configuration and scripts
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
.env
|
||||
dist
|
||||
out
|
||||
@@ -0,0 +1,9 @@
|
||||
# `noble-client`
|
||||
|
||||
This is a Cloudflare Workers Durable Object that can be deployed to Cloudflare's edge network.
|
||||
|
||||
It uses `noble-es` to provide a simple interface to interact with the Sonr network.
|
||||
|
||||
## Usage
|
||||
|
||||
### Deploying to Cloudflare
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "noble-client",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"deploy": "wrangler deploy",
|
||||
"dev": "wrangler dev",
|
||||
"start": "wrangler dev"
|
||||
},
|
||||
"devDependencies": {
|
||||
"wrangler": "^3.60.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"sonr-es": "^0.5.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
export * from "./stub.js";
|
||||
|
||||
/**
|
||||
* Welcome to Cloudflare Workers! This is your first Durable Objects application.
|
||||
*
|
||||
* - Run `npm run dev` in your terminal to start a development server
|
||||
* - Open a browser tab at http://localhost:8787/ to see your Durable Object in action
|
||||
* - Run `npm run deploy` to publish your application
|
||||
*
|
||||
* Learn more at https://developers.cloudflare.com/durable-objects
|
||||
*/
|
||||
|
||||
/**
|
||||
* Env provides a mechanism to reference bindings declared in wrangler.toml within JavaScript
|
||||
*
|
||||
* @typedef {Object} Env
|
||||
* @property {DurableObjectNamespace} NOBLE_DURABLE_CLIENT - The Durable Object namespace binding
|
||||
*/
|
||||
|
||||
|
||||
export default {
|
||||
/**
|
||||
* This is the standard fetch handler for a Cloudflare Worker
|
||||
*
|
||||
* @param {Request} request - The request submitted to the Worker from the client
|
||||
* @param {Env} env - The interface to reference bindings declared in wrangler.toml
|
||||
* @param {ExecutionContext} ctx - The execution context of the Worker
|
||||
* @returns {Promise<Response>} The response to be sent back to the client
|
||||
*/
|
||||
async fetch(request, env, ctx) {
|
||||
// We will create a `DurableObjectId` using the pathname from the Worker request
|
||||
// This id refers to a unique instance of our 'MyDurableObject' class above
|
||||
let id = env.NOBLE_DURABLE_CLIENT.idFromName(new URL(request.url).pathname);
|
||||
|
||||
// This stub creates a communication channel with the Durable Object instance
|
||||
// The Durable Object constructor will be invoked upon the first call for a given id
|
||||
let stub = env.NOBLE_DURABLE_CLIENT.get(id);
|
||||
|
||||
// We call the `sayHello()` RPC method on the stub to invoke the method on the remote
|
||||
// Durable Object instance
|
||||
let greeting = await stub.sayHello("world");
|
||||
|
||||
return new Response(greeting);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { DurableObject } from "cloudflare:workers";
|
||||
|
||||
/** A Durable Object's behavior is defined in an exported Javascript class */
|
||||
export class NobleDurableClient extends DurableObject {
|
||||
/**
|
||||
* The constructor is invoked once upon creation of the Durable Object, i.e. the first call to
|
||||
* `DurableObjectStub::get` for a given identifier (no-op constructors can be omitted)
|
||||
*
|
||||
* @param {DurableObjectState} ctx - The interface for interacting with Durable Object state
|
||||
* @param {Env} env - The interface to reference bindings declared in wrangler.toml
|
||||
*/
|
||||
constructor(ctx, env) {
|
||||
super(ctx, env);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Durable Object exposes an RPC method sayHello which will be invoked when when a Durable
|
||||
* Object instance receives a request from a Worker via the same method invocation on the stub
|
||||
*
|
||||
* @param {string} name - The name provided to a Durable Object instance from a Worker
|
||||
* @returns {Promise<string>} The greeting to be sent back to the Worker
|
||||
*/
|
||||
async sayHello(name) {
|
||||
return `Hello, ${name}!`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#:schema node_modules/wrangler/config-schema.json
|
||||
name = "noble-client"
|
||||
main = "src/index.js"
|
||||
compatibility_date = "2024-11-12"
|
||||
|
||||
# Workers Logs
|
||||
# Docs: https://developers.cloudflare.com/workers/observability/logs/workers-logs/
|
||||
# Configuration: https://developers.cloudflare.com/workers/observability/logs/workers-logs/#enable-workers-logs
|
||||
[observability]
|
||||
enabled = true
|
||||
|
||||
# Automatically place your workloads in an optimal location to minimize latency.
|
||||
# If you are running back-end logic in a Worker, running it closer to your back-end infrastructure
|
||||
# rather than the end user may result in better performance.
|
||||
# Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
|
||||
# [placement]
|
||||
# mode = "smart"
|
||||
|
||||
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
||||
# Docs:
|
||||
# - https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
||||
# Note: Use secrets to store sensitive data.
|
||||
# - https://developers.cloudflare.com/workers/configuration/secrets/
|
||||
# [vars]
|
||||
# MY_VARIABLE = "production_value"
|
||||
|
||||
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
|
||||
# [ai]
|
||||
# binding = "AI"
|
||||
|
||||
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
||||
# [[analytics_engine_datasets]]
|
||||
# binding = "MY_DATASET"
|
||||
|
||||
# Bind a headless browser instance running on Cloudflare's global network.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
||||
# [browser]
|
||||
# binding = "MY_BROWSER"
|
||||
|
||||
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
||||
# [[d1_databases]]
|
||||
# binding = "MY_DB"
|
||||
# database_name = "my-database"
|
||||
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
||||
# [[dispatch_namespaces]]
|
||||
# binding = "MY_DISPATCHER"
|
||||
# namespace = "my-namespace"
|
||||
|
||||
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
||||
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
|
||||
[[durable_objects.bindings]]
|
||||
name = "NOBLE_DURABLE_CLIENT"
|
||||
class_name = "NobleDurableClient"
|
||||
|
||||
# Durable Object migrations.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
|
||||
[[migrations]]
|
||||
tag = "v1"
|
||||
new_classes = ["NobleDurableClient"]
|
||||
|
||||
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
||||
# [[hyperdrive]]
|
||||
# binding = "MY_HYPERDRIVE"
|
||||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
||||
# [[kv_namespaces]]
|
||||
# binding = "MY_KV_NAMESPACE"
|
||||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
||||
# [[mtls_certificates]]
|
||||
# binding = "MY_CERTIFICATE"
|
||||
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
|
||||
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
||||
# [[queues.producers]]
|
||||
# binding = "MY_QUEUE"
|
||||
# queue = "my-queue"
|
||||
|
||||
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
||||
# [[queues.consumers]]
|
||||
# queue = "my-queue"
|
||||
|
||||
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
||||
# [[r2_buckets]]
|
||||
# binding = "MY_BUCKET"
|
||||
# bucket_name = "my-bucket"
|
||||
|
||||
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
||||
# [[services]]
|
||||
# binding = "MY_SERVICE"
|
||||
# service = "my-service"
|
||||
|
||||
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
||||
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
||||
# [[vectorize]]
|
||||
# binding = "MY_INDEX"
|
||||
# index_name = "my-index"
|
||||
Reference in New Issue
Block a user