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

Add functionset declaration #47

Open
minenwerfer opened this issue Nov 25, 2024 · 0 comments
Open

Add functionset declaration #47

minenwerfer opened this issue Nov 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@minenwerfer
Copy link
Contributor

minenwerfer commented Nov 25, 2024

What problem this addresses: The #1 problem with the language right now is the amount of code repetition when setting collection functions. If you have 15 collections with 5 functions each, and you add a new role to the access control, you'll have to manually change 15*5 = 75 lines.

This approach was inspired by SASS's mixin/include feature.

functionset Readable {
  get @expose
  getAll @expose
  count @expose
}

functionset Writable {
  insert @expose
  remove @expose
}

collection Person {
  properties {
    name str
  }
  functions {
    @include(Readable)
    @include(Writable)
    // @include(InvalidFunctionSet)
    //          ^ function set "InvalidFunctionSet" not found
  }
}

// same as
collection Person {
  properties {
    name str
  }
  functions {
    get @expose
    getAll @expose
    count @expose
    insert @expose
    remove @expose
  }
}

Both output:

export const person = defineCollection({
  // ....
  functions: {
    get,
    getAll,
    count,
    insert,
    remove,
  },
  exposedFunctions: {
    // ...
  },
})
@minenwerfer minenwerfer added the enhancement New feature or request label Nov 25, 2024
@minenwerfer minenwerfer added this to the First beta release milestone Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant