Skip to content

Commit

Permalink
Merge branch 'main' into dylan/ref-string
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway authored Oct 15, 2024
2 parents e678a42 + 409e674 commit 360925b
Show file tree
Hide file tree
Showing 342 changed files with 42,262 additions and 7,993 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ fn addInternalPackages(b: *Build, obj: *Compile, opts: *BunBuildOptions) void {
.{ .file = "ErrorCode.zig", .import = "ErrorCode" },
.{ .file = "runtime.out.js" },
.{ .file = "bake.client.js", .import = "bake-codegen/bake.client.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bake.error.js", .import = "bake-codegen/bake.error.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bake.server.js", .import = "bake-codegen/bake.server.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bun-error/index.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bun-error/bun-error.css", .enable = opts.shouldEmbedCode() },
Expand Down
2 changes: 1 addition & 1 deletion cmake/tools/SetupWebKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")

if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION 01ac6a63449713c5b7cf38fb03628283041f63be)
set(WEBKIT_VERSION 12e2f46fb01f7c5cf5a992b9414ddfaab32b7110)
endif()

if(WEBKIT_LOCAL)
Expand Down
4 changes: 2 additions & 2 deletions docs/api/dns.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In Bun v1.1.9, we added support for DNS caching. This cache makes repeated conne

At the time of writing, we cache up to 255 entries for a maximum of 30 seconds (each). If any connections to a host fail, we remove the entry from the cache. When multiple connections are made to the same host simultaneously, DNS lookups are deduplicated to avoid making multiple requests for the same host.

This cache is automatically used by;
This cache is automatically used by:

- `bun install`
- `fetch()`
Expand Down Expand Up @@ -99,7 +99,7 @@ console.log(stats);

### Configuring DNS cache TTL

Bun defaults to 30 seconds for the TTL of DNS cache entries. To change this, you can set the envionrment variable `$BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`. For example, to set the TTL to 5 seconds:
Bun defaults to 30 seconds for the TTL of DNS cache entries. To change this, you can set the environment variable `$BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`. For example, to set the TTL to 5 seconds:

```sh
BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS=5 bun run my-script.ts
Expand Down
22 changes: 22 additions & 0 deletions docs/api/sqlite.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ As a performance optimization, the class constructor is not called, default init

The database columns are set as properties on the class instance.

### `.iterate()` (`@@iterator`)

Use `.iterate()` to run a query and incrementally return results. This is useful for large result sets that you want to process one row at a time without loading all the results into memory.

```ts
const query = db.query("SELECT * FROM foo");
for (const row of query.iterate()) {
console.log(row);
}
```

You can also use the `@@iterator` protocol:

```ts
const query = db.query("SELECT * FROM foo");
for (const row of query) {
console.log(row);
}
```

This feature was added in Bun v1.1.31.

### `.values()`

Use `values()` to run a query and get back all results as an array of arrays.
Expand Down
6 changes: 0 additions & 6 deletions docs/guides/ecosystem/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
name: Build an app with Next.js and Bun
---

{% callout %}
The Next.js [App Router](https://nextjs.org/docs/app) currently relies on Node.js APIs that Bun does not yet implement. The guide below uses Bun to initialize a project and install dependencies, but it uses Node.js to run the dev server.
{% /callout %}

---

Initialize a Next.js app with `create-next-app`. This automatically installs dependencies using `npm`.

```sh
Expand Down
10 changes: 0 additions & 10 deletions docs/guides/runtime/import-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ data.version; // => "1.0.0"
data.author.name; // => "John Dough"
```

Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes/) and [JSON modules](https://github.com/tc39/proposal-json-modules) syntax.

```ts
import data from "./package.json" with { type: "json" };

data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"
```

---

Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes/) and [JSON modules](https://github.com/tc39/proposal-json-modules) syntax.
Expand Down
9 changes: 6 additions & 3 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ declare module "bun" {
* automatically run in a worker thread.
*
* The underlying implementation of these functions are provided by the Zig
* Standard Library. Thanks to @jedisct1 and other Zig constributors for their
* Standard Library. Thanks to @jedisct1 and other Zig contributors for their
* work on this.
*
* ### Example with argon2
Expand Down Expand Up @@ -1753,7 +1753,7 @@ declare module "bun" {
* instead which runs in a worker thread.
*
* The underlying implementation of these functions are provided by the Zig
* Standard Library. Thanks to @jedisct1 and other Zig constributors for their
* Standard Library. Thanks to @jedisct1 and other Zig contributors for their
* work on this.
*
* ### Example with argon2
Expand Down Expand Up @@ -1792,7 +1792,7 @@ declare module "bun" {
* instead which runs in a worker thread.
*
* The underlying implementation of these functions are provided by the Zig
* Standard Library. Thanks to @jedisct1 and other Zig constributors for their
* Standard Library. Thanks to @jedisct1 and other Zig contributors for their
* work on this.
*
* ### Example with argon2
Expand Down Expand Up @@ -4448,15 +4448,18 @@ declare module "bun" {
hostname: string;
port: number;
tls?: TLSOptions;
exclusive?: boolean;
}

interface TCPSocketConnectOptions<Data = undefined> extends SocketOptions<Data> {
hostname: string;
port: number;
tls?: boolean;
exclusive?: boolean;
}

interface UnixSocketOptions<Data = undefined> extends SocketOptions<Data> {
tls?: TLSOptions;
unix: string;
}

Expand Down
8 changes: 0 additions & 8 deletions packages/bun-types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1838,14 +1838,6 @@ declare global {
withCredentials?: boolean;
}

interface EventSource extends Bun.EventSource {}
var EventSource: typeof globalThis extends {
onerror: any;
EventSource: infer T;
}
? T
: EventSource;

interface PromiseConstructor {
/**
* Create a deferred promise, with exposed `resolve` and `reject` methods which can be called
Expand Down
9 changes: 9 additions & 0 deletions packages/bun-types/sqlite.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ declare module "bun:sqlite" {
*/
get(...params: ParamsType): ReturnType | null;

/**
* Execute the prepared statement and return an
*
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
*
*/
iterate(...params: ParamsType): IterableIterator<ReturnType>;
[Symbol.iterator](): IterableIterator<ReturnType>;

/**
* Execute the prepared statement. This returns `undefined`.
*
Expand Down
4 changes: 0 additions & 4 deletions packages/bun-types/test/globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ const writableStream = new WritableStream();
const a = new ResolveError();
a.level;
}
{
const a = new EventSource("asdf");
a.CLOSED;
}
{
const a = new AbortController();
a;
Expand Down
9 changes: 7 additions & 2 deletions scripts/runner.node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ async function runTests() {
reportOutputToGitHubAction("failing_tests", markdown);
}

if (!isCI) console.log("-------");
if (!isCI) console.log("passing", results.length - failedTests.length, "/", results.length);
if (!isCI) {
console.log("-------");
console.log("passing", results.length - failedTests.length, "/", results.length);
for (const { testPath } of failedTests) {
console.log("-", testPath);
}
}
return results;
}

Expand Down
34 changes: 34 additions & 0 deletions src/baby_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ pub fn BabyList(comptime Type: type) type {

pub const Elem = Type;

pub fn parse(input: *bun.css.Parser) bun.css.Result(ListType) {
return switch (input.parseCommaSeparated(Type, bun.css.generic.parseFor(Type))) {
.result => |v| return .{ .result = ListType{
.ptr = v.items.ptr,
.len = @intCast(v.items.len),
.cap = @intCast(v.capacity),
} },
.err => |e| return .{ .err = e },
};
}

pub fn toCss(this: *const ListType, comptime W: type, dest: *bun.css.Printer(W)) bun.css.PrintErr!void {
return bun.css.to_css.fromBabyList(Type, this, W, dest);
}

pub fn eql(lhs: *const ListType, rhs: *const ListType) bool {
if (lhs.len != rhs.len) return false;
for (lhs.sliceConst(), rhs.sliceConst()) |*a, *b| {
if (!bun.css.generic.eql(Type, a, b)) return false;
}
return true;
}

pub fn set(this: *@This(), slice_: []Type) void {
this.ptr = slice_.ptr;
this.len = @as(u32, @truncate(slice_.len));
Expand All @@ -29,6 +52,12 @@ pub fn BabyList(comptime Type: type) type {
this.* = .{};
}

pub fn shrinkAndFree(this: *@This(), allocator: std.mem.Allocator, size: usize) void {
var list_ = this.listManaged(allocator);
list_.shrinkAndFree(size);
this.update(list_);
}

pub fn orderedRemove(this: *@This(), index: usize) Type {
var l = this.list();
defer this.update(l);
Expand Down Expand Up @@ -290,6 +319,11 @@ pub fn BabyList(comptime Type: type) type {
return this.ptr[0..this.len];
}

pub fn sliceConst(this: *const ListType) callconv(bun.callconv_inline) []const Type {
@setRuntimeSafety(false);
return this.ptr[0..this.len];
}

pub fn write(this: *@This(), allocator: std.mem.Allocator, str: []const u8) !u32 {
if (comptime Type != u8)
@compileError("Unsupported for type " ++ @typeName(Type));
Expand Down
Loading

0 comments on commit 360925b

Please sign in to comment.