fern-api 0.41.0-rc1 → 0.41.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/bundle.cjs +379 -22
- package/package.json +1 -1
package/bundle.cjs
CHANGED
|
@@ -1208726,7 +1208726,7 @@ var AccessTokenPosthogManager = class {
|
|
|
1208726
1208726
|
properties: {
|
|
1208727
1208727
|
...event,
|
|
1208728
1208728
|
...event.properties,
|
|
1208729
|
-
version: "0.41.0
|
|
1208729
|
+
version: "0.41.0",
|
|
1208730
1208730
|
usingAccessToken: true
|
|
1208731
1208731
|
}
|
|
1208732
1208732
|
});
|
|
@@ -1208788,7 +1208788,7 @@ var UserPosthogManager = class {
|
|
|
1208788
1208788
|
distinctId: this.userId ?? await this.getPersistedDistinctId(),
|
|
1208789
1208789
|
event: "CLI",
|
|
1208790
1208790
|
properties: {
|
|
1208791
|
-
version: "0.41.0
|
|
1208791
|
+
version: "0.41.0",
|
|
1208792
1208792
|
...event,
|
|
1208793
1208793
|
...event.properties
|
|
1208794
1208794
|
}
|
|
@@ -1213878,10 +1213878,10 @@ var CliContext = class {
|
|
|
1213878
1213878
|
return "fern-api";
|
|
1213879
1213879
|
}
|
|
1213880
1213880
|
getPackageVersion() {
|
|
1213881
|
-
if ("0.41.0
|
|
1213881
|
+
if ("0.41.0" == null) {
|
|
1213882
1213882
|
this.logger.error("CLI_VERSION is not defined");
|
|
1213883
1213883
|
}
|
|
1213884
|
-
return "0.41.0
|
|
1213884
|
+
return "0.41.0";
|
|
1213885
1213885
|
}
|
|
1213886
1213886
|
getCliName() {
|
|
1213887
1213887
|
if ("fern" == null) {
|
|
@@ -1215080,6 +1215080,33 @@ var RootApiFileSchema = z.strictObject({
|
|
|
1215080
1215080
|
version: z.optional(VersionDeclarationSchema)
|
|
1215081
1215081
|
});
|
|
1215082
1215082
|
|
|
1215083
|
+
// ../fern-definition/schema/lib/utils/RawContainerType.js
|
|
1215084
|
+
var RawContainerType = {
|
|
1215085
|
+
optional: "optional",
|
|
1215086
|
+
set: "set",
|
|
1215087
|
+
list: "list",
|
|
1215088
|
+
map: "map",
|
|
1215089
|
+
literal: "literal"
|
|
1215090
|
+
};
|
|
1215091
|
+
var RawContanerTypes = new Set(Object.values(RawContainerType));
|
|
1215092
|
+
|
|
1215093
|
+
// ../fern-definition/schema/lib/utils/generics/parseGeneric.js
|
|
1215094
|
+
function parseGeneric(name2) {
|
|
1215095
|
+
const genericMatch = name2.match(/([\w.]+)<([\w,\s]+)>/);
|
|
1215096
|
+
if ((genericMatch == null ? void 0 : genericMatch[0]) != null && genericMatch[1] != null && genericMatch[2] != null && !RawContanerTypes.has(genericMatch[1].trim())) {
|
|
1215097
|
+
return {
|
|
1215098
|
+
name: genericMatch[1].trim(),
|
|
1215099
|
+
arguments: genericMatch[2].split(",").map((arg) => arg.trim())
|
|
1215100
|
+
};
|
|
1215101
|
+
}
|
|
1215102
|
+
return void 0;
|
|
1215103
|
+
}
|
|
1215104
|
+
|
|
1215105
|
+
// ../fern-definition/schema/lib/utils/generics/isGeneric.js
|
|
1215106
|
+
function isGeneric(name2) {
|
|
1215107
|
+
return parseGeneric(name2) != null;
|
|
1215108
|
+
}
|
|
1215109
|
+
|
|
1215083
1215110
|
// ../fern-definition/schema/lib/utils/getRequestBody.js
|
|
1215084
1215111
|
function getRequestBody(endpoint) {
|
|
1215085
1215112
|
if (endpoint.request == null) {
|
|
@@ -1257323,9 +1257350,44 @@ function maybeConvertWellKnownProtobufType({ type: type2 }) {
|
|
|
1257323
1257350
|
return void 0;
|
|
1257324
1257351
|
}
|
|
1257325
1257352
|
|
|
1257353
|
+
// ../generation/ir-generator/lib/converters/type-declarations/convertGenericTypeDeclaration.js
|
|
1257354
|
+
async function convertGenericTypeDeclaration({ generic, file, typeResolver }) {
|
|
1257355
|
+
var _a6;
|
|
1257356
|
+
const genericInstantiation = typeof generic === "string" ? generic : generic.type;
|
|
1257357
|
+
const maybeGeneric = parseGeneric(genericInstantiation);
|
|
1257358
|
+
if (maybeGeneric == null) {
|
|
1257359
|
+
throw new Error(`Invalid generic type definition: ${genericInstantiation}`);
|
|
1257360
|
+
}
|
|
1257361
|
+
const resolvedBaseGeneric = typeResolver.getDeclarationOfNamedTypeOrThrow({
|
|
1257362
|
+
referenceToNamedType: genericInstantiation,
|
|
1257363
|
+
file
|
|
1257364
|
+
});
|
|
1257365
|
+
if (maybeGeneric.arguments && isRawObjectDefinition(resolvedBaseGeneric.declaration)) {
|
|
1257366
|
+
const genericArgumentDefinitions = ((_a6 = parseGeneric(resolvedBaseGeneric.typeName)) == null ? void 0 : _a6.arguments) ?? [];
|
|
1257367
|
+
const newProperties = Object.entries(resolvedBaseGeneric.declaration.properties ?? {}).map(([key, value]) => {
|
|
1257368
|
+
var _a7;
|
|
1257369
|
+
let maybeReplacedValue = value;
|
|
1257370
|
+
if (typeof value === "string" && (genericArgumentDefinitions == null ? void 0 : genericArgumentDefinitions.includes(value))) {
|
|
1257371
|
+
maybeReplacedValue = ((_a7 = maybeGeneric.arguments) == null ? void 0 : _a7[genericArgumentDefinitions.indexOf(value)]) ?? value;
|
|
1257372
|
+
}
|
|
1257373
|
+
return [key, maybeReplacedValue];
|
|
1257374
|
+
});
|
|
1257375
|
+
return Type2.object({
|
|
1257376
|
+
extends: getExtensionsAsList(resolvedBaseGeneric.declaration.extends).map((extended) => parseTypeName({ typeName: extended, file })),
|
|
1257377
|
+
properties: await getObjectPropertiesFromRawObjectSchema({ properties: Object.fromEntries(newProperties) }, file),
|
|
1257378
|
+
extraProperties: resolvedBaseGeneric.declaration["extra-properties"] ?? false,
|
|
1257379
|
+
extendedProperties: void 0
|
|
1257380
|
+
});
|
|
1257381
|
+
}
|
|
1257382
|
+
throw new Error(`Generic type definition not supported: ${genericInstantiation}`);
|
|
1257383
|
+
}
|
|
1257384
|
+
|
|
1257326
1257385
|
// ../generation/ir-generator/lib/converters/type-declarations/convertAliasTypeDeclaration.js
|
|
1257327
|
-
function convertAliasTypeDeclaration({ alias, file, typeResolver }) {
|
|
1257386
|
+
async function convertAliasTypeDeclaration({ alias, file, typeResolver }) {
|
|
1257328
1257387
|
const aliasOfStr = typeof alias === "string" ? alias : alias.type;
|
|
1257388
|
+
if (isGeneric(aliasOfStr)) {
|
|
1257389
|
+
return await convertGenericTypeDeclaration({ generic: aliasOfStr, file, typeResolver });
|
|
1257390
|
+
}
|
|
1257329
1257391
|
return Type2.alias({
|
|
1257330
1257392
|
aliasOf: file.parseTypeReference(alias),
|
|
1257331
1257393
|
resolvedType: constructResolvedTypeReference({ aliasOf: aliasOfStr, file, typeResolver })
|
|
@@ -1257369,22 +1257431,41 @@ function convertUndiscriminatedUnionTypeDeclaration({ union: union4, file }) {
|
|
|
1257369
1257431
|
}
|
|
1257370
1257432
|
|
|
1257371
1257433
|
// ../generation/ir-generator/lib/converters/type-declarations/getReferencedTypesFromRawDeclaration.js
|
|
1257434
|
+
function getObjectRawTypeReferences(objectDeclaration) {
|
|
1257435
|
+
const types3 = [];
|
|
1257436
|
+
if (objectDeclaration.extends != null) {
|
|
1257437
|
+
const extendsArr = typeof objectDeclaration.extends === "string" ? [objectDeclaration.extends] : objectDeclaration.extends;
|
|
1257438
|
+
types3.push(...extendsArr);
|
|
1257439
|
+
}
|
|
1257440
|
+
if (objectDeclaration.properties != null) {
|
|
1257441
|
+
types3.push(...Object.values(objectDeclaration.properties).map((property5) => typeof property5 === "string" ? property5 : property5.type));
|
|
1257442
|
+
}
|
|
1257443
|
+
return types3;
|
|
1257444
|
+
}
|
|
1257372
1257445
|
function getReferencedTypesFromRawDeclaration({ typeDeclaration, file, typeResolver, seenTypeNames = new SeenTypeNamesImpl() }) {
|
|
1257373
1257446
|
const rawTypeReferences = visitRawTypeDeclaration(typeDeclaration, {
|
|
1257374
1257447
|
alias: (aliasDeclaration) => {
|
|
1257375
|
-
|
|
1257376
|
-
|
|
1257377
|
-
|
|
1257378
|
-
|
|
1257379
|
-
|
|
1257380
|
-
const
|
|
1257381
|
-
|
|
1257382
|
-
|
|
1257383
|
-
|
|
1257384
|
-
|
|
1257448
|
+
var _a6;
|
|
1257449
|
+
const aliasTypeReference = typeof aliasDeclaration === "string" ? aliasDeclaration : aliasDeclaration.type;
|
|
1257450
|
+
const parsedGeneric = parseGeneric(aliasTypeReference);
|
|
1257451
|
+
if (parsedGeneric != null) {
|
|
1257452
|
+
const rawTypeReferences2 = new Set(parsedGeneric.arguments ?? []);
|
|
1257453
|
+
const resolvedBaseGeneric = typeResolver.getDeclarationOfNamedTypeOrThrow({
|
|
1257454
|
+
referenceToNamedType: aliasTypeReference,
|
|
1257455
|
+
file
|
|
1257456
|
+
});
|
|
1257457
|
+
const resolvedBaseGenericArguments = (_a6 = parseGeneric(resolvedBaseGeneric.typeName)) == null ? void 0 : _a6.arguments;
|
|
1257458
|
+
if (isRawObjectDefinition(resolvedBaseGeneric.declaration)) {
|
|
1257459
|
+
const underlyingObjectRawTypeReferences = getObjectRawTypeReferences(resolvedBaseGeneric.declaration);
|
|
1257460
|
+
if (resolvedBaseGenericArguments) {
|
|
1257461
|
+
underlyingObjectRawTypeReferences.filter((typeReference) => !resolvedBaseGenericArguments.includes(typeReference)).forEach((type2) => rawTypeReferences2.add(type2));
|
|
1257462
|
+
}
|
|
1257463
|
+
}
|
|
1257464
|
+
return Array.from(rawTypeReferences2);
|
|
1257385
1257465
|
}
|
|
1257386
|
-
return
|
|
1257466
|
+
return [aliasTypeReference];
|
|
1257387
1257467
|
},
|
|
1257468
|
+
object: (objectDeclaration) => getObjectRawTypeReferences(objectDeclaration),
|
|
1257388
1257469
|
discriminatedUnion: (unionDeclaration) => {
|
|
1257389
1257470
|
const types3 = [];
|
|
1257390
1257471
|
if (unionDeclaration["base-properties"] != null) {
|
|
@@ -1257436,6 +1257517,9 @@ function getReferencedTypesFromRawDeclaration({ typeDeclaration, file, typeResol
|
|
|
1257436
1257517
|
referenceToNamedType: rawName,
|
|
1257437
1257518
|
file
|
|
1257438
1257519
|
});
|
|
1257520
|
+
if (isGeneric(maybeDeclaration.typeName)) {
|
|
1257521
|
+
continue;
|
|
1257522
|
+
}
|
|
1257439
1257523
|
referencedTypes.push(...getReferencedTypesFromRawDeclaration({
|
|
1257440
1257524
|
typeDeclaration: maybeDeclaration.declaration,
|
|
1257441
1257525
|
file: maybeDeclaration.file,
|
|
@@ -1259904,7 +1259988,7 @@ var TypeResolverImpl = class {
|
|
|
1259904
1259988
|
return declaration;
|
|
1259905
1259989
|
}
|
|
1259906
1259990
|
getDeclarationOfNamedType({ referenceToNamedType, file }) {
|
|
1259907
|
-
var _a6;
|
|
1259991
|
+
var _a6, _b4;
|
|
1259908
1259992
|
const parsedReference = parseReferenceToTypeName({
|
|
1259909
1259993
|
reference: referenceToNamedType,
|
|
1259910
1259994
|
referencedIn: file.relativeFilepath,
|
|
@@ -1259919,6 +1260003,24 @@ var TypeResolverImpl = class {
|
|
|
1259919
1260003
|
}
|
|
1259920
1260004
|
const declaration = (_a6 = definitionFile.types) == null ? void 0 : _a6[parsedReference.typeName];
|
|
1259921
1260005
|
if (declaration == null) {
|
|
1260006
|
+
const parsedGeneric = parseGeneric(parsedReference.typeName);
|
|
1260007
|
+
if (parsedGeneric != null) {
|
|
1260008
|
+
for (const type2 of Object.keys(definitionFile.types ?? {}) ?? []) {
|
|
1260009
|
+
if (parsedGeneric.name && type2.startsWith(parsedGeneric.name) && type2.endsWith(">")) {
|
|
1260010
|
+
const genericDeclaration = (_b4 = definitionFile.types) == null ? void 0 : _b4[type2];
|
|
1260011
|
+
return genericDeclaration != null ? {
|
|
1260012
|
+
typeName: type2,
|
|
1260013
|
+
declaration: genericDeclaration,
|
|
1260014
|
+
file: constructFernFileContext({
|
|
1260015
|
+
relativeFilepath: parsedReference.relativeFilepath,
|
|
1260016
|
+
definitionFile,
|
|
1260017
|
+
casingsGenerator: file.casingsGenerator,
|
|
1260018
|
+
rootApiFile: this.workspace.definition.rootApiFile.contents
|
|
1260019
|
+
})
|
|
1260020
|
+
} : void 0;
|
|
1260021
|
+
}
|
|
1260022
|
+
}
|
|
1260023
|
+
}
|
|
1259922
1260024
|
return void 0;
|
|
1259923
1260025
|
}
|
|
1259924
1260026
|
return {
|
|
@@ -1260211,6 +1260313,9 @@ async function generateIntermediateRepresentation({ fdrApiDefinitionId, workspac
|
|
|
1260211
1260313
|
return;
|
|
1260212
1260314
|
}
|
|
1260213
1260315
|
for (const [typeName, typeDeclaration] of Object.entries(types4)) {
|
|
1260316
|
+
if (isGeneric(typeName)) {
|
|
1260317
|
+
continue;
|
|
1260318
|
+
}
|
|
1260214
1260319
|
const convertedTypeDeclarationWithFilepaths = await convertTypeDeclaration({
|
|
1260215
1260320
|
typeName,
|
|
1260216
1260321
|
typeDeclaration,
|
|
@@ -1265234,7 +1265339,8 @@ function createTypeReferenceVisitor(visitor) {
|
|
|
1265234
1265339
|
typeReference,
|
|
1265235
1265340
|
_default: _default2,
|
|
1265236
1265341
|
validation,
|
|
1265237
|
-
location: location3
|
|
1265342
|
+
location: location3,
|
|
1265343
|
+
nodePath
|
|
1265238
1265344
|
}, nodePath));
|
|
1265239
1265345
|
};
|
|
1265240
1265346
|
}
|
|
@@ -1265713,7 +1265819,7 @@ async function visitTypeDeclarations({ typeDeclarations, visitor, nodePath }) {
|
|
|
1265713
1265819
|
async function visitTypeDeclaration({ typeName, declaration, visitor, nodePathForType }) {
|
|
1265714
1265820
|
var _a6;
|
|
1265715
1265821
|
const visitTypeReference = createTypeReferenceVisitor(visitor);
|
|
1265716
|
-
await ((_a6 = visitor.typeDeclaration) == null ? void 0 : _a6.call(visitor, { typeName: { isInlined: false, name: typeName }, declaration }, nodePathForType));
|
|
1265822
|
+
await ((_a6 = visitor.typeDeclaration) == null ? void 0 : _a6.call(visitor, { typeName: { isInlined: false, name: typeName }, declaration, nodePath: nodePathForType }, nodePathForType));
|
|
1265717
1265823
|
const visitExamples = async (examples) => {
|
|
1265718
1265824
|
var _a7;
|
|
1265719
1265825
|
if (examples == null) {
|
|
@@ -1267781,11 +1267887,29 @@ var NoUndefinedTypeReferenceRule = {
|
|
|
1267781
1267887
|
if (typesForFilepath == null) {
|
|
1267782
1267888
|
return false;
|
|
1267783
1267889
|
}
|
|
1267890
|
+
const maybeGeneric = parseGeneric(reference.parsed.typeName);
|
|
1267891
|
+
if (maybeGeneric != null) {
|
|
1267892
|
+
return maybeGeneric.name ? typesForFilepath.has(maybeGeneric.name) : false;
|
|
1267893
|
+
}
|
|
1267784
1267894
|
return typesForFilepath.has(reference.parsed.typeName);
|
|
1267785
1267895
|
}
|
|
1267896
|
+
function checkGenericType(reference, nodePath) {
|
|
1267897
|
+
var _a6, _b4, _c4;
|
|
1267898
|
+
if (nodePath != null) {
|
|
1267899
|
+
const mutableNodePath = [...nodePath];
|
|
1267900
|
+
while (mutableNodePath.length > 0) {
|
|
1267901
|
+
const nodePathItem = mutableNodePath.pop();
|
|
1267902
|
+
const maybeGeneric = nodePathItem ? typeof nodePathItem === "string" ? parseGeneric(nodePathItem) : parseGeneric(nodePathItem.key) : void 0;
|
|
1267903
|
+
if (maybeGeneric != null) {
|
|
1267904
|
+
return ((_a6 = reference.parsed) == null ? void 0 : _a6.typeName) && ((_c4 = maybeGeneric.arguments) == null ? void 0 : _c4.includes((_b4 = reference.parsed) == null ? void 0 : _b4.typeName));
|
|
1267905
|
+
}
|
|
1267906
|
+
}
|
|
1267907
|
+
}
|
|
1267908
|
+
return false;
|
|
1267909
|
+
}
|
|
1267786
1267910
|
return {
|
|
1267787
1267911
|
definitionFile: {
|
|
1267788
|
-
typeReference: ({ typeReference, location: location3 }, { relativeFilepath, contents }) => {
|
|
1267912
|
+
typeReference: ({ typeReference, location: location3, nodePath }, { relativeFilepath, contents }) => {
|
|
1267789
1267913
|
const parsedRawFileType = parseRawFileType(typeReference);
|
|
1267790
1267914
|
if (parsedRawFileType != null) {
|
|
1267791
1267915
|
if (location3 === TypeReferenceLocation.InlinedRequestProperty) {
|
|
@@ -1267848,7 +1267972,7 @@ var NoUndefinedTypeReferenceRule = {
|
|
|
1267848
1267972
|
severity: "error",
|
|
1267849
1267973
|
message: "The text type can only be used as a response-stream or response."
|
|
1267850
1267974
|
});
|
|
1267851
|
-
} else if (!doesTypeExist(namedType)) {
|
|
1267975
|
+
} else if (!doesTypeExist(namedType) && !checkGenericType(namedType, nodePath)) {
|
|
1267852
1267976
|
violations.push({
|
|
1267853
1267977
|
severity: "error",
|
|
1267854
1267978
|
message: `Type ${source_default.bold(((_c4 = namedType.parsed) == null ? void 0 : _c4.typeName) ?? namedType.fullyQualifiedName)} is not defined.`
|
|
@@ -1267869,6 +1267993,12 @@ async function getTypesByFilepath(workspace) {
|
|
|
1267869
1267993
|
await visitDefinitionFileYamlAst(file, {
|
|
1267870
1267994
|
typeDeclaration: ({ typeName }) => {
|
|
1267871
1267995
|
if (!typeName.isInlined) {
|
|
1267996
|
+
const maybeGenericDeclaration = parseGeneric(typeName.name);
|
|
1267997
|
+
if (maybeGenericDeclaration != null) {
|
|
1267998
|
+
if (maybeGenericDeclaration.name) {
|
|
1267999
|
+
typesForFile.add(maybeGenericDeclaration.name);
|
|
1268000
|
+
}
|
|
1268001
|
+
}
|
|
1267872
1268002
|
typesForFile.add(typeName.name);
|
|
1267873
1268003
|
}
|
|
1267874
1268004
|
}
|
|
@@ -1267958,6 +1268088,56 @@ var NoUndefinedVariableReferenceRule = {
|
|
|
1267958
1268088
|
}
|
|
1267959
1268089
|
};
|
|
1267960
1268090
|
|
|
1268091
|
+
// ../fern-definition/validator/lib/rules/no-unused-generic/no-unused-generic.js
|
|
1268092
|
+
var NoUnusedGenericRule = {
|
|
1268093
|
+
name: "no-unused-generic",
|
|
1268094
|
+
create: async ({ workspace }) => {
|
|
1268095
|
+
const instantiations = /* @__PURE__ */ new Set();
|
|
1268096
|
+
await visitAllDefinitionFiles(workspace, async (_4, file) => {
|
|
1268097
|
+
await visitDefinitionFileYamlAst(file, {
|
|
1268098
|
+
typeDeclaration: (type2) => {
|
|
1268099
|
+
visitRawTypeDeclaration(type2.declaration, {
|
|
1268100
|
+
alias: (alias) => {
|
|
1268101
|
+
const maybeGenericDeclaration = parseGeneric(typeof alias === "string" ? alias : alias.type);
|
|
1268102
|
+
if (maybeGenericDeclaration != null && maybeGenericDeclaration.name) {
|
|
1268103
|
+
const [maybeTypeName, typeName, ..._rest] = maybeGenericDeclaration.name.split(".");
|
|
1268104
|
+
const key = typeName ?? maybeTypeName;
|
|
1268105
|
+
if (key) {
|
|
1268106
|
+
instantiations.add(key);
|
|
1268107
|
+
}
|
|
1268108
|
+
}
|
|
1268109
|
+
},
|
|
1268110
|
+
enum: () => {
|
|
1268111
|
+
},
|
|
1268112
|
+
object: () => {
|
|
1268113
|
+
},
|
|
1268114
|
+
discriminatedUnion: () => {
|
|
1268115
|
+
},
|
|
1268116
|
+
undiscriminatedUnion: () => {
|
|
1268117
|
+
}
|
|
1268118
|
+
});
|
|
1268119
|
+
}
|
|
1268120
|
+
});
|
|
1268121
|
+
});
|
|
1268122
|
+
return {
|
|
1268123
|
+
definitionFile: {
|
|
1268124
|
+
typeName: (name2) => {
|
|
1268125
|
+
const maybeGenericDeclaration = parseGeneric(name2);
|
|
1268126
|
+
if (maybeGenericDeclaration == null) {
|
|
1268127
|
+
return [];
|
|
1268128
|
+
}
|
|
1268129
|
+
return maybeGenericDeclaration.name && instantiations.has(maybeGenericDeclaration.name) ? [] : [
|
|
1268130
|
+
{
|
|
1268131
|
+
severity: "error",
|
|
1268132
|
+
message: `Generic "${name2}" is declared but never used.`
|
|
1268133
|
+
}
|
|
1268134
|
+
];
|
|
1268135
|
+
}
|
|
1268136
|
+
}
|
|
1268137
|
+
};
|
|
1268138
|
+
}
|
|
1268139
|
+
};
|
|
1268140
|
+
|
|
1267961
1268141
|
// ../fern-definition/validator/lib/rules/only-object-extensions/only-object-extensions.js
|
|
1267962
1268142
|
var OnlyObjectExtensionsRule = {
|
|
1267963
1268143
|
name: "only-object-extensions",
|
|
@@ -1268576,6 +1268756,181 @@ var ValidFieldNamesRule = {
|
|
|
1268576
1268756
|
}
|
|
1268577
1268757
|
};
|
|
1268578
1268758
|
|
|
1268759
|
+
// ../fern-definition/validator/lib/rules/valid-generic/valid-generic.js
|
|
1268760
|
+
var ValidGenericRule = {
|
|
1268761
|
+
name: "valid-generic",
|
|
1268762
|
+
create: async ({ workspace }) => {
|
|
1268763
|
+
const genericArgumentCounts = await getGenericArgumentCounts(workspace);
|
|
1268764
|
+
const propertyBasedErrors = {
|
|
1268765
|
+
object: [],
|
|
1268766
|
+
discriminatedUnion: []
|
|
1268767
|
+
};
|
|
1268768
|
+
return {
|
|
1268769
|
+
definitionFile: {
|
|
1268770
|
+
typeDeclaration: ({ typeName, declaration, nodePath }) => {
|
|
1268771
|
+
const errors2 = [];
|
|
1268772
|
+
if (!typeName.isInlined) {
|
|
1268773
|
+
const maybeGeneric = parseGeneric(typeName.name);
|
|
1268774
|
+
if (maybeGeneric != null) {
|
|
1268775
|
+
if (!visitRawTypeDeclaration(declaration, {
|
|
1268776
|
+
alias: () => {
|
|
1268777
|
+
return false;
|
|
1268778
|
+
},
|
|
1268779
|
+
enum: () => {
|
|
1268780
|
+
return false;
|
|
1268781
|
+
},
|
|
1268782
|
+
object: () => {
|
|
1268783
|
+
return true;
|
|
1268784
|
+
},
|
|
1268785
|
+
discriminatedUnion: () => {
|
|
1268786
|
+
return false;
|
|
1268787
|
+
},
|
|
1268788
|
+
undiscriminatedUnion: () => {
|
|
1268789
|
+
return false;
|
|
1268790
|
+
}
|
|
1268791
|
+
})) {
|
|
1268792
|
+
errors2.push({
|
|
1268793
|
+
severity: "error",
|
|
1268794
|
+
message: "Generics are only supported for object declarations"
|
|
1268795
|
+
});
|
|
1268796
|
+
}
|
|
1268797
|
+
}
|
|
1268798
|
+
}
|
|
1268799
|
+
visitRawTypeDeclaration(declaration, {
|
|
1268800
|
+
alias: (aliasValue) => {
|
|
1268801
|
+
const alias = typeof aliasValue === "string" ? aliasValue : aliasValue.type;
|
|
1268802
|
+
const maybeGeneric = parseGeneric(alias);
|
|
1268803
|
+
if (maybeGeneric != null) {
|
|
1268804
|
+
const [maybeTypeName, typeName2, ..._rest] = maybeGeneric.name.split(".");
|
|
1268805
|
+
const key = typeName2 ?? maybeTypeName;
|
|
1268806
|
+
if (key && key in genericArgumentCounts && genericArgumentCounts[key] !== maybeGeneric.arguments.length) {
|
|
1268807
|
+
errors2.push({
|
|
1268808
|
+
severity: "error",
|
|
1268809
|
+
message: `Generic ${key} expects ${genericArgumentCounts[key]} arguments, but received ${maybeGeneric.arguments.length} <${maybeGeneric.arguments.join(",")}>`
|
|
1268810
|
+
});
|
|
1268811
|
+
}
|
|
1268812
|
+
} else {
|
|
1268813
|
+
if (alias in genericArgumentCounts) {
|
|
1268814
|
+
errors2.push({
|
|
1268815
|
+
severity: "error",
|
|
1268816
|
+
message: `Generic ${alias} expects ${genericArgumentCounts[alias]} arguments, but received none`
|
|
1268817
|
+
});
|
|
1268818
|
+
}
|
|
1268819
|
+
}
|
|
1268820
|
+
},
|
|
1268821
|
+
enum: (enumValue) => {
|
|
1268822
|
+
if (typeof enumValue !== "string") {
|
|
1268823
|
+
enumValue.enum.forEach((value) => {
|
|
1268824
|
+
const enumValue2 = typeof value === "string" ? value : value.value;
|
|
1268825
|
+
if (isGeneric(enumValue2)) {
|
|
1268826
|
+
errors2.push({
|
|
1268827
|
+
severity: "error",
|
|
1268828
|
+
message: `Cannot reference generic ${enumValue2} from enum`
|
|
1268829
|
+
});
|
|
1268830
|
+
}
|
|
1268831
|
+
});
|
|
1268832
|
+
}
|
|
1268833
|
+
},
|
|
1268834
|
+
object: (objectValue) => {
|
|
1268835
|
+
Object.entries((objectValue == null ? void 0 : objectValue.properties) ?? {}).forEach(([key, value]) => {
|
|
1268836
|
+
if (isGeneric(typeof value === "string" ? value : value.type)) {
|
|
1268837
|
+
if (nodePath) {
|
|
1268838
|
+
(propertyBasedErrors.object ?? (propertyBasedErrors.object = [])).push({
|
|
1268839
|
+
key,
|
|
1268840
|
+
nodePath
|
|
1268841
|
+
});
|
|
1268842
|
+
} else {
|
|
1268843
|
+
errors2.push({
|
|
1268844
|
+
severity: "error",
|
|
1268845
|
+
message: `Cannot reference generic ${value} from object property ${key}`
|
|
1268846
|
+
});
|
|
1268847
|
+
}
|
|
1268848
|
+
}
|
|
1268849
|
+
});
|
|
1268850
|
+
},
|
|
1268851
|
+
discriminatedUnion: (discriminatedUnionValue) => {
|
|
1268852
|
+
Object.entries(discriminatedUnionValue.union).forEach(([key, value]) => {
|
|
1268853
|
+
const discriminatedUnionValue2 = typeof value === "string" ? value : typeof value.type === "string" ? value.type : void 0;
|
|
1268854
|
+
if (discriminatedUnionValue2 && isGeneric(discriminatedUnionValue2)) {
|
|
1268855
|
+
if (nodePath) {
|
|
1268856
|
+
(propertyBasedErrors.discriminatedUnion ?? (propertyBasedErrors.discriminatedUnion = [])).push({
|
|
1268857
|
+
key,
|
|
1268858
|
+
nodePath
|
|
1268859
|
+
});
|
|
1268860
|
+
} else {
|
|
1268861
|
+
errors2.push({
|
|
1268862
|
+
severity: "error",
|
|
1268863
|
+
message: `Cannot reference generic ${value} from union property ${key}`
|
|
1268864
|
+
});
|
|
1268865
|
+
}
|
|
1268866
|
+
}
|
|
1268867
|
+
});
|
|
1268868
|
+
},
|
|
1268869
|
+
undiscriminatedUnion: (undiscriminatedUnionValue) => {
|
|
1268870
|
+
undiscriminatedUnionValue.union.forEach((value) => {
|
|
1268871
|
+
const discriminatedUnionValue = typeof value === "string" ? value : value.type;
|
|
1268872
|
+
if (isGeneric(discriminatedUnionValue)) {
|
|
1268873
|
+
errors2.push({
|
|
1268874
|
+
severity: "error",
|
|
1268875
|
+
message: `Cannot reference generic ${discriminatedUnionValue} from union`
|
|
1268876
|
+
});
|
|
1268877
|
+
}
|
|
1268878
|
+
});
|
|
1268879
|
+
}
|
|
1268880
|
+
});
|
|
1268881
|
+
return errors2;
|
|
1268882
|
+
},
|
|
1268883
|
+
typeReference: ({ typeReference, nodePath }) => {
|
|
1268884
|
+
const errors2 = [];
|
|
1268885
|
+
if (nodePath) {
|
|
1268886
|
+
for (const propertyBasedTypeDeclaration of Object.keys(propertyBasedErrors)) {
|
|
1268887
|
+
for (const { key, nodePath: propertyNodePath } of propertyBasedErrors[propertyBasedTypeDeclaration]) {
|
|
1268888
|
+
if (propertyNodePath.length > 0 && nodePath.join(",").startsWith(propertyNodePath.join(",")) && nodePath.includes(key)) {
|
|
1268889
|
+
errors2.push({
|
|
1268890
|
+
severity: "error",
|
|
1268891
|
+
message: `Cannot reference generic ${typeReference} from ${propertyBasedTypeDeclaration.toLowerCase().includes("union") ? "union" : propertyBasedTypeDeclaration}`
|
|
1268892
|
+
});
|
|
1268893
|
+
}
|
|
1268894
|
+
}
|
|
1268895
|
+
}
|
|
1268896
|
+
}
|
|
1268897
|
+
return errors2;
|
|
1268898
|
+
}
|
|
1268899
|
+
}
|
|
1268900
|
+
};
|
|
1268901
|
+
}
|
|
1268902
|
+
};
|
|
1268903
|
+
async function getGenericArgumentCounts(workspace) {
|
|
1268904
|
+
const genericArgumentCounts = {};
|
|
1268905
|
+
await visitAllDefinitionFiles(workspace, async (relativeFilepath, file) => {
|
|
1268906
|
+
await visitDefinitionFileYamlAst(file, {
|
|
1268907
|
+
typeDeclaration: ({ typeName, declaration }) => {
|
|
1268908
|
+
if (!typeName.isInlined) {
|
|
1268909
|
+
const maybeGeneric = parseGeneric(typeName.name);
|
|
1268910
|
+
if (maybeGeneric != null) {
|
|
1268911
|
+
visitRawTypeDeclaration(declaration, {
|
|
1268912
|
+
alias: () => {
|
|
1268913
|
+
},
|
|
1268914
|
+
enum: () => {
|
|
1268915
|
+
},
|
|
1268916
|
+
object: () => {
|
|
1268917
|
+
if (maybeGeneric.name && maybeGeneric.arguments) {
|
|
1268918
|
+
genericArgumentCounts[maybeGeneric.name] = maybeGeneric.arguments.length;
|
|
1268919
|
+
}
|
|
1268920
|
+
},
|
|
1268921
|
+
discriminatedUnion: () => {
|
|
1268922
|
+
},
|
|
1268923
|
+
undiscriminatedUnion: () => {
|
|
1268924
|
+
}
|
|
1268925
|
+
});
|
|
1268926
|
+
}
|
|
1268927
|
+
}
|
|
1268928
|
+
}
|
|
1268929
|
+
});
|
|
1268930
|
+
});
|
|
1268931
|
+
return genericArgumentCounts;
|
|
1268932
|
+
}
|
|
1268933
|
+
|
|
1268579
1268934
|
// ../fern-definition/validator/lib/rules/valid-navigation/valid-navigation.js
|
|
1268580
1268935
|
var import_path32 = __toESM(require("path"), 1);
|
|
1268581
1268936
|
var ValidNavigationRule = {
|
|
@@ -1270313,7 +1270668,9 @@ function getAllRules() {
|
|
|
1270313
1270668
|
ValidExampleErrorRule,
|
|
1270314
1270669
|
ValidTypeReferenceWithDefaultAndValidationRule,
|
|
1270315
1270670
|
ValidStreamConditionRule,
|
|
1270316
|
-
ValidVersionRule
|
|
1270671
|
+
ValidVersionRule,
|
|
1270672
|
+
NoUnusedGenericRule,
|
|
1270673
|
+
ValidGenericRule
|
|
1270317
1270674
|
];
|
|
1270318
1270675
|
}
|
|
1270319
1270676
|
function getAllEnabledRules() {
|