@sohcah/openapi-generator 0.0.1 → 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.
@@ -1,4 +1,4 @@
1
- import { NotImplementedError, OpenApiGenerator } from "./types-7ABKlnLu.js";
1
+ import { NotImplementedError, OpenApiGenerator } from "./types-DzA8rjw7.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-COF3JXv1.d.ts.map
26
+ //# sourceMappingURL=index-CiJW9J8K.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-COF3JXv1.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-CiJW9J8K.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-7ABKlnLu.js";
2
- import { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile } from "./index-COF3JXv1.js";
1
+ import "./types-DzA8rjw7.js";
2
+ import { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile } from "./index-CiJW9J8K.js";
3
3
  export { OpenapiGenerateOptions, OpenapiGenerateToFileOptions, generate, generateToFile };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./helpers-ChEkrLHV.js";
2
- import { generate, generateToFile } from "./src-UQLWBWmZ.js";
1
+ import "./helpers-CKmqJXD5.js";
2
+ import { generate, generateToFile } from "./src-B0C1RYUJ.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, require_lib } from "./helpers-ChEkrLHV.js";
2
+ import { DocumentContext, NotImplementedError, getKey, require_lib } from "./helpers-CKmqJXD5.js";
3
3
  import { Effect, Stream } from "effect";
4
4
  import { bundle } from "@readme/openapi-parser";
5
5
  import { generate } from "@babel/generator";
@@ -7,12 +7,12 @@ 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.1";
10
+ var version = "0.0.2";
11
11
  var type = "module";
12
12
  var license = "MIT";
13
13
  var author = "Sam Hindess <mail@sohcah.dev>";
14
- var publishConfig = { "access": "public" };
15
14
  var files = ["dist"];
15
+ 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";
@@ -71,8 +71,8 @@ var package_default = {
71
71
  type,
72
72
  license,
73
73
  author,
74
- publishConfig,
75
74
  files,
75
+ publishConfig,
76
76
  main,
77
77
  module,
78
78
  types,
@@ -164,4 +164,4 @@ const generateToFile = Effect.fn(function* ({ onGenerated, output, watch,...opti
164
164
 
165
165
  //#endregion
166
166
  export { generate$2 as generate, generateToFile };
167
- //# sourceMappingURL=src-UQLWBWmZ.js.map
167
+ //# sourceMappingURL=src-B0C1RYUJ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"src-UQLWBWmZ.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.1\",\n \"type\": \"module\",\n \"license\": \"MIT\",\n \"author\": \"Sam Hindess <mail@sohcah.dev>\",\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"files\": [\n \"dist\"\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 [\"get\", \"post\", \"put\", \"delete\"] as const) {\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;oBACO,EACf,UAAU,SACX;YACQ,CACP,MACD;WACO;aACE;YACD;UACF,EACL,qBAAqB,gBACtB;cACU;CACT,KAAK;EACH,WAAW;EACX,SAAS;CACV;CACD,YAAY;EACV,WAAW;EACX,SA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,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"}
1
+ {"version":3,"file":"src-B0C1RYUJ.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.2\",\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 [\"get\", \"post\", \"put\", \"delete\"] as const) {\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;CACpB,eAAe;CACf,mBAAmB;CACnB,wBAAwB;CACxB,oBAAoB;CACpB,yBAAyB;CACzB,wBAAwB;CACxB,eAAe;CACf,eAAe;CACf,qBA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AAC"}
@@ -25,7 +25,7 @@ declare class DocumentContext extends DocumentContext_base {}
25
25
  declare namespace helpers_d_exports {
26
26
  export { OperationKey, ensureImport, ensureNamespaceImport, getKey };
27
27
  }
28
- declare const ensureImport: (name: string, from: string) => Effect.Effect<t.Identifier, never, DocumentContext>;
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>;
30
30
  declare const getKey: (name: string) => Effect.Effect<{
31
31
  lower: string;
@@ -63,4 +63,4 @@ interface OpenApiSchemaGenerator extends OpenApiGenerator {
63
63
  interface OpenApiClientGenerator extends OpenApiGenerator {}
64
64
  //#endregion
65
65
  export { DocumentContext, ImportReference, NotImplementedError, OpenApiClientGenerator, OpenApiGenerator, OpenApiParametersSchema, OpenApiResponseSchema, OpenApiSchemaGenerator, OperationKey, OperationObject, SchemaObject, helpers_d_exports };
66
- //# sourceMappingURL=types-7ABKlnLu.d.ts.map
66
+ //# sourceMappingURL=types-DzA8rjw7.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DzA8rjw7.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,SFLgB,EAAA,CAAA;qBEMpB;yBACI;;ADPzB,cCQC,oBDRsB,kBAAA,gBAAA,EAAA,iBAAA,qBAAA,C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,GG8B/D,MAAA,CAAO,MH9BwD,CG+BlE,uBH/BkE,EGgClE,mBHhCkE,EGiClE,eHjCkE,CAAA;EAAe,oBAAA,EAAA,CAAA,YAAA,EG8BjE,YH9BiE,EAAA,SAAA,EGqCtE,eHrCsE,EAAA,GGsC9E,MAAA,CAAO,MHtCuE,CGuCjF,qBHvCiF,GAAA,IAAA,EGwCjF,mBHxCiF,EGyCjF,eHzCiF,CAAA;oBG2CjE,CAAA,CAAE;;UAGL,sBAAA,SAA+B,kBFpDhD"}
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@sohcah/openapi-generator",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Sam Hindess <mail@sohcah.dev>",
7
- "publishConfig": {
8
- "access": "public"
9
- },
10
7
  "files": [
11
8
  "dist"
12
9
  ],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
13
  "main": "./dist/index.js",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
@@ -68,4 +68,4 @@
68
68
  "volta": {
69
69
  "extends": "../../package.json"
70
70
  }
71
- }
71
+ }