moltar / typescript-runtime-type-benchmarks

📊 Benchmark Comparison of Packages with Runtime Validation and TypeScript Support
https://moltar.github.io/typescript-runtime-type-benchmarks/
637 stars 62 forks source link

Bun support and linting configuration refactor #1225

Closed DarkGL closed 2 weeks ago

DarkGL commented 4 months ago

This is work in progress.

I'm still having some problems running bun, and I'm looking for help to fix it.

https://github.com/DarkGL/typescript-runtime-type-benchmarks/actions/runs/9016482516/job/24842376959

moltar commented 4 months ago

@nin-jin Can you help @DarkGL with this?

screenshot-20240511T151635-F0UVb8A0@2x

DarkGL commented 4 months ago

Tried with 1.1.10 but still the same

kravetsone commented 2 months ago

@nin-jin Can you help @DarkGL with this?

screenshot-20240511T151635-F0UVb8A0@2x

Not Bun-only issue

I create file index.mjs

import {
    $mol_data_email,
    $mol_data_integer,
    $mol_data_optional,
    $mol_data_pipe,
    $mol_data_record,
    $mol_data_string,
    $mol_data_variant,
} from "mol_data_all";

const PersonDTO = $mol_data_record({
    name: $mol_data_string,
    age: $mol_data_optional($mol_data_integer),
    birthday: $mol_data_pipe($mol_data_string),
});

// Derived Type
const UserDTO = $mol_data_record({
    ...PersonDTO.config,
    phone: $mol_data_variant($mol_data_string, $mol_data_integer),
    mail: $mol_data_email,
});

// Ensure this is a User
const jin = UserDTO({
    name: "Jin",
    age: 33,
    birthday: "1984-08-04T12:00:00Z",
    phone: 791234567890,
    mail: "foo@example.org",
});

console.log(jin);

And run it with node index.mjs

PS C:\Users\krave\Desktop\test\tests\mol-bun> node .\index.mjs
file:///C:/Users/krave/Desktop/test/tests/mol-bun/index.mjs:2
        $mol_data_email,
        ^^^^^^^^^^^^^^^
SyntaxError: The requested module 'mol_data_all' does not provide an export named '$mol_data_email'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:131:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:213:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Node.js v20.9.0
kravetsone commented 2 months ago

@nin-jin карловский почини пж ESM 🙏🙏

kravetsone commented 2 months ago

Yay! I've run all the benchmarks on the Bun

kravetsone commented 2 months ago

Yay! I've run all the benchmarks on the Bun

i use

const {
  $mol_data_tagged: Tagged,
  $mol_data_integer: Integer,
} = require("mol_data_all"); 

In bun you can mix require+import but not in node...

kravetsone commented 2 months ago

Why it closed?

DarkGL commented 2 months ago

I currently don't have time to work on this, if you are interested you can pick it up :)

nin-jin commented 3 weeks ago

Ух ты, сколько тут страданий. Я только сейчас узнал про эту проблему. У нас экспортируются не сами сущности, а дефолтный контекст, их содержащий. Там описано, что с этим делать.

kravetsone commented 3 weeks ago

Ух ты, сколько тут страданий. Я только сейчас узнал про эту проблему. У нас экспортируются не сами сущности, а дефолтный контекст, их содержащий. Там описано, что с этим делать.

Но почему типы врут?

nin-jin commented 3 weeks ago

Где врут?

DarkGL commented 3 weeks ago

Great to hear that you are aware of the problem, reopened, and hopefully we can get it landed

kravetsone commented 3 weeks ago

Great to hear that you are aware of the problem, reopened, and hopefully we can get it landed

this example works fine (based on https://github.com/hyoo-ru/mam_mol/issues/692#issuecomment-2283249762)

import $ from "mol_data_all";
const {
    $mol_data_email,
    $mol_data_integer,
    $mol_data_optional,
    $mol_data_pipe,
    $mol_data_record,
    $mol_data_string,
    $mol_data_variant,
} = $;

console.log($);

const PersonDTO = $mol_data_record({
    name: $mol_data_string,
    age: $mol_data_optional($mol_data_integer),
    birthday: $mol_data_pipe($mol_data_string),
});

// Derived Type
const UserDTO = $mol_data_record({
    ...PersonDTO.config,
    phone: $mol_data_variant($mol_data_string, $mol_data_integer),
    mail: $mol_data_email,
});

// Ensure this is a User
const jin = UserDTO({
    name: "Jin",
    age: 33,
    birthday: "1984-08-04T12:00:00Z",
    phone: 791234567890,
    mail: "foo@example.org",
});

console.log(jin);
DarkGL commented 3 weeks ago

I think it's ready for review :)

@moltar

moltar commented 3 weeks ago

@DarkGL Massive work! ❤️

@hoeck lots of graphing changes on this one; please see if you have any opinions

DarkGL commented 2 weeks ago

@hoeck just a friendly reminder

I want to start working on integrating deno after merging this :)

kravetsone commented 2 weeks ago

@hoeck just a friendly reminder

I want to start working on integrating deno after merging this :)

I guess it will be harder... But why not

hoeck commented 2 weeks ago

@hoeck just a friendly reminder

I want to start working on integrating deno after merging this :)

Sry for the delay, looking at it now ...

DarkGL commented 2 weeks ago

Thanks ! I will fix those typos in next pr, and maybe figure out more general way rather than just copying 😅

DarkGL commented 2 weeks ago

It looks like I have broken selecting default version for Node @hoeck @moltar

kravetsone commented 2 weeks ago

@hoeck just a friendly reminder

I want to start working on integrating deno after merging this :)

Great work!

hoeck commented 2 weeks ago

It looks like I have broken selecting default version for Node @hoeck @moltar

You're right, I've created an issue for that: #3111 (and thanks for testing your changes :grin:)

The init code is using nodeVersion as a key to set the initial selected one. In the new file format this is now runtime and runtimeVersion: https://github.com/moltar/typescript-runtime-type-benchmarks/blob/master/docs/app.tsx#L480

That wasn't caught by Typescript as the fetch response is not properly typed and/or runtime type checked (all while this repo is about runtype type checking :laughing: )

Can you fix it? If you don't have the time or need help, please let me know.

hoeck commented 2 weeks ago

Thanks ! I will fix those typos in next pr, and maybe figure out more general way rather than just copying 😅

nah that sort/order/groupby code was not good to begin with so copying is totally fine :smile: .

I've played around with a client-side PostgresSQL database (electric-sql/pglite) lately. Maybe (just maybe) we could load all results into an sqlite db and then use that for querying / grouping / sorting instead of hand-rolling everything in JS.