@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.
- package/README.md +15 -0
- package/dist/index.cjs +176 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +173 -2
- package/dist/index.js.map +1 -1
- package/dist/sdk-config/index.cjs +135 -1
- package/dist/sdk-config/index.cjs.map +1 -1
- package/dist/sdk-config/index.d.cts +1 -1
- package/dist/sdk-config/index.d.ts +1 -1
- package/dist/sdk-config/index.js +135 -2
- package/dist/sdk-config/index.js.map +1 -1
- package/dist/sdk-config/v1/index.cjs +135 -1
- package/dist/sdk-config/v1/index.cjs.map +1 -1
- package/dist/sdk-config/v1/index.d.cts +3367 -3329
- package/dist/sdk-config/v1/index.d.ts +3367 -3329
- package/dist/sdk-config/v1/index.js +135 -2
- package/dist/sdk-config/v1/index.js.map +1 -1
- package/dist/sdk-config-ir/index.cjs +150 -0
- package/dist/sdk-config-ir/index.cjs.map +1 -1
- package/dist/sdk-config-ir/index.d.cts +1 -1
- package/dist/sdk-config-ir/index.d.ts +1 -1
- package/dist/sdk-config-ir/index.js +148 -1
- package/dist/sdk-config-ir/index.js.map +1 -1
- package/dist/sdk-config-ir/v1/index.cjs +150 -0
- package/dist/sdk-config-ir/v1/index.cjs.map +1 -1
- package/dist/sdk-config-ir/v1/index.d.cts +26 -1
- package/dist/sdk-config-ir/v1/index.d.ts +26 -1
- package/dist/sdk-config-ir/v1/index.js +148 -1
- package/dist/sdk-config-ir/v1/index.js.map +1 -1
- package/package.json +1 -1
- package/src/sdk-config/v1/README.md +5 -3
- package/src/sdk-config-ir/v1/README.md +6 -0
|
@@ -772,6 +772,8 @@ var generationConfigSchema = zod.z.strictObject({
|
|
|
772
772
|
inferServiceNames: zod.z.boolean().default(false),
|
|
773
773
|
includeDeprecatedOperations: zod.z.boolean().default(true),
|
|
774
774
|
multipleResponses: zod.z.boolean().default(false),
|
|
775
|
+
/** Generate the entire SDK project, including package manifests and publishable artifacts. */
|
|
776
|
+
generateFullProject: zod.z.boolean().default(false),
|
|
775
777
|
devContainer: zod.z.boolean().default(false),
|
|
776
778
|
allowMockClient: zod.z.boolean().default(false),
|
|
777
779
|
ignoreFiles: zod.z.array(nonEmptyStringSchema).optional(),
|
|
@@ -1202,6 +1204,151 @@ var sdkConfigIrV1Schema = zod.z.strictObject({
|
|
|
1202
1204
|
function parseSdkConfigIrV1(value) {
|
|
1203
1205
|
return sdkConfigIrV1Schema.parse(value);
|
|
1204
1206
|
}
|
|
1207
|
+
var OMIT = /* @__PURE__ */ Symbol("omit");
|
|
1208
|
+
function inputJsonSchema(schema) {
|
|
1209
|
+
return zod.z.toJSONSchema(schema, {
|
|
1210
|
+
io: "input",
|
|
1211
|
+
unrepresentable: "any"
|
|
1212
|
+
});
|
|
1213
|
+
}
|
|
1214
|
+
function stripUnknownProperties(value, schema) {
|
|
1215
|
+
return project(value, schema, schema, false);
|
|
1216
|
+
}
|
|
1217
|
+
function omitSchemaDefaults(value, schema) {
|
|
1218
|
+
const projected = project(value, schema, schema, true);
|
|
1219
|
+
return projected === OMIT ? void 0 : projected;
|
|
1220
|
+
}
|
|
1221
|
+
function project(value, candidateSchema, rootSchema, omitDefaults) {
|
|
1222
|
+
const resolvedCandidate = resolveSchema(candidateSchema, rootSchema);
|
|
1223
|
+
if (omitDefaults && Object.hasOwn(resolvedCandidate, "default") && deepEqual(value, resolvedCandidate.default)) {
|
|
1224
|
+
return OMIT;
|
|
1225
|
+
}
|
|
1226
|
+
const schema = selectSchema(value, resolvedCandidate, rootSchema);
|
|
1227
|
+
if (omitDefaults && schema !== resolvedCandidate && Object.hasOwn(schema, "default") && deepEqual(value, schema.default)) {
|
|
1228
|
+
return OMIT;
|
|
1229
|
+
}
|
|
1230
|
+
if (Array.isArray(value)) {
|
|
1231
|
+
if (!schema.items) return value;
|
|
1232
|
+
return value.map((item) => {
|
|
1233
|
+
const projected = project(item, schema.items, rootSchema, omitDefaults);
|
|
1234
|
+
return projected === OMIT ? item : projected;
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
if (!isRecord(value) || schema.type !== "object") return value;
|
|
1238
|
+
const entries = [];
|
|
1239
|
+
const properties = schema.properties ?? {};
|
|
1240
|
+
const unionProperties = omitDefaults ? properties : collectAlternativeProperties(resolvedCandidate, rootSchema);
|
|
1241
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
1242
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
1243
|
+
const projected = project(value[key], propertySchema, rootSchema, omitDefaults);
|
|
1244
|
+
if (projected !== OMIT) entries.push([key, projected]);
|
|
1245
|
+
}
|
|
1246
|
+
for (const [key, fieldValue] of Object.entries(value)) {
|
|
1247
|
+
if (Object.hasOwn(properties, key)) continue;
|
|
1248
|
+
if (Object.hasOwn(unionProperties, key)) {
|
|
1249
|
+
entries.push([key, fieldValue]);
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (schema.additionalProperties !== false) {
|
|
1253
|
+
const projected = typeof schema.additionalProperties === "object" ? project(fieldValue, schema.additionalProperties, rootSchema, omitDefaults) : fieldValue;
|
|
1254
|
+
if (projected !== OMIT) entries.push([key, projected]);
|
|
1255
|
+
} else if (omitDefaults) {
|
|
1256
|
+
throw new Error(`Cannot serialize property unknown to the wire schema: ${key}`);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
return Object.fromEntries(entries);
|
|
1260
|
+
}
|
|
1261
|
+
function collectAlternativeProperties(schema, rootSchema) {
|
|
1262
|
+
const alternatives = schema.oneOf ?? schema.anyOf;
|
|
1263
|
+
if (!alternatives) return schema.properties ?? {};
|
|
1264
|
+
return Object.assign(
|
|
1265
|
+
{},
|
|
1266
|
+
...alternatives.map((alternative) => resolveSchema(alternative, rootSchema).properties ?? {})
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1269
|
+
function selectSchema(value, schema, rootSchema) {
|
|
1270
|
+
const alternatives = schema.oneOf ?? schema.anyOf;
|
|
1271
|
+
if (!alternatives || alternatives.length === 0) return schema;
|
|
1272
|
+
const best = alternatives.map((alternative, index) => {
|
|
1273
|
+
const resolved = resolveSchema(alternative, rootSchema);
|
|
1274
|
+
return { index, schema: resolved, score: schemaMatchScore(value, resolved) };
|
|
1275
|
+
}).sort((left, right) => right.score - left.score || left.index - right.index)[0];
|
|
1276
|
+
return best.score === Number.NEGATIVE_INFINITY ? schema : best.schema;
|
|
1277
|
+
}
|
|
1278
|
+
function schemaMatchScore(value, schema) {
|
|
1279
|
+
if (Object.hasOwn(schema, "const") && !deepEqual(value, schema.const)) {
|
|
1280
|
+
return Number.NEGATIVE_INFINITY;
|
|
1281
|
+
}
|
|
1282
|
+
if (schema.enum && !schema.enum.some((candidate) => deepEqual(value, candidate))) {
|
|
1283
|
+
return Number.NEGATIVE_INFINITY;
|
|
1284
|
+
}
|
|
1285
|
+
if (schema.type === "object") {
|
|
1286
|
+
if (!isRecord(value)) return Number.NEGATIVE_INFINITY;
|
|
1287
|
+
const properties = schema.properties ?? {};
|
|
1288
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
1289
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
1290
|
+
if (Object.hasOwn(propertySchema, "const") && !deepEqual(value[key], propertySchema.const)) {
|
|
1291
|
+
return Number.NEGATIVE_INFINITY;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return Object.keys(value).filter((key) => Object.hasOwn(properties, key)).length;
|
|
1295
|
+
}
|
|
1296
|
+
if (schema.type === "array") return Array.isArray(value) ? 1 : Number.NEGATIVE_INFINITY;
|
|
1297
|
+
if (schema.type === "string") return typeof value === "string" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1298
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
1299
|
+
return typeof value === "number" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1300
|
+
}
|
|
1301
|
+
if (schema.type === "boolean") return typeof value === "boolean" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1302
|
+
if (schema.type === "null") return value === null ? 1 : Number.NEGATIVE_INFINITY;
|
|
1303
|
+
return 0;
|
|
1304
|
+
}
|
|
1305
|
+
function resolveSchema(schema, rootSchema) {
|
|
1306
|
+
if (!schema.$ref) return schema;
|
|
1307
|
+
if (!schema.$ref.startsWith("#/$defs/")) return schema;
|
|
1308
|
+
const name = schema.$ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
|
|
1309
|
+
return rootSchema.$defs?.[name] ?? schema;
|
|
1310
|
+
}
|
|
1311
|
+
function isRecord(value) {
|
|
1312
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1313
|
+
}
|
|
1314
|
+
function deepEqual(left, right) {
|
|
1315
|
+
if (Object.is(left, right)) return true;
|
|
1316
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
1317
|
+
return left.length === right.length && left.every((value, index) => deepEqual(value, right[index]));
|
|
1318
|
+
}
|
|
1319
|
+
if (isRecord(left) && isRecord(right)) {
|
|
1320
|
+
const leftKeys = Object.keys(left);
|
|
1321
|
+
const rightKeys = Object.keys(right);
|
|
1322
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
|
|
1323
|
+
}
|
|
1324
|
+
return false;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
// src/sdk-config-ir/v1/wire.ts
|
|
1328
|
+
var sdkConfigIrCapabilitySchema = zod.z.enum(["generation.generateFullProject"]);
|
|
1329
|
+
var sdkConfigIrV1InputJsonSchema = inputJsonSchema(sdkConfigIrV1Schema);
|
|
1330
|
+
function serializeSdkConfigIrV1(value) {
|
|
1331
|
+
const parsed = parseSdkConfigIrV1(value);
|
|
1332
|
+
const wireValue = omitSchemaDefaults(parsed, sdkConfigIrV1InputJsonSchema);
|
|
1333
|
+
const requiredCapabilities = [];
|
|
1334
|
+
if (wireValue === void 0) {
|
|
1335
|
+
throw new Error("SDK Config IR v1 root cannot be omitted from its wire payload");
|
|
1336
|
+
}
|
|
1337
|
+
if (parsed.generation.generateFullProject) {
|
|
1338
|
+
requiredCapabilities.push("generation.generateFullProject");
|
|
1339
|
+
}
|
|
1340
|
+
const json = JSON.stringify(wireValue);
|
|
1341
|
+
if (json === void 0) {
|
|
1342
|
+
throw new Error("SDK Config IR v1 could not be serialized as JSON");
|
|
1343
|
+
}
|
|
1344
|
+
return {
|
|
1345
|
+
body: new TextEncoder().encode(json),
|
|
1346
|
+
requiredCapabilities
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
function parseSdkConfigIrV1ForConsumption(value) {
|
|
1350
|
+
return parseSdkConfigIrV1(stripUnknownProperties(value, sdkConfigIrV1InputJsonSchema));
|
|
1351
|
+
}
|
|
1205
1352
|
|
|
1206
1353
|
exports.SDK_CONFIG_IR_V1_SCHEMA_VERSION = SDK_CONFIG_IR_V1_SCHEMA_VERSION;
|
|
1207
1354
|
exports.apiConfigSchema = apiConfigSchema;
|
|
@@ -1233,6 +1380,7 @@ exports.nonEmptyStringSchema = nonEmptyStringSchema;
|
|
|
1233
1380
|
exports.outputConfigSchema = outputConfigSchema;
|
|
1234
1381
|
exports.packageConfigSchema = packageConfigSchema;
|
|
1235
1382
|
exports.parseSdkConfigIrV1 = parseSdkConfigIrV1;
|
|
1383
|
+
exports.parseSdkConfigIrV1ForConsumption = parseSdkConfigIrV1ForConsumption;
|
|
1236
1384
|
exports.phpGenerationConfigSchema = phpGenerationConfigSchema;
|
|
1237
1385
|
exports.publishConfigSchema = publishConfigSchema;
|
|
1238
1386
|
exports.publishRegistrySchema = publishRegistrySchema;
|
|
@@ -1243,7 +1391,9 @@ exports.relativePathSchema = relativePathSchema;
|
|
|
1243
1391
|
exports.replayConfigSchema = replayConfigSchema;
|
|
1244
1392
|
exports.rubyGenerationConfigSchema = rubyGenerationConfigSchema;
|
|
1245
1393
|
exports.rustGenerationConfigSchema = rustGenerationConfigSchema;
|
|
1394
|
+
exports.sdkConfigIrCapabilitySchema = sdkConfigIrCapabilitySchema;
|
|
1246
1395
|
exports.sdkConfigIrV1Schema = sdkConfigIrV1Schema;
|
|
1396
|
+
exports.serializeSdkConfigIrV1 = serializeSdkConfigIrV1;
|
|
1247
1397
|
exports.sourceConfigSchema = sourceConfigSchema;
|
|
1248
1398
|
exports.sourceSpecConfigSchema = sourceSpecConfigSchema;
|
|
1249
1399
|
exports.sourceSpecTypeSchema = sourceSpecTypeSchema;
|