Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(s3) s3 client #15740

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
4 changes: 4 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4371,6 +4371,10 @@ GlobalObject::PromiseFunctions GlobalObject::promiseHandlerID(Zig::FFIFunction h
return GlobalObject::PromiseFunctions::Bun__FetchTasklet__onResolveRequestStream;
} else if (handler == Bun__FetchTasklet__onRejectRequestStream) {
return GlobalObject::PromiseFunctions::Bun__FetchTasklet__onRejectRequestStream;
} else if (handler == Bun__S3HttpStreamUpload__onResolveRequestStream) {
return GlobalObject::PromiseFunctions::Bun__S3HttpStreamUpload__onResolveRequestStream;
} else if (handler == Bun__S3HttpStreamUpload__onRejectRequestStream) {
return GlobalObject::PromiseFunctions::Bun__S3HttpStreamUpload__onRejectRequestStream;
} else {
RELEASE_ASSERT_NOT_REACHED();
}
Expand Down
4 changes: 3 additions & 1 deletion src/bun.js/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ class GlobalObject : public Bun::GlobalScope {
Bun__onRejectEntryPointResult,
Bun__FetchTasklet__onRejectRequestStream,
Bun__FetchTasklet__onResolveRequestStream,
Bun__S3HttpStreamUpload__onRejectRequestStream,
Bun__S3HttpStreamUpload__onResolveRequestStream,
};
static constexpr size_t promiseFunctionsSize = 26;
static constexpr size_t promiseFunctionsSize = 28;

static PromiseFunctions promiseHandlerID(SYSV_ABI EncodedJSValue (*handler)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1));

Expand Down
34 changes: 34 additions & 0 deletions src/bun.js/bindings/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5819,6 +5819,40 @@ extern "C" int JSC__JSValue__toISOString(JSC::JSGlobalObject* globalObject, Enco
return charactersWritten;
}

extern "C" int JSC__JSValue__DateNowISOString(JSC::JSGlobalObject* globalObject, char* buf)
{
char buffer[29];
JSC::DateInstance* thisDateObj = JSC::DateInstance::create(globalObject->vm(), globalObject->dateStructure(), globalObject->jsDateNow());

if (!std::isfinite(thisDateObj->internalNumber()))
return -1;

auto& vm = globalObject->vm();

const GregorianDateTime* gregorianDateTime = thisDateObj->gregorianDateTimeUTC(vm.dateCache);
if (!gregorianDateTime)
return -1;

// If the year is outside the bounds of 0 and 9999 inclusive we want to use the extended year format (ES 15.9.1.15.1).
int ms = static_cast<int>(fmod(thisDateObj->internalNumber(), msPerSecond));
if (ms < 0)
ms += msPerSecond;

int charactersWritten;
if (gregorianDateTime->year() > 9999 || gregorianDateTime->year() < 0)
charactersWritten = snprintf(buffer, sizeof(buffer), "%+07d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);
else
charactersWritten = snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", gregorianDateTime->year(), gregorianDateTime->month() + 1, gregorianDateTime->monthDay(), gregorianDateTime->hour(), gregorianDateTime->minute(), gregorianDateTime->second(), ms);

memcpy(buf, buffer, charactersWritten);

ASSERT(charactersWritten > 0 && static_cast<unsigned>(charactersWritten) < sizeof(buffer));
if (static_cast<unsigned>(charactersWritten) >= sizeof(buffer))
return -1;

return charactersWritten;
}

#pragma mark - WebCore::DOMFormData

CPP_DECL void WebCore__DOMFormData__append(WebCore__DOMFormData* arg0, ZigString* arg1, ZigString* arg2)
Expand Down
11 changes: 11 additions & 0 deletions src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4305,6 +4305,15 @@ pub const JSValue = enum(i64) {

return buf[0..@as(usize, @intCast(count))];
}
extern fn JSC__JSValue__DateNowISOString(*JSGlobalObject, f64) JSValue;
pub fn getDateNowISOString(globalObject: *JSC.JSGlobalObject, buf: *[28]u8) []const u8 {
const count = JSC__JSValue__DateNowISOString(globalObject, buf);
if (count < 0) {
return "";
}

return buf[0..@as(usize, @intCast(count))];
}

/// Return the pointer to the wrapped object only if it is a direct instance of the type.
/// If the object does not match the type, return null.
Expand Down Expand Up @@ -4364,6 +4373,7 @@ pub const JSValue = enum(i64) {
}

extern fn JSC__JSValue__dateInstanceFromNumber(*JSGlobalObject, f64) JSValue;

pub fn fromDateNumber(globalObject: *JSGlobalObject, value: f64) JSValue {
JSC.markBinding(@src());
return JSC__JSValue__dateInstanceFromNumber(globalObject, value);
Expand Down Expand Up @@ -5615,6 +5625,7 @@ pub const JSValue = enum(i64) {
}
return JSC.Node.validators.throwErrInvalidArgType(global, property_name, .{}, "string", prop);
},
i32 => return prop.coerce(i32, global),
else => @compileError("TODO:" ++ @typeName(T)),
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/bun.js/bindings/headers.h

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

13 changes: 13 additions & 0 deletions src/bun.js/event_loop.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const ReadFileTask = WebCore.Blob.ReadFile.ReadFileTask;
const WriteFileTask = WebCore.Blob.WriteFile.WriteFileTask;
const napi_async_work = JSC.napi.napi_async_work;
const FetchTasklet = Fetch.FetchTasklet;
const AWS = @import("../s3.zig").AWSCredentials;
const S3HttpSimpleTask = AWS.S3HttpSimpleTask;
const S3HttpStreamUpload = AWS.S3HttpStreamUpload;
const JSValue = JSC.JSValue;
const js = JSC.C;
const Waker = bun.Async.Waker;
Expand Down Expand Up @@ -407,6 +410,8 @@ const ServerAllConnectionsClosedTask = @import("./api/server.zig").ServerAllConn
// Task.get(ReadFileTask) -> ?ReadFileTask
pub const Task = TaggedPointerUnion(.{
FetchTasklet,
S3HttpSimpleTask,
S3HttpStreamUpload,
PosixSignalTask,
AsyncGlobWalkTask,
AsyncTransformTask,
Expand Down Expand Up @@ -1005,6 +1010,14 @@ pub const EventLoop = struct {
var fetch_task: *Fetch.FetchTasklet = task.get(Fetch.FetchTasklet).?;
fetch_task.onProgressUpdate();
},
.S3HttpSimpleTask => {
var s3_task: *S3HttpSimpleTask = task.get(S3HttpSimpleTask).?;
s3_task.onResponse();
},
.S3HttpStreamUpload => {
var s3_task: *S3HttpStreamUpload = task.get(S3HttpStreamUpload).?;
s3_task.onResponse();
},
@field(Task.Tag, @typeName(AsyncGlobWalkTask)) => {
var globWalkTask: *AsyncGlobWalkTask = task.get(AsyncGlobWalkTask).?;
globWalkTask.*.runFromJS();
Expand Down
Loading
Loading