@dropsh/plugin-schemata 0.0.2
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.
- package/LICENSE +51 -0
- package/README.md +47 -0
- package/dist/plugins/schemata/src/index.js +28 -0
- package/dist/plugins/schemata/src/schemata.js +21 -0
- package/package.json +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
drupal-cli is dual-licensed. You may use this software under the terms of
|
|
2
|
+
either the MIT License or the GNU General Public License version 2 or any
|
|
3
|
+
later version, at your option.
|
|
4
|
+
|
|
5
|
+
SPDX-License-Identifier: (MIT OR GPL-2.0-or-later)
|
|
6
|
+
|
|
7
|
+
================================================================================
|
|
8
|
+
MIT License
|
|
9
|
+
================================================================================
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2026 Christian Wiedemann
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
in the Software without restriction, including without limitation the rights
|
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
furnished to do so, subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
SOFTWARE.
|
|
30
|
+
|
|
31
|
+
================================================================================
|
|
32
|
+
GNU General Public License, version 2 or later
|
|
33
|
+
================================================================================
|
|
34
|
+
|
|
35
|
+
The full text of the GNU GPL v2 is available at:
|
|
36
|
+
https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
|
|
37
|
+
|
|
38
|
+
The full text of any later GPL version is available at:
|
|
39
|
+
https://www.gnu.org/licenses/
|
|
40
|
+
|
|
41
|
+
Copyright (C) 2026 Christian Wiedemann
|
|
42
|
+
|
|
43
|
+
This program is free software; you can redistribute it and/or modify it under
|
|
44
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
45
|
+
Foundation; either version 2 of the License, or (at your option) any later
|
|
46
|
+
version.
|
|
47
|
+
|
|
48
|
+
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
49
|
+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
50
|
+
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
51
|
+
details.
|
package/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# @dropsh/plugin-schemata
|
|
2
|
+
|
|
3
|
+
Authoritative JSON Schema source for [dropsh](https://github.com/pen-drop/dropsh),
|
|
4
|
+
the entity-agnostic CLI for Drupal 11 JSON:API.
|
|
5
|
+
|
|
6
|
+
By default dropsh derives a shallow schema from sample records (field names only,
|
|
7
|
+
no required fields or constraints). With this plugin installed, `dropsh schema`
|
|
8
|
+
instead returns the **authoritative** schema from Drupal's `schemata` module —
|
|
9
|
+
with required fields and constraints — so client-side validation in `create` /
|
|
10
|
+
`update` is meaningful.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @dropsh/plugin-schemata
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`dropsh` is a peer dependency.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import { schemataPlugin } from "@dropsh/plugin-schemata";
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
site: { base_url: "https://my-drupal.example.com", jsonapi_prefix: "/jsonapi" },
|
|
27
|
+
plugins: [schemataPlugin()],
|
|
28
|
+
};
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
dropsh schema node/article --for=create
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The output carries `x-dropsh-source: "schemata"` when the authoritative schema was
|
|
36
|
+
used (vs `"heuristic"` / `"heuristic-empty"` for the sample-derived fallback). If
|
|
37
|
+
the modules are missing or the endpoint is unreachable, the plugin transparently
|
|
38
|
+
falls back to the base schema.
|
|
39
|
+
|
|
40
|
+
## Required Drupal modules
|
|
41
|
+
|
|
42
|
+
- [`schemata`](https://www.drupal.org/project/schemata)
|
|
43
|
+
- `jsonapi_schema` (provided by the schemata project)
|
|
44
|
+
|
|
45
|
+
## License
|
|
46
|
+
|
|
47
|
+
MIT OR GPL-2.0-or-later
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { HttpError } from "dropsh/plugin";
|
|
2
|
+
import { fetchSchemata, SCHEMATA_MISS } from "./schemata.js";
|
|
3
|
+
export function schemataPlugin() {
|
|
4
|
+
return {
|
|
5
|
+
id: "schemata",
|
|
6
|
+
requiredModules: ["schemata", "jsonapi_schema"],
|
|
7
|
+
async extendSchema(entityType, bundle, baseSchema, ctx) {
|
|
8
|
+
let result;
|
|
9
|
+
try {
|
|
10
|
+
result = await fetchSchemata({
|
|
11
|
+
http: ctx.http,
|
|
12
|
+
auth: ctx.auth,
|
|
13
|
+
baseUrl: ctx.baseUrl,
|
|
14
|
+
entity: entityType,
|
|
15
|
+
bundle,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (err instanceof HttpError)
|
|
20
|
+
return baseSchema;
|
|
21
|
+
throw err;
|
|
22
|
+
}
|
|
23
|
+
if (result === SCHEMATA_MISS)
|
|
24
|
+
return baseSchema;
|
|
25
|
+
return result;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { HttpError } from "dropsh/plugin";
|
|
2
|
+
export const SCHEMATA_MISS = Symbol("SCHEMATA_MISS");
|
|
3
|
+
export async function fetchSchemata(deps) {
|
|
4
|
+
const base = deps.baseUrl.replace(/\/+$/, "");
|
|
5
|
+
const url = `${base}/schemata/${deps.entity}/${deps.bundle}?_format=schema_json&_describes=api_json`;
|
|
6
|
+
const req = await deps.auth.apply({
|
|
7
|
+
method: "GET",
|
|
8
|
+
url,
|
|
9
|
+
headers: { Accept: "application/json" },
|
|
10
|
+
});
|
|
11
|
+
let res;
|
|
12
|
+
try {
|
|
13
|
+
res = await deps.http.send(req);
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
if (err instanceof HttpError && err.status === 404)
|
|
17
|
+
return SCHEMATA_MISS;
|
|
18
|
+
throw err;
|
|
19
|
+
}
|
|
20
|
+
return JSON.parse(res.body);
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dropsh/plugin-schemata",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/plugins/schemata/src/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./dist/plugins/schemata/src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/plugins/schemata/src",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"access": "public"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"dropsh": "*"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.6.0",
|
|
21
|
+
"vitest": "^4.1.8",
|
|
22
|
+
"dropsh": "0.0.2"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsc",
|
|
26
|
+
"test": "vitest run --passWithNoTests",
|
|
27
|
+
"typecheck": "tsc --noEmit"
|
|
28
|
+
}
|
|
29
|
+
}
|