@sohcah/openapi-generator 0.0.3 → 0.1.1

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.
@@ -1,4 +1,4 @@
1
- import { NotImplementedError, OpenApiGenerator } from "./types-Ced1bVkh.js";
1
+ import { NotImplementedError, OpenApiGenerator } from "./types-DjImZ4S-.js";
2
2
  import { Effect } from "effect";
3
3
  import { FileSystem } from "@effect/platform/FileSystem";
4
4
  import * as _effect_platform_Error0 from "@effect/platform/Error";
@@ -23,4 +23,4 @@ declare const generate: (args_0: OpenapiGenerateOptions) => Effect.Effect<string
23
23
  declare const generateToFile: (args_0: OpenapiGenerateToFileOptions) => Effect.Effect<void, NotImplementedError | _effect_platform_Error0.PlatformError, FileSystem>;
24
24
  //#endregion
25
25
  export { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile };
26
- //# sourceMappingURL=index-IbWqUJNI.d.ts.map
26
+ //# sourceMappingURL=index-BOme2BJ_.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-IbWqUJNI.d.ts","names":[],"sources":["../../src/generator.ts","../../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;KASY,gBAAA;cACE;AADd,CAAA;;;KCEK,gCACD,SAAA,CAAU,SAAS,KACnB,WAAA,CAAY,SAAS,KACrB,SAAA,CAAU,SAAS;KAEX,sBAAA,GAAyB;UAC3B;ADRV,CAAA;KCWY,4BAAA,GAA+B;;;EATtC,WAAA,CAAA,EAAW,GAAA,GAAA,IAAA;CAAA;AACO,cAcV,QAdU,EAAA,CAAA,MAAA,EAcF,sBAdE,EAAA,GAcF,MAAA,CAAA,MAdE,CAAA,MAAA,EAcF,mBAAA,EAdE,KAAA,CAAA;AAAnB,cA8BS,cA9BC,EAAA,CAAA,MAAA,EA8Ba,4BA9Bb,EAAA,GA8Ba,MAAA,CAAA,MA9Bb,CAAA,IAAA,EA8Ba,mBAAA,GAAA,uBAAA,CAAA,aA9Bb,EA8Ba,UA9Bb,CAAA"}
1
+ {"version":3,"file":"index-BOme2BJ_.d.ts","names":[],"sources":["../../src/generator.ts","../../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;KASY,gBAAA;cACE;AADd,CAAA;;;KCEK,gCACD,SAAA,CAAU,SAAS,KACnB,WAAA,CAAY,SAAS,KACrB,SAAA,CAAU,SAAS;KAEX,sBAAA,GAAyB;UAC3B;ADRV,CAAA;KCWY,4BAAA,GAA+B;;;EATtC,WAAA,CAAA,EAAW,GAAA,GAAA,IAAA;CAAA;AACO,cAcV,QAdU,EAAA,CAAA,MAAA,EAcF,sBAdE,EAAA,GAcF,MAAA,CAAA,MAdE,CAAA,MAAA,EAcF,mBAAA,EAdE,KAAA,CAAA;AAAnB,cA8BS,cA9BC,EAAA,CAAA,MAAA,EA8Ba,4BA9Bb,EAAA,GA8Ba,MAAA,CAAA,MA9Bb,CAAA,IAAA,EA8Ba,mBAAA,GAAA,uBAAA,CAAA,aA9Bb,EA8Ba,UA9Bb,CAAA"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import "./types-Ced1bVkh.js";
2
- import { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile } from "./index-IbWqUJNI.js";
1
+ import "./types-DjImZ4S-.js";
2
+ import { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile } from "./index-BOme2BJ_.js";
3
3
  export { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./helpers-0HehGkaU.js";
2
- import { generate, generateToFile } from "./src-BlhnnMdZ.js";
1
+ import "./helpers-tkoILkcL.js";
2
+ import { generate, generateToFile } from "./src-CPzblUde.js";
3
3
 
4
4
  export { generate, generateToFile };
@@ -1,5 +1,5 @@
1
1
  import { __toESM } from "./chunk-51aI8Tpl.js";
2
- import { DocumentContext, NotImplementedError, getKey, httpMethods, require_lib } from "./helpers-0HehGkaU.js";
2
+ import { DocumentContext, NotImplementedError, getKey, httpMethods, require_lib } from "./helpers-tkoILkcL.js";
3
3
  import { Effect, Stream } from "effect";
4
4
  import { bundle } from "@readme/openapi-parser";
5
5
  import { generate } from "@babel/generator";
@@ -7,7 +7,7 @@ import { FileSystem } from "@effect/platform/FileSystem";
7
7
 
8
8
  //#region package.json
9
9
  var name = "@sohcah/openapi-generator";
10
- var version = "0.0.3";
10
+ var version = "0.1.1";
11
11
  var type = "module";
12
12
  var license = "MIT";
13
13
  var author = "Sam Hindess <mail@sohcah.dev>";
@@ -16,7 +16,7 @@ var publishConfig = { "access": "public" };
16
16
  var main = "./dist/index.js";
17
17
  var module = "./dist/index.js";
18
18
  var types = "./dist/index.d.ts";
19
- var bin = { "openapi-generator": "./dist/cli.js" };
19
+ var bin = "./dist/cli.js";
20
20
  var exports = {
21
21
  ".": {
22
22
  "default": "./dist/index.js",
@@ -44,6 +44,7 @@ var devDependencies = {
44
44
  "@tanstack/react-query": "^5.85.3",
45
45
  "@types/babel__generator": "^7.27.0",
46
46
  "@types/node": "^24.3.0",
47
+ "@types/regex-escape": "^3",
47
48
  "openapi-types": "^12.1.3",
48
49
  "tsdown": "^0.14.1",
49
50
  "typescript": "^5.9.2",
@@ -62,6 +63,7 @@ var dependencies = {
62
63
  "@effect/typeclass": "^0.36.0",
63
64
  "@readme/openapi-parser": "^5.0.1",
64
65
  "effect": "^3.17.7",
66
+ "regex-escape": "^3.4.11",
65
67
  "zod": "^4.1.11"
66
68
  };
67
69
  var volta = { "extends": "../../package.json" };
@@ -159,4 +161,4 @@ const generateToFile = Effect.fn(function* ({ onGenerated, output, watch,...opti
159
161
 
160
162
  //#endregion
161
163
  export { generate$2 as generate, generateToFile };
162
- //# sourceMappingURL=src-BlhnnMdZ.js.map
164
+ //# sourceMappingURL=src-CPzblUde.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"src-CPzblUde.js","names":["options: GeneratorOptions","t","packageJson","generate","document: APIDocument<object>","context: DocumentContextData","generate","generateEffect","babelGenerate","event: WatchEvent"],"sources":["../package.json","../src/generator.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@sohcah/openapi-generator\",\n \"version\": \"0.1.1\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"Sam Hindess <mail@sohcah.dev>\",\n \"files\": [\n \"dist\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": \"./dist/cli.js\",\n \"exports\": {\n \".\": {\n \"default\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n },\n \"./config\": {\n \"default\": \"./dist/config.js\",\n \"types\": \"./dist/config.d.ts\"\n },\n \"./generators\": {\n \"default\": \"./dist/generators/index.js\",\n \"types\": \"./dist/generators/index.d.ts\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"engines\": {\n \"node\": \">=22.16.0\"\n },\n \"scripts\": {\n \"build\": \"tsdown\",\n \"dev\": \"tsdown --watch\",\n \"test\": \"vitest --run\",\n \"cli\": \"./dist/cli.js\",\n \"sample\": \"yarn build && yarn cli generate -c ./sample/openapi.config.ts && SCHEMA_FORMAT=effect yarn cli generate -c ./sample/openapi.config.ts && SCHEMA_FORMAT=zod-mini yarn cli generate -c ./sample/openapi.config.ts\"\n },\n \"devDependencies\": {\n \"@tanstack/react-query\": \"^5.85.3\",\n \"@types/babel__generator\": \"^7.27.0\",\n \"@types/node\": \"^24.3.0\",\n \"@types/regex-escape\": \"^3\",\n \"openapi-types\": \"^12.1.3\",\n \"tsdown\": \"^0.14.1\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"dependencies\": {\n \"@babel/generator\": \"^7.28.3\",\n \"@effect/cli\": \"^0.69.0\",\n \"@effect/cluster\": \"^0.48.0\",\n \"@effect/experimental\": \"^0.54.6\",\n \"@effect/platform\": \"^0.90.3\",\n \"@effect/platform-node\": \"^0.96.0\",\n \"@effect/printer-ansi\": \"^0.45.0\",\n \"@effect/rpc\": \"^0.69.0\",\n \"@effect/sql\": \"^0.44.1\",\n \"@effect/typeclass\": \"^0.36.0\",\n \"@readme/openapi-parser\": \"^5.0.1\",\n \"effect\": \"^3.17.7\",\n \"regex-escape\": \"^3.4.11\",\n \"zod\": \"^4.1.11\"\n },\n \"volta\": {\n \"extends\": \"../../package.json\"\n }\n}\n","import * as t from \"@babel/types\";\nimport { Effect } from \"effect\";\nimport type { APIDocument } from \"./types.js\";\nimport { DocumentContext, type DocumentContextData } from \"./context.js\";\nimport { NotImplementedError } from \"./errors.js\";\nimport type { OpenApiGenerator } from \"./generators/types.js\";\nimport * as generationHelpers from \"./generators/helpers.js\";\nimport packageJson from \"../package.json\" with { type: \"json\" };\n\nexport type GeneratorOptions = {\n generators: OpenApiGenerator[];\n};\n\nconst build = Effect.fn(function* (options: GeneratorOptions) {\n const ctx = yield* DocumentContext;\n\n for (const generator of options.generators) {\n if (!generator.initialize) continue;\n yield* generator.initialize();\n }\n\n for (const [pathKey, path] of Object.entries(ctx.document.paths ?? {})) {\n if (!path) continue;\n if (path.$ref) {\n return yield* new NotImplementedError({\n message: \"$ref in path\",\n });\n }\n for (const methodKey of generationHelpers.httpMethods) {\n const method = path[methodKey];\n if (!method) continue;\n\n const operationKey = yield* generationHelpers.getKey(\n method.operationId ??\n `${methodKey}${pathKey.replace(/\\/(.?)/g, (_, g) => g.toUpperCase())}`\n );\n\n for (const generator of options.generators) {\n if (!generator.processOperation) continue;\n yield* generator.processOperation(\n operationKey,\n pathKey,\n methodKey,\n method\n );\n }\n }\n }\n\n for (const schema of Object.values(ctx.document.components?.schemas ?? {})) {\n for (const generator of options.generators) {\n if (!generator.processSchema) continue;\n yield* generator.processSchema(schema);\n }\n }\n\n const program = t.program([\n ...ctx.imports,\n ...[...ctx.schemas.values()].flat(),\n ]);\n t.addComment(program, \"leading\", \"eslint-disable\", false);\n t.addComment(program, \"leading\", \"prettier-ignore\", false);\n t.addComment(program, \"leading\", ` Version: ${packageJson.version}`, true);\n t.addComment(\n program,\n \"leading\",\n ` Generated by @sohcah/openapi-generator`,\n true\n );\n return program;\n});\n\nexport const generate = Effect.fn(function* (\n document: APIDocument<object>,\n options: GeneratorOptions\n) {\n const context: DocumentContextData = {\n document,\n imports: [],\n schemas: new Map(),\n processingSchemas: new Set(),\n processingSchemaTypes: new Set(),\n };\n\n return yield* build(options).pipe(\n Effect.provideService(DocumentContext, context)\n );\n});\n","import fs from \"node:fs/promises\";\nimport { bundle } from \"@readme/openapi-parser\";\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from \"openapi-types\";\nimport { generate as babelGenerate } from \"@babel/generator\";\nimport {\n generate as generateEffect,\n type GeneratorOptions,\n} from \"./generator.js\";\nimport { Effect, Stream } from \"effect\";\nimport { FileSystem, type WatchEvent } from \"@effect/platform/FileSystem\";\n\ntype APIDocument<T extends object> =\n | OpenAPIV2.Document<T>\n | OpenAPIV3_1.Document<T>\n | OpenAPIV3.Document<T>;\n\nexport type OpenapiGenerateOptions = GeneratorOptions & {\n schema: APIDocument<object> | string;\n};\n\nexport type OpenapiGenerateToFileOptions = OpenapiGenerateOptions & {\n output: string;\n watch?: boolean;\n onGenerated?: () => void;\n};\n\nexport const generate = Effect.fn(function* ({\n schema,\n ...options\n}: OpenapiGenerateOptions) {\n const result = yield* Effect.tryPromise(() => bundle(schema));\n if (!(\"components\" in result)) {\n return yield* Effect.die(\n new Error(\"Not a valid OpenAPI 3.x document\")\n );\n }\n\n const program = yield* generateEffect(result, options);\n\n return babelGenerate(program).code;\n});\n\nexport const generateToFile = Effect.fn(function* ({\n onGenerated,\n output,\n watch,\n ...options\n}: OpenapiGenerateToFileOptions) {\n const fs = yield* FileSystem;\n let lastCode = yield* generate(options);\n yield* fs.writeFileString(output, lastCode);\n onGenerated?.();\n\n if (watch) {\n if (typeof options.schema !== \"string\") {\n throw new Error(\"Schema must a file path to use watch mode\");\n }\n yield* Stream.runForEach(\n fs.watch(options.schema),\n Effect.fn(function* (event: WatchEvent) {\n if (event._tag === \"Update\") {\n const outputCode = yield* generate(options);\n if (outputCode !== lastCode) {\n yield* fs.writeFileString(output, outputCode);\n onGenerated?.();\n lastCode = outputCode;\n }\n }\n })\n );\n }\n});\n"],"mappings":";;;;;;;;WACU;cACG;WACH;cACG;aACD;YACD,CACP,MACD;oBACgB,EACf,UAAU,SACX;WACO;aACE;YACD;UACF;cACI;CACT,KAAK;EACH,WAAW;EACX,SAAS;CACV;CACD,YAAY;EACV,WAAW;EACX,SAAS;CACV;CACD,gBAAgB;EACd,WAAW;EACX,SAAS;CACV;CACD,kBAAkB;AACnB;cACU,EACT,QAAQ,YACT;cACU;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,OAAO;CACP,UAAU;AACX;sBACkB;CACjB,yBAAyB;CACzB,2BAA2B;CAC3B,eAAe;CACf,uBAAuB;CACvB,iBAAiB;CACjB,UAAU;CACV,cAAc;CACd,UAAU;AACX;mBACe;CACd,oBAAoB;CACpB,eAAe;CACf,mBAAmB;CACnB,wBAAwB;CACxB,oBAAoB;CACpB,yBAAyB;CACzB,wBAAwB;CACxB,eAAe;CACf,eAAe;CACf,qBAAqB;CACrB,0BAA0B;CAC1B,UAAU;CACV,gBAAgB;CAChB,OAAO;AACR;YACQ,EACP,WAAW,qBACZ;sBArEH;;;;;;;;;;;;;;;;;;AAsEC;;;;;ACzDD,MAAM,QAAQ,OAAO,GAAG,WAAWA,SAA2B;CAC5D,MAAM,MAAM,OAAO;AAEnB,MAAK,MAAM,aAAa,QAAQ,YAAY;AAC1C,MAAI,CAAC,UAAU,WAAY;EAC3B,OAAO,UAAU,YAAY;CAC9B;AAED,MAAK,MAAM,CAAC,SAAS,KAAK,IAAI,OAAO,QAAQ,IAAI,SAAS,SAAS,CAAE,EAAC,EAAE;AACtE,MAAI,CAAC,KAAM;AACX,MAAI,KAAK,KACP,QAAO,OAAO,IAAI,oBAAoB,EACpC,SA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AAM,OAAO,OAAO,CAAC;AAC7D,KAAI,EAAE,gBAAgB,QACpB,QAAO,OAAO,OAAO,oBACnB,IAAI,MAAM,oCACX;CAGH,MAAM,UAAU,OAAOC,WAAe,QAAQ,QAAQ;AAEtD,QAAOC,SAAc,QAAQ,CAAC;AAC/B,EAAC;AAEF,MAAa,iBAAiB,OAAO,GAAG,WAAW,EACjD,aACA,QACA,MACA,GAAG,SAC0B,EAAE;CAC/B,MAAM,KAAK,OAAO;CAClB,IAAI,WAAW,OAAOF,WAAS,QAAQ;CACvC,OAAO,GAAG,gBAAgB,QAAQ,SAAS;CAC3C,eAAe;AAEf,KAAI,OAAO;AACT,MAAI,OAAO,QAAQ,WAAW,SAC5B,OAAM,IAAI,MAAM;EAElB,OAAO,OAAO,WACZ,GAAG,MAAM,QAAQ,OAAO,EACxB,OAAO,GAAG,WAAWG,OAAmB;AACtC,OAAI,MAAM,SAAS,UAAU;IAC3B,MAAM,aAAa,OAAOH,WAAS,QAAQ;AAC3C,QAAI,eAAe,UAAU;KAC3B,OAAO,GAAG,gBAAgB,QAAQ,WAAW;KAC7C,eAAe;KACf,WAAW;IACZ;GACF;EACF,EAAC,CACH;CACF;AACF,EAAC"}
@@ -23,7 +23,7 @@ interface DocumentContextData {
23
23
  declare const DocumentContext_base: Context.TagClass<DocumentContext, "DocumentContext", DocumentContextData>;
24
24
  declare class DocumentContext extends DocumentContext_base {}
25
25
  declare namespace helpers_d_exports {
26
- export { HttpMethod, OperationKey, ensureImport, ensureNamespaceImport, getKey, httpMethods };
26
+ export { HttpMethod, OperationKey, ensureImport, ensureNamespaceImport, getKey, httpMethods, notImplementedStatement };
27
27
  }
28
28
  declare const ensureImport: (name: string, from: string, typeOnly?: boolean | undefined) => Effect.Effect<t.Identifier, never, DocumentContext>;
29
29
  declare const ensureNamespaceImport: (name: string, from: string) => Effect.Effect<t.Identifier, never, DocumentContext>;
@@ -37,6 +37,7 @@ type OperationKey = {
37
37
  };
38
38
  declare const httpMethods: readonly ["get", "post", "put", "delete", "options", "head", "patch", "trace"];
39
39
  type HttpMethod = (typeof httpMethods)[number];
40
+ declare const notImplementedStatement: t.BlockStatement;
40
41
  //#endregion
41
42
  //#region src/generators/types.d.ts
42
43
  interface ImportReference {
@@ -58,11 +59,13 @@ interface OpenApiResponseSchema {
58
59
  typeReference: t.TSTypeReference;
59
60
  }
60
61
  interface OpenApiSchemaGenerator extends OpenApiGenerator {
61
- ensureParametersSchema: (operationKey: OperationKey, operation: OperationObject) => Effect.Effect<OpenApiParametersSchema, NotImplementedError, DocumentContext>;
62
- ensureResponseSchema: (operationKey: OperationKey, operation: OperationObject) => Effect.Effect<OpenApiResponseSchema | null, NotImplementedError, DocumentContext>;
62
+ decodeResponse: (schema: t.Expression, response: t.Expression) => Effect.Effect<t.Expression>;
63
+ encodeParameters: (schema: t.Expression, parameters: t.Expression) => Effect.Effect<t.Expression>;
64
+ ensureParametersSchema: (operationKey: OperationKey, operation: OperationObject, path: string) => Effect.Effect<OpenApiParametersSchema, NotImplementedError, DocumentContext>;
65
+ ensureResponseSchema: (operationKey: OperationKey, operation: OperationObject) => Effect.Effect<OpenApiResponseSchema, NotImplementedError, DocumentContext>;
63
66
  get schemaType(): t.TSEntityName;
64
67
  }
65
68
  interface OpenApiClientGenerator extends OpenApiGenerator {}
66
69
  //#endregion
67
70
  export { DocumentContext, HttpMethod, ImportReference, NotImplementedError, OpenApiClientGenerator, OpenApiGenerator, OpenApiParametersSchema, OpenApiResponseSchema, OpenApiSchemaGenerator, OperationKey, OperationObject, SchemaObject, helpers_d_exports };
68
- //# sourceMappingURL=types-Ced1bVkh.d.ts.map
71
+ //# sourceMappingURL=types-DjImZ4S-.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DjImZ4S-.d.ts","names":[],"sources":["../../src/errors.ts","../../src/types.ts","../../src/context.ts","../../src/generators/helpers.ts","../../src/generators/types.ts"],"sourcesContent":[],"mappings":";;;;;cAEa,mBAAA,SAA4B,IAAA,CAAK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eHdhC,CAAA;EAAQ,gBACD,CAAA,EAAA,CAAA,YAAA,EGaH,YHbG,EAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EGeyB,UHfzB,EAAA,SAAA,EGkBR,eHlBQ,EAAA,GGmBhB,MAAA,CAAO,MHnBS,CAAA,IAAA,EGmBI,mBHnBJ,EGmByB,eHnBzB,CAAA;;AAAD,UGsBL,uBAAA,CHtBK;EAIV,UAAA,EGmBE,CAAA,CAAE,UHnBQ;EAAA,aAAA,EGoBP,CAAA,CAAE,eHpBK;;AAA4B,UGuBnC,qBAAA,CHvB+C;EAAY,UAAA,EGwB9D,CAAA,CAAE,UHxB4D;EAEhE,aAAA,EGuBK,CAAA,CAAE,eHvBQ;;AAAG,UG0Bb,sBAAA,SAA+B,gBH1BN,CAAA;EAAe,cAAa,EAAA,CAAA,MAAA,EG2B3C,CAAA,CAAE,UH3ByC,EAAA,QAAA,EG2BnB,CAAA,CAAE,UH3BiB,EAAA,GG2BF,MAAA,CAAO,MH3BL,CG2BY,CAAA,CAAE,UH3Bd,CAAA;EAAe,gBAAA,EAAA,CAAA,MAAA,EG4BxD,CAAA,CAAE,UH5BsD,EAAA,UAAA,EG4B9B,CAAA,CAAE,UH5B4B,EAAA,GG4Bb,MAAA,CAAO,MH5BM,CG4BC,CAAA,CAAE,UH5BH,CAAA;yCG4BA,yBAGtE,kCAER,MAAA,CAAO,OACV,yBACA,qBACA;uCAHgB,yBAOL,oBACR,MAAA,CAAO,OACV,uBACA,qBACA;oBAEgB,CAAA,CAAE;AFpDtB;AAAoC,UEuDnB,sBAAA,SAA+B,gBFvDZ,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sohcah/openapi-generator",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Sam Hindess <mail@sohcah.dev>",
@@ -13,9 +13,7 @@
13
13
  "main": "./dist/index.js",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
- "bin": {
17
- "openapi-generator": "./dist/cli.js"
18
- },
16
+ "bin": "./dist/cli.js",
19
17
  "exports": {
20
18
  ".": {
21
19
  "default": "./dist/index.js",
@@ -45,6 +43,7 @@
45
43
  "@tanstack/react-query": "^5.85.3",
46
44
  "@types/babel__generator": "^7.27.0",
47
45
  "@types/node": "^24.3.0",
46
+ "@types/regex-escape": "^3",
48
47
  "openapi-types": "^12.1.3",
49
48
  "tsdown": "^0.14.1",
50
49
  "typescript": "^5.9.2",
@@ -63,6 +62,7 @@
63
62
  "@effect/typeclass": "^0.36.0",
64
63
  "@readme/openapi-parser": "^5.0.1",
65
64
  "effect": "^3.17.7",
65
+ "regex-escape": "^3.4.11",
66
66
  "zod": "^4.1.11"
67
67
  },
68
68
  "volta": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"src-BlhnnMdZ.js","names":["options: GeneratorOptions","t","packageJson","generate","document: APIDocument<object>","context: DocumentContextData","generate","generateEffect","babelGenerate","event: WatchEvent"],"sources":["../package.json","../src/generator.ts","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@sohcah/openapi-generator\",\n \"version\": \"0.0.3\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"Sam Hindess <mail@sohcah.dev>\",\n \"files\": [\n \"dist\"\n ],\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"bin\": {\n \"openapi-generator\": \"./dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"default\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\"\n },\n \"./config\": {\n \"default\": \"./dist/config.js\",\n \"types\": \"./dist/config.d.ts\"\n },\n \"./generators\": {\n \"default\": \"./dist/generators/index.js\",\n \"types\": \"./dist/generators/index.d.ts\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"engines\": {\n \"node\": \">=22.16.0\"\n },\n \"scripts\": {\n \"build\": \"tsdown\",\n \"dev\": \"tsdown --watch\",\n \"test\": \"vitest --run\",\n \"cli\": \"./dist/cli.js\",\n \"sample\": \"yarn build && yarn cli generate -c ./sample/openapi.config.ts && SCHEMA_FORMAT=effect yarn cli generate -c ./sample/openapi.config.ts && SCHEMA_FORMAT=zod-mini yarn cli generate -c ./sample/openapi.config.ts\"\n },\n \"devDependencies\": {\n \"@tanstack/react-query\": \"^5.85.3\",\n \"@types/babel__generator\": \"^7.27.0\",\n \"@types/node\": \"^24.3.0\",\n \"openapi-types\": \"^12.1.3\",\n \"tsdown\": \"^0.14.1\",\n \"typescript\": \"^5.9.2\",\n \"vitest\": \"^3.2.4\"\n },\n \"dependencies\": {\n \"@babel/generator\": \"^7.28.3\",\n \"@effect/cli\": \"^0.69.0\",\n \"@effect/cluster\": \"^0.48.0\",\n \"@effect/experimental\": \"^0.54.6\",\n \"@effect/platform\": \"^0.90.3\",\n \"@effect/platform-node\": \"^0.96.0\",\n \"@effect/printer-ansi\": \"^0.45.0\",\n \"@effect/rpc\": \"^0.69.0\",\n \"@effect/sql\": \"^0.44.1\",\n \"@effect/typeclass\": \"^0.36.0\",\n \"@readme/openapi-parser\": \"^5.0.1\",\n \"effect\": \"^3.17.7\",\n \"zod\": \"^4.1.11\"\n },\n \"volta\": {\n \"extends\": \"../../package.json\"\n }\n}\n","import * as t from \"@babel/types\";\nimport { Effect } from \"effect\";\nimport type { APIDocument } from \"./types.js\";\nimport { DocumentContext, type DocumentContextData } from \"./context.js\";\nimport { NotImplementedError } from \"./errors.js\";\nimport type { OpenApiGenerator } from \"./generators/types.js\";\nimport * as generationHelpers from \"./generators/helpers.js\";\nimport packageJson from \"../package.json\" with { type: \"json\" };\n\nexport type GeneratorOptions = {\n generators: OpenApiGenerator[];\n};\n\nconst build = Effect.fn(function* (options: GeneratorOptions) {\n const ctx = yield* DocumentContext;\n\n for (const generator of options.generators) {\n if (!generator.initialize) continue;\n yield* generator.initialize();\n }\n\n for (const [pathKey, path] of Object.entries(ctx.document.paths ?? {})) {\n if (!path) continue;\n if (path.$ref) {\n return yield* new NotImplementedError({\n message: \"$ref in path\",\n });\n }\n for (const methodKey of generationHelpers.httpMethods) {\n const method = path[methodKey];\n if (!method) continue;\n\n const operationKey = yield* generationHelpers.getKey(\n method.operationId ??\n `${methodKey}${pathKey.replace(/\\/(.?)/g, (_, g) => g.toUpperCase())}`\n );\n\n for (const generator of options.generators) {\n if (!generator.processOperation) continue;\n yield* generator.processOperation(\n operationKey,\n pathKey,\n methodKey,\n method\n );\n }\n }\n }\n\n for (const schema of Object.values(ctx.document.components?.schemas ?? {})) {\n for (const generator of options.generators) {\n if (!generator.processSchema) continue;\n yield* generator.processSchema(schema);\n }\n }\n\n const program = t.program([\n ...ctx.imports,\n ...[...ctx.schemas.values()].flat(),\n ]);\n t.addComment(program, \"leading\", \"eslint-disable\", false);\n t.addComment(program, \"leading\", \"prettier-ignore\", false);\n t.addComment(program, \"leading\", ` Version: ${packageJson.version}`, true);\n t.addComment(\n program,\n \"leading\",\n ` Generated by @sohcah/openapi-generator`,\n true\n );\n return program;\n});\n\nexport const generate = Effect.fn(function* (\n document: APIDocument<object>,\n options: GeneratorOptions\n) {\n const context: DocumentContextData = {\n document,\n imports: [],\n schemas: new Map(),\n processingSchemas: new Set(),\n processingSchemaTypes: new Set(),\n };\n\n return yield* build(options).pipe(\n Effect.provideService(DocumentContext, context)\n );\n});\n","import fs from \"node:fs/promises\";\nimport { bundle } from \"@readme/openapi-parser\";\nimport type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from \"openapi-types\";\nimport { generate as babelGenerate } from \"@babel/generator\";\nimport {\n generate as generateEffect,\n type GeneratorOptions,\n} from \"./generator.js\";\nimport { Effect, Stream } from \"effect\";\nimport { FileSystem, type WatchEvent } from \"@effect/platform/FileSystem\";\n\ntype APIDocument<T extends object> =\n | OpenAPIV2.Document<T>\n | OpenAPIV3_1.Document<T>\n | OpenAPIV3.Document<T>;\n\nexport type OpenapiGenerateOptions = GeneratorOptions & {\n schema: APIDocument<object> | string;\n};\n\nexport type OpenapiGenerateToFileOptions = OpenapiGenerateOptions & {\n output: string;\n watch?: boolean;\n onGenerated?: () => void;\n};\n\nexport const generate = Effect.fn(function* ({\n schema,\n ...options\n}: OpenapiGenerateOptions) {\n const result = yield* Effect.tryPromise(() => bundle(schema));\n if (!(\"components\" in result)) {\n return yield* Effect.die(\n new Error(\"Not a valid OpenAPI 3.x document\")\n );\n }\n\n const program = yield* generateEffect(result, options);\n\n return babelGenerate(program).code;\n});\n\nexport const generateToFile = Effect.fn(function* ({\n onGenerated,\n output,\n watch,\n ...options\n}: OpenapiGenerateToFileOptions) {\n const fs = yield* FileSystem;\n let lastCode = yield* generate(options);\n yield* fs.writeFileString(output, lastCode);\n onGenerated?.();\n\n if (watch) {\n if (typeof options.schema !== \"string\") {\n throw new Error(\"Schema must a file path to use watch mode\");\n }\n yield* Stream.runForEach(\n fs.watch(options.schema),\n Effect.fn(function* (event: WatchEvent) {\n if (event._tag === \"Update\") {\n const outputCode = yield* generate(options);\n if (outputCode !== lastCode) {\n yield* fs.writeFileString(output, outputCode);\n onGenerated?.();\n lastCode = outputCode;\n }\n }\n })\n );\n }\n});\n"],"mappings":";;;;;;;;WACU;cACG;WACH;cACG;aACD;YACD,CACP,MACD;oBACgB,EACf,UAAU,SACX;WACO;aACE;YACD;UACF,EACL,qBAAqB,gBACtB;cACU;CACT,KAAK;EACH,WAAW;EACX,SAAS;CACV;CACD,YAAY;EACV,WAAW;EACX,SAAS;CACV;CACD,gBAAgB;EACd,WAAW;EACX,SAAS;CACV;CACD,kBAAkB;AACnB;cACU,EACT,QAAQ,YACT;cACU;CACT,SAAS;CACT,OAAO;CACP,QAAQ;CACR,OAAO;CACP,UAAU;AACX;sBACkB;CACjB,yBAAyB;CACzB,2BAA2B;CAC3B,eAAe;CACf,iBAAiB;CACjB,UAAU;CACV,cAAc;CACd,UAAU;AACX;mBACe;CACd,oBAAoB;C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gB,QAAQ,WAAW;KAC7C,eAAe;KACf,WAAW;IACZ;GACF;EACF,EAAC,CACH;CACF;AACF,EAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-Ced1bVkh.d.ts","names":[],"sources":["../../src/errors.ts","../../src/types.ts","../../src/context.ts","../../src/generators/helpers.ts","../../src/generators/types.ts"],"sourcesContent":[],"mappings":";;;;;cAEa,mBAAA,SAA4B,IAAA,CAAK;;;;;KCAlC,gCACR,WAAA,CAAY,SAAS,KACrB,SAAA,CAAU,SAAS;KAIX,YAAA,GAAe,SAAA,CAAU,eAAe,WAAA,CAAY;KAEpD,eAAA,GAAkB,WAAA,CAAY,kBAAkB,SAAA,CAAU;;;UCNrD,mBAAA;YACL;WACD,CAAA,CAAE;EFJA,OAAA,EEKF,GFLE,CAAA,MAAA,EEKU,CAAA,CAAE,SFLQ,EAAQ,CAAA;qBEMpB;yBACI;;ADPzB,cCQC,oBDRsB,kBAAA,gBAAA,EAAA,iBAAA,qBAAA,CAAA;AAAA,cCUV,eAAA,SAAwB,oBAGlC,CDboB;AAAA;;;cEGV,8EAAY,MAAA,CAAA,OAAA,CAAA,CAAA,mBAAA;cAgCZ,uDAAqB,MAAA,CAAA,OAAA,CAAA,CAAA,mBAAA;AHnCrB,cGgEA,MHhEoB,EAAA,CAAA,IAAA,EAAA,MAAa,EAAA,GGgE3B,MAAA,CAAA,MHhEgC,CAAA;;;GG2EjD;AF3EU,KE6EA,YAAA,GF7EW;EAAA,KAAA,EAAA,MAAA;EAAA,KACE,EAAA,MAAA;CAAC;AACH,cEgFV,WFhFU,EAAA,SAAA,CAAA,KAAA,EAAA,MAAA,EAAA,KAAA,EAAA,QAAA,EAAA,SAAA,EAAA,MAAA,EAAA,OAAA,EAAA,OAAA,CAAA;AAAnB,KE2FQ,UAAA,GF3FE,CAAA,OE2FmB,WF3FnB,CAAA,CAAA,MAAA,CAAA;;;ADFD,UIKI,eAAA,CJLgB;;;;ACAjC;AAAuB,UGWN,gBAAA,C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