@ir-kit/openapi-ts-paths 0.1.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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ahmed Rowaihi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @ir-kit/openapi-ts-paths
2
+
3
+ Per-operation route consts emitted from an OpenAPI spec — spec template, URLPattern-style pattern, method, and operationId, ready for tree-shakable runtime routing and matching. Plugin for [`@hey-api/openapi-ts`](https://heyapi.dev).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -D @ir-kit/openapi-ts-paths @hey-api/openapi-ts
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```ts
14
+ import { defineConfig } from "@hey-api/openapi-ts";
15
+ import { defineConfig as definePathsConfig } from "@ir-kit/openapi-ts-paths";
16
+
17
+ export default defineConfig({
18
+ input: "openapi.yaml",
19
+ output: { path: "./generated" },
20
+ plugins: [
21
+ "@hey-api/typescript",
22
+ definePathsConfig({
23
+ output: "paths", // → generated/paths.ts
24
+ naming: { casing: "camelCase", suffix: "Route" },
25
+ }),
26
+ ],
27
+ });
28
+ ```
29
+
30
+ ## Output
31
+
32
+ For each operation that has a `path` and an `operationId`, the plugin emits:
33
+
34
+ ```ts
35
+ export const getPetByIdRoute = {
36
+ spec: "/pets/{id}",
37
+ pattern: "/pets/:id",
38
+ method: "get",
39
+ operationId: "getPetById",
40
+ } as const;
41
+ ```
42
+
43
+ - `spec` — the original `{param}` template, useful when re-issuing the request.
44
+ - `pattern` — `:param` form, ready to feed `URLPattern`, `path-to-regexp`, your router of choice.
45
+ - `method` — lower-case verb.
46
+ - `operationId` — the OpenAPI id when present.
47
+
48
+ `as const` keeps every value literal-typed so downstream code can narrow on `route.method`, etc.
49
+
50
+ ## Why route consts (instead of runtime routing)
51
+
52
+ Tree-shakable: only the routes you import end up in the bundle. Pair with the matchers in [`@ir-kit/openapi-tools`](../../openapi-tools) for client-side dispatch:
53
+
54
+ ```ts
55
+ import { match } from "@ir-kit/openapi-tools/match";
56
+ import { getPetByIdRoute } from "./generated/paths";
57
+
58
+ const params = match(getPetByIdRoute.pattern, "/pets/42"); // { id: "42" }
59
+ ```
60
+
61
+ Or feed them to a router framework that takes pattern strings.
62
+
63
+ ## Options
64
+
65
+ ```ts
66
+ definePathsConfig({
67
+ output: "paths", // filename (no extension). Default: "paths"
68
+ naming: {
69
+ casing: "camelCase", // any @hey-api/shared NamingRule | Casing
70
+ suffix: "Route", // appended to each const name
71
+ },
72
+ });
73
+ ```
74
+
75
+ ## License
76
+
77
+ MIT
@@ -0,0 +1,6 @@
1
+ import type { PathsPlugin } from "./types";
2
+ export declare const defaultConfig: PathsPlugin["Config"];
3
+ export declare const defineConfig: (userConfig?: Omit<import("./types").UserConfig, "name"> | undefined) => Omit<import("@hey-api/shared").Plugin.Config<import("@hey-api/shared").Plugin.Types<import("./types").UserConfig, import("./types").Config, never>>, "name"> & {
4
+ name: any;
5
+ };
6
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,QAAQ,CAY/C,CAAC;AAEF,eAAO,MAAM,YAAY;;CAAoC,CAAC"}
package/dist/config.js ADDED
@@ -0,0 +1,17 @@
1
+ import { definePluginConfig } from "@hey-api/shared";
2
+ import { handler } from "./plugin";
3
+ export const defaultConfig = {
4
+ config: {
5
+ output: "paths",
6
+ naming: {
7
+ casing: "camelCase",
8
+ suffix: "Route",
9
+ },
10
+ },
11
+ dependencies: ["@hey-api/typescript"],
12
+ handler,
13
+ name: "@ir-kit/paths",
14
+ tags: ["transformer"],
15
+ };
16
+ export const defineConfig = definePluginConfig(defaultConfig);
17
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,CAAC,MAAM,aAAa,GAA0B;IAClD,MAAM,EAAE;QACN,MAAM,EAAE,OAAO;QACf,MAAM,EAAE;YACN,MAAM,EAAE,WAAW;YACnB,MAAM,EAAE,OAAO;SAChB;KACF;IACD,YAAY,EAAE,CAAC,qBAAqB,CAAC;IACrC,OAAO;IACP,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,CAAC,aAAa,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC,aAAa,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import "./types";
2
+ export { defaultConfig, defineConfig } from "./config";
3
+ export type { PathsPlugin } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import "./types";
2
+ export { defaultConfig, defineConfig } from "./config";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,CAAC;AAEjB,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { PathsPlugin } from "./types";
2
+ export declare const handler: PathsPlugin["Handler"];
3
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAW3C,eAAO,MAAM,OAAO,EAAE,WAAW,CAAC,SAAS,CAoB1C,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,28 @@
1
+ import { $ } from "@hey-api/openapi-ts";
2
+ import { applyNaming } from "@hey-api/shared";
3
+ /** `/users/{id}/posts/{postId}` → `/users/:id/posts/:postId` */
4
+ function specToPattern(spec) {
5
+ return spec.replace(/\{([^}]+)\}/g, ":$1");
6
+ }
7
+ function sanitize(name) {
8
+ return name.replace(/[^\w]/g, "");
9
+ }
10
+ export const handler = ({ plugin }) => {
11
+ const { casing, suffix } = plugin.config.naming;
12
+ plugin.forEach("operation", ({ operation }) => {
13
+ if (!operation.path || !operation.id)
14
+ return;
15
+ const baseName = sanitize(applyNaming(operation.id, { casing }));
16
+ const symbolName = `${baseName}${suffix}`;
17
+ const symbol = plugin.symbol(symbolName);
18
+ let routeObj = $.object()
19
+ .prop("spec", $.literal(operation.path))
20
+ .prop("pattern", $.literal(specToPattern(operation.path)))
21
+ .prop("method", $.literal(operation.method.toLowerCase()));
22
+ if (operation.operationId) {
23
+ routeObj = routeObj.prop("operationId", $.literal(operation.operationId));
24
+ }
25
+ plugin.node($.const(symbol).export().assign(routeObj.as("const")));
26
+ });
27
+ };
28
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,qBAAqB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,gEAAgE;AAChE,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAA2B,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;IAEhD,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE;QAC5C,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE;YAAE,OAAO;QAE7C,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACjE,MAAM,UAAU,GAAG,GAAG,QAAQ,GAAG,MAAM,EAAE,CAAC;QAC1C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAEzC,IAAI,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE;aACtB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aACvC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;aACzD,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QAC7D,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;YAC1B,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACrE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { Casing, DefinePlugin, NamingRule, Plugin } from "@hey-api/shared";
2
+ export type UserConfig = Plugin.Hooks & Plugin.UserExports & {
3
+ name: "@ir-kit/paths";
4
+ /** Filename (no extension). @default "paths" */
5
+ output?: string;
6
+ /** Route const naming: `applyNaming(operationId, casing) + suffix` (e.g. `getPetByIdRoute`). */
7
+ naming?: {
8
+ /** @default 'camelCase' */
9
+ casing?: NamingRule | Casing;
10
+ /** @default 'Route' */
11
+ suffix?: string;
12
+ };
13
+ };
14
+ export type Config = Plugin.Hooks & Plugin.Exports & {
15
+ name: "@ir-kit/paths";
16
+ output: string;
17
+ naming: {
18
+ casing: Casing;
19
+ suffix: string;
20
+ };
21
+ };
22
+ export type PathsPlugin = DefinePlugin<UserConfig, Config>;
23
+ declare module "@hey-api/openapi-ts" {
24
+ interface PluginConfigMap {
25
+ "@ir-kit/paths": PathsPlugin["Types"];
26
+ }
27
+ }
28
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEhF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,GACnC,MAAM,CAAC,WAAW,GAAG;IACnB,IAAI,EAAE,eAAe,CAAC;IACtB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gGAAgG;IAChG,MAAM,CAAC,EAAE;QACP,2BAA2B;QAC3B,MAAM,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;QAC7B,uBAAuB;QACvB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEJ,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,GAC/B,MAAM,CAAC,OAAO,GAAG;IACf,IAAI,EAAE,eAAe,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AAEJ,MAAM,MAAM,WAAW,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAE3D,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAiB,eAAe;QAC9B,eAAe,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;KACvC;CACF"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@ir-kit/openapi-ts-paths",
3
+ "version": "0.1.0",
4
+ "description": "Plugin for @hey-api/openapi-ts — emit per-operation route consts (spec template, URLPattern, method, operationId) for tree-shakable runtime routing and matching",
5
+ "keywords": [
6
+ "openapi",
7
+ "openapi-ts",
8
+ "routes",
9
+ "router",
10
+ "matcher",
11
+ "url-pattern",
12
+ "typescript",
13
+ "codegen",
14
+ "type-safe",
15
+ "plugin"
16
+ ],
17
+ "homepage": "https://github.com/ir-kit/ir-kit/tree/main/packages/openapi/plugins/paths",
18
+ "bugs": {
19
+ "url": "https://github.com/ir-kit/ir-kit/issues"
20
+ },
21
+ "license": "MIT",
22
+ "author": {
23
+ "name": "Ahmed Rowaihi",
24
+ "email": "ahmedrowaihi@gmail.com"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/ir-kit/ir-kit.git",
29
+ "directory": "packages/openapi/plugins/paths"
30
+ },
31
+ "type": "module",
32
+ "main": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "require": "./dist/index.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "files": [
43
+ "dist",
44
+ "README.md",
45
+ "LICENSE.md"
46
+ ],
47
+ "publishConfig": {
48
+ "access": "public",
49
+ "provenance": true
50
+ },
51
+ "peerDependencies": {
52
+ "@hey-api/codegen-core": ">=0.7.0",
53
+ "@hey-api/openapi-ts": ">=0.95.0",
54
+ "@hey-api/shared": ">=0.3.0"
55
+ },
56
+ "devDependencies": {
57
+ "@hey-api/codegen-core": "^0.8.1",
58
+ "@hey-api/openapi-ts": "^0.97.0",
59
+ "@hey-api/shared": "^0.4.2",
60
+ "@types/node": "^22",
61
+ "@ir-kit/tsconfig": "0.0.0"
62
+ },
63
+ "engines": {
64
+ "node": ">=20.19.0"
65
+ },
66
+ "scripts": {
67
+ "build": "tsc",
68
+ "dev": "tsc --watch",
69
+ "typecheck": "tsc --noEmit"
70
+ }
71
+ }