Skip to content

Streamline resource creation api #798

Closed
@Polleps

Description

@Polleps
Member

Creating new resources with @tomic/lib is currently very unintuitive, to create a resource you need to "fetch" or "get" a resource but tell the store it is new. It also doesn't set any properties so you can't directly save it.

We should have a separate function to create new resources e.g. store.newResource(). Ideally this also takes a class(es) and parent because you have to set those on all resources anyway.

Something like

const resource = store.newResource('https://my-folder', dataBrowser.classes.folder, 'https://my-parent');

Alternatively we could add an overload to the Resource constructor e.g.

const resource = new Resource('https://my-folder', dataBrowser.classes.folder, 'https://my-parent');

Maybe we can add a way to quickly set additional properties too

Activity

joepio

joepio commented on Jan 10, 2024

@joepio
Member

Some additional thoughts:

  • The parent is always required
  • A class is not required, but often useful
  • A subject could be generated, so it could be an optional argument.
Polleps

Polleps commented on Jan 10, 2024

@Polleps
MemberAuthor

I just realised we need store to set the parent and a class so going the store.newResource() route makes more sense

joepio

joepio commented on Jan 10, 2024

@joepio
Member

That way even the parent becomes optional - we could default to the serverURL.

added 2 commits that reference this issue on Jan 15, 2024

#798 Streamline Resource Creation API

#798 Changed docs to use store.newResource

added a commit that references this issue on Jan 15, 2024

#798 Streamline Resource Creation API

added a commit that references this issue on Jan 15, 2024

#798 Changed docs to use store.newResource

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @joepio@Polleps

    Issue actions

      Streamline resource creation api · Issue #798 · atomicdata-dev/atomic-server