@kizunajs/swift 2.0.0-beta.3 → 2.0.0-beta.4
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/README.md +17 -1
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{generator-BpGEeivv.cjs → generator-BAginTbM.cjs} +24 -4
- package/dist/{generator-DfFjWZhf.mjs → generator-DXJbInzN.mjs} +24 -4
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,8 +10,24 @@ pnpm add -D @kizunajs/swift
|
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
+
Name the client in your config, and `kizuna generate` writes it with the rest:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { swiftClient } from '@kizunajs/swift';
|
|
17
|
+
|
|
18
|
+
export default defineConfig({
|
|
19
|
+
routes,
|
|
20
|
+
clients: [
|
|
21
|
+
swiftClient({
|
|
22
|
+
output: '../ios/MyApp/Generated/APIClient.swift',
|
|
23
|
+
namespace: 'API',
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
13
29
|
```sh
|
|
14
|
-
kizuna
|
|
30
|
+
kizuna generate
|
|
15
31
|
```
|
|
16
32
|
|
|
17
33
|
## Documentation
|
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-DXJbInzN.mjs";
|
|
3
3
|
import { mkdirSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { dirname, resolve } from "node:path";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
@@ -100,8 +100,7 @@ const propertyName = (key, camelCase) => {
|
|
|
100
100
|
if (!camel) return "field";
|
|
101
101
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
102
102
|
};
|
|
103
|
-
const objectFields = (schema, registry, hint) => {
|
|
104
|
-
const shape = (0, kizunajs_generator.readObjectShape)(schema) ?? {};
|
|
103
|
+
const objectFields = (schema, registry, hint, shape = (0, kizunajs_generator.readObjectShape)(schema) ?? {}) => {
|
|
105
104
|
const fields = [];
|
|
106
105
|
const seen = /* @__PURE__ */ new Map();
|
|
107
106
|
for (const [key, value] of Object.entries(shape)) {
|
|
@@ -253,8 +252,9 @@ const mapType = (schema, registry, hint) => {
|
|
|
253
252
|
optional: false
|
|
254
253
|
};
|
|
255
254
|
}
|
|
255
|
+
const elementType = mapType(element, registry, `${hint}Item`).expression.replace(/\?$/, "");
|
|
256
256
|
return {
|
|
257
|
-
expression: `[${
|
|
257
|
+
expression: `[${(0, kizunajs_generator.unwrapOptionalWrappers)(element).nullable ? `${elementType}?` : elementType}]`,
|
|
258
258
|
optional: false
|
|
259
259
|
};
|
|
260
260
|
}
|
|
@@ -955,13 +955,33 @@ const SWIFT_PRIMITIVE_TYPES = new Set([
|
|
|
955
955
|
"Void",
|
|
956
956
|
"Foundation.Data"
|
|
957
957
|
]);
|
|
958
|
+
/**
|
|
959
|
+
* Where a dictionary's key ends and its value begins, or -1 for an array.
|
|
960
|
+
*/
|
|
961
|
+
const dictionarySeparator = (inner) => {
|
|
962
|
+
let depth = 0;
|
|
963
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
964
|
+
const character = inner[index];
|
|
965
|
+
if (character === "[") depth += 1;
|
|
966
|
+
else if (character === "]") depth -= 1;
|
|
967
|
+
else if (character === ":" && depth === 0) return index;
|
|
968
|
+
}
|
|
969
|
+
return -1;
|
|
970
|
+
};
|
|
958
971
|
const resolveType = (typeName, currentOperation, context, scope = "actor") => {
|
|
959
972
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
960
973
|
const optional = typeName.endsWith("?");
|
|
961
974
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
962
975
|
if (SWIFT_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
963
976
|
if (base.startsWith("[") && base.endsWith("]")) {
|
|
964
|
-
const
|
|
977
|
+
const inner = base.slice(1, -1);
|
|
978
|
+
const separator = dictionarySeparator(inner);
|
|
979
|
+
if (separator !== -1) {
|
|
980
|
+
const key = resolveType(inner.slice(0, separator).trim(), currentOperation, context, scope);
|
|
981
|
+
const value = resolveType(inner.slice(separator + 1).trim(), currentOperation, context, scope);
|
|
982
|
+
return optional ? `[${key}: ${value}]?` : `[${key}: ${value}]`;
|
|
983
|
+
}
|
|
984
|
+
const resolved = resolveType(inner, currentOperation, context, scope);
|
|
965
985
|
return optional ? `[${resolved}]?` : `[${resolved}]`;
|
|
966
986
|
}
|
|
967
987
|
if (base === "MultipartFile" || base === "ValidationError" || base === "ValidationIssue") {
|
|
@@ -100,8 +100,7 @@ const propertyName = (key, camelCase) => {
|
|
|
100
100
|
if (!camel) return "field";
|
|
101
101
|
return /^[0-9]/.test(camel) ? `_${camel}` : camel;
|
|
102
102
|
};
|
|
103
|
-
const objectFields = (schema, registry, hint) => {
|
|
104
|
-
const shape = readObjectShape(schema) ?? {};
|
|
103
|
+
const objectFields = (schema, registry, hint, shape = readObjectShape(schema) ?? {}) => {
|
|
105
104
|
const fields = [];
|
|
106
105
|
const seen = /* @__PURE__ */ new Map();
|
|
107
106
|
for (const [key, value] of Object.entries(shape)) {
|
|
@@ -253,8 +252,9 @@ const mapType = (schema, registry, hint) => {
|
|
|
253
252
|
optional: false
|
|
254
253
|
};
|
|
255
254
|
}
|
|
255
|
+
const elementType = mapType(element, registry, `${hint}Item`).expression.replace(/\?$/, "");
|
|
256
256
|
return {
|
|
257
|
-
expression: `[${
|
|
257
|
+
expression: `[${unwrapOptionalWrappers(element).nullable ? `${elementType}?` : elementType}]`,
|
|
258
258
|
optional: false
|
|
259
259
|
};
|
|
260
260
|
}
|
|
@@ -955,13 +955,33 @@ const SWIFT_PRIMITIVE_TYPES = new Set([
|
|
|
955
955
|
"Void",
|
|
956
956
|
"Foundation.Data"
|
|
957
957
|
]);
|
|
958
|
+
/**
|
|
959
|
+
* Where a dictionary's key ends and its value begins, or -1 for an array.
|
|
960
|
+
*/
|
|
961
|
+
const dictionarySeparator = (inner) => {
|
|
962
|
+
let depth = 0;
|
|
963
|
+
for (let index = 0; index < inner.length; index += 1) {
|
|
964
|
+
const character = inner[index];
|
|
965
|
+
if (character === "[") depth += 1;
|
|
966
|
+
else if (character === "]") depth -= 1;
|
|
967
|
+
else if (character === ":" && depth === 0) return index;
|
|
968
|
+
}
|
|
969
|
+
return -1;
|
|
970
|
+
};
|
|
958
971
|
const resolveType = (typeName, currentOperation, context, scope = "actor") => {
|
|
959
972
|
const { operationTypeMap, namespaceName, clientName, fileLevelTypeNames } = context;
|
|
960
973
|
const optional = typeName.endsWith("?");
|
|
961
974
|
const base = optional ? typeName.slice(0, -1) : typeName;
|
|
962
975
|
if (SWIFT_PRIMITIVE_TYPES.has(base)) return typeName;
|
|
963
976
|
if (base.startsWith("[") && base.endsWith("]")) {
|
|
964
|
-
const
|
|
977
|
+
const inner = base.slice(1, -1);
|
|
978
|
+
const separator = dictionarySeparator(inner);
|
|
979
|
+
if (separator !== -1) {
|
|
980
|
+
const key = resolveType(inner.slice(0, separator).trim(), currentOperation, context, scope);
|
|
981
|
+
const value = resolveType(inner.slice(separator + 1).trim(), currentOperation, context, scope);
|
|
982
|
+
return optional ? `[${key}: ${value}]?` : `[${key}: ${value}]`;
|
|
983
|
+
}
|
|
984
|
+
const resolved = resolveType(inner, currentOperation, context, scope);
|
|
965
985
|
return optional ? `[${resolved}]?` : `[${resolved}]`;
|
|
966
986
|
}
|
|
967
987
|
if (base === "MultipartFile" || base === "ValidationError" || base === "ValidationIssue") {
|
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-BAginTbM.cjs");
|
|
3
3
|
//#region src/client-target.ts
|
|
4
4
|
/**
|
|
5
5
|
* A Swift client target for `kizuna.config.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.4",
|
|
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.
|
|
62
|
+
"@kizunajs/cli": "2.0.0-beta.4"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"zod": "^4.0.0",
|
|
66
|
-
"kizunajs": "2.0.0-beta.
|
|
66
|
+
"kizunajs": "2.0.0-beta.4"
|
|
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.
|
|
73
|
+
"kizunajs": "2.0.0-beta.4"
|
|
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",
|