@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.
@@ -766,6 +766,8 @@ var generationConfigSchema = z.strictObject({
766
766
  inferServiceNames: z.boolean().default(false),
767
767
  includeDeprecatedOperations: z.boolean().default(true),
768
768
  multipleResponses: z.boolean().default(false),
769
+ /** Generate the entire SDK project, including package manifests and publishable artifacts. */
770
+ generateFullProject: z.boolean().default(false),
769
771
  devContainer: z.boolean().default(false),
770
772
  allowMockClient: z.boolean().default(false),
771
773
  ignoreFiles: z.array(nonEmptyStringSchema).optional(),
@@ -1196,7 +1198,152 @@ var sdkConfigIrV1Schema = z.strictObject({
1196
1198
  function parseSdkConfigIrV1(value) {
1197
1199
  return sdkConfigIrV1Schema.parse(value);
1198
1200
  }
1201
+ var OMIT = /* @__PURE__ */ Symbol("omit");
1202
+ function inputJsonSchema(schema) {
1203
+ return z.toJSONSchema(schema, {
1204
+ io: "input",
1205
+ unrepresentable: "any"
1206
+ });
1207
+ }
1208
+ function stripUnknownProperties(value, schema) {
1209
+ return project(value, schema, schema, false);
1210
+ }
1211
+ function omitSchemaDefaults(value, schema) {
1212
+ const projected = project(value, schema, schema, true);
1213
+ return projected === OMIT ? void 0 : projected;
1214
+ }
1215
+ function project(value, candidateSchema, rootSchema, omitDefaults) {
1216
+ const resolvedCandidate = resolveSchema(candidateSchema, rootSchema);
1217
+ if (omitDefaults && Object.hasOwn(resolvedCandidate, "default") && deepEqual(value, resolvedCandidate.default)) {
1218
+ return OMIT;
1219
+ }
1220
+ const schema = selectSchema(value, resolvedCandidate, rootSchema);
1221
+ if (omitDefaults && schema !== resolvedCandidate && Object.hasOwn(schema, "default") && deepEqual(value, schema.default)) {
1222
+ return OMIT;
1223
+ }
1224
+ if (Array.isArray(value)) {
1225
+ if (!schema.items) return value;
1226
+ return value.map((item) => {
1227
+ const projected = project(item, schema.items, rootSchema, omitDefaults);
1228
+ return projected === OMIT ? item : projected;
1229
+ });
1230
+ }
1231
+ if (!isRecord(value) || schema.type !== "object") return value;
1232
+ const entries = [];
1233
+ const properties = schema.properties ?? {};
1234
+ const unionProperties = omitDefaults ? properties : collectAlternativeProperties(resolvedCandidate, rootSchema);
1235
+ for (const [key, propertySchema] of Object.entries(properties)) {
1236
+ if (!Object.hasOwn(value, key)) continue;
1237
+ const projected = project(value[key], propertySchema, rootSchema, omitDefaults);
1238
+ if (projected !== OMIT) entries.push([key, projected]);
1239
+ }
1240
+ for (const [key, fieldValue] of Object.entries(value)) {
1241
+ if (Object.hasOwn(properties, key)) continue;
1242
+ if (Object.hasOwn(unionProperties, key)) {
1243
+ entries.push([key, fieldValue]);
1244
+ continue;
1245
+ }
1246
+ if (schema.additionalProperties !== false) {
1247
+ const projected = typeof schema.additionalProperties === "object" ? project(fieldValue, schema.additionalProperties, rootSchema, omitDefaults) : fieldValue;
1248
+ if (projected !== OMIT) entries.push([key, projected]);
1249
+ } else if (omitDefaults) {
1250
+ throw new Error(`Cannot serialize property unknown to the wire schema: ${key}`);
1251
+ }
1252
+ }
1253
+ return Object.fromEntries(entries);
1254
+ }
1255
+ function collectAlternativeProperties(schema, rootSchema) {
1256
+ const alternatives = schema.oneOf ?? schema.anyOf;
1257
+ if (!alternatives) return schema.properties ?? {};
1258
+ return Object.assign(
1259
+ {},
1260
+ ...alternatives.map((alternative) => resolveSchema(alternative, rootSchema).properties ?? {})
1261
+ );
1262
+ }
1263
+ function selectSchema(value, schema, rootSchema) {
1264
+ const alternatives = schema.oneOf ?? schema.anyOf;
1265
+ if (!alternatives || alternatives.length === 0) return schema;
1266
+ const best = alternatives.map((alternative, index) => {
1267
+ const resolved = resolveSchema(alternative, rootSchema);
1268
+ return { index, schema: resolved, score: schemaMatchScore(value, resolved) };
1269
+ }).sort((left, right) => right.score - left.score || left.index - right.index)[0];
1270
+ return best.score === Number.NEGATIVE_INFINITY ? schema : best.schema;
1271
+ }
1272
+ function schemaMatchScore(value, schema) {
1273
+ if (Object.hasOwn(schema, "const") && !deepEqual(value, schema.const)) {
1274
+ return Number.NEGATIVE_INFINITY;
1275
+ }
1276
+ if (schema.enum && !schema.enum.some((candidate) => deepEqual(value, candidate))) {
1277
+ return Number.NEGATIVE_INFINITY;
1278
+ }
1279
+ if (schema.type === "object") {
1280
+ if (!isRecord(value)) return Number.NEGATIVE_INFINITY;
1281
+ const properties = schema.properties ?? {};
1282
+ for (const [key, propertySchema] of Object.entries(properties)) {
1283
+ if (!Object.hasOwn(value, key)) continue;
1284
+ if (Object.hasOwn(propertySchema, "const") && !deepEqual(value[key], propertySchema.const)) {
1285
+ return Number.NEGATIVE_INFINITY;
1286
+ }
1287
+ }
1288
+ return Object.keys(value).filter((key) => Object.hasOwn(properties, key)).length;
1289
+ }
1290
+ if (schema.type === "array") return Array.isArray(value) ? 1 : Number.NEGATIVE_INFINITY;
1291
+ if (schema.type === "string") return typeof value === "string" ? 1 : Number.NEGATIVE_INFINITY;
1292
+ if (schema.type === "number" || schema.type === "integer") {
1293
+ return typeof value === "number" ? 1 : Number.NEGATIVE_INFINITY;
1294
+ }
1295
+ if (schema.type === "boolean") return typeof value === "boolean" ? 1 : Number.NEGATIVE_INFINITY;
1296
+ if (schema.type === "null") return value === null ? 1 : Number.NEGATIVE_INFINITY;
1297
+ return 0;
1298
+ }
1299
+ function resolveSchema(schema, rootSchema) {
1300
+ if (!schema.$ref) return schema;
1301
+ if (!schema.$ref.startsWith("#/$defs/")) return schema;
1302
+ const name = schema.$ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
1303
+ return rootSchema.$defs?.[name] ?? schema;
1304
+ }
1305
+ function isRecord(value) {
1306
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1307
+ }
1308
+ function deepEqual(left, right) {
1309
+ if (Object.is(left, right)) return true;
1310
+ if (Array.isArray(left) && Array.isArray(right)) {
1311
+ return left.length === right.length && left.every((value, index) => deepEqual(value, right[index]));
1312
+ }
1313
+ if (isRecord(left) && isRecord(right)) {
1314
+ const leftKeys = Object.keys(left);
1315
+ const rightKeys = Object.keys(right);
1316
+ return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
1317
+ }
1318
+ return false;
1319
+ }
1320
+
1321
+ // src/sdk-config-ir/v1/wire.ts
1322
+ var sdkConfigIrCapabilitySchema = z.enum(["generation.generateFullProject"]);
1323
+ var sdkConfigIrV1InputJsonSchema = inputJsonSchema(sdkConfigIrV1Schema);
1324
+ function serializeSdkConfigIrV1(value) {
1325
+ const parsed = parseSdkConfigIrV1(value);
1326
+ const wireValue = omitSchemaDefaults(parsed, sdkConfigIrV1InputJsonSchema);
1327
+ const requiredCapabilities = [];
1328
+ if (wireValue === void 0) {
1329
+ throw new Error("SDK Config IR v1 root cannot be omitted from its wire payload");
1330
+ }
1331
+ if (parsed.generation.generateFullProject) {
1332
+ requiredCapabilities.push("generation.generateFullProject");
1333
+ }
1334
+ const json = JSON.stringify(wireValue);
1335
+ if (json === void 0) {
1336
+ throw new Error("SDK Config IR v1 could not be serialized as JSON");
1337
+ }
1338
+ return {
1339
+ body: new TextEncoder().encode(json),
1340
+ requiredCapabilities
1341
+ };
1342
+ }
1343
+ function parseSdkConfigIrV1ForConsumption(value) {
1344
+ return parseSdkConfigIrV1(stripUnknownProperties(value, sdkConfigIrV1InputJsonSchema));
1345
+ }
1199
1346
 
1200
- export { SDK_CONFIG_IR_V1_SCHEMA_VERSION, apiConfigSchema, apiImportSettingsSchema, authConfigSchema, authSchemeSchema, cliGenerationConfigSchema, clientConfigOverrideSchema, clientConfigSchema, clientRetryOverrideSchema, compatibilityConfigSchema, composerPackageNameSchema, csharpGenerationConfigSchema, dependencySchema, docsConfigSchema, exactSemverSchema, generationConfigSchema, goGenerationConfigSchema, goModulePathSchema, javaGenerationConfigSchema, jsonObjectSchema, jsonValueSchema, kotlinGenerationConfigSchema, languageGenerationConfigSchema, legacyInputSchema, mcpAvailabilityStatuses, mcpGenerationConfigSchema, nonEmptyStringSchema, outputConfigSchema, packageConfigSchema, parseSdkConfigIrV1, phpGenerationConfigSchema, publishConfigSchema, publishRegistrySchema, pythonGenerationConfigSchema, readmeCustomSectionSchema, readmeEndpointSchema, relativePathSchema, replayConfigSchema, rubyGenerationConfigSchema, rustGenerationConfigSchema, sdkConfigIrV1Schema, sourceConfigSchema, sourceSpecConfigSchema, sourceSpecTypeSchema, swiftGenerationConfigSchema, targetConfigSchema, targetLanguageSchema, terraformGenerationConfigSchema, typescriptGenerationConfigSchema, unsupportedFieldSchema, webhookSignatureSchema };
1347
+ export { SDK_CONFIG_IR_V1_SCHEMA_VERSION, apiConfigSchema, apiImportSettingsSchema, authConfigSchema, authSchemeSchema, cliGenerationConfigSchema, clientConfigOverrideSchema, clientConfigSchema, clientRetryOverrideSchema, compatibilityConfigSchema, composerPackageNameSchema, csharpGenerationConfigSchema, dependencySchema, docsConfigSchema, exactSemverSchema, generationConfigSchema, goGenerationConfigSchema, goModulePathSchema, javaGenerationConfigSchema, jsonObjectSchema, jsonValueSchema, kotlinGenerationConfigSchema, languageGenerationConfigSchema, legacyInputSchema, mcpAvailabilityStatuses, mcpGenerationConfigSchema, nonEmptyStringSchema, outputConfigSchema, packageConfigSchema, parseSdkConfigIrV1, parseSdkConfigIrV1ForConsumption, phpGenerationConfigSchema, publishConfigSchema, publishRegistrySchema, pythonGenerationConfigSchema, readmeCustomSectionSchema, readmeEndpointSchema, relativePathSchema, replayConfigSchema, rubyGenerationConfigSchema, rustGenerationConfigSchema, sdkConfigIrCapabilitySchema, sdkConfigIrV1Schema, serializeSdkConfigIrV1, sourceConfigSchema, sourceSpecConfigSchema, sourceSpecTypeSchema, swiftGenerationConfigSchema, targetConfigSchema, targetLanguageSchema, terraformGenerationConfigSchema, typescriptGenerationConfigSchema, unsupportedFieldSchema, webhookSignatureSchema };
1201
1348
  //# sourceMappingURL=index.js.map
1202
1349
  //# sourceMappingURL=index.js.map