@kizunajs/swift 2.0.0-beta.10 → 2.0.0-beta.12

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/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const require_generator = require("./generator-B9dFb9Mu.cjs");
2
+ const require_generator = require("./generator-BmO3raeP.cjs");
3
3
  let node_fs = require("node:fs");
4
4
  let node_path = require("node:path");
5
5
  let node_util = require("node:util");
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { t as generateSwiftClient } from "./generator-DOSsavcH.mjs";
2
+ import { t as generateSwiftClient } from "./generator-CqKvXynF.mjs";
3
3
  import { mkdirSync, writeFileSync } from "node:fs";
4
4
  import { dirname, resolve } from "node:path";
5
5
  import { parseArgs } from "node:util";
@@ -556,7 +556,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
556
556
  stream
557
557
  };
558
558
  };
559
- const swiftGenerator = (0, kizunajs_generator.createGenerator)((options, _api) => {
559
+ const swiftRoutesWalk = (options) => {
560
560
  const flatMethods = [];
561
561
  const groupMap = /* @__PURE__ */ new Map();
562
562
  return {
@@ -588,7 +588,7 @@ const swiftGenerator = (0, kizunajs_generator.createGenerator)((options, _api) =
588
588
  };
589
589
  }
590
590
  };
591
- });
591
+ };
592
592
  const SWIFT_KEYWORDS = new Set([
593
593
  "associatedtype",
594
594
  "class",
@@ -1996,18 +1996,8 @@ const emitClient = (writer, config, partition, context, typesByOperation) => {
1996
1996
  }
1997
1997
  });
1998
1998
  };
1999
- /**
2000
- * Generate a Swift API client from a kizuna config.
2001
- *
2002
- * - `namespaceName`: the actor class. Defaults to `APIClient`.
2003
- */
2004
- const generateSwiftClient = (api, options) => {
2005
- const { namespaceName, camelCaseProperties = false, unknownEnumCase = false } = options;
2006
- const registry = new TypeRegistry(camelCaseProperties, unknownEnumCase);
2007
- const partition = swiftGenerator(api, {
2008
- namespaceName,
2009
- registry
2010
- });
1999
+ const renderSwiftClient = (api, partition, registry, options) => {
2000
+ const { namespaceName } = options;
2011
2001
  const allMethods = [...partition.flatMethods, ...partition.groups.flatMap((group) => group.methods)];
2012
2002
  const operationTypeMap = buildOperationTypeMap(allMethods, registry);
2013
2003
  const clientName = `${namespaceName}Client`;
@@ -2084,6 +2074,26 @@ const generateSwiftClient = (api, options) => {
2084
2074
  for (const warning of registry.warnings()) process.stderr.write(`[kizuna/swift] AnyCodable fallback at ${warning}\n`);
2085
2075
  return writer.toString();
2086
2076
  };
2077
+ /**
2078
+ * The Swift client's walk: the routes into a partition, then the file.
2079
+ */
2080
+ const swiftClientWalk = (api, options) => {
2081
+ const registry = new TypeRegistry(options.camelCaseProperties ?? false, options.unknownEnumCase ?? false);
2082
+ const routes = swiftRoutesWalk({
2083
+ namespaceName: options.namespaceName,
2084
+ registry
2085
+ });
2086
+ return {
2087
+ processRoute: routes.processRoute,
2088
+ finalize: () => renderSwiftClient(api, routes.finalize(), registry, options)
2089
+ };
2090
+ };
2091
+ /**
2092
+ * Generate a Swift API client from a kizuna config.
2093
+ *
2094
+ * - `namespaceName`: the actor class. Defaults to `APIClient`.
2095
+ */
2096
+ const generateSwiftClient = (api, options) => (0, kizunajs_generator.walkApi)(api, swiftClientWalk(api, options), { skipHidden: true });
2087
2097
  //#endregion
2088
2098
  Object.defineProperty(exports, "generateSwiftClient", {
2089
2099
  enumerable: true,
@@ -2091,3 +2101,9 @@ Object.defineProperty(exports, "generateSwiftClient", {
2091
2101
  return generateSwiftClient;
2092
2102
  }
2093
2103
  });
2104
+ Object.defineProperty(exports, "swiftClientWalk", {
2105
+ enumerable: true,
2106
+ get: function() {
2107
+ return swiftClientWalk;
2108
+ }
2109
+ });
@@ -1,4 +1,4 @@
1
- import { createGenerator, isBinarySchema, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorStringLiteral, readMetaDescription, readMetaId, readObjectShape, resolveResponseBody, resolveResponseContentType, resolveResponseHeaders, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamMode, toCamelCase, toPascalCase, unwrapOptionalWrappers } from "kizunajs/generator";
1
+ import { isBinarySchema, isDiscriminatedUnionSchema, isFileSchema, isHintPrefix, isIntegerSchema, isJsonMediaType, isNamedStream, isObjectSchema, isStreamResponse, isSuccessStatus, isVoidSchema, localTypeName, mergeHeaderFields, parsePath, readDef, readDefType, readDeprecation, readDiscriminatedUnion, readDiscriminatorStringLiteral, readMetaDescription, readMetaId, readObjectShape, resolveResponseBody, resolveResponseContentType, resolveResponseHeaders, routeStreams, sanitizeFieldName, sanitizeIdentifier, shortTypeName, soleStreamResponse, statusToCamelCase, streamMode, toCamelCase, toPascalCase, unwrapOptionalWrappers, walkApi } from "kizunajs/generator";
2
2
  //#region src/emit.ts
3
3
  var SwiftWriter = class {
4
4
  lines = [];
@@ -556,7 +556,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
556
556
  stream
557
557
  };
558
558
  };
559
- const swiftGenerator = createGenerator((options, _api) => {
559
+ const swiftRoutesWalk = (options) => {
560
560
  const flatMethods = [];
561
561
  const groupMap = /* @__PURE__ */ new Map();
562
562
  return {
@@ -588,7 +588,7 @@ const swiftGenerator = createGenerator((options, _api) => {
588
588
  };
589
589
  }
590
590
  };
591
- });
591
+ };
592
592
  const SWIFT_KEYWORDS = new Set([
593
593
  "associatedtype",
594
594
  "class",
@@ -1996,18 +1996,8 @@ const emitClient = (writer, config, partition, context, typesByOperation) => {
1996
1996
  }
1997
1997
  });
1998
1998
  };
1999
- /**
2000
- * Generate a Swift API client from a kizuna config.
2001
- *
2002
- * - `namespaceName`: the actor class. Defaults to `APIClient`.
2003
- */
2004
- const generateSwiftClient = (api, options) => {
2005
- const { namespaceName, camelCaseProperties = false, unknownEnumCase = false } = options;
2006
- const registry = new TypeRegistry(camelCaseProperties, unknownEnumCase);
2007
- const partition = swiftGenerator(api, {
2008
- namespaceName,
2009
- registry
2010
- });
1999
+ const renderSwiftClient = (api, partition, registry, options) => {
2000
+ const { namespaceName } = options;
2011
2001
  const allMethods = [...partition.flatMethods, ...partition.groups.flatMap((group) => group.methods)];
2012
2002
  const operationTypeMap = buildOperationTypeMap(allMethods, registry);
2013
2003
  const clientName = `${namespaceName}Client`;
@@ -2084,5 +2074,25 @@ const generateSwiftClient = (api, options) => {
2084
2074
  for (const warning of registry.warnings()) process.stderr.write(`[kizuna/swift] AnyCodable fallback at ${warning}\n`);
2085
2075
  return writer.toString();
2086
2076
  };
2077
+ /**
2078
+ * The Swift client's walk: the routes into a partition, then the file.
2079
+ */
2080
+ const swiftClientWalk = (api, options) => {
2081
+ const registry = new TypeRegistry(options.camelCaseProperties ?? false, options.unknownEnumCase ?? false);
2082
+ const routes = swiftRoutesWalk({
2083
+ namespaceName: options.namespaceName,
2084
+ registry
2085
+ });
2086
+ return {
2087
+ processRoute: routes.processRoute,
2088
+ finalize: () => renderSwiftClient(api, routes.finalize(), registry, options)
2089
+ };
2090
+ };
2091
+ /**
2092
+ * Generate a Swift API client from a kizuna config.
2093
+ *
2094
+ * - `namespaceName`: the actor class. Defaults to `APIClient`.
2095
+ */
2096
+ const generateSwiftClient = (api, options) => walkApi(api, swiftClientWalk(api, options), { skipHidden: true });
2087
2097
  //#endregion
2088
- export { generateSwiftClient as t };
2098
+ export { swiftClientWalk as n, generateSwiftClient as t };
package/dist/index.cjs CHANGED
@@ -1,17 +1,44 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-B9dFb9Mu.cjs");
2
+ const require_generator = require("./generator-BmO3raeP.cjs");
3
+ let kizunajs_generator = require("kizunajs/generator");
4
+ let zod = require("zod");
3
5
  //#region src/client-target.ts
6
+ const SwiftClientOptionsSchema = zod.z.object({
7
+ /**
8
+ * Name of the generated namespace enum.
9
+ *
10
+ * @default 'API'
11
+ */
12
+ namespace: zod.z.string().default("API"),
13
+ /**
14
+ * Convert wire field names to camelCase properties, mapping the wire name
15
+ * back via `CodingKeys`.
16
+ *
17
+ * @default false
18
+ */
19
+ camelCaseProperties: zod.z.boolean().optional(),
20
+ /**
21
+ * Give every enum an `unknown` case, so a value the client has not been
22
+ * generated for decodes instead of throwing.
23
+ *
24
+ * @default false
25
+ */
26
+ unknownEnumCase: zod.z.boolean().optional()
27
+ });
4
28
  /**
5
- * A Swift client target for `kizuna.config.ts`.
29
+ * A Swift client for `kizuna.config.ts`.
6
30
  *
7
31
  * @example
8
- * swiftClient({ output: './Sources/APIClient/APIClient.swift', namespace: 'API' });
32
+ * swiftClient({
33
+ * output: './Sources/APIClient/APIClient.swift',
34
+ * namespace: 'API',
35
+ * });
9
36
  */
10
- const swiftClient = (options) => ({
11
- kind: "swift",
12
- output: options.output,
13
- generate: (contract) => require_generator.generateSwiftClient(contract, {
14
- namespaceName: options.namespace ?? "API",
37
+ const swiftClient = (0, kizunajs_generator.defineClient)({
38
+ target: "swift",
39
+ options: SwiftClientOptionsSchema,
40
+ generate: ({ options, api }) => require_generator.swiftClientWalk(api, {
41
+ namespaceName: options.namespace,
15
42
  camelCaseProperties: options.camelCaseProperties,
16
43
  unknownEnumCase: options.unknownEnumCase
17
44
  })
package/dist/index.d.cts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import { GeneratedFileOptions } from "kizunajs/generator";
2
+ import * as _$kizunajs from "kizunajs";
3
+ import { ApiDefinition } from "kizunajs";
4
+ import { z } from "zod";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  interface SwiftConfig {
@@ -29,41 +32,28 @@ interface SwiftConfig {
29
32
  declare const generateSwiftClient: (api: ApiDefinition, options: SwiftConfig) => string;
30
33
  //#endregion
31
34
  //#region src/client-target.d.ts
35
+ declare const SwiftClientOptionsSchema: z.ZodObject<{
36
+ namespace: z.ZodDefault<z.ZodString>;
37
+ camelCaseProperties: z.ZodOptional<z.ZodBoolean>;
38
+ unknownEnumCase: z.ZodOptional<z.ZodBoolean>;
39
+ }, z.core.$strip>;
32
40
  /**
33
41
  * Where a generated Swift client is written, and what it is called there.
34
42
  */
35
- interface SwiftClientOptions {
36
- /**
37
- * Path the generated file is written to.
38
- */
39
- output: string;
40
- /**
41
- * Name of the generated namespace enum.
42
- *
43
- * @default 'API'
44
- */
45
- namespace?: string;
46
- /**
47
- * Convert wire field names to camelCase properties, mapping the wire name
48
- * back via `CodingKeys`.
49
- *
50
- * @default false
51
- */
52
- camelCaseProperties?: boolean;
53
- /**
54
- * Give every enum an `unknown` case, so a value the client has not been
55
- * generated for decodes instead of throwing.
56
- *
57
- * @default false
58
- */
59
- unknownEnumCase?: boolean;
60
- }
43
+ type SwiftClientOptions = z.input<typeof SwiftClientOptionsSchema> & GeneratedFileOptions;
61
44
  /**
62
- * A Swift client target for `kizuna.config.ts`.
45
+ * A Swift client for `kizuna.config.ts`.
63
46
  *
64
47
  * @example
65
- * swiftClient({ output: './Sources/APIClient/APIClient.swift', namespace: 'API' });
48
+ * swiftClient({
49
+ * output: './Sources/APIClient/APIClient.swift',
50
+ * namespace: 'API',
51
+ * });
66
52
  */
67
- declare const swiftClient: (options: SwiftClientOptions) => ClientTarget;
53
+ declare const swiftClient: (options: {
54
+ namespace?: string | undefined;
55
+ camelCaseProperties?: boolean | undefined;
56
+ unknownEnumCase?: boolean | undefined;
57
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
68
58
  //#endregion
69
59
  export { type SwiftClientOptions, type SwiftConfig, generateSwiftClient, swiftClient };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,7 @@
1
- import { ApiDefinition, ClientTarget } from "kizunajs";
1
+ import { GeneratedFileOptions } from "kizunajs/generator";
2
+ import { z } from "zod";
3
+ import * as _$kizunajs from "kizunajs";
4
+ import { ApiDefinition } from "kizunajs";
2
5
 
3
6
  //#region src/generator.d.ts
4
7
  interface SwiftConfig {
@@ -29,41 +32,28 @@ interface SwiftConfig {
29
32
  declare const generateSwiftClient: (api: ApiDefinition, options: SwiftConfig) => string;
30
33
  //#endregion
31
34
  //#region src/client-target.d.ts
35
+ declare const SwiftClientOptionsSchema: z.ZodObject<{
36
+ namespace: z.ZodDefault<z.ZodString>;
37
+ camelCaseProperties: z.ZodOptional<z.ZodBoolean>;
38
+ unknownEnumCase: z.ZodOptional<z.ZodBoolean>;
39
+ }, z.core.$strip>;
32
40
  /**
33
41
  * Where a generated Swift client is written, and what it is called there.
34
42
  */
35
- interface SwiftClientOptions {
36
- /**
37
- * Path the generated file is written to.
38
- */
39
- output: string;
40
- /**
41
- * Name of the generated namespace enum.
42
- *
43
- * @default 'API'
44
- */
45
- namespace?: string;
46
- /**
47
- * Convert wire field names to camelCase properties, mapping the wire name
48
- * back via `CodingKeys`.
49
- *
50
- * @default false
51
- */
52
- camelCaseProperties?: boolean;
53
- /**
54
- * Give every enum an `unknown` case, so a value the client has not been
55
- * generated for decodes instead of throwing.
56
- *
57
- * @default false
58
- */
59
- unknownEnumCase?: boolean;
60
- }
43
+ type SwiftClientOptions = z.input<typeof SwiftClientOptionsSchema> & GeneratedFileOptions;
61
44
  /**
62
- * A Swift client target for `kizuna.config.ts`.
45
+ * A Swift client for `kizuna.config.ts`.
63
46
  *
64
47
  * @example
65
- * swiftClient({ output: './Sources/APIClient/APIClient.swift', namespace: 'API' });
48
+ * swiftClient({
49
+ * output: './Sources/APIClient/APIClient.swift',
50
+ * namespace: 'API',
51
+ * });
66
52
  */
67
- declare const swiftClient: (options: SwiftClientOptions) => ClientTarget;
53
+ declare const swiftClient: (options: {
54
+ namespace?: string | undefined;
55
+ camelCaseProperties?: boolean | undefined;
56
+ unknownEnumCase?: boolean | undefined;
57
+ } & GeneratedFileOptions) => _$kizunajs.GeneratedFile;
68
58
  //#endregion
69
59
  export { type SwiftClientOptions, type SwiftConfig, generateSwiftClient, swiftClient };
package/dist/index.mjs CHANGED
@@ -1,16 +1,41 @@
1
- import { t as generateSwiftClient } from "./generator-DOSsavcH.mjs";
2
- //#region src/client-target.ts
1
+ import { n as swiftClientWalk, t as generateSwiftClient } from "./generator-CqKvXynF.mjs";
2
+ import { defineClient } from "kizunajs/generator";
3
+ import { z } from "zod";
3
4
  /**
4
- * A Swift client target for `kizuna.config.ts`.
5
+ * A Swift client for `kizuna.config.ts`.
5
6
  *
6
7
  * @example
7
- * swiftClient({ output: './Sources/APIClient/APIClient.swift', namespace: 'API' });
8
+ * swiftClient({
9
+ * output: './Sources/APIClient/APIClient.swift',
10
+ * namespace: 'API',
11
+ * });
8
12
  */
9
- const swiftClient = (options) => ({
10
- kind: "swift",
11
- output: options.output,
12
- generate: (contract) => generateSwiftClient(contract, {
13
- namespaceName: options.namespace ?? "API",
13
+ const swiftClient = defineClient({
14
+ target: "swift",
15
+ options: z.object({
16
+ /**
17
+ * Name of the generated namespace enum.
18
+ *
19
+ * @default 'API'
20
+ */
21
+ namespace: z.string().default("API"),
22
+ /**
23
+ * Convert wire field names to camelCase properties, mapping the wire name
24
+ * back via `CodingKeys`.
25
+ *
26
+ * @default false
27
+ */
28
+ camelCaseProperties: z.boolean().optional(),
29
+ /**
30
+ * Give every enum an `unknown` case, so a value the client has not been
31
+ * generated for decodes instead of throwing.
32
+ *
33
+ * @default false
34
+ */
35
+ unknownEnumCase: z.boolean().optional()
36
+ }),
37
+ generate: ({ options, api }) => swiftClientWalk(api, {
38
+ namespaceName: options.namespace,
14
39
  camelCaseProperties: options.camelCaseProperties,
15
40
  unknownEnumCase: options.unknownEnumCase
16
41
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizunajs/swift",
3
- "version": "2.0.0-beta.10",
3
+ "version": "2.0.0-beta.12",
4
4
  "description": "Swift client generation for Kizuna.js APIs",
5
5
  "keywords": [
6
6
  "kizunajs",
@@ -59,18 +59,18 @@
59
59
  "access": "public"
60
60
  },
61
61
  "dependencies": {
62
- "@kizunajs/cli": "2.0.0-beta.10"
62
+ "@kizunajs/cli": "2.0.0-beta.12"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "zod": "^4.0.0",
66
- "kizunajs": "2.0.0-beta.10"
66
+ "kizunajs": "2.0.0-beta.12"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/node": "^24",
70
70
  "tsdown": "^0.21.0",
71
71
  "typescript": "^6.0.3",
72
72
  "zod": "^4.0.0",
73
- "kizunajs": "2.0.0-beta.10"
73
+ "kizunajs": "2.0.0-beta.12"
74
74
  },
75
75
  "scripts": {
76
76
  "build": "tsdown src/index.ts src/cli.ts --format esm,cjs --dts --clean --external kizunajs --external @kizunajs/cli --external zod",