Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/source/ComposerGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => {
w.wl(s"struct $helper").bracedSemi {
w.wl(s"using CppType = $cls;")
w.wl("using ComposerType = Composer:: Value;")
w.wl("using ComposerType = Valdi:: Value;")
w.wl(s"using Boxed = $helper;")
w.wl
w.wl("static CppType toCpp(const ComposerType& v);")
w.wl("static ComposerType fromCpp(const CppType& c);")
w.wl
w.wl("static const Composer::ValueSchema& schema() noexcept;")
w.wl("static const Valdi::ValueSchema& schema() noexcept;")
}
}), (w => {}))
writeCppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle, spec.composerIncludePrefix) (ident.name, origin, refs.cpp, (w => {
w.wl("using namespace Composer;")
w.wl("using namespace Valdi;")
w.wl
w.w(s"auto $helper::toCpp(const ComposerType& v) -> CppType").braced {
w.wl("auto o = v.getTypedObjectRef();")
Expand Down Expand Up @@ -247,18 +247,18 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
writeHppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle)(ident.name, origin, refs.hpp, Nil, (w => {
w.w(s"struct $helper : ::djinni::composer::JsInterface<$cls, $helper>").bracedSemi {
w.wl("static void registerSchema(bool resolve) noexcept;")
w.wl("static const Composer::ValueSchema& schemaRef() noexcept;")
w.wl("static const Composer::ValueSchema& schema() noexcept;")
w.wl("static const Valdi::ValueSchema& schemaRef() noexcept;")
w.wl("static const Valdi::ValueSchema& schema() noexcept;")

// cpp marshal helper
if (i.ext.cpp) {
w.wl("static Composer::Ref<Composer::ValueTypedProxyObject> toComposer(const CppOptType& c);")
w.wl("static Valdi::Ref<Valdi::ValueTypedProxyObject> toComposer(const CppOptType& c);")
}

// js proxy
if (i.ext.js) {
w.w(s"struct ComposerProxy: $cls, ::djinni::composer::ComposerProxyBase").bracedSemi {
w.wl("ComposerProxy(Composer::Ref<Composer::ValueTypedProxyObject> js) : ComposerProxyBase(js) {}")
w.wl("ComposerProxy(Valdi::Ref<Valdi::ValueTypedProxyObject> js) : ComposerProxyBase(js) {}")
for (m <- i.methods.filter(m => !m.static)) {
w.w(s"${cppMarshal.fqReturnType(m.ret)} ${idCpp.method(m.ident)}(")
w.w(m.params.map(p => {
Expand All @@ -273,7 +273,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
//static methods
val staticMethods = i.methods.filter(m => m.static)
if (!staticMethods.isEmpty) {
w.wl("static void djinniInitStaticMethods(Composer::Ref<Composer::ValueMap> m) noexcept;")
w.wl("static void djinniInitStaticMethods(Valdi::Ref<Valdi::ValueMap> m) noexcept;")
}

//TODO ???
Expand All @@ -285,7 +285,7 @@ class ComposerGenerator(spec: Spec) extends Generator(spec) {
}), (w => {}))

writeCppFileGeneric(spec.composerOutFolder.get, helperNamespace(), composerFilenameStyle, spec.composerIncludePrefix)(ident.name, origin, refs.cpp, (w => {
w.wl("using namespace Composer;")
w.wl("using namespace Valdi;")
w.wl("using namespace std::placeholders;")
w.wl
w.wl(s"""static STRING_CONST(schemaName, "${schemaTypeNameForInterface(ident)}");""")
Expand Down
42 changes: 21 additions & 21 deletions support-lib/composer/DataRef_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace djinni::composer {

struct ComposerDataObject: Composer::ComposerObject {
struct ComposerDataObject: Valdi::ComposerObject {
COMPOSER_CLASS_HEADER(ComposerDataObject);
std::variant<std::vector<uint8_t>, std::string, std::shared_ptr<DataRef::Impl>> _data;
};
Expand All @@ -30,33 +30,33 @@ class DataRefComposer: public DataRef::Impl {
public:
// create an empty buffer from c++
explicit DataRefComposer(size_t len) {
auto bytes = Composer::makeShared<Composer::Bytes>();
auto bytes = Valdi::makeShared<Valdi::Bytes>();
bytes->assignVec(std::vector<uint8_t>(len));
_array = Composer::makeShared<Composer::ValueTypedArray>(Composer::kDefaultTypedArrayType, bytes);
_array = Valdi::makeShared<Valdi::ValueTypedArray>(Valdi::kDefaultTypedArrayType, bytes);
}
// wrap an array object from JS
explicit DataRefComposer(const Composer::Ref<Composer::ValueTypedArray>& array) {
explicit DataRefComposer(const Valdi::Ref<Valdi::ValueTypedArray>& array) {
_array = array;
}
// take over a std::vector's buffer without copying it
explicit DataRefComposer(std::vector<uint8_t>&& vec) {
auto container = Composer::makeShared<ComposerDataObject>();
auto container = Valdi::makeShared<ComposerDataObject>();
container->_data = std::move(vec);
const auto& containedVec = std::get<std::vector<uint8_t>>(container->_data);
auto bytes = containedVec.data();
auto len = containedVec.size();
_array = Composer::makeShared<Composer::ValueTypedArray>(Composer::kDefaultTypedArrayType,
Composer::BytesView(container, bytes, len));
_array = Valdi::makeShared<Valdi::ValueTypedArray>(Valdi::kDefaultTypedArrayType,
Valdi::BytesView(container, bytes, len));
}
// take over a std::string's buffer without copying it
explicit DataRefComposer(std::string&& str) {
auto container = Composer::makeShared<ComposerDataObject>();
auto container = Valdi::makeShared<ComposerDataObject>();
container->_data = std::move(str);
const std::string& containedStr = std::get<std::string>(container->_data);
auto bytes = reinterpret_cast<const uint8_t*>(containedStr.data());
auto len = containedStr.size();
_array = Composer::makeShared<Composer::ValueTypedArray>(Composer::kDefaultTypedArrayType,
Composer::BytesView(container, bytes, len));
_array = Valdi::makeShared<Valdi::ValueTypedArray>(Valdi::kDefaultTypedArrayType,
Valdi::BytesView(container, bytes, len));
}

DataRefComposer(const DataRefComposer&) = delete;
Expand All @@ -71,38 +71,38 @@ class DataRefComposer: public DataRef::Impl {
return const_cast<uint8_t*>(_array->getBuffer().data());
}

Composer::Ref<Composer::ValueTypedArray> platformObj() const {
Valdi::Ref<Valdi::ValueTypedArray> platformObj() const {
return _array;
}

private:
Composer::Ref<Composer::ValueTypedArray> _array;
Valdi::Ref<Valdi::ValueTypedArray> _array;
};

DataRef NativeDataRef::toCpp(const Composer::Value& v) {
DataRef NativeDataRef::toCpp(const Valdi::Value& v) {
auto arr = v.getTypedArrayRef();
auto impl = std::make_shared<DataRefComposer>(arr);
return DataRef(impl);
}

Composer::Value NativeDataRef::fromCpp(const DataRef& c) {
Valdi::Value NativeDataRef::fromCpp(const DataRef& c) {
auto impl = std::dynamic_pointer_cast<DataRefComposer>(c.impl());
if (impl) {
auto arr = impl->platformObj();
return Composer::Value(arr);
return Valdi::Value(arr);
} else {
auto container = Composer::makeShared<ComposerDataObject>();
auto container = Valdi::makeShared<ComposerDataObject>();
auto bytes = c.buf();
auto len = c.len();
container->_data = c.impl();
auto arr = Composer::makeShared<Composer::ValueTypedArray>(Composer::kDefaultTypedArrayType,
Composer::BytesView(container, bytes, len));
return Composer::Value(arr);
auto arr = Valdi::makeShared<Valdi::ValueTypedArray>(Valdi::kDefaultTypedArrayType,
Valdi::BytesView(container, bytes, len));
return Valdi::Value(arr);
}
}

const Composer::ValueSchema& NativeDataRef::schema() {
static auto schema = Composer::ValueSchema::valueTypedArray();
const Valdi::ValueSchema& NativeDataRef::schema() {
static auto schema = Valdi::ValueSchema::valueTypedArray();
return schema;
}

Expand Down
4 changes: 2 additions & 2 deletions support-lib/composer/DataRef_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ namespace djinni::composer {

struct NativeDataRef {
using CppType = DataRef;
using ComposerType = Composer::Value;
using ComposerType = Valdi::Value;
using Boxed = NativeDataRef;

static CppType toCpp(const ComposerType& v);
static ComposerType fromCpp(const CppType& c);

static const Composer::ValueSchema& schema();
static const Valdi::ValueSchema& schema();
};

} // namespace djinni
12 changes: 6 additions & 6 deletions support-lib/composer/DataView_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace djinni::composer {

struct NativeDataView {
using CppType = DataView;
using ComposerType = Composer::Value;
using ComposerType = Valdi::Value;
using Boxed = NativeDataView;

static CppType toCpp(const ComposerType& v) {
Expand All @@ -33,13 +33,13 @@ struct NativeDataView {
}

static ComposerType fromCpp(const CppType& c) {
Composer::BytesView buf(nullptr, c.buf(), c.len());
auto arr = Composer::makeShared<Composer::ValueTypedArray>(Composer::kDefaultTypedArrayType, buf);
return Composer::Value(arr);
Valdi::BytesView buf(nullptr, c.buf(), c.len());
auto arr = Valdi::makeShared<Valdi::ValueTypedArray>(Valdi::kDefaultTypedArrayType, buf);
return Valdi::Value(arr);
}

static const Composer::ValueSchema& schema() {
static auto schema = Composer::ValueSchema::valueTypedArray();
static const Valdi::ValueSchema& schema() {
static auto schema = Valdi::ValueSchema::valueTypedArray();
return schema;
}
};
Expand Down
38 changes: 19 additions & 19 deletions support-lib/composer/Future_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class FutureAdaptor

public:
using CppType = Future<CppResType>;
using ComposerType = Composer::Value;
using ComposerType = Valdi::Value;

using Boxed = FutureAdaptor;

using NativePromiseType = Promise<CppResType>;

static CppType toCpp(ComposerType o)
{
auto composerPromise = castOrNull<Composer::Promise>(o.getComposerObject());
auto cppPromise = Composer::makeShared<Promise<CppResType>>();
auto composerPromise = castOrNull<Valdi::Promise>(o.getComposerObject());
auto cppPromise = Valdi::makeShared<Promise<CppResType>>();
auto cppFuture = cppPromise->getFuture();
composerPromise->onComplete([cppPromise] (const Composer::Result<Composer::Value>& result) {
composerPromise->onComplete([cppPromise] (const Valdi::Result<Valdi::Value>& result) {
if (result.success()) {
if constexpr(std::is_same_v<Void, RESULT>) {
cppPromise->setValue();
Expand All @@ -56,40 +56,40 @@ class FutureAdaptor

static ComposerType fromCpp(CppType c)
{
auto composerPromise = Composer::makeShared<Composer::ResolvablePromise>();
auto composerPromise = Valdi::makeShared<Valdi::ResolvablePromise>();
c.then([composerPromise] (Future<CppResType> f) {
try {
if constexpr(std::is_same_v<Void, RESULT>) {
composerPromise->fulfill(Composer::Result<Composer::Value>(Composer::Value::undefined()));
composerPromise->fulfill(Valdi::Result<Valdi::Value>(Valdi::Value::undefined()));
} else {
composerPromise->fulfill(Composer::Result<Composer::Value>(RESULT::fromCpp(f.get())));
composerPromise->fulfill(Valdi::Result<Valdi::Value>(RESULT::fromCpp(f.get())));
}
} catch (const std::exception& e) {
composerPromise->fulfill({Composer::Result<Composer::Value>{Composer::Error(e.what())}});
composerPromise->fulfill({Valdi::Result<Valdi::Value>{Valdi::Error(e.what())}});
}
});
return Composer::Value(composerPromise);
return Valdi::Value(composerPromise);
}
static const Composer::ValueSchema& schema() {
static auto schema = Composer::ValueSchema::promise(schemaOrRef<RESULT>());
static const Valdi::ValueSchema& schema() {
static auto schema = Valdi::ValueSchema::promise(schemaOrRef<RESULT>());
return schema;
}
};

template<typename U>
struct ExceptionHandlingTraits<FutureAdaptor<U>> {
static Composer::Value handleNativeException(const std::exception& e, const Composer::ValueFunctionCallContext& callContext) noexcept {
static Valdi::Value handleNativeException(const std::exception& e, const Valdi::ValueFunctionCallContext& callContext) noexcept {
// store C++ exception in JS Error and raise in JS runtime
auto msg = STRING_FORMAT("C++: {}", e.what());
auto composerPromise = Composer::makeShared<Composer::ResolvablePromise>();
composerPromise->fulfill(Composer::Result<Composer::Value>(Composer::Error(std::move(msg))));
return Composer::Value(composerPromise);
auto composerPromise = Valdi::makeShared<Valdi::ResolvablePromise>();
composerPromise->fulfill(Valdi::Result<Valdi::Value>(Valdi::Error(std::move(msg))));
return Valdi::Value(composerPromise);
}
static Composer::Value handleNativeException(const JsException& e, const Composer::ValueFunctionCallContext& callContext) noexcept {
static Valdi::Value handleNativeException(const JsException& e, const Valdi::ValueFunctionCallContext& callContext) noexcept {
// JS error passthrough
auto composerPromise = Composer::makeShared<Composer::ResolvablePromise>();
composerPromise->fulfill(Composer::Result<Composer::Value>(e.cause()));
return Composer::Value(composerPromise);
auto composerPromise = Valdi::makeShared<Valdi::ResolvablePromise>();
composerPromise->fulfill(Valdi::Result<Valdi::Value>(e.cause()));
return Valdi::Value(composerPromise);
}
};

Expand Down
12 changes: 6 additions & 6 deletions support-lib/composer/Outcome_composer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class Outcome
using ErrorComposerType = typename ERROR::Boxed::ComposerType;
public:
using CppType = expected<ResultCppType, ErrorCppType>;
using ComposerType = Composer::Value;
using ComposerType = Valdi::Value;
using Boxed = Outcome;

static CppType toCpp(ComposerType v)
{
auto outcomeCpp = castOrNull<Composer::ComposerOutcome>(v.getComposerObject());
auto outcomeCpp = castOrNull<Valdi::ComposerOutcome>(v.getComposerObject());
if (outcomeCpp->error.isUndefined()) {
return {RESULT::toCpp(outcomeCpp->result)};
} else {
Expand All @@ -45,17 +45,17 @@ class Outcome

static ComposerType fromCpp(const CppType& c)
{
auto outcomeCpp = Composer::makeShared<Composer::ComposerOutcome>();
auto outcomeCpp = Valdi::makeShared<Valdi::ComposerOutcome>();
if (c.has_value()) {
outcomeCpp->result = RESULT::fromCpp(c.value());
} else {
outcomeCpp->error = ERROR::fromCpp(c.error());
}
return Composer::Value(outcomeCpp);
return Valdi::Value(outcomeCpp);
}

static const Composer::ValueSchema& schema() {
static auto schema = Composer::ValueSchema::outcome(schemaOrRef<RESULT>(), schemaOrRef<ERROR>());
static const Valdi::ValueSchema& schema() {
static auto schema = Valdi::ValueSchema::outcome(schemaOrRef<RESULT>(), schemaOrRef<ERROR>());
return schema;
}
};
Expand Down
8 changes: 4 additions & 4 deletions support-lib/composer/djinni_composer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace djinni::composer {

using namespace Composer;
using namespace Valdi;

std::unordered_map<ComposerProxyId, std::weak_ptr<ComposerProxyBase>> jsProxyCache;
std::unordered_map<void*, CppProxyCacheEntry> cppProxyCache;
Expand All @@ -35,7 +35,7 @@ void checkForNull(void* ptr, const char* context) {

ValueSchema resolveSchema(const ValueSchema& unresolved, std::function<void()> registerSchemaFunc) noexcept {
registerSchemaFunc();
Composer::ValueSchemaTypeResolver resolver(Composer::ValueSchemaRegistry::sharedInstance().get());
Valdi::ValueSchemaTypeResolver resolver(Valdi::ValueSchemaRegistry::sharedInstance().get());
auto result = resolver.resolveTypeReferences(unresolved);
result.ensureSuccess();
return result.moveValue();
Expand All @@ -46,7 +46,7 @@ void registerSchemaImpl(const ValueSchema& schema, bool resolve) noexcept {
if (!resolve) {
registry->registerSchema(schema);
} else {
Composer::ValueSchemaTypeResolver resolver(registry.get());
Valdi::ValueSchemaTypeResolver resolver(registry.get());
auto result = resolver.resolveTypeReferences(schema);
result.ensureSuccess();
auto key = ValueSchemaRegistryKey(ValueSchema::typeReference(ValueSchemaTypeReference::named(schema.getClass()->getClassName())));
Expand Down Expand Up @@ -79,7 +79,7 @@ Date::CppType Date::toCpp(const Date::ComposerType& v) noexcept {

Date::ComposerType Date::fromCpp(const Date::CppType& c) noexcept {
auto millisecondsSinceEpoch = std::chrono::duration_cast<std::chrono::milliseconds>(c.time_since_epoch());
return Composer::Value(static_cast<double>(millisecondsSinceEpoch.count()));
return Valdi::Value(static_cast<double>(millisecondsSinceEpoch.count()));
}

const ValueSchema& Date::schema() noexcept {
Expand Down
Loading
Loading