wunderwerkio / drupal-kit Goto Github PK
View Code? Open in Web Editor NEWModern, modular and composable Drupal SDK for Node.js, Edge and Browser with an extensive plugin system and first-class TypeScript support.
Modern, modular and composable Drupal SDK for Node.js, Edge and Browser with an extensive plugin system and first-class TypeScript support.
Implement built-in pagination support for JSON:API requests.
See here: https://www.drupal.org/docs/core-modules-and-themes/core-modules/jsonapi-module/pagination
The implementation should also feature a convenient way to do pagination with resources that may be omitted from the result array because of insufficient permissions.
The Drupal docs describe this issue rather well.
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__"
}
}
}
An option to set default HTTP headers for each request should be added to drupalkit core.
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.
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.
Type results from the request
method which returns a Result
type is hard to read and sometimes just wrong.
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.
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:
fetch
supportfetch
(e.g. node-fetch
) can be manually supplied in the options.Add support for the /user-api/resend-mail
endpoint of the drupal user-api
module.
It should be possible to properly unset existing auth data in drupalkit core. Not just by setting auth to an empty string.
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)
version.ts
file that exports a constant with the current version.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.
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.
Test files should also be included when running the typecheck
command.
tsconfig.json
to typecheck test files with custom configuration (e.g. skipLibCheck
)typecheck
command to utilize pnpm run
to run the two typecheck commands in parallelSome 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
.
To follow TypeScript best practices, the names of generics should either be T
or start with T
.
See here: https://www.totaltypescript.com/tips/how-to-name-your-types
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
Currently, there are some minor problems / inconveniences with the jsonapi resource types:
create
payload always expects the full JSON:API resource, which must not be the case (e.g. data generated on the server)create
payload also expects a required type
property, which is redundant, because the type is known at the time of the API request.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.JsonApiResources
interface at all. This can lead to potential errors and user confusion.Those things should be improved to increase DX.
Support NextJS specific options for the fetch
call regarding caching.
NextJS documentation: https://nextjs.org/docs/app/building-your-application/data-fetching/fetching#static-data-fetching
Write a script to generate Release notes for GitHub Releases automatically.
The create and update payloads are missing the type
and id
parameters, if not supplied in the initial payload.
This data must be set, otherwise Drupal returns an error in the request.
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.
Currently the contents for the npm packages are not optimal.
Include only the following files:
./dist
README.md
CHANGELOG.md
LICENSE
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.