@deployowl/nosql 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +520 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +498 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# @deployowl/nosql
|
|
2
|
+
|
|
3
|
+
Zero-config Edge NoSQL SDK for DeployOwl.
|
|
4
|
+
|
|
5
|
+
Use this SDK to store, query, and manage JSON document collections on DeployOwl's global edge infrastructure from Vercel, Render, Cloud Run, Supabase, Railway, Fly.io, or any server environment.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @deployowl/nosql
|
|
13
|
+
# or
|
|
14
|
+
pnpm add @deployowl/nosql
|
|
15
|
+
# or
|
|
16
|
+
yarn add @deployowl/nosql
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Initialize the client
|
|
24
|
+
|
|
25
|
+
Construct the client once at module load:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { createClient } from '@deployowl/nosql';
|
|
29
|
+
|
|
30
|
+
const db = createClient({
|
|
31
|
+
apiKey: process.env.OWL_NOSQL_KEY!, // Your owl_ API key (min 32 chars)
|
|
32
|
+
// gatewayUrl: 'https://owlnosql.deployowl.com', // Optional default
|
|
33
|
+
// autoHashIds: true, // Auto-hash non-alphanumeric IDs to SHA-256
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const users = db.collection('users');
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
> **Security Note:** `createClient()` must only be run in server environments. Calling it in a browser context will throw an error to prevent API key exposure.
|
|
40
|
+
|
|
41
|
+
### 2. Write a document
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
await users.insert('user_9482', {
|
|
45
|
+
email: 'ada@example.com',
|
|
46
|
+
plan: 'pro',
|
|
47
|
+
signupAt: Date.now(),
|
|
48
|
+
tags: ['early', 'beta']
|
|
49
|
+
});
|
|
50
|
+
// → { id: 'user_9482', written: true, bytes: 87 }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 3. Read a document
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const ada = await users.find('user_9482');
|
|
57
|
+
// → { email: 'ada@example.com', plan: 'pro', ... }
|
|
58
|
+
|
|
59
|
+
// Bypass edge cache for fresh read:
|
|
60
|
+
const fresh = await users.find('user_9482', { bypassCache: true });
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 4. Index and Query
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// Define indexed fields (once per collection):
|
|
67
|
+
await users.index(['email', 'plan']);
|
|
68
|
+
|
|
69
|
+
// Query documents:
|
|
70
|
+
const pros = await users.query({ plan: 'pro' });
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### 5. Delete
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
await users.delete('user_9482');
|
|
77
|
+
// → { deleted: true }
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## API Reference
|
|
83
|
+
|
|
84
|
+
| Method | Signature | Description |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `collection(name)` | `name: string` | Get collection handle (alphanumeric, `_`, `-`, max 64 chars). |
|
|
87
|
+
| `find(id, opts?)` | `id: string`, `opts.bypassCache?: boolean` | Fetch document. Returns `T \| null`. |
|
|
88
|
+
| `insert(id, payload, opts?)` | `id: string`, `payload: object`, `opts.ifMatch?: string` | Insert document. |
|
|
89
|
+
| `delete(id)` | `id: string` | Delete document. |
|
|
90
|
+
| `query(filter)` | `filter: object` | Query documents by indexed fields. Returns `T[]`. |
|
|
91
|
+
| `list()` | — | List all document IDs in the collection. |
|
|
92
|
+
| `index(fields)` | `fields: string[]` | Create indexes on collection fields. |
|
|
93
|
+
| `reindex()` | — | Rebuild collection shard indexes. |
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Document & ID Rules
|
|
98
|
+
|
|
99
|
+
- **ID Rules:** Alphanumeric, `_`, `-`, max 128 chars. IDs starting with `_` are reserved.
|
|
100
|
+
- **Auto-Hashing:** With `autoHashIds: true`, non-conforming IDs are automatically SHA-256 hashed to `hash_<base64url>`.
|
|
101
|
+
- **Errors:** Throws `OwlError` with `.code`, `.message`, `.statusCode`. `find()` swallows 404 and returns `null`.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
Proprietary © DeployOwl. All rights reserved.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare function encryptRoute(path: string, apiKey: string): Promise<string>;
|
|
2
|
+
declare function decryptRoute(token: string, apiKey: string): Promise<string>;
|
|
3
|
+
declare class MessagePack {
|
|
4
|
+
static serialize(value: any): Uint8Array;
|
|
5
|
+
static deserialize(buffer: ArrayBuffer | Uint8Array): any;
|
|
6
|
+
}
|
|
7
|
+
declare class OwlError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly statusCode: number;
|
|
10
|
+
constructor(code: string, message: string, statusCode: number);
|
|
11
|
+
}
|
|
12
|
+
interface ClientOptions {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
gatewayUrl?: string;
|
|
15
|
+
retry?: {
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
initialDelayMs?: number;
|
|
18
|
+
maxDelayMs?: number;
|
|
19
|
+
jitterMs?: number;
|
|
20
|
+
};
|
|
21
|
+
autoHashIds?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare function createClient(options: ClientOptions): {
|
|
24
|
+
collection: (collectionName: string) => {
|
|
25
|
+
find: <T = Record<string, any>>(id: string, findOpt?: {
|
|
26
|
+
bypassCache?: boolean;
|
|
27
|
+
}) => Promise<T | null>;
|
|
28
|
+
insert: (id: string, payload: Record<string, any>, opt?: {
|
|
29
|
+
ifMatch?: string;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
written: boolean;
|
|
33
|
+
bytes: number;
|
|
34
|
+
}>;
|
|
35
|
+
delete: (id: string) => Promise<{
|
|
36
|
+
deleted: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
query: <T = Record<string, any>>(filter: Record<string, any>) => Promise<T[]>;
|
|
39
|
+
list: () => Promise<string[]>;
|
|
40
|
+
reindex: () => Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
index: (fields: string[]) => Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { type ClientOptions, MessagePack, OwlError, createClient, decryptRoute, encryptRoute };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
declare function encryptRoute(path: string, apiKey: string): Promise<string>;
|
|
2
|
+
declare function decryptRoute(token: string, apiKey: string): Promise<string>;
|
|
3
|
+
declare class MessagePack {
|
|
4
|
+
static serialize(value: any): Uint8Array;
|
|
5
|
+
static deserialize(buffer: ArrayBuffer | Uint8Array): any;
|
|
6
|
+
}
|
|
7
|
+
declare class OwlError extends Error {
|
|
8
|
+
readonly code: string;
|
|
9
|
+
readonly statusCode: number;
|
|
10
|
+
constructor(code: string, message: string, statusCode: number);
|
|
11
|
+
}
|
|
12
|
+
interface ClientOptions {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
gatewayUrl?: string;
|
|
15
|
+
retry?: {
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
initialDelayMs?: number;
|
|
18
|
+
maxDelayMs?: number;
|
|
19
|
+
jitterMs?: number;
|
|
20
|
+
};
|
|
21
|
+
autoHashIds?: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare function createClient(options: ClientOptions): {
|
|
24
|
+
collection: (collectionName: string) => {
|
|
25
|
+
find: <T = Record<string, any>>(id: string, findOpt?: {
|
|
26
|
+
bypassCache?: boolean;
|
|
27
|
+
}) => Promise<T | null>;
|
|
28
|
+
insert: (id: string, payload: Record<string, any>, opt?: {
|
|
29
|
+
ifMatch?: string;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
id: string;
|
|
32
|
+
written: boolean;
|
|
33
|
+
bytes: number;
|
|
34
|
+
}>;
|
|
35
|
+
delete: (id: string) => Promise<{
|
|
36
|
+
deleted: boolean;
|
|
37
|
+
}>;
|
|
38
|
+
query: <T = Record<string, any>>(filter: Record<string, any>) => Promise<T[]>;
|
|
39
|
+
list: () => Promise<string[]>;
|
|
40
|
+
reindex: () => Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
index: (fields: string[]) => Promise<{
|
|
44
|
+
success: boolean;
|
|
45
|
+
}>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { type ClientOptions, MessagePack, OwlError, createClient, decryptRoute, encryptRoute };
|