npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

clearable-object

v0.0.1

Published

A simple library for adding clear functionality to Cloudflare Durable Objects. Supports clearing storage and alarms with optional authentication.

Downloads

3

Readme

Clearable Object

A simple library for adding clear functionality to Cloudflare Durable Objects. Supports clearing storage and alarms with optional authentication.

Installation

npm i clearable-object

Quick Start

Decorator Pattern (Recommended)

import { Clearable } from "clearable-object";

@Clearable({ secret: "user:pass", isPublic: false })
export class MyDurableObject extends DurableObject {
  // Automatically adds GET /clear endpoint
}

Manual Integration

import { Clear } from "clearable-object";

export class MyDurableObject extends DurableObject {
  clear = new Clear(this, { secret: "user:pass" });

  async fetch(request: Request) {
    const url = new URL(request.url);

    if (url.pathname === "/clear") {
      const result = await this.clear.clear();
      return new Response(JSON.stringify(result));
    }
    // ... your logic
  }
}

Endpoints (Decorator)

  • GET /clear - Clear all data (storage and alarm)
  • GET /clear?storage=false - Skip clearing storage
  • GET /clear?alarm=false - Skip clearing alarm

API Methods

Clear All Data

await clear.clear({
  clearStorage: true, // Clear Durable Object storage
  clearAlarm: true, // Clear scheduled alarm
});

Check Authentication

const isAuthorized = clear.checkAuth(request);

Get Unauthorized Response

return clear.unauthorizedResponse();

Response Format

interface ClearResult {
  success: boolean;
  storageCleared: boolean; // Whether storage was cleared
  alarmCleared: boolean; // Whether alarm was cleared
  errors?: string[]; // Any errors encountered
  warnings?: string[]; // Any warnings
}

Configuration Options

interface ClearOptions {
  secret?: string; // Authentication secret
  isPublic?: boolean; // Allow unauthenticated access
}

Authentication

Configure with secret option. Supports Basic Auth and API key query parameter.

Basic Auth

curl -u user:pass https://your-worker.com/clear

API Key Query Parameter

curl https://your-worker.com/clear?apiKey=user:pass

Configuration Examples

// Require authentication
@Clearable({ secret: "myuser:mypass" })

// Public access (no auth required)
@Clearable({ isPublic: true })

// No auth, not public (will reject all requests)
@Clearable()

Safety Features

  • Graceful Error Handling: Storage and alarm clearing failures are handled independently
  • Detailed Reporting: Know exactly what was cleared and what failed
  • Flexible Options: Choose what to clear via query parameters
  • Authentication: Protect destructive operations with Basic Auth or API keys

Use Cases

  • Development: Quick reset during testing
  • Maintenance: Clean up corrupted data
  • Migration: Prepare for fresh data import
  • Debugging: Clear state to isolate issues

Example Responses

Successful Clear

{
  "success": true,
  "storageCleared": true,
  "alarmCleared": true
}

Partial Success with Warnings

{
  "success": true,
  "storageCleared": true,
  "alarmCleared": false,
  "warnings": ["No alarm was set to clear"]
}

Authentication Error

{
  "error": "Unauthorized",
  "message": "Valid authentication required"
}

TypeScript Support

Full TypeScript support with proper type definitions for all methods and responses.

import { Clear, ClearResult, ClearOptions } from "clearable-object";

const clear = new Clear(durableObject, options);
const result: ClearResult = await clear.clear();