@openpkg-ts/sdk 0.55.0 → 0.55.1

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/index.js CHANGED
@@ -18,6 +18,11 @@ import {
18
18
  groupByVisibility,
19
19
  isMethod,
20
20
  isProperty,
21
+ isRequiredOnlyAnyOf,
22
+ normalizeExport,
23
+ normalizeMembers,
24
+ normalizeSchema,
25
+ normalizeType,
21
26
  query,
22
27
  resolveTypeRef,
23
28
  sortByName,
@@ -25,7 +30,7 @@ import {
25
30
  toPagefindRecords,
26
31
  toSearchIndex,
27
32
  toSearchIndexJSON
28
- } from "./shared/chunk-pwvdnach.js";
33
+ } from "./shared/chunk-jfjmy1r0.js";
29
34
 
30
35
  // src/primitives/diff.ts
31
36
  import {
@@ -2897,6 +2902,23 @@ function declaredTypeNode(decl) {
2897
2902
  const withType = decl;
2898
2903
  return withType?.type;
2899
2904
  }
2905
+ function propertyTypeNode(prop) {
2906
+ const decls = prop.getDeclarations() ?? [];
2907
+ if (decls.length <= 1)
2908
+ return declaredTypeNode(prop.valueDeclaration ?? decls[0]);
2909
+ const nodes = decls.map(declaredTypeNode).filter((n) => n !== undefined);
2910
+ const informative = nodes.filter((n) => n.kind !== ts5.SyntaxKind.NeverKeyword && n.kind !== ts5.SyntaxKind.UndefinedKeyword);
2911
+ const [first, ...rest] = informative.length > 0 ? informative : nodes;
2912
+ if (!first)
2913
+ return;
2914
+ try {
2915
+ const text = (n) => n.getText().replace(/\s+/g, " ");
2916
+ const firstText = text(first);
2917
+ return rest.every((n) => text(n) === firstText) ? first : undefined;
2918
+ } catch {
2919
+ return;
2920
+ }
2921
+ }
2900
2922
  function typeNodeOfSignature(sig) {
2901
2923
  const decl = sig.getDeclaration();
2902
2924
  if (!decl || !ts5.isFunctionLike(decl))
@@ -3038,7 +3060,7 @@ function decoratePropertySchema(schema, prop, propType, checker) {
3038
3060
  let result = obj;
3039
3061
  if (!derivable && !("x-ts-type" in obj)) {
3040
3062
  result = { ...result, "x-ts-type": text };
3041
- const declared = writtenTypeText(declaredTypeNode(decl));
3063
+ const declared = writtenTypeText(propertyTypeNode(prop));
3042
3064
  if (declared && declared !== text && !PRIMITIVES.has(declared) && !("x-ts-declared" in obj)) {
3043
3065
  result = { ...result, "x-ts-declared": declared };
3044
3066
  }
@@ -3977,8 +3999,7 @@ function buildObjectSchema(properties, checker, ctx, originalType) {
3977
3999
  const isOptionalProp = !!(prop.flags & ts5.SymbolFlags.Optional);
3978
4000
  const rawPropType = checker.getTypeOfSymbol(prop);
3979
4001
  const propType = isOptionalProp ? stripUndefinedFromType(rawPropType, checker) : rawPropType;
3980
- const decl = prop.valueDeclaration ?? prop.getDeclarations()?.[0];
3981
- let propSchema = buildSchema(propType, checker, ctx, declaredTypeNode(decl));
4002
+ let propSchema = buildSchema(propType, checker, ctx, propertyTypeNode(prop));
3982
4003
  const docComment = prop.getDocumentationComment(checker);
3983
4004
  if (docComment.length > 0) {
3984
4005
  const description = docComment.map((c) => c.text).join(`
@@ -4645,12 +4666,22 @@ function resolvedProperties(type, checker) {
4645
4666
  const seen = new Map;
4646
4667
  for (const arm of objectArms(type, checker)) {
4647
4668
  for (const prop of armProperties(arm, checker)) {
4648
- if (!seen.has(prop.getName()))
4649
- seen.set(prop.getName(), prop);
4669
+ const name = prop.getName();
4670
+ const current = seen.get(name);
4671
+ if (!current || isAbsentMarker(current, checker) && !isAbsentMarker(prop, checker)) {
4672
+ seen.set(name, prop);
4673
+ }
4650
4674
  }
4651
4675
  }
4652
4676
  return [...seen.values()];
4653
4677
  }
4678
+ function isAbsentMarker(prop, checker) {
4679
+ const type = stripUndefinedFromType(checker.getTypeOfSymbol(prop), checker);
4680
+ return !!(type.flags & (ts7.TypeFlags.Never | ts7.TypeFlags.Undefined));
4681
+ }
4682
+ function armRequiredNames(arm, checker) {
4683
+ return new Set(armProperties(arm, checker).filter((p) => !(p.flags & ts7.SymbolFlags.Optional)).map((p) => p.getName()));
4684
+ }
4654
4685
  var PRIMITIVE_LIKE = ts7.TypeFlags.StringLike | ts7.TypeFlags.NumberLike | ts7.TypeFlags.BigIntLike | ts7.TypeFlags.BooleanLike | ts7.TypeFlags.ESSymbolLike | ts7.TypeFlags.Void | ts7.TypeFlags.Undefined | ts7.TypeFlags.Null;
4655
4686
  function objectArms(type, checker) {
4656
4687
  const arms = type.isUnion() ? type.types : [type];
@@ -4675,22 +4706,33 @@ function resolvedObjectSchema(schema, param, decl, isOptional, ctx) {
4675
4706
  const props = resolvedProperties(type, checker);
4676
4707
  const resolved = buildObjectSchema(props, checker, ctx, type);
4677
4708
  if (arms.length > 1) {
4678
- const requiredInAll = new Set(props.map((p) => p.getName()));
4679
- for (const arm of arms) {
4680
- const armRequired = new Set(armProperties(arm, checker).filter((p) => !(p.flags & ts7.SymbolFlags.Optional)).map((p) => p.getName()));
4681
- for (const name of [...requiredInAll])
4682
- if (!armRequired.has(name))
4683
- requiredInAll.delete(name);
4684
- }
4685
- const required = resolved.required?.filter((n) => requiredInAll.has(n));
4686
- if (required?.length)
4709
+ const perArm = arms.map((arm) => armRequiredNames(arm, checker));
4710
+ const requiredInAll = new Set(props.map((p) => p.getName()).filter((name) => perArm.every((set) => set.has(name))));
4711
+ const required = props.map((p) => p.getName()).filter((n) => requiredInAll.has(n));
4712
+ if (required.length)
4687
4713
  resolved.required = required;
4688
4714
  else
4689
4715
  delete resolved.required;
4716
+ const emitted = new Set(Object.keys(resolved.properties));
4717
+ const anyOf = perArmRequired(perArm, requiredInAll, emitted);
4718
+ if (anyOf)
4719
+ resolved.anyOf = anyOf;
4690
4720
  }
4691
4721
  resolved["x-ts-type"] = renderTypeText(type, checker, decl);
4692
4722
  return resolved;
4693
4723
  }
4724
+ function perArmRequired(perArm, shared, emitted) {
4725
+ const distinct = new Map;
4726
+ for (const set of perArm) {
4727
+ const extra = [...set].filter((name) => emitted.has(name) && !shared.has(name));
4728
+ if (extra.length === 0)
4729
+ return;
4730
+ distinct.set(extra.join("\x00"), extra);
4731
+ }
4732
+ if (distinct.size < 2)
4733
+ return;
4734
+ return [...distinct.values()].map((required) => ({ required }));
4735
+ }
4694
4736
  function annotateBindingElements(pattern, param, jsdocTags) {
4695
4737
  const schema = param.schema;
4696
4738
  const properties = schema?.properties;
@@ -5457,14 +5499,23 @@ function schemaFromTypeNode(node, ctx) {
5457
5499
  }
5458
5500
  function parametersFromAst(decl, ctx) {
5459
5501
  const jsdocTags = ts11.getJSDocTags(decl);
5502
+ const taken = new Set(decl.parameters.flatMap((p) => ts11.isIdentifier(p.name) ? [p.name.text] : []));
5460
5503
  return decl.parameters.map((p) => {
5461
- const name = ts11.isIdentifier(p.name) ? p.name.text : p.name.getText();
5504
+ const pattern = bindingPatternKind(p);
5505
+ let name;
5506
+ if (pattern) {
5507
+ name = destructuredParamName(pattern, taken);
5508
+ taken.add(name);
5509
+ } else {
5510
+ name = ts11.isIdentifier(p.name) ? p.name.text : p.name.getText();
5511
+ }
5462
5512
  const isOptional = !!p.questionToken || !!p.initializer;
5463
5513
  const param = {
5464
5514
  name,
5465
5515
  schema: schemaFromTypeNode(p.type, ctx),
5466
5516
  required: !isOptional && !p.dotDotDotToken,
5467
- ...p.dotDotDotToken ? { rest: true } : {}
5517
+ ...p.dotDotDotToken ? { rest: true } : {},
5518
+ ...pattern ? { "x-ts-destructured": true } : {}
5468
5519
  };
5469
5520
  const description = getParamDescription(name, jsdocTags);
5470
5521
  if (description)
@@ -6159,544 +6210,6 @@ function serializeValue(name, node, symbol, jsdocNode, type, typeNode, ctx) {
6159
6210
  };
6160
6211
  }
6161
6212
 
6162
- // src/types/schema-normalizer.ts
6163
- import { JSON_SCHEMA_DRAFT } from "@openpkg-ts/spec";
6164
- var TS_PRIMITIVE_NORMALIZATIONS = {
6165
- void: () => ({ type: "null", "x-ts-type": "void" }),
6166
- never: () => ({ not: {} }),
6167
- any: () => ({ "x-ts-type": "any" }),
6168
- unknown: () => ({ "x-ts-type": "unknown" }),
6169
- undefined: () => ({ type: "null", "x-ts-type": "undefined" }),
6170
- bigint: () => ({ type: "integer", "x-ts-type": "bigint" }),
6171
- symbol: () => ({ type: "string", "x-ts-type": "symbol" })
6172
- };
6173
- function normalizeSchema(schema, options = {}) {
6174
- const { includeSchemaField = false } = options;
6175
- const normalized = normalizeSchemaInternal(schema, options);
6176
- if (includeSchemaField && typeof normalized === "object") {
6177
- return {
6178
- $schema: JSON_SCHEMA_DRAFT,
6179
- ...normalized
6180
- };
6181
- }
6182
- return normalized;
6183
- }
6184
- function normalizeSchemaInternal(schema, options) {
6185
- const result = normalizeSchemaDispatch(schema, options);
6186
- if (schema && typeof schema === "object" && !Array.isArray(schema)) {
6187
- const s = schema;
6188
- if (s.deprecated === true && result.deprecated === undefined) {
6189
- result.deprecated = true;
6190
- }
6191
- if (s.readOnly === true && result.readOnly === undefined) {
6192
- result.readOnly = true;
6193
- }
6194
- for (const key of Object.keys(s)) {
6195
- if (key.startsWith("x-") && s[key] !== undefined && result[key] === undefined) {
6196
- result[key] = s[key];
6197
- }
6198
- }
6199
- if (Array.isArray(s.typeArguments) && s.typeArguments.length > 0 && result["x-ts-type-arguments"] === undefined) {
6200
- result["x-ts-type-arguments"] = s.typeArguments.map((arg) => normalizeSchemaInternal(arg, options));
6201
- }
6202
- }
6203
- return result;
6204
- }
6205
- function normalizeSchemaDispatch(schema, options) {
6206
- if (typeof schema === "string") {
6207
- return normalizeStringType(schema);
6208
- }
6209
- if (schema == null) {
6210
- return {};
6211
- }
6212
- if (typeof schema !== "object") {
6213
- return {};
6214
- }
6215
- if ("anyOf" in schema && Array.isArray(schema.anyOf)) {
6216
- return normalizeCombinator("anyOf", schema.anyOf, schema, options);
6217
- }
6218
- if ("allOf" in schema && Array.isArray(schema.allOf)) {
6219
- return normalizeCombinator("allOf", schema.allOf, schema, options);
6220
- }
6221
- if ("oneOf" in schema && Array.isArray(schema.oneOf)) {
6222
- return normalizeCombinator("oneOf", schema.oneOf, schema, options);
6223
- }
6224
- if ("$ref" in schema && typeof schema.$ref === "string") {
6225
- return normalizeRef(schema, options);
6226
- }
6227
- if ("type" in schema && typeof schema.type === "string") {
6228
- return normalizeTypedSchema(schema, options);
6229
- }
6230
- return normalizeGenericObject(schema, options);
6231
- }
6232
- function normalizeStringType(type) {
6233
- const specialNormalization = TS_PRIMITIVE_NORMALIZATIONS[type];
6234
- if (specialNormalization) {
6235
- return specialNormalization();
6236
- }
6237
- if (["string", "number", "boolean", "integer", "null", "object", "array"].includes(type)) {
6238
- return { type };
6239
- }
6240
- return { "x-ts-type": type };
6241
- }
6242
- function normalizeTypedSchema(schema, options) {
6243
- const { type } = schema;
6244
- const specialNormalization = TS_PRIMITIVE_NORMALIZATIONS[type];
6245
- if (specialNormalization) {
6246
- const normalized = specialNormalization();
6247
- return mergeSchemaFields(normalized, schema, ["type"]);
6248
- }
6249
- if (type === "function") {
6250
- return normalizeFunctionType(schema, options);
6251
- }
6252
- if (type === "tuple") {
6253
- return normalizeTupleType(schema, options);
6254
- }
6255
- if (type === "array") {
6256
- return normalizeArrayType(schema, options);
6257
- }
6258
- if (type === "object") {
6259
- return normalizeObjectType(schema, options);
6260
- }
6261
- if (["string", "number", "boolean", "integer", "null"].includes(type)) {
6262
- return normalizeStandardType(schema, options);
6263
- }
6264
- const result = { "x-ts-type": type };
6265
- return mergeSchemaFields(result, schema, ["type"]);
6266
- }
6267
- function normalizeFunctionType(schema, options) {
6268
- const result = {
6269
- "x-ts-function": true
6270
- };
6271
- if ("signatures" in schema && Array.isArray(schema.signatures)) {
6272
- result["x-ts-signatures"] = schema.signatures.map((sig) => normalizeSignature(sig, options));
6273
- }
6274
- if ("description" in schema && schema.description) {
6275
- result.description = schema.description;
6276
- }
6277
- return result;
6278
- }
6279
- function normalizeSignature(signature, options) {
6280
- const result = {};
6281
- if (signature.parameters) {
6282
- result.parameters = signature.parameters.map((param) => ({
6283
- name: param.name,
6284
- schema: normalizeSchemaInternal(param.schema, options),
6285
- ...param.required !== undefined ? { required: param.required } : {},
6286
- ...param.description ? { description: param.description } : {},
6287
- ...param.default !== undefined ? { default: param.default } : {},
6288
- ...param.rest ? { rest: param.rest } : {},
6289
- ...param["x-ts-destructured"] ? { "x-ts-destructured": true } : {}
6290
- }));
6291
- }
6292
- if (signature.returns) {
6293
- result.returns = {
6294
- schema: normalizeSchemaInternal(signature.returns.schema, options),
6295
- ...signature.returns.description ? { description: signature.returns.description } : {}
6296
- };
6297
- }
6298
- if (signature.description) {
6299
- result.description = signature.description;
6300
- }
6301
- if (signature.typeParameters) {
6302
- result.typeParameters = signature.typeParameters;
6303
- }
6304
- return result;
6305
- }
6306
- function normalizeTupleType(schema, options) {
6307
- const result = { type: "array" };
6308
- const prefix = Array.isArray(schema.prefixItems) ? schema.prefixItems : Array.isArray(schema.prefixedItems) ? schema.prefixedItems : undefined;
6309
- if (prefix) {
6310
- result.prefixItems = prefix.map((item) => normalizeSchemaInternal(item, options));
6311
- } else if ("items" in schema && Array.isArray(schema.items)) {
6312
- result.prefixItems = schema.items.map((item) => normalizeSchemaInternal(item, options));
6313
- result.minItems = schema.items.length;
6314
- result.maxItems = schema.items.length;
6315
- }
6316
- if ("minItems" in schema && typeof schema.minItems === "number") {
6317
- result.minItems = schema.minItems;
6318
- }
6319
- if ("maxItems" in schema && typeof schema.maxItems === "number") {
6320
- result.maxItems = schema.maxItems;
6321
- }
6322
- if ("description" in schema && schema.description) {
6323
- result.description = schema.description;
6324
- }
6325
- return result;
6326
- }
6327
- function normalizeArrayType(schema, options) {
6328
- const result = { type: "array" };
6329
- if ("items" in schema && schema.items && !Array.isArray(schema.items)) {
6330
- result.items = normalizeSchemaInternal(schema.items, options);
6331
- }
6332
- const arrayPrefix = Array.isArray(schema.prefixItems) ? schema.prefixItems : Array.isArray(schema.prefixedItems) ? schema.prefixedItems : undefined;
6333
- if (arrayPrefix) {
6334
- result.prefixItems = arrayPrefix.map((item) => normalizeSchemaInternal(item, options));
6335
- }
6336
- if ("minItems" in schema && typeof schema.minItems === "number") {
6337
- result.minItems = schema.minItems;
6338
- }
6339
- if ("maxItems" in schema && typeof schema.maxItems === "number") {
6340
- result.maxItems = schema.maxItems;
6341
- }
6342
- if (schema.uniqueItems === true) {
6343
- result.uniqueItems = true;
6344
- }
6345
- if (schema.contains && typeof schema.contains === "object") {
6346
- result.contains = normalizeSchemaInternal(schema.contains, options);
6347
- }
6348
- for (const keyword of ["title", "default"]) {
6349
- if (keyword in schema && schema[keyword] !== undefined) {
6350
- result[keyword] = schema[keyword];
6351
- }
6352
- }
6353
- if ("description" in schema && schema.description) {
6354
- result.description = schema.description;
6355
- }
6356
- return result;
6357
- }
6358
- function normalizeObjectType(schema, options) {
6359
- const result = { type: "object" };
6360
- if ("properties" in schema && schema.properties) {
6361
- const properties = schema.properties;
6362
- result.properties = Object.fromEntries(Object.entries(properties).map(([key, value]) => [
6363
- key,
6364
- normalizeSchemaInternal(value, options)
6365
- ]));
6366
- }
6367
- if ("required" in schema && Array.isArray(schema.required)) {
6368
- result.required = schema.required;
6369
- }
6370
- if ("additionalProperties" in schema) {
6371
- if (typeof schema.additionalProperties === "boolean") {
6372
- result.additionalProperties = schema.additionalProperties;
6373
- } else if (schema.additionalProperties) {
6374
- result.additionalProperties = normalizeSchemaInternal(schema.additionalProperties, options);
6375
- }
6376
- }
6377
- for (const keyword of ["patternProperties", "$defs"]) {
6378
- const value = schema[keyword];
6379
- if (value && typeof value === "object" && !Array.isArray(value)) {
6380
- result[keyword] = Object.fromEntries(Object.entries(value).map(([key, nested]) => [
6381
- key,
6382
- normalizeSchemaInternal(nested, options)
6383
- ]));
6384
- }
6385
- }
6386
- if (schema.propertyNames && typeof schema.propertyNames === "object") {
6387
- result.propertyNames = normalizeSchemaInternal(schema.propertyNames, options);
6388
- }
6389
- for (const keyword of ["title", "default", "examples", "minProperties", "maxProperties"]) {
6390
- if (keyword in schema && schema[keyword] !== undefined) {
6391
- result[keyword] = schema[keyword];
6392
- }
6393
- }
6394
- if ("description" in schema && schema.description) {
6395
- result.description = schema.description;
6396
- }
6397
- return result;
6398
- }
6399
- function normalizeStandardType(schema, options) {
6400
- const result = { type: schema.type };
6401
- const validationKeywords = [
6402
- "enum",
6403
- "const",
6404
- "format",
6405
- "pattern",
6406
- "minimum",
6407
- "maximum",
6408
- "exclusiveMinimum",
6409
- "exclusiveMaximum",
6410
- "multipleOf",
6411
- "minLength",
6412
- "maxLength",
6413
- "description",
6414
- "default",
6415
- "examples",
6416
- "title"
6417
- ];
6418
- for (const keyword of validationKeywords) {
6419
- if (keyword in schema && schema[keyword] !== undefined) {
6420
- result[keyword] = schema[keyword];
6421
- }
6422
- }
6423
- for (const key of Object.keys(schema)) {
6424
- if (key.startsWith("x-") && schema[key] !== undefined) {
6425
- const value = schema[key];
6426
- if (isSchemaLike(value)) {
6427
- result[key] = normalizeSchemaInternal(value, options);
6428
- } else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
6429
- result[key] = normalizeGenericObject(value, options);
6430
- } else {
6431
- result[key] = value;
6432
- }
6433
- }
6434
- }
6435
- return result;
6436
- }
6437
- function normalizeRef(schema, options) {
6438
- const result = { $ref: schema.$ref };
6439
- if (schema.typeArguments && schema.typeArguments.length > 0) {
6440
- result["x-ts-type-arguments"] = schema.typeArguments.map((arg) => normalizeSchemaInternal(arg, options));
6441
- }
6442
- for (const key of Object.keys(schema)) {
6443
- if (key.startsWith("x-ts-") && schema[key] !== undefined) {
6444
- result[key] = schema[key];
6445
- }
6446
- }
6447
- return result;
6448
- }
6449
- function normalizeCombinator(keyword, schemas, originalSchema, options) {
6450
- let branches = schemas.map((s) => normalizeSchemaInternal(s, options));
6451
- if (keyword !== "allOf") {
6452
- const seen = new Set;
6453
- branches = branches.filter((b) => {
6454
- const key = JSON.stringify(b);
6455
- if (seen.has(key))
6456
- return false;
6457
- seen.add(key);
6458
- return true;
6459
- });
6460
- if (branches.length === 1) {
6461
- const single = { ...branches[0] };
6462
- if ("description" in originalSchema && originalSchema.description && !single.description) {
6463
- single.description = originalSchema.description;
6464
- }
6465
- return single;
6466
- }
6467
- }
6468
- const result = { [keyword]: branches };
6469
- if ((keyword === "anyOf" || keyword === "oneOf") && "discriminator" in originalSchema && originalSchema.discriminator) {
6470
- result.discriminator = originalSchema.discriminator;
6471
- }
6472
- if ("description" in originalSchema && originalSchema.description) {
6473
- result.description = originalSchema.description;
6474
- }
6475
- return result;
6476
- }
6477
- function normalizeGenericObject(schema, options) {
6478
- const result = {};
6479
- for (const [key, value] of Object.entries(schema)) {
6480
- if (value == null)
6481
- continue;
6482
- if (isSchemaLike(value)) {
6483
- result[key] = normalizeSchemaInternal(value, options);
6484
- } else if (Array.isArray(value)) {
6485
- result[key] = value.map((item) => isSchemaLike(item) ? normalizeSchemaInternal(item, options) : item);
6486
- } else if (typeof value === "object") {
6487
- result[key] = normalizeGenericObject(value, options);
6488
- } else {
6489
- result[key] = value;
6490
- }
6491
- }
6492
- return result;
6493
- }
6494
- function isSchemaLike(value) {
6495
- if (typeof value !== "object" || value == null)
6496
- return false;
6497
- if (typeof value === "string")
6498
- return true;
6499
- const obj = value;
6500
- return "type" in obj || "$ref" in obj || "anyOf" in obj || "allOf" in obj || "oneOf" in obj || "properties" in obj || "items" in obj || "prefixItems" in obj || "prefixedItems" in obj;
6501
- }
6502
- function mergeSchemaFields(target, source, excludeKeys) {
6503
- if (typeof source !== "object" || source == null) {
6504
- return target;
6505
- }
6506
- const excludeSet = new Set(excludeKeys);
6507
- const result = { ...target };
6508
- for (const [key, value] of Object.entries(source)) {
6509
- if (!excludeSet.has(key) && value !== undefined) {
6510
- if (!(key in result)) {
6511
- result[key] = value;
6512
- }
6513
- }
6514
- }
6515
- return result;
6516
- }
6517
- function isVendorSchemaExport(exp) {
6518
- return !!exp.tags?.some((t) => t.name === "schema-source" && t.text === "standard-json-schema");
6519
- }
6520
- function normalizeExport(exp, options = {}) {
6521
- const result = { ...exp };
6522
- const vendorSchema = isVendorSchemaExport(exp);
6523
- if (exp.schema && !vendorSchema) {
6524
- result.schema = normalizeSchema(exp.schema, options);
6525
- }
6526
- if (exp.signatures) {
6527
- result.signatures = exp.signatures.map((sig) => normalizeSignatureSpec(sig, options));
6528
- }
6529
- if (exp.members) {
6530
- result.members = exp.members.map((member) => normalizeMember(member, options));
6531
- }
6532
- if (!vendorSchema && shouldGenerateMembersSchema(exp.kind) && exp.members && exp.members.length > 0) {
6533
- result.schema = withOpenArms(normalizeMembers(exp.members, options), result.schema);
6534
- }
6535
- return result;
6536
- }
6537
- function withOpenArms(membersSchema, provided) {
6538
- const arms = provided?.allOf;
6539
- return Array.isArray(arms) ? { allOf: [membersSchema, ...arms] } : membersSchema;
6540
- }
6541
- function normalizeType(type, options = {}) {
6542
- const result = { ...type };
6543
- if (type.schema) {
6544
- result.schema = normalizeSchema(type.schema, options);
6545
- }
6546
- if (type.members) {
6547
- result.members = type.members.map((member) => normalizeMember(member, options));
6548
- }
6549
- if (shouldGenerateMembersSchema(type.kind) && type.members && type.members.length > 0) {
6550
- result.schema = withOpenArms(normalizeMembers(type.members, options), result.schema);
6551
- }
6552
- return result;
6553
- }
6554
- function shouldGenerateMembersSchema(kind) {
6555
- return kind === "interface" || kind === "class";
6556
- }
6557
- function normalizeSignatureSpec(signature, options) {
6558
- const result = { ...signature };
6559
- if (signature.parameters) {
6560
- result.parameters = signature.parameters.map((param) => ({
6561
- ...param,
6562
- schema: normalizeSchema(param.schema, options)
6563
- }));
6564
- }
6565
- if (signature.returns) {
6566
- result.returns = {
6567
- ...signature.returns,
6568
- schema: normalizeSchema(signature.returns.schema, options)
6569
- };
6570
- }
6571
- return result;
6572
- }
6573
- function normalizeMember(member, options) {
6574
- const result = { ...member };
6575
- if (member.schema) {
6576
- result.schema = normalizeSchema(member.schema, options);
6577
- }
6578
- if (member.signatures) {
6579
- result.signatures = member.signatures.map((sig) => normalizeSignatureSpec(sig, options));
6580
- }
6581
- return result;
6582
- }
6583
- function normalizeMembers(members, options = {}) {
6584
- const properties = {};
6585
- const required = [];
6586
- let additionalProperties;
6587
- let numberIndexSchema;
6588
- for (const member of members) {
6589
- const { name, kind } = member;
6590
- if (kind === "index" || kind === "index-signature") {
6591
- if (name === "[number]") {
6592
- numberIndexSchema = normalizeMemberToSchema(member, options);
6593
- } else {
6594
- additionalProperties = normalizeMemberToSchema(member, options);
6595
- }
6596
- continue;
6597
- }
6598
- if (!name)
6599
- continue;
6600
- const memberSchema = normalizeMemberToSchema(member, options);
6601
- properties[name] = memberSchema;
6602
- if (!isOptionalMember(member)) {
6603
- required.push(name);
6604
- }
6605
- }
6606
- const result = {
6607
- type: "object",
6608
- properties
6609
- };
6610
- if (required.length > 0) {
6611
- result.required = required;
6612
- }
6613
- if (additionalProperties !== undefined) {
6614
- result.additionalProperties = additionalProperties;
6615
- }
6616
- if (numberIndexSchema !== undefined) {
6617
- result.patternProperties = { "^\\d+$": numberIndexSchema };
6618
- result["x-ts-index-key"] = "number";
6619
- }
6620
- return result;
6621
- }
6622
- function memberDocExtras(member) {
6623
- const extras = {};
6624
- if (member.description) {
6625
- extras.description = member.description;
6626
- }
6627
- if (member.flags?.readonly === true) {
6628
- extras.readOnly = true;
6629
- }
6630
- if (member.deprecated) {
6631
- extras.deprecated = true;
6632
- const reason = member.deprecationReason ?? member.tags?.find((t) => t.name === "deprecated")?.text;
6633
- if (reason?.trim()) {
6634
- extras["x-deprecated-reason"] = reason;
6635
- }
6636
- }
6637
- return extras;
6638
- }
6639
- function normalizeMemberToSchema(member, options) {
6640
- const { kind, schema, signatures } = member;
6641
- if (kind === "method" || kind === "call-signature") {
6642
- return normalizeMethodMember(member, options);
6643
- }
6644
- if (kind === "getter") {
6645
- const baseSchema2 = schema ? normalizeSchemaInternal(schema, options) : {};
6646
- return {
6647
- ...baseSchema2,
6648
- "x-ts-accessor": "getter",
6649
- ...memberDocExtras(member)
6650
- };
6651
- }
6652
- if (kind === "setter") {
6653
- const baseSchema2 = schema ? normalizeSchemaInternal(schema, options) : {};
6654
- return {
6655
- ...baseSchema2,
6656
- "x-ts-accessor": "setter",
6657
- ...memberDocExtras(member)
6658
- };
6659
- }
6660
- if (kind === "index" || kind === "index-signature") {
6661
- if (schema && typeof schema === "object" && "additionalProperties" in schema) {
6662
- return normalizeSchemaInternal(schema.additionalProperties, options);
6663
- }
6664
- return schema ? normalizeSchemaInternal(schema, options) : {};
6665
- }
6666
- if (signatures && signatures.length > 0) {
6667
- return normalizeMethodMember(member, options);
6668
- }
6669
- const baseSchema = schema ? normalizeSchemaInternal(schema, options) : {};
6670
- const extras = memberDocExtras(member);
6671
- return Object.keys(extras).length > 0 ? { ...baseSchema, ...extras } : baseSchema;
6672
- }
6673
- function normalizeMethodMember(member, options) {
6674
- const result = {
6675
- "x-ts-function": true
6676
- };
6677
- if (member.flags?.methodSyntax === true) {
6678
- result["x-ts-method"] = true;
6679
- }
6680
- const memberTypeText = member.schema && typeof member.schema === "object" ? member.schema["x-ts-type"] : undefined;
6681
- if (typeof memberTypeText === "string") {
6682
- result["x-ts-type"] = memberTypeText;
6683
- }
6684
- if (member.signatures && member.signatures.length > 0) {
6685
- result["x-ts-signatures"] = member.signatures.map((sig) => normalizeSignature(sig, options));
6686
- }
6687
- Object.assign(result, memberDocExtras(member));
6688
- return result;
6689
- }
6690
- function isOptionalMember(member) {
6691
- if (member.flags?.optional === true) {
6692
- return true;
6693
- }
6694
- if (member.name?.endsWith("?")) {
6695
- return true;
6696
- }
6697
- return false;
6698
- }
6699
-
6700
6213
  // src/primitives/get.ts
6701
6214
  async function getExport(options) {
6702
6215
  const { entryFile, exportName, baseDir, content, maxTypeDepth } = options;
@@ -9063,7 +8576,7 @@ import {
9063
8576
  validateSpec as validateSpec2
9064
8577
  } from "@openpkg-ts/spec";
9065
8578
  // src/schema/json-schema.ts
9066
- import { JSON_SCHEMA_DRAFT as JSON_SCHEMA_DRAFT2 } from "@openpkg-ts/spec";
8579
+ import { JSON_SCHEMA_DRAFT } from "@openpkg-ts/spec";
9067
8580
 
9068
8581
  // src/schema/ref-walker.ts
9069
8582
  var INTERNAL_REF_PREFIX = "#/types/";
@@ -9199,7 +8712,7 @@ function exportToJsonSchema(subject, spec, options = {}) {
9199
8712
  if (Object.keys(defs).length > 0)
9200
8713
  doc.$defs = defs;
9201
8714
  if (includeSchemaField)
9202
- return { $schema: JSON_SCHEMA_DRAFT2, ...doc };
8715
+ return { $schema: JSON_SCHEMA_DRAFT, ...doc };
9203
8716
  return doc;
9204
8717
  }
9205
8718
  function toJsonSchema(spec, options = {}) {
@@ -9236,7 +8749,7 @@ function toJsonSchema(spec, options = {}) {
9236
8749
  }
9237
8750
  const doc = { $defs: defs };
9238
8751
  if (includeSchemaField)
9239
- return { $schema: JSON_SCHEMA_DRAFT2, ...doc };
8752
+ return { $schema: JSON_SCHEMA_DRAFT, ...doc };
9240
8753
  return doc;
9241
8754
  }
9242
8755
 
@@ -9611,6 +9124,7 @@ export {
9611
9124
  isSymbolDeprecated,
9612
9125
  isStandardJSONSchema,
9613
9126
  isSchemaType,
9127
+ isRequiredOnlyAnyOf,
9614
9128
  isRemoteInput,
9615
9129
  isReadonlyPropertySymbol,
9616
9130
  isPureRefSchema,