@edgespark/server-types 0.0.1-alpha.4 → 0.0.1-alpha.6
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 +21 -79
- package/dist/index.d.ts +52 -28
- package/dist/index.d.ts.map +1 -1
- package/package.json +5 -10
- package/dist/index.js +0 -6
- package/dist/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,90 +1,32 @@
|
|
|
1
1
|
# @edgespark/server-types
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript type definitions for EdgeSpark server SDK.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What's Included
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- `Client<TSchema>` - Main SDK client interface
|
|
8
|
+
- `AuthClient` - Authentication with path-based conventions
|
|
9
|
+
- `User` - Authenticated user identity
|
|
10
|
+
- `StorageClient` / `BucketClient` - File storage operations
|
|
11
|
+
- `SecretClient` - Environment secrets access
|
|
8
12
|
|
|
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
|
-
```
|
|
13
|
+
## Usage
|
|
42
14
|
|
|
43
|
-
|
|
44
|
-
```bash
|
|
45
|
-
cd edge/workers/user-worker
|
|
46
|
-
wrangler deploy
|
|
47
|
-
```
|
|
15
|
+
This package is pre-installed in EdgeSpark projects. Types are used for autocompletion and type checking:
|
|
48
16
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
pnpm version minor # 0.0.1 → 0.1.0
|
|
53
|
-
pnpm publish
|
|
54
|
-
```
|
|
17
|
+
```typescript
|
|
18
|
+
import type { Client } from "@edgespark/server-types";
|
|
19
|
+
import { tables } from "@generated";
|
|
55
20
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
21
|
+
export async function createApp(edgespark: Client<typeof tables>) {
|
|
22
|
+
// Full IntelliSense for:
|
|
23
|
+
// - edgespark.db (Drizzle ORM)
|
|
24
|
+
// - edgespark.auth
|
|
25
|
+
// - edgespark.storage
|
|
26
|
+
// - edgespark.secret
|
|
27
|
+
}
|
|
63
28
|
```
|
|
64
29
|
|
|
65
|
-
|
|
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
|
|
30
|
+
## Learn More
|
|
77
31
|
|
|
78
|
-
|
|
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-types
|
|
87
|
-
pnpm build # Compile TypeScript
|
|
88
|
-
pnpm version <patch|minor|major>
|
|
89
|
-
pnpm publish --access public
|
|
90
|
-
```
|
|
32
|
+
Visit [edgespark.dev](https://edgespark.dev) to get started.
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import type { DrizzleD1Database } from "drizzle-orm/d1";
|
|
|
10
10
|
* export async function createApp(edgespark: Client<typeof tables>): Promise<Hono> {
|
|
11
11
|
* const app = new Hono();
|
|
12
12
|
* app.get('/api/posts', async (c) => {
|
|
13
|
+
* const userId = edgespark.auth.user!.id; // Guaranteed on /api/* routes
|
|
13
14
|
* const posts = await edgespark.db.select().from(tables.posts);
|
|
14
15
|
* return c.json({ posts });
|
|
15
16
|
* });
|
|
@@ -19,41 +20,64 @@ import type { DrizzleD1Database } from "drizzle-orm/d1";
|
|
|
19
20
|
export interface Client<TSchema extends Record<string, unknown> = Record<string, never>> {
|
|
20
21
|
/** Drizzle D1 database client */
|
|
21
22
|
db: DrizzleD1Database<TSchema>;
|
|
22
|
-
/** Authentication client
|
|
23
|
+
/** Authentication client */
|
|
23
24
|
auth: AuthClient;
|
|
24
|
-
/** File storage client
|
|
25
|
+
/** File storage client */
|
|
25
26
|
storage: StorageClient;
|
|
26
|
-
/**
|
|
27
|
+
/** Access environment secrets */
|
|
27
28
|
secret: SecretClient;
|
|
28
29
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
30
|
+
/**
|
|
31
|
+
* Authenticated user identity (immutable for request duration)
|
|
32
|
+
* @example const userId = edgespark.auth.user!.id;
|
|
33
|
+
*/
|
|
34
|
+
export interface User {
|
|
35
|
+
/** User ID (use for DB foreign keys) */
|
|
36
|
+
id: string;
|
|
37
|
+
/** Email (null for anonymous or private OAuth like GitHub) */
|
|
38
|
+
email: string | null;
|
|
39
|
+
/** Display name (null for anonymous or some OAuth) */
|
|
40
|
+
name: string | null;
|
|
41
|
+
/** Avatar URL */
|
|
42
|
+
image: string | null;
|
|
43
|
+
/** Whether email is verified */
|
|
44
|
+
emailVerified: boolean;
|
|
45
|
+
/** Whether user is anonymous (guest, not registered) */
|
|
46
|
+
isAnonymous: boolean;
|
|
47
|
+
/** Account creation timestamp */
|
|
48
|
+
createdAt: Date;
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Authentication client - framework enforces auth based on path conventions
|
|
52
|
+
*
|
|
53
|
+
* Path conventions:
|
|
54
|
+
* - /api/* → Auth required, user guaranteed non-null
|
|
55
|
+
* - /api/public/* → Auth optional, user may be null or authenticated
|
|
56
|
+
* - /api/webhooks/* → No auth, user always null (use webhook signatures)
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // On /api/* routes, user is guaranteed
|
|
60
|
+
* app.get('/api/profile', (c) => {
|
|
61
|
+
* const user = edgespark.auth.user!; // Safe, framework ensures auth
|
|
62
|
+
* return c.json({ id: user.id, email: user.email });
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // On /api/public/* routes, check if authenticated
|
|
66
|
+
* app.get('/api/public/posts', (c) => {
|
|
67
|
+
* if (edgespark.auth.isAuthenticated()) {
|
|
68
|
+
* // Show personalized content
|
|
69
|
+
* }
|
|
70
|
+
* });
|
|
71
|
+
*/
|
|
50
72
|
export interface AuthClient {
|
|
51
|
-
/**
|
|
52
|
-
|
|
73
|
+
/** Current user (immutable for request). Guaranteed on /api/*, optional on /api/public/*, null on /api/webhooks/* */
|
|
74
|
+
readonly user: User | null;
|
|
75
|
+
/** Returns true if user is authenticated */
|
|
76
|
+
isAuthenticated(): boolean;
|
|
53
77
|
}
|
|
54
78
|
export interface SecretClient {
|
|
55
79
|
/**
|
|
56
|
-
* Get secret by name
|
|
80
|
+
* Get secret by name
|
|
57
81
|
* @example const key = edgespark.secret.get('API_KEY');
|
|
58
82
|
*/
|
|
59
83
|
get(name: string): string | null;
|
|
@@ -201,7 +225,7 @@ export interface BucketClient {
|
|
|
201
225
|
success: boolean;
|
|
202
226
|
}>;
|
|
203
227
|
/**
|
|
204
|
-
* Generate presigned upload URL for direct client uploads
|
|
228
|
+
* Generate presigned upload URL for direct client uploads
|
|
205
229
|
* @example
|
|
206
230
|
* import { buckets } from '@generated';
|
|
207
231
|
* const bucket = edgespark.storage.from(buckets.videos);
|
|
@@ -214,7 +238,7 @@ export interface BucketClient {
|
|
|
214
238
|
expiresAt: Date;
|
|
215
239
|
}>;
|
|
216
240
|
/**
|
|
217
|
-
* Generate presigned download URL for direct client downloads
|
|
241
|
+
* Generate presigned download URL for direct client downloads
|
|
218
242
|
* @example
|
|
219
243
|
* import { buckets } from '@generated';
|
|
220
244
|
* const bucket = edgespark.storage.from(buckets.videos);
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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;AAMxD;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,MAAM,CACrB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAE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1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.6",
|
|
4
4
|
"description": "Type definitions for EdgeSpark server SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"edgespark",
|
|
@@ -9,21 +9,18 @@
|
|
|
9
9
|
"d1",
|
|
10
10
|
"r2",
|
|
11
11
|
"drizzle",
|
|
12
|
-
"hono",
|
|
13
12
|
"typescript",
|
|
14
13
|
"types"
|
|
15
14
|
],
|
|
16
|
-
"type": "module",
|
|
17
|
-
"main": "./dist/index.js",
|
|
18
15
|
"types": "./dist/index.d.ts",
|
|
19
16
|
"exports": {
|
|
20
17
|
".": {
|
|
21
|
-
"types": "./dist/index.d.ts"
|
|
22
|
-
"import": "./dist/index.js"
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
23
19
|
}
|
|
24
20
|
},
|
|
25
21
|
"files": [
|
|
26
|
-
"dist"
|
|
22
|
+
"dist/*.d.ts",
|
|
23
|
+
"dist/*.d.ts.map"
|
|
27
24
|
],
|
|
28
25
|
"sideEffects": false,
|
|
29
26
|
"engines": {
|
|
@@ -36,12 +33,10 @@
|
|
|
36
33
|
"prepublishOnly": "pnpm build && pnpm typecheck"
|
|
37
34
|
},
|
|
38
35
|
"peerDependencies": {
|
|
39
|
-
"drizzle-orm": ">=0.
|
|
36
|
+
"drizzle-orm": ">=0.40.0"
|
|
40
37
|
},
|
|
41
38
|
"devDependencies": {
|
|
42
|
-
"@cloudflare/workers-types": "^4.20251111.0",
|
|
43
39
|
"drizzle-orm": "^0.44.0",
|
|
44
|
-
"hono": "^4.10.0",
|
|
45
40
|
"typescript": "^5.9.3"
|
|
46
41
|
},
|
|
47
42
|
"license": "MIT",
|
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|