@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.
@@ -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, options)}`;
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, options)).join(", ");
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 (threshold && members.length > threshold) {
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, options)).join(" | ");
155
- return `${shownStr} | ... (${remaining} more)`;
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, options)).join(" | ");
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, options)).join(" & ");
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, options) : "unknown";
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, options)).join(", ");
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, options)}`).join("; ");
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.35.1",
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.35.1",
45
+ "@openpkg-ts/spec": "^0.37.0",
46
46
  "picomatch": "4.0.3",
47
47
  "typescript": "^5.0.0"
48
48
  },