export-runtime 0.0.13 → 0.0.14

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.
@@ -471,10 +471,245 @@ fs.writeFileSync(configPath, configContent);
471
471
  const wranglerPath = path.join(cwd, "wrangler.toml");
472
472
  fs.writeFileSync(wranglerPath, wranglerLines.join("\n"));
473
473
 
474
+ // --- Generate .export-client.d.ts ---
475
+
476
+ const clientDtsLines = [
477
+ `// Auto-generated client type definitions. Do not edit manually.`,
478
+ ``,
479
+ `/** D1 query result from tagged template literal */`,
480
+ `export interface ExportD1Query<T = Record<string, unknown>> {`,
481
+ ` /** Execute query and return all results */`,
482
+ ` all(): Promise<{ results: T[]; success: boolean; meta: object }>;`,
483
+ ` /** Execute query and return first result */`,
484
+ ` first<K extends keyof T>(colName?: K): Promise<K extends keyof T ? T[K] : T | null>;`,
485
+ ` /** Execute query without returning results */`,
486
+ ` run(): Promise<{ success: boolean; meta: object }>;`,
487
+ ` /** Execute query and return raw array results */`,
488
+ ` raw<K extends keyof T = keyof T>(): Promise<K extends keyof T ? T[K][] : unknown[][]>;`,
489
+ ` /** Thenable - defaults to .all() */`,
490
+ ` then<TResult = { results: T[]; success: boolean; meta: object }>(`,
491
+ ` onfulfilled?: (value: { results: T[]; success: boolean; meta: object }) => TResult | PromiseLike<TResult>,`,
492
+ ` onrejected?: (reason: any) => TResult | PromiseLike<TResult>`,
493
+ ` ): Promise<TResult>;`,
494
+ `}`,
495
+ ``,
496
+ `/** D1 database proxy - use as tagged template literal */`,
497
+ `export interface ExportD1Proxy {`,
498
+ ` <T = Record<string, unknown>>(strings: TemplateStringsArray, ...values: unknown[]): ExportD1Query<T>;`,
499
+ `}`,
500
+ ``,
501
+ `/** R2 object metadata */`,
502
+ `export interface ExportR2ObjectMeta {`,
503
+ ` key: string;`,
504
+ ` size: number;`,
505
+ ` etag: string;`,
506
+ ` httpEtag: string;`,
507
+ ` uploaded: Date;`,
508
+ ` httpMetadata?: Record<string, string>;`,
509
+ ` customMetadata?: Record<string, string>;`,
510
+ `}`,
511
+ ``,
512
+ `/** R2 object with body */`,
513
+ `export interface ExportR2Object extends ExportR2ObjectMeta {`,
514
+ ` body: ReadableStream<Uint8Array>;`,
515
+ ` bodyUsed: boolean;`,
516
+ ` arrayBuffer(): Promise<ArrayBuffer>;`,
517
+ ` text(): Promise<string>;`,
518
+ ` json<T = unknown>(): Promise<T>;`,
519
+ ` blob(): Promise<Blob>;`,
520
+ `}`,
521
+ ``,
522
+ `/** R2 list result */`,
523
+ `export interface ExportR2ListResult {`,
524
+ ` objects: ExportR2ObjectMeta[];`,
525
+ ` truncated: boolean;`,
526
+ ` cursor?: string;`,
527
+ ` delimitedPrefixes: string[];`,
528
+ `}`,
529
+ ``,
530
+ `/** R2 bucket proxy */`,
531
+ `export interface ExportR2Proxy {`,
532
+ ` get(key: string, options?: { type?: "arrayBuffer" | "text" | "json" | "stream" }): Promise<ExportR2Object | null>;`,
533
+ ` put(key: string, value: string | ArrayBuffer | ReadableStream | Blob, options?: {`,
534
+ ` httpMetadata?: Record<string, string>;`,
535
+ ` customMetadata?: Record<string, string>;`,
536
+ ` }): Promise<ExportR2ObjectMeta>;`,
537
+ ` delete(key: string | string[]): Promise<void>;`,
538
+ ` list(options?: {`,
539
+ ` prefix?: string;`,
540
+ ` limit?: number;`,
541
+ ` cursor?: string;`,
542
+ ` delimiter?: string;`,
543
+ ` include?: ("httpMetadata" | "customMetadata")[];`,
544
+ ` }): Promise<ExportR2ListResult>;`,
545
+ ` head(key: string): Promise<ExportR2ObjectMeta | null>;`,
546
+ `}`,
547
+ ``,
548
+ `/** KV list result */`,
549
+ `export interface ExportKVListResult {`,
550
+ ` keys: { name: string; expiration?: number; metadata?: unknown }[];`,
551
+ ` list_complete: boolean;`,
552
+ ` cursor?: string;`,
553
+ `}`,
554
+ ``,
555
+ `/** KV namespace proxy */`,
556
+ `export interface ExportKVProxy {`,
557
+ ` get<T = string>(key: string, options?: { type?: "text" | "json" | "arrayBuffer" | "stream"; cacheTtl?: number }): Promise<T | null>;`,
558
+ ` put(key: string, value: string | ArrayBuffer | ReadableStream, options?: {`,
559
+ ` expiration?: number;`,
560
+ ` expirationTtl?: number;`,
561
+ ` metadata?: unknown;`,
562
+ ` }): Promise<void>;`,
563
+ ` delete(key: string): Promise<void>;`,
564
+ ` list(options?: {`,
565
+ ` prefix?: string;`,
566
+ ` limit?: number;`,
567
+ ` cursor?: string;`,
568
+ ` }): Promise<ExportKVListResult>;`,
569
+ ` getWithMetadata<T = string, M = unknown>(key: string, options?: { type?: "text" | "json" | "arrayBuffer" | "stream"; cacheTtl?: number }): Promise<{`,
570
+ ` value: T | null;`,
571
+ ` metadata: M | null;`,
572
+ ` }>;`,
573
+ `}`,
574
+ ``,
575
+ `/** Auth sign-in methods */`,
576
+ `export interface ExportAuthSignIn {`,
577
+ ` /** Sign in with OAuth provider */`,
578
+ ` social(provider: string, options?: { callbackURL?: string; scopes?: string[] }): Promise<{ redirectUrl?: string; token?: string; user?: object }>;`,
579
+ ` /** Sign in with email and password */`,
580
+ ` email(email: string, password: string, options?: object): Promise<{ success: boolean; token?: string; user?: object; error?: string }>;`,
581
+ `}`,
582
+ ``,
583
+ `/** Auth sign-up methods */`,
584
+ `export interface ExportAuthSignUp {`,
585
+ ` /** Sign up with email, password, and name */`,
586
+ ` email(email: string, password: string, name?: string, options?: object): Promise<{ success: boolean; token?: string; user?: object; error?: string }>;`,
587
+ `}`,
588
+ ``,
589
+ `/** Auth session */`,
590
+ `export interface ExportAuthSession {`,
591
+ ` token: string;`,
592
+ ` userId: string;`,
593
+ ` expiresAt: Date;`,
594
+ `}`,
595
+ ``,
596
+ `/** Auth user */`,
597
+ `export interface ExportAuthUser {`,
598
+ ` id: string;`,
599
+ ` email: string;`,
600
+ ` name?: string;`,
601
+ ` image?: string;`,
602
+ ` emailVerified: boolean;`,
603
+ ` createdAt: Date;`,
604
+ ` updatedAt: Date;`,
605
+ `}`,
606
+ ``,
607
+ `/** Auth client proxy */`,
608
+ `export interface ExportAuthProxy {`,
609
+ ` signIn: ExportAuthSignIn;`,
610
+ ` signUp: ExportAuthSignUp;`,
611
+ ` signOut(): Promise<{ success: boolean }>;`,
612
+ ` getSession(): Promise<ExportAuthSession | null>;`,
613
+ ` getUser(): Promise<ExportAuthUser | null>;`,
614
+ ` setToken(token: string): Promise<{ success: boolean }>;`,
615
+ ` readonly isAuthenticated: boolean;`,
616
+ `}`,
617
+ ``,
618
+ ];
619
+
620
+ // Generate D1 type mapping
621
+ if (allD1Bindings.length > 0) {
622
+ clientDtsLines.push(`/** D1 database bindings */`);
623
+ clientDtsLines.push(`export interface ExportD1Bindings {`);
624
+ for (const name of allD1Bindings) {
625
+ clientDtsLines.push(` ${name}: ExportD1Proxy;`);
626
+ }
627
+ clientDtsLines.push(`}`);
628
+ clientDtsLines.push(``);
629
+ } else {
630
+ clientDtsLines.push(`export interface ExportD1Bindings {}`);
631
+ clientDtsLines.push(``);
632
+ }
633
+
634
+ // Generate R2 type mapping
635
+ if (r2Bindings.length > 0) {
636
+ clientDtsLines.push(`/** R2 bucket bindings */`);
637
+ clientDtsLines.push(`export interface ExportR2Bindings {`);
638
+ for (const name of r2Bindings) {
639
+ clientDtsLines.push(` ${name}: ExportR2Proxy;`);
640
+ }
641
+ clientDtsLines.push(`}`);
642
+ clientDtsLines.push(``);
643
+ } else {
644
+ clientDtsLines.push(`export interface ExportR2Bindings {}`);
645
+ clientDtsLines.push(``);
646
+ }
647
+
648
+ // Generate KV type mapping
649
+ if (kvBindings.length > 0) {
650
+ clientDtsLines.push(`/** KV namespace bindings */`);
651
+ clientDtsLines.push(`export interface ExportKVBindings {`);
652
+ for (const name of kvBindings) {
653
+ clientDtsLines.push(` ${name}: ExportKVProxy;`);
654
+ }
655
+ clientDtsLines.push(`}`);
656
+ clientDtsLines.push(``);
657
+ } else {
658
+ clientDtsLines.push(`export interface ExportKVBindings {}`);
659
+ clientDtsLines.push(``);
660
+ }
661
+
662
+ // Generate main client interface
663
+ clientDtsLines.push(`/** Export client with typed storage bindings */`);
664
+ clientDtsLines.push(`export interface ExportClient {`);
665
+ clientDtsLines.push(` d1: ExportD1Bindings;`);
666
+ clientDtsLines.push(` r2: ExportR2Bindings;`);
667
+ clientDtsLines.push(` kv: ExportKVBindings;`);
668
+ clientDtsLines.push(` auth: ${authConfig ? 'ExportAuthProxy' : 'null'};`);
669
+ clientDtsLines.push(`}`);
670
+ clientDtsLines.push(``);
671
+ clientDtsLines.push(`declare const client: ExportClient;`);
672
+ clientDtsLines.push(`export default client;`);
673
+ clientDtsLines.push(``);
674
+
675
+ const clientDtsPath = path.join(cwd, ".export-client.d.ts");
676
+ fs.writeFileSync(clientDtsPath, clientDtsLines.join("\n"));
677
+
678
+ // --- Generate export.d.ts (module declaration helper) ---
679
+
680
+ const moduleDtsLines = [
681
+ `// Type declarations for your export worker.`,
682
+ `// Update the URL to match your deployed worker or local dev server.`,
683
+ `//`,
684
+ `// Usage in your client code:`,
685
+ `// import client, { myFunction } from "https://my-worker.workers.dev";`,
686
+ `// const result = await client.d1.MY_DB\`SELECT * FROM users\`;`,
687
+ ``,
688
+ `declare module "http://localhost:8787" {`,
689
+ ` export * from "./.export-client";`,
690
+ ` export { default } from "./.export-client";`,
691
+ `}`,
692
+ ``,
693
+ `// Add more module declarations for your deployed URLs:`,
694
+ `// declare module "https://my-worker.workers.dev" {`,
695
+ `// export * from "./.export-client";`,
696
+ `// export { default } from "./.export-client";`,
697
+ `// }`,
698
+ ``,
699
+ ];
700
+
701
+ const moduleDtsPath = path.join(cwd, "export.d.ts");
702
+ // Only write if it doesn't exist (user may have customized it)
703
+ if (!fs.existsSync(moduleDtsPath)) {
704
+ fs.writeFileSync(moduleDtsPath, moduleDtsLines.join("\n"));
705
+ console.log("Generated module declarations →", moduleDtsPath);
706
+ }
707
+
474
708
  // --- Output summary ---
475
709
 
476
710
  console.log(`Discovered ${modules.length} module(s): ${modules.map(m => m.routePath || "/").join(", ")}`);
477
711
  console.log("Generated type definitions + minified core →", outPath);
478
712
  console.log("Generated module map →", moduleMapPath);
479
713
  console.log("Generated shared import module →", sharedModulePath);
714
+ console.log("Generated client types →", clientDtsPath);
480
715
  console.log("Generated wrangler.toml →", wranglerPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-runtime",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Cloudflare Workers ESM Export Framework Runtime",
5
5
  "keywords": [
6
6
  "cloudflare",