profile
viewpoint

calebmer/accelerate 6

Accelerate back and forth through time for your database or other in-place systems

calebmer/ardite 5

A fully JSON and immutable database

calebmer/decode-universe 4

The universe of all digital assets used in building, maintaining, and distributing Decode products.

calebmer/express-graphql 1

Create a GraphQL HTTP server with Express.

calebmer/apollo-client 0

:rocket: A fully-featured caching GraphQL client for any server or UI framework

calebmer/babel 0

:tropical_fish: Babel is a compiler for writing next generation JavaScript.

calebmer/babel-preset-modern-node 0

Babel preset for modern node apps

issue closedcalebmer/graphql-resolve-batch

Case when batch results length is (correctly) less than source length

Hi 👋, I'm new to GraphQL and ended up here after trying to optimize how the resolver fetches embedded documents (I'm using mongodb+mongoose).

Currently I have the following schema:

type Query {
        workEntries: [WorkEntry]
        ...
}

type WorkEntry {
        _id: ID!,
        task: Task!,
        ...
}

type Task {
        _id: ID!,
        project: Project!,
        ...
}

type Project {
        name: String!
        ...
}

There're 1000+ WorkEntry records, and each linked to a Task, which in turns is linked to a Project.

Now, I'm trying to batch the resolution of tasks since I'd like to avoid one mongodb query per WorkEntry to fetch the Task and then another query to fetch the Project.

I tried adding a resolver for WorkEntry as follows:

WorkEntry: {
		task: createBatchResolver( workEntries =>
			Task.find( { 
				_id: { 
					$in: workEntries.map( ( { task } ) => task ) 
				} 
			} ).exec()
		)
	},

But this is throwing an error saying it must return the same number of values. Now, this would be correct in my case since I have an "N to 1" relationship (multiple WorkEntry documents may be linked to the same task).

Is there any workaround for this? I'm I completely misunderstanding the purpose of this module?

Thanks!

closed time in 3 days

nicolasalliaume

issue commentcalebmer/graphql-resolve-batch

Case when batch results length is (correctly) less than source length

This is actually the correct behavior! You have a list of inputs that look like ['a', 'b', 'c', 'b'] and GraphQL expects to resolve objects in that order. So what you need to do is:

createBatchResolver(async workEntries => {
  const tasks = await Task.find(...).exec();
  const taskById = new Map(tasks.map(task => [task._id, task]));
  return workEntries.map(workEntry => taskById.get(workEntry.task));
})
nicolasalliaume

comment created time in 3 days

push eventcalebmer/dom-testing-library

Caleb Meredith

commit sha 4b41f2f39167171791086d43c00c8a89c7e75491

Update events.js

view details

push time in 6 days

PR opened testing-library/dom-testing-library

Support `clipboardData` like `dataTransfer`.

To support the paste event you need the clipboardData key (which jsdom ignores). This commit extends how DOM testing library supports dataTransfer for the drop event to clipboardData.

This allows us to write tests for pasting.

Checklist:

  • [ ] Documentation added to the docs site (n/a)
  • [ ] I've prepared a PR for types targeting DefinitelyTyped (n/a)
  • [ ] Tests (let’s see what CI says)
  • [x] Ready to be merged
+18 -14

0 comment

1 changed file

pr created time in 6 days

push eventcalebmer/dom-testing-library

Caleb Meredith

commit sha d73ddeb90edcd509cd7c0c9e7ffee97b375b06bc

Support `clipboardData` like `dataTransfer`.

view details

push time in 6 days

fork calebmer/dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.

https://testing-library.com

fork in 6 days

push eventcalebmer/calebmer.github.io

Caleb Meredith

commit sha e94cb273f66c0448bb88e2b8d9e4c6cf063b0287

Update CNAME

view details

push time in 7 days

PR opened jsdom/jsdom

Prevent infinite loop when mutation observer calls observe within the callback

Disclaimer: I haven’t carefully thought this change through. Probably consider this more like an issue with the change that fixed the issue for me.

While using jsdom I ran into a test that wouldn’t terminate. After debugging I discovered some code that fired in a mutation observer which was effectively:

observer.disconnect();
// Do some stuff...
observer.observe();

Since this happens during notifyMutationObservers() the new observer.observe() call added to the _nodeList which caused the for-loop to then execute on the new node, however that called the callback which added to _nodeList and so on forever.

+5 -1

0 comment

1 changed file

pr created time in 14 days

push eventcalebmer/jsdom

Caleb Meredith

commit sha 839b261c7ee2ad1a216bd0290ec1b629085161ea

Prevent infinite loop when mutation observer calls observe within the callback

view details

push time in 14 days

issue openedfacebook/create-react-app

Tests don’t support `.cjs` files

I have a dependency that uses w3c-keyname the main file of which uses the .cjs file extension (https://unpkg.com/w3c-keyname@2.2.4/index.cjs). In tests this file is imported as the file name probably tripping create-react-app’s “textual file” support. It’s fine when bundling because the package has a .js ES module file.

Node.js now supports loading files with a .cjs extension as a part of its native ES Module support: https://nodejs.org/api/esm.html

created time in 14 days

push eventcalebmer/calebmer.github.io

Caleb Meredith

commit sha 56a7d4768dea03def772390f3b74714db8b87e9c

Update CNAME

view details

push time in 20 days

issue openedrust-lang/rls

Integrating RLS with Bazel and VSCode

What’s the current recommendation for RLS support in projects that use Bazel and VSCode?

created time in a month

issue commentjesseweed/seti-ui

Use .ts icon for .tsx files

referred here from https://github.com/microsoft/vscode/issues/93347

calebmer

comment created time in 2 months

issue commentmicrosoft/vscode

Change icon for .tsx file to .ts

will do :+1:

https://github.com/jesseweed/seti-ui/issues/557

calebmer

comment created time in 2 months

issue openedjesseweed/seti-ui

Use .ts icon for .tsx files

At Airtable we use the .tsx extension for all of our files. Including all our backend files. Having the React icon for all of these files is a little bit jarring. Could we change the .tsx icon extension to be identical to the .ts icon? Or at least make it configurable.

The way we think about it is .tsx is version 2 of the TypeScript dialect so we should just use it everywhere instead of supporting multiple dialects of TypeScript.

created time in 2 months

issue commentmicrosoft/vscode

Change icon for .tsx file to .ts

Confirmed that this does break JSX syntax highlighting. @JacksonKearl could you reopen?

calebmer

comment created time in 2 months

issue commentmicrosoft/vscode

Change icon for .tsx file to .ts

@JacksonKearl will that break syntax highlighting for JSX?

calebmer

comment created time in 2 months

issue commentbazelbuild/rules_nodejs

ts_library compiles tsx files to js not jsx

at Airtable we use the convention that all TypeScript files have the .tsx extension

we think of it as TypeScript syntax v2 so instead of supporting three dialects (JS, TS, TSX) we choose to only support two

calebmer

comment created time in 2 months

issue openedbazelbuild/rules_nodejs

ts_library compiles tsx files to js not jsx

On first glance this appears to be incorrect because ts_library compiles .tsx files to .js and not .jsx. Am I missing something or could we change this?

https://github.com/bazelbuild/rules_nodejs/blob/04204df8848faf9024d8200bff32e8f0db82003c/internal/node/node.bzl#L120-L121

created time in 2 months

pull request commentarchshift/dynstack

Implement Iterator::size_hint and ExactSizeIterator

Thank you! ❤️

faern

comment created time in 2 months

issue openedmicrosoft/vscode

Change icon for .tsx file to .ts

At Airtable we use the .tsx extension for all of our files. Including all our backend files. Having the React icon for all of these files is a little bit jarring. Could we change the .tsx icon extension to be identical to the .ts icon? Or at least make it configurable.

The way we think about it is .tsx is version 2 of the TypeScript dialect so we should just use it everywhere instead of supporting multiple dialects of TypeScript.

created time in 2 months

issue openedbazelbuild/vscode-bazel

Disable code lens

I find the code lens really annoying since while editing a BUILD file the code lens goes away and only reappears when I hit save moving everything around. A lot of my BUILD file calls are also macros that generate multiple rules so the code lens isn’t very useful anyway.

Could an option be added to disable the code lens?

created time in 2 months

issue commentrust-lang/rust

Rust compiler panic in librustc/traits/codegen

I’m able to get this code working by changing map to:

pub fn map<X, F, T, U>(self, mut mapper: F) -> impl Stream<Item = Result<U, Error>>
where
    X: Table,
    S: for<'a> Selection<'a, X, Data = T>,
    F: FnMut(T) -> U,
{
    let RowStream { selection, stream } = self;
    stream.map(move |row| {
        let row = row.map_err(log::convert_error!("failed to execute sql query"))?;
        let row = Arc::new(row);
        let data = selection.dangerously_select_from_row(&row);
        let data = mapper(data);
        Ok::<_, Error>(data)
    })
}
calebmer

comment created time in 2 months

issue commentrust-lang/rust

Rust compiler panic

This code is probably relevant. It’s doing some admittedly weird things:

/// A stream of PostgreSQL rows that were selected with some properly
/// typed `Selection`.
///
/// Doesn’t actually implement `Stream` because we need to make sure the
/// lifetimes are correct.
pub struct RowStream<S> {
    selection: S,
    stream: postgresql::RowStream,
}

impl<S> RowStream<S> {
    /// Maps the typed borrowed row data into whatever format you want to use.
    /// We don’t implement `Stream` since it’s important that we get the
    /// lifetimes right.
    #[inline]
    pub fn map<X, F, T>(self, mut mapper: F) -> impl Stream<Item = Result<T, Error>>
    where
        X: Table,
        S: for<'a> Selection<'a, X>,
        F: for<'a> FnMut(<S as Selection<'a, X>>::Data) -> T,
    {
        let RowStream { selection, stream } = self;
        stream.map(move |row| {
            let row = row.map_err(log::convert_error!("failed to execute sql query"))?;
            let row = Arc::new(row);
            let data = selection.dangerously_select_from_row(&row);
            let data = mapper(data);
            Ok::<_, Error>(data)
        })
    }

    /// Map all the items and then collect them into a `Vec`. Same as
    /// `stream.map().try_collect::<Vec<_>>()`.
    #[inline]
    pub async fn map_collect<X, F, T>(self, mut mapper: F) -> Result<Vec<T>, Error>
    where
        X: Table,
        S: for<'a> Selection<'a, X>,
        F: for<'a> FnMut(<S as Selection<'a, X>>::Data) -> T,
    {
        self.map(mapper).try_collect().await
    }

    /// Collects all the rows into a `Vec` as long as the data does not
    /// contain references.
    #[inline]
    pub async fn collect<'a, X, T>(self) -> Result<Vec<T>, Error>
    where
        X: Table,
        S: for<'b> Selection<'b, X, Data = T>,
        T: 'static,
    {
        self.map_collect(|row| row).await
    }
}
calebmer

comment created time in 2 months

issue commentrust-lang/rust

Rust compiler panic

Expanding the error message:

OutputTypeParameterMismatch(
  Binder(
    <[closure@server/model/core/select.rs:357:26: 357:35] as std::ops::FnMut<(
      <column::Column<select_tests::test::Table, types::I32Type> as selection::Selection<'_, select_tests::test::Table>>::Data,
    )>>
  ),
  Binder(
    <[closure@server/model/core/select.rs:357:26: 357:35] as std::ops::FnMut<(
      i32,
    )>>
  ),
  Sorts(
    ExpectedFound {
      expected: i32,
      found: <column::Column<select_tests::test::Table, types::I32Type> as selection::Selection<'_, select_tests::test::Table>>::Data
    }
  )
)

…and zooming in on:

      expected: i32,
      found: <column::Column<select_tests::test::Table, types::I32Type> as selection::Selection<'_, select_tests::test::Table>>::Data

…the type found: <column::Column<select_tests::test::Table, types::I32Type> as selection::Selection<'_, select_tests::test::Table>>::Data should resolve to i32.

calebmer

comment created time in 2 months

issue commentrust-lang/rust

Rust compiler panic

A little bit more information, if I take this code:

#[harness::test]
async fn select_equals() -> Result<(), Box<dyn Error>> {
    let client = connect().await?;

    assert_eq!(
        test::select()
            .where_eq(test::bar(), 32)
            .with(test::bar())
            .execute(&client)
            .await?
            .collect()
            .await?,
        vec![32]
    );

    Ok(())
}

…and remove #[harness::test] it compiles without error. Here’s the implementation of my harness macro:

https://gist.github.com/calebmer/752055b54d3573435048a41c6fd609e8

calebmer

comment created time in 2 months

issue openedrust-lang/rust

Rust compiler panic

The Rust compiler panicked with the following message. I’m not planning on taking the time to create a minimal repro, so you can immediately close if you’d like. Don’t know how useful just sharing a panic. message is.

error: internal compiler error: src/librustc/traits/codegen/mod.rs:57: Encountered error `OutputTypeParameterMismatch(Binder(<[closure@server/universe/schema/types/workspace.rs:66:30: 66:55] as std::ops::FnMut<(<graphql_prepare::prepare::PreparedSelection<model_district_raw::account::Table> as model_core::selection::Selection<'_, model_district_raw::account::Table>>::Data,)>>), Binder(<[closure@server/universe/schema/types/workspace.rs:66:30: 66:55] as std::ops::FnMut<(graphql_prepare::prepare::PreparedData<model_district_raw::account::Table>,)>>), Sorts(ExpectedFound { expected: graphql_prepare::prepare::PreparedData<model_district_raw::account::Table>, found: <graphql_prepare::prepare::PreparedSelection<model_district_raw::account::Table> as model_core::selection::Selection<'_, model_district_raw::account::Table>>::Data }))` selecting `Binder(<[closure@server/universe/schema/types/workspace.rs:66:30: 66:55] as std::ops::FnMut<(graphql_prepare::prepare::PreparedData<model_district_raw::account::Table>,)>>)` during codegen

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:873:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.42.0 (b8cedc004 2020-03-09) running on x86_64-apple-darwin

created time in 2 months

issue commentarchshift/dynstack

Is DynStack Send + Sync?

Oh, it looks like the code in this repo is Send/Sync but the version released to Cargo is not. Could you publish a new version?

https://github.com/archshift/dynstack/blob/f4475bad4abd9ff8fdccc9d929d6f969b427dfde/src/lib.rs#L103-L104

calebmer

comment created time in 2 months

issue openedarchshift/dynstack

Implement ExactSizeIterator and size_hint for DynStackIter

I use DynStack with some code that expects an ExactSizeIterator. I’ve added a wrapper in my codebase to implement that trait, but it would be cool if an ExactSizeIterator implementation were upstreamed.

struct DynStackIter<'a, T: 'a + ?Sized> {
    len: usize,
    n: usize,
    iter: dynstack::DynStackIter<'a, T>,
}

impl<'a, T: 'a + ?Sized> DynStackIter<'a, T> {
    #[inline]
    fn new(dynstack: &'a DynStack<T>) -> Self {
        DynStackIter {
            len: dynstack.len(),
            n: 0,
            iter: dynstack.iter(),
        }
    }
}

impl<'a, T: 'a + ?Sized> Iterator for DynStackIter<'a, T> {
    type Item = &'a T;

    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        let item = self.iter.next();
        if item.is_some() {
            self.n += 1;
        }
        item
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        (self.len - self.n, Some(self.len - self.n))
    }
}

impl<'a, T: 'a + ?Sized> ExactSizeIterator for DynStackIter<'a, T> {
    #[inline]
    fn len(&self) -> usize {
        self.len - self.n
    }
}

created time in 2 months

issue openedarchshift/dynstack

Is DynStack Send?

DynStack does not auto-implement Send because it has a *mut u8 pointer. I’m like 80% sure it is Send after quickly perusing the code and have added a wrapper in my codebase that unsafely implements Send.

Is it safe to implement Send for DynStack?

created time in 2 months

more