Code Monkey home page Code Monkey logo

alge's Introduction

Hey! ๐Ÿ‘‹

I am a developer passionate about system design, developer experience, static typing, and functional programming. Educated in design theory, practice, and social responsibility, I fell into programming through the portal of open source, Node.js, and GitHub. Over a decade later I find myself in love with TypeScript and working at Prisma, leading development on the Prisma Data Platform Control Plane. In my personal life, I sometimes work on open source projects, but closest to my heart are the backpacking trips I take my two boys on across the beautiful rugged Canadian wilderness! ๐Ÿ—ป๐Ÿ‡จ๐Ÿ‡ฆ

alge's People

Contributors

jasonkuhrt avatar jolg42 avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

rnproj jolg42

alge's Issues

Use zod validation

Perceived Problem

Input is not validated so at construction time an invalid email could be given etc.

Ideas / Proposed Solution(s)

Use zod schema parse function
Consider a way to opt out for performance sensitive reasons

Export types for TS inference

Screenshot

Getting this TS error in Molt Command:

src/ParameterSpec/validate.ts:6:14 - error TS2742: The inferred type of 'Result' cannot be named without a reference to '../../node_modules/alge/dist/esm/core/types.js'. This is likely not portable. A type annotation is necessary.

6 export const Result = Alge.data(`Result`, {
               ~~~~~~

src/ParameterSpec/validate.ts:6:14 - error TS2742: The inferred type of 'Result' cannot be named without a reference to '../../node_modules/alge/dist/esm/data/types/Controller.js'. This is likely not portable. A type annotation is necessary.

6 export const Result = Alge.data(`Result`, {
               ~~~~~~

src/ParameterSpec/validate.ts:6:14 - error TS2742: The inferred type of 'Result' cannot be named without a reference to '../../node_modules/alge/dist/esm/record/types/StoredRecord.js'. This is likely not portable. A type annotation is necessary.

6 export const Result = Alge.data(`Result`, {
               ~~~~~~


Found 3 errors in the same file, starting at: src/ParameterSpec/validate.ts:6

Description

Try fixing this by exporting types from Alge...

See if having another exported entrypoint of alge/types solves this for the consumer.

Repro Steps/Link

Passing a Zod object schema directly to shorthands

Perceived Problem

Currently you can do this:

const Square = Alge.data('shape', {
  Square: { ...  },
  Circle: { ... },
  Rectangle: { ... },
})

But not this:

const Rectangle = z.object({ ... })
const Square = z.object({ ... })
const Circle = z.object({ ... })

const Square = Alge.data('shape', {
  Square,
  Circle,
  Rectangle,
})

In other words we accept: Record<string, z.ZodType<unknown>> but not z.SomeZodObject. Not supporting this overload feels like a lost incremental opportunity.

Ideas / Proposed Solution(s)

Support it.

Document extensions

Perceived Problem

There is a concept of extensions, which is the ability in the builder to add custom api surface area to the controller.

We actually use this feature in our examples: https://github.com/jasonkuhrt/alge/blob/main/examples/Moniker.ts#L45-L62

This is not documented.

Ideas / Proposed Solution(s)

Document it in our features. This is probably a new category, either before or after codecs, but lower anyways, since it is perhaps more advanced.

Customize tag field "_tag"

Hey ๐Ÿ‘‹
Thanks for creating this awesome library.

Is it possible to change the name of the tag field for JSON codecs?
I want to use a different name for the field and not "_tag". It's not a hard blocker but just wanted to check if there is a configuration option that supports this.

Infer should include utility types

Perceived Problem

There are some utility types that sometimes need referencing:

  • Record constructor input
  • ...

Ideas / Proposed Solution(s)

  • Make them available from infer

Add support for CommonJS consumers

Perceived Problem

Alge currently can only be consumed by ESM packages/projects. This leaves out too many people in the community I feel.

Ideas / Proposed Solution(s)

I'm actually not sure what the mechanism to support both ESM and CJS is anymore. I am already fairly knowledgeable but hopefully there's just something simple I don't know yet. Anyways, more research to do.

Support zod defaults

Perceived Problem

Ideas / Proposed Solution(s)

  • When used we should honour that and not require the constructor to provide the input
  • Note this overlaps with the native defaults feature
  • Run zod defaults AFTER the native defaults system

Add JSDoc everywhere

Perceived Problem

We've got some basic docs in the readme but no thorough inline documentation.

Ideas / Proposed Solution(s)

Make JSDoc first class documentation and probably have a policy of it being the source of truth.

Reconsider API terminology

What

Terminology:

Code:

Alge.data(...).variant(...).schema(...)
Alge.datum(...).schema(...)

What we talk about:

  • "controller"
  • "builder"

Why

This is 6 terms :/. Can we make this simpler?

How

Words instead of data: adt, union, create, build, make, ...

I'd like to merge variant and datum because they are basically the same just in a different context, variant/datum: model, record, struct, ...

As for schema, it is the one that bothers me least but there are alternatives here too: shape, ...

Examples:

Alge.union(...).record(...).schema(...)
Alge.record(...).schema(...)

Alge.union(...).record(...).shape(...)
Alge.record(...).shape(...)

Alge.adt(...).model(...).schema(...)
Alge.model(...).schema(...)

Right now I think union + record + schema is a sweet spot:

  • union nudges toward formal and TS terminology
  • record nudges toward Haskell terminology (for product types), what Prisma generally refers for database rows (Postgres etc.)/documents (mongo etc.), and TS term for objects. Re TS I'm of two minds because actually in TS records are indexed types which are are a different beast and arguably make the term overlap more confusing, on the there hand its still objects/data and in that regard make the overlap helpful.
  • schema is a common term for what we are doing in Alge as well. It does get blurry in that sometimes schemas mean validation as well, but other times just types, which in turn is variable according to what the type system can represent. shape is cute and feels maybe a little less technical, but in this case I think it might add more confusion than not.

ADT-level update function

It can dispatch to member update functions based on tag. Of course the algorithm is the same for each so it doesn't even need to do that. It simply needs to adjust the types of the changes parameter.

Narrow matcher handler input based on data pattern

Perceived Problem

From #83 (comment)

Realized an advanced type refinement feature we could have. But save for a future issue.

const Shape = Alge.data('Shape')
  .record('Circle', { color: z.string().optional(), radius: z.number() })
  .record('Square', { color: z.string().optional(), size: z.number() })

/* ... */

const result = Alge.match(shape).Circle({ color: 'red' }, (data) => data)
//                                                         1
  1. The data that comes through should have color: 'red' instead of color?: string since the pattern match guarantees that.

Ideas / Proposed Solution(s)

Implement this.

Shorthand API

Perceived Problem

@Weakky pointed out that for simple cases the current API is verbose. I agree!

Ideas / Proposed Solution(s)

I sketched out some alternatives here: https://gist.github.com/jasonkuhrt/7ad238bcc13e853ff7456f624f794879

I think this could work:

//--------------------------------------------------------------------------------------
// Centralized

const Shape = Alge.union(`Shape`, {
  Rectangle: {
    width: Length,
    height: Length,
  },
  Circle: {
    radius: Length,
  },
  Square: {
    size: Length,
  },
})

//--------------------------------------------------------------------------------------
// Separated

const Rectangle = Alge.record(`Rectangle`, {
  width: Length,
  height: Length,
})

const Circle = Alge.record(`Circle`, {
  radius: Length,
})

const Square = Alge.record(`Square`, {
  size: Length,
})

const Shape = Alge.union(`Shape`, {
  Rectangle,
  Circle,
  Square,
})

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/actions/setup/action.yml
  • actions/setup-node v4
  • actions/cache v3
.github/workflows/pr.yml
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
  • actions/checkout v4
.github/workflows/release.yml
.github/workflows/trunk.yml
npm
package.json
  • lodash.ismatch ^4.4.0
  • remeda ^1.9.1
  • ts-toolbelt ^9.6.0
  • zod ^3.21.4
  • @prisma-labs/prettier-config 0.1.0
  • @swc/core 1.3.100
  • @swc/helpers 0.5.3
  • @tsconfig/node16-strictest 1.0.4
  • @types/lodash.ismatch 4.4.9
  • @types/node 20.10.3
  • @types/semver 7.5.6
  • @types/semver-utils 1.1.3
  • @typescript-eslint/eslint-plugin 6.13.2
  • @typescript-eslint/parser 6.13.2
  • dripip 0.10.0
  • eslint 8.55.0
  • eslint-config-prisma 0.2.0
  • eslint-plugin-codegen 0.21.0
  • eslint-plugin-deprecation 2.0.0
  • eslint-plugin-only-warn 1.1.0
  • eslint-plugin-prefer-arrow 1.2.3
  • eslint-plugin-simple-import-sort 10.0.0
  • eslint-plugin-tsdoc 0.2.17
  • execa 8.0.1
  • fast-glob 3.3.2
  • fs-jetpack 5.1.0
  • markdown-toc 1.2.0
  • prettier 3.1.0
  • semver 7.5.4
  • semver-utils 1.1.4
  • ts-node 10.9.1
  • tsd 0.29.0
  • typescript 5.3.3
  • vitest 0.34.6
  • pnpm 8.12.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.