@kizunajs/swift 2.0.0-beta.18 → 2.0.0-beta.19
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
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { t as generateSwiftClient } from "./generator-
|
|
2
|
+
import { t as generateSwiftClient } from "./generator-CjCPSdEz.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -47,7 +47,6 @@ var TypeRegistry = class {
|
|
|
47
47
|
unionVariantOwners = /* @__PURE__ */ new Map();
|
|
48
48
|
brands = /* @__PURE__ */ new Map();
|
|
49
49
|
usesAnyCodable = false;
|
|
50
|
-
usesNullish = false;
|
|
51
50
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
52
51
|
this.camelCaseProperties = camelCaseProperties;
|
|
53
52
|
this.unknownEnumCase = unknownEnumCase;
|
|
@@ -111,13 +110,11 @@ const propertyName = (key, camelCase) => {
|
|
|
111
110
|
if (!camel) return "field";
|
|
112
111
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
113
112
|
};
|
|
114
|
-
const objectFields = (schema, registry, hint,
|
|
113
|
+
const objectFields = (schema, registry, hint, shape = readObjectShape(schema) ?? {}) => {
|
|
115
114
|
const fields = [];
|
|
116
115
|
const seen = /* @__PURE__ */ new Map();
|
|
117
116
|
for (const [key, value] of Object.entries(shape)) {
|
|
118
117
|
const result = mapType(value, registry, `${hint}${toPascalCase(key)}`);
|
|
119
|
-
const nullish = nullishTriState && result.nullish === true;
|
|
120
|
-
if (nullish) registry.usesNullish = true;
|
|
121
118
|
const deprecation = readDeprecation(value);
|
|
122
119
|
const swiftName = propertyName(key, registry.camelCaseProperties);
|
|
123
120
|
const previousWireName = seen.get(swiftName);
|
|
@@ -126,10 +123,9 @@ const objectFields = (schema, registry, hint, nullishTriState = true, shape = re
|
|
|
126
123
|
fields.push({
|
|
127
124
|
name: swiftName,
|
|
128
125
|
wireName: key,
|
|
129
|
-
type:
|
|
130
|
-
optional: result.optional
|
|
126
|
+
type: result.expression,
|
|
127
|
+
optional: result.optional,
|
|
131
128
|
requiredNullable: result.requiredNullable,
|
|
132
|
-
nullish,
|
|
133
129
|
description: readMetaDescription(value),
|
|
134
130
|
isFile: result.isFile,
|
|
135
131
|
deprecated: deprecation !== void 0,
|
|
@@ -242,7 +238,6 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
242
238
|
expression: innerResult.expression.endsWith("?") ? innerResult.expression : `${innerResult.expression}?`,
|
|
243
239
|
optional: true,
|
|
244
240
|
requiredNullable: nullable && !optional,
|
|
245
|
-
nullish: nullable && optional,
|
|
246
241
|
isFile: innerResult.isFile
|
|
247
242
|
};
|
|
248
243
|
}
|
|
@@ -424,13 +419,10 @@ const sanitizeCaseName = (literal) => {
|
|
|
424
419
|
if (/^[0-9]/.test(cleaned)) return `_${cleaned}`;
|
|
425
420
|
return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
|
|
426
421
|
};
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
*/
|
|
430
|
-
const collectObjectFields = (schema, registry, hint, json = false) => {
|
|
431
|
-
return objectFields(schema, registry, hint, json);
|
|
422
|
+
const collectObjectFields = (schema, registry, hint) => {
|
|
423
|
+
return objectFields(schema, registry, hint);
|
|
432
424
|
};
|
|
433
|
-
const hasDefault = (field) => field.optional && field.requiredNullable !== true
|
|
425
|
+
const hasDefault = (field) => field.optional && field.requiredNullable !== true;
|
|
434
426
|
const objectFieldCount = (schema) => {
|
|
435
427
|
return Object.keys(readObjectShape(schema) ?? {}).length;
|
|
436
428
|
};
|
|
@@ -487,7 +479,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
487
479
|
else bodyDescriptor = {
|
|
488
480
|
kind: "json-flat",
|
|
489
481
|
structName,
|
|
490
|
-
flattened: collectObjectFields(route.body, registry, bodyHint
|
|
482
|
+
flattened: collectObjectFields(route.body, registry, bodyHint),
|
|
491
483
|
multipartFields: []
|
|
492
484
|
};
|
|
493
485
|
}
|
|
@@ -707,62 +699,9 @@ const sanitizeEnumCaseName = (value) => {
|
|
|
707
699
|
if (!camel) return "_";
|
|
708
700
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
709
701
|
};
|
|
710
|
-
const NULLISH_TYPE = /^Nullish<(.+)>$/;
|
|
711
|
-
const emitNullish = (writer) => {
|
|
712
|
-
writer.blank();
|
|
713
|
-
writer.docComment("A `.nullish()` field: left out, sent as `null`, or sent with a value.");
|
|
714
|
-
writer.block("public enum Nullish<Wrapped>", () => {
|
|
715
|
-
writer.line("case absent");
|
|
716
|
-
writer.line("case null");
|
|
717
|
-
writer.line("case some(Wrapped)");
|
|
718
|
-
writer.blank();
|
|
719
|
-
writer.block("public var value: Wrapped?", () => {
|
|
720
|
-
writer.line("if case .some(let value) = self { return value }");
|
|
721
|
-
writer.line("return nil");
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
writer.blank();
|
|
725
|
-
writer.line("extension Nullish: Sendable where Wrapped: Sendable {}");
|
|
726
|
-
writer.line("extension Nullish: Equatable where Wrapped: Equatable {}");
|
|
727
|
-
writer.line("extension Nullish: Hashable where Wrapped: Hashable {}");
|
|
728
|
-
writer.blank();
|
|
729
|
-
writer.block("extension Nullish: Encodable where Wrapped: Encodable", () => {
|
|
730
|
-
writer.block("public func encode(to encoder: Encoder) throws", () => {
|
|
731
|
-
writer.line("var container = encoder.singleValueContainer()");
|
|
732
|
-
writer.line("switch self {");
|
|
733
|
-
writer.line("case .absent, .null: try container.encodeNil()");
|
|
734
|
-
writer.line("case .some(let value): try container.encode(value)");
|
|
735
|
-
writer.line("}");
|
|
736
|
-
});
|
|
737
|
-
});
|
|
738
|
-
writer.blank();
|
|
739
|
-
writer.block("extension Nullish: Decodable where Wrapped: Decodable", () => {
|
|
740
|
-
writer.block("public init(from decoder: Decoder) throws", () => {
|
|
741
|
-
writer.line("let container = try decoder.singleValueContainer()");
|
|
742
|
-
writer.line("self = container.decodeNil() ? .null : .some(try container.decode(Wrapped.self))");
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
writer.blank();
|
|
746
|
-
writer.block("extension KeyedEncodingContainer", () => {
|
|
747
|
-
writer.block("public mutating func encode<Wrapped: Encodable>(_ value: Nullish<Wrapped>, forKey key: Key) throws", () => {
|
|
748
|
-
writer.line("switch value {");
|
|
749
|
-
writer.line("case .absent: return");
|
|
750
|
-
writer.line("case .null: try encodeNil(forKey: key)");
|
|
751
|
-
writer.line("case .some(let wrapped): try encode(wrapped, forKey: key)");
|
|
752
|
-
writer.line("}");
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
writer.blank();
|
|
756
|
-
writer.block("extension KeyedDecodingContainer", () => {
|
|
757
|
-
writer.block("public func decode<Wrapped: Decodable>(_ type: Nullish<Wrapped>.Type, forKey key: Key) throws -> Nullish<Wrapped>", () => {
|
|
758
|
-
writer.line("guard contains(key) else { return .absent }");
|
|
759
|
-
writer.line("return try decodeNil(forKey: key) ? .null : .some(try decode(Wrapped.self, forKey: key))");
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
};
|
|
763
702
|
const defaultArgument = (field) => {
|
|
764
703
|
if (!hasDefault(field)) return "";
|
|
765
|
-
return
|
|
704
|
+
return " = nil";
|
|
766
705
|
};
|
|
767
706
|
const optionalize = (type, optional) => {
|
|
768
707
|
if (!optional) return type;
|
|
@@ -919,8 +858,6 @@ const emitStruct = (writer, type, context, ownedTypeMap, ownedTypeLookup, regist
|
|
|
919
858
|
const hasFile = type.fields.some((field) => field.isFile);
|
|
920
859
|
const conformances = hasFile ? "Sendable, Equatable" : "Codable, Sendable, Equatable";
|
|
921
860
|
const resolveOwnedType = (raw) => {
|
|
922
|
-
const nullish = NULLISH_TYPE.exec(raw);
|
|
923
|
-
if (nullish) return `Nullish<${resolveOwnedType(nullish[1])}>`;
|
|
924
861
|
const optional = raw.endsWith("?");
|
|
925
862
|
const stripped = optional ? raw.slice(0, -1) : raw;
|
|
926
863
|
const isArray = stripped.startsWith("[") && stripped.endsWith("]");
|
|
@@ -1109,8 +1046,6 @@ const dictionarySeparator = (inner) => {
|
|
|
1109
1046
|
};
|
|
1110
1047
|
const resolveType = (typeName, currentOperation, context, scope = "actor") => {
|
|
1111
1048
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
1112
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
1113
|
-
if (nullish) return `Nullish<${resolveType(nullish[1], currentOperation, context, scope)}>`;
|
|
1114
1049
|
const optional = typeName.endsWith("?");
|
|
1115
1050
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
1116
1051
|
if (SWIFT_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
@@ -1406,7 +1341,7 @@ const emitKizunaStreaming = (writer) => {
|
|
|
1406
1341
|
writer.line("let retry: Int?");
|
|
1407
1342
|
});
|
|
1408
1343
|
writer.blank();
|
|
1409
|
-
writer.block("static func open<Failure: KizunaFailure>(_ request: inout URLRequest, session: URLSession, requestMiddleware: (@Sendable (inout URLRequest) async throws -> Void)?, failure: Failure.Type) async throws(Failure) -> (URLSession.AsyncBytes, Int, HTTPURLResponse)", () => {
|
|
1344
|
+
writer.block("static func open<Failure: KizunaFailure>(_ request: inout URLRequest, session: URLSession, requestMiddleware: (@Sendable (inout URLRequest) async throws -> Void)?, responseMiddleware: (@Sendable (URLRequest, Foundation.Data, URLResponse) async -> Void)?, failure: Failure.Type) async throws(Failure) -> (URLSession.AsyncBytes, Int, HTTPURLResponse)", () => {
|
|
1410
1345
|
writer.line("if let requestMiddleware {");
|
|
1411
1346
|
writer.line(" do { try await requestMiddleware(&request) }");
|
|
1412
1347
|
writer.line(" catch is CancellationError { throw Failure.cancelled }");
|
|
@@ -1419,6 +1354,7 @@ const emitKizunaStreaming = (writer) => {
|
|
|
1419
1354
|
writer.line("catch is CancellationError { throw Failure.cancelled }");
|
|
1420
1355
|
writer.line("catch let error as URLError where error.code == .cancelled { throw Failure.cancelled }");
|
|
1421
1356
|
writer.line("catch { throw Failure.requestFailed(error) }");
|
|
1357
|
+
writer.line("if let responseMiddleware { await responseMiddleware(request, Foundation.Data(), response) }");
|
|
1422
1358
|
writer.line("guard let httpResponse = response as? HTTPURLResponse else { throw Failure.invalidResponse }");
|
|
1423
1359
|
writer.line("return (bytes, httpResponse.statusCode, httpResponse)");
|
|
1424
1360
|
});
|
|
@@ -1873,7 +1809,7 @@ const emitStreamMethodTail = (writer, method, context, receiver, responseBinding
|
|
|
1873
1809
|
const qualifiedResult = `${context.clientName}.${method.operationName}.${method.resultWrapperName}`;
|
|
1874
1810
|
const hasHeaders = method.resultHeaderFields.length > 0;
|
|
1875
1811
|
const collect = `let data = try await Kizuna.collect(bytes, failure: ${failure}.self)`;
|
|
1876
|
-
writer.line(`let (bytes, statusCode, ${responseBinding}) = try await Kizuna.open(&request, session: ${receiver}session, requestMiddleware: ${receiver}requestMiddleware, failure: ${failure}.self)`);
|
|
1812
|
+
writer.line(`let (bytes, statusCode, ${responseBinding}) = try await Kizuna.open(&request, session: ${receiver}session, requestMiddleware: ${receiver}requestMiddleware, responseMiddleware: ${receiver}responseMiddleware, failure: ${failure}.self)`);
|
|
1877
1813
|
writer.line("switch statusCode {");
|
|
1878
1814
|
writer.line(`case ${stream.status}:`);
|
|
1879
1815
|
writer.indent(() => {
|
|
@@ -2215,7 +2151,6 @@ const renderSwiftClient = (api, partition, registry, options) => {
|
|
|
2215
2151
|
anyCodable: registry.usesAnyCodable
|
|
2216
2152
|
}, partition, context, typesByOperation);
|
|
2217
2153
|
for (const group of partition.groups) emitSubClientStruct(writer, group, clientName, context);
|
|
2218
|
-
if (registry.usesNullish) emitNullish(writer);
|
|
2219
2154
|
emitKizunaFailureProtocols(writer);
|
|
2220
2155
|
emitKizunaNamespace(writer, {
|
|
2221
2156
|
multipart: usesMultipart,
|
|
@@ -47,7 +47,6 @@ var TypeRegistry = class {
|
|
|
47
47
|
unionVariantOwners = /* @__PURE__ */ new Map();
|
|
48
48
|
brands = /* @__PURE__ */ new Map();
|
|
49
49
|
usesAnyCodable = false;
|
|
50
|
-
usesNullish = false;
|
|
51
50
|
constructor(camelCaseProperties = false, unknownEnumCase = false) {
|
|
52
51
|
this.camelCaseProperties = camelCaseProperties;
|
|
53
52
|
this.unknownEnumCase = unknownEnumCase;
|
|
@@ -111,13 +110,11 @@ const propertyName = (key, camelCase) => {
|
|
|
111
110
|
if (!camel) return "field";
|
|
112
111
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
113
112
|
};
|
|
114
|
-
const objectFields = (schema, registry, hint,
|
|
113
|
+
const objectFields = (schema, registry, hint, shape = (0, kizunajs_generator.readObjectShape)(schema) ?? {}) => {
|
|
115
114
|
const fields = [];
|
|
116
115
|
const seen = /* @__PURE__ */ new Map();
|
|
117
116
|
for (const [key, value] of Object.entries(shape)) {
|
|
118
117
|
const result = mapType(value, registry, `${hint}${(0, kizunajs_generator.toPascalCase)(key)}`);
|
|
119
|
-
const nullish = nullishTriState && result.nullish === true;
|
|
120
|
-
if (nullish) registry.usesNullish = true;
|
|
121
118
|
const deprecation = (0, kizunajs_generator.readDeprecation)(value);
|
|
122
119
|
const swiftName = propertyName(key, registry.camelCaseProperties);
|
|
123
120
|
const previousWireName = seen.get(swiftName);
|
|
@@ -126,10 +123,9 @@ const objectFields = (schema, registry, hint, nullishTriState = true, shape = (0
|
|
|
126
123
|
fields.push({
|
|
127
124
|
name: swiftName,
|
|
128
125
|
wireName: key,
|
|
129
|
-
type:
|
|
130
|
-
optional: result.optional
|
|
126
|
+
type: result.expression,
|
|
127
|
+
optional: result.optional,
|
|
131
128
|
requiredNullable: result.requiredNullable,
|
|
132
|
-
nullish,
|
|
133
129
|
description: (0, kizunajs_generator.readMetaDescription)(value),
|
|
134
130
|
isFile: result.isFile,
|
|
135
131
|
deprecated: deprecation !== void 0,
|
|
@@ -242,7 +238,6 @@ const mapUnbrandedType = (schema, registry, hint) => {
|
|
|
242
238
|
expression: innerResult.expression.endsWith("?") ? innerResult.expression : `${innerResult.expression}?`,
|
|
243
239
|
optional: true,
|
|
244
240
|
requiredNullable: nullable && !optional,
|
|
245
|
-
nullish: nullable && optional,
|
|
246
241
|
isFile: innerResult.isFile
|
|
247
242
|
};
|
|
248
243
|
}
|
|
@@ -424,13 +419,10 @@ const sanitizeCaseName = (literal) => {
|
|
|
424
419
|
if (/^[0-9]/.test(cleaned)) return `_${cleaned}`;
|
|
425
420
|
return cleaned.charAt(0).toLowerCase() + cleaned.slice(1);
|
|
426
421
|
};
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
*/
|
|
430
|
-
const collectObjectFields = (schema, registry, hint, json = false) => {
|
|
431
|
-
return objectFields(schema, registry, hint, json);
|
|
422
|
+
const collectObjectFields = (schema, registry, hint) => {
|
|
423
|
+
return objectFields(schema, registry, hint);
|
|
432
424
|
};
|
|
433
|
-
const hasDefault = (field) => field.optional && field.requiredNullable !== true
|
|
425
|
+
const hasDefault = (field) => field.optional && field.requiredNullable !== true;
|
|
434
426
|
const objectFieldCount = (schema) => {
|
|
435
427
|
return Object.keys((0, kizunajs_generator.readObjectShape)(schema) ?? {}).length;
|
|
436
428
|
};
|
|
@@ -487,7 +479,7 @@ const buildRouteMethod = (routeKey, route, registry, deprecated, deprecationMess
|
|
|
487
479
|
else bodyDescriptor = {
|
|
488
480
|
kind: "json-flat",
|
|
489
481
|
structName,
|
|
490
|
-
flattened: collectObjectFields(route.body, registry, bodyHint
|
|
482
|
+
flattened: collectObjectFields(route.body, registry, bodyHint),
|
|
491
483
|
multipartFields: []
|
|
492
484
|
};
|
|
493
485
|
}
|
|
@@ -707,62 +699,9 @@ const sanitizeEnumCaseName = (value) => {
|
|
|
707
699
|
if (!camel) return "_";
|
|
708
700
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
709
701
|
};
|
|
710
|
-
const NULLISH_TYPE = /^Nullish<(.+)>$/;
|
|
711
|
-
const emitNullish = (writer) => {
|
|
712
|
-
writer.blank();
|
|
713
|
-
writer.docComment("A `.nullish()` field: left out, sent as `null`, or sent with a value.");
|
|
714
|
-
writer.block("public enum Nullish<Wrapped>", () => {
|
|
715
|
-
writer.line("case absent");
|
|
716
|
-
writer.line("case null");
|
|
717
|
-
writer.line("case some(Wrapped)");
|
|
718
|
-
writer.blank();
|
|
719
|
-
writer.block("public var value: Wrapped?", () => {
|
|
720
|
-
writer.line("if case .some(let value) = self { return value }");
|
|
721
|
-
writer.line("return nil");
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
writer.blank();
|
|
725
|
-
writer.line("extension Nullish: Sendable where Wrapped: Sendable {}");
|
|
726
|
-
writer.line("extension Nullish: Equatable where Wrapped: Equatable {}");
|
|
727
|
-
writer.line("extension Nullish: Hashable where Wrapped: Hashable {}");
|
|
728
|
-
writer.blank();
|
|
729
|
-
writer.block("extension Nullish: Encodable where Wrapped: Encodable", () => {
|
|
730
|
-
writer.block("public func encode(to encoder: Encoder) throws", () => {
|
|
731
|
-
writer.line("var container = encoder.singleValueContainer()");
|
|
732
|
-
writer.line("switch self {");
|
|
733
|
-
writer.line("case .absent, .null: try container.encodeNil()");
|
|
734
|
-
writer.line("case .some(let value): try container.encode(value)");
|
|
735
|
-
writer.line("}");
|
|
736
|
-
});
|
|
737
|
-
});
|
|
738
|
-
writer.blank();
|
|
739
|
-
writer.block("extension Nullish: Decodable where Wrapped: Decodable", () => {
|
|
740
|
-
writer.block("public init(from decoder: Decoder) throws", () => {
|
|
741
|
-
writer.line("let container = try decoder.singleValueContainer()");
|
|
742
|
-
writer.line("self = container.decodeNil() ? .null : .some(try container.decode(Wrapped.self))");
|
|
743
|
-
});
|
|
744
|
-
});
|
|
745
|
-
writer.blank();
|
|
746
|
-
writer.block("extension KeyedEncodingContainer", () => {
|
|
747
|
-
writer.block("public mutating func encode<Wrapped: Encodable>(_ value: Nullish<Wrapped>, forKey key: Key) throws", () => {
|
|
748
|
-
writer.line("switch value {");
|
|
749
|
-
writer.line("case .absent: return");
|
|
750
|
-
writer.line("case .null: try encodeNil(forKey: key)");
|
|
751
|
-
writer.line("case .some(let wrapped): try encode(wrapped, forKey: key)");
|
|
752
|
-
writer.line("}");
|
|
753
|
-
});
|
|
754
|
-
});
|
|
755
|
-
writer.blank();
|
|
756
|
-
writer.block("extension KeyedDecodingContainer", () => {
|
|
757
|
-
writer.block("public func decode<Wrapped: Decodable>(_ type: Nullish<Wrapped>.Type, forKey key: Key) throws -> Nullish<Wrapped>", () => {
|
|
758
|
-
writer.line("guard contains(key) else { return .absent }");
|
|
759
|
-
writer.line("return try decodeNil(forKey: key) ? .null : .some(try decode(Wrapped.self, forKey: key))");
|
|
760
|
-
});
|
|
761
|
-
});
|
|
762
|
-
};
|
|
763
702
|
const defaultArgument = (field) => {
|
|
764
703
|
if (!hasDefault(field)) return "";
|
|
765
|
-
return
|
|
704
|
+
return " = nil";
|
|
766
705
|
};
|
|
767
706
|
const optionalize = (type, optional) => {
|
|
768
707
|
if (!optional) return type;
|
|
@@ -919,8 +858,6 @@ const emitStruct = (writer, type, context, ownedTypeMap, ownedTypeLookup, regist
|
|
|
919
858
|
const hasFile = type.fields.some((field) => field.isFile);
|
|
920
859
|
const conformances = hasFile ? "Sendable, Equatable" : "Codable, Sendable, Equatable";
|
|
921
860
|
const resolveOwnedType = (raw) => {
|
|
922
|
-
const nullish = NULLISH_TYPE.exec(raw);
|
|
923
|
-
if (nullish) return `Nullish<${resolveOwnedType(nullish[1])}>`;
|
|
924
861
|
const optional = raw.endsWith("?");
|
|
925
862
|
const stripped = optional ? raw.slice(0, -1) : raw;
|
|
926
863
|
const isArray = stripped.startsWith("[") && stripped.endsWith("]");
|
|
@@ -1109,8 +1046,6 @@ const dictionarySeparator = (inner) => {
|
|
|
1109
1046
|
};
|
|
1110
1047
|
const resolveType = (typeName, currentOperation, context, scope = "actor") => {
|
|
1111
1048
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
1112
|
-
const nullish = NULLISH_TYPE.exec(typeName);
|
|
1113
|
-
if (nullish) return `Nullish<${resolveType(nullish[1], currentOperation, context, scope)}>`;
|
|
1114
1049
|
const optional = typeName.endsWith("?");
|
|
1115
1050
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
1116
1051
|
if (SWIFT_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
@@ -1406,7 +1341,7 @@ const emitKizunaStreaming = (writer) => {
|
|
|
1406
1341
|
writer.line("let retry: Int?");
|
|
1407
1342
|
});
|
|
1408
1343
|
writer.blank();
|
|
1409
|
-
writer.block("static func open<Failure: KizunaFailure>(_ request: inout URLRequest, session: URLSession, requestMiddleware: (@Sendable (inout URLRequest) async throws -> Void)?, failure: Failure.Type) async throws(Failure) -> (URLSession.AsyncBytes, Int, HTTPURLResponse)", () => {
|
|
1344
|
+
writer.block("static func open<Failure: KizunaFailure>(_ request: inout URLRequest, session: URLSession, requestMiddleware: (@Sendable (inout URLRequest) async throws -> Void)?, responseMiddleware: (@Sendable (URLRequest, Foundation.Data, URLResponse) async -> Void)?, failure: Failure.Type) async throws(Failure) -> (URLSession.AsyncBytes, Int, HTTPURLResponse)", () => {
|
|
1410
1345
|
writer.line("if let requestMiddleware {");
|
|
1411
1346
|
writer.line(" do { try await requestMiddleware(&request) }");
|
|
1412
1347
|
writer.line(" catch is CancellationError { throw Failure.cancelled }");
|
|
@@ -1419,6 +1354,7 @@ const emitKizunaStreaming = (writer) => {
|
|
|
1419
1354
|
writer.line("catch is CancellationError { throw Failure.cancelled }");
|
|
1420
1355
|
writer.line("catch let error as URLError where error.code == .cancelled { throw Failure.cancelled }");
|
|
1421
1356
|
writer.line("catch { throw Failure.requestFailed(error) }");
|
|
1357
|
+
writer.line("if let responseMiddleware { await responseMiddleware(request, Foundation.Data(), response) }");
|
|
1422
1358
|
writer.line("guard let httpResponse = response as? HTTPURLResponse else { throw Failure.invalidResponse }");
|
|
1423
1359
|
writer.line("return (bytes, httpResponse.statusCode, httpResponse)");
|
|
1424
1360
|
});
|
|
@@ -1873,7 +1809,7 @@ const emitStreamMethodTail = (writer, method, context, receiver, responseBinding
|
|
|
1873
1809
|
const qualifiedResult = `${context.clientName}.${method.operationName}.${method.resultWrapperName}`;
|
|
1874
1810
|
const hasHeaders = method.resultHeaderFields.length > 0;
|
|
1875
1811
|
const collect = `let data = try await Kizuna.collect(bytes, failure: ${failure}.self)`;
|
|
1876
|
-
writer.line(`let (bytes, statusCode, ${responseBinding}) = try await Kizuna.open(&request, session: ${receiver}session, requestMiddleware: ${receiver}requestMiddleware, failure: ${failure}.self)`);
|
|
1812
|
+
writer.line(`let (bytes, statusCode, ${responseBinding}) = try await Kizuna.open(&request, session: ${receiver}session, requestMiddleware: ${receiver}requestMiddleware, responseMiddleware: ${receiver}responseMiddleware, failure: ${failure}.self)`);
|
|
1877
1813
|
writer.line("switch statusCode {");
|
|
1878
1814
|
writer.line(`case ${stream.status}:`);
|
|
1879
1815
|
writer.indent(() => {
|
|
@@ -2215,7 +2151,6 @@ const renderSwiftClient = (api, partition, registry, options) => {
|
|
|
2215
2151
|
anyCodable: registry.usesAnyCodable
|
|
2216
2152
|
}, partition, context, typesByOperation);
|
|
2217
2153
|
for (const group of partition.groups) emitSubClientStruct(writer, group, clientName, context);
|
|
2218
|
-
if (registry.usesNullish) emitNullish(writer);
|
|
2219
2154
|
emitKizunaFailureProtocols(writer);
|
|
2220
2155
|
emitKizunaNamespace(writer, {
|
|
2221
2156
|
multipart: usesMultipart,
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generator = require("./generator-
|
|
2
|
+
const require_generator = require("./generator-DBNFuaBB.cjs");
|
|
3
3
|
let kizunajs_generator = require("kizunajs/generator");
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
//#region src/client-target.ts
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kizunajs/swift",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.19",
|
|
4
4
|
"description": "Swift client generation for Kizuna.js APIs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kizunajs",
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@kizunajs/cli": "2.0.0-beta.
|
|
62
|
+
"@kizunajs/cli": "2.0.0-beta.19"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"kizunajs": "2.0.0-beta.
|
|
65
|
+
"kizunajs": "2.0.0-beta.19",
|
|
66
66
|
"zod": "^4.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"kizunajs": "2.0.0-beta.
|
|
69
|
+
"kizunajs": "2.0.0-beta.19",
|
|
70
70
|
"@types/node": "^24",
|
|
71
71
|
"tsdown": "^0.21.0",
|
|
72
72
|
"typescript": "^6.0.3",
|