@openpkg-ts/sdk 0.35.1 → 0.37.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/browser.d.ts +56 -9
- package/dist/browser.js +114 -1
- package/dist/index.d.ts +42 -15
- package/dist/index.js +618 -260
- package/dist/shared/{chunk-4fgxg5jj.js → chunk-hnajr1tb.js} +16 -11
- package/package.json +2 -2
|
@@ -115,6 +115,11 @@ function formatSchema(schema, options) {
|
|
|
115
115
|
return "unknown";
|
|
116
116
|
if (typeof schema === "string")
|
|
117
117
|
return schema;
|
|
118
|
+
const depth = options?._depth ?? 0;
|
|
119
|
+
const maxDepth = options?.maxDepth ?? 3;
|
|
120
|
+
if (depth >= maxDepth)
|
|
121
|
+
return "...";
|
|
122
|
+
const nextOpts = { ...options, _depth: depth + 1 };
|
|
118
123
|
const withPackage = (typeStr) => {
|
|
119
124
|
if (options?.includePackage && typeof schema === "object" && "x-ts-package" in schema) {
|
|
120
125
|
const pkg = schema["x-ts-package"];
|
|
@@ -135,41 +140,41 @@ function formatSchema(schema, options) {
|
|
|
135
140
|
}
|
|
136
141
|
if ("x-ts-type-predicate" in schema) {
|
|
137
142
|
const pred = schema["x-ts-type-predicate"];
|
|
138
|
-
return `${pred.parameterName} is ${formatSchema(pred.type,
|
|
143
|
+
return `${pred.parameterName} is ${formatSchema(pred.type, nextOpts)}`;
|
|
139
144
|
}
|
|
140
145
|
if ("$ref" in schema && typeof schema.$ref === "string") {
|
|
141
146
|
const baseName = schema.$ref.replace("#/types/", "");
|
|
142
147
|
if ("x-ts-type-arguments" in schema && Array.isArray(schema["x-ts-type-arguments"])) {
|
|
143
|
-
const args = schema["x-ts-type-arguments"].map((s) => formatSchema(s,
|
|
148
|
+
const args = schema["x-ts-type-arguments"].map((s) => formatSchema(s, nextOpts)).join(", ");
|
|
144
149
|
return withPackage(`${baseName}<${args}>`);
|
|
145
150
|
}
|
|
146
151
|
return withPackage(baseName);
|
|
147
152
|
}
|
|
148
153
|
if ("anyOf" in schema && Array.isArray(schema.anyOf)) {
|
|
149
|
-
const threshold = options?.collapseUnionThreshold;
|
|
154
|
+
const threshold = options?.collapseUnionThreshold ?? 5;
|
|
150
155
|
const members = schema.anyOf;
|
|
151
|
-
if (
|
|
156
|
+
if (members.length > threshold) {
|
|
152
157
|
const shown = members.slice(0, 3);
|
|
153
158
|
const remaining = members.length - 3;
|
|
154
|
-
const shownStr = shown.map((s) => formatSchema(s,
|
|
155
|
-
return `${shownStr} | ...
|
|
159
|
+
const shownStr = shown.map((s) => formatSchema(s, nextOpts)).join(" | ");
|
|
160
|
+
return `${shownStr} | ... and ${remaining} more`;
|
|
156
161
|
}
|
|
157
|
-
return members.map((s) => formatSchema(s,
|
|
162
|
+
return members.map((s) => formatSchema(s, nextOpts)).join(" | ");
|
|
158
163
|
}
|
|
159
164
|
if ("allOf" in schema && Array.isArray(schema.allOf)) {
|
|
160
|
-
return schema.allOf.map((s) => formatSchema(s,
|
|
165
|
+
return schema.allOf.map((s) => formatSchema(s, nextOpts)).join(" & ");
|
|
161
166
|
}
|
|
162
167
|
if ("type" in schema && schema.type === "array") {
|
|
163
|
-
const items = "items" in schema ? formatSchema(schema.items,
|
|
168
|
+
const items = "items" in schema ? formatSchema(schema.items, nextOpts) : "unknown";
|
|
164
169
|
return `${items}[]`;
|
|
165
170
|
}
|
|
166
171
|
if ("type" in schema && schema.type === "tuple" && "items" in schema) {
|
|
167
|
-
const items = schema.items.map((s) => formatSchema(s,
|
|
172
|
+
const items = schema.items.map((s) => formatSchema(s, nextOpts)).join(", ");
|
|
168
173
|
return `[${items}]`;
|
|
169
174
|
}
|
|
170
175
|
if ("type" in schema && schema.type === "object") {
|
|
171
176
|
if ("properties" in schema && schema.properties) {
|
|
172
|
-
const props = Object.entries(schema.properties).map(([k, v]) => `${k}: ${formatSchema(v,
|
|
177
|
+
const props = Object.entries(schema.properties).map(([k, v]) => `${k}: ${formatSchema(v, nextOpts)}`).join("; ");
|
|
173
178
|
return `{ ${props} }`;
|
|
174
179
|
}
|
|
175
180
|
return "object";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test": "bun test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@openpkg-ts/spec": "^0.
|
|
45
|
+
"@openpkg-ts/spec": "^0.37.0",
|
|
46
46
|
"picomatch": "4.0.3",
|
|
47
47
|
"typescript": "^5.0.0"
|
|
48
48
|
},
|