@dropsh/plugin-jsonapi-schema 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DropSHPlugin } from "dropsh/plugin";
|
|
2
|
+
/**
|
|
3
|
+
* Authoritative JSON:API write-schema source backed by the Drupal
|
|
4
|
+
* `jsonapi_schema` module (works on Drupal 10.1+/11 + PHP 8.4, unlike the
|
|
5
|
+
* dead `schemata_json_schema` endpoint which 500s there).
|
|
6
|
+
*
|
|
7
|
+
* Outcomes are distinguished instead of collapsed into one silent fallback:
|
|
8
|
+
* - 200 → the derived write schema replaces the heuristic base.
|
|
9
|
+
* - 404 → the module/route is absent; fall back to the heuristic base **and**
|
|
10
|
+
* warn why (so the user knows the constraint-bearing schema is missing).
|
|
11
|
+
* - any other status / unparseable body → the endpoint is broken; fall back to
|
|
12
|
+
* the heuristic base **and** warn visibly. Never swallowed silently.
|
|
13
|
+
*/
|
|
14
|
+
export declare function jsonapiSchemaPlugin(): DropSHPlugin;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AuthAdapter, HttpClient } from "dropsh/plugin";
|
|
2
|
+
/** Sentinel returned when the jsonapi_schema route is absent (HTTP 404). */
|
|
3
|
+
export declare const JSONAPI_SCHEMA_MISS: unique symbol;
|
|
4
|
+
export interface FetchJsonapiSchemaDeps {
|
|
5
|
+
http: HttpClient;
|
|
6
|
+
auth: AuthAdapter;
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
jsonapiPrefix: string;
|
|
9
|
+
entity: string;
|
|
10
|
+
bundle: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetch the resource-object schema for a bundle from the jsonapi_schema module.
|
|
14
|
+
*
|
|
15
|
+
* Route (dynamic, registered by jsonapi_schema): the resource-object schema
|
|
16
|
+
* lives at `{jsonapiPrefix}/{entity}/{bundle}/resource/schema`. It describes a
|
|
17
|
+
* single JSON:API resource object (type + attributes + relationships), which is
|
|
18
|
+
* exactly what a create/update payload's `data` member must satisfy.
|
|
19
|
+
*
|
|
20
|
+
* Returns the parsed schema on 200, {@link JSONAPI_SCHEMA_MISS} on 404 (module
|
|
21
|
+
* or route absent), and throws on any other HTTP status (a broken endpoint must
|
|
22
|
+
* be surfaced, never silently swallowed) or an unparseable body.
|
|
23
|
+
*/
|
|
24
|
+
export declare function fetchJsonapiSchema(deps: FetchJsonapiSchemaDeps): Promise<unknown | typeof JSONAPI_SCHEMA_MISS>;
|
|
25
|
+
/**
|
|
26
|
+
* Transform a jsonapi_schema resource-object schema into a JSON Schema that
|
|
27
|
+
* validates a dropsh create/update payload — a JSON:API document envelope
|
|
28
|
+
* `{ data: { type, id, attributes, relationships } }`.
|
|
29
|
+
*
|
|
30
|
+
* The module emits `{ allOf: [ { properties: { type, attributes, relationships }
|
|
31
|
+
* (local $refs) }, { $ref: "https://jsonapi.org/schema#/definitions/resource" } ],
|
|
32
|
+
* definitions: {...} }`. We inline the local definitions, drop the external
|
|
33
|
+
* jsonapi.org `$ref` (Ajv cannot fetch it), and wrap the resource object as the
|
|
34
|
+
* `data` member. dropsh's `toOperationVariant` later tailors `required` per
|
|
35
|
+
* operation, so we only assert the resource `type` here.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildWriteSchema(resourceSchema: unknown): unknown;
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dropsh/plugin-jsonapi-schema",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/plugins/jsonapi-schema/src/index.js",
|
|
6
|
+
"types": "./dist/plugins/jsonapi-schema/src/index.d.ts",
|
|
6
7
|
"exports": {
|
|
7
|
-
".":
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/plugins/jsonapi-schema/src/index.d.ts",
|
|
10
|
+
"default": "./dist/plugins/jsonapi-schema/src/index.js"
|
|
11
|
+
}
|
|
8
12
|
},
|
|
9
13
|
"files": [
|
|
10
14
|
"dist/plugins/jsonapi-schema/src",
|
|
@@ -19,7 +23,7 @@
|
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"typescript": "^5.6.0",
|
|
21
25
|
"vitest": "^4.1.8",
|
|
22
|
-
"dropsh": "0.5.
|
|
26
|
+
"dropsh": "0.5.6"
|
|
23
27
|
},
|
|
24
28
|
"scripts": {
|
|
25
29
|
"build": "tsc",
|