@postman/sdk-config 0.5.0 → 0.6.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.
@@ -1246,10 +1246,16 @@ function finishOutputMapping(mapping, outputMode, sourcePath, state, index) {
1246
1246
  for (const path of collectLeafPaths(outputMode, sourcePath)) {
1247
1247
  if (path[path.length - 1] === "_visit") consume(state, path);
1248
1248
  }
1249
+ const legacyGenerateFullProject = isObject(outputMode) ? outputMode.generateFullProject : void 0;
1250
+ const generationShape = typeof legacyGenerateFullProject === "boolean" ? { generation: { ...mapping.generation, generateFullProject: legacyGenerateFullProject } } : {};
1251
+ if (typeof legacyGenerateFullProject === "boolean") {
1252
+ consume(state, [...sourcePath, "generateFullProject"]);
1253
+ }
1249
1254
  const unsupported = collectUnsupported(outputMode, sourcePath, state);
1250
1255
  const hasCredentials = unsupported.some((diagnostic) => isCredentialPath(diagnostic.path));
1251
1256
  return {
1252
1257
  ...mapping,
1258
+ ...generationShape,
1253
1259
  unsupportedFields: [
1254
1260
  ...state.credentialDiagnostics ?? [],
1255
1261
  ...hasCredentials ? [
@@ -1333,6 +1339,113 @@ function outputDiagnostic(path, index) {
1333
1339
  suggestedAction: resolvedGuidance?.suggestedAction ?? "Review this output setting and preserve it outside SDK Config when no equivalent exists."
1334
1340
  };
1335
1341
  }
1342
+ var OMIT = /* @__PURE__ */ Symbol("omit");
1343
+ function inputJsonSchema(schema) {
1344
+ return zod.z.toJSONSchema(schema, {
1345
+ io: "input",
1346
+ unrepresentable: "any"
1347
+ });
1348
+ }
1349
+ function stripUnknownProperties(value, schema) {
1350
+ return project(value, schema, schema);
1351
+ }
1352
+ function project(value, candidateSchema, rootSchema, omitDefaults) {
1353
+ const resolvedCandidate = resolveSchema(candidateSchema, rootSchema);
1354
+ const schema = selectSchema(value, resolvedCandidate, rootSchema);
1355
+ if (Array.isArray(value)) {
1356
+ if (!schema.items) return value;
1357
+ return value.map((item) => {
1358
+ const projected = project(item, schema.items, rootSchema);
1359
+ return projected === OMIT ? item : projected;
1360
+ });
1361
+ }
1362
+ if (!isRecord(value) || schema.type !== "object") return value;
1363
+ const entries = [];
1364
+ const properties = schema.properties ?? {};
1365
+ const unionProperties = collectAlternativeProperties(resolvedCandidate, rootSchema);
1366
+ for (const [key, propertySchema] of Object.entries(properties)) {
1367
+ if (!Object.hasOwn(value, key)) continue;
1368
+ const projected = project(value[key], propertySchema, rootSchema);
1369
+ if (projected !== OMIT) entries.push([key, projected]);
1370
+ }
1371
+ for (const [key, fieldValue] of Object.entries(value)) {
1372
+ if (Object.hasOwn(properties, key)) continue;
1373
+ if (Object.hasOwn(unionProperties, key)) {
1374
+ entries.push([key, fieldValue]);
1375
+ continue;
1376
+ }
1377
+ if (schema.additionalProperties !== false) {
1378
+ const projected = typeof schema.additionalProperties === "object" ? project(fieldValue, schema.additionalProperties, rootSchema) : fieldValue;
1379
+ if (projected !== OMIT) entries.push([key, projected]);
1380
+ }
1381
+ }
1382
+ return Object.fromEntries(entries);
1383
+ }
1384
+ function collectAlternativeProperties(schema, rootSchema) {
1385
+ const alternatives = schema.oneOf ?? schema.anyOf;
1386
+ if (!alternatives) return schema.properties ?? {};
1387
+ return Object.assign(
1388
+ {},
1389
+ ...alternatives.map((alternative) => resolveSchema(alternative, rootSchema).properties ?? {})
1390
+ );
1391
+ }
1392
+ function selectSchema(value, schema, rootSchema) {
1393
+ const alternatives = schema.oneOf ?? schema.anyOf;
1394
+ if (!alternatives || alternatives.length === 0) return schema;
1395
+ const best = alternatives.map((alternative, index) => {
1396
+ const resolved = resolveSchema(alternative, rootSchema);
1397
+ return { index, schema: resolved, score: schemaMatchScore(value, resolved) };
1398
+ }).sort((left, right) => right.score - left.score || left.index - right.index)[0];
1399
+ return best.score === Number.NEGATIVE_INFINITY ? schema : best.schema;
1400
+ }
1401
+ function schemaMatchScore(value, schema) {
1402
+ if (Object.hasOwn(schema, "const") && !deepEqual(value, schema.const)) {
1403
+ return Number.NEGATIVE_INFINITY;
1404
+ }
1405
+ if (schema.enum && !schema.enum.some((candidate) => deepEqual(value, candidate))) {
1406
+ return Number.NEGATIVE_INFINITY;
1407
+ }
1408
+ if (schema.type === "object") {
1409
+ if (!isRecord(value)) return Number.NEGATIVE_INFINITY;
1410
+ const properties = schema.properties ?? {};
1411
+ for (const [key, propertySchema] of Object.entries(properties)) {
1412
+ if (!Object.hasOwn(value, key)) continue;
1413
+ if (Object.hasOwn(propertySchema, "const") && !deepEqual(value[key], propertySchema.const)) {
1414
+ return Number.NEGATIVE_INFINITY;
1415
+ }
1416
+ }
1417
+ return Object.keys(value).filter((key) => Object.hasOwn(properties, key)).length;
1418
+ }
1419
+ if (schema.type === "array") return Array.isArray(value) ? 1 : Number.NEGATIVE_INFINITY;
1420
+ if (schema.type === "string") return typeof value === "string" ? 1 : Number.NEGATIVE_INFINITY;
1421
+ if (schema.type === "number" || schema.type === "integer") {
1422
+ return typeof value === "number" ? 1 : Number.NEGATIVE_INFINITY;
1423
+ }
1424
+ if (schema.type === "boolean") return typeof value === "boolean" ? 1 : Number.NEGATIVE_INFINITY;
1425
+ if (schema.type === "null") return value === null ? 1 : Number.NEGATIVE_INFINITY;
1426
+ return 0;
1427
+ }
1428
+ function resolveSchema(schema, rootSchema) {
1429
+ if (!schema.$ref) return schema;
1430
+ if (!schema.$ref.startsWith("#/$defs/")) return schema;
1431
+ const name = schema.$ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
1432
+ return rootSchema.$defs?.[name] ?? schema;
1433
+ }
1434
+ function isRecord(value) {
1435
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1436
+ }
1437
+ function deepEqual(left, right) {
1438
+ if (Object.is(left, right)) return true;
1439
+ if (Array.isArray(left) && Array.isArray(right)) {
1440
+ return left.length === right.length && left.every((value, index) => deepEqual(value, right[index]));
1441
+ }
1442
+ if (isRecord(left) && isRecord(right)) {
1443
+ const leftKeys = Object.keys(left);
1444
+ const rightKeys = Object.keys(right);
1445
+ return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
1446
+ }
1447
+ return false;
1448
+ }
1336
1449
  var namingConfigSchema = zod.z.strictObject({
1337
1450
  clientName: nonEmptyStringSchema.optional(),
1338
1451
  exportedClientName: nonEmptyStringSchema.optional(),
@@ -1431,6 +1544,8 @@ var generationConfigOverrideShape = {
1431
1544
  inferServiceNames: zod.z.boolean().optional(),
1432
1545
  includeDeprecatedOperations: zod.z.boolean().optional(),
1433
1546
  multipleResponses: zod.z.boolean().optional(),
1547
+ /** Generate the entire SDK project, including package manifests and publishable artifacts. */
1548
+ generateFullProject: zod.z.boolean().optional(),
1434
1549
  devContainer: zod.z.boolean().optional(),
1435
1550
  allowMockClient: zod.z.boolean().optional(),
1436
1551
  ignoreFiles: zod.z.array(nonEmptyStringSchema).optional(),
@@ -1459,6 +1574,7 @@ var sdkConfigV1GenerationConfigSchema = zod.z.strictObject({
1459
1574
  inferServiceNames: zod.z.boolean().default(false),
1460
1575
  includeDeprecatedOperations: zod.z.boolean().default(true),
1461
1576
  multipleResponses: zod.z.boolean().default(false),
1577
+ generateFullProject: zod.z.boolean().default(false),
1462
1578
  devContainer: zod.z.boolean().default(false),
1463
1579
  allowMockClient: zod.z.boolean().default(false)
1464
1580
  });
@@ -2008,6 +2124,10 @@ function validateSdkConfigV1(value) {
2008
2124
  function parseSdkConfigV1(value) {
2009
2125
  return sdkConfigV1Schema.parse(value);
2010
2126
  }
2127
+ var sdkConfigV1InputJsonSchema = inputJsonSchema(sdkConfigV1Schema);
2128
+ function parseSdkConfigV1ForConsumption(value) {
2129
+ return parseSdkConfigV1(stripUnknownProperties(value, sdkConfigV1InputJsonSchema));
2130
+ }
2011
2131
 
2012
2132
  // src/sdk-config/v1/fern-config-mapper.ts
2013
2133
  var generatorLanguages = {
@@ -2063,7 +2183,14 @@ function mapFernConfigToSdkConfigV1(input) {
2063
2183
  api.audiences = [...input.group.audiences.audiences];
2064
2184
  }
2065
2185
  const targets = mapped.map(
2066
- ({ generator, invocation, language, output, package: outputPackage }, index) => {
2186
+ ({
2187
+ generator,
2188
+ invocation,
2189
+ language,
2190
+ output,
2191
+ package: outputPackage,
2192
+ generation: outputGeneration
2193
+ }, index) => {
2067
2194
  const target = {
2068
2195
  language,
2069
2196
  output,
@@ -2077,6 +2204,7 @@ function mapFernConfigToSdkConfigV1(input) {
2077
2204
  }
2078
2205
  const targetGeneration = {
2079
2206
  ...generations.targetOverrides[index],
2207
+ ...outputGeneration,
2080
2208
  ...invocation.targetGeneration
2081
2209
  };
2082
2210
  if (Object.keys(targetGeneration).length > 0) {
@@ -2254,6 +2382,9 @@ function mapInvocation(generator, language, activeLanguages, index) {
2254
2382
  if (generator.keywords?.length) {
2255
2383
  generation.reservedKeywords = [...generator.keywords];
2256
2384
  }
2385
+ if (generator.generateFullProject !== void 0) {
2386
+ generation.generateFullProject = generator.generateFullProject;
2387
+ }
2257
2388
  const settings = isObject(generator.settings) ? generator.settings : void 0;
2258
2389
  if (settings) {
2259
2390
  const inlinePathParameters = takeBoolean(settings, ["inlinePathParameters"], state, [
@@ -2396,6 +2527,8 @@ function mapCommonConfig(language, config, state, client, generation, packageCon
2396
2527
  basePath
2397
2528
  );
2398
2529
  if (webSockets !== void 0) generation.webSockets = webSockets;
2530
+ const generateFullProject = takeBoolean(config, ["generateFullProject"], state, basePath);
2531
+ if (generateFullProject !== void 0) generation.generateFullProject = generateFullProject;
2399
2532
  const inlineTypes = takeBoolean(config, ["enableInlineTypes"], state, basePath);
2400
2533
  const omitUndefined = takeBoolean(config, ["omitUndefined"], state, basePath);
2401
2534
  const forwardEnums = takeBoolean(config, ["enableForwardCompatibleEnums"], state, basePath);
@@ -2874,6 +3007,7 @@ exports.FernConfigMappingError = FernConfigMappingError;
2874
3007
  exports.SDK_CONFIG_V1_SCHEMA_VERSION = SDK_CONFIG_V1_SCHEMA_VERSION;
2875
3008
  exports.mapFernConfigToSdkConfigV1 = mapFernConfigToSdkConfigV1;
2876
3009
  exports.parseSdkConfigV1 = parseSdkConfigV1;
3010
+ exports.parseSdkConfigV1ForConsumption = parseSdkConfigV1ForConsumption;
2877
3011
  exports.sdkConfigV1ApiConfigSchema = sdkConfigV1ApiConfigSchema;
2878
3012
  exports.sdkConfigV1AuthConfigSchema = sdkConfigV1AuthConfigSchema;
2879
3013
  exports.sdkConfigV1AuthSchemeSchema = sdkConfigV1AuthSchemeSchema;