@postman/sdk-config 0.5.1 → 0.7.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 +263 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +260 -28
- package/dist/index.js.map +1 -1
- package/dist/sdk-config/index.cjs +224 -27
- package/dist/sdk-config/index.cjs.map +1 -1
- package/dist/sdk-config/index.d.cts +2 -2
- package/dist/sdk-config/index.d.ts +2 -2
- package/dist/sdk-config/index.js +224 -28
- package/dist/sdk-config/index.js.map +1 -1
- package/dist/sdk-config/v1/index.cjs +224 -27
- package/dist/sdk-config/v1/index.cjs.map +1 -1
- package/dist/sdk-config/v1/index.d.cts +20 -2
- package/dist/sdk-config/v1/index.d.ts +20 -2
- package/dist/sdk-config/v1/index.js +224 -28
- package/dist/sdk-config/v1/index.js.map +1 -1
- package/dist/sdk-config-ir/index.cjs +153 -0
- package/dist/sdk-config-ir/index.cjs.map +1 -1
- package/dist/sdk-config-ir/index.d.cts +2 -2
- package/dist/sdk-config-ir/index.d.ts +2 -2
- package/dist/sdk-config-ir/index.js +151 -1
- package/dist/sdk-config-ir/index.js.map +1 -1
- package/dist/sdk-config-ir/v1/index.cjs +153 -0
- package/dist/sdk-config-ir/v1/index.cjs.map +1 -1
- package/dist/sdk-config-ir/v1/index.d.cts +43 -3
- package/dist/sdk-config-ir/v1/index.d.ts +43 -3
- package/dist/sdk-config-ir/v1/index.js +151 -1
- package/dist/sdk-config-ir/v1/index.js.map +1 -1
- package/dist/{typescript-BruxA5zG.d.cts → typescript-BdDv_kwT.d.cts} +8 -0
- package/dist/{typescript-BruxA5zG.d.ts → typescript-BdDv_kwT.d.ts} +8 -0
- package/package.json +1 -1
- package/src/sdk-config-ir/v1/README.md +10 -2
|
@@ -468,17 +468,22 @@ var typescriptGenerationConfigSchema = zod.z.strictObject({
|
|
|
468
468
|
compilerOptions: compilerOptionsSchema.optional(),
|
|
469
469
|
httpClient: httpClientSchema.optional(),
|
|
470
470
|
packageManager: zod.z.enum(["pnpm", "yarn"]).optional(),
|
|
471
|
+
/** e.g. `1.22.22` — from the customer's own `config.packageJson.packageManager` (`yarn@1.22.22`). */
|
|
472
|
+
packageManagerVersion: nonEmptyStringSchema.optional(),
|
|
471
473
|
testFramework: zod.z.enum(["jest", "vitest"]).optional(),
|
|
472
474
|
namingStrategy: zod.z.enum(["base", "originalPropertyNames"]).optional(),
|
|
473
475
|
bundle: zod.z.boolean().optional(),
|
|
474
476
|
exportClassDefault: zod.z.boolean().optional(),
|
|
475
477
|
/** Name of the top-level namespace export emitted by Fern-compatible TypeScript SDKs. */
|
|
476
478
|
namespaceExportName: nonEmptyStringSchema.optional(),
|
|
479
|
+
consolidateTypeFiles: zod.z.boolean().optional(),
|
|
477
480
|
allowCustomFetcher: zod.z.boolean().optional(),
|
|
478
481
|
useBrandedStringAliases: zod.z.boolean().optional(),
|
|
479
482
|
useLegacyExports: zod.z.boolean().optional(),
|
|
480
483
|
useBigInt: zod.z.boolean().optional(),
|
|
481
484
|
serdeLayer: zod.z.boolean().optional(),
|
|
485
|
+
/** Ship only the ESM build (drops CJS) to avoid the Node dual-package hazard. */
|
|
486
|
+
esmOnly: zod.z.boolean().optional(),
|
|
482
487
|
scripts: zod.z.array(packageScriptSchema).optional()
|
|
483
488
|
});
|
|
484
489
|
|
|
@@ -1204,6 +1209,151 @@ var sdkConfigIrV1Schema = zod.z.strictObject({
|
|
|
1204
1209
|
function parseSdkConfigIrV1(value) {
|
|
1205
1210
|
return sdkConfigIrV1Schema.parse(value);
|
|
1206
1211
|
}
|
|
1212
|
+
var OMIT = /* @__PURE__ */ Symbol("omit");
|
|
1213
|
+
function inputJsonSchema(schema) {
|
|
1214
|
+
return zod.z.toJSONSchema(schema, {
|
|
1215
|
+
io: "input",
|
|
1216
|
+
unrepresentable: "any"
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
function stripUnknownProperties(value, schema) {
|
|
1220
|
+
return project(value, schema, schema, false);
|
|
1221
|
+
}
|
|
1222
|
+
function omitSchemaDefaults(value, schema) {
|
|
1223
|
+
const projected = project(value, schema, schema, true);
|
|
1224
|
+
return projected === OMIT ? void 0 : projected;
|
|
1225
|
+
}
|
|
1226
|
+
function project(value, candidateSchema, rootSchema, omitDefaults) {
|
|
1227
|
+
const resolvedCandidate = resolveSchema(candidateSchema, rootSchema);
|
|
1228
|
+
if (omitDefaults && Object.hasOwn(resolvedCandidate, "default") && deepEqual(value, resolvedCandidate.default)) {
|
|
1229
|
+
return OMIT;
|
|
1230
|
+
}
|
|
1231
|
+
const schema = selectSchema(value, resolvedCandidate, rootSchema);
|
|
1232
|
+
if (omitDefaults && schema !== resolvedCandidate && Object.hasOwn(schema, "default") && deepEqual(value, schema.default)) {
|
|
1233
|
+
return OMIT;
|
|
1234
|
+
}
|
|
1235
|
+
if (Array.isArray(value)) {
|
|
1236
|
+
if (!schema.items) return value;
|
|
1237
|
+
return value.map((item) => {
|
|
1238
|
+
const projected = project(item, schema.items, rootSchema, omitDefaults);
|
|
1239
|
+
return projected === OMIT ? item : projected;
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
if (!isRecord(value) || schema.type !== "object") return value;
|
|
1243
|
+
const entries = [];
|
|
1244
|
+
const properties = schema.properties ?? {};
|
|
1245
|
+
const unionProperties = omitDefaults ? properties : collectAlternativeProperties(resolvedCandidate, rootSchema);
|
|
1246
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
1247
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
1248
|
+
const projected = project(value[key], propertySchema, rootSchema, omitDefaults);
|
|
1249
|
+
if (projected !== OMIT) entries.push([key, projected]);
|
|
1250
|
+
}
|
|
1251
|
+
for (const [key, fieldValue] of Object.entries(value)) {
|
|
1252
|
+
if (Object.hasOwn(properties, key)) continue;
|
|
1253
|
+
if (Object.hasOwn(unionProperties, key)) {
|
|
1254
|
+
entries.push([key, fieldValue]);
|
|
1255
|
+
continue;
|
|
1256
|
+
}
|
|
1257
|
+
if (schema.additionalProperties !== false) {
|
|
1258
|
+
const projected = typeof schema.additionalProperties === "object" ? project(fieldValue, schema.additionalProperties, rootSchema, omitDefaults) : fieldValue;
|
|
1259
|
+
if (projected !== OMIT) entries.push([key, projected]);
|
|
1260
|
+
} else if (omitDefaults) {
|
|
1261
|
+
throw new Error(`Cannot serialize property unknown to the wire schema: ${key}`);
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return Object.fromEntries(entries);
|
|
1265
|
+
}
|
|
1266
|
+
function collectAlternativeProperties(schema, rootSchema) {
|
|
1267
|
+
const alternatives = schema.oneOf ?? schema.anyOf;
|
|
1268
|
+
if (!alternatives) return schema.properties ?? {};
|
|
1269
|
+
return Object.assign(
|
|
1270
|
+
{},
|
|
1271
|
+
...alternatives.map((alternative) => resolveSchema(alternative, rootSchema).properties ?? {})
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
function selectSchema(value, schema, rootSchema) {
|
|
1275
|
+
const alternatives = schema.oneOf ?? schema.anyOf;
|
|
1276
|
+
if (!alternatives || alternatives.length === 0) return schema;
|
|
1277
|
+
const best = alternatives.map((alternative, index) => {
|
|
1278
|
+
const resolved = resolveSchema(alternative, rootSchema);
|
|
1279
|
+
return { index, schema: resolved, score: schemaMatchScore(value, resolved) };
|
|
1280
|
+
}).sort((left, right) => right.score - left.score || left.index - right.index)[0];
|
|
1281
|
+
return best.score === Number.NEGATIVE_INFINITY ? schema : best.schema;
|
|
1282
|
+
}
|
|
1283
|
+
function schemaMatchScore(value, schema) {
|
|
1284
|
+
if (Object.hasOwn(schema, "const") && !deepEqual(value, schema.const)) {
|
|
1285
|
+
return Number.NEGATIVE_INFINITY;
|
|
1286
|
+
}
|
|
1287
|
+
if (schema.enum && !schema.enum.some((candidate) => deepEqual(value, candidate))) {
|
|
1288
|
+
return Number.NEGATIVE_INFINITY;
|
|
1289
|
+
}
|
|
1290
|
+
if (schema.type === "object") {
|
|
1291
|
+
if (!isRecord(value)) return Number.NEGATIVE_INFINITY;
|
|
1292
|
+
const properties = schema.properties ?? {};
|
|
1293
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
1294
|
+
if (!Object.hasOwn(value, key)) continue;
|
|
1295
|
+
if (Object.hasOwn(propertySchema, "const") && !deepEqual(value[key], propertySchema.const)) {
|
|
1296
|
+
return Number.NEGATIVE_INFINITY;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return Object.keys(value).filter((key) => Object.hasOwn(properties, key)).length;
|
|
1300
|
+
}
|
|
1301
|
+
if (schema.type === "array") return Array.isArray(value) ? 1 : Number.NEGATIVE_INFINITY;
|
|
1302
|
+
if (schema.type === "string") return typeof value === "string" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1303
|
+
if (schema.type === "number" || schema.type === "integer") {
|
|
1304
|
+
return typeof value === "number" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1305
|
+
}
|
|
1306
|
+
if (schema.type === "boolean") return typeof value === "boolean" ? 1 : Number.NEGATIVE_INFINITY;
|
|
1307
|
+
if (schema.type === "null") return value === null ? 1 : Number.NEGATIVE_INFINITY;
|
|
1308
|
+
return 0;
|
|
1309
|
+
}
|
|
1310
|
+
function resolveSchema(schema, rootSchema) {
|
|
1311
|
+
if (!schema.$ref) return schema;
|
|
1312
|
+
if (!schema.$ref.startsWith("#/$defs/")) return schema;
|
|
1313
|
+
const name = schema.$ref.slice("#/$defs/".length).replaceAll("~1", "/").replaceAll("~0", "~");
|
|
1314
|
+
return rootSchema.$defs?.[name] ?? schema;
|
|
1315
|
+
}
|
|
1316
|
+
function isRecord(value) {
|
|
1317
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1318
|
+
}
|
|
1319
|
+
function deepEqual(left, right) {
|
|
1320
|
+
if (Object.is(left, right)) return true;
|
|
1321
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
1322
|
+
return left.length === right.length && left.every((value, index) => deepEqual(value, right[index]));
|
|
1323
|
+
}
|
|
1324
|
+
if (isRecord(left) && isRecord(right)) {
|
|
1325
|
+
const leftKeys = Object.keys(left);
|
|
1326
|
+
const rightKeys = Object.keys(right);
|
|
1327
|
+
return leftKeys.length === rightKeys.length && leftKeys.every((key) => Object.hasOwn(right, key) && deepEqual(left[key], right[key]));
|
|
1328
|
+
}
|
|
1329
|
+
return false;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// src/sdk-config-ir/v1/wire.ts
|
|
1333
|
+
var sdkConfigIrCapabilitySchema = zod.z.enum(["generation.generateFullProject"]);
|
|
1334
|
+
var sdkConfigIrV1InputJsonSchema = inputJsonSchema(sdkConfigIrV1Schema);
|
|
1335
|
+
function serializeSdkConfigIrV1(value) {
|
|
1336
|
+
const parsed = parseSdkConfigIrV1(value);
|
|
1337
|
+
const wireValue = omitSchemaDefaults(parsed, sdkConfigIrV1InputJsonSchema);
|
|
1338
|
+
const requiredCapabilities = [];
|
|
1339
|
+
if (wireValue === void 0) {
|
|
1340
|
+
throw new Error("SDK Config IR v1 root cannot be omitted from its wire payload");
|
|
1341
|
+
}
|
|
1342
|
+
if (parsed.generation.generateFullProject) {
|
|
1343
|
+
requiredCapabilities.push("generation.generateFullProject");
|
|
1344
|
+
}
|
|
1345
|
+
const json = JSON.stringify(wireValue);
|
|
1346
|
+
if (json === void 0) {
|
|
1347
|
+
throw new Error("SDK Config IR v1 could not be serialized as JSON");
|
|
1348
|
+
}
|
|
1349
|
+
return {
|
|
1350
|
+
body: new TextEncoder().encode(json),
|
|
1351
|
+
requiredCapabilities
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
function parseSdkConfigIrV1ForConsumption(value) {
|
|
1355
|
+
return parseSdkConfigIrV1(stripUnknownProperties(value, sdkConfigIrV1InputJsonSchema));
|
|
1356
|
+
}
|
|
1207
1357
|
|
|
1208
1358
|
exports.SDK_CONFIG_IR_V1_SCHEMA_VERSION = SDK_CONFIG_IR_V1_SCHEMA_VERSION;
|
|
1209
1359
|
exports.apiConfigSchema = apiConfigSchema;
|
|
@@ -1235,6 +1385,7 @@ exports.nonEmptyStringSchema = nonEmptyStringSchema;
|
|
|
1235
1385
|
exports.outputConfigSchema = outputConfigSchema;
|
|
1236
1386
|
exports.packageConfigSchema = packageConfigSchema;
|
|
1237
1387
|
exports.parseSdkConfigIrV1 = parseSdkConfigIrV1;
|
|
1388
|
+
exports.parseSdkConfigIrV1ForConsumption = parseSdkConfigIrV1ForConsumption;
|
|
1238
1389
|
exports.phpGenerationConfigSchema = phpGenerationConfigSchema;
|
|
1239
1390
|
exports.publishConfigSchema = publishConfigSchema;
|
|
1240
1391
|
exports.publishRegistrySchema = publishRegistrySchema;
|
|
@@ -1245,7 +1396,9 @@ exports.relativePathSchema = relativePathSchema;
|
|
|
1245
1396
|
exports.replayConfigSchema = replayConfigSchema;
|
|
1246
1397
|
exports.rubyGenerationConfigSchema = rubyGenerationConfigSchema;
|
|
1247
1398
|
exports.rustGenerationConfigSchema = rustGenerationConfigSchema;
|
|
1399
|
+
exports.sdkConfigIrCapabilitySchema = sdkConfigIrCapabilitySchema;
|
|
1248
1400
|
exports.sdkConfigIrV1Schema = sdkConfigIrV1Schema;
|
|
1401
|
+
exports.serializeSdkConfigIrV1 = serializeSdkConfigIrV1;
|
|
1249
1402
|
exports.sourceConfigSchema = sourceConfigSchema;
|
|
1250
1403
|
exports.sourceSpecConfigSchema = sourceSpecConfigSchema;
|
|
1251
1404
|
exports.sourceSpecTypeSchema = sourceSpecTypeSchema;
|