Giter VIP home page Giter VIP logo

drupal-kit's People

Contributors

chfoidl avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

drupal-kit's Issues

JSON:API wrong types for create / update payload relationships

Currently, the type for the relationships in the payloads for create and update actions is incorrect.

According to the JSON:API specification, the format of relationships in the create (https://jsonapi.org/format/#crud-creating) and update (https://jsonapi.org/format/#crud-updating-resource-relationships) payloads must be resource linkages.

Therefore the payload must adhere to the following format:

relationships: {
  my_field: {
    data: {
      type: "entity--bundle",
      id: "__id__"
    }
  }  
}

Catch drupal server errors

Drupalkit may expose critical server-related information when the Drupal installation is misconfigured and a stack trace is being returned in the error message.

For good practice, those errors should be intercepted by drupalkit and a generic error message should be returned instead.

JSON:API - Create and update payload wrong format

The payload format for create and update operations on JSON:API resources has the wrong format.

The payload must be an object that contains the resource in the data property.
Currently the resource is passed directly.

Fix types from ts-results

Type results from the request method which returns a Result type is hard to read and sometimes just wrong.

Add tests for type definition

Drupal-kit relies heavily on the TypeScript type system to provide a good DX.

Parts of drupal-kit that rely on declaration merging (e.g. jsonapi resources) should be tested explicitly.

Edge compat / Node 18 fetch

To be able to use drupal-kit on the Edge, we need to drop support for the built-in node-fetch package.

Several reasons support this decision:

  • Node 18 has native fetch support
  • Node 18 is LTS
  • A polyfilled fetch (e.g. node-fetch) can be manually supplied in the options.

Add ability to unset auth

It should be possible to properly unset existing auth data in drupalkit core. Not just by setting auth to an empty string.

Fix version in user agent

Currently the user agent used by drupal-kit is hardcoded to drupalkit/0.0.0-development.

The user agent should be in the following format:

drupal-kit/0.1.3 (as an example)

Tasks

  • Add version.ts file that exports a constant with the current version.
  • Automatically update version constant on version update but before publish.

Fix relationship type for `DeriveSimpleJsonApiResourceObject`

When defining a JsonApiResource type that can have different resource types for one given relationship, the resulting type when using drupalkit.jsonApi.simplifyResourceResponse() is not a discriminated union.

This is bad because switch/case statements would not narrow the type of the related resource.

Support menu items in JSON:API

Drupal 10.1 added native support for /jsonapi/menu_items/{menu} endpoint.

This endpoint gets all menu items associated with the given menu, but it is different than the standard resource endpoint.

Expand typecheck to include test files

Test files should also be included when running the typecheck command.

Tasks

  • Add separate tsconfig.json to typecheck test files with custom configuration (e.g. skipLibCheck)
  • Add separate typecheck commands for source and test files
  • Modify typecheck command to utilize pnpm run to run the two typecheck commands in parallel

Add types for specific drupalkit errors for matching methods

Some modules implement a more specific DrupalkitError like the DrupalkitJsonApiError.

Through hooks the DrupalkitJsonApiError is created from standard DrupalkitError for all JSON:API routes.
This implies, that all methods of the jsonapi plugin return the specific error, TypeScript however has types for just the DrupalkitError.

Tasks

  • Change error types in method return type to the specific error where applicable

Dependency "qs" not compatible with edge runtime

Due to the dependency qs of the core module, drupal kit is not compatible with the edge runtime.

Failed to compile.

../../node_modules/.pnpm/[email protected]/node_modules/function-bind/implementation.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
Learn More: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/function-bind/implementation.js
../../node_modules/.pnpm/[email protected]/node_modules/function-bind/index.js
../../node_modules/.pnpm/[email protected]/node_modules/get-intrinsic/index.js
../../node_modules/.pnpm/[email protected]/node_modules/side-channel/index.js
../../node_modules/.pnpm/[email protected]/node_modules/qs/lib/stringify.js
../../node_modules/.pnpm/[email protected]/node_modules/qs/lib/index.js
../../node_modules/.pnpm/@[email protected]/node_modules/@drupal-kit/core/dist/index.mjs

Improve types for jsonapi plugin

Currently, there are some minor problems / inconveniences with the jsonapi resource types:

  • The type of the create payload always expects the full JSON:API resource, which must not be the case (e.g. data generated on the server)
  • The create payload also expects a required type property, which is redundant, because the type is known at the time of the API request.
  • The update payload also has the above problem and additionally requires the id in the payload, which is also known at the time of the API request.
  • TypeScript does not check the type of the augmented JsonApiResources interface at all. This can lead to potential errors and user confusion.

Those things should be improved to increase DX.

Transform JSON:API responses with Jsona

Working with entities that have lots of nested relations is tedious with the traditional JSON:API.

The remarkable Jsona deserializer solves this issue by embedding relationships, attributes, links and included entities all into a simple object.

Cleanup npm package contents

Currently the contents for the npm packages are not optimal.

Include only the following files:

  • ./dist
  • README.md
  • CHANGELOG.md
  • LICENSE

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.