Refactor Zig imports and file structure (part 1) (#21270)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
taylor.fish
2025-07-22 17:51:38 -07:00
committed by GitHub
parent 73d92c7518
commit 07cd45deae
564 changed files with 9917 additions and 9697 deletions

View File

@@ -33,8 +33,8 @@ pub const AnyPostgresError = error{
UnknownFormatCode,
};
pub fn postgresErrorToJS(globalObject: *JSC.JSGlobalObject, message: ?[]const u8, err: AnyPostgresError) JSValue {
const error_code: JSC.Error = switch (err) {
pub fn postgresErrorToJS(globalObject: *jsc.JSGlobalObject, message: ?[]const u8, err: AnyPostgresError) JSValue {
const error_code: jsc.Error = switch (err) {
error.ConnectionClosed => .POSTGRES_CONNECTION_CLOSED,
error.ExpectedRequest => .POSTGRES_EXPECTED_REQUEST,
error.ExpectedStatement => .POSTGRES_EXPECTED_STATEMENT,
@@ -83,5 +83,5 @@ pub fn postgresErrorToJS(globalObject: *JSC.JSGlobalObject, message: ?[]const u8
const bun = @import("bun");
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -29,7 +29,7 @@ pub const CommandTag = union(enum) {
other: []const u8,
pub fn toJSTag(this: CommandTag, globalObject: *JSC.JSGlobalObject) JSValue {
pub fn toJSTag(this: CommandTag, globalObject: *jsc.JSGlobalObject) JSValue {
return switch (this) {
.INSERT => JSValue.jsNumber(1),
.DELETE => JSValue.jsNumber(2),
@@ -39,7 +39,7 @@ pub const CommandTag = union(enum) {
.MOVE => JSValue.jsNumber(6),
.FETCH => JSValue.jsNumber(7),
.COPY => JSValue.jsNumber(8),
.other => |tag| JSC.ZigString.init(tag).toJS(globalObject),
.other => |tag| jsc.ZigString.init(tag).toJS(globalObject),
};
}
@@ -101,5 +101,5 @@ const debug = bun.Output.scoped(.Postgres, false);
const bun = @import("bun");
const std = @import("std");
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -193,7 +193,7 @@ pub const DataCell = extern struct {
if (slice.len <= count) return "";
return slice[count..];
}
fn parseArray(bytes: []const u8, bigint: bool, comptime arrayType: types.Tag, globalObject: *JSC.JSGlobalObject, offset: ?*usize, comptime is_json_sub_array: bool) !DataCell {
fn parseArray(bytes: []const u8, bigint: bool, comptime arrayType: types.Tag, globalObject: *jsc.JSGlobalObject, offset: ?*usize, comptime is_json_sub_array: bool) !DataCell {
const closing_brace = if (is_json_sub_array) ']' else '}';
const opening_brace = if (is_json_sub_array) '[' else '{';
if (bytes.len < 2 or bytes[0] != opening_brace) {
@@ -587,7 +587,7 @@ pub const DataCell = extern struct {
return DataCell{ .tag = .array, .value = .{ .array = .{ .ptr = array.items.ptr, .len = @truncate(array.items.len), .cap = @truncate(array.capacity) } } };
}
pub fn fromBytes(binary: bool, bigint: bool, oid: types.Tag, bytes: []const u8, globalObject: *JSC.JSGlobalObject) !DataCell {
pub fn fromBytes(binary: bool, bigint: bool, oid: types.Tag, bytes: []const u8, globalObject: *jsc.JSGlobalObject) !DataCell {
switch (oid) {
// TODO: .int2_array, .float8_array
inline .int4_array, .float4_array => |tag| {
@@ -1001,22 +1001,22 @@ pub const DataCell = extern struct {
binary: bool = false,
bigint: bool = false,
count: usize = 0,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
extern fn JSC__constructObjectFromDataCell(
*JSC.JSGlobalObject,
*jsc.JSGlobalObject,
JSValue,
JSValue,
[*]DataCell,
u32,
Flags,
u8, // result_mode
?[*]JSC.JSObject.ExternColumnIdentifier, // names
?[*]jsc.JSObject.ExternColumnIdentifier, // names
u32, // names count
) JSValue;
pub fn toJS(this: *Putter, globalObject: *JSC.JSGlobalObject, array: JSValue, structure: JSValue, flags: Flags, result_mode: PostgresSQLQueryResultMode, cached_structure: ?PostgresCachedStructure) JSValue {
var names: ?[*]JSC.JSObject.ExternColumnIdentifier = null;
pub fn toJS(this: *Putter, globalObject: *jsc.JSGlobalObject, array: JSValue, structure: JSValue, flags: Flags, result_mode: PostgresSQLQueryResultMode, cached_structure: ?PostgresCachedStructure) JSValue {
var names: ?[*]jsc.JSObject.ExternColumnIdentifier = null;
var names_count: u32 = 0;
if (cached_structure) |c| {
if (c.fields) |f| {
@@ -1101,5 +1101,5 @@ const short = types.short;
const bun = @import("bun");
const String = bun.String;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,15 +2,15 @@ const ObjectIterator = @This();
array: JSValue,
columns: JSValue = .zero,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
cell_i: usize = 0,
row_i: usize = 0,
current_row: JSC.JSValue = .zero,
current_row: jsc.JSValue = .zero,
columns_count: usize = 0,
array_length: usize = 0,
any_failed: bool = false,
pub fn next(this: *ObjectIterator) ?JSC.JSValue {
pub fn next(this: *ObjectIterator) ?jsc.JSValue {
if (this.row_i >= this.array_length) {
return null;
}
@@ -22,7 +22,7 @@ pub fn next(this: *ObjectIterator) ?JSC.JSValue {
const globalObject = this.globalObject;
if (this.current_row == .zero) {
this.current_row = JSC.JSObject.getIndex(this.array, globalObject, @intCast(row_i)) catch {
this.current_row = jsc.JSObject.getIndex(this.array, globalObject, @intCast(row_i)) catch {
this.any_failed = true;
return null;
};
@@ -39,7 +39,7 @@ pub fn next(this: *ObjectIterator) ?JSC.JSValue {
}
}
const property = JSC.JSObject.getIndex(this.columns, globalObject, @intCast(cell_i)) catch {
const property = jsc.JSObject.getIndex(this.columns, globalObject, @intCast(cell_i)) catch {
this.any_failed = true;
return null;
};
@@ -59,5 +59,5 @@ pub fn next(this: *ObjectIterator) ?JSC.JSValue {
const bun = @import("bun");
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -1,16 +1,16 @@
structure: JSC.Strong.Optional = .empty,
// only populated if more than JSC.JSC__JSObject__maxInlineCapacity fields otherwise the structure will contain all fields inlined
fields: ?[]JSC.JSObject.ExternColumnIdentifier = null,
structure: jsc.Strong.Optional = .empty,
// only populated if more than jsc.JSC__JSObject__maxInlineCapacity fields otherwise the structure will contain all fields inlined
fields: ?[]jsc.JSObject.ExternColumnIdentifier = null,
pub fn has(this: *@This()) bool {
return this.structure.has() or this.fields != null;
}
pub fn jsValue(this: *const @This()) ?JSC.JSValue {
pub fn jsValue(this: *const @This()) ?jsc.JSValue {
return this.structure.get();
}
pub fn set(this: *@This(), globalObject: *JSC.JSGlobalObject, value: ?JSC.JSValue, fields: ?[]JSC.JSObject.ExternColumnIdentifier) void {
pub fn set(this: *@This(), globalObject: *jsc.JSGlobalObject, value: ?jsc.JSValue, fields: ?[]jsc.JSObject.ExternColumnIdentifier) void {
if (value) |v| {
this.structure.set(globalObject, v);
}
@@ -29,4 +29,4 @@ pub fn deinit(this: *@This()) void {
}
const bun = @import("bun");
const JSC = bun.JSC;
const jsc = bun.jsc;

View File

@@ -1,7 +1,7 @@
pub fn writeBind(
name: []const u8,
cursor_name: bun.String,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
values_array: JSValue,
columns_value: JSValue,
parameter_fields: []const int4,
@@ -209,7 +209,7 @@ pub fn writeQuery(
}
pub fn prepareAndQueryWithSignature(
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
query: []const u8,
array_value: JSValue,
comptime Context: type,
@@ -230,7 +230,7 @@ pub fn prepareAndQueryWithSignature(
}
pub fn bindAndExecute(
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
statement: *PostgresSQLStatement,
array_value: JSValue,
columns_value: JSValue,
@@ -342,5 +342,5 @@ const short = types.short;
const bun = @import("bun");
const String = bun.String;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -14,7 +14,7 @@ pipelined_requests: u32 = 0,
nonpipelinable_requests: u32 = 0,
poll_ref: bun.Async.KeepAlive = .{},
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
statements: PreparedStatementsMap,
prepared_statement_id: u64 = 0,
@@ -34,7 +34,7 @@ options_buf: []const u8 = "",
authentication_state: AuthenticationState = .{ .pending = {} },
tls_ctx: ?*uws.SocketContext = null,
tls_config: JSC.API.ServerConfig.SSLConfig = .{},
tls_config: jsc.API.ServerConfig.SSLConfig = .{},
tls_status: TLSStatus = .none,
ssl_mode: SSLMode = .disable,
@@ -136,18 +136,18 @@ pub fn resetConnectionTimeout(this: *PostgresSQLConnection) void {
this.globalObject.bunVM().timer.insert(&this.timer);
}
pub fn getQueries(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) bun.JSError!JSC.JSValue {
pub fn getQueries(_: *PostgresSQLConnection, thisValue: jsc.JSValue, globalObject: *jsc.JSGlobalObject) bun.JSError!jsc.JSValue {
if (js.queriesGetCached(thisValue)) |value| {
return value;
}
const array = try JSC.JSValue.createEmptyArray(globalObject, 0);
const array = try jsc.JSValue.createEmptyArray(globalObject, 0);
js.queriesSetCached(thisValue, globalObject, array);
return array;
}
pub fn getOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue {
pub fn getOnConnect(_: *PostgresSQLConnection, thisValue: jsc.JSValue, _: *jsc.JSGlobalObject) jsc.JSValue {
if (js.onconnectGetCached(thisValue)) |value| {
return value;
}
@@ -155,11 +155,11 @@ pub fn getOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.J
return .js_undefined;
}
pub fn setOnConnect(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
pub fn setOnConnect(_: *PostgresSQLConnection, thisValue: jsc.JSValue, globalObject: *jsc.JSGlobalObject, value: jsc.JSValue) void {
js.onconnectSetCached(thisValue, globalObject, value);
}
pub fn getOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.JSGlobalObject) JSC.JSValue {
pub fn getOnClose(_: *PostgresSQLConnection, thisValue: jsc.JSValue, _: *jsc.JSGlobalObject) jsc.JSValue {
if (js.oncloseGetCached(thisValue)) |value| {
return value;
}
@@ -167,7 +167,7 @@ pub fn getOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, _: *JSC.JSG
return .js_undefined;
}
pub fn setOnClose(_: *PostgresSQLConnection, thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject, value: JSC.JSValue) void {
pub fn setOnClose(_: *PostgresSQLConnection, thisValue: jsc.JSValue, globalObject: *jsc.JSGlobalObject, value: jsc.JSValue) void {
js.oncloseSetCached(thisValue, globalObject, value);
}
@@ -328,7 +328,7 @@ pub fn failWithJSValue(this: *PostgresSQLConnection, value: JSValue) void {
) catch |e| this.globalObject.reportActiveExceptionAsUnhandled(e);
}
pub fn failFmt(this: *PostgresSQLConnection, comptime error_code: JSC.Error, comptime fmt: [:0]const u8, args: anytype) void {
pub fn failFmt(this: *PostgresSQLConnection, comptime error_code: jsc.Error, comptime fmt: [:0]const u8, args: anytype) void {
this.failWithJSValue(error_code.fmt(this.globalObject, fmt, args));
}
@@ -553,17 +553,17 @@ pub fn onData(this: *PostgresSQLConnection, data: []const u8) void {
this.read_buffer.head = 0;
}
pub fn constructor(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!*PostgresSQLConnection {
pub fn constructor(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!*PostgresSQLConnection {
_ = callframe;
return globalObject.throw("PostgresSQLConnection cannot be constructed directly", .{});
}
comptime {
const jscall = JSC.toJSHostFn(call);
const jscall = jsc.toJSHostFn(call);
@export(&jscall, .{ .name = "PostgresSQLConnection__createInstance" });
}
pub fn call(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
pub fn call(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
var vm = globalObject.bunVM();
const arguments = callframe.arguments_old(15).slice();
const hostname_str = try arguments[0].toBunString(globalObject);
@@ -587,13 +587,13 @@ pub fn call(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JS
const tls_object = arguments[6];
var tls_config: JSC.API.ServerConfig.SSLConfig = .{};
var tls_config: jsc.API.ServerConfig.SSLConfig = .{};
var tls_ctx: ?*uws.SocketContext = null;
if (ssl_mode != .disable) {
tls_config = if (tls_object.isBoolean() and tls_object.toBoolean())
.{}
else if (tls_object.isObject())
(JSC.API.ServerConfig.SSLConfig.fromJS(vm, globalObject, tls_object) catch return .zero) orelse .{}
(jsc.API.ServerConfig.SSLConfig.fromJS(vm, globalObject, tls_object) catch return .zero) orelse .{}
else {
return globalObject.throwInvalidArguments("tls must be a boolean or an object", .{});
};
@@ -810,18 +810,18 @@ pub fn ref(this: *@This()) void {
this.ref_count += 1;
}
pub fn doRef(this: *@This(), _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doRef(this: *@This(), _: *jsc.JSGlobalObject, _: *jsc.CallFrame) bun.JSError!JSValue {
this.poll_ref.ref(this.globalObject.bunVM());
this.updateHasPendingActivity();
return .js_undefined;
}
pub fn doUnref(this: *@This(), _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doUnref(this: *@This(), _: *jsc.JSGlobalObject, _: *jsc.CallFrame) bun.JSError!JSValue {
this.poll_ref.unref(this.globalObject.bunVM());
this.updateHasPendingActivity();
return .js_undefined;
}
pub fn doFlush(this: *PostgresSQLConnection, _: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSC.JSValue {
pub fn doFlush(this: *PostgresSQLConnection, _: *jsc.JSGlobalObject, _: *jsc.CallFrame) bun.JSError!jsc.JSValue {
this.registerAutoFlusher();
return .js_undefined;
}
@@ -836,7 +836,7 @@ pub fn deref(this: *@This()) void {
}
}
pub fn doClose(this: *@This(), globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doClose(this: *@This(), globalObject: *jsc.JSGlobalObject, _: *jsc.CallFrame) bun.JSError!JSValue {
_ = globalObject;
this.disconnect();
this.unregisterAutoFlusher();
@@ -872,7 +872,7 @@ pub fn deinit(this: *@This()) void {
bun.default_allocator.destroy(this);
}
fn refAndClose(this: *@This(), js_reason: ?JSC.JSValue) void {
fn refAndClose(this: *@This(), js_reason: ?jsc.JSValue) void {
// refAndClose is always called when we wanna to disconnect or when we are closed
if (!this.socket.isClosed()) {
@@ -1265,7 +1265,7 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera
};
var stack_buf: [70]DataCell = undefined;
var cells: []DataCell = stack_buf[0..@min(statement.fields.len, JSC.JSObject.maxInlineCapacity())];
var cells: []DataCell = stack_buf[0..@min(statement.fields.len, jsc.JSObject.maxInlineCapacity())];
var free_cells = false;
defer {
for (cells[0..putter.count]) |*cell| {
@@ -1274,7 +1274,7 @@ pub fn on(this: *PostgresSQLConnection, comptime MessageType: @Type(.enum_litera
if (free_cells) bun.default_allocator.free(cells);
}
if (statement.fields.len >= JSC.JSObject.maxInlineCapacity()) {
if (statement.fields.len >= jsc.JSObject.maxInlineCapacity()) {
cells = try bun.default_allocator.alloc(DataCell, statement.fields.len);
free_cells = true;
}
@@ -1688,11 +1688,11 @@ pub fn updateRef(this: *PostgresSQLConnection) void {
}
}
pub fn getConnected(this: *PostgresSQLConnection, _: *JSC.JSGlobalObject) JSValue {
pub fn getConnected(this: *PostgresSQLConnection, _: *jsc.JSGlobalObject) JSValue {
return JSValue.jsBoolean(this.status == Status.connected);
}
pub fn consumeOnConnectCallback(this: *const PostgresSQLConnection, globalObject: *JSC.JSGlobalObject) ?JSC.JSValue {
pub fn consumeOnConnectCallback(this: *const PostgresSQLConnection, globalObject: *jsc.JSGlobalObject) ?jsc.JSValue {
debug("consumeOnConnectCallback", .{});
const on_connect = js.onconnectGetCached(this.js_value) orelse return null;
debug("consumeOnConnectCallback exists", .{});
@@ -1701,7 +1701,7 @@ pub fn consumeOnConnectCallback(this: *const PostgresSQLConnection, globalObject
return on_connect;
}
pub fn consumeOnCloseCallback(this: *const PostgresSQLConnection, globalObject: *JSC.JSGlobalObject) ?JSC.JSValue {
pub fn consumeOnCloseCallback(this: *const PostgresSQLConnection, globalObject: *jsc.JSGlobalObject) ?jsc.JSValue {
debug("consumeOnCloseCallback", .{});
const on_close = js.oncloseGetCached(this.js_value) orelse return null;
debug("consumeOnCloseCallback exists", .{});
@@ -1715,7 +1715,7 @@ const debug = bun.Output.scoped(.Postgres, false);
const MAX_PIPELINE_SIZE = std.math.maxInt(u16); // about 64KB per connection
pub const js = JSC.Codegen.JSPostgresSQLConnection;
pub const js = jsc.Codegen.JSPostgresSQLConnection;
pub const fromJS = js.fromJS;
pub const fromJSDirect = js.fromJSDirect;
pub const toJS = js.toJS;
@@ -1742,9 +1742,9 @@ const bun = @import("bun");
const BoringSSL = bun.BoringSSL;
const assert = bun.assert;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const AutoFlusher = JSC.WebCore.AutoFlusher;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;
const AutoFlusher = jsc.WebCore.AutoFlusher;
const uws = bun.uws;
const Socket = uws.AnySocket;

View File

@@ -1,9 +1,9 @@
tcp: ?*uws.SocketContext = null,
onQueryResolveFn: JSC.Strong.Optional = .empty,
onQueryRejectFn: JSC.Strong.Optional = .empty,
onQueryResolveFn: jsc.Strong.Optional = .empty,
onQueryRejectFn: jsc.Strong.Optional = .empty,
pub fn init(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
pub fn init(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
var ctx = &globalObject.bunVM().rareData().postgresql_context;
ctx.onQueryResolveFn.set(globalObject, callframe.argument(0));
ctx.onQueryRejectFn.set(globalObject, callframe.argument(1));
@@ -12,10 +12,10 @@ pub fn init(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JS
}
comptime {
const js_init = JSC.toJSHostFn(init);
const js_init = jsc.toJSHostFn(init);
@export(&js_init, .{ .name = "PostgresSQLContext__init" });
}
const bun = @import("bun");
const JSC = bun.JSC;
const jsc = bun.jsc;
const uws = bun.uws;

View File

@@ -20,7 +20,7 @@ flags: packed struct(u8) {
_padding: u1 = 0,
} = .{},
pub fn getTarget(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, clean_target: bool) JSC.JSValue {
pub fn getTarget(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, clean_target: bool) jsc.JSValue {
const thisValue = this.thisValue.get();
if (thisValue == .zero) {
return .zero;
@@ -90,7 +90,7 @@ pub fn ref(this: *@This()) void {
pub fn onWriteFail(
this: *@This(),
err: AnyPostgresError,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
queries_array: JSValue,
) void {
this.status = .fail;
@@ -101,7 +101,7 @@ pub fn onWriteFail(
return;
}
const vm = JSC.VirtualMachine.get();
const vm = jsc.VirtualMachine.get();
const function = vm.rareData().postgresql_context.onQueryRejectFn.get().?;
const event_loop = vm.eventLoop();
event_loop.runCallback(function, globalObject, thisValue, &.{
@@ -110,7 +110,7 @@ pub fn onWriteFail(
queries_array,
});
}
pub fn onJSError(this: *@This(), err: JSC.JSValue, globalObject: *JSC.JSGlobalObject) void {
pub fn onJSError(this: *@This(), err: jsc.JSValue, globalObject: *jsc.JSGlobalObject) void {
this.status = .fail;
this.ref();
defer this.deref();
@@ -122,7 +122,7 @@ pub fn onJSError(this: *@This(), err: JSC.JSValue, globalObject: *JSC.JSGlobalOb
return;
}
var vm = JSC.VirtualMachine.get();
var vm = jsc.VirtualMachine.get();
const function = vm.rareData().postgresql_context.onQueryRejectFn.get().?;
const event_loop = vm.eventLoop();
event_loop.runCallback(function, globalObject, thisValue, &.{
@@ -130,11 +130,11 @@ pub fn onJSError(this: *@This(), err: JSC.JSValue, globalObject: *JSC.JSGlobalOb
err,
});
}
pub fn onError(this: *@This(), err: PostgresSQLStatement.Error, globalObject: *JSC.JSGlobalObject) void {
pub fn onError(this: *@This(), err: PostgresSQLStatement.Error, globalObject: *jsc.JSGlobalObject) void {
this.onJSError(err.toJS(globalObject), globalObject);
}
pub fn allowGC(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) void {
pub fn allowGC(thisValue: jsc.JSValue, globalObject: *jsc.JSGlobalObject) void {
if (thisValue == .zero) {
return;
}
@@ -145,13 +145,13 @@ pub fn allowGC(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) void {
js.targetSetCached(thisValue, globalObject, .zero);
}
fn consumePendingValue(thisValue: JSC.JSValue, globalObject: *JSC.JSGlobalObject) ?JSValue {
fn consumePendingValue(thisValue: jsc.JSValue, globalObject: *jsc.JSGlobalObject) ?JSValue {
const pending_value = js.pendingValueGetCached(thisValue) orelse return null;
js.pendingValueSetCached(thisValue, globalObject, .zero);
return pending_value;
}
pub fn onResult(this: *@This(), command_tag_str: []const u8, globalObject: *JSC.JSGlobalObject, connection: JSC.JSValue, is_last: bool) void {
pub fn onResult(this: *@This(), command_tag_str: []const u8, globalObject: *jsc.JSGlobalObject, connection: jsc.JSValue, is_last: bool) void {
this.ref();
defer this.deref();
@@ -170,7 +170,7 @@ pub fn onResult(this: *@This(), command_tag_str: []const u8, globalObject: *JSC.
return;
}
const vm = JSC.VirtualMachine.get();
const vm = jsc.VirtualMachine.get();
const function = vm.rareData().postgresql_context.onQueryResolveFn.get().?;
const event_loop = vm.eventLoop();
const tag = CommandTag.init(command_tag_str);
@@ -185,7 +185,7 @@ pub fn onResult(this: *@This(), command_tag_str: []const u8, globalObject: *JSC.
});
}
pub fn constructor(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!*PostgresSQLQuery {
pub fn constructor(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!*PostgresSQLQuery {
_ = callframe;
return globalThis.throw("PostgresSQLQuery cannot be constructed directly", .{});
}
@@ -195,9 +195,9 @@ pub fn estimatedSize(this: *PostgresSQLQuery) usize {
return @sizeOf(PostgresSQLQuery);
}
pub fn call(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSC.JSValue {
pub fn call(globalThis: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!jsc.JSValue {
const arguments = callframe.arguments_old(6).slice();
var args = JSC.CallFrame.ArgumentsSlice.init(globalThis.bunVM(), arguments);
var args = jsc.CallFrame.ArgumentsSlice.init(globalThis.bunVM(), arguments);
defer args.deinit();
const query = args.nextEat() orelse {
return globalThis.throw("query must be a string", .{});
@@ -256,22 +256,22 @@ pub fn call(globalThis: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSEr
return this_value;
}
pub fn push(this: *PostgresSQLQuery, globalThis: *JSC.JSGlobalObject, value: JSValue) void {
pub fn push(this: *PostgresSQLQuery, globalThis: *jsc.JSGlobalObject, value: JSValue) void {
var pending_value = this.pending_value.get() orelse return;
pending_value.push(globalThis, value);
}
pub fn doDone(this: *@This(), globalObject: *JSC.JSGlobalObject, _: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doDone(this: *@This(), globalObject: *jsc.JSGlobalObject, _: *jsc.CallFrame) bun.JSError!JSValue {
_ = globalObject;
this.flags.is_done = true;
return .js_undefined;
}
pub fn setPendingValue(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
pub fn setPendingValue(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!JSValue {
const result = callframe.argument(0);
js.pendingValueSetCached(this.thisValue.get(), globalObject, result);
return .js_undefined;
}
pub fn setMode(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
pub fn setMode(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!JSValue {
const js_mode = callframe.argument(0);
if (js_mode.isEmptyOrUndefinedOrNull() or !js_mode.isNumber()) {
return globalObject.throwInvalidArgumentType("setMode", "mode", "Number");
@@ -284,7 +284,7 @@ pub fn setMode(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callf
return .js_undefined;
}
pub fn doRun(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doRun(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!JSValue {
var arguments_ = callframe.arguments_old(2);
const arguments = arguments_.slice();
const connection: *PostgresSQLConnection = arguments[0].as(PostgresSQLConnection) orelse {
@@ -465,7 +465,7 @@ pub fn doRun(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callfra
return .js_undefined;
}
pub fn doCancel(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFrame) bun.JSError!JSValue {
pub fn doCancel(this: *PostgresSQLQuery, globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.JSError!JSValue {
_ = callframe;
_ = globalObject;
_ = this;
@@ -474,13 +474,13 @@ pub fn doCancel(this: *PostgresSQLQuery, globalObject: *JSC.JSGlobalObject, call
}
comptime {
const jscall = JSC.toJSHostFn(call);
const jscall = jsc.toJSHostFn(call);
@export(&jscall, .{ .name = "PostgresSQLQuery__createInstance" });
}
const debug = bun.Output.scoped(.Postgres, false);
pub const js = JSC.Codegen.JSPostgresSQLQuery;
pub const js = jsc.Codegen.JSPostgresSQLQuery;
pub const fromJS = js.fromJS;
pub const fromJSDirect = js.fromJSDirect;
pub const toJS = js.toJS;
@@ -498,7 +498,7 @@ const PostgresSQLQueryResultMode = @import("./PostgresSQLQueryResultMode.zig").P
const AnyPostgresError = @import("./AnyPostgresError.zig").AnyPostgresError;
const postgresErrorToJS = @import("./AnyPostgresError.zig").postgresErrorToJS;
const JSC = bun.JSC;
const JSGlobalObject = JSC.JSGlobalObject;
const JSRef = JSC.JSRef;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSGlobalObject = jsc.JSGlobalObject;
const JSRef = jsc.JSRef;
const JSValue = jsc.JSValue;

View File

@@ -21,7 +21,7 @@ pub const Error = union(enum) {
}
}
pub fn toJS(this: *const @This(), globalObject: *JSC.JSGlobalObject) JSValue {
pub fn toJS(this: *const @This(), globalObject: *jsc.JSGlobalObject) JSValue {
return switch (this.*) {
.protocol => |err| err.toJS(globalObject),
.postgres_error => |err| postgresErrorToJS(globalObject, null, err),
@@ -117,14 +117,14 @@ pub fn deinit(this: *PostgresSQLStatement) void {
bun.default_allocator.destroy(this);
}
pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *JSC.JSGlobalObject) PostgresCachedStructure {
pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *jsc.JSGlobalObject) PostgresCachedStructure {
if (this.cached_structure.has()) {
return this.cached_structure;
}
this.checkForDuplicateFields();
// lets avoid most allocations
var stack_ids: [70]JSC.JSObject.ExternColumnIdentifier = undefined;
var stack_ids: [70]jsc.JSObject.ExternColumnIdentifier = undefined;
// lets de duplicate the fields early
var nonDuplicatedCount = this.fields.len;
for (this.fields) |*field| {
@@ -132,13 +132,13 @@ pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *JSC
nonDuplicatedCount -= 1;
}
}
const ids = if (nonDuplicatedCount <= JSC.JSObject.maxInlineCapacity()) stack_ids[0..nonDuplicatedCount] else bun.default_allocator.alloc(JSC.JSObject.ExternColumnIdentifier, nonDuplicatedCount) catch bun.outOfMemory();
const ids = if (nonDuplicatedCount <= jsc.JSObject.maxInlineCapacity()) stack_ids[0..nonDuplicatedCount] else bun.default_allocator.alloc(jsc.JSObject.ExternColumnIdentifier, nonDuplicatedCount) catch bun.outOfMemory();
var i: usize = 0;
for (this.fields) |*field| {
if (field.name_or_index == .duplicate) continue;
var id: *JSC.JSObject.ExternColumnIdentifier = &ids[i];
var id: *jsc.JSObject.ExternColumnIdentifier = &ids[i];
switch (field.name_or_index) {
.name => |name| {
id.value.name = String.createAtomIfPossible(name.slice());
@@ -156,10 +156,10 @@ pub fn structure(this: *PostgresSQLStatement, owner: JSValue, globalObject: *JSC
i += 1;
}
if (nonDuplicatedCount > JSC.JSObject.maxInlineCapacity()) {
if (nonDuplicatedCount > jsc.JSObject.maxInlineCapacity()) {
this.cached_structure.set(globalObject, null, ids);
} else {
this.cached_structure.set(globalObject, JSC.JSObject.createStructure(
this.cached_structure.set(globalObject, jsc.JSObject.createStructure(
globalObject,
owner,
@truncate(ids.len),
@@ -187,5 +187,5 @@ const int4 = types.int4;
const bun = @import("bun");
const String = bun.String;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -1,10 +1,10 @@
pub const QueryBindingIterator = union(enum) {
array: JSC.JSArrayIterator,
array: jsc.JSArrayIterator,
objects: ObjectIterator,
pub fn init(array: JSValue, columns: JSValue, globalObject: *JSC.JSGlobalObject) bun.JSError!QueryBindingIterator {
pub fn init(array: JSValue, columns: JSValue, globalObject: *jsc.JSGlobalObject) bun.JSError!QueryBindingIterator {
if (columns.isEmptyOrUndefinedOrNull()) {
return .{ .array = try JSC.JSArrayIterator.init(array, globalObject) };
return .{ .array = try jsc.JSArrayIterator.init(array, globalObject) };
}
return .{
@@ -18,7 +18,7 @@ pub const QueryBindingIterator = union(enum) {
};
}
pub fn next(this: *QueryBindingIterator) bun.JSError!?JSC.JSValue {
pub fn next(this: *QueryBindingIterator) bun.JSError!?jsc.JSValue {
return switch (this.*) {
.array => |*iter| iter.next(),
.objects => |*iter| iter.next(),
@@ -60,5 +60,5 @@ pub const QueryBindingIterator = union(enum) {
const ObjectIterator = @import("./ObjectIterator.zig");
const bun = @import("bun");
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -65,7 +65,7 @@ pub fn clientKey(this: *const SASL) [32]u8 {
pub fn clientKeySignature(_: *const SASL, client_key: []const u8, auth_string: []const u8) [32]u8 {
var sha_digest = std.mem.zeroes(bun.sha.SHA256.Digest);
bun.sha.SHA256.hash(client_key, &sha_digest, JSC.VirtualMachine.get().rareData().boringEngine());
bun.sha.SHA256.hash(client_key, &sha_digest, jsc.VirtualMachine.get().rareData().boringEngine());
return hmac(&sha_digest, auth_string).?;
}
@@ -89,6 +89,6 @@ const PostgresSQLConnection = @import("./PostgresSQLConnection.zig");
const std = @import("std");
const bun = @import("bun");
const JSC = bun.JSC;
const assert = bun.assert;
const Crypto = JSC.API.Bun.Crypto;
const jsc = bun.jsc;
const Crypto = jsc.API.Bun.Crypto;

View File

@@ -36,7 +36,7 @@ pub fn hash(this: *const Signature) u64 {
return hasher.final();
}
pub fn generate(globalObject: *JSC.JSGlobalObject, query: []const u8, array_value: JSValue, columns: JSValue, prepared_statement_id: u64, unnamed: bool) !Signature {
pub fn generate(globalObject: *jsc.JSGlobalObject, query: []const u8, array_value: JSValue, columns: JSValue, prepared_statement_id: u64, unnamed: bool) !Signature {
var fields = std.ArrayList(int4).init(bun.default_allocator);
var name = try std.ArrayList(u8).initCapacity(bun.default_allocator, query.len);
@@ -108,5 +108,5 @@ const QueryBindingIterator = @import("./QueryBindingIterator.zig").QueryBindingI
const types = @import("./PostgresTypes.zig");
const int4 = types.int4;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -29,7 +29,7 @@ pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReade
pub const decode = DecoderWrap(ErrorResponse, decodeInternal).decode;
pub fn toJS(this: ErrorResponse, globalObject: *JSC.JSGlobalObject) JSValue {
pub fn toJS(this: ErrorResponse, globalObject: *jsc.JSGlobalObject) JSValue {
var b = bun.StringBuilder{};
defer b.deinit(bun.default_allocator);
@@ -119,7 +119,7 @@ pub fn toJS(this: ErrorResponse, globalObject: *JSC.JSGlobalObject) JSValue {
.{ "table", table, void },
.{ "where", where, void },
};
const error_code: JSC.Error =
const error_code: jsc.Error =
// https://www.postgresql.org/docs/8.1/errcodes-appendix.html
if (code.eqlComptime("42601"))
.POSTGRES_SYNTAX_ERROR
@@ -132,14 +132,14 @@ pub fn toJS(this: ErrorResponse, globalObject: *JSC.JSGlobalObject) JSValue {
const value = brk: {
if (field.@"2" == i32) {
if (field.@"1".toInt32()) |val| {
break :brk JSC.JSValue.jsNumberFromInt32(val);
break :brk jsc.JSValue.jsNumberFromInt32(val);
}
}
break :brk field.@"1".toJS(globalObject);
};
err.put(globalObject, JSC.ZigString.static(field.@"0"), value);
err.put(globalObject, jsc.ZigString.static(field.@"0"), value);
}
}
@@ -154,5 +154,5 @@ const NewReader = @import("./NewReader.zig").NewReader;
const bun = @import("bun");
const String = bun.String;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -19,7 +19,7 @@ pub fn decodeInternal(this: *@This(), comptime Container: type, reader: NewReade
}
pub const decode = DecoderWrap(NoticeResponse, decodeInternal).decode;
pub fn toJS(this: NoticeResponse, globalObject: *JSC.JSGlobalObject) JSValue {
pub fn toJS(this: NoticeResponse, globalObject: *jsc.JSGlobalObject) JSValue {
var b = bun.StringBuilder{};
defer b.deinit(bun.default_allocator);
@@ -39,7 +39,7 @@ pub fn toJS(this: NoticeResponse, globalObject: *JSC.JSGlobalObject) JSValue {
_ = b.append("\n");
}
return JSC.ZigString.init(b.allocatedSlice()[0..b.len]).toJS(globalObject);
return jsc.ZigString.init(b.allocatedSlice()[0..b.len]).toJS(globalObject);
}
const bun = @import("bun");
@@ -48,5 +48,5 @@ const DecoderWrap = @import("./DecoderWrap.zig").DecoderWrap;
const FieldMessage = @import("./FieldMessage.zig").FieldMessage;
const NewReader = @import("./NewReader.zig").NewReader;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,7 +2,7 @@ pub const to = 25;
pub const from = [_]short{1002};
pub fn toJSWithType(
globalThis: *JSC.JSGlobalObject,
globalThis: *jsc.JSGlobalObject,
comptime Type: type,
value: Type,
) AnyPostgresError!JSValue {
@@ -31,7 +31,7 @@ pub fn toJSWithType(
}
pub fn toJS(
globalThis: *JSC.JSGlobalObject,
globalThis: *jsc.JSGlobalObject,
value: anytype,
) !JSValue {
var str = try toJSWithType(globalThis, @TypeOf(value), value);
@@ -46,5 +46,5 @@ const Data = @import("../Data.zig").Data;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -265,7 +265,7 @@ pub const Tag = enum(short) {
fn toJSWithType(
tag: Tag,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
comptime Type: type,
value: Type,
) AnyPostgresError!JSValue {
@@ -310,13 +310,13 @@ pub const Tag = enum(short) {
pub fn toJS(
tag: Tag,
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
value: anytype,
) AnyPostgresError!JSValue {
return toJSWithType(tag, globalObject, @TypeOf(value), value);
}
pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSValue) bun.JSError!Tag {
pub fn fromJS(globalObject: *jsc.JSGlobalObject, value: JSValue) bun.JSError!Tag {
if (value.isEmptyOrUndefinedOrNull()) {
return Tag.numeric;
}
@@ -405,5 +405,5 @@ const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,7 +2,7 @@ pub const to = 16;
pub const from = [_]short{16};
pub fn toJS(
_: *JSC.JSGlobalObject,
_: *jsc.JSGlobalObject,
value: bool,
) AnyPostgresError!JSValue {
return JSValue.jsBoolean(value);
@@ -14,5 +14,5 @@ const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,7 +2,7 @@ pub const to = 17;
pub const from = [_]short{17};
pub fn toJS(
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
value: *Data,
) AnyPostgresError!JSValue {
defer value.deinit();
@@ -19,5 +19,5 @@ const Data = @import("../Data.zig").Data;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -11,7 +11,7 @@ pub fn fromBinary(bytes: []const u8) f64 {
return (double_microseconds / std.time.us_per_ms) + POSTGRES_EPOCH_DATE;
}
pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSValue) bun.JSError!i64 {
pub fn fromJS(globalObject: *jsc.JSGlobalObject, value: JSValue) bun.JSError!i64 {
const double_value = if (value.isDate())
value.getUnixTimestamp()
else if (value.isNumber())
@@ -27,7 +27,7 @@ pub fn fromJS(globalObject: *JSC.JSGlobalObject, value: JSValue) bun.JSError!i64
}
pub fn toJS(
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
value: anytype,
) JSValue {
switch (@TypeOf(value)) {
@@ -51,5 +51,5 @@ const Data = @import("../Data.zig").Data;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,7 +2,7 @@ pub const to = 114;
pub const from = [_]short{ 114, 3802 };
pub fn toJS(
globalObject: *JSC.JSGlobalObject,
globalObject: *jsc.JSGlobalObject,
value: *Data,
) AnyPostgresError!JSValue {
defer value.deinit();
@@ -23,5 +23,5 @@ const Data = @import("../Data.zig").Data;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;

View File

@@ -2,7 +2,7 @@ pub const to = 0;
pub const from = [_]short{ 21, 23, 26, 700, 701 };
pub fn toJS(
_: *JSC.JSGlobalObject,
_: *jsc.JSGlobalObject,
value: anytype,
) AnyPostgresError!JSValue {
return JSValue.jsNumber(value);
@@ -14,5 +14,5 @@ const AnyPostgresError = @import("../AnyPostgresError.zig").AnyPostgresError;
const int_types = @import("./int_types.zig");
const short = int_types.short;
const JSC = bun.JSC;
const JSValue = JSC.JSValue;
const jsc = bun.jsc;
const JSValue = jsc.JSValue;