@edgespark/server-types 0.0.1-alpha.0
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 +90 -0
- package/dist/index.d.ts +166 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# @edgespark/server
|
|
2
|
+
|
|
3
|
+
Type definitions for EdgeSpark Server SDK.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is a **types-only** package. The actual implementation lives in `edge/workers/user-worker/src/sdk-server/` and is deployed with the user-worker.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
sdk/server-types/src/index.ts ← Types (this package)
|
|
11
|
+
↓
|
|
12
|
+
workspace:*
|
|
13
|
+
↓
|
|
14
|
+
sdk-server/ ← Implementation (imports types from here)
|
|
15
|
+
↓
|
|
16
|
+
deployed
|
|
17
|
+
↓
|
|
18
|
+
user-worker ← Runtime (serves SDK to user code)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Development Flow
|
|
22
|
+
|
|
23
|
+
### Adding a New Feature
|
|
24
|
+
|
|
25
|
+
1. **Add types** in `sdk/server-types/src/index.ts`
|
|
26
|
+
```typescript
|
|
27
|
+
export interface QueueClient {
|
|
28
|
+
send(message: string): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Client<TSchema> {
|
|
32
|
+
// ... existing
|
|
33
|
+
queue: QueueClient; // new
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. **Implement** in `edge/workers/user-worker/src/sdk-server/`
|
|
38
|
+
```typescript
|
|
39
|
+
import type { QueueClient } from "@edgespark/server-types";
|
|
40
|
+
// ... implementation
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. **Deploy user-worker** (implementation goes live)
|
|
44
|
+
```bash
|
|
45
|
+
cd edge/workers/user-worker
|
|
46
|
+
wrangler deploy
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. **Publish types** to npm
|
|
50
|
+
```bash
|
|
51
|
+
cd sdk/server
|
|
52
|
+
pnpm version minor # 0.0.1 → 0.1.0
|
|
53
|
+
pnpm publish
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Types-Only Changes (JSDoc, comments)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd sdk/server
|
|
60
|
+
# Edit src/index.ts
|
|
61
|
+
pnpm version patch # 0.0.1 → 0.0.2
|
|
62
|
+
pnpm publish
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
No deployment needed.
|
|
66
|
+
|
|
67
|
+
## Rules
|
|
68
|
+
|
|
69
|
+
| Rule | Why |
|
|
70
|
+
|------|-----|
|
|
71
|
+
| Deploy impl BEFORE publishing types | New types + old impl = runtime errors |
|
|
72
|
+
| Types can publish WITHOUT deploy | JSDoc/comment changes are safe |
|
|
73
|
+
| Use `workspace:*` locally | Instant feedback during dev |
|
|
74
|
+
| Bump version on every publish | npm requires unique versions |
|
|
75
|
+
|
|
76
|
+
## Local Development
|
|
77
|
+
|
|
78
|
+
The `user-worker` package uses `"@edgespark/server-types": "workspace:*"` which means:
|
|
79
|
+
- Changes to `sdk/server-types/src/index.ts` are immediately available
|
|
80
|
+
- Run `pnpm build` in `sdk/server-types/` to update `dist/`
|
|
81
|
+
- No need to publish during development
|
|
82
|
+
|
|
83
|
+
## Publishing
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
cd sdk/server
|
|
87
|
+
pnpm build # Compile TypeScript
|
|
88
|
+
pnpm version <patch|minor|major>
|
|
89
|
+
pnpm publish --access public
|
|
90
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @edgespark/server-types - Type definitions for EdgeSpark server SDK
|
|
3
|
+
* @module @edgespark/server-types
|
|
4
|
+
*/
|
|
5
|
+
import type { DrizzleD1Database } from "drizzle-orm/d1";
|
|
6
|
+
import type { MiddlewareHandler } from "hono";
|
|
7
|
+
/**
|
|
8
|
+
* EdgeSpark Client - main SDK entry point
|
|
9
|
+
* @template TSchema - Database schema from @generated
|
|
10
|
+
* @example
|
|
11
|
+
* export async function backend(app: Hono, edgespark: Client<typeof tables>) {
|
|
12
|
+
* app.get('/api/users', async (c) => {
|
|
13
|
+
* const users = await edgespark.db.select().from(tables.users);
|
|
14
|
+
* return c.json({ users });
|
|
15
|
+
* });
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export interface Client<TSchema extends Record<string, unknown> = Record<string, never>> {
|
|
19
|
+
/** Drizzle D1 database client */
|
|
20
|
+
db: DrizzleD1Database<TSchema>;
|
|
21
|
+
/** Authentication client (Better Auth) */
|
|
22
|
+
auth: AuthClient;
|
|
23
|
+
/** File storage client (R2) */
|
|
24
|
+
storage: StorageClient;
|
|
25
|
+
/** Environment secrets (ES_USER_SECRET__* prefix) */
|
|
26
|
+
secret: SecretClient;
|
|
27
|
+
}
|
|
28
|
+
export interface AuthSession {
|
|
29
|
+
session: {
|
|
30
|
+
id: string;
|
|
31
|
+
createdAt: string;
|
|
32
|
+
updatedAt: string;
|
|
33
|
+
userId: string;
|
|
34
|
+
token: string;
|
|
35
|
+
expiresAt: string;
|
|
36
|
+
ipAddress?: string | null;
|
|
37
|
+
userAgent?: string | null;
|
|
38
|
+
};
|
|
39
|
+
user?: {
|
|
40
|
+
id: string;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
email: string;
|
|
44
|
+
emailVerified: boolean;
|
|
45
|
+
name: string;
|
|
46
|
+
image?: string | null;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export interface AuthClient {
|
|
50
|
+
/** Get current session. Returns null if not authenticated. */
|
|
51
|
+
getSession(): Promise<AuthSession | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Hono middleware enforcing auth. Sets `c.get('auth')`.
|
|
54
|
+
* @example app.get('/api/me', edgespark.auth.middleware(), (c) => c.json(c.get('auth')));
|
|
55
|
+
*/
|
|
56
|
+
middleware(): MiddlewareHandler;
|
|
57
|
+
}
|
|
58
|
+
export interface SecretClient {
|
|
59
|
+
/**
|
|
60
|
+
* Get secret by name. Reads from env.ES_USER_SECRET__{name}.
|
|
61
|
+
* @example const key = edgespark.secret.get('API_KEY');
|
|
62
|
+
*/
|
|
63
|
+
get(name: string): string | null;
|
|
64
|
+
}
|
|
65
|
+
/** Bucket definition from @generated/storage_schema */
|
|
66
|
+
export interface BucketDef {
|
|
67
|
+
readonly bucket_name: string;
|
|
68
|
+
readonly description: string;
|
|
69
|
+
}
|
|
70
|
+
export interface StorageClient {
|
|
71
|
+
/**
|
|
72
|
+
* Create storage URI for database storage
|
|
73
|
+
* @example const uri = edgespark.storage.toUri(buckets.avatars, 'user-1.jpg'); // "s3://avatars/user-1.jpg"
|
|
74
|
+
*/
|
|
75
|
+
toUri(bucket: BucketDef, path: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Parse storage URI back to bucket + path
|
|
78
|
+
* @example const { bucket, path } = edgespark.storage.fromUri(user.avatarUri);
|
|
79
|
+
*/
|
|
80
|
+
fromUri(uri: string): {
|
|
81
|
+
bucket: BucketDef;
|
|
82
|
+
path: string;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Select bucket for operations
|
|
86
|
+
* @example await edgespark.storage.from(buckets.uploads).put('file.txt', buffer);
|
|
87
|
+
*/
|
|
88
|
+
from(bucket: BucketDef): BucketClient;
|
|
89
|
+
}
|
|
90
|
+
export interface BucketClient {
|
|
91
|
+
/**
|
|
92
|
+
* Upload file (<100MB). Use createPresignedPutUrl for large files.
|
|
93
|
+
* @example await bucket.put('photo.jpg', buffer, { contentType: 'image/jpeg' });
|
|
94
|
+
*/
|
|
95
|
+
put(path: string, file: ArrayBuffer, options?: StorageHttpMetadata): Promise<{
|
|
96
|
+
success: boolean;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Download file. Returns null if not found.
|
|
100
|
+
* @example const file = await bucket.get('doc.pdf'); if (file) { ... }
|
|
101
|
+
*/
|
|
102
|
+
get(path: string): Promise<StorageObject | null>;
|
|
103
|
+
/**
|
|
104
|
+
* Get metadata only (no body). Faster than get() for existence checks.
|
|
105
|
+
* @example const meta = await bucket.head('file.txt'); if (meta) { ... }
|
|
106
|
+
*/
|
|
107
|
+
head(path: string): Promise<StorageObjectMetadata | null>;
|
|
108
|
+
/**
|
|
109
|
+
* List files with optional prefix filter
|
|
110
|
+
* @example const { objects, hasMore, cursor } = await bucket.list('user-123/');
|
|
111
|
+
*/
|
|
112
|
+
list(prefix?: string, options?: {
|
|
113
|
+
limit?: number;
|
|
114
|
+
cursor?: string;
|
|
115
|
+
}): Promise<StorageListResult>;
|
|
116
|
+
/**
|
|
117
|
+
* Delete file(s). Supports bulk delete up to 1000 paths.
|
|
118
|
+
* @example await bucket.delete(['file1.jpg', 'file2.jpg']);
|
|
119
|
+
*/
|
|
120
|
+
delete(paths: string | string[]): Promise<{
|
|
121
|
+
success: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Generate presigned upload URL for direct client uploads
|
|
125
|
+
* @example const { uploadUrl } = await bucket.createPresignedPutUrl('video.mp4', 3600);
|
|
126
|
+
*/
|
|
127
|
+
createPresignedPutUrl(path: string, expiresInSecs?: number, options?: StorageHttpMetadata): Promise<{
|
|
128
|
+
uploadUrl: string;
|
|
129
|
+
path: string;
|
|
130
|
+
expiresAt: Date;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Generate presigned download URL for direct client downloads
|
|
134
|
+
* @example const { downloadUrl } = await bucket.createPresignedGetUrl('video.mp4', 3600);
|
|
135
|
+
*/
|
|
136
|
+
createPresignedGetUrl(path: string, expiresInSecs?: number): Promise<{
|
|
137
|
+
downloadUrl: string;
|
|
138
|
+
path: string;
|
|
139
|
+
expiresAt: Date;
|
|
140
|
+
}>;
|
|
141
|
+
}
|
|
142
|
+
export interface StorageHttpMetadata {
|
|
143
|
+
contentType?: string;
|
|
144
|
+
contentDisposition?: string;
|
|
145
|
+
contentEncoding?: string;
|
|
146
|
+
cacheControl?: string;
|
|
147
|
+
}
|
|
148
|
+
export interface StorageObjectMetadata {
|
|
149
|
+
size: number;
|
|
150
|
+
httpMetadata: StorageHttpMetadata;
|
|
151
|
+
}
|
|
152
|
+
export interface StorageObject {
|
|
153
|
+
body: ArrayBuffer;
|
|
154
|
+
metadata: StorageObjectMetadata;
|
|
155
|
+
}
|
|
156
|
+
export interface StorageFileInfo {
|
|
157
|
+
key: string;
|
|
158
|
+
size: number;
|
|
159
|
+
uploaded: Date;
|
|
160
|
+
}
|
|
161
|
+
export interface StorageListResult {
|
|
162
|
+
objects: StorageFileInfo[];
|
|
163
|
+
hasMore: boolean;
|
|
164
|
+
cursor?: string;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAM9C;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM,CACrB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAE/D,iCAAiC;IACjC,EAAE,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAE/B,0CAA0C;IAC1C,IAAI,EAAE,UAAU,CAAC;IAEjB,+BAA+B;IAC/B,OAAO,EAAE,aAAa,CAAC;IAEvB,qDAAqD;IACrD,MAAM,EAAE,Y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AS,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;CACpE;AAMD,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,mBAAmB,CAAC;CACnC;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,qBAAqB,CAAC;CACjC;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edgespark/server-types",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"description": "Type definitions for EdgeSpark server SDK",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"edgespark",
|
|
7
|
+
"cloudflare",
|
|
8
|
+
"workers",
|
|
9
|
+
"d1",
|
|
10
|
+
"r2",
|
|
11
|
+
"drizzle",
|
|
12
|
+
"hono",
|
|
13
|
+
"typescript",
|
|
14
|
+
"types"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"drizzle-orm": ">=0.30.0",
|
|
34
|
+
"hono": ">=4.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@cloudflare/workers-types": "^4.20251111.0",
|
|
38
|
+
"drizzle-orm": "^0.44.0",
|
|
39
|
+
"hono": "^4.10.0",
|
|
40
|
+
"typescript": "^5.9.3"
|
|
41
|
+
},
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"typecheck": "tsc --noEmit",
|
|
49
|
+
"lint": "tsc --noEmit"
|
|
50
|
+
}
|
|
51
|
+
}
|