@inflector/aura 0.8.0 → 0.8.1

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/dist/bin.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env bun
2
2
  export declare function build(silent?: boolean): void;
3
- export declare function serve(mode: "dev" | "prod"): Promise<void>;
4
3
  export declare function dev(): Promise<void>;
5
4
  //# sourceMappingURL=bin.d.ts.map
package/dist/bin.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAmLA,wBAAgB,KAAK,CAAC,MAAM,UAAQ,QAgDnC;AAwJD,wBAAsB,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,MAAM,iBAqL/C;AAmRD,wBAAsB,GAAG,kBAiFxB"}
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AA6JA,wBAAgB,KAAK,CAAC,MAAM,UAAQ,QA4CnC;AAiWD,wBAAsB,GAAG,kBAuDxB"}
package/dist/bin.js CHANGED
@@ -167,21 +167,21 @@ export function build(silent = false) {
167
167
  // IMPORTANT:
168
168
  // - SSEHandler is NOT generic
169
169
  // - Client exposes parsed data, not raw SSE events
170
- const header = `
171
- export type SSEEvent = {
172
- event: string;
173
- data: any;
174
- };
175
-
176
- export type SSEStream<T> = {
177
- onMessage(cb: (data: T) => void): Promise<void>;
178
- abort(): void;
179
- };
180
-
181
- export type FnResult<TJson, TSse = never> =
182
- TSse extends never
183
- ? Promise<TJson>
184
- : Promise<TJson> | SSEStream<TSse>;
170
+ const header = `
171
+ export type SSEEvent = {
172
+ event: string;
173
+ data: any;
174
+ };
175
+
176
+ export type SSEStream<T> = {
177
+ onMessage(cb: (data: T) => void): Promise<void>;
178
+ abort(): void;
179
+ };
180
+
181
+ export type FnResult<TJson, TSse = never> =
182
+ TSse extends never
183
+ ? Promise<TJson>
184
+ : Promise<TJson> | SSEStream<TSse>;
185
185
  `.trimStart();
186
186
  const body = objectToTypeWithReturn("AuraFunctions", structure);
187
187
  const tsType = header + "\n\n" + body;
@@ -321,159 +321,6 @@ async function pull() {
321
321
  log.error(err.message);
322
322
  }
323
323
  }
324
- export async function serve(mode) {
325
- let Config;
326
- try {
327
- Config = JSON.parse(fs.readFileSync("./Aura/config.json", "utf-8"));
328
- }
329
- catch {
330
- log.error("Config file not found. Run `aura init` first.");
331
- return;
332
- }
333
- const upstreamUrl = Config.Url.replace(/\/$/, "");
334
- const AURA_KEY = process.env.AURA_KEY;
335
- const proxyRequest = async (req) => {
336
- const url = new URL(req.url);
337
- const targetUrl = `${upstreamUrl}${url.pathname}${url.search}`;
338
- const headers = new Headers();
339
- // @ts-ignore
340
- for (const [key, value] of req.headers.entries()) {
341
- if (["host", "accept-encoding", "connection", "transfer-encoding"].includes(key.toLowerCase()))
342
- continue;
343
- headers.set(key, value);
344
- }
345
- headers.set("x-forwarded-host", req.headers.get("host") ?? "");
346
- headers.set("x-forwarded-proto", req.headers.get("x-forwarded-proto") ?? "http");
347
- headers.set("x-forwarded-for", req.headers.get("x-forwarded-for") ?? "");
348
- if (AURA_KEY)
349
- headers.set("Authorization", `Bearer ${AURA_KEY}`);
350
- try {
351
- const upstream = await fetch(targetUrl, {
352
- method: req.method,
353
- headers,
354
- body: req.method === "GET" || req.method === "HEAD" ? undefined : req.body,
355
- signal: req.signal,
356
- });
357
- const resHeaders = new Headers();
358
- // @ts-ignore
359
- for (const [key, value] of upstream.headers.entries()) {
360
- if (["content-encoding", "content-length", "transfer-encoding"].includes(key.toLowerCase()))
361
- continue;
362
- resHeaders.append(key, value);
363
- }
364
- return new Response(upstream.body, {
365
- status: upstream.status,
366
- statusText: upstream.statusText,
367
- headers: resHeaders,
368
- });
369
- }
370
- catch (err) {
371
- if (err.name === "AbortError" || req.signal?.aborted) {
372
- return new Response(null, { status: 499 });
373
- }
374
- return new Response(JSON.stringify({ error: "Upstream Proxy Failed" }), {
375
- status: 502,
376
- headers: { "Content-Type": "application/json" },
377
- });
378
- }
379
- };
380
- if (mode === "dev") {
381
- const { createServer, mergeConfig, loadConfigFromFile } = await import("vite");
382
- const configFile = path.resolve(process.cwd(), "vite.config.ts");
383
- const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, configFile);
384
- if (!configResult?.config) {
385
- log.error("Could not load vite.config.ts");
386
- return;
387
- }
388
- const vite = await createServer(mergeConfig(configResult.config, {
389
- configFile: false,
390
- server: {
391
- proxy: {
392
- "/api": {
393
- target: upstreamUrl,
394
- changeOrigin: true,
395
- secure: false,
396
- ws: true,
397
- cookieDomainRewrite: "",
398
- rewrite: (path) => path, // identity — no rewrite, keep as-is
399
- configure(proxy) {
400
- proxy.on("proxyReq", (proxyReq, req) => {
401
- proxyReq.setHeader("connection", "close");
402
- if (AURA_KEY)
403
- proxyReq.setHeader("Authorization", `Bearer ${AURA_KEY}`);
404
- if (req.headers.cookie)
405
- proxyReq.setHeader("cookie", req.headers.cookie);
406
- });
407
- proxy.on("error", (err, req, res) => {
408
- console.error("[proxy error]", err.message, req.url);
409
- if (!res.headersSent) {
410
- res.writeHead(502, { "Content-Type": "application/json" });
411
- res.end(JSON.stringify({
412
- error: "Proxy error",
413
- detail: err.message,
414
- }));
415
- }
416
- });
417
- },
418
- },
419
- },
420
- },
421
- }));
422
- if (vite.bindCLIShortcuts)
423
- vite.bindCLIShortcuts({ print: true });
424
- await vite.listen();
425
- vite.printUrls();
426
- return;
427
- }
428
- // prod
429
- const configFile = path.resolve(process.cwd(), "vite.config.ts");
430
- const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, configFile);
431
- const port = configResult?.config?.preview?.port ?? 80;
432
- const getMimeType = (p) => {
433
- if (p.endsWith(".js"))
434
- return "application/javascript";
435
- if (p.endsWith(".css"))
436
- return "text/css";
437
- if (p.endsWith(".html"))
438
- return "text/html";
439
- if (p.endsWith(".json"))
440
- return "application/json";
441
- if (p.endsWith(".png"))
442
- return "image/png";
443
- if (p.endsWith(".jpg") || p.endsWith(".jpeg"))
444
- return "image/jpeg";
445
- if (p.endsWith(".svg"))
446
- return "image/svg+xml";
447
- return "application/octet-stream";
448
- };
449
- Bun.serve({
450
- hostname: "0.0.0.0",
451
- port,
452
- idleTimeout: 0,
453
- async fetch(req) {
454
- const url = new URL(req.url);
455
- if (url.pathname.startsWith("/api"))
456
- return proxyRequest(req);
457
- const filePath = `./dist${url.pathname}`;
458
- const file = Bun.file(filePath);
459
- if (await file.exists()) {
460
- return new Response(file, {
461
- headers: { "Content-Type": getMimeType(filePath) },
462
- });
463
- }
464
- const index = Bun.file("./dist/index.html");
465
- if (await index.exists()) {
466
- return new Response(index, {
467
- headers: { "Content-Type": "text/html" },
468
- });
469
- }
470
- return new Response("Not Found", { status: 404 });
471
- },
472
- });
473
- log.success(`Server running on http://localhost:${port}`);
474
- log.dim(` • Proxying /api → ${upstreamUrl}`);
475
- log.dim(` • Serving static → ./dist`);
476
- }
477
324
  function init(c = "vite") {
478
325
  log.info("Initializing Aura project...");
479
326
  const filesContent = {
@@ -486,14 +333,14 @@ function init(c = "vite") {
486
333
  },
487
334
  indexTs: {
488
335
  path: "./Aura/index.ts",
489
- content: `import { CreateAura } from "@inflector/aura"
490
- import * as AuraConfig from "./config.json"
491
- import * as Tables from "./schema.ts"
492
- import type { AuraFunctions } from "./.generated"
493
- export const Aura = CreateAura<AuraFunctions, typeof Tables>({
494
- config: AuraConfig,
495
- Tables
496
- })
336
+ content: `import { CreateAura } from "@inflector/aura"
337
+ import * as AuraConfig from "./config.json"
338
+ import * as Tables from "./schema.ts"
339
+ import type { AuraFunctions } from "./.generated"
340
+ export const Aura = CreateAura<AuraFunctions, typeof Tables>({
341
+ config: AuraConfig,
342
+ Tables
343
+ })
497
344
  `,
498
345
  },
499
346
  schemaTs: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inflector/aura",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",