@checkstack/common 0.9.0 → 0.10.0
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/CHANGELOG.md +52 -0
- package/package.json +2 -2
- package/src/procedure-builder.ts +37 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# @checkstack/common
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9016526: Add a `/rest/:pluginId/*` HTTP mount that serves every plugin's oRPC contract
|
|
8
|
+
through the REST/OpenAPI shape described by `/api/openapi.json`. Queries are
|
|
9
|
+
`GET` with query parameters, mutations are `POST` with the input as the raw
|
|
10
|
+
JSON body. The existing `/api/:pluginId/*` mount continues to serve oRPC's
|
|
11
|
+
native wire protocol unchanged, so existing clients are not affected.
|
|
12
|
+
|
|
13
|
+
The OpenAPI spec at `/api/openapi.json` now reflects the real mount: every
|
|
14
|
+
`paths` entry is prefixed with `/rest` instead of `/api`.
|
|
15
|
+
|
|
16
|
+
Also fixes a SPA-fallback bug: the backend's `/api-docs` route previously
|
|
17
|
+
returned 404 on production deployments because the static-file middleware
|
|
18
|
+
skipped any path starting with `/api`, capturing `/api-docs` along with real
|
|
19
|
+
API routes. The skip now requires a trailing slash (`/api/`, `/rest/`).
|
|
20
|
+
|
|
21
|
+
Required access rules are now visible in the API Docs UI. The OpenAPI spec
|
|
22
|
+
generator was reading a non-existent `accessRules` field on procedure
|
|
23
|
+
metadata; the real field is `access: AccessRule[]`. Each procedure's access
|
|
24
|
+
rules are now flattened to fully-qualified IDs (e.g. `catalog.system.read`)
|
|
25
|
+
and emitted under `x-orpc-meta.accessRules`, which the existing
|
|
26
|
+
`Required Access Rules` section in the docs UI already knew how to render.
|
|
27
|
+
|
|
28
|
+
The API Docs schema renderer now handles record types (zod `z.record`),
|
|
29
|
+
`$ref`s into `components.schemas`, `oneOf`/`anyOf`/`allOf`, nullable union
|
|
30
|
+
types (`type: ["string", "null"]`), and `format` qualifiers. Previously
|
|
31
|
+
record outputs like `{ statuses: object }` masked the actual value type;
|
|
32
|
+
they now render as `{ [key]: <ResolvedType> { ... } }` with the inner
|
|
33
|
+
schema expanded, capped at 12 levels with cycle detection.
|
|
34
|
+
|
|
35
|
+
**REST method conventions.** `proc()` now defaults to `GET` for queries and
|
|
36
|
+
`POST` for mutations on the `/rest` mount, using bracket-notation query
|
|
37
|
+
params (`?filter[status]=active&ids[0]=a`) for GET inputs. Existing
|
|
38
|
+
procedures were updated to follow REST semantics:
|
|
39
|
+
|
|
40
|
+
- `update*` mutations → `PATCH`
|
|
41
|
+
- `delete*` / `remove*` mutations → `DELETE`
|
|
42
|
+
- `getBulk*` queries and any query taking a large array input → `POST`
|
|
43
|
+
(because `@orpc/openapi@1.13.x` has no GET→POST URL-length fallback)
|
|
44
|
+
|
|
45
|
+
GET endpoints require an `object` input — bare scalars like
|
|
46
|
+
`.input(z.string())` are not valid on GET. `getSystemConfigurations` was
|
|
47
|
+
refactored from `.input(z.string())` to `.input(z.object({ systemId: ... }))`
|
|
48
|
+
to fit the GET shape; the only call-site update was the in-process router
|
|
49
|
+
unpacking `input.systemId` instead of passing `input` directly.
|
|
50
|
+
|
|
51
|
+
The API Docs UI now renders query parameters (path/query/header/cookie) in a
|
|
52
|
+
dedicated table for GET endpoints, and the fetch example shows them in the
|
|
53
|
+
URL with `<required>` / `<optional>` placeholders.
|
|
54
|
+
|
|
3
55
|
## 0.9.0
|
|
4
56
|
|
|
5
57
|
### Minor Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@checkstack/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "Elastic-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"typescript": "^5.7.2",
|
|
22
22
|
"@checkstack/tsconfig": "0.0.7",
|
|
23
|
-
"@checkstack/scripts": "0.3.
|
|
23
|
+
"@checkstack/scripts": "0.3.1"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"typecheck": "tsgo -b",
|
package/src/procedure-builder.ts
CHANGED
|
@@ -22,19 +22,40 @@ export type TypedContractProcedureBuilder<TMeta extends ProcedureMetadata> =
|
|
|
22
22
|
* The return type preserves the operationType in the generic parameter,
|
|
23
23
|
* enabling type-safe hook selection (useQuery vs useMutation) in usePluginClient.
|
|
24
24
|
*
|
|
25
|
+
* REST shape (via `/rest/:pluginId/*` mounted with oRPC's OpenAPIHandler):
|
|
26
|
+
* queries default to HTTP `GET` (input encoded into the URL as bracket-notation
|
|
27
|
+
* query params, e.g. `?ids[0]=a&ids[1]=b`); mutations default to `POST` with the
|
|
28
|
+
* input as the JSON body.
|
|
29
|
+
*
|
|
30
|
+
* Override the method by chaining `.route({ method: "..." })` after
|
|
31
|
+
* `proc({...})`. The repo convention is:
|
|
32
|
+
* - `create*` / `add*` → `POST` (default for mutations)
|
|
33
|
+
* - `update*` → `PATCH` (partial updates)
|
|
34
|
+
* - `delete*` / `remove*` → `DELETE`
|
|
35
|
+
* - `getBulk*` and any query with → `POST` (avoid URL-length limits;
|
|
36
|
+
* a large array input no automatic GET→POST fallback
|
|
37
|
+
* in `@orpc/openapi@1.13.x`)
|
|
38
|
+
*
|
|
39
|
+
* Constraint to know about: when method is `GET` (the default for queries),
|
|
40
|
+
* the input schema must be an `object`, `any`, or `unknown` — never a bare
|
|
41
|
+
* scalar like `z.string()`. GET has no field name to attach a top-level scalar
|
|
42
|
+
* to in a query string, so oRPC's OpenAPI generator throws at boot. Wrap the
|
|
43
|
+
* input in an object (`z.object({ id: z.string() })`) or, if the existing call
|
|
44
|
+
* sites can't be migrated, override the method to `POST`.
|
|
45
|
+
*
|
|
25
46
|
* @example
|
|
26
47
|
* ```typescript
|
|
27
48
|
* import { proc } from "@checkstack/common";
|
|
28
49
|
*
|
|
29
50
|
* export const myContract = {
|
|
30
|
-
* //
|
|
51
|
+
* // GET /rest/myplugin/getItems
|
|
31
52
|
* getItems: proc({
|
|
32
53
|
* operationType: "query",
|
|
33
54
|
* userType: "public",
|
|
34
55
|
* access: [myAccess.items.read],
|
|
35
56
|
* }).output(z.array(ItemSchema)),
|
|
36
57
|
*
|
|
37
|
-
* //
|
|
58
|
+
* // POST /rest/myplugin/createItem
|
|
38
59
|
* createItem: proc({
|
|
39
60
|
* operationType: "mutation",
|
|
40
61
|
* userType: "authenticated",
|
|
@@ -42,11 +63,24 @@ export type TypedContractProcedureBuilder<TMeta extends ProcedureMetadata> =
|
|
|
42
63
|
* })
|
|
43
64
|
* .input(CreateItemSchema)
|
|
44
65
|
* .output(ItemSchema),
|
|
66
|
+
*
|
|
67
|
+
* // POST /rest/myplugin/getBulkItems — bulk query overrides default GET
|
|
68
|
+
* // because `ids` can be too long for a query string.
|
|
69
|
+
* getBulkItems: proc({
|
|
70
|
+
* operationType: "query",
|
|
71
|
+
* userType: "public",
|
|
72
|
+
* access: [myAccess.items.read],
|
|
73
|
+
* })
|
|
74
|
+
* .route({ method: "POST" })
|
|
75
|
+
* .input(z.object({ ids: z.array(z.string()) })),
|
|
45
76
|
* };
|
|
46
77
|
* ```
|
|
47
78
|
*/
|
|
48
79
|
export function proc<TMeta extends ProcedureMetadata>(
|
|
49
80
|
meta: TMeta
|
|
50
81
|
): TypedContractProcedureBuilder<TMeta> {
|
|
51
|
-
|
|
82
|
+
const defaultMethod = meta.operationType === "query" ? "GET" : "POST";
|
|
83
|
+
return oc
|
|
84
|
+
.$meta<TMeta>(meta)
|
|
85
|
+
.route({ method: defaultMethod }) as TypedContractProcedureBuilder<TMeta>;
|
|
52
86
|
}
|