@ir-kit/openapi 0.2.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
- export type { BodyShape } from "./operation/body.js";
1
+ export type { EnumEntryIdent, EnumKind, EnumLiteral, ObjectProperty, ObjectShape, Schema, SchemaDiscriminator, SchemaOrBool, SchemaPrimitiveType, UnionShape, } from "@ir-kit/schema";
2
+ export { assertNoEnumCollisions, classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, } from "@ir-kit/schema";
3
+ export { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
4
+ export type { BodyShape, ClassifiedBody } from "./operation/body.js";
2
5
  export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
3
6
  export type { IteratedOperation } from "./operation/iter.js";
4
7
  export { iterOperations } from "./operation/iter.js";
@@ -12,15 +15,9 @@ export { parseTemplatedSegment } from "./operation/template.js";
12
15
  export { FORM_URLENCODED_MEDIA, HTTP_METHOD_LITERAL, HTTP_METHODS, type HttpMethod, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "./spec/constants.js";
13
16
  export type { Casing, EnumPassOptions, NamingConfig, NamingRule, NormalizeOptions, ObjectPassOptions, } from "./spec/normalize/index.js";
14
17
  export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
15
- export { isMeaningless, refName } from "./spec/ref.js";
18
+ export { isMeaningless } from "./spec/ref.js";
16
19
  export { extractSecuritySchemeNames, securityKey } from "./spec/security.js";
17
20
  export type { TypeCtx } from "./type/context.js";
18
21
  export type { SchemaToTypeOps } from "./type/dispatch.js";
19
22
  export { schemaToType } from "./type/dispatch.js";
20
- export type { EnumEntryIdent, EnumKind, EnumLiteral } from "./type/enum.js";
21
- export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
22
- export type { ObjectProperty, ObjectShape } from "./type/object.js";
23
- export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
24
- export type { UnionShape } from "./type/union.js";
25
- export { classifyUnion } from "./type/union.js";
26
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACrE,YAAY,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EACZ,KAAK,UAAU,EACf,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,MAAM,EACN,eAAe,EACf,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;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als, classifyObject, classifyUnion, extractEnumValues, isNullable, isPrimitive, isRefOnly, isSchemaObject, isUnionShape, iterateObjectProperties, primitiveTag, refName, typeList, } from "@ir-kit/schema";
2
+ export { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
1
3
  export { classifyBody, isOpaqueJsonBody } from "./operation/body.js";
2
4
  export { iterOperations } from "./operation/iter.js";
3
5
  export { collectLocatedParams, PARAM_LOCATIONS, paramsAt, } from "./operation/params.js";
@@ -6,10 +8,7 @@ export { deriveBaseName, operationDocLine, splitPathSegments, } from "./operatio
6
8
  export { parseTemplatedSegment } from "./operation/template.js";
7
9
  export { FORM_URLENCODED_MEDIA, HTTP_METHOD_LITERAL, HTTP_METHODS, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "./spec/constants.js";
8
10
  export { normalizeSpec, SAFE_NORMALIZE } from "./spec/normalize/index.js";
9
- export { isMeaningless, refName } from "./spec/ref.js";
11
+ export { isMeaningless } from "./spec/ref.js";
10
12
  export { extractSecuritySchemeNames, securityKey } from "./spec/security.js";
11
13
  export { schemaToType } from "./type/dispatch.js";
12
- export { assertNoEnumCollisions, classifyEnumLiterals, } from "./type/enum.js";
13
- export { classifyObjectShape, iterateObjectProperties, } from "./type/object.js";
14
- export { classifyUnion } from "./type/union.js";
15
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,QAAQ,GACT,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,GACjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBA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,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,YAAY,EAEZ,aAAa,EACb,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAS7B,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAG7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,44 +1,37 @@
1
1
  import type { IR } from "@hey-api/shared";
2
+ import { type Schema } from "@ir-kit/schema";
2
3
  /**
3
- * `true` when a JSON-typed body has no concrete `type` but carries an
4
- * `items[]` (typical of bare `oneOf`/`anyOf` schemas) — there's no
5
- * cleanly-typed structure to bind to, so each emitter falls back to a
6
- * raw byte buffer (`[]byte` / `ByteArray` / `Data`).
4
+ * `true` when a JSON-typed body has no concrete `type` but carries
5
+ * `oneOf`/`anyOf` branches — there's no cleanly-typed structure to
6
+ * bind to, so each emitter falls back to a raw byte buffer (`[]byte` /
7
+ * `ByteArray` / `Data`).
7
8
  */
8
- export declare function isOpaqueJsonBody(schema: IR.SchemaObject): boolean;
9
+ export declare function isOpaqueJsonBody(schema: Schema): boolean;
9
10
  /**
10
- * Outcome of inspecting `IR.BodyObject`'s media type + schema shape.
11
- * Each emitter switches on `kind` to pick its body-param strategy.
11
+ * Outcome of inspecting a body's media type + schema shape. Each
12
+ * emitter switches on `kind` to pick its body-param strategy.
12
13
  */
13
- export type BodyShape =
14
- /** `application/json` with a meaningful schema. */
15
- {
14
+ export type BodyShape = {
16
15
  kind: "json-typed";
17
- }
18
- /** `application/json` whose schema collapses to opaque (oneOf/anyOf
19
- * without a single shared shape). Each emitter falls back to bytes. */
20
- | {
16
+ } | {
21
17
  kind: "json-opaque";
22
- }
23
- /** `multipart/form-data` whose schema is an object — flatten props
24
- * into one func param each. */
25
- | {
18
+ } | {
26
19
  kind: "multipart-object";
27
- }
28
- /** `application/x-www-form-urlencoded` whose schema is an object —
29
- * flatten props into one func param each. */
30
- | {
20
+ } | {
31
21
  kind: "form-urlencoded-object";
32
- }
33
- /** Empty / octet-stream / image/* / unknown — caller pre-encodes a
34
- * single bytes param. */
35
- | {
22
+ } | {
36
23
  kind: "opaque";
37
24
  };
25
+ export interface ClassifiedBody {
26
+ shape: BodyShape;
27
+ /** The body's schema in canonical form, ready to feed `schemaToType`
28
+ * or `iterateObjectProperties`. */
29
+ schema: Schema;
30
+ }
38
31
  /**
39
- * Classify a body by its media type + schema shape so emitters can
40
- * dispatch identically on `kind`. The media-type matching rules use
41
- * the shared constants in `../spec/constants` — single source of truth.
32
+ * Classify a body by media type + schema shape and return the schema
33
+ * pre-converted to canonical form so each emitter can dispatch on
34
+ * `shape.kind` without re-converting.
42
35
  */
43
- export declare function classifyBody(body: IR.BodyObject): BodyShape;
36
+ export declare function classifyBody(body: IR.BodyObject): ClassifiedBody;
44
37
  //# sourceMappingURL=body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/operation/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAO1C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,OAAO,CAEjE;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS;AACnB,mDAAmD;AACjD;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE;AACxB;wEACwE;GACtE;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE;AACzB;gCACgC;GAC9B;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE;AAC9B;8CAC8C;GAC5C;IAAE,IAAI,EAAE,wBAAwB,CAAA;CAAE;AACpC;0BAC0B;GACxB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS,CAiB3D"}
1
+ {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/operation/body.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAS7C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GACjB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GACtB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,GAC5B;IAAE,IAAI,EAAE,wBAAwB,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC;AAEvB,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,CAAC;IACjB;wCACoC;IACpC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,cAAc,CAkBhE"}
@@ -1,33 +1,41 @@
1
+ import {} from "@ir-kit/schema";
2
+ import { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
1
3
  import { FORM_URLENCODED_MEDIA, JSON_MEDIA_RE, MULTIPART_FORM_MEDIA, } from "../spec/constants.js";
2
4
  /**
3
- * `true` when a JSON-typed body has no concrete `type` but carries an
4
- * `items[]` (typical of bare `oneOf`/`anyOf` schemas) — there's no
5
- * cleanly-typed structure to bind to, so each emitter falls back to a
6
- * raw byte buffer (`[]byte` / `ByteArray` / `Data`).
5
+ * `true` when a JSON-typed body has no concrete `type` but carries
6
+ * `oneOf`/`anyOf` branches — there's no cleanly-typed structure to
7
+ * bind to, so each emitter falls back to a raw byte buffer (`[]byte` /
8
+ * `ByteArray` / `Data`).
7
9
  */
8
10
  export function isOpaqueJsonBody(schema) {
9
- return !schema.type && Array.isArray(schema.items) && schema.items.length > 0;
11
+ if (schema.type)
12
+ return false;
13
+ return Boolean(schema.oneOf?.length || schema.anyOf?.length);
10
14
  }
11
15
  /**
12
- * Classify a body by its media type + schema shape so emitters can
13
- * dispatch identically on `kind`. The media-type matching rules use
14
- * the shared constants in `../spec/constants` — single source of truth.
16
+ * Classify a body by media type + schema shape and return the schema
17
+ * pre-converted to canonical form so each emitter can dispatch on
18
+ * `shape.kind` without re-converting.
15
19
  */
16
20
  export function classifyBody(body) {
17
21
  const mt = (body.mediaType ?? "").toLowerCase();
18
- const schema = body.schema;
22
+ const schema = fromHeyApi(body.schema);
19
23
  const isObject = schema.type === "object" && Boolean(schema.properties);
24
+ let shape;
20
25
  if (mt && JSON_MEDIA_RE.test(mt)) {
21
- return isOpaqueJsonBody(schema)
26
+ shape = isOpaqueJsonBody(schema)
22
27
  ? { kind: "json-opaque" }
23
28
  : { kind: "json-typed" };
24
29
  }
25
- if (mt.startsWith(MULTIPART_FORM_MEDIA) && isObject) {
26
- return { kind: "multipart-object" };
30
+ else if (mt.startsWith(MULTIPART_FORM_MEDIA) && isObject) {
31
+ shape = { kind: "multipart-object" };
27
32
  }
28
- if (mt.startsWith(FORM_URLENCODED_MEDIA) && isObject) {
29
- return { kind: "form-urlencoded-object" };
33
+ else if (mt.startsWith(FORM_URLENCODED_MEDIA) && isObject) {
34
+ shape = { kind: "form-urlencoded-object" };
30
35
  }
31
- return { kind: "opaque" };
36
+ else {
37
+ shape = { kind: "opaque" };
38
+ }
39
+ return { shape, schema };
32
40
  }
33
41
  //# sourceMappingURL=body.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"body.js","sourceRoot":"","sources":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,IAAI,EAAE,wBAAwB,EAAE,CAAC;IAC7C,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC3B,CAAC"}
@@ -1,58 +1,38 @@
1
1
  import type { IR } from "@hey-api/shared";
2
- /**
3
- * Match a 3-digit HTTP status code in the 2xx range. Treats string
4
- * codes only (matching hey-api's IR shape) so `"default"` and `"4XX"`
5
- * style buckets don't accidentally classify as success.
6
- */
2
+ import type { Schema } from "@ir-kit/schema";
7
3
  export declare const isSuccessStatus: (code: string) => boolean;
8
4
  /**
9
- * Return the operation's 2xx responses as `[code, response]` tuples,
10
- * sorted by code for stable per-target emission order.
11
- *
12
- * Common pattern across emitters: 0 → no return, 1 → decode straight,
13
- * 2+ → emit a sum-type return that dispatches on the status code.
5
+ * Operation's 2xx responses as `[code, response]` tuples, sorted by
6
+ * code for stable per-target emission order.
14
7
  */
15
8
  export declare function successResponses(op: IR.OperationObject): Array<readonly [string, IR.ResponseObject]>;
16
9
  /**
17
- * One arm of a multi-2xx sum-type return. Each emitter parameterises
18
- * `T` with its own target type (`GoType`, `KtType`, `SwType`) for the
19
- * decoded payload. `payloadType` is omitted for empty bodies (e.g. 204).
10
+ * One arm of a multi-2xx sum-type return. Status code + payload
11
+ * schema (canonical, already converted from hey-api).
20
12
  */
21
- export interface ResponseCase<T> {
13
+ export interface ResponseCase {
22
14
  statusCode: string;
23
- caseName: string;
24
- payloadType?: T;
15
+ /** `undefined` for empty / meaningless responses (e.g. `204`). */
16
+ schema: Schema | undefined;
25
17
  }
26
18
  /**
27
19
  * Shape of an operation's success return, normalised so each emitter
28
- * can switch on `kind` instead of re-deriving the same 4-way logic
29
- * (no successes, single empty, single typed, multi-case) from the
30
- * `successResponses` array.
20
+ * can switch on `kind`. Schemas are canonical {@link Schema}.
31
21
  */
32
22
  export type ReturnShape =
33
- /** Either no 2xx responses at all, or a single 2xx whose schema is
34
- * empty / meaningless. Caller renders its Unit / Void analog. */
23
+ /** No 2xx responses, or a single 2xx with empty schema. */
35
24
  {
36
25
  kind: "void";
37
26
  }
38
- /** Single 2xx response with a non-empty schema. Caller calls
39
- * `schemaToType(schema)` and uses the result as the return. */
27
+ /** Single 2xx with non-empty schema. */
40
28
  | {
41
29
  kind: "single";
42
- schema: IR.SchemaObject;
30
+ schema: Schema;
43
31
  }
44
- /** Multiple 2xx responses. Caller emits a sum-type (Go interface,
45
- * Kotlin sealed class, Swift enum) and dispatches on status. */
32
+ /** Multiple 2xx — emitter renders a sum type. */
46
33
  | {
47
34
  kind: "multi";
48
- cases: ReadonlyArray<readonly [string, IR.ResponseObject]>;
35
+ cases: ReadonlyArray<ResponseCase>;
49
36
  };
50
- /**
51
- * Classify the success-path return for an operation. Folds the
52
- * "0 success → void / 1 success with empty schema → void / 1 success
53
- * with schema → single / 2+ success → multi" decision tree into one
54
- * tagged union so each emitter just switches on `kind` and applies
55
- * its target rendering.
56
- */
57
37
  export declare function classifyReturnShape(op: IR.OperationObject): ReturnShape;
58
38
  //# sourceMappingURL=responses.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"responses.d.ts","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAG1C;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAA+B,CAAC;AAE/E;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,EAAE,CAAC,eAAe,GACrB,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,CAAC,CAM7C;AAED;;;;GAIG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,CA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AAK,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;CAAE,CAAC;AAE1D,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,GAAG,WAAW,CAqBvE"}
@@ -1,39 +1,39 @@
1
+ import { fromHeyApi } from "@ir-kit/schema/adapters/heyapi";
1
2
  import { isMeaningless } from "../spec/ref.js";
2
- /**
3
- * Match a 3-digit HTTP status code in the 2xx range. Treats string
4
- * codes only (matching hey-api's IR shape) so `"default"` and `"4XX"`
5
- * style buckets don't accidentally classify as success.
6
- */
7
3
  export const isSuccessStatus = (code) => /^2\d\d$/.test(code);
8
4
  /**
9
- * Return the operation's 2xx responses as `[code, response]` tuples,
10
- * sorted by code for stable per-target emission order.
11
- *
12
- * Common pattern across emitters: 0 → no return, 1 → decode straight,
13
- * 2+ → emit a sum-type return that dispatches on the status code.
5
+ * Operation's 2xx responses as `[code, response]` tuples, sorted by
6
+ * code for stable per-target emission order.
14
7
  */
15
8
  export function successResponses(op) {
16
9
  return Object.entries(op.responses ?? {})
17
10
  .filter(([k]) => isSuccessStatus(k))
18
11
  .sort(([a], [b]) => a.localeCompare(b));
19
12
  }
20
- /**
21
- * Classify the success-path return for an operation. Folds the
22
- * "0 success → void / 1 success with empty schema → void / 1 success
23
- * with schema → single / 2+ success → multi" decision tree into one
24
- * tagged union so each emitter just switches on `kind` and applies
25
- * its target rendering.
26
- */
27
13
  export function classifyReturnShape(op) {
28
14
  const success = successResponses(op);
29
15
  if (success.length === 0)
30
16
  return { kind: "void" };
31
17
  if (success.length === 1) {
32
18
  const [, resp] = success[0];
33
- if (!resp?.schema || isMeaningless(resp.schema))
19
+ if (!resp?.schema)
20
+ return { kind: "void" };
21
+ const schema = fromHeyApi(resp.schema);
22
+ if (isMeaningless(schema))
34
23
  return { kind: "void" };
35
- return { kind: "single", schema: resp.schema };
24
+ return { kind: "single", schema };
36
25
  }
37
- return { kind: "multi", cases: success };
26
+ return {
27
+ kind: "multi",
28
+ cases: success.map(([statusCode, resp]) => {
29
+ if (!resp?.schema)
30
+ return { statusCode, schema: undefined };
31
+ const schema = fromHeyApi(resp.schema);
32
+ return {
33
+ statusCode,
34
+ schema: isMeaningless(schema) ? undefined : schema,
35
+ };
36
+ }),
37
+ };
38
38
  }
39
39
  //# sourceMappingURL=responses.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/operation/responses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,EAAsB;IAEtB,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,IAAI,EAAE,CAAC;SACtC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;SACnC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAEvC,CAAC;AACJ,CAAC;AAiCD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAsB;IACxD,MAAM,OAAO,GAAG,gBAAgB,CAAC,EAAE,CAAC,CAAC;IACrC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAClD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;YA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OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,aAAa,CAAC,MAAM,CAAC;YAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACnD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IACpC,CAAC;IACD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE;YACxC,IAAI,CAAC,IAAI,EAAE,MAAM;gBAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;YAC5D,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACvC,OAAO;gBACL,UAAU;gBACV,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;aACnD,CAAC;QACJ,CAAC,CAAC;KACH,CAAC;AACJ,CAAC"}
@@ -1,17 +1,7 @@
1
- import type { IR } from "@hey-api/shared";
1
+ import type { Schema } from "@ir-kit/schema";
2
2
  /**
3
- * Extract the type name from a `$ref` pointing into
4
- * `#/components/schemas`. Non-schema refs pass through unchanged so
5
- * the caller can decide how to surface them; in practice generators
6
- * only see schema refs because hey-api's ref-parser inlines other
7
- * pointer types (parameters, requestBodies, responses) before the IR
8
- * stage.
3
+ * Empty / unknown / void schemas — short-circuits a 2xx response to a
4
+ * no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
9
5
  */
10
- export declare function refName(ref: string): string;
11
- /**
12
- * Empty / unknown / void schemas — used to short-circuit a 2xx response
13
- * to a no-payload return type (Kotlin `Unit`, Swift `Void`, Go's
14
- * absence of a return type).
15
- */
16
- export declare function isMeaningless(s: IR.SchemaObject): boolean;
6
+ export declare function isMeaningless(s: Schema): boolean;
17
7
  //# sourceMappingURL=ref.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAI1C;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI3C;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,GAAG,OAAO,CAUzD"}
1
+ {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAOhD"}
package/dist/spec/ref.js CHANGED
@@ -1,32 +1,18 @@
1
- const REF_SCHEMA_PREFIX = "#/components/schemas/";
2
1
  /**
3
- * Extract the type name from a `$ref` pointing into
4
- * `#/components/schemas`. Non-schema refs pass through unchanged so
5
- * the caller can decide how to surface them; in practice generators
6
- * only see schema refs because hey-api's ref-parser inlines other
7
- * pointer types (parameters, requestBodies, responses) before the IR
8
- * stage.
9
- */
10
- export function refName(ref) {
11
- return ref.startsWith(REF_SCHEMA_PREFIX)
12
- ? ref.slice(REF_SCHEMA_PREFIX.length)
13
- : ref;
14
- }
15
- /**
16
- * Empty / unknown / void schemas — used to short-circuit a 2xx response
17
- * to a no-payload return type (Kotlin `Unit`, Swift `Void`, Go's
18
- * absence of a return type).
2
+ * Empty / unknown / void schemas — short-circuits a 2xx response to a
3
+ * no-payload return (Kotlin `Unit`, Swift `Void`, Go's absent return).
19
4
  */
20
5
  export function isMeaningless(s) {
21
6
  if (s.$ref || s.const !== undefined)
22
7
  return false;
23
- if (s.items && s.items.length > 0)
8
+ if (s.items)
24
9
  return false;
25
10
  if (s.properties && Object.keys(s.properties).length > 0)
26
11
  return false;
27
- return (s.type === undefined ||
28
- s.type === "unknown" ||
29
- s.type === "void" ||
30
- s.type === "never");
12
+ if (s.oneOf?.length || s.anyOf?.length || s.allOf?.length)
13
+ return false;
14
+ if (s.enum && s.enum.length > 0)
15
+ return false;
16
+ return s.type === undefined;
31
17
  }
32
18
  //# sourceMappingURL=ref.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAEA,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW;IACjC,OAAO,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC;QACtC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC;QACrC,CAAC,CAAC,GAAG,CAAC;AACV,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,CAAkB;IAC9C,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAChD,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,OAAO,CACL,CAAC,CAAC,IAAI,KAAK,SAAS;QACpB,CAAC,CAAC,IAAI,KAAK,SAAS;QACpB,CAAC,CAAC,IAAI,KAAK,MAAM;QACjB,CAAC,CAAC,IAAI,KAAK,OAAO,CACnB,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"ref.js","sourceRoot":"","sources":["../../src/spec/ref.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,CAAS;IACrC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IAC1B,IAAI,CAAC,CAAC,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM;QAAE,OAAO,KAAK,CAAC;IACxE,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC;AAC9B,CAAC"}
@@ -1,86 +1,58 @@
1
- import type { IR } from "@hey-api/shared";
1
+ import { type ObjectProperty, type Schema } from "@ir-kit/schema";
2
2
  import type { TypeCtx } from "./context.js";
3
- import { assertNoEnumCollisions } from "./enum.js";
4
- import { classifyObjectShape, iterateObjectProperties, type ObjectProperty } from "./object.js";
5
- import { classifyUnion } from "./union.js";
6
3
  /**
7
- * Per-target leaf operations the shared dispatchers (schemaToType,
8
- * unionToType, inlineObjectType, buildEnumFromIR) call into. `T` is
9
- * the emitter's target type (GoType / KtType / SwType), `D` is its
10
- * decl type (GoDecl / KtDecl / SwDecl).
4
+ * Per-target leaf operations the shared dispatchers (`schemaToType`,
5
+ * `unionToType`, `inlineObjectType`) call into. `T` is the emitter's
6
+ * target type (`GoType` / `KtType` / `SwType`), `D` its decl type.
11
7
  *
12
- * Each emitter writes one of these records. Per-target rendering
13
- * (pointer vs nullable, naming conventions, synthName joiner,
14
- * decl-construction call shape) lives entirely here; the dispatchers
15
- * stay neutral.
8
+ * Each emitter writes one of these records. All per-target rendering
9
+ * (pointer vs nullable, naming conventions, synthName joiner, decl
10
+ * construction) lives here; the dispatchers stay neutral.
16
11
  */
17
12
  export interface SchemaToTypeOps<T, D> {
18
- /** `$ref` → named target type. */
19
13
  refType(name: string): T;
20
- /** Array element → target array/slice/list type. */
21
14
  arrayType(elem: T): T;
22
- /** Open object's value type — target map's value-of-Any. */
23
15
  mapType(valueType: T): T;
24
- /** "No return" analog — `goAny` (Go callers drop the result slot),
16
+ /** Caller's "no return" analog — `goAny` (drops the result slot),
25
17
  * `ktUnit`, `swVoid`. */
26
18
  voidType(): T;
27
- /** Untyped fallback — `goAny` / `ktAny` / `swAny`. */
19
+ /** Caller's untyped fallback — `goAny` / `ktAny` / `swAny`. */
28
20
  anyType(): T;
29
- /** Standalone nullable-any — what `null`-typed primitives become.
30
- * Go wraps any in pointer; Kotlin / Swift wrap in nullable/optional. */
21
+ /** Standalone nullable-any — what `null`-typed primitives become. */
31
22
  nullableAnyType(): T;
32
- /** Wrap a known type in the target's optional wrapper for the
33
- * union "single + nullable" path. Go's choice is conditional
34
- * (`isPointerable` check), so this hook receives both `nullable`
35
- * and the bare inner type and decides. */
23
+ /** Wrap a known type in the target's optional wrapper for the union
24
+ * "single + nullable" path. Go's choice is conditional
25
+ * (`isPointerable`), so the hook receives both the inner type and
26
+ * the nullable bit. */
36
27
  wrapForUnionSingle(inner: T, nullable: boolean): T;
37
- /** Fallback type for unions with 2+ non-null branches. Go ignores
38
- * the nullable bit (`interface{}` already holds nil); Kotlin /
39
- * Swift wrap if nullable. */
28
+ /** Fallback type for unions with 2+ non-null branches. Go ignores
29
+ * `nullable` (interface already holds nil); Kotlin / Swift wrap. */
40
30
  unionFallback(nullable: boolean): T;
41
- /** Primitive dispatch (string, integer, number, boolean). Returns
42
- * `undefined` for non-primitive schemas so the outer dispatcher
43
- * can fall through to compound handling. */
44
- primitiveType(schema: IR.SchemaObject): T | undefined;
45
- /** Build a synth name from ctx.ownerName + propPath. Joiner is
46
- * per-target — Go uses `""` to keep `go vet` quiet, Kotlin /
47
- * Swift / TypeScript use `"_"`. */
31
+ /** Primitive dispatch. Returns `undefined` for non-primitive schemas
32
+ * so the outer dispatcher can fall through. */
33
+ primitiveType(schema: Schema): T | undefined;
34
+ /** Build a synth name from `ctx.ownerName` + `propPath`. Joiner is
35
+ * per-target — Go uses `""` to keep `go vet` quiet, Kotlin / Swift
36
+ * use `"_"`. */
48
37
  synthName(ownerName: string, propPath: ReadonlyArray<string>): string;
49
- /** Build a named struct/data-class/struct decl from an iterated
50
- * property list. Per-target work: property identifier transform,
51
- * optional wrapping, target field construction, annotation /
52
- * coding-key emission. Returns the decl; the caller chooses to
53
- * `emit` it (dispatcher does this; schema.ts also calls this
54
- * directly for top-level component schemas). */
55
- buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): D;
56
- /** Emit a string-typed enum decl and return a ref. Per-target work:
57
- * case-identifier transform (Go `<Type><Raw>`, Kotlin
58
- * `SCREAMING_SNAKE`, Swift `camel`), decl construction, runtime
59
- * bookkeeping (`@SerialName`, `Codable` conformance). */
38
+ buildStructDecl(name: string, properties: ReadonlyArray<ObjectProperty>, ctx: TypeCtx<D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): D;
60
39
  emitStringEnum(name: string, raws: ReadonlyArray<string>, emit: (d: D) => void): T;
61
- /** Same for integer-typed enums. */
62
40
  emitIntegerEnum(name: string, raws: ReadonlyArray<number>, emit: (d: D) => void): T;
63
41
  }
42
+ export declare function unionToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
43
+ export declare function inlineObjectType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: Schema, c: TypeCtx<D>) => T): T;
64
44
  /**
65
- * Resolve a union-shaped `IR.SchemaObject` to a target type. Wraps
66
- * `classifyUnion` with per-target hooks for each branch.
67
- */
68
- export declare function unionToType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): T;
69
- /**
70
- * Resolve an inline object schema to a target type. Three-way
71
- * dispatch via `classifyObjectShape`, then per-target rendering:
45
+ * Top-level dispatch from a canonical {@link Schema} to a target type.
46
+ * Routes each schema shape to the appropriate handler (`unionToType` /
47
+ * `inlineObjectType` / per-target enum emitter / target leaf constructor).
48
+ * Per-target leaf decisions live in `ops`.
72
49
  *
73
- * - named-struct → synth a name, build + emit struct, return ref
74
- * - map → wrap value type in the target's map
75
- * - open-map → map<string, any>
76
- */
77
- export declare function inlineObjectType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>, dispatch: (s: IR.SchemaObject, c: TypeCtx<D>) => T): T;
78
- /**
79
- * Top-level dispatch from `IR.SchemaObject` to a target type. Routes
80
- * each schema shape to the appropriate handler (`unionToType` /
81
- * `inlineObjectType` / per-target enum emitter / target leaf
82
- * constructor). The per-target leaf decisions live in `ops`.
50
+ * Dispatch order:
51
+ * 1. `$ref` → named ref
52
+ * 2. enum (`enum: [...]` or `oneOf`-of-consts)
53
+ * 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
54
+ * 4. primitive (per-target hook decides)
55
+ * 5. compound by `type` (array / object / null)
83
56
  */
84
- export declare function schemaToType<T, D>(schema: IR.SchemaObject, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
85
- export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
57
+ export declare function schemaToType<T, D>(schema: Schema, ctx: TypeCtx<D>, ops: SchemaToTypeOps<T, D>): T;
86
58
  //# sourceMappingURL=dispatch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","s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ec/ref.js";
2
- import { assertNoEnumCollisions, classifyEnumLiterals, } from "./enum.js";
3
- import { classifyObjectShape, iterateObjectProperties, } from "./object.js";
4
- import { classifyUnion } from "./union.js";
5
- /**
6
- * Resolve a union-shaped `IR.SchemaObject` to a target type. Wraps
7
- * `classifyUnion` with per-target hooks for each branch.
8
- */
1
+ import { classifyEnumLiterals, classifyObject, classifyUnion, extractEnumValues, isSchemaObject, isUnionShape, iterateObjectProperties, refName, } from "@ir-kit/schema";
9
2
  export function unionToType(schema, ctx, ops, dispatch) {
10
3
  const shape = classifyUnion(schema);
11
4
  switch (shape.kind) {
@@ -19,16 +12,8 @@ export function unionToType(schema, ctx, ops, dispatch) {
19
12
  return ops.unionFallback(shape.nullable);
20
13
  }
21
14
  }
22
- /**
23
- * Resolve an inline object schema to a target type. Three-way
24
- * dispatch via `classifyObjectShape`, then per-target rendering:
25
- *
26
- * - named-struct → synth a name, build + emit struct, return ref
27
- * - map → wrap value type in the target's map
28
- * - open-map → map<string, any>
29
- */
30
15
  export function inlineObjectType(schema, ctx, ops, dispatch) {
31
- const shape = classifyObjectShape(schema);
16
+ const shape = classifyObject(schema);
32
17
  switch (shape.kind) {
33
18
  case "named-struct": {
34
19
  const name = ops.synthName(ctx.ownerName, ctx.propPath);
@@ -43,60 +28,52 @@ export function inlineObjectType(schema, ctx, ops, dispatch) {
43
28
  }
44
29
  }
45
30
  /**
46
- * Top-level dispatch from `IR.SchemaObject` to a target type. Routes
47
- * each schema shape to the appropriate handler (`unionToType` /
48
- * `inlineObjectType` / per-target enum emitter / target leaf
49
- * constructor). The per-target leaf decisions live in `ops`.
31
+ * Top-level dispatch from a canonical {@link Schema} to a target type.
32
+ * Routes each schema shape to the appropriate handler (`unionToType` /
33
+ * `inlineObjectType` / per-target enum emitter / target leaf constructor).
34
+ * Per-target leaf decisions live in `ops`.
35
+ *
36
+ * Dispatch order:
37
+ * 1. `$ref` → named ref
38
+ * 2. enum (`enum: [...]` or `oneOf`-of-consts)
39
+ * 3. union shape (`oneOf` / `anyOf` / `allOf` / array-form `type`)
40
+ * 4. primitive (per-target hook decides)
41
+ * 5. compound by `type` (array / object / null)
50
42
  */
51
43
  export function schemaToType(schema, ctx, ops) {
52
44
  const dispatch = (s, c) => schemaToType(s, c, ops);
53
45
  if (schema.$ref)
54
46
  return ops.refType(refName(schema.$ref));
55
- // Untyped item-bearing schema → union (oneOf/anyOf, possibly nullable).
56
- if (schema.items && schema.items.length > 0 && !schema.type) {
57
- return unionToType(schema, ctx, ops, dispatch);
47
+ const enumValues = extractEnumValues(schema);
48
+ if (enumValues && enumValues.length > 0) {
49
+ const name = ops.synthName(ctx.ownerName, ctx.propPath);
50
+ const filtered = enumValues.filter((v) => typeof v === "string" ||
51
+ typeof v === "number" ||
52
+ typeof v === "boolean");
53
+ const kind = classifyEnumLiterals(filtered, name);
54
+ if (kind === "integer")
55
+ return ops.emitIntegerEnum(name, filtered, ctx.emit);
56
+ return ops.emitStringEnum(name, filtered, ctx.emit);
58
57
  }
58
+ if (isUnionShape(schema))
59
+ return unionToType(schema, ctx, ops, dispatch);
59
60
  const primitive = ops.primitiveType(schema);
60
61
  if (primitive !== undefined)
61
62
  return primitive;
62
- switch (schema.type) {
63
+ const t = Array.isArray(schema.type) ? schema.type[0] : schema.type;
64
+ switch (t) {
63
65
  case "array": {
64
- const elem = schema.items?.[0];
65
- return ops.arrayType(elem ? dispatch(elem, ctx) : ops.anyType());
66
- }
67
- case "tuple":
68
- return ops.arrayType(ops.anyType());
69
- case "enum": {
70
- const name = ops.synthName(ctx.ownerName, ctx.propPath);
71
- // Caller's emit walks the schema's `items[].const`; we surface
72
- // the typed list via the helper rather than re-defining the
73
- // literal-extraction here (lives in @ir-kit/openapi-tools).
74
- const rawValues = (schema.items ?? [])
75
- .map((i) => i.const)
76
- .filter((v) => typeof v === "string" ||
77
- typeof v === "number" ||
78
- typeof v === "boolean");
79
- // Collision enforcement is per-target (the identifiers differ),
80
- // so we hand off to the target's emitStringEnum / emitIntegerEnum
81
- // hook with the raw values; they call assertNoEnumCollisions
82
- // internally after computing their identifiers.
83
- const kind = classifyEnumLiterals(rawValues, name);
84
- if (kind === "integer")
85
- return ops.emitIntegerEnum(name, rawValues, ctx.emit);
86
- return ops.emitStringEnum(name, rawValues, ctx.emit);
66
+ const items = schema.items;
67
+ return ops.arrayType(items && isSchemaObject(items)
68
+ ? dispatch(items, ctx)
69
+ : ops.anyType());
87
70
  }
88
71
  case "object":
89
72
  return inlineObjectType(schema, ctx, ops, dispatch);
90
73
  case "null":
91
74
  return ops.nullableAnyType();
92
- case "never":
93
- case "void":
94
- case "undefined":
95
- return ops.voidType();
96
75
  default:
97
76
  return ops.anyType();
98
77
  }
99
78
  }
100
- // Re-export so emitters can import everything from one place.
101
- export { assertNoEnumCollisions, classifyObjectShape, classifyUnion, iterateObjectProperties, };
102
79
  //# sourceMappingURL=dispatch.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/type/dispatch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAkF3C;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,MAAuB,EACvB,GAAe,EACf,GAA0B,EAC1B,QAAkD;IAElD,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACpC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,8BAA8B;YACjC,OAAO,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,oBAAoB;YACvB,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;QACvB,KAAK,QAAQ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,SAAS,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAE9C,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IACpE,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,OAAO,CAAC,CAAC,CAAC;YACb,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;YAC3B,OAAO,GAAG,CAAC,SAAS,CAClB,KAAK,IAAI,cAAc,CAAC,KAAK,CAAC;gBAC5B,CAAC,CAAC,QAAQ,CAAC,KAAe,EAAE,GAAG,CAAC;gBAChC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAClB,CAAC;QACJ,CAAC;QACD,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,MAAM;YACT,OAAO,GAAG,CAAC,eAAe,EAAE,CAAC;QAC/B;YACE,OAAO,GAAG,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ir-kit/openapi",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Language-agnostic OpenAPI IR-walking primitives shared by the native-SDK generators. Each helper consumes @hey-api/shared's IR and returns target-neutral data — parameter locations, response categories, body media-type classifications — so per-language emitters can stay focused on rendering.",
5
5
  "keywords": [
6
6
  "openapi",
@@ -55,7 +55,8 @@
55
55
  "node": ">=20.19.0"
56
56
  },
57
57
  "dependencies": {
58
- "@ir-kit/codegen-core": "0.1.0"
58
+ "@ir-kit/codegen-core": "0.1.0",
59
+ "@ir-kit/schema": "0.2.0"
59
60
  },
60
61
  "scripts": {
61
62
  "build": "tsc -p tsconfig.build.json",
@@ -1,42 +0,0 @@
1
- /**
2
- * The supported leaf shape for `IR.SchemaObject` enum values. Mirrors
3
- * `EnumLiteral` from `@ir-kit/openapi-tools` — re-declared here to keep
4
- * the package's dependency footprint minimal (this is a 3-word union;
5
- * a workspace dep just to import it would be heavyweight).
6
- */
7
- export type EnumLiteral = string | number | boolean;
8
- export type EnumKind = "string" | "integer";
9
- /**
10
- * Classify a set of enum literals as all-string or all-integer. Throws
11
- * on mixed (or otherwise unsupported) shapes. Each emitter then picks
12
- * its target rendering — Go emits `type ... string` + typed-consts,
13
- * Kotlin emits an `enum class(val raw: String)` or a typealias to
14
- * `Int`, Swift emits a raw-typed `enum: String, Codable`.
15
- *
16
- * `name` is woven into the thrown error message so the caller doesn't
17
- * have to re-wrap; emitter call-sites previously open-coded the same
18
- * `throw new Error(\`Enum ${name}: members must all be strings or all
19
- * integers; got ...\`)` line.
20
- */
21
- export declare function classifyEnumLiterals(values: ReadonlyArray<EnumLiteral>, name: string): EnumKind;
22
- export interface EnumEntryIdent<T extends string | number> {
23
- /** The identifier emitted into the target source (Go `StatusAvailable`,
24
- * Kotlin `available`, Swift `available`). */
25
- identifier: string;
26
- /** The raw enum value the identifier was derived from. */
27
- raw: T;
28
- }
29
- /**
30
- * Detect emitter-side identifier collisions across enum entries and
31
- * throw a descriptive error. Each emitter normalises raw enum values
32
- * to its own identifier convention (Go `enumEntrySuffix`, Kotlin
33
- * `enumEntryIdent`, Swift `safeCaseName`); when two raw values
34
- * normalise to the same identifier the emitted source won't compile,
35
- * so we throw early with the offending name and the colliding raws.
36
- *
37
- * `noun` is the label used in the error message — kept per-emitter to
38
- * preserve historical wording (Go / Kotlin say `entry name`, Swift
39
- * says `case name`); tests pin the exact phrase.
40
- */
41
- export declare function assertNoEnumCollisions<T extends string | number>(schemaName: string, entries: Iterable<EnumEntryIdent<T>>, noun?: "entry name" | "case name"): void;
42
- //# sourceMappingURL=enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/type/enum.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,EAClC,IAAI,EAAE,MAAM,GACX,QAAQ,CAWV;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACvD;kDAC8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,GAAG,EAAE,CAAC,CAAC;CACR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAC9D,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EACpC,IAAI,GAAE,YAAY,GAAG,WAA0B,GAC9C,IAAI,CAiBN"}
package/dist/type/enum.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- * Classify a set of enum literals as all-string or all-integer. Throws
3
- * on mixed (or otherwise unsupported) shapes. Each emitter then picks
4
- * its target rendering — Go emits `type ... string` + typed-consts,
5
- * Kotlin emits an `enum class(val raw: String)` or a typealias to
6
- * `Int`, Swift emits a raw-typed `enum: String, Codable`.
7
- *
8
- * `name` is woven into the thrown error message so the caller doesn't
9
- * have to re-wrap; emitter call-sites previously open-coded the same
10
- * `throw new Error(\`Enum ${name}: members must all be strings or all
11
- * integers; got ...\`)` line.
12
- */
13
- export function classifyEnumLiterals(values, name) {
14
- const allStrings = values.every((v) => typeof v === "string");
15
- const allIntegers = values.every((v) => typeof v === "number" && Number.isInteger(v));
16
- if (!allStrings && !allIntegers) {
17
- throw new Error(`Enum ${name}: members must all be strings or all integers; got ${JSON.stringify(values)}`);
18
- }
19
- return allIntegers ? "integer" : "string";
20
- }
21
- /**
22
- * Detect emitter-side identifier collisions across enum entries and
23
- * throw a descriptive error. Each emitter normalises raw enum values
24
- * to its own identifier convention (Go `enumEntrySuffix`, Kotlin
25
- * `enumEntryIdent`, Swift `safeCaseName`); when two raw values
26
- * normalise to the same identifier the emitted source won't compile,
27
- * so we throw early with the offending name and the colliding raws.
28
- *
29
- * `noun` is the label used in the error message — kept per-emitter to
30
- * preserve historical wording (Go / Kotlin say `entry name`, Swift
31
- * says `case name`); tests pin the exact phrase.
32
- */
33
- export function assertNoEnumCollisions(schemaName, entries, noun = "entry name") {
34
- const collisions = new Map();
35
- for (const { identifier, raw } of entries) {
36
- const list = collisions.get(identifier) ?? [];
37
- list.push(raw);
38
- collisions.set(identifier, list);
39
- }
40
- for (const [identifier, raws] of collisions) {
41
- if (raws.length > 1) {
42
- const formatted = raws
43
- .map((r) => (typeof r === "string" ? `"${r}"` : String(r)))
44
- .join(", ");
45
- throw new Error(`Enum ${schemaName}: ${noun} "${identifier}" collides for raw values [${formatted}]`);
46
- }
47
- }
48
- }
49
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/type/enum.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAkC,EAClC,IAAY;IAEZ,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CACpD,CAAC;IACF,IAAI,CAAC,UAAU,IAA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- * picks its target rendering:
5
- *
6
- * - `named-struct` → synth a name, emit a struct/data-class/struct,
7
- * return a ref to it
8
- * - `map` → render as `map[string]V` / `Map<String, V>` /
9
- * `[String: V]` over the inner value schema
10
- * - `open-map` → same map, but value is `any` / `Any` / `Any`
11
- * since `additionalProperties` was missing or
12
- * `true`/empty
13
- */
14
- export type ObjectShape = {
15
- kind: "named-struct";
16
- } | {
17
- kind: "map";
18
- valueSchema: IR.SchemaObject;
19
- } | {
20
- kind: "open-map";
21
- };
22
- /**
23
- * Classify an object-shaped schema by its property layout. Used by
24
- * each emitter's `inlineObjectType` to drive the same three-way
25
- * dispatch identically.
26
- */
27
- export declare function classifyObjectShape(schema: IR.SchemaObject): ObjectShape;
28
- export interface ObjectProperty {
29
- jsonKey: string;
30
- schema: IR.SchemaObject;
31
- /** True when the property name appears in `schema.required`. */
32
- required: boolean;
33
- /** True when the property is `string` + `format: "binary"`. Common
34
- * enough across emitters (multipart-binary handling) to surface
35
- * alongside the basic iteration. */
36
- isBinary: boolean;
37
- /** The propPath segment for this property, ready to plug into a
38
- * recursive `schemaToType(propSchema, { ...ctx, propPath: [segment] })`
39
- * call. Pre-computed as `pascal(jsonKey)` since both `synthName`
40
- * variants (codegen-core's `_`-joined and Go's `""`-joined) expect
41
- * PascalCase parts. */
42
- propPathSegment: string;
43
- }
44
- /**
45
- * Walk `schema.properties` in declaration order and yield one
46
- * `ObjectProperty` per entry, with the `required` membership,
47
- * binary-format detection, and pre-computed propPath segment
48
- * surfaced. Used by every emitter's `type/object.ts`
49
- * (struct/data-class/struct field generation) and `operation/body.ts`
50
- * (multipart / urlencoded flat-param expansion).
51
- */
52
- export declare function iterateObjectProperties(schema: IR.SchemaObject): Generator<ObjectProperty>;
53
- //# sourceMappingURL=object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/type/object.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAG1C;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,GACxB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,EAAE,CAAC,YAAY,CAAA;CAAE,GAC7C;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAEzB;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,WAAW,CAMxE;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC;IACxB,gEAAgE;IAChE,QAAQ,EAAE,OAAO,CAAC;IAClB;;yCAEqC;IACrC,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;4BAIwB;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAiB,uBAAuB,CACtC,MAAM,EAAE,EAAE,CAAC,YAAY,GACtB,SAAS,CAAC,cAAc,CAAC,CAW3B"}
@@ -1,36 +0,0 @@
1
- import { pascal } from "@ir-kit/codegen-core";
2
- /**
3
- * Classify an object-shaped schema by its property layout. Used by
4
- * each emitter's `inlineObjectType` to drive the same three-way
5
- * dispatch identically.
6
- */
7
- export function classifyObjectShape(schema) {
8
- const hasNamedProperties = Object.keys(schema.properties ?? {}).length > 0;
9
- if (hasNamedProperties)
10
- return { kind: "named-struct" };
11
- const ap = schema.additionalProperties;
12
- if (ap && typeof ap === "object")
13
- return { kind: "map", valueSchema: ap };
14
- return { kind: "open-map" };
15
- }
16
- /**
17
- * Walk `schema.properties` in declaration order and yield one
18
- * `ObjectProperty` per entry, with the `required` membership,
19
- * binary-format detection, and pre-computed propPath segment
20
- * surfaced. Used by every emitter's `type/object.ts`
21
- * (struct/data-class/struct field generation) and `operation/body.ts`
22
- * (multipart / urlencoded flat-param expansion).
23
- */
24
- export function* iterateObjectProperties(schema) {
25
- const required = new Set(schema.required ?? []);
26
- for (const [jsonKey, propSchema] of Object.entries(schema.properties ?? {})) {
27
- yield {
28
- jsonKey,
29
- schema: propSchema,
30
- required: required.has(jsonKey),
31
- isBinary: propSchema.type === "string" && propSchema.format === "binary",
32
- propPathSegment: pascal(jsonKey),
33
- };
34
- }
35
- }
36
- //# sourceMappingURL=object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/type/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAmB9C;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAuB;IACzD,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3E,IAAI,kBAAkB;QAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;IACxD,MAAM,EAAE,GAAG,MAAM,CAAC,oBAAoB,CAAC;IACvC,IAAI,EAAE,IAAI,OAAO,EAAE,KAAK,QAAQ;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IAC1E,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC;AAmBD;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,uBAAuB,CACtC,MAAuB;IAEvB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;IAChD,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC,EAAE,CAAC;QAC5E,MAAM;YACJ,OAAO;YACP,MAAM,EAAE,UAAU;YAClB,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;YAC/B,QAAQ,EAAE,UAAU,CAAC,IAAI,KAAK,QAAQ,IAAI,UAAU,CAAC,MAAM,KAAK,QAAQ;YACxE,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC;SACjC,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -1,35 +0,0 @@
1
- import type { IR } from "@hey-api/shared";
2
- /**
3
- * Outcome of inspecting a union-shaped schema. Pure structural —
4
- * caller still needs to decide how to render each kind in its target
5
- * language (Go pointer vs Kotlin nullable vs Swift optional, fall-back
6
- * to `any` vs `Any` vs language equivalents).
7
- */
8
- export type UnionShape = {
9
- kind: "intersection-with-properties";
10
- } | {
11
- kind: "intersection-empty";
12
- } | {
13
- kind: "single";
14
- inner: IR.SchemaObject;
15
- nullable: boolean;
16
- } | {
17
- kind: "multi";
18
- nullable: boolean;
19
- };
20
- /**
21
- * Classify a union-shaped schema (`logicalOperator: "or" | "and"`)
22
- * into one of the cases each emitter handles. hey-api represents
23
- * OpenAPI 3.1 nullables as `or` unions with a `{type:"null"}` branch;
24
- * `allOf` folds become `and`.
25
- *
26
- * - `and` + properties → caller dispatches to its inline-object path.
27
- * - `and` empty → caller renders its `any` analog.
28
- * - 1 non-null branch → caller renders the inner, applying its own
29
- * nullable wrapper iff `nullable === true`.
30
- * - 2+ non-null → caller falls back to its `any`; `nullable`
31
- * is reported but caller decides whether to
32
- * apply it (Go drops it, KT/Swift wrap).
33
- */
34
- export declare function classifyUnion(schema: IR.SchemaObject): UnionShape;
35
- //# sourceMappingURL=union.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"union.d.ts","sourceRoot":"","sources":["../../src/type/union.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,8BAA8B,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,oBAAoB,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,GAAG,UAAU,CAajE"}
@@ -1,29 +0,0 @@
1
- /**
2
- * Classify a union-shaped schema (`logicalOperator: "or" | "and"`)
3
- * into one of the cases each emitter handles. hey-api represents
4
- * OpenAPI 3.1 nullables as `or` unions with a `{type:"null"}` branch;
5
- * `allOf` folds become `and`.
6
- *
7
- * - `and` + properties → caller dispatches to its inline-object path.
8
- * - `and` empty → caller renders its `any` analog.
9
- * - 1 non-null branch → caller renders the inner, applying its own
10
- * nullable wrapper iff `nullable === true`.
11
- * - 2+ non-null → caller falls back to its `any`; `nullable`
12
- * is reported but caller decides whether to
13
- * apply it (Go drops it, KT/Swift wrap).
14
- */
15
- export function classifyUnion(schema) {
16
- if (schema.logicalOperator === "and") {
17
- return schema.properties
18
- ? { kind: "intersection-with-properties" }
19
- : { kind: "intersection-empty" };
20
- }
21
- const items = schema.items ?? [];
22
- const nonNull = items.filter((i) => i.type !== "null");
23
- const nullable = nonNull.length < items.length;
24
- if (nonNull.length === 1) {
25
- return { kind: "single", inner: nonNull[0], nullable };
26
- }
27
- return { kind: "multi", nullable };
28
- }
29
- //# sourceMappingURL=union.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"union.js","sourceRoot":"","sources":["../../src/type/union.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAAC,MAAuB;IACnD,IAAI,MAAM,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACrC,OAAO,MAAM,CAAC,UAAU;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,8BAA8B,EAAE;YAC1C,CAAC,CAAC,EAAE,IAAI,EAAE,oBAAoB,EAAE,CAAC;IACrC,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC/C,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,QAAQ,EAAE,CAAC;IAC1D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}