tidewave 0.3.0 → 0.5.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/dist/core.d.ts CHANGED
@@ -72,6 +72,11 @@ export declare function createExtractError(code: ExtractError['error']['code'],
72
72
  export interface TidewaveConfig {
73
73
  port?: number;
74
74
  host?: string;
75
+ clientUrl?: string;
75
76
  allowRemoteAccess?: boolean;
76
77
  allowedOrigins?: string[];
78
+ team?: {
79
+ id?: string;
80
+ token?: string;
81
+ };
77
82
  }
@@ -1,32 +1,3 @@
1
- import { createRequire } from "node:module";
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
- var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
- var __export = (target, all) => {
20
- for (var name in all)
21
- __defProp(target, name, {
22
- get: all[name],
23
- enumerable: true,
24
- configurable: true,
25
- set: (newValue) => all[name] = () => newValue
26
- });
27
- };
28
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
29
-
30
1
  // src/evaluation/eval_worker.ts
31
2
  process.on("message", async ({ code, args }) => {
32
3
  if (!process.send) {
@@ -40,7 +11,7 @@ process.on("message", async ({ code, args }) => {
40
11
  process.send({
41
12
  type: "result",
42
13
  success: true,
43
- data: (result || null) && result
14
+ data: (result ?? null) && result
44
15
  });
45
16
  } catch (error) {
46
17
  process.send({
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { extractDocs, getSourceLocation, formatOutput } from './resolution';
2
- import { executeIsolated } from './evaluation/code_executor';
2
+ import type { EvaluatedModuleResult, EvaluationRequest } from './core';
3
3
  export declare const Tidewave: {
4
4
  extractDocs: typeof extractDocs;
5
5
  getSourceLocation: typeof getSourceLocation;
6
6
  formatOutput: typeof formatOutput;
7
- executeIsolated: typeof executeIsolated;
7
+ executeIsolated(request: EvaluationRequest): Promise<EvaluatedModuleResult>;
8
8
  };
@@ -0,0 +1,54 @@
1
+ export interface StoredLogRecord {
2
+ timestamp: string;
3
+ severityText: string;
4
+ body: string;
5
+ attributes?: Record<string, any>;
6
+ resource?: Record<string, any>;
7
+ }
8
+ export interface LogFilterOptions {
9
+ tail?: number;
10
+ grep?: string;
11
+ level?: string;
12
+ since?: string;
13
+ }
14
+ /**
15
+ * Standalone circular buffer for storing logs.
16
+ * This is a global singleton that is not tied to any logger or exporter.
17
+ * Both console.log patches and OpenTelemetry processors write directly to this buffer.
18
+ */
19
+ export declare class CircularBuffer {
20
+ private buffer;
21
+ private maxSize;
22
+ private writeIndex;
23
+ private count;
24
+ constructor(maxSize?: number);
25
+ /**
26
+ * Add a log entry to the circular buffer.
27
+ * This method is called directly by console patching and OTel processors.
28
+ */
29
+ addLog(log: StoredLogRecord): void;
30
+ /**
31
+ * Get logs from the buffer with optional filtering.
32
+ */
33
+ getLogs(options?: LogFilterOptions): StoredLogRecord[];
34
+ /**
35
+ * Get all logs in chronological order.
36
+ */
37
+ private getAllLogs;
38
+ /**
39
+ * Get statistics about the buffer usage.
40
+ */
41
+ getStats(): {
42
+ totalLogs: number;
43
+ bufferSize: number;
44
+ bufferUsage: string;
45
+ };
46
+ /**
47
+ * Clear the buffer.
48
+ */
49
+ clear(): void;
50
+ }
51
+ declare global {
52
+ var __tidewaveCircularBuffer: CircularBuffer | undefined;
53
+ }
54
+ export declare const circularBuffer: CircularBuffer;
@@ -0,0 +1,2 @@
1
+ export { TidewaveSpanProcessor } from './tidewave-span-processor';
2
+ export { TidewaveLogRecordProcessor } from './tidewave-log-record-processor';
@@ -0,0 +1,17 @@
1
+ import type { LogRecordProcessor, SdkLogRecord } from '@opentelemetry/sdk-logs';
2
+ import type { Context } from '@opentelemetry/api';
3
+ /**
4
+ * Custom LogRecordProcessor that captures OpenTelemetry logger logs
5
+ * and writes them directly to the circular buffer.
6
+ *
7
+ * This is opt-in for users who want to capture actual logger logs
8
+ * (not console.log, which is handled separately by console patching).
9
+ */
10
+ export declare class TidewaveLogRecordProcessor implements LogRecordProcessor {
11
+ /**
12
+ * Called when a log record is emitted.
13
+ */
14
+ onEmit(logRecord: SdkLogRecord, _context?: Context): void;
15
+ forceFlush(): Promise<void>;
16
+ shutdown(): Promise<void>;
17
+ }
@@ -0,0 +1,26 @@
1
+ import type { SpanProcessor } from '@opentelemetry/sdk-trace-base';
2
+ import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
3
+ import type { Span, Context } from '@opentelemetry/api';
4
+ /**
5
+ * Custom SpanProcessor that converts OpenTelemetry spans to logs and writes them
6
+ * directly to the circular buffer.
7
+ * This is used to capture Next.js HTTP request/response spans and
8
+ * make them available via the get_logs tool.
9
+ */
10
+ export declare class TidewaveSpanProcessor implements SpanProcessor {
11
+ /**
12
+ * Called when a span is started. We don't need to do anything here.
13
+ */
14
+ onStart(_span: Span, _parentContext: Context): void;
15
+ /**
16
+ * Called when a span ends. This is where we convert the span to a log entry
17
+ * and write it directly to the circular buffer.
18
+ */
19
+ onEnd(span: ReadableSpan): void;
20
+ /**
21
+ * Calculate span duration in milliseconds from high-resolution time
22
+ */
23
+ private calculateDuration;
24
+ forceFlush(): Promise<void>;
25
+ shutdown(): Promise<void>;
26
+ }
@@ -1,15 +1,11 @@
1
1
  import type { NextApiRequest, NextApiResponse } from 'next';
2
- import { NextResponse, type NextRequest } from 'next/server';
3
- import { type Request, type Response } from './http';
4
- import type { TidewaveConfig } from './core';
2
+ import { type Request, type Response } from '../http';
3
+ import type { TidewaveConfig } from '../core';
5
4
  type NextJsHandler = (_req: NextApiRequest, _res: NextApiResponse) => Promise<void>;
6
- type NextJsMiddleware = (_req: NextRequest) => Promise<NextResponse>;
7
5
  type NextHandler = () => ValueOrPromise<unknown>;
8
6
  export type FunctionLike = (...args: any[]) => unknown;
9
7
  export type Nextable<H extends FunctionLike> = (...args: [...Parameters<H>, NextHandler]) => ValueOrPromise<any>;
10
8
  export type ValueOrPromise<T> = T | Promise<T>;
11
9
  export type RequestHandler<Req extends Request, Res extends Response> = (req: Req, res: Res) => ValueOrPromise<void>;
12
10
  export declare function tidewaveHandler(config?: TidewaveConfig): Promise<NextJsHandler>;
13
- export declare function tidewaveMiddleware(): NextJsMiddleware;
14
- export declare function isTidewaveRoute(pathname: string): boolean;
15
11
  export {};