@xlr-lib/xlr-sdk 0.1.1-next.3 → 0.1.1-next.5

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.
@@ -41,10 +41,8 @@ module.exports = __toCommonJS(src_exports);
41
41
  // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/sdk.ts
42
42
  var import_xlr_utils3 = require("@xlr-lib/xlr-utils");
43
43
  var import_xlr_utils4 = require("@xlr-lib/xlr-utils");
44
- var import_xlr_converters = require("@xlr-lib/xlr-converters");
45
44
  var import_fs = __toESM(require("fs"));
46
45
  var import_path = __toESM(require("path"));
47
- var import_typescript = __toESM(require("typescript"));
48
46
 
49
47
  // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts
50
48
  var BasicXLRRegistry = class {
@@ -645,13 +643,11 @@ function simpleTransformGenerator(typeToTransform, capabilityToTransform, functi
645
643
  var XLRSDK = class {
646
644
  registry;
647
645
  validator;
648
- tsWriter;
649
646
  computedNodeCache;
650
647
  externalTransformFunctions;
651
648
  constructor(customRegistry) {
652
649
  this.registry = customRegistry ?? new BasicXLRRegistry();
653
650
  this.validator = new XLRValidator(this.getType.bind(this));
654
- this.tsWriter = new import_xlr_converters.TSWriter();
655
651
  this.computedNodeCache = /* @__PURE__ */ new Map();
656
652
  this.externalTransformFunctions = /* @__PURE__ */ new Map();
657
653
  }
@@ -816,32 +812,6 @@ var XLRSDK = class {
816
812
  validateByType(type, rootNode) {
817
813
  return this.validator.validateType(rootNode, type);
818
814
  }
819
- /**
820
- * Exports the types loaded into the registry to the specified format
821
- *
822
- * @param exportType - what format to export as
823
- * @param importMap - a map of primitive packages to types exported from that package to add import statements
824
- * @param filters - filter out plugins/capabilities/types you don't want to export
825
- * @param transforms - transforms to apply to types before exporting them
826
- * @returns [filename, content][] - Tuples of filenames and content to write
827
- */
828
- exportRegistry(exportType, importMap, filters, transforms) {
829
- const typesToExport = this.registry.list(filters).map((type) => {
830
- const effectiveType = transforms?.reduce(
831
- (typeAccumulator, transformFn) => transformFn(
832
- typeAccumulator,
833
- this.registry.info(type.name)?.capability
834
- ),
835
- type
836
- ) ?? type;
837
- return effectiveType;
838
- });
839
- if (exportType === "TypeScript") {
840
- const outputString = this.exportToTypeScript(typesToExport, importMap);
841
- return [["out.d.ts", outputString]];
842
- }
843
- throw new Error(`Unknown export format ${exportType}`);
844
- }
845
815
  /**
846
816
  * Transforms a generated XLR node into its final representation by resolving all `extends` properties.
847
817
  * If `optimize` is set to true the following operations are also performed:
@@ -923,63 +893,6 @@ var XLRSDK = class {
923
893
  }
924
894
  return xlrTransformWalker(transformMap)(resolvedObject);
925
895
  }
926
- exportToTypeScript(typesToExport, importMap) {
927
- const referencedImports = /* @__PURE__ */ new Set();
928
- const exportedTypes = /* @__PURE__ */ new Map();
929
- const printer = import_typescript.default.createPrinter({ newLine: import_typescript.default.NewLineKind.LineFeed });
930
- let resultFile = import_typescript.default.createSourceFile(
931
- "output.d.ts",
932
- "",
933
- import_typescript.default.ScriptTarget.ES2017,
934
- false,
935
- // setParentNodes
936
- import_typescript.default.ScriptKind.TS
937
- );
938
- typesToExport.forEach((typeNode) => {
939
- const { type, referencedTypes, additionalTypes } = this.tsWriter.convertNamedType(typeNode);
940
- exportedTypes.set(typeNode.name, type);
941
- additionalTypes?.forEach(
942
- (additionalType, name) => exportedTypes.set(name, additionalType)
943
- );
944
- referencedTypes?.forEach(
945
- (referencedType) => referencedImports.add(referencedType)
946
- );
947
- });
948
- const typesToPrint = [];
949
- exportedTypes.forEach(
950
- (type) => typesToPrint.push(
951
- printer.printNode(import_typescript.default.EmitHint.Unspecified, type, resultFile)
952
- )
953
- );
954
- importMap.forEach((imports, packageName) => {
955
- const applicableImports = imports.filter((i) => referencedImports.has(i));
956
- resultFile = import_typescript.default.factory.updateSourceFile(resultFile, [
957
- import_typescript.default.factory.createImportDeclaration(
958
- /* modifiers */
959
- void 0,
960
- import_typescript.default.factory.createImportClause(
961
- false,
962
- void 0,
963
- import_typescript.default.factory.createNamedImports(
964
- applicableImports.map(
965
- (i) => import_typescript.default.factory.createImportSpecifier(
966
- false,
967
- void 0,
968
- import_typescript.default.factory.createIdentifier(i)
969
- )
970
- )
971
- )
972
- ),
973
- import_typescript.default.factory.createStringLiteral(packageName)
974
- ),
975
- ...resultFile.statements
976
- ]);
977
- });
978
- const headerText = printer.printFile(resultFile);
979
- const nodeText = typesToPrint.join("\n");
980
- return `${headerText}
981
- ${nodeText}`;
982
- }
983
896
  };
984
897
  // Annotate the CommonJS export names for ESM import in node:
985
898
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/sdk.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/validator.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/types.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/utils.ts"],"sourcesContent":["export * from \"./sdk\";\nexport * from \"./types\";\nexport * from \"./registry\";\nexport * from \"./utils\";\n","/* eslint-disable prettier/prettier */\nimport type {\n Manifest,\n NamedType,\n NodeType,\n ObjectNode,\n ObjectType,\n TransformFunction,\n TSManifest,\n} from \"@xlr-lib/xlr\";\nimport type { TopLevelDeclaration } from \"@xlr-lib/xlr-utils\";\nimport {\n computeEffectiveObject,\n resolveConditional,\n resolveReferenceNode,\n} from \"@xlr-lib/xlr-utils\";\nimport { fillInGenerics } from \"@xlr-lib/xlr-utils\";\nimport type { Node } from \"jsonc-parser\";\nimport { TSWriter } from \"@xlr-lib/xlr-converters\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport ts from \"typescript\";\n\nimport type { XLRRegistry, Filters } from \"./registry\";\nimport { BasicXLRRegistry } from \"./registry\";\nimport type { ExportTypes } from \"./types\";\nimport { XLRValidator } from \"./validator\";\nimport { TransformFunctionMap, xlrTransformWalker } from \"./utils\";\n\nexport interface GetTypeOptions {\n /** Resolves `extends` fields in objects */\n getRawType?: boolean;\n /** Perform optimizations to resolve all references, type intersections, and conditionals */\n optimize?: boolean;\n}\n\n/**\n * Abstraction for interfacing with XLRs making it more approachable to use without understanding the inner workings of the types and how they are packaged\n */\nexport class XLRSDK {\n private registry: XLRRegistry;\n private validator: XLRValidator;\n private tsWriter: TSWriter;\n private computedNodeCache: Map<string, NodeType>;\n private externalTransformFunctions: Map<string, TransformFunction>;\n\n constructor(customRegistry?: XLRRegistry) {\n this.registry = customRegistry ?? new BasicXLRRegistry();\n this.validator = new XLRValidator(this.getType.bind(this));\n this.tsWriter = new TSWriter();\n this.computedNodeCache = new Map();\n this.externalTransformFunctions = new Map();\n }\n\n /**\n * Loads definitions from a path on the filesystem\n *\n * @param inputPath - path to the directory to load (above the xlr folder)\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public loadDefinitionsFromDisk(\n inputPath: string,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n const manifest = JSON.parse(\n fs.readFileSync(path.join(inputPath, \"xlr\", \"manifest.json\")).toString(),\n (key: unknown, value: unknown) => {\n // Custom parser because JSON objects -> JS Objects, not maps\n if (typeof value === \"object\" && value !== null) {\n if (key === \"capabilities\") {\n return new Map(Object.entries(value));\n }\n }\n\n return value;\n }\n ) as Manifest;\n\n manifest.capabilities?.forEach((capabilityList, capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n capabilityList.forEach((extensionName) => {\n if (!filters?.typeFilter || !extensionName.match(filters?.typeFilter)) {\n const cType: NamedType<NodeType> = JSON.parse(\n fs\n .readFileSync(\n path.join(inputPath, \"xlr\", `${extensionName}.json`)\n )\n .toString()\n );\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n cType\n ) ?? cType;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Load definitions from a js/ts file in memory\n *\n * @param manifest - The imported XLR manifest module\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public async loadDefinitionsFromModule(\n manifest: TSManifest,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n Object.keys(manifest.capabilities)?.forEach((capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n const capabilityList = manifest.capabilities[capabilityName];\n capabilityList.forEach((extension) => {\n if (\n !filters?.typeFilter ||\n !extension.name.match(filters?.typeFilter)\n ) {\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n extension\n ) ?? extension;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Statically load transform function that should be applied to every XLR bundle that is imported\n */\n public addTransformFunction(name: string, fn: TransformFunction): void {\n this.externalTransformFunctions.set(name, fn);\n }\n\n /**\n * Remove any transform function loaded via the `addTransformFunction` method by name\n */\n public removeTransformFunction(name: string): void {\n this.externalTransformFunctions.delete(name);\n }\n\n /**\n * Returns a Type that has been previously loaded\n *\n * @param id - Type to retrieve\n * @param options - `GetTypeOptions`\n * @returns `NamedType<NodeType>` | `undefined`\n */\n public getType(\n id: string,\n options?: GetTypeOptions\n ): NamedType<NodeType> | undefined {\n let type = this.registry.get(id);\n if (options?.getRawType === true || !type) {\n return type;\n }\n\n if (this.computedNodeCache.has(id)) {\n return JSON.parse(JSON.stringify(this.computedNodeCache.get(id))) as\n | NamedType<NodeType>\n | undefined;\n }\n\n type = this.resolveType(type, options?.optimize)\n\n this.computedNodeCache.set(id, type);\n\n return type;\n }\n\n /**\n * Returns if a Type with `id` has been loaded into the DSK\n *\n * @param id - Type to retrieve\n * @returns `boolean`\n */\n public hasType(id: string) {\n return this.registry.has(id);\n }\n\n /**\n * Lists types that have been loaded into the SDK\n *\n * @param filters - Any filters to apply to the types returned (a positive match will omit)\n * @returns `Array<NamedTypes>`\n */\n public listTypes(filters?: Filters) {\n return this.registry.list(filters);\n }\n\n /**\n * Returns meta information around a registered type\n *\n * @param id - Name of Type to retrieve\n * @returns `TypeMetaData` | `undefined`\n */\n public getTypeInfo(id: string) {\n return this.registry.info(id);\n }\n\n /**\n * Validates if a JSONC Node follows the XLR Type registered under the `typeName` specified\n *\n * @param typeName - Registered XLR Type to use for validation\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByName(typeName: string, rootNode: Node) {\n const xlr = this.getType(typeName);\n if (!xlr) {\n throw new Error(\n `Type ${typeName} does not exist in registry, can't validate`\n );\n }\n\n return this.validator.validateType(rootNode, xlr);\n }\n\n /**\n * Validates if a JSONC Node follows the supplied XLR Type\n *\n * @param type - Type to validate against\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByType(type: NodeType, rootNode: Node) {\n return this.validator.validateType(rootNode, type);\n }\n\n /**\n * Exports the types loaded into the registry to the specified format\n *\n * @param exportType - what format to export as\n * @param importMap - a map of primitive packages to types exported from that package to add import statements\n * @param filters - filter out plugins/capabilities/types you don't want to export\n * @param transforms - transforms to apply to types before exporting them\n * @returns [filename, content][] - Tuples of filenames and content to write\n */\n public exportRegistry(\n exportType: ExportTypes,\n importMap: Map<string, string[]>,\n filters?: Filters,\n transforms?: Array<TransformFunction>\n ): [string, string][] {\n const typesToExport = this.registry.list(filters).map((type) => {\n const effectiveType =\n transforms?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n this.registry.info(type.name)?.capability as string\n ) as NamedType<NodeType>,\n type\n ) ?? type;\n\n return effectiveType;\n });\n\n if (exportType === \"TypeScript\") {\n const outputString = this.exportToTypeScript(typesToExport, importMap);\n return [[\"out.d.ts\", outputString]];\n }\n\n throw new Error(`Unknown export format ${exportType}`);\n }\n\n /**\n * Transforms a generated XLR node into its final representation by resolving all `extends` properties.\n * If `optimize` is set to true the following operations are also performed:\n * - Solving any conditional types\n * - Computing the effective types of any union elements\n * - Resolving any ref nodes\n * - filing in any remaining generics with their default value\n */\n private resolveType(type: NamedType, optimize = true): NamedType {\n const resolvedObject = fillInGenerics(type, new Map(), true);\n\n let transformMap: TransformFunctionMap = {\n object: [(objectNode: ObjectType) => {\n if (objectNode.extends) {\n const refName = objectNode.extends.ref.split(\"<\")[0];\n let extendedType = this.getType(refName, {getRawType: true});\n if (!extendedType) {\n throw new Error(\n `Error resolving ${objectNode.name}: can't find extended type ${refName}`\n );\n }\n\n extendedType = resolveReferenceNode(\n objectNode.extends,\n extendedType as NamedType<ObjectType>\n ) as NamedType;\n if (extendedType.type === \"object\") {\n return {\n ...computeEffectiveObject(\n extendedType as ObjectType,\n objectNode as ObjectType,\n false\n ),\n name: objectNode.name,\n description: objectNode.description,\n };\n }\n\n if( extendedType.type === \"or\"){\n return {\n ...this.validator.computeIntersectionType([\n objectNode,\n extendedType\n ]\n ),\n name: objectNode.name,\n description: objectNode.description,\n } as any;\n }\n\n // if the merge isn't straightforward, defer until validation time for now\n return {\n name: objectNode.name,\n type: \"and\",\n and: [\n {\n ...objectNode,\n extends: undefined,\n },\n extendedType,\n ],\n } as unknown as ObjectNode;\n }\n\n return objectNode;\n }],\n } \n\n if(optimize){\n transformMap = {\n ...transformMap,\n conditional: [(node) => {\n return resolveConditional(node) as any\n }],\n and: [(node) => {\n return {\n ...this.validator.computeIntersectionType(node.and),\n ...(node.name ? { name: node.name } : {}),\n } as any\n }],\n ref: [(refNode) => {\n return this.validator.getRefType(refNode) as any\n }]\n }\n }\n\n return xlrTransformWalker(transformMap)(resolvedObject) as NamedType\n }\n\n private exportToTypeScript(\n typesToExport: NamedType[],\n importMap: Map<string, string[]>\n ): string {\n const referencedImports: Set<string> = new Set();\n const exportedTypes: Map<string, TopLevelDeclaration> = new Map();\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n let resultFile = ts.createSourceFile(\n \"output.d.ts\",\n \"\",\n ts.ScriptTarget.ES2017,\n false, // setParentNodes\n ts.ScriptKind.TS\n );\n\n typesToExport.forEach((typeNode) => {\n const { type, referencedTypes, additionalTypes } =\n this.tsWriter.convertNamedType(typeNode);\n exportedTypes.set(typeNode.name, type);\n additionalTypes?.forEach((additionalType, name) =>\n exportedTypes.set(name, additionalType)\n );\n referencedTypes?.forEach((referencedType) =>\n referencedImports.add(referencedType)\n );\n });\n\n const typesToPrint: Array<string> = [];\n\n exportedTypes.forEach((type) =>\n typesToPrint.push(\n printer.printNode(ts.EmitHint.Unspecified, type, resultFile)\n )\n );\n\n importMap.forEach((imports, packageName) => {\n const applicableImports = imports.filter((i) => referencedImports.has(i));\n resultFile = ts.factory.updateSourceFile(resultFile, [\n ts.factory.createImportDeclaration(\n /* modifiers */ undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports(\n applicableImports.map((i) =>\n ts.factory.createImportSpecifier(\n false,\n undefined,\n ts.factory.createIdentifier(i)\n )\n )\n )\n ),\n ts.factory.createStringLiteral(packageName)\n ),\n ...resultFile.statements,\n ]);\n });\n\n const headerText = printer.printFile(resultFile);\n const nodeText = typesToPrint.join(\"\\n\");\n return `${headerText}\\n${nodeText}`;\n }\n}\n","import type { NamedType, NodeType } from \"@xlr-lib/xlr\";\nimport type { XLRRegistry, Filters, TypeMetadata } from \"./types\";\n\n/**\n * Basic example of a XLRs Registry\n */\nexport class BasicXLRRegistry implements XLRRegistry {\n private typeMap: Map<string, NamedType<NodeType>>;\n private pluginMap: Map<string, Map<string, Array<string>>>;\n private infoMap: Map<string, TypeMetadata>;\n\n constructor() {\n this.typeMap = new Map();\n this.pluginMap = new Map();\n this.infoMap = new Map();\n }\n\n /** Returns a copy of the XLR to guard against unexpected type modification */\n get(id: string): NamedType<NodeType> | undefined {\n const value = this.typeMap.get(id);\n return value ? JSON.parse(JSON.stringify(value)) : undefined;\n }\n\n add(type: NamedType<NodeType>, plugin: string, capability: string): void {\n this.typeMap.set(type.name, type);\n this.infoMap.set(type.name, { plugin, capability });\n\n if (!this.pluginMap.has(plugin)) {\n this.pluginMap.set(plugin, new Map());\n }\n\n const pluginsCapabilities = this.pluginMap.get(plugin) as Map<\n string,\n Array<string>\n >;\n\n if (!pluginsCapabilities.has(capability)) {\n pluginsCapabilities.set(capability, []);\n }\n\n const providedCapabilities = pluginsCapabilities.get(\n capability,\n ) as string[];\n providedCapabilities.push(type.name);\n }\n\n has(id: string): boolean {\n return this.typeMap.has(id);\n }\n\n list(filterArgs?: Filters): NamedType<NodeType>[] {\n const validTypes: Array<string> = [];\n\n this.pluginMap.forEach((manifest, pluginName) => {\n if (\n !filterArgs?.pluginFilter ||\n !pluginName.match(filterArgs.pluginFilter)\n ) {\n manifest.forEach((types, capabilityName) => {\n if (\n !filterArgs?.capabilityFilter ||\n !capabilityName.match(filterArgs.capabilityFilter)\n ) {\n types.forEach((type) => {\n if (\n !filterArgs?.typeFilter ||\n !type.match(filterArgs.typeFilter)\n ) {\n validTypes.push(type);\n }\n });\n }\n });\n }\n });\n return validTypes.map((type) => this.get(type) as NamedType);\n }\n\n info(id: string): TypeMetadata | undefined {\n return this.infoMap.get(id);\n }\n}\n","import type { Node } from \"jsonc-parser\";\nimport type {\n ArrayType,\n NamedType,\n NodeType,\n ObjectType,\n OrType,\n PrimitiveTypes,\n RefType,\n TemplateLiteralType,\n} from \"@xlr-lib/xlr\";\nimport {\n makePropertyMap,\n resolveConditional,\n isPrimitiveTypeNode,\n resolveReferenceNode,\n computeEffectiveObject,\n} from \"@xlr-lib/xlr-utils\";\nimport { ValidationSeverity } from \"./types\";\nimport type { ValidationMessage } from \"./types\";\n\nexport interface XLRValidatorConfig {\n /** URL mapping for supplemental documentation */\n urlMapping?: Record<string, string>;\n}\n\nconst MAX_VALID_SHOWN = 20;\n\n/**\n * Validator for XLRs on JSON Nodes\n */\nexport class XLRValidator {\n private config: XLRValidatorConfig;\n private resolveType: (id: string) => NamedType<NodeType> | undefined;\n private regexCache: Map<string, RegExp>;\n\n constructor(\n resolveType: (id: string) => NamedType<NodeType> | undefined,\n config?: XLRValidatorConfig,\n ) {\n this.config = config || {};\n this.resolveType = resolveType;\n this.regexCache = new Map();\n }\n\n /** Main entrypoint for validation */\n public validateType(\n rootNode: Node,\n xlrNode: NodeType,\n ): Array<ValidationMessage> {\n const validationIssues = new Array<ValidationMessage>();\n if (xlrNode.type === \"object\") {\n if (rootNode.type === \"object\") {\n validationIssues.push(...this.validateObject(xlrNode, rootNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an object but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"array\") {\n if (rootNode.type === \"array\") {\n validationIssues.push(...this.validateArray(rootNode, xlrNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an array but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"template\") {\n const error = this.validateTemplate(rootNode, xlrNode);\n if (error) {\n validationIssues.push(error);\n }\n } else if (xlrNode.type === \"or\") {\n const potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }> = [];\n\n for (const potentialType of xlrNode.or) {\n const potentialErrors = this.validateType(rootNode, potentialType);\n\n if (potentialErrors.length === 0) {\n return validationIssues;\n }\n\n potentialTypeErrors.push({\n type: potentialType,\n errors: potentialErrors,\n });\n }\n\n let message: string;\n const expectedTypes = xlrNode.or\n .map((node) =>\n isPrimitiveTypeNode(node)\n ? node.type\n : (node.name ?? node.title ?? node.type ?? \"<unnamed type>\"),\n )\n .join(\" | \");\n\n if (xlrNode.name) {\n message = `Does not match any of the expected types for type: '${xlrNode.name}'`;\n } else if (xlrNode.title) {\n message = `Does not match any of the expected types for property: '${xlrNode.title}'`;\n } else {\n message = `Does not match any of the types: ${expectedTypes}`;\n }\n\n const { infoMessage } = this.generateNestedTypesInfo(\n potentialTypeErrors,\n xlrNode,\n rootNode,\n );\n\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: message.trim(),\n severity: ValidationSeverity.Error,\n });\n\n if (infoMessage) {\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: infoMessage,\n severity: ValidationSeverity.Info,\n });\n }\n } else if (xlrNode.type === \"and\") {\n const effectiveType = {\n ...this.computeIntersectionType(xlrNode.and),\n ...(xlrNode.name ? { name: xlrNode.name } : {}),\n };\n validationIssues.push(...this.validateType(rootNode, effectiveType));\n } else if (xlrNode.type === \"record\") {\n rootNode.children?.forEach((child) => {\n validationIssues.push(\n ...this.validateType(child.children?.[0] as Node, xlrNode.keyType),\n );\n validationIssues.push(\n ...this.validateType(child.children?.[1] as Node, xlrNode.valueType),\n );\n });\n } else if (xlrNode.type === \"ref\") {\n const refType = this.getRefType(xlrNode);\n if (refType === undefined) {\n validationIssues.push({\n type: \"unknown\",\n node: rootNode,\n message: `Type \"${xlrNode.ref}\" is not defined in provided bundles`,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push(\n ...this.validateType(rootNode, refType as NamedType),\n );\n }\n } else if (isPrimitiveTypeNode(xlrNode)) {\n if (!this.validateLiteralType(xlrNode, rootNode)) {\n if (\n (xlrNode.type === \"string\" ||\n xlrNode.type === \"number\" ||\n xlrNode.type === \"boolean\") &&\n xlrNode.const\n ) {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected \"${xlrNode.const}\" but got \"${rootNode.value}\"`,\n expected: xlrNode.const,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${rootNode.type}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n });\n }\n }\n } else if (xlrNode.type === \"conditional\") {\n // Resolve RefNodes in check conditions if needed\n let { right, left } = xlrNode.check;\n\n if (right.type === \"ref\") {\n right = this.getRefType(right);\n }\n\n if (left.type === \"ref\") {\n left = this.getRefType(left);\n }\n\n const resolvedXLRNode = {\n ...xlrNode,\n check: {\n left,\n right,\n },\n };\n\n const resolvedConditional = resolveConditional(resolvedXLRNode);\n if (resolvedConditional === resolvedXLRNode) {\n throw Error(\n `Unable to resolve conditional type at runtime: ${xlrNode.name}`,\n );\n }\n\n validationIssues.push(\n ...this.validateType(rootNode, resolvedConditional),\n );\n } else {\n throw Error(`Unknown type ${xlrNode.type}`);\n }\n\n return validationIssues;\n }\n\n private generateNestedTypesInfo(\n potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }>,\n xlrNode: OrType,\n rootNode: Node,\n ): { nestedTypesList: string; infoMessage?: string } {\n const nestedTypes = new Set<string>();\n\n // TODO: Create a recursive function that returns value or xlrNode info\n // First, try to extract types from potential type errors\n potentialTypeErrors.forEach((typeError) => {\n if (typeError.type.type !== \"template\") {\n typeError.errors.forEach((error) => {\n if (error.type === \"type\" && error.expected) {\n // Split by separate types if union\n String(error.expected)\n .split(\" | \")\n .forEach((val) => nestedTypes.add(val.trim()));\n }\n });\n }\n });\n\n // If no types found from errors, try using type from xlrNode\n if (nestedTypes.size === 0) {\n xlrNode.or.forEach((type) => {\n const typeName =\n type.name ?? type.title ?? type.type ?? \"<unnamed type>\";\n nestedTypes.add(typeName);\n });\n }\n\n const nestedTypesArray = [...nestedTypes];\n\n // Display list of expected types as a union\n let nestedTypesList =\n nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(\" | \") +\n (nestedTypesArray.length > MAX_VALID_SHOWN\n ? ` | +${\n nestedTypesArray.length - MAX_VALID_SHOWN\n } ... ${nestedTypesArray.pop()}`\n : \"\");\n\n // TODO: Be able to pass the validator's config to the SDK\n const docsURL = this.config.urlMapping;\n\n // Support passing in a URL for matching type\n if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {\n nestedTypesList = docsURL[xlrNode.name];\n }\n\n // Support supplemental info message\n let infoMessage;\n\n if (rootNode.value !== undefined) {\n infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;\n } else if (nestedTypesList) {\n infoMessage = `Expected: ${nestedTypesList}`;\n }\n\n return { nestedTypesList, infoMessage };\n }\n\n private validateTemplate(\n node: Node,\n xlrNode: TemplateLiteralType,\n ): ValidationMessage | undefined {\n if (node.type !== \"string\") {\n return {\n type: \"type\",\n node: node.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${typeof node}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n };\n }\n\n const regex = this.getRegex(xlrNode.format);\n const valid = regex.exec(node.value);\n if (!valid) {\n return {\n type: \"value\",\n node: node.parent as Node,\n message: `Does not match expected format: ${xlrNode.format}`,\n expected: xlrNode.format,\n severity: ValidationSeverity.Error,\n };\n }\n }\n\n private validateArray(rootNode: Node, xlrNode: ArrayType) {\n const issues: Array<ValidationMessage> = [];\n rootNode.children?.forEach((child) =>\n issues.push(...this.validateType(child, xlrNode.elementType)),\n );\n return issues;\n }\n\n private validateObject(xlrNode: ObjectType, node: Node) {\n const issues: Array<ValidationMessage> = [];\n const objectProps = makePropertyMap(node);\n\n for (const prop in xlrNode.properties) {\n const expectedType = xlrNode.properties[prop];\n const valueNode = objectProps.get(prop);\n if (expectedType.required && valueNode === undefined) {\n issues.push({\n type: \"missing\",\n node,\n message: `Property \"${prop}\" missing from type \"${xlrNode.name}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n\n if (valueNode) {\n issues.push(\n ...this.validateType(valueNode, expectedType.node as NamedType),\n );\n }\n }\n\n // Check if unknown keys are allowed and if they are - do the violate the constraint\n const extraKeys = Array.from(objectProps.keys()).filter(\n (key) => xlrNode.properties[key] === undefined,\n );\n if (xlrNode.additionalProperties === false && extraKeys.length > 0) {\n issues.push({\n type: \"value\",\n node,\n message: `Unexpected properties on \"${xlrNode.name}\": ${extraKeys.join(\n \", \",\n )}`,\n severity: ValidationSeverity.Error,\n });\n } else {\n issues.push(\n ...extraKeys.flatMap((key) =>\n this.validateType(\n objectProps.get(key) as Node,\n xlrNode.additionalProperties as NodeType,\n ),\n ),\n );\n }\n\n return issues;\n }\n\n private validateLiteralType(expectedType: PrimitiveTypes, literalType: Node) {\n switch (expectedType.type) {\n case \"boolean\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"boolean\";\n case \"number\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"number\";\n case \"string\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"string\";\n case \"null\":\n return literalType.value === null;\n case \"never\":\n return literalType === undefined;\n case \"any\":\n return literalType !== undefined;\n case \"unknown\":\n return literalType !== undefined;\n case \"undefined\":\n return true;\n default:\n return false;\n }\n }\n\n public getRefType(ref: RefType): NodeType {\n let refName = ref.ref;\n if (refName.indexOf(\"<\") > 0) {\n [refName] = refName.split(\"<\");\n }\n\n const actualType = this.resolveType(refName);\n if (!actualType) {\n throw new Error(`Error: can't resolve type reference ${refName}`);\n }\n\n return resolveReferenceNode(ref, actualType);\n }\n\n private getRegex(expString: string): RegExp {\n if (this.regexCache.has(expString)) {\n return this.regexCache.get(expString) as RegExp;\n }\n\n const exp = new RegExp(expString);\n this.regexCache.set(expString, exp);\n return exp;\n }\n\n public computeIntersectionType(types: Array<NodeType>): ObjectType | OrType {\n let firstElement = types[0];\n let effectiveType: ObjectType | OrType;\n\n // Capture the original top-level type name if exists\n const topLevelTypeName = types[0].name;\n\n if (firstElement.type === \"ref\") {\n firstElement = this.getRefType(firstElement);\n }\n\n if (firstElement.type === \"and\") {\n effectiveType = this.computeIntersectionType(firstElement.and);\n } else if (firstElement.type === \"record\") {\n effectiveType = {\n type: \"object\",\n properties: {},\n additionalProperties: firstElement.valueType,\n };\n } else if (firstElement.type !== \"or\" && firstElement.type !== \"object\") {\n throw new Error(\n `Can't compute a union with a non-object type ${firstElement.type} (${firstElement.name})`,\n );\n } else {\n effectiveType = firstElement;\n }\n\n types.slice(1).forEach((type) => {\n let typeToApply = type;\n\n if (typeToApply.type === \"record\") {\n typeToApply = {\n type: \"object\",\n properties: {},\n additionalProperties: typeToApply.valueType,\n };\n }\n\n if (type.type === \"ref\") {\n typeToApply = this.getRefType(type);\n }\n\n if (typeToApply.type === \"and\") {\n typeToApply = this.computeIntersectionType([type, effectiveType]);\n }\n\n if (typeToApply.type === \"object\") {\n if (effectiveType.type === \"object\") {\n effectiveType = computeEffectiveObject(effectiveType, typeToApply);\n } else {\n effectiveType = {\n ...effectiveType,\n or: effectiveType.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n typeToApply,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n }\n } else if (typeToApply.type === \"or\") {\n if (effectiveType.type === \"object\") {\n effectiveType = {\n ...typeToApply,\n or: typeToApply.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n effectiveType,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n } else {\n throw new Error(\"unimplemented operation or x or projection\");\n }\n } else {\n throw new Error(\n `Can't compute a union with a non-object type ${typeToApply.type} (${typeToApply.name})`,\n );\n }\n });\n\n // If the final effective type is an or type and doesn't have a name, use the top-level type name\n if (\n effectiveType.type === \"or\" &&\n !effectiveType.name &&\n topLevelTypeName\n ) {\n effectiveType.name = topLevelTypeName;\n }\n\n return effectiveType;\n }\n}\n","import type { Node } from \"jsonc-parser\";\n\n/** Support Export Formats */\nexport type ExportTypes = \"TypeScript\";\n\nexport interface BaseValidationMessage<ErrorType extends string = string> {\n /** Validation Type */\n type: ErrorType;\n\n /** Error message text */\n message: string;\n\n /** JSONC node that the error originates from */\n node: Node;\n\n /** Level of the message */\n severity: ValidationSeverity;\n}\n\nexport interface TypeValidationError extends BaseValidationMessage<\"type\"> {\n /** Expected types */\n expected?: string[] | string | number | boolean;\n}\n\nexport type MissingValidationError = BaseValidationMessage<\"missing\">;\n\nexport type UnknownValidationError = BaseValidationMessage<\"unknown\">;\n\nexport interface ValueValidationError extends BaseValidationMessage<\"value\"> {\n /** Expected value */\n expected?: string;\n}\n\nexport type UnexpectedValidationError = BaseValidationMessage<\"unexpected\">;\n\nexport type ValidationMessage =\n | TypeValidationError\n | MissingValidationError\n | UnknownValidationError\n | ValueValidationError\n | UnexpectedValidationError;\n\nexport enum ValidationSeverity {\n Error = 1,\n Warning = 2,\n Info = 3,\n Trace = 4,\n}\n","import type {\n NamedType,\n NodeTypeStrings,\n NodeTypeMap,\n TransformFunction,\n NodeType,\n ObjectProperty,\n RefNode,\n} from \"@xlr-lib/xlr\";\nimport { isGenericNamedType } from \"@xlr-lib/xlr-utils\";\n\ntype TypedTransformFunction<T extends NodeTypeStrings = NodeTypeStrings> = (\n input: NodeTypeMap[T],\n) => NodeTypeMap[T];\n\nexport type TransformFunctionMap = {\n [nodeType in NodeTypeStrings]?: Array<TypedTransformFunction<nodeType>>;\n};\n\nconst isMatchingCapability = (\n capability: string,\n capabilitiesToMatch: string | Array<string>,\n): boolean => {\n if (Array.isArray(capabilitiesToMatch)) {\n return capabilitiesToMatch.includes(capability);\n }\n\n return capability === capabilitiesToMatch;\n};\n\nexport function xlrTransformWalker(\n transformMap: TransformFunctionMap,\n): (node: NodeType) => NodeType {\n const walker = (n: NamedType | NodeType): NodeType => {\n let node = { ...n };\n const transformFunctions = transformMap[node.type] as unknown as Array<\n TypedTransformFunction<typeof node.type>\n >;\n\n for (const transformFn of transformFunctions ?? []) {\n node = transformFn(node);\n }\n\n if (node.type === \"object\") {\n const newObjectProperties: Record<string, ObjectProperty> = {};\n\n for (const key in node.properties) {\n const value = node.properties[key];\n newObjectProperties[key] = {\n required: value.required,\n node: walker(value.node),\n };\n }\n\n // need to walk generic tokens\n return {\n ...node,\n properties: { ...newObjectProperties },\n ...(isGenericNamedType(node)\n ? {\n genericTokens: node.genericTokens.map((token) => {\n return {\n ...token,\n constraints: token.constraints\n ? walker(token.constraints)\n : undefined,\n default: token.default ? walker(token.default) : undefined,\n };\n }),\n }\n : {}),\n extends: node.extends ? (walker(node.extends) as RefNode) : undefined,\n additionalProperties: node.additionalProperties\n ? walker(node.additionalProperties)\n : false,\n };\n }\n\n if (node.type === \"array\") {\n return {\n ...node,\n elementType: walker(node.elementType),\n };\n }\n\n if (node.type === \"and\") {\n return {\n ...node,\n and: node.and.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"or\") {\n return {\n ...node,\n or: node.or.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"ref\") {\n return {\n ...node,\n ...(node.genericArguments\n ? {\n genericArguments: node.genericArguments?.map((arg) =>\n walker(arg),\n ),\n }\n : {}),\n };\n }\n\n if (node.type === \"tuple\") {\n return {\n ...node,\n elementTypes: node.elementTypes.map((element) => {\n return {\n name: element.name,\n type: walker(element.type),\n optional: element.optional,\n };\n }),\n additionalItems: node.additionalItems\n ? walker(node.additionalItems)\n : false,\n };\n }\n\n if (node.type === \"function\") {\n return {\n ...node,\n parameters: node.parameters.map((param) => {\n return {\n ...param,\n type: walker(param.type),\n default: param.default ? walker(param.default) : undefined,\n };\n }),\n returnType: node.returnType ? walker(node.returnType) : undefined,\n };\n }\n\n if (node.type === \"record\") {\n return {\n ...node,\n keyType: walker(node.keyType),\n valueType: walker(node.valueType),\n };\n }\n\n if (node.type === \"conditional\") {\n return {\n ...node,\n check: {\n left: walker(node.check.left),\n right: walker(node.check.left),\n },\n value: {\n true: walker(node.value.true),\n false: walker(node.value.false),\n },\n };\n }\n\n return node;\n };\n\n return walker;\n}\n\n/**\n * Helper function for simple transforms\n * Walks an XLR tree looking for the specified node type calls the supplied function when called\n */\nexport function simpleTransformGenerator<\n T extends NodeTypeStrings = NodeTypeStrings,\n>(\n typeToTransform: T,\n capabilityToTransform: string | Array<string>,\n functionToRun: TypedTransformFunction<T>,\n): TransformFunction {\n /** walker for an XLR tree to touch every node */\n return (n: NamedType | NodeType, capability: string) => {\n // Run transform on base node before running on children\n if (isMatchingCapability(capability, capabilityToTransform)) {\n return xlrTransformWalker({ [typeToTransform]: [functionToRun] })(n);\n }\n\n return n;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,IAAAA,oBAIO;AACP,IAAAA,oBAA+B;AAE/B,4BAAyB;AACzB,gBAAe;AACf,kBAAiB;AACjB,wBAAe;;;ACfR,IAAM,mBAAN,MAA8C;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,YAAY,oBAAI,IAAI;AACzB,SAAK,UAAU,oBAAI,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,IAAI,IAA6C;AAC/C,UAAM,QAAQ,KAAK,QAAQ,IAAI,EAAE;AACjC,WAAO,QAAQ,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,EACrD;AAAA,EAEA,IAAI,MAA2B,QAAgB,YAA0B;AACvE,SAAK,QA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,YACA,kBAAAA,QAAG,QAAQ;AAAA,cACT,kBAAkB;AAAA,gBAAI,CAAC,MACrB,kBAAAA,QAAG,QAAQ;AAAA,kBACT;AAAA,kBACA;AAAA,kBACA,kBAAAA,QAAG,QAAQ,iBAAiB,CAAC;AAAA,gBAC/B;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA,kBAAAA,QAAG,QAAQ,oBAAoB,WAAW;AAAA,QAC5C;AAAA,QACA,GAAG,WAAW;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAED,UAAM,aAAa,QAAQ,UAAU,UAAU;AAC/C,UAAM,WAAW,aAAa,KAAK,IAAI;AACvC,WAAO,GAAG,UAAU;AAAA,EAAK,QAAQ;AAAA,EACnC;AACF;","names":["import_xlr_utils","ValidationSeverity","import_xlr_utils","fs","path","ts"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/sdk.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/validator.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/types.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/utils.ts"],"sourcesContent":["export * from \"./sdk\";\nexport * from \"./types\";\nexport * from \"./registry\";\nexport * from \"./utils\";\n","/* eslint-disable prettier/prettier */\nimport type {\n Manifest,\n NamedType,\n NodeType,\n ObjectNode,\n ObjectType,\n TransformFunction,\n TSManifest,\n} from \"@xlr-lib/xlr\";\nimport {\n computeEffectiveObject,\n resolveConditional,\n resolveReferenceNode,\n} from \"@xlr-lib/xlr-utils\";\nimport { fillInGenerics } from \"@xlr-lib/xlr-utils\";\nimport type { Node } from \"jsonc-parser\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nimport type { XLRRegistry, Filters } from \"./registry\";\nimport { BasicXLRRegistry } from \"./registry\";\nimport { XLRValidator } from \"./validator\";\nimport { TransformFunctionMap, xlrTransformWalker } from \"./utils\";\n\nexport interface GetTypeOptions {\n /** Resolves `extends` fields in objects */\n getRawType?: boolean;\n /** Perform optimizations to resolve all references, type intersections, and conditionals */\n optimize?: boolean;\n}\n\n/**\n * Abstraction for interfacing with XLRs making it more approachable to use without understanding the inner workings of the types and how they are packaged\n */\nexport class XLRSDK {\n private registry: XLRRegistry;\n private validator: XLRValidator;\n private computedNodeCache: Map<string, NodeType>;\n private externalTransformFunctions: Map<string, TransformFunction>;\n\n constructor(customRegistry?: XLRRegistry) {\n this.registry = customRegistry ?? new BasicXLRRegistry();\n this.validator = new XLRValidator(this.getType.bind(this));\n this.computedNodeCache = new Map();\n this.externalTransformFunctions = new Map();\n }\n\n /**\n * Loads definitions from a path on the filesystem\n *\n * @param inputPath - path to the directory to load (above the xlr folder)\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public loadDefinitionsFromDisk(\n inputPath: string,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n const manifest = JSON.parse(\n fs.readFileSync(path.join(inputPath, \"xlr\", \"manifest.json\")).toString(),\n (key: unknown, value: unknown) => {\n // Custom parser because JSON objects -> JS Objects, not maps\n if (typeof value === \"object\" && value !== null) {\n if (key === \"capabilities\") {\n return new Map(Object.entries(value));\n }\n }\n\n return value;\n }\n ) as Manifest;\n\n manifest.capabilities?.forEach((capabilityList, capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n capabilityList.forEach((extensionName) => {\n if (!filters?.typeFilter || !extensionName.match(filters?.typeFilter)) {\n const cType: NamedType<NodeType> = JSON.parse(\n fs\n .readFileSync(\n path.join(inputPath, \"xlr\", `${extensionName}.json`)\n )\n .toString()\n );\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n cType\n ) ?? cType;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Load definitions from a js/ts file in memory\n *\n * @param manifest - The imported XLR manifest module\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public async loadDefinitionsFromModule(\n manifest: TSManifest,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n Object.keys(manifest.capabilities)?.forEach((capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n const capabilityList = manifest.capabilities[capabilityName];\n capabilityList.forEach((extension) => {\n if (\n !filters?.typeFilter ||\n !extension.name.match(filters?.typeFilter)\n ) {\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n extension\n ) ?? extension;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Statically load transform function that should be applied to every XLR bundle that is imported\n */\n public addTransformFunction(name: string, fn: TransformFunction): void {\n this.externalTransformFunctions.set(name, fn);\n }\n\n /**\n * Remove any transform function loaded via the `addTransformFunction` method by name\n */\n public removeTransformFunction(name: string): void {\n this.externalTransformFunctions.delete(name);\n }\n\n /**\n * Returns a Type that has been previously loaded\n *\n * @param id - Type to retrieve\n * @param options - `GetTypeOptions`\n * @returns `NamedType<NodeType>` | `undefined`\n */\n public getType(\n id: string,\n options?: GetTypeOptions\n ): NamedType<NodeType> | undefined {\n let type = this.registry.get(id);\n if (options?.getRawType === true || !type) {\n return type;\n }\n\n if (this.computedNodeCache.has(id)) {\n return JSON.parse(JSON.stringify(this.computedNodeCache.get(id))) as\n | NamedType<NodeType>\n | undefined;\n }\n\n type = this.resolveType(type, options?.optimize)\n\n this.computedNodeCache.set(id, type);\n\n return type;\n }\n\n /**\n * Returns if a Type with `id` has been loaded into the DSK\n *\n * @param id - Type to retrieve\n * @returns `boolean`\n */\n public hasType(id: string) {\n return this.registry.has(id);\n }\n\n /**\n * Lists types that have been loaded into the SDK\n *\n * @param filters - Any filters to apply to the types returned (a positive match will omit)\n * @returns `Array<NamedTypes>`\n */\n public listTypes(filters?: Filters) {\n return this.registry.list(filters);\n }\n\n /**\n * Returns meta information around a registered type\n *\n * @param id - Name of Type to retrieve\n * @returns `TypeMetaData` | `undefined`\n */\n public getTypeInfo(id: string) {\n return this.registry.info(id);\n }\n\n /**\n * Validates if a JSONC Node follows the XLR Type registered under the `typeName` specified\n *\n * @param typeName - Registered XLR Type to use for validation\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByName(typeName: string, rootNode: Node) {\n const xlr = this.getType(typeName);\n if (!xlr) {\n throw new Error(\n `Type ${typeName} does not exist in registry, can't validate`\n );\n }\n\n return this.validator.validateType(rootNode, xlr);\n }\n\n /**\n * Validates if a JSONC Node follows the supplied XLR Type\n *\n * @param type - Type to validate against\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByType(type: NodeType, rootNode: Node) {\n return this.validator.validateType(rootNode, type);\n }\n\n /**\n * Transforms a generated XLR node into its final representation by resolving all `extends` properties.\n * If `optimize` is set to true the following operations are also performed:\n * - Solving any conditional types\n * - Computing the effective types of any union elements\n * - Resolving any ref nodes\n * - filing in any remaining generics with their default value\n */\n private resolveType(type: NamedType, optimize = true): NamedType {\n const resolvedObject = fillInGenerics(type, new Map(), true);\n\n let transformMap: TransformFunctionMap = {\n object: [(objectNode: ObjectType) => {\n if (objectNode.extends) {\n const refName = objectNode.extends.ref.split(\"<\")[0];\n let extendedType = this.getType(refName, {getRawType: true});\n if (!extendedType) {\n throw new Error(\n `Error resolving ${objectNode.name}: can't find extended type ${refName}`\n );\n }\n\n extendedType = resolveReferenceNode(\n objectNode.extends,\n extendedType as NamedType<ObjectType>\n ) as NamedType;\n if (extendedType.type === \"object\") {\n return {\n ...computeEffectiveObject(\n extendedType as ObjectType,\n objectNode as ObjectType,\n false\n ),\n name: objectNode.name,\n description: objectNode.description,\n };\n }\n\n if( extendedType.type === \"or\"){\n return {\n ...this.validator.computeIntersectionType([\n objectNode,\n extendedType\n ]\n ),\n name: objectNode.name,\n description: objectNode.description,\n } as any;\n }\n\n // if the merge isn't straightforward, defer until validation time for now\n return {\n name: objectNode.name,\n type: \"and\",\n and: [\n {\n ...objectNode,\n extends: undefined,\n },\n extendedType,\n ],\n } as unknown as ObjectNode;\n }\n\n return objectNode;\n }],\n } \n\n if(optimize){\n transformMap = {\n ...transformMap,\n conditional: [(node) => {\n return resolveConditional(node) as any\n }],\n and: [(node) => {\n return {\n ...this.validator.computeIntersectionType(node.and),\n ...(node.name ? { name: node.name } : {}),\n } as any\n }],\n ref: [(refNode) => {\n return this.validator.getRefType(refNode) as any\n }]\n }\n }\n\n return xlrTransformWalker(transformMap)(resolvedObject) as NamedType\n }\n\n}\n","import type { NamedType, NodeType } from \"@xlr-lib/xlr\";\nimport type { XLRRegistry, Filters, TypeMetadata } from \"./types\";\n\n/**\n * Basic example of a XLRs Registry\n */\nexport class BasicXLRRegistry implements XLRRegistry {\n private typeMap: Map<string, NamedType<NodeType>>;\n private pluginMap: Map<string, Map<string, Array<string>>>;\n private infoMap: Map<string, TypeMetadata>;\n\n constructor() {\n this.typeMap = new Map();\n this.pluginMap = new Map();\n this.infoMap = new Map();\n }\n\n /** Returns a copy of the XLR to guard against unexpected type modification */\n get(id: string): NamedType<NodeType> | undefined {\n const value = this.typeMap.get(id);\n return value ? JSON.parse(JSON.stringify(value)) : undefined;\n }\n\n add(type: NamedType<NodeType>, plugin: string, capability: string): void {\n this.typeMap.set(type.name, type);\n this.infoMap.set(type.name, { plugin, capability });\n\n if (!this.pluginMap.has(plugin)) {\n this.pluginMap.set(plugin, new Map());\n }\n\n const pluginsCapabilities = this.pluginMap.get(plugin) as Map<\n string,\n Array<string>\n >;\n\n if (!pluginsCapabilities.has(capability)) {\n pluginsCapabilities.set(capability, []);\n }\n\n const providedCapabilities = pluginsCapabilities.get(\n capability,\n ) as string[];\n providedCapabilities.push(type.name);\n }\n\n has(id: string): boolean {\n return this.typeMap.has(id);\n }\n\n list(filterArgs?: Filters): NamedType<NodeType>[] {\n const validTypes: Array<string> = [];\n\n this.pluginMap.forEach((manifest, pluginName) => {\n if (\n !filterArgs?.pluginFilter ||\n !pluginName.match(filterArgs.pluginFilter)\n ) {\n manifest.forEach((types, capabilityName) => {\n if (\n !filterArgs?.capabilityFilter ||\n !capabilityName.match(filterArgs.capabilityFilter)\n ) {\n types.forEach((type) => {\n if (\n !filterArgs?.typeFilter ||\n !type.match(filterArgs.typeFilter)\n ) {\n validTypes.push(type);\n }\n });\n }\n });\n }\n });\n return validTypes.map((type) => this.get(type) as NamedType);\n }\n\n info(id: string): TypeMetadata | undefined {\n return this.infoMap.get(id);\n }\n}\n","import type { Node } from \"jsonc-parser\";\nimport type {\n ArrayType,\n NamedType,\n NodeType,\n ObjectType,\n OrType,\n PrimitiveTypes,\n RefType,\n TemplateLiteralType,\n} from \"@xlr-lib/xlr\";\nimport {\n makePropertyMap,\n resolveConditional,\n isPrimitiveTypeNode,\n resolveReferenceNode,\n computeEffectiveObject,\n} from \"@xlr-lib/xlr-utils\";\nimport { ValidationSeverity } from \"./types\";\nimport type { ValidationMessage } from \"./types\";\n\nexport interface XLRValidatorConfig {\n /** URL mapping for supplemental documentation */\n urlMapping?: Record<string, string>;\n}\n\nconst MAX_VALID_SHOWN = 20;\n\n/**\n * Validator for XLRs on JSON Nodes\n */\nexport class XLRValidator {\n private config: XLRValidatorConfig;\n private resolveType: (id: string) => NamedType<NodeType> | undefined;\n private regexCache: Map<string, RegExp>;\n\n constructor(\n resolveType: (id: string) => NamedType<NodeType> | undefined,\n config?: XLRValidatorConfig,\n ) {\n this.config = config || {};\n this.resolveType = resolveType;\n this.regexCache = new Map();\n }\n\n /** Main entrypoint for validation */\n public validateType(\n rootNode: Node,\n xlrNode: NodeType,\n ): Array<ValidationMessage> {\n const validationIssues = new Array<ValidationMessage>();\n if (xlrNode.type === \"object\") {\n if (rootNode.type === \"object\") {\n validationIssues.push(...this.validateObject(xlrNode, rootNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an object but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"array\") {\n if (rootNode.type === \"array\") {\n validationIssues.push(...this.validateArray(rootNode, xlrNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an array but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"template\") {\n const error = this.validateTemplate(rootNode, xlrNode);\n if (error) {\n validationIssues.push(error);\n }\n } else if (xlrNode.type === \"or\") {\n const potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }> = [];\n\n for (const potentialType of xlrNode.or) {\n const potentialErrors = this.validateType(rootNode, potentialType);\n\n if (potentialErrors.length === 0) {\n return validationIssues;\n }\n\n potentialTypeErrors.push({\n type: potentialType,\n errors: potentialErrors,\n });\n }\n\n let message: string;\n const expectedTypes = xlrNode.or\n .map((node) =>\n isPrimitiveTypeNode(node)\n ? node.type\n : (node.name ?? node.title ?? node.type ?? \"<unnamed type>\"),\n )\n .join(\" | \");\n\n if (xlrNode.name) {\n message = `Does not match any of the expected types for type: '${xlrNode.name}'`;\n } else if (xlrNode.title) {\n message = `Does not match any of the expected types for property: '${xlrNode.title}'`;\n } else {\n message = `Does not match any of the types: ${expectedTypes}`;\n }\n\n const { infoMessage } = this.generateNestedTypesInfo(\n potentialTypeErrors,\n xlrNode,\n rootNode,\n );\n\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: message.trim(),\n severity: ValidationSeverity.Error,\n });\n\n if (infoMessage) {\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: infoMessage,\n severity: ValidationSeverity.Info,\n });\n }\n } else if (xlrNode.type === \"and\") {\n const effectiveType = {\n ...this.computeIntersectionType(xlrNode.and),\n ...(xlrNode.name ? { name: xlrNode.name } : {}),\n };\n validationIssues.push(...this.validateType(rootNode, effectiveType));\n } else if (xlrNode.type === \"record\") {\n rootNode.children?.forEach((child) => {\n validationIssues.push(\n ...this.validateType(child.children?.[0] as Node, xlrNode.keyType),\n );\n validationIssues.push(\n ...this.validateType(child.children?.[1] as Node, xlrNode.valueType),\n );\n });\n } else if (xlrNode.type === \"ref\") {\n const refType = this.getRefType(xlrNode);\n if (refType === undefined) {\n validationIssues.push({\n type: \"unknown\",\n node: rootNode,\n message: `Type \"${xlrNode.ref}\" is not defined in provided bundles`,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push(\n ...this.validateType(rootNode, refType as NamedType),\n );\n }\n } else if (isPrimitiveTypeNode(xlrNode)) {\n if (!this.validateLiteralType(xlrNode, rootNode)) {\n if (\n (xlrNode.type === \"string\" ||\n xlrNode.type === \"number\" ||\n xlrNode.type === \"boolean\") &&\n xlrNode.const\n ) {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected \"${xlrNode.const}\" but got \"${rootNode.value}\"`,\n expected: xlrNode.const,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${rootNode.type}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n });\n }\n }\n } else if (xlrNode.type === \"conditional\") {\n // Resolve RefNodes in check conditions if needed\n let { right, left } = xlrNode.check;\n\n if (right.type === \"ref\") {\n right = this.getRefType(right);\n }\n\n if (left.type === \"ref\") {\n left = this.getRefType(left);\n }\n\n const resolvedXLRNode = {\n ...xlrNode,\n check: {\n left,\n right,\n },\n };\n\n const resolvedConditional = resolveConditional(resolvedXLRNode);\n if (resolvedConditional === resolvedXLRNode) {\n throw Error(\n `Unable to resolve conditional type at runtime: ${xlrNode.name}`,\n );\n }\n\n validationIssues.push(\n ...this.validateType(rootNode, resolvedConditional),\n );\n } else {\n throw Error(`Unknown type ${xlrNode.type}`);\n }\n\n return validationIssues;\n }\n\n private generateNestedTypesInfo(\n potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }>,\n xlrNode: OrType,\n rootNode: Node,\n ): { nestedTypesList: string; infoMessage?: string } {\n const nestedTypes = new Set<string>();\n\n // TODO: Create a recursive function that returns value or xlrNode info\n // First, try to extract types from potential type errors\n potentialTypeErrors.forEach((typeError) => {\n if (typeError.type.type !== \"template\") {\n typeError.errors.forEach((error) => {\n if (error.type === \"type\" && error.expected) {\n // Split by separate types if union\n String(error.expected)\n .split(\" | \")\n .forEach((val) => nestedTypes.add(val.trim()));\n }\n });\n }\n });\n\n // If no types found from errors, try using type from xlrNode\n if (nestedTypes.size === 0) {\n xlrNode.or.forEach((type) => {\n const typeName =\n type.name ?? type.title ?? type.type ?? \"<unnamed type>\";\n nestedTypes.add(typeName);\n });\n }\n\n const nestedTypesArray = [...nestedTypes];\n\n // Display list of expected types as a union\n let nestedTypesList =\n nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(\" | \") +\n (nestedTypesArray.length > MAX_VALID_SHOWN\n ? ` | +${\n nestedTypesArray.length - MAX_VALID_SHOWN\n } ... ${nestedTypesArray.pop()}`\n : \"\");\n\n // TODO: Be able to pass the validator's config to the SDK\n const docsURL = this.config.urlMapping;\n\n // Support passing in a URL for matching type\n if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {\n nestedTypesList = docsURL[xlrNode.name];\n }\n\n // Support supplemental info message\n let infoMessage;\n\n if (rootNode.value !== undefined) {\n infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;\n } else if (nestedTypesList) {\n infoMessage = `Expected: ${nestedTypesList}`;\n }\n\n return { nestedTypesList, infoMessage };\n }\n\n private validateTemplate(\n node: Node,\n xlrNode: TemplateLiteralType,\n ): ValidationMessage | undefined {\n if (node.type !== \"string\") {\n return {\n type: \"type\",\n node: node.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${typeof node}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n };\n }\n\n const regex = this.getRegex(xlrNode.format);\n const valid = regex.exec(node.value);\n if (!valid) {\n return {\n type: \"value\",\n node: node.parent as Node,\n message: `Does not match expected format: ${xlrNode.format}`,\n expected: xlrNode.format,\n severity: ValidationSeverity.Error,\n };\n }\n }\n\n private validateArray(rootNode: Node, xlrNode: ArrayType) {\n const issues: Array<ValidationMessage> = [];\n rootNode.children?.forEach((child) =>\n issues.push(...this.validateType(child, xlrNode.elementType)),\n );\n return issues;\n }\n\n private validateObject(xlrNode: ObjectType, node: Node) {\n const issues: Array<ValidationMessage> = [];\n const objectProps = makePropertyMap(node);\n\n for (const prop in xlrNode.properties) {\n const expectedType = xlrNode.properties[prop];\n const valueNode = objectProps.get(prop);\n if (expectedType.required && valueNode === undefined) {\n issues.push({\n type: \"missing\",\n node,\n message: `Property \"${prop}\" missing from type \"${xlrNode.name}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n\n if (valueNode) {\n issues.push(\n ...this.validateType(valueNode, expectedType.node as NamedType),\n );\n }\n }\n\n // Check if unknown keys are allowed and if they are - do the violate the constraint\n const extraKeys = Array.from(objectProps.keys()).filter(\n (key) => xlrNode.properties[key] === undefined,\n );\n if (xlrNode.additionalProperties === false && extraKeys.length > 0) {\n issues.push({\n type: \"value\",\n node,\n message: `Unexpected properties on \"${xlrNode.name}\": ${extraKeys.join(\n \", \",\n )}`,\n severity: ValidationSeverity.Error,\n });\n } else {\n issues.push(\n ...extraKeys.flatMap((key) =>\n this.validateType(\n objectProps.get(key) as Node,\n xlrNode.additionalProperties as NodeType,\n ),\n ),\n );\n }\n\n return issues;\n }\n\n private validateLiteralType(expectedType: PrimitiveTypes, literalType: Node) {\n switch (expectedType.type) {\n case \"boolean\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"boolean\";\n case \"number\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"number\";\n case \"string\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"string\";\n case \"null\":\n return literalType.value === null;\n case \"never\":\n return literalType === undefined;\n case \"any\":\n return literalType !== undefined;\n case \"unknown\":\n return literalType !== undefined;\n case \"undefined\":\n return true;\n default:\n return false;\n }\n }\n\n public getRefType(ref: RefType): NodeType {\n let refName = ref.ref;\n if (refName.indexOf(\"<\") > 0) {\n [refName] = refName.split(\"<\");\n }\n\n const actualType = this.resolveType(refName);\n if (!actualType) {\n throw new Error(`Error: can't resolve type reference ${refName}`);\n }\n\n return resolveReferenceNode(ref, actualType);\n }\n\n private getRegex(expString: string): RegExp {\n if (this.regexCache.has(expString)) {\n return this.regexCache.get(expString) as RegExp;\n }\n\n const exp = new RegExp(expString);\n this.regexCache.set(expString, exp);\n return exp;\n }\n\n public computeIntersectionType(types: Array<NodeType>): ObjectType | OrType {\n let firstElement = types[0];\n let effectiveType: ObjectType | OrType;\n\n // Capture the original top-level type name if exists\n const topLevelTypeName = types[0].name;\n\n if (firstElement.type === \"ref\") {\n firstElement = this.getRefType(firstElement);\n }\n\n if (firstElement.type === \"and\") {\n effectiveType = this.computeIntersectionType(firstElement.and);\n } else if (firstElement.type === \"record\") {\n effectiveType = {\n type: \"object\",\n properties: {},\n additionalProperties: firstElement.valueType,\n };\n } else if (firstElement.type !== \"or\" && firstElement.type !== \"object\") {\n throw new Error(\n `Can't compute a union with a non-object type ${firstElement.type} (${firstElement.name})`,\n );\n } else {\n effectiveType = firstElement;\n }\n\n types.slice(1).forEach((type) => {\n let typeToApply = type;\n\n if (typeToApply.type === \"record\") {\n typeToApply = {\n type: \"object\",\n properties: {},\n additionalProperties: typeToApply.valueType,\n };\n }\n\n if (type.type === \"ref\") {\n typeToApply = this.getRefType(type);\n }\n\n if (typeToApply.type === \"and\") {\n typeToApply = this.computeIntersectionType([type, effectiveType]);\n }\n\n if (typeToApply.type === \"object\") {\n if (effectiveType.type === \"object\") {\n effectiveType = computeEffectiveObject(effectiveType, typeToApply);\n } else {\n effectiveType = {\n ...effectiveType,\n or: effectiveType.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n typeToApply,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n }\n } else if (typeToApply.type === \"or\") {\n if (effectiveType.type === \"object\") {\n effectiveType = {\n ...typeToApply,\n or: typeToApply.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n effectiveType,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n } else {\n throw new Error(\"unimplemented operation or x or projection\");\n }\n } else {\n throw new Error(\n `Can't compute a union with a non-object type ${typeToApply.type} (${typeToApply.name})`,\n );\n }\n });\n\n // If the final effective type is an or type and doesn't have a name, use the top-level type name\n if (\n effectiveType.type === \"or\" &&\n !effectiveType.name &&\n topLevelTypeName\n ) {\n effectiveType.name = topLevelTypeName;\n }\n\n return effectiveType;\n }\n}\n","import type { Node } from \"jsonc-parser\";\n\nexport interface BaseValidationMessage<ErrorType extends string = string> {\n /** Validation Type */\n type: ErrorType;\n\n /** Error message text */\n message: string;\n\n /** JSONC node that the error originates from */\n node: Node;\n\n /** Level of the message */\n severity: ValidationSeverity;\n}\n\nexport interface TypeValidationError extends BaseValidationMessage<\"type\"> {\n /** Expected types */\n expected?: string[] | string | number | boolean;\n}\n\nexport type MissingValidationError = BaseValidationMessage<\"missing\">;\n\nexport type UnknownValidationError = BaseValidationMessage<\"unknown\">;\n\nexport interface ValueValidationError extends BaseValidationMessage<\"value\"> {\n /** Expected value */\n expected?: string;\n}\n\nexport type UnexpectedValidationError = BaseValidationMessage<\"unexpected\">;\n\nexport type ValidationMessage =\n | TypeValidationError\n | MissingValidationError\n | UnknownValidationError\n | ValueValidationError\n | UnexpectedValidationError;\n\nexport enum ValidationSeverity {\n Error = 1,\n Warning = 2,\n Info = 3,\n Trace = 4,\n}\n","import type {\n NamedType,\n NodeTypeStrings,\n NodeTypeMap,\n TransformFunction,\n NodeType,\n ObjectProperty,\n RefNode,\n} from \"@xlr-lib/xlr\";\nimport { isGenericNamedType } from \"@xlr-lib/xlr-utils\";\n\ntype TypedTransformFunction<T extends NodeTypeStrings = NodeTypeStrings> = (\n input: NodeTypeMap[T],\n) => NodeTypeMap[T];\n\nexport type TransformFunctionMap = {\n [nodeType in NodeTypeStrings]?: Array<TypedTransformFunction<nodeType>>;\n};\n\nconst isMatchingCapability = (\n capability: string,\n capabilitiesToMatch: string | Array<string>,\n): boolean => {\n if (Array.isArray(capabilitiesToMatch)) {\n return capabilitiesToMatch.includes(capability);\n }\n\n return capability === capabilitiesToMatch;\n};\n\nexport function xlrTransformWalker(\n transformMap: TransformFunctionMap,\n): (node: NodeType) => NodeType {\n const walker = (n: NamedType | NodeType): NodeType => {\n let node = { ...n };\n const transformFunctions = transformMap[node.type] as unknown as Array<\n TypedTransformFunction<typeof node.type>\n >;\n\n for (const transformFn of transformFunctions ?? []) {\n node = transformFn(node);\n }\n\n if (node.type === \"object\") {\n const newObjectProperties: Record<string, ObjectProperty> = {};\n\n for (const key in node.properties) {\n const value = node.properties[key];\n newObjectProperties[key] = {\n required: value.required,\n node: walker(value.node),\n };\n }\n\n // need to walk generic tokens\n return {\n ...node,\n properties: { ...newObjectProperties },\n ...(isGenericNamedType(node)\n ? {\n genericTokens: node.genericTokens.map((token) => {\n return {\n ...token,\n constraints: token.constraints\n ? walker(token.constraints)\n : undefined,\n default: token.default ? walker(token.default) : undefined,\n };\n }),\n }\n : {}),\n extends: node.extends ? (walker(node.extends) as RefNode) : undefined,\n additionalProperties: node.additionalProperties\n ? walker(node.additionalProperties)\n : false,\n };\n }\n\n if (node.type === \"array\") {\n return {\n ...node,\n elementType: walker(node.elementType),\n };\n }\n\n if (node.type === \"and\") {\n return {\n ...node,\n and: node.and.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"or\") {\n return {\n ...node,\n or: node.or.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"ref\") {\n return {\n ...node,\n ...(node.genericArguments\n ? {\n genericArguments: node.genericArguments?.map((arg) =>\n walker(arg),\n ),\n }\n : {}),\n };\n }\n\n if (node.type === \"tuple\") {\n return {\n ...node,\n elementTypes: node.elementTypes.map((element) => {\n return {\n name: element.name,\n type: walker(element.type),\n optional: element.optional,\n };\n }),\n additionalItems: node.additionalItems\n ? walker(node.additionalItems)\n : false,\n };\n }\n\n if (node.type === \"function\") {\n return {\n ...node,\n parameters: node.parameters.map((param) => {\n return {\n ...param,\n type: walker(param.type),\n default: param.default ? walker(param.default) : undefined,\n };\n }),\n returnType: node.returnType ? walker(node.returnType) : undefined,\n };\n }\n\n if (node.type === \"record\") {\n return {\n ...node,\n keyType: walker(node.keyType),\n valueType: walker(node.valueType),\n };\n }\n\n if (node.type === \"conditional\") {\n return {\n ...node,\n check: {\n left: walker(node.check.left),\n right: walker(node.check.left),\n },\n value: {\n true: walker(node.value.true),\n false: walker(node.value.false),\n },\n };\n }\n\n return node;\n };\n\n return walker;\n}\n\n/**\n * Helper function for simple transforms\n * Walks an XLR tree looking for the specified node type calls the supplied function when called\n */\nexport function simpleTransformGenerator<\n T extends NodeTypeStrings = NodeTypeStrings,\n>(\n typeToTransform: T,\n capabilityToTransform: string | Array<string>,\n functionToRun: TypedTransformFunction<T>,\n): TransformFunction {\n /** walker for an XLR tree to touch every node */\n return (n: NamedType | NodeType, capability: string) => {\n // Run transform on base node before running on children\n if (isMatchingCapability(capability, capabilityToTransform)) {\n return xlrTransformWalker({ [typeToTransform]: [functionToRun] })(n);\n }\n\n return n;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACUA,IAAAA,oBAIO;AACP,IAAAA,oBAA+B;AAE/B,gBAAe;AACf,kBAAiB;;;ACZV,IAAM,mBAAN,MAA8C;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,YAAY,oBAAI,IAAI;AACzB,SAAK,UAAU,oBAAI,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,IAAI,IAA6C;AAC/C,UAAM,QAAQ,KAAK,QAAQ,IAAI,EAAE;AACjC,WAAO,QAAQ,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,EACrD;AAAA,EAEA,IAAI,MAA2B,QAAgB,YAA0B;AACvE,SAAK,QAAQ,IAAI,KAAK,MAAM,IAAI;AAChC,SAAK,QAAQ,IAAI,KAAK,MAAM,EAAE,QAAQ,WAAW,CAAC;AAElD,QAAI,CAAC,KAAK,UAAU,IAAI,MAAM,GAAG;AAC/B,WAAK,UAAU,IAAI,QAAQ,oBAAI,IAAI,CAAC;AAAA,IACtC;AAEA,UAAM,sBAAsB,KAAK,UAAU,IAAI,MAAM;AAKrD,QAAI,CAAC,oBAAoB,IAAI,UAAU,GAAG;AACxC,0BAAoB,IAAI,YAAY,CAAC,CAAC;AAAA,IACxC;AAEA,UAAM,uBAAuB,oBAAoB;AAAA,MAC/C;AAAA,IACF;AACA,yBAAqB,KAAK,KAAK,IAAI;AAA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,sCAAmB,IAAI;AAAA,QAChC,CAAC;AAAA,QACD,KAAK,CAAC,CAAC,SAAS;AACd,iBAAO;AAAA,YACL,GAAG,KAAK,UAAU,wBAAwB,KAAK,GAAG;AAAA,YAClD,GAAI,KAAK,OAAO,EAAE,MAAM,KAAK,KAAK,IAAI,CAAC;AAAA,UACzC;AAAA,QACF,CAAC;AAAA,QACD,KAAK,CAAC,CAAC,YAAY;AACjB,iBAAO,KAAK,UAAU,WAAW,OAAO;AAAA,QAC1C,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO,mBAAmB,YAAY,EAAE,cAAc;AAAA,EACxD;AAEF;","names":["import_xlr_utils","ValidationSeverity","import_xlr_utils","fs","path"]}
@@ -5,10 +5,8 @@ import {
5
5
  resolveReferenceNode as resolveReferenceNode2
6
6
  } from "@xlr-lib/xlr-utils";
7
7
  import { fillInGenerics } from "@xlr-lib/xlr-utils";
8
- import { TSWriter } from "@xlr-lib/xlr-converters";
9
8
  import fs from "fs";
10
9
  import path from "path";
11
- import ts from "typescript";
12
10
 
13
11
  // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts
14
12
  var BasicXLRRegistry = class {
@@ -615,13 +613,11 @@ function simpleTransformGenerator(typeToTransform, capabilityToTransform, functi
615
613
  var XLRSDK = class {
616
614
  registry;
617
615
  validator;
618
- tsWriter;
619
616
  computedNodeCache;
620
617
  externalTransformFunctions;
621
618
  constructor(customRegistry) {
622
619
  this.registry = customRegistry ?? new BasicXLRRegistry();
623
620
  this.validator = new XLRValidator(this.getType.bind(this));
624
- this.tsWriter = new TSWriter();
625
621
  this.computedNodeCache = /* @__PURE__ */ new Map();
626
622
  this.externalTransformFunctions = /* @__PURE__ */ new Map();
627
623
  }
@@ -786,32 +782,6 @@ var XLRSDK = class {
786
782
  validateByType(type, rootNode) {
787
783
  return this.validator.validateType(rootNode, type);
788
784
  }
789
- /**
790
- * Exports the types loaded into the registry to the specified format
791
- *
792
- * @param exportType - what format to export as
793
- * @param importMap - a map of primitive packages to types exported from that package to add import statements
794
- * @param filters - filter out plugins/capabilities/types you don't want to export
795
- * @param transforms - transforms to apply to types before exporting them
796
- * @returns [filename, content][] - Tuples of filenames and content to write
797
- */
798
- exportRegistry(exportType, importMap, filters, transforms) {
799
- const typesToExport = this.registry.list(filters).map((type) => {
800
- const effectiveType = transforms?.reduce(
801
- (typeAccumulator, transformFn) => transformFn(
802
- typeAccumulator,
803
- this.registry.info(type.name)?.capability
804
- ),
805
- type
806
- ) ?? type;
807
- return effectiveType;
808
- });
809
- if (exportType === "TypeScript") {
810
- const outputString = this.exportToTypeScript(typesToExport, importMap);
811
- return [["out.d.ts", outputString]];
812
- }
813
- throw new Error(`Unknown export format ${exportType}`);
814
- }
815
785
  /**
816
786
  * Transforms a generated XLR node into its final representation by resolving all `extends` properties.
817
787
  * If `optimize` is set to true the following operations are also performed:
@@ -893,63 +863,6 @@ var XLRSDK = class {
893
863
  }
894
864
  return xlrTransformWalker(transformMap)(resolvedObject);
895
865
  }
896
- exportToTypeScript(typesToExport, importMap) {
897
- const referencedImports = /* @__PURE__ */ new Set();
898
- const exportedTypes = /* @__PURE__ */ new Map();
899
- const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
900
- let resultFile = ts.createSourceFile(
901
- "output.d.ts",
902
- "",
903
- ts.ScriptTarget.ES2017,
904
- false,
905
- // setParentNodes
906
- ts.ScriptKind.TS
907
- );
908
- typesToExport.forEach((typeNode) => {
909
- const { type, referencedTypes, additionalTypes } = this.tsWriter.convertNamedType(typeNode);
910
- exportedTypes.set(typeNode.name, type);
911
- additionalTypes?.forEach(
912
- (additionalType, name) => exportedTypes.set(name, additionalType)
913
- );
914
- referencedTypes?.forEach(
915
- (referencedType) => referencedImports.add(referencedType)
916
- );
917
- });
918
- const typesToPrint = [];
919
- exportedTypes.forEach(
920
- (type) => typesToPrint.push(
921
- printer.printNode(ts.EmitHint.Unspecified, type, resultFile)
922
- )
923
- );
924
- importMap.forEach((imports, packageName) => {
925
- const applicableImports = imports.filter((i) => referencedImports.has(i));
926
- resultFile = ts.factory.updateSourceFile(resultFile, [
927
- ts.factory.createImportDeclaration(
928
- /* modifiers */
929
- void 0,
930
- ts.factory.createImportClause(
931
- false,
932
- void 0,
933
- ts.factory.createNamedImports(
934
- applicableImports.map(
935
- (i) => ts.factory.createImportSpecifier(
936
- false,
937
- void 0,
938
- ts.factory.createIdentifier(i)
939
- )
940
- )
941
- )
942
- ),
943
- ts.factory.createStringLiteral(packageName)
944
- ),
945
- ...resultFile.statements
946
- ]);
947
- });
948
- const headerText = printer.printFile(resultFile);
949
- const nodeText = typesToPrint.join("\n");
950
- return `${headerText}
951
- ${nodeText}`;
952
- }
953
866
  };
954
867
  export {
955
868
  BasicXLRRegistry,
package/dist/index.mjs CHANGED
@@ -5,10 +5,8 @@ import {
5
5
  resolveReferenceNode as resolveReferenceNode2
6
6
  } from "@xlr-lib/xlr-utils";
7
7
  import { fillInGenerics } from "@xlr-lib/xlr-utils";
8
- import { TSWriter } from "@xlr-lib/xlr-converters";
9
8
  import fs from "fs";
10
9
  import path from "path";
11
- import ts from "typescript";
12
10
 
13
11
  // ../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts
14
12
  var BasicXLRRegistry = class {
@@ -615,13 +613,11 @@ function simpleTransformGenerator(typeToTransform, capabilityToTransform, functi
615
613
  var XLRSDK = class {
616
614
  registry;
617
615
  validator;
618
- tsWriter;
619
616
  computedNodeCache;
620
617
  externalTransformFunctions;
621
618
  constructor(customRegistry) {
622
619
  this.registry = customRegistry ?? new BasicXLRRegistry();
623
620
  this.validator = new XLRValidator(this.getType.bind(this));
624
- this.tsWriter = new TSWriter();
625
621
  this.computedNodeCache = /* @__PURE__ */ new Map();
626
622
  this.externalTransformFunctions = /* @__PURE__ */ new Map();
627
623
  }
@@ -786,32 +782,6 @@ var XLRSDK = class {
786
782
  validateByType(type, rootNode) {
787
783
  return this.validator.validateType(rootNode, type);
788
784
  }
789
- /**
790
- * Exports the types loaded into the registry to the specified format
791
- *
792
- * @param exportType - what format to export as
793
- * @param importMap - a map of primitive packages to types exported from that package to add import statements
794
- * @param filters - filter out plugins/capabilities/types you don't want to export
795
- * @param transforms - transforms to apply to types before exporting them
796
- * @returns [filename, content][] - Tuples of filenames and content to write
797
- */
798
- exportRegistry(exportType, importMap, filters, transforms) {
799
- const typesToExport = this.registry.list(filters).map((type) => {
800
- const effectiveType = transforms?.reduce(
801
- (typeAccumulator, transformFn) => transformFn(
802
- typeAccumulator,
803
- this.registry.info(type.name)?.capability
804
- ),
805
- type
806
- ) ?? type;
807
- return effectiveType;
808
- });
809
- if (exportType === "TypeScript") {
810
- const outputString = this.exportToTypeScript(typesToExport, importMap);
811
- return [["out.d.ts", outputString]];
812
- }
813
- throw new Error(`Unknown export format ${exportType}`);
814
- }
815
785
  /**
816
786
  * Transforms a generated XLR node into its final representation by resolving all `extends` properties.
817
787
  * If `optimize` is set to true the following operations are also performed:
@@ -893,63 +863,6 @@ var XLRSDK = class {
893
863
  }
894
864
  return xlrTransformWalker(transformMap)(resolvedObject);
895
865
  }
896
- exportToTypeScript(typesToExport, importMap) {
897
- const referencedImports = /* @__PURE__ */ new Set();
898
- const exportedTypes = /* @__PURE__ */ new Map();
899
- const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
900
- let resultFile = ts.createSourceFile(
901
- "output.d.ts",
902
- "",
903
- ts.ScriptTarget.ES2017,
904
- false,
905
- // setParentNodes
906
- ts.ScriptKind.TS
907
- );
908
- typesToExport.forEach((typeNode) => {
909
- const { type, referencedTypes, additionalTypes } = this.tsWriter.convertNamedType(typeNode);
910
- exportedTypes.set(typeNode.name, type);
911
- additionalTypes?.forEach(
912
- (additionalType, name) => exportedTypes.set(name, additionalType)
913
- );
914
- referencedTypes?.forEach(
915
- (referencedType) => referencedImports.add(referencedType)
916
- );
917
- });
918
- const typesToPrint = [];
919
- exportedTypes.forEach(
920
- (type) => typesToPrint.push(
921
- printer.printNode(ts.EmitHint.Unspecified, type, resultFile)
922
- )
923
- );
924
- importMap.forEach((imports, packageName) => {
925
- const applicableImports = imports.filter((i) => referencedImports.has(i));
926
- resultFile = ts.factory.updateSourceFile(resultFile, [
927
- ts.factory.createImportDeclaration(
928
- /* modifiers */
929
- void 0,
930
- ts.factory.createImportClause(
931
- false,
932
- void 0,
933
- ts.factory.createNamedImports(
934
- applicableImports.map(
935
- (i) => ts.factory.createImportSpecifier(
936
- false,
937
- void 0,
938
- ts.factory.createIdentifier(i)
939
- )
940
- )
941
- )
942
- ),
943
- ts.factory.createStringLiteral(packageName)
944
- ),
945
- ...resultFile.statements
946
- ]);
947
- });
948
- const headerText = printer.printFile(resultFile);
949
- const nodeText = typesToPrint.join("\n");
950
- return `${headerText}
951
- ${nodeText}`;
952
- }
953
866
  };
954
867
  export {
955
868
  BasicXLRRegistry,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/sdk.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/validator.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/types.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/utils.ts"],"sourcesContent":["/* eslint-disable prettier/prettier */\nimport type {\n Manifest,\n NamedType,\n NodeType,\n ObjectNode,\n ObjectType,\n TransformFunction,\n TSManifest,\n} from \"@xlr-lib/xlr\";\nimport type { TopLevelDeclaration } from \"@xlr-lib/xlr-utils\";\nimport {\n computeEffectiveObject,\n resolveConditional,\n resolveReferenceNode,\n} from \"@xlr-lib/xlr-utils\";\nimport { fillInGenerics } from \"@xlr-lib/xlr-utils\";\nimport type { Node } from \"jsonc-parser\";\nimport { TSWriter } from \"@xlr-lib/xlr-converters\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport ts from \"typescript\";\n\nimport type { XLRRegistry, Filters } from \"./registry\";\nimport { BasicXLRRegistry } from \"./registry\";\nimport type { ExportTypes } from \"./types\";\nimport { XLRValidator } from \"./validator\";\nimport { TransformFunctionMap, xlrTransformWalker } from \"./utils\";\n\nexport interface GetTypeOptions {\n /** Resolves `extends` fields in objects */\n getRawType?: boolean;\n /** Perform optimizations to resolve all references, type intersections, and conditionals */\n optimize?: boolean;\n}\n\n/**\n * Abstraction for interfacing with XLRs making it more approachable to use without understanding the inner workings of the types and how they are packaged\n */\nexport class XLRSDK {\n private registry: XLRRegistry;\n private validator: XLRValidator;\n private tsWriter: TSWriter;\n private computedNodeCache: Map<string, NodeType>;\n private externalTransformFunctions: Map<string, TransformFunction>;\n\n constructor(customRegistry?: XLRRegistry) {\n this.registry = customRegistry ?? new BasicXLRRegistry();\n this.validator = new XLRValidator(this.getType.bind(this));\n this.tsWriter = new TSWriter();\n this.computedNodeCache = new Map();\n this.externalTransformFunctions = new Map();\n }\n\n /**\n * Loads definitions from a path on the filesystem\n *\n * @param inputPath - path to the directory to load (above the xlr folder)\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public loadDefinitionsFromDisk(\n inputPath: string,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n const manifest = JSON.parse(\n fs.readFileSync(path.join(inputPath, \"xlr\", \"manifest.json\")).toString(),\n (key: unknown, value: unknown) => {\n // Custom parser because JSON objects -> JS Objects, not maps\n if (typeof value === \"object\" && value !== null) {\n if (key === \"capabilities\") {\n return new Map(Object.entries(value));\n }\n }\n\n return value;\n }\n ) as Manifest;\n\n manifest.capabilities?.forEach((capabilityList, capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n capabilityList.forEach((extensionName) => {\n if (!filters?.typeFilter || !extensionName.match(filters?.typeFilter)) {\n const cType: NamedType<NodeType> = JSON.parse(\n fs\n .readFileSync(\n path.join(inputPath, \"xlr\", `${extensionName}.json`)\n )\n .toString()\n );\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n cType\n ) ?? cType;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Load definitions from a js/ts file in memory\n *\n * @param manifest - The imported XLR manifest module\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public async loadDefinitionsFromModule(\n manifest: TSManifest,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n Object.keys(manifest.capabilities)?.forEach((capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n const capabilityList = manifest.capabilities[capabilityName];\n capabilityList.forEach((extension) => {\n if (\n !filters?.typeFilter ||\n !extension.name.match(filters?.typeFilter)\n ) {\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n extension\n ) ?? extension;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Statically load transform function that should be applied to every XLR bundle that is imported\n */\n public addTransformFunction(name: string, fn: TransformFunction): void {\n this.externalTransformFunctions.set(name, fn);\n }\n\n /**\n * Remove any transform function loaded via the `addTransformFunction` method by name\n */\n public removeTransformFunction(name: string): void {\n this.externalTransformFunctions.delete(name);\n }\n\n /**\n * Returns a Type that has been previously loaded\n *\n * @param id - Type to retrieve\n * @param options - `GetTypeOptions`\n * @returns `NamedType<NodeType>` | `undefined`\n */\n public getType(\n id: string,\n options?: GetTypeOptions\n ): NamedType<NodeType> | undefined {\n let type = this.registry.get(id);\n if (options?.getRawType === true || !type) {\n return type;\n }\n\n if (this.computedNodeCache.has(id)) {\n return JSON.parse(JSON.stringify(this.computedNodeCache.get(id))) as\n | NamedType<NodeType>\n | undefined;\n }\n\n type = this.resolveType(type, options?.optimize)\n\n this.computedNodeCache.set(id, type);\n\n return type;\n }\n\n /**\n * Returns if a Type with `id` has been loaded into the DSK\n *\n * @param id - Type to retrieve\n * @returns `boolean`\n */\n public hasType(id: string) {\n return this.registry.has(id);\n }\n\n /**\n * Lists types that have been loaded into the SDK\n *\n * @param filters - Any filters to apply to the types returned (a positive match will omit)\n * @returns `Array<NamedTypes>`\n */\n public listTypes(filters?: Filters) {\n return this.registry.list(filters);\n }\n\n /**\n * Returns meta information around a registered type\n *\n * @param id - Name of Type to retrieve\n * @returns `TypeMetaData` | `undefined`\n */\n public getTypeInfo(id: string) {\n return this.registry.info(id);\n }\n\n /**\n * Validates if a JSONC Node follows the XLR Type registered under the `typeName` specified\n *\n * @param typeName - Registered XLR Type to use for validation\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByName(typeName: string, rootNode: Node) {\n const xlr = this.getType(typeName);\n if (!xlr) {\n throw new Error(\n `Type ${typeName} does not exist in registry, can't validate`\n );\n }\n\n return this.validator.validateType(rootNode, xlr);\n }\n\n /**\n * Validates if a JSONC Node follows the supplied XLR Type\n *\n * @param type - Type to validate against\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByType(type: NodeType, rootNode: Node) {\n return this.validator.validateType(rootNode, type);\n }\n\n /**\n * Exports the types loaded into the registry to the specified format\n *\n * @param exportType - what format to export as\n * @param importMap - a map of primitive packages to types exported from that package to add import statements\n * @param filters - filter out plugins/capabilities/types you don't want to export\n * @param transforms - transforms to apply to types before exporting them\n * @returns [filename, content][] - Tuples of filenames and content to write\n */\n public exportRegistry(\n exportType: ExportTypes,\n importMap: Map<string, string[]>,\n filters?: Filters,\n transforms?: Array<TransformFunction>\n ): [string, string][] {\n const typesToExport = this.registry.list(filters).map((type) => {\n const effectiveType =\n transforms?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n this.registry.info(type.name)?.capability as string\n ) as NamedType<NodeType>,\n type\n ) ?? type;\n\n return effectiveType;\n });\n\n if (exportType === \"TypeScript\") {\n const outputString = this.exportToTypeScript(typesToExport, importMap);\n return [[\"out.d.ts\", outputString]];\n }\n\n throw new Error(`Unknown export format ${exportType}`);\n }\n\n /**\n * Transforms a generated XLR node into its final representation by resolving all `extends` properties.\n * If `optimize` is set to true the following operations are also performed:\n * - Solving any conditional types\n * - Computing the effective types of any union elements\n * - Resolving any ref nodes\n * - filing in any remaining generics with their default value\n */\n private resolveType(type: NamedType, optimize = true): NamedType {\n const resolvedObject = fillInGenerics(type, new Map(), true);\n\n let transformMap: TransformFunctionMap = {\n object: [(objectNode: ObjectType) => {\n if (objectNode.extends) {\n const refName = objectNode.extends.ref.split(\"<\")[0];\n let extendedType = this.getType(refName, {getRawType: true});\n if (!extendedType) {\n throw new Error(\n `Error resolving ${objectNode.name}: can't find extended type ${refName}`\n );\n }\n\n extendedType = resolveReferenceNode(\n objectNode.extends,\n extendedType as NamedType<ObjectType>\n ) as NamedType;\n if (extendedType.type === \"object\") {\n return {\n ...computeEffectiveObject(\n extendedType as ObjectType,\n objectNode as ObjectType,\n false\n ),\n name: objectNode.name,\n description: objectNode.description,\n };\n }\n\n if( extendedType.type === \"or\"){\n return {\n ...this.validator.computeIntersectionType([\n objectNode,\n extendedType\n ]\n ),\n name: objectNode.name,\n description: objectNode.description,\n } as any;\n }\n\n // if the merge isn't straightforward, defer until validation time for now\n return {\n name: objectNode.name,\n type: \"and\",\n and: [\n {\n ...objectNode,\n extends: undefined,\n },\n extendedType,\n ],\n } as unknown as ObjectNode;\n }\n\n return objectNode;\n }],\n } \n\n if(optimize){\n transformMap = {\n ...transformMap,\n conditional: [(node) => {\n return resolveConditional(node) as any\n }],\n and: [(node) => {\n return {\n ...this.validator.computeIntersectionType(node.and),\n ...(node.name ? { name: node.name } : {}),\n } as any\n }],\n ref: [(refNode) => {\n return this.validator.getRefType(refNode) as any\n }]\n }\n }\n\n return xlrTransformWalker(transformMap)(resolvedObject) as NamedType\n }\n\n private exportToTypeScript(\n typesToExport: NamedType[],\n importMap: Map<string, string[]>\n ): string {\n const referencedImports: Set<string> = new Set();\n const exportedTypes: Map<string, TopLevelDeclaration> = new Map();\n const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });\n\n let resultFile = ts.createSourceFile(\n \"output.d.ts\",\n \"\",\n ts.ScriptTarget.ES2017,\n false, // setParentNodes\n ts.ScriptKind.TS\n );\n\n typesToExport.forEach((typeNode) => {\n const { type, referencedTypes, additionalTypes } =\n this.tsWriter.convertNamedType(typeNode);\n exportedTypes.set(typeNode.name, type);\n additionalTypes?.forEach((additionalType, name) =>\n exportedTypes.set(name, additionalType)\n );\n referencedTypes?.forEach((referencedType) =>\n referencedImports.add(referencedType)\n );\n });\n\n const typesToPrint: Array<string> = [];\n\n exportedTypes.forEach((type) =>\n typesToPrint.push(\n printer.printNode(ts.EmitHint.Unspecified, type, resultFile)\n )\n );\n\n importMap.forEach((imports, packageName) => {\n const applicableImports = imports.filter((i) => referencedImports.has(i));\n resultFile = ts.factory.updateSourceFile(resultFile, [\n ts.factory.createImportDeclaration(\n /* modifiers */ undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports(\n applicableImports.map((i) =>\n ts.factory.createImportSpecifier(\n false,\n undefined,\n ts.factory.createIdentifier(i)\n )\n )\n )\n ),\n ts.factory.createStringLiteral(packageName)\n ),\n ...resultFile.statements,\n ]);\n });\n\n const headerText = printer.printFile(resultFile);\n const nodeText = typesToPrint.join(\"\\n\");\n return `${headerText}\\n${nodeText}`;\n }\n}\n","import type { NamedType, NodeType } from \"@xlr-lib/xlr\";\nimport type { XLRRegistry, Filters, TypeMetadata } from \"./types\";\n\n/**\n * Basic example of a XLRs Registry\n */\nexport class BasicXLRRegistry implements XLRRegistry {\n private typeMap: Map<string, NamedType<NodeType>>;\n private pluginMap: Map<string, Map<string, Array<string>>>;\n private infoMap: Map<string, TypeMetadata>;\n\n constructor() {\n this.typeMap = new Map();\n this.pluginMap = new Map();\n this.infoMap = new Map();\n }\n\n /** Returns a copy of the XLR to guard against unexpected type modification */\n get(id: string): NamedType<NodeType> | undefined {\n const value = this.typeMap.get(id);\n return value ? JSON.parse(JSON.stringify(value)) : undefined;\n }\n\n add(type: NamedType<NodeType>, plugin: string, capability: string): void {\n this.typeMap.set(type.name, type);\n this.infoMap.set(type.name, { plugin, capability });\n\n if (!this.pluginMap.has(plugin)) {\n this.pluginMap.set(plugin, new Map());\n }\n\n const pluginsCapabilities = this.pluginMap.get(plugin) as Map<\n string,\n Array<string>\n >;\n\n if (!pluginsCapabilities.has(capability)) {\n pluginsCapabilities.set(capability, []);\n }\n\n const providedCapabilities = pluginsCapabilities.get(\n capability,\n ) as string[];\n providedCapabilities.push(type.name);\n }\n\n has(id: string): boolean {\n return this.typeMap.has(id);\n }\n\n list(filterArgs?: Filters): NamedType<NodeType>[] {\n const validTypes: Array<string> = [];\n\n this.pluginMap.forEach((manifest, pluginName) => {\n if (\n !filterArgs?.pluginFilter ||\n !pluginName.match(filterArgs.pluginFilter)\n ) {\n manifest.forEach((types, capabilityName) => {\n if (\n !filterArgs?.capabilityFilter ||\n !capabilityName.match(filterArgs.capabilityFilter)\n ) {\n types.forEach((type) => {\n if (\n !filterArgs?.typeFilter ||\n !type.match(filterArgs.typeFilter)\n ) {\n validTypes.push(type);\n }\n });\n }\n });\n }\n });\n return validTypes.map((type) => this.get(type) as NamedType);\n }\n\n info(id: string): TypeMetadata | undefined {\n return this.infoMap.get(id);\n }\n}\n","import type { Node } from \"jsonc-parser\";\nimport type {\n ArrayType,\n NamedType,\n NodeType,\n ObjectType,\n OrType,\n PrimitiveTypes,\n RefType,\n TemplateLiteralType,\n} from \"@xlr-lib/xlr\";\nimport {\n makePropertyMap,\n resolveConditional,\n isPrimitiveTypeNode,\n resolveReferenceNode,\n computeEffectiveObject,\n} from \"@xlr-lib/xlr-utils\";\nimport { ValidationSeverity } from \"./types\";\nimport type { ValidationMessage } from \"./types\";\n\nexport interface XLRValidatorConfig {\n /** URL mapping for supplemental documentation */\n urlMapping?: Record<string, string>;\n}\n\nconst MAX_VALID_SHOWN = 20;\n\n/**\n * Validator for XLRs on JSON Nodes\n */\nexport class XLRValidator {\n private config: XLRValidatorConfig;\n private resolveType: (id: string) => NamedType<NodeType> | undefined;\n private regexCache: Map<string, RegExp>;\n\n constructor(\n resolveType: (id: string) => NamedType<NodeType> | undefined,\n config?: XLRValidatorConfig,\n ) {\n this.config = config || {};\n this.resolveType = resolveType;\n this.regexCache = new Map();\n }\n\n /** Main entrypoint for validation */\n public validateType(\n rootNode: Node,\n xlrNode: NodeType,\n ): Array<ValidationMessage> {\n const validationIssues = new Array<ValidationMessage>();\n if (xlrNode.type === \"object\") {\n if (rootNode.type === \"object\") {\n validationIssues.push(...this.validateObject(xlrNode, rootNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an object but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"array\") {\n if (rootNode.type === \"array\") {\n validationIssues.push(...this.validateArray(rootNode, xlrNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an array but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"template\") {\n const error = this.validateTemplate(rootNode, xlrNode);\n if (error) {\n validationIssues.push(error);\n }\n } else if (xlrNode.type === \"or\") {\n const potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }> = [];\n\n for (const potentialType of xlrNode.or) {\n const potentialErrors = this.validateType(rootNode, potentialType);\n\n if (potentialErrors.length === 0) {\n return validationIssues;\n }\n\n potentialTypeErrors.push({\n type: potentialType,\n errors: potentialErrors,\n });\n }\n\n let message: string;\n const expectedTypes = xlrNode.or\n .map((node) =>\n isPrimitiveTypeNode(node)\n ? node.type\n : (node.name ?? node.title ?? node.type ?? \"<unnamed type>\"),\n )\n .join(\" | \");\n\n if (xlrNode.name) {\n message = `Does not match any of the expected types for type: '${xlrNode.name}'`;\n } else if (xlrNode.title) {\n message = `Does not match any of the expected types for property: '${xlrNode.title}'`;\n } else {\n message = `Does not match any of the types: ${expectedTypes}`;\n }\n\n const { infoMessage } = this.generateNestedTypesInfo(\n potentialTypeErrors,\n xlrNode,\n rootNode,\n );\n\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: message.trim(),\n severity: ValidationSeverity.Error,\n });\n\n if (infoMessage) {\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: infoMessage,\n severity: ValidationSeverity.Info,\n });\n }\n } else if (xlrNode.type === \"and\") {\n const effectiveType = {\n ...this.computeIntersectionType(xlrNode.and),\n ...(xlrNode.name ? { name: xlrNode.name } : {}),\n };\n validationIssues.push(...this.validateType(rootNode, effectiveType));\n } else if (xlrNode.type === \"record\") {\n rootNode.children?.forEach((child) => {\n validationIssues.push(\n ...this.validateType(child.children?.[0] as Node, xlrNode.keyType),\n );\n validationIssues.push(\n ...this.validateType(child.children?.[1] as Node, xlrNode.valueType),\n );\n });\n } else if (xlrNode.type === \"ref\") {\n const refType = this.getRefType(xlrNode);\n if (refType === undefined) {\n validationIssues.push({\n type: \"unknown\",\n node: rootNode,\n message: `Type \"${xlrNode.ref}\" is not defined in provided bundles`,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push(\n ...this.validateType(rootNode, refType as NamedType),\n );\n }\n } else if (isPrimitiveTypeNode(xlrNode)) {\n if (!this.validateLiteralType(xlrNode, rootNode)) {\n if (\n (xlrNode.type === \"string\" ||\n xlrNode.type === \"number\" ||\n xlrNode.type === \"boolean\") &&\n xlrNode.const\n ) {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected \"${xlrNode.const}\" but got \"${rootNode.value}\"`,\n expected: xlrNode.const,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${rootNode.type}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n });\n }\n }\n } else if (xlrNode.type === \"conditional\") {\n // Resolve RefNodes in check conditions if needed\n let { right, left } = xlrNode.check;\n\n if (right.type === \"ref\") {\n right = this.getRefType(right);\n }\n\n if (left.type === \"ref\") {\n left = this.getRefType(left);\n }\n\n const resolvedXLRNode = {\n ...xlrNode,\n check: {\n left,\n right,\n },\n };\n\n const resolvedConditional = resolveConditional(resolvedXLRNode);\n if (resolvedConditional === resolvedXLRNode) {\n throw Error(\n `Unable to resolve conditional type at runtime: ${xlrNode.name}`,\n );\n }\n\n validationIssues.push(\n ...this.validateType(rootNode, resolvedConditional),\n );\n } else {\n throw Error(`Unknown type ${xlrNode.type}`);\n }\n\n return validationIssues;\n }\n\n private generateNestedTypesInfo(\n potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }>,\n xlrNode: OrType,\n rootNode: Node,\n ): { nestedTypesList: string; infoMessage?: string } {\n const nestedTypes = new Set<string>();\n\n // TODO: Create a recursive function that returns value or xlrNode info\n // First, try to extract types from potential type errors\n potentialTypeErrors.forEach((typeError) => {\n if (typeError.type.type !== \"template\") {\n typeError.errors.forEach((error) => {\n if (error.type === \"type\" && error.expected) {\n // Split by separate types if union\n String(error.expected)\n .split(\" | \")\n .forEach((val) => nestedTypes.add(val.trim()));\n }\n });\n }\n });\n\n // If no types found from errors, try using type from xlrNode\n if (nestedTypes.size === 0) {\n xlrNode.or.forEach((type) => {\n const typeName =\n type.name ?? type.title ?? type.type ?? \"<unnamed type>\";\n nestedTypes.add(typeName);\n });\n }\n\n const nestedTypesArray = [...nestedTypes];\n\n // Display list of expected types as a union\n let nestedTypesList =\n nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(\" | \") +\n (nestedTypesArray.length > MAX_VALID_SHOWN\n ? ` | +${\n nestedTypesArray.length - MAX_VALID_SHOWN\n } ... ${nestedTypesArray.pop()}`\n : \"\");\n\n // TODO: Be able to pass the validator's config to the SDK\n const docsURL = this.config.urlMapping;\n\n // Support passing in a URL for matching type\n if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {\n nestedTypesList = docsURL[xlrNode.name];\n }\n\n // Support supplemental info message\n let infoMessage;\n\n if (rootNode.value !== undefined) {\n infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;\n } else if (nestedTypesList) {\n infoMessage = `Expected: ${nestedTypesList}`;\n }\n\n return { nestedTypesList, infoMessage };\n }\n\n private validateTemplate(\n node: Node,\n xlrNode: TemplateLiteralType,\n ): ValidationMessage | undefined {\n if (node.type !== \"string\") {\n return {\n type: \"type\",\n node: node.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${typeof node}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n };\n }\n\n const regex = this.getRegex(xlrNode.format);\n const valid = regex.exec(node.value);\n if (!valid) {\n return {\n type: \"value\",\n node: node.parent as Node,\n message: `Does not match expected format: ${xlrNode.format}`,\n expected: xlrNode.format,\n severity: ValidationSeverity.Error,\n };\n }\n }\n\n private validateArray(rootNode: Node, xlrNode: ArrayType) {\n const issues: Array<ValidationMessage> = [];\n rootNode.children?.forEach((child) =>\n issues.push(...this.validateType(child, xlrNode.elementType)),\n );\n return issues;\n }\n\n private validateObject(xlrNode: ObjectType, node: Node) {\n const issues: Array<ValidationMessage> = [];\n const objectProps = makePropertyMap(node);\n\n for (const prop in xlrNode.properties) {\n const expectedType = xlrNode.properties[prop];\n const valueNode = objectProps.get(prop);\n if (expectedType.required && valueNode === undefined) {\n issues.push({\n type: \"missing\",\n node,\n message: `Property \"${prop}\" missing from type \"${xlrNode.name}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n\n if (valueNode) {\n issues.push(\n ...this.validateType(valueNode, expectedType.node as NamedType),\n );\n }\n }\n\n // Check if unknown keys are allowed and if they are - do the violate the constraint\n const extraKeys = Array.from(objectProps.keys()).filter(\n (key) => xlrNode.properties[key] === undefined,\n );\n if (xlrNode.additionalProperties === false && extraKeys.length > 0) {\n issues.push({\n type: \"value\",\n node,\n message: `Unexpected properties on \"${xlrNode.name}\": ${extraKeys.join(\n \", \",\n )}`,\n severity: ValidationSeverity.Error,\n });\n } else {\n issues.push(\n ...extraKeys.flatMap((key) =>\n this.validateType(\n objectProps.get(key) as Node,\n xlrNode.additionalProperties as NodeType,\n ),\n ),\n );\n }\n\n return issues;\n }\n\n private validateLiteralType(expectedType: PrimitiveTypes, literalType: Node) {\n switch (expectedType.type) {\n case \"boolean\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"boolean\";\n case \"number\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"number\";\n case \"string\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"string\";\n case \"null\":\n return literalType.value === null;\n case \"never\":\n return literalType === undefined;\n case \"any\":\n return literalType !== undefined;\n case \"unknown\":\n return literalType !== undefined;\n case \"undefined\":\n return true;\n default:\n return false;\n }\n }\n\n public getRefType(ref: RefType): NodeType {\n let refName = ref.ref;\n if (refName.indexOf(\"<\") > 0) {\n [refName] = refName.split(\"<\");\n }\n\n const actualType = this.resolveType(refName);\n if (!actualType) {\n throw new Error(`Error: can't resolve type reference ${refName}`);\n }\n\n return resolveReferenceNode(ref, actualType);\n }\n\n private getRegex(expString: string): RegExp {\n if (this.regexCache.has(expString)) {\n return this.regexCache.get(expString) as RegExp;\n }\n\n const exp = new RegExp(expString);\n this.regexCache.set(expString, exp);\n return exp;\n }\n\n public computeIntersectionType(types: Array<NodeType>): ObjectType | OrType {\n let firstElement = types[0];\n let effectiveType: ObjectType | OrType;\n\n // Capture the original top-level type name if exists\n const topLevelTypeName = types[0].name;\n\n if (firstElement.type === \"ref\") {\n firstElement = this.getRefType(firstElement);\n }\n\n if (firstElement.type === \"and\") {\n effectiveType = this.computeIntersectionType(firstElement.and);\n } else if (firstElement.type === \"record\") {\n effectiveType = {\n type: \"object\",\n properties: {},\n additionalProperties: firstElement.valueType,\n };\n } else if (firstElement.type !== \"or\" && firstElement.type !== \"object\") {\n throw new Error(\n `Can't compute a union with a non-object type ${firstElement.type} (${firstElement.name})`,\n );\n } else {\n effectiveType = firstElement;\n }\n\n types.slice(1).forEach((type) => {\n let typeToApply = type;\n\n if (typeToApply.type === \"record\") {\n typeToApply = {\n type: \"object\",\n properties: {},\n additionalProperties: typeToApply.valueType,\n };\n }\n\n if (type.type === \"ref\") {\n typeToApply = this.getRefType(type);\n }\n\n if (typeToApply.type === \"and\") {\n typeToApply = this.computeIntersectionType([type, effectiveType]);\n }\n\n if (typeToApply.type === \"object\") {\n if (effectiveType.type === \"object\") {\n effectiveType = computeEffectiveObject(effectiveType, typeToApply);\n } else {\n effectiveType = {\n ...effectiveType,\n or: effectiveType.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n typeToApply,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n }\n } else if (typeToApply.type === \"or\") {\n if (effectiveType.type === \"object\") {\n effectiveType = {\n ...typeToApply,\n or: typeToApply.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n effectiveType,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n } else {\n throw new Error(\"unimplemented operation or x or projection\");\n }\n } else {\n throw new Error(\n `Can't compute a union with a non-object type ${typeToApply.type} (${typeToApply.name})`,\n );\n }\n });\n\n // If the final effective type is an or type and doesn't have a name, use the top-level type name\n if (\n effectiveType.type === \"or\" &&\n !effectiveType.name &&\n topLevelTypeName\n ) {\n effectiveType.name = topLevelTypeName;\n }\n\n return effectiveType;\n }\n}\n","import type { Node } from \"jsonc-parser\";\n\n/** Support Export Formats */\nexport type ExportTypes = \"TypeScript\";\n\nexport interface BaseValidationMessage<ErrorType extends string = string> {\n /** Validation Type */\n type: ErrorType;\n\n /** Error message text */\n message: string;\n\n /** JSONC node that the error originates from */\n node: Node;\n\n /** Level of the message */\n severity: ValidationSeverity;\n}\n\nexport interface TypeValidationError extends BaseValidationMessage<\"type\"> {\n /** Expected types */\n expected?: string[] | string | number | boolean;\n}\n\nexport type MissingValidationError = BaseValidationMessage<\"missing\">;\n\nexport type UnknownValidationError = BaseValidationMessage<\"unknown\">;\n\nexport interface ValueValidationError extends BaseValidationMessage<\"value\"> {\n /** Expected value */\n expected?: string;\n}\n\nexport type UnexpectedValidationError = BaseValidationMessage<\"unexpected\">;\n\nexport type ValidationMessage =\n | TypeValidationError\n | MissingValidationError\n | UnknownValidationError\n | ValueValidationError\n | UnexpectedValidationError;\n\nexport enum ValidationSeverity {\n Error = 1,\n Warning = 2,\n Info = 3,\n Trace = 4,\n}\n","import type {\n NamedType,\n NodeTypeStrings,\n NodeTypeMap,\n TransformFunction,\n NodeType,\n ObjectProperty,\n RefNode,\n} from \"@xlr-lib/xlr\";\nimport { isGenericNamedType } from \"@xlr-lib/xlr-utils\";\n\ntype TypedTransformFunction<T extends NodeTypeStrings = NodeTypeStrings> = (\n input: NodeTypeMap[T],\n) => NodeTypeMap[T];\n\nexport type TransformFunctionMap = {\n [nodeType in NodeTypeStrings]?: Array<TypedTransformFunction<nodeType>>;\n};\n\nconst isMatchingCapability = (\n capability: string,\n capabilitiesToMatch: string | Array<string>,\n): boolean => {\n if (Array.isArray(capabilitiesToMatch)) {\n return capabilitiesToMatch.includes(capability);\n }\n\n return capability === capabilitiesToMatch;\n};\n\nexport function xlrTransformWalker(\n transformMap: TransformFunctionMap,\n): (node: NodeType) => NodeType {\n const walker = (n: NamedType | NodeType): NodeType => {\n let node = { ...n };\n const transformFunctions = transformMap[node.type] as unknown as Array<\n TypedTransformFunction<typeof node.type>\n >;\n\n for (const transformFn of transformFunctions ?? []) {\n node = transformFn(node);\n }\n\n if (node.type === \"object\") {\n const newObjectProperties: Record<string, ObjectProperty> = {};\n\n for (const key in node.properties) {\n const value = node.properties[key];\n newObjectProperties[key] = {\n required: value.required,\n node: walker(value.node),\n };\n }\n\n // need to walk generic tokens\n return {\n ...node,\n properties: { ...newObjectProperties },\n ...(isGenericNamedType(node)\n ? {\n genericTokens: node.genericTokens.map((token) => {\n return {\n ...token,\n constraints: token.constraints\n ? walker(token.constraints)\n : undefined,\n default: token.default ? walker(token.default) : undefined,\n };\n }),\n }\n : {}),\n extends: node.extends ? (walker(node.extends) as RefNode) : undefined,\n additionalProperties: node.additionalProperties\n ? walker(node.additionalProperties)\n : false,\n };\n }\n\n if (node.type === \"array\") {\n return {\n ...node,\n elementType: walker(node.elementType),\n };\n }\n\n if (node.type === \"and\") {\n return {\n ...node,\n and: node.and.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"or\") {\n return {\n ...node,\n or: node.or.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"ref\") {\n return {\n ...node,\n ...(node.genericArguments\n ? {\n genericArguments: node.genericArguments?.map((arg) =>\n walker(arg),\n ),\n }\n : {}),\n };\n }\n\n if (node.type === \"tuple\") {\n return {\n ...node,\n elementTypes: node.elementTypes.map((element) => {\n return {\n name: element.name,\n type: walker(element.type),\n optional: element.optional,\n };\n }),\n additionalItems: node.additionalItems\n ? walker(node.additionalItems)\n : false,\n };\n }\n\n if (node.type === \"function\") {\n return {\n ...node,\n parameters: node.parameters.map((param) => {\n return {\n ...param,\n type: walker(param.type),\n default: param.default ? walker(param.default) : undefined,\n };\n }),\n returnType: node.returnType ? walker(node.returnType) : undefined,\n };\n }\n\n if (node.type === \"record\") {\n return {\n ...node,\n keyType: walker(node.keyType),\n valueType: walker(node.valueType),\n };\n }\n\n if (node.type === \"conditional\") {\n return {\n ...node,\n check: {\n left: walker(node.check.left),\n right: walker(node.check.left),\n },\n value: {\n true: walker(node.value.true),\n false: walker(node.value.false),\n },\n };\n }\n\n return node;\n };\n\n return walker;\n}\n\n/**\n * Helper function for simple transforms\n * Walks an XLR tree looking for the specified node type calls the supplied function when called\n */\nexport function simpleTransformGenerator<\n T extends NodeTypeStrings = NodeTypeStrings,\n>(\n typeToTransform: T,\n capabilityToTransform: string | Array<string>,\n functionToRun: TypedTransformFunction<T>,\n): TransformFunction {\n /** walker for an XLR tree to touch every node */\n return (n: NamedType | NodeType, capability: string) => {\n // Run transform on base node before running on children\n if (isMatchingCapability(capability, capabilityToTransform)) {\n return xlrTransformWalker({ [typeToTransform]: [functionToRun] })(n);\n }\n\n return n;\n };\n}\n"],"mappings":";AAWA;AAAA,EACE,0BAAAA;AAAA,EACA,sBAAAC;AAAA,EACA,wBAAAC;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,SAAS,gBAAgB;AACzB,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,QAAQ;;;ACfR,IAAM,mBAAN,MAA8C;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,YAAY,oBAAI,IAAI;AACzB,SAAK,UAAU,oBAAI,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,IAAI,IAA6C;AAC/C,UAAM,QAAQ,KAAK,QAAQ,IAAI,EAAE;AACjC,WAAO,QAAQ,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,EACrD;AAAA,EAEA,IAAI,MAA2B,QA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AA,cACT,kBAAkB;AAAA,gBAAI,CAAC,MACrB,GAAG,QAAQ;AAAA,kBACT;AAAA,kBACA;AAAA,kBACA,GAAG,QAAQ,iBAAiB,CAAC;AAAA,gBAC/B;AAAA,cACF;AAAA,YACF;AAAA,UACF;AAAA,UACA,GAAG,QAAQ,oBAAoB,WAAW;AAAA,QAC5C;AAAA,QACA,GAAG,WAAW;AAAA,MAChB,CAAC;AAAA,IACH,CAAC;AAED,UAAM,aAAa,QAAQ,UAAU,UAAU;AAC/C,UAAM,WAAW,aAAa,KAAK,IAAI;AACvC,WAAO,GAAG,UAAU;AAAA,EAAK,QAAQ;AAAA,EACnC;AACF;","names":["computeEffectiveObject","resolveConditional","resolveReferenceNode","ValidationSeverity","resolveReferenceNode","computeEffectiveObject","resolveConditional"]}
1
+ {"version":3,"sources":["../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/sdk.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/registry/basic-registry.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/validator.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/types.ts","../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/sdk/src/utils.ts"],"sourcesContent":["/* eslint-disable prettier/prettier */\nimport type {\n Manifest,\n NamedType,\n NodeType,\n ObjectNode,\n ObjectType,\n TransformFunction,\n TSManifest,\n} from \"@xlr-lib/xlr\";\nimport {\n computeEffectiveObject,\n resolveConditional,\n resolveReferenceNode,\n} from \"@xlr-lib/xlr-utils\";\nimport { fillInGenerics } from \"@xlr-lib/xlr-utils\";\nimport type { Node } from \"jsonc-parser\";\nimport fs from \"fs\";\nimport path from \"path\";\n\nimport type { XLRRegistry, Filters } from \"./registry\";\nimport { BasicXLRRegistry } from \"./registry\";\nimport { XLRValidator } from \"./validator\";\nimport { TransformFunctionMap, xlrTransformWalker } from \"./utils\";\n\nexport interface GetTypeOptions {\n /** Resolves `extends` fields in objects */\n getRawType?: boolean;\n /** Perform optimizations to resolve all references, type intersections, and conditionals */\n optimize?: boolean;\n}\n\n/**\n * Abstraction for interfacing with XLRs making it more approachable to use without understanding the inner workings of the types and how they are packaged\n */\nexport class XLRSDK {\n private registry: XLRRegistry;\n private validator: XLRValidator;\n private computedNodeCache: Map<string, NodeType>;\n private externalTransformFunctions: Map<string, TransformFunction>;\n\n constructor(customRegistry?: XLRRegistry) {\n this.registry = customRegistry ?? new BasicXLRRegistry();\n this.validator = new XLRValidator(this.getType.bind(this));\n this.computedNodeCache = new Map();\n this.externalTransformFunctions = new Map();\n }\n\n /**\n * Loads definitions from a path on the filesystem\n *\n * @param inputPath - path to the directory to load (above the xlr folder)\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public loadDefinitionsFromDisk(\n inputPath: string,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n const manifest = JSON.parse(\n fs.readFileSync(path.join(inputPath, \"xlr\", \"manifest.json\")).toString(),\n (key: unknown, value: unknown) => {\n // Custom parser because JSON objects -> JS Objects, not maps\n if (typeof value === \"object\" && value !== null) {\n if (key === \"capabilities\") {\n return new Map(Object.entries(value));\n }\n }\n\n return value;\n }\n ) as Manifest;\n\n manifest.capabilities?.forEach((capabilityList, capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n capabilityList.forEach((extensionName) => {\n if (!filters?.typeFilter || !extensionName.match(filters?.typeFilter)) {\n const cType: NamedType<NodeType> = JSON.parse(\n fs\n .readFileSync(\n path.join(inputPath, \"xlr\", `${extensionName}.json`)\n )\n .toString()\n );\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n cType\n ) ?? cType;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Load definitions from a js/ts file in memory\n *\n * @param manifest - The imported XLR manifest module\n * @param filters - Any filters to apply when loading the types (a positive match will omit)\n * @param transforms - any transforms to apply to the types being loaded\n */\n public async loadDefinitionsFromModule(\n manifest: TSManifest,\n filters?: Omit<Filters, \"pluginFilter\">,\n transforms?: Array<TransformFunction>\n ) {\n this.computedNodeCache.clear();\n\n const transformsToRun = [\n ...this.externalTransformFunctions.values(),\n ...(transforms ?? []),\n ];\n\n Object.keys(manifest.capabilities)?.forEach((capabilityName) => {\n if (\n filters?.capabilityFilter &&\n capabilityName.match(filters?.capabilityFilter)\n )\n return;\n const capabilityList = manifest.capabilities[capabilityName];\n capabilityList.forEach((extension) => {\n if (\n !filters?.typeFilter ||\n !extension.name.match(filters?.typeFilter)\n ) {\n const effectiveType =\n transformsToRun?.reduce(\n (typeAccumulator: NamedType<NodeType>, transformFn) =>\n transformFn(\n typeAccumulator,\n capabilityName\n ) as NamedType<NodeType>,\n extension\n ) ?? extension;\n\n this.registry.add(effectiveType, manifest.pluginName, capabilityName);\n }\n });\n });\n }\n\n /**\n * Statically load transform function that should be applied to every XLR bundle that is imported\n */\n public addTransformFunction(name: string, fn: TransformFunction): void {\n this.externalTransformFunctions.set(name, fn);\n }\n\n /**\n * Remove any transform function loaded via the `addTransformFunction` method by name\n */\n public removeTransformFunction(name: string): void {\n this.externalTransformFunctions.delete(name);\n }\n\n /**\n * Returns a Type that has been previously loaded\n *\n * @param id - Type to retrieve\n * @param options - `GetTypeOptions`\n * @returns `NamedType<NodeType>` | `undefined`\n */\n public getType(\n id: string,\n options?: GetTypeOptions\n ): NamedType<NodeType> | undefined {\n let type = this.registry.get(id);\n if (options?.getRawType === true || !type) {\n return type;\n }\n\n if (this.computedNodeCache.has(id)) {\n return JSON.parse(JSON.stringify(this.computedNodeCache.get(id))) as\n | NamedType<NodeType>\n | undefined;\n }\n\n type = this.resolveType(type, options?.optimize)\n\n this.computedNodeCache.set(id, type);\n\n return type;\n }\n\n /**\n * Returns if a Type with `id` has been loaded into the DSK\n *\n * @param id - Type to retrieve\n * @returns `boolean`\n */\n public hasType(id: string) {\n return this.registry.has(id);\n }\n\n /**\n * Lists types that have been loaded into the SDK\n *\n * @param filters - Any filters to apply to the types returned (a positive match will omit)\n * @returns `Array<NamedTypes>`\n */\n public listTypes(filters?: Filters) {\n return this.registry.list(filters);\n }\n\n /**\n * Returns meta information around a registered type\n *\n * @param id - Name of Type to retrieve\n * @returns `TypeMetaData` | `undefined`\n */\n public getTypeInfo(id: string) {\n return this.registry.info(id);\n }\n\n /**\n * Validates if a JSONC Node follows the XLR Type registered under the `typeName` specified\n *\n * @param typeName - Registered XLR Type to use for validation\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByName(typeName: string, rootNode: Node) {\n const xlr = this.getType(typeName);\n if (!xlr) {\n throw new Error(\n `Type ${typeName} does not exist in registry, can't validate`\n );\n }\n\n return this.validator.validateType(rootNode, xlr);\n }\n\n /**\n * Validates if a JSONC Node follows the supplied XLR Type\n *\n * @param type - Type to validate against\n * @param rootNode - Node to validate\n * @returns `Array<ValidationErrors>`\n */\n public validateByType(type: NodeType, rootNode: Node) {\n return this.validator.validateType(rootNode, type);\n }\n\n /**\n * Transforms a generated XLR node into its final representation by resolving all `extends` properties.\n * If `optimize` is set to true the following operations are also performed:\n * - Solving any conditional types\n * - Computing the effective types of any union elements\n * - Resolving any ref nodes\n * - filing in any remaining generics with their default value\n */\n private resolveType(type: NamedType, optimize = true): NamedType {\n const resolvedObject = fillInGenerics(type, new Map(), true);\n\n let transformMap: TransformFunctionMap = {\n object: [(objectNode: ObjectType) => {\n if (objectNode.extends) {\n const refName = objectNode.extends.ref.split(\"<\")[0];\n let extendedType = this.getType(refName, {getRawType: true});\n if (!extendedType) {\n throw new Error(\n `Error resolving ${objectNode.name}: can't find extended type ${refName}`\n );\n }\n\n extendedType = resolveReferenceNode(\n objectNode.extends,\n extendedType as NamedType<ObjectType>\n ) as NamedType;\n if (extendedType.type === \"object\") {\n return {\n ...computeEffectiveObject(\n extendedType as ObjectType,\n objectNode as ObjectType,\n false\n ),\n name: objectNode.name,\n description: objectNode.description,\n };\n }\n\n if( extendedType.type === \"or\"){\n return {\n ...this.validator.computeIntersectionType([\n objectNode,\n extendedType\n ]\n ),\n name: objectNode.name,\n description: objectNode.description,\n } as any;\n }\n\n // if the merge isn't straightforward, defer until validation time for now\n return {\n name: objectNode.name,\n type: \"and\",\n and: [\n {\n ...objectNode,\n extends: undefined,\n },\n extendedType,\n ],\n } as unknown as ObjectNode;\n }\n\n return objectNode;\n }],\n } \n\n if(optimize){\n transformMap = {\n ...transformMap,\n conditional: [(node) => {\n return resolveConditional(node) as any\n }],\n and: [(node) => {\n return {\n ...this.validator.computeIntersectionType(node.and),\n ...(node.name ? { name: node.name } : {}),\n } as any\n }],\n ref: [(refNode) => {\n return this.validator.getRefType(refNode) as any\n }]\n }\n }\n\n return xlrTransformWalker(transformMap)(resolvedObject) as NamedType\n }\n\n}\n","import type { NamedType, NodeType } from \"@xlr-lib/xlr\";\nimport type { XLRRegistry, Filters, TypeMetadata } from \"./types\";\n\n/**\n * Basic example of a XLRs Registry\n */\nexport class BasicXLRRegistry implements XLRRegistry {\n private typeMap: Map<string, NamedType<NodeType>>;\n private pluginMap: Map<string, Map<string, Array<string>>>;\n private infoMap: Map<string, TypeMetadata>;\n\n constructor() {\n this.typeMap = new Map();\n this.pluginMap = new Map();\n this.infoMap = new Map();\n }\n\n /** Returns a copy of the XLR to guard against unexpected type modification */\n get(id: string): NamedType<NodeType> | undefined {\n const value = this.typeMap.get(id);\n return value ? JSON.parse(JSON.stringify(value)) : undefined;\n }\n\n add(type: NamedType<NodeType>, plugin: string, capability: string): void {\n this.typeMap.set(type.name, type);\n this.infoMap.set(type.name, { plugin, capability });\n\n if (!this.pluginMap.has(plugin)) {\n this.pluginMap.set(plugin, new Map());\n }\n\n const pluginsCapabilities = this.pluginMap.get(plugin) as Map<\n string,\n Array<string>\n >;\n\n if (!pluginsCapabilities.has(capability)) {\n pluginsCapabilities.set(capability, []);\n }\n\n const providedCapabilities = pluginsCapabilities.get(\n capability,\n ) as string[];\n providedCapabilities.push(type.name);\n }\n\n has(id: string): boolean {\n return this.typeMap.has(id);\n }\n\n list(filterArgs?: Filters): NamedType<NodeType>[] {\n const validTypes: Array<string> = [];\n\n this.pluginMap.forEach((manifest, pluginName) => {\n if (\n !filterArgs?.pluginFilter ||\n !pluginName.match(filterArgs.pluginFilter)\n ) {\n manifest.forEach((types, capabilityName) => {\n if (\n !filterArgs?.capabilityFilter ||\n !capabilityName.match(filterArgs.capabilityFilter)\n ) {\n types.forEach((type) => {\n if (\n !filterArgs?.typeFilter ||\n !type.match(filterArgs.typeFilter)\n ) {\n validTypes.push(type);\n }\n });\n }\n });\n }\n });\n return validTypes.map((type) => this.get(type) as NamedType);\n }\n\n info(id: string): TypeMetadata | undefined {\n return this.infoMap.get(id);\n }\n}\n","import type { Node } from \"jsonc-parser\";\nimport type {\n ArrayType,\n NamedType,\n NodeType,\n ObjectType,\n OrType,\n PrimitiveTypes,\n RefType,\n TemplateLiteralType,\n} from \"@xlr-lib/xlr\";\nimport {\n makePropertyMap,\n resolveConditional,\n isPrimitiveTypeNode,\n resolveReferenceNode,\n computeEffectiveObject,\n} from \"@xlr-lib/xlr-utils\";\nimport { ValidationSeverity } from \"./types\";\nimport type { ValidationMessage } from \"./types\";\n\nexport interface XLRValidatorConfig {\n /** URL mapping for supplemental documentation */\n urlMapping?: Record<string, string>;\n}\n\nconst MAX_VALID_SHOWN = 20;\n\n/**\n * Validator for XLRs on JSON Nodes\n */\nexport class XLRValidator {\n private config: XLRValidatorConfig;\n private resolveType: (id: string) => NamedType<NodeType> | undefined;\n private regexCache: Map<string, RegExp>;\n\n constructor(\n resolveType: (id: string) => NamedType<NodeType> | undefined,\n config?: XLRValidatorConfig,\n ) {\n this.config = config || {};\n this.resolveType = resolveType;\n this.regexCache = new Map();\n }\n\n /** Main entrypoint for validation */\n public validateType(\n rootNode: Node,\n xlrNode: NodeType,\n ): Array<ValidationMessage> {\n const validationIssues = new Array<ValidationMessage>();\n if (xlrNode.type === \"object\") {\n if (rootNode.type === \"object\") {\n validationIssues.push(...this.validateObject(xlrNode, rootNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an object but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"array\") {\n if (rootNode.type === \"array\") {\n validationIssues.push(...this.validateArray(rootNode, xlrNode));\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode,\n message: `Expected an array but got an \"${rootNode.type}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n } else if (xlrNode.type === \"template\") {\n const error = this.validateTemplate(rootNode, xlrNode);\n if (error) {\n validationIssues.push(error);\n }\n } else if (xlrNode.type === \"or\") {\n const potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }> = [];\n\n for (const potentialType of xlrNode.or) {\n const potentialErrors = this.validateType(rootNode, potentialType);\n\n if (potentialErrors.length === 0) {\n return validationIssues;\n }\n\n potentialTypeErrors.push({\n type: potentialType,\n errors: potentialErrors,\n });\n }\n\n let message: string;\n const expectedTypes = xlrNode.or\n .map((node) =>\n isPrimitiveTypeNode(node)\n ? node.type\n : (node.name ?? node.title ?? node.type ?? \"<unnamed type>\"),\n )\n .join(\" | \");\n\n if (xlrNode.name) {\n message = `Does not match any of the expected types for type: '${xlrNode.name}'`;\n } else if (xlrNode.title) {\n message = `Does not match any of the expected types for property: '${xlrNode.title}'`;\n } else {\n message = `Does not match any of the types: ${expectedTypes}`;\n }\n\n const { infoMessage } = this.generateNestedTypesInfo(\n potentialTypeErrors,\n xlrNode,\n rootNode,\n );\n\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: message.trim(),\n severity: ValidationSeverity.Error,\n });\n\n if (infoMessage) {\n validationIssues.push({\n type: \"value\",\n node: rootNode,\n message: infoMessage,\n severity: ValidationSeverity.Info,\n });\n }\n } else if (xlrNode.type === \"and\") {\n const effectiveType = {\n ...this.computeIntersectionType(xlrNode.and),\n ...(xlrNode.name ? { name: xlrNode.name } : {}),\n };\n validationIssues.push(...this.validateType(rootNode, effectiveType));\n } else if (xlrNode.type === \"record\") {\n rootNode.children?.forEach((child) => {\n validationIssues.push(\n ...this.validateType(child.children?.[0] as Node, xlrNode.keyType),\n );\n validationIssues.push(\n ...this.validateType(child.children?.[1] as Node, xlrNode.valueType),\n );\n });\n } else if (xlrNode.type === \"ref\") {\n const refType = this.getRefType(xlrNode);\n if (refType === undefined) {\n validationIssues.push({\n type: \"unknown\",\n node: rootNode,\n message: `Type \"${xlrNode.ref}\" is not defined in provided bundles`,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push(\n ...this.validateType(rootNode, refType as NamedType),\n );\n }\n } else if (isPrimitiveTypeNode(xlrNode)) {\n if (!this.validateLiteralType(xlrNode, rootNode)) {\n if (\n (xlrNode.type === \"string\" ||\n xlrNode.type === \"number\" ||\n xlrNode.type === \"boolean\") &&\n xlrNode.const\n ) {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected \"${xlrNode.const}\" but got \"${rootNode.value}\"`,\n expected: xlrNode.const,\n severity: ValidationSeverity.Error,\n });\n } else {\n validationIssues.push({\n type: \"type\",\n node: rootNode.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${rootNode.type}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n });\n }\n }\n } else if (xlrNode.type === \"conditional\") {\n // Resolve RefNodes in check conditions if needed\n let { right, left } = xlrNode.check;\n\n if (right.type === \"ref\") {\n right = this.getRefType(right);\n }\n\n if (left.type === \"ref\") {\n left = this.getRefType(left);\n }\n\n const resolvedXLRNode = {\n ...xlrNode,\n check: {\n left,\n right,\n },\n };\n\n const resolvedConditional = resolveConditional(resolvedXLRNode);\n if (resolvedConditional === resolvedXLRNode) {\n throw Error(\n `Unable to resolve conditional type at runtime: ${xlrNode.name}`,\n );\n }\n\n validationIssues.push(\n ...this.validateType(rootNode, resolvedConditional),\n );\n } else {\n throw Error(`Unknown type ${xlrNode.type}`);\n }\n\n return validationIssues;\n }\n\n private generateNestedTypesInfo(\n potentialTypeErrors: Array<{\n type: NodeType;\n errors: Array<ValidationMessage>;\n }>,\n xlrNode: OrType,\n rootNode: Node,\n ): { nestedTypesList: string; infoMessage?: string } {\n const nestedTypes = new Set<string>();\n\n // TODO: Create a recursive function that returns value or xlrNode info\n // First, try to extract types from potential type errors\n potentialTypeErrors.forEach((typeError) => {\n if (typeError.type.type !== \"template\") {\n typeError.errors.forEach((error) => {\n if (error.type === \"type\" && error.expected) {\n // Split by separate types if union\n String(error.expected)\n .split(\" | \")\n .forEach((val) => nestedTypes.add(val.trim()));\n }\n });\n }\n });\n\n // If no types found from errors, try using type from xlrNode\n if (nestedTypes.size === 0) {\n xlrNode.or.forEach((type) => {\n const typeName =\n type.name ?? type.title ?? type.type ?? \"<unnamed type>\";\n nestedTypes.add(typeName);\n });\n }\n\n const nestedTypesArray = [...nestedTypes];\n\n // Display list of expected types as a union\n let nestedTypesList =\n nestedTypesArray.slice(0, MAX_VALID_SHOWN).join(\" | \") +\n (nestedTypesArray.length > MAX_VALID_SHOWN\n ? ` | +${\n nestedTypesArray.length - MAX_VALID_SHOWN\n } ... ${nestedTypesArray.pop()}`\n : \"\");\n\n // TODO: Be able to pass the validator's config to the SDK\n const docsURL = this.config.urlMapping;\n\n // Support passing in a URL for matching type\n if (docsURL && xlrNode.name && docsURL[xlrNode.name]) {\n nestedTypesList = docsURL[xlrNode.name];\n }\n\n // Support supplemental info message\n let infoMessage;\n\n if (rootNode.value !== undefined) {\n infoMessage = `Got: ${rootNode.value} and expected: ${nestedTypesList}`;\n } else if (nestedTypesList) {\n infoMessage = `Expected: ${nestedTypesList}`;\n }\n\n return { nestedTypesList, infoMessage };\n }\n\n private validateTemplate(\n node: Node,\n xlrNode: TemplateLiteralType,\n ): ValidationMessage | undefined {\n if (node.type !== \"string\") {\n return {\n type: \"type\",\n node: node.parent as Node,\n message: `Expected type \"${xlrNode.type}\" but got \"${typeof node}\"`,\n expected: xlrNode.type,\n severity: ValidationSeverity.Error,\n };\n }\n\n const regex = this.getRegex(xlrNode.format);\n const valid = regex.exec(node.value);\n if (!valid) {\n return {\n type: \"value\",\n node: node.parent as Node,\n message: `Does not match expected format: ${xlrNode.format}`,\n expected: xlrNode.format,\n severity: ValidationSeverity.Error,\n };\n }\n }\n\n private validateArray(rootNode: Node, xlrNode: ArrayType) {\n const issues: Array<ValidationMessage> = [];\n rootNode.children?.forEach((child) =>\n issues.push(...this.validateType(child, xlrNode.elementType)),\n );\n return issues;\n }\n\n private validateObject(xlrNode: ObjectType, node: Node) {\n const issues: Array<ValidationMessage> = [];\n const objectProps = makePropertyMap(node);\n\n for (const prop in xlrNode.properties) {\n const expectedType = xlrNode.properties[prop];\n const valueNode = objectProps.get(prop);\n if (expectedType.required && valueNode === undefined) {\n issues.push({\n type: \"missing\",\n node,\n message: `Property \"${prop}\" missing from type \"${xlrNode.name}\"`,\n severity: ValidationSeverity.Error,\n });\n }\n\n if (valueNode) {\n issues.push(\n ...this.validateType(valueNode, expectedType.node as NamedType),\n );\n }\n }\n\n // Check if unknown keys are allowed and if they are - do the violate the constraint\n const extraKeys = Array.from(objectProps.keys()).filter(\n (key) => xlrNode.properties[key] === undefined,\n );\n if (xlrNode.additionalProperties === false && extraKeys.length > 0) {\n issues.push({\n type: \"value\",\n node,\n message: `Unexpected properties on \"${xlrNode.name}\": ${extraKeys.join(\n \", \",\n )}`,\n severity: ValidationSeverity.Error,\n });\n } else {\n issues.push(\n ...extraKeys.flatMap((key) =>\n this.validateType(\n objectProps.get(key) as Node,\n xlrNode.additionalProperties as NodeType,\n ),\n ),\n );\n }\n\n return issues;\n }\n\n private validateLiteralType(expectedType: PrimitiveTypes, literalType: Node) {\n switch (expectedType.type) {\n case \"boolean\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"boolean\";\n case \"number\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"number\";\n case \"string\":\n if (expectedType.const) {\n return expectedType.const === literalType.value;\n }\n\n return typeof literalType.value === \"string\";\n case \"null\":\n return literalType.value === null;\n case \"never\":\n return literalType === undefined;\n case \"any\":\n return literalType !== undefined;\n case \"unknown\":\n return literalType !== undefined;\n case \"undefined\":\n return true;\n default:\n return false;\n }\n }\n\n public getRefType(ref: RefType): NodeType {\n let refName = ref.ref;\n if (refName.indexOf(\"<\") > 0) {\n [refName] = refName.split(\"<\");\n }\n\n const actualType = this.resolveType(refName);\n if (!actualType) {\n throw new Error(`Error: can't resolve type reference ${refName}`);\n }\n\n return resolveReferenceNode(ref, actualType);\n }\n\n private getRegex(expString: string): RegExp {\n if (this.regexCache.has(expString)) {\n return this.regexCache.get(expString) as RegExp;\n }\n\n const exp = new RegExp(expString);\n this.regexCache.set(expString, exp);\n return exp;\n }\n\n public computeIntersectionType(types: Array<NodeType>): ObjectType | OrType {\n let firstElement = types[0];\n let effectiveType: ObjectType | OrType;\n\n // Capture the original top-level type name if exists\n const topLevelTypeName = types[0].name;\n\n if (firstElement.type === \"ref\") {\n firstElement = this.getRefType(firstElement);\n }\n\n if (firstElement.type === \"and\") {\n effectiveType = this.computeIntersectionType(firstElement.and);\n } else if (firstElement.type === \"record\") {\n effectiveType = {\n type: \"object\",\n properties: {},\n additionalProperties: firstElement.valueType,\n };\n } else if (firstElement.type !== \"or\" && firstElement.type !== \"object\") {\n throw new Error(\n `Can't compute a union with a non-object type ${firstElement.type} (${firstElement.name})`,\n );\n } else {\n effectiveType = firstElement;\n }\n\n types.slice(1).forEach((type) => {\n let typeToApply = type;\n\n if (typeToApply.type === \"record\") {\n typeToApply = {\n type: \"object\",\n properties: {},\n additionalProperties: typeToApply.valueType,\n };\n }\n\n if (type.type === \"ref\") {\n typeToApply = this.getRefType(type);\n }\n\n if (typeToApply.type === \"and\") {\n typeToApply = this.computeIntersectionType([type, effectiveType]);\n }\n\n if (typeToApply.type === \"object\") {\n if (effectiveType.type === \"object\") {\n effectiveType = computeEffectiveObject(effectiveType, typeToApply);\n } else {\n effectiveType = {\n ...effectiveType,\n or: effectiveType.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n typeToApply,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n }\n } else if (typeToApply.type === \"or\") {\n if (effectiveType.type === \"object\") {\n effectiveType = {\n ...typeToApply,\n or: typeToApply.or.map((y) => {\n const intersectedType = this.computeIntersectionType([\n y,\n effectiveType,\n ]);\n\n // If the intersected type doesn't have a name, use the top-level type name\n if (!intersectedType.name && topLevelTypeName) {\n intersectedType.name = topLevelTypeName;\n }\n\n return intersectedType;\n }),\n };\n } else {\n throw new Error(\"unimplemented operation or x or projection\");\n }\n } else {\n throw new Error(\n `Can't compute a union with a non-object type ${typeToApply.type} (${typeToApply.name})`,\n );\n }\n });\n\n // If the final effective type is an or type and doesn't have a name, use the top-level type name\n if (\n effectiveType.type === \"or\" &&\n !effectiveType.name &&\n topLevelTypeName\n ) {\n effectiveType.name = topLevelTypeName;\n }\n\n return effectiveType;\n }\n}\n","import type { Node } from \"jsonc-parser\";\n\nexport interface BaseValidationMessage<ErrorType extends string = string> {\n /** Validation Type */\n type: ErrorType;\n\n /** Error message text */\n message: string;\n\n /** JSONC node that the error originates from */\n node: Node;\n\n /** Level of the message */\n severity: ValidationSeverity;\n}\n\nexport interface TypeValidationError extends BaseValidationMessage<\"type\"> {\n /** Expected types */\n expected?: string[] | string | number | boolean;\n}\n\nexport type MissingValidationError = BaseValidationMessage<\"missing\">;\n\nexport type UnknownValidationError = BaseValidationMessage<\"unknown\">;\n\nexport interface ValueValidationError extends BaseValidationMessage<\"value\"> {\n /** Expected value */\n expected?: string;\n}\n\nexport type UnexpectedValidationError = BaseValidationMessage<\"unexpected\">;\n\nexport type ValidationMessage =\n | TypeValidationError\n | MissingValidationError\n | UnknownValidationError\n | ValueValidationError\n | UnexpectedValidationError;\n\nexport enum ValidationSeverity {\n Error = 1,\n Warning = 2,\n Info = 3,\n Trace = 4,\n}\n","import type {\n NamedType,\n NodeTypeStrings,\n NodeTypeMap,\n TransformFunction,\n NodeType,\n ObjectProperty,\n RefNode,\n} from \"@xlr-lib/xlr\";\nimport { isGenericNamedType } from \"@xlr-lib/xlr-utils\";\n\ntype TypedTransformFunction<T extends NodeTypeStrings = NodeTypeStrings> = (\n input: NodeTypeMap[T],\n) => NodeTypeMap[T];\n\nexport type TransformFunctionMap = {\n [nodeType in NodeTypeStrings]?: Array<TypedTransformFunction<nodeType>>;\n};\n\nconst isMatchingCapability = (\n capability: string,\n capabilitiesToMatch: string | Array<string>,\n): boolean => {\n if (Array.isArray(capabilitiesToMatch)) {\n return capabilitiesToMatch.includes(capability);\n }\n\n return capability === capabilitiesToMatch;\n};\n\nexport function xlrTransformWalker(\n transformMap: TransformFunctionMap,\n): (node: NodeType) => NodeType {\n const walker = (n: NamedType | NodeType): NodeType => {\n let node = { ...n };\n const transformFunctions = transformMap[node.type] as unknown as Array<\n TypedTransformFunction<typeof node.type>\n >;\n\n for (const transformFn of transformFunctions ?? []) {\n node = transformFn(node);\n }\n\n if (node.type === \"object\") {\n const newObjectProperties: Record<string, ObjectProperty> = {};\n\n for (const key in node.properties) {\n const value = node.properties[key];\n newObjectProperties[key] = {\n required: value.required,\n node: walker(value.node),\n };\n }\n\n // need to walk generic tokens\n return {\n ...node,\n properties: { ...newObjectProperties },\n ...(isGenericNamedType(node)\n ? {\n genericTokens: node.genericTokens.map((token) => {\n return {\n ...token,\n constraints: token.constraints\n ? walker(token.constraints)\n : undefined,\n default: token.default ? walker(token.default) : undefined,\n };\n }),\n }\n : {}),\n extends: node.extends ? (walker(node.extends) as RefNode) : undefined,\n additionalProperties: node.additionalProperties\n ? walker(node.additionalProperties)\n : false,\n };\n }\n\n if (node.type === \"array\") {\n return {\n ...node,\n elementType: walker(node.elementType),\n };\n }\n\n if (node.type === \"and\") {\n return {\n ...node,\n and: node.and.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"or\") {\n return {\n ...node,\n or: node.or.map((element) => walker(element)),\n };\n }\n\n if (node.type === \"ref\") {\n return {\n ...node,\n ...(node.genericArguments\n ? {\n genericArguments: node.genericArguments?.map((arg) =>\n walker(arg),\n ),\n }\n : {}),\n };\n }\n\n if (node.type === \"tuple\") {\n return {\n ...node,\n elementTypes: node.elementTypes.map((element) => {\n return {\n name: element.name,\n type: walker(element.type),\n optional: element.optional,\n };\n }),\n additionalItems: node.additionalItems\n ? walker(node.additionalItems)\n : false,\n };\n }\n\n if (node.type === \"function\") {\n return {\n ...node,\n parameters: node.parameters.map((param) => {\n return {\n ...param,\n type: walker(param.type),\n default: param.default ? walker(param.default) : undefined,\n };\n }),\n returnType: node.returnType ? walker(node.returnType) : undefined,\n };\n }\n\n if (node.type === \"record\") {\n return {\n ...node,\n keyType: walker(node.keyType),\n valueType: walker(node.valueType),\n };\n }\n\n if (node.type === \"conditional\") {\n return {\n ...node,\n check: {\n left: walker(node.check.left),\n right: walker(node.check.left),\n },\n value: {\n true: walker(node.value.true),\n false: walker(node.value.false),\n },\n };\n }\n\n return node;\n };\n\n return walker;\n}\n\n/**\n * Helper function for simple transforms\n * Walks an XLR tree looking for the specified node type calls the supplied function when called\n */\nexport function simpleTransformGenerator<\n T extends NodeTypeStrings = NodeTypeStrings,\n>(\n typeToTransform: T,\n capabilityToTransform: string | Array<string>,\n functionToRun: TypedTransformFunction<T>,\n): TransformFunction {\n /** walker for an XLR tree to touch every node */\n return (n: NamedType | NodeType, capability: string) => {\n // Run transform on base node before running on children\n if (isMatchingCapability(capability, capabilityToTransform)) {\n return xlrTransformWalker({ [typeToTransform]: [functionToRun] })(n);\n }\n\n return n;\n };\n}\n"],"mappings":";AAUA;AAAA,EACE,0BAAAA;AAAA,EACA,sBAAAC;AAAA,EACA,wBAAAC;AAAA,OACK;AACP,SAAS,sBAAsB;AAE/B,OAAO,QAAQ;AACf,OAAO,UAAU;;;ACZV,IAAM,mBAAN,MAA8C;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EAER,cAAc;AACZ,SAAK,UAAU,oBAAI,IAAI;AACvB,SAAK,YAAY,oBAAI,IAAI;AACzB,SAAK,UAAU,oBAAI,IAAI;AAAA,EACzB;AAAA;AAAA,EAGA,IAAI,IAA6C;AAC/C,UAAM,QAAQ,KAAK,QAAQ,IAAI,EAAE;AACjC,WAAO,QAAQ,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,EACrD;AAAA,EAEA,IAAI,MAA2B,QAAgB,YAA0B;AACvE,SAAK,QAAQ,IAAI,KAAK,MAAM,IAAI;AAChC,SAAK,QAAQ,IAAI,KAAK,MAAM,EAAE,QAAQ,WAAW,CAAC;AAElD,QAAI,CAAC,KAAK,UAAU,IAAI,MAAM,GAAG;AAC/B,WAAK,UAAU,IAAI,QAAQ,oBAAI,IAAI,CAAC;AAAA,IACtC;AAEA,UAAM,sBAAsB,KAAK,UAAU,IAAI,MAAM;AAKrD,QAAI,CAAC,oBAAoB,IAAI,UAAU,GAAG;AACxC,0BAAoB,IAAI,YAAY,CAAC,CAAC;AAAA,IACxC;AAEA,UAAM,uBAAuB,oBAAoB;AAAA,MAC/C;AAAA,IACF;AACA,yBAAqB,KAAK,KAAK,IAAI;AAAA,EACrC;AAAA,EAEA,IAAI,IAAqB;AACvB,WAAO,KAAK,QAAQ,IAAI,EAAE;AAAA,EAC5B;AAAA,EAEA,KAAK,YAA6C;AAChD,UAAM,aAA4B,CAAC;AAEnC,SAAK,UAAU,QAAQ,CAAC,UAAU,eA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,KAAK,OAAO,EAAE,MAAM,KAAK,KAAK,IAAI,CAAC;AAAA,UACzC;AAAA,QACF,CAAC;AAAA,QACD,KAAK,CAAC,CAAC,YAAY;AACjB,iBAAO,KAAK,UAAU,WAAW,OAAO;AAAA,QAC1C,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO,mBAAmB,YAAY,EAAE,cAAc;AAAA,EACxD;AAEF;","names":["computeEffectiveObject","resolveConditional","resolveReferenceNode","ValidationSeverity","resolveReferenceNode","computeEffectiveObject","resolveConditional"]}
package/package.json CHANGED
@@ -6,12 +6,11 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@xlr-lib/xlr-sdk",
9
- "version": "0.1.1-next.3",
9
+ "version": "0.1.1-next.5",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@xlr-lib/xlr": "0.1.1-next.3",
13
- "@xlr-lib/xlr-utils": "0.1.1-next.3",
14
- "@xlr-lib/xlr-converters": "0.1.1-next.3",
12
+ "@xlr-lib/xlr": "0.1.1-next.5",
13
+ "@xlr-lib/xlr-utils": "0.1.1-next.5",
15
14
  "@types/fs-extra": "^9.0.13",
16
15
  "@types/node": "^18.18.0",
17
16
  "fs-extra": "^10.0.0",
@@ -32,7 +31,5 @@
32
31
  "default": "./dist/cjs/index.cjs"
33
32
  }
34
33
  },
35
- "peerDependencies": {
36
- "typescript": "5.5.4"
37
- }
34
+ "peerDependencies": {}
38
35
  }
@@ -1,10 +1,5 @@
1
1
  import { test, expect, describe } from "vitest";
2
- import type {
3
- NamedType,
4
- TransformFunction,
5
- OrType,
6
- ObjectType,
7
- } from "@xlr-lib/xlr";
2
+ import type { NamedType, OrType, ObjectType } from "@xlr-lib/xlr";
8
3
  import { parseTree } from "jsonc-parser";
9
4
  import { Types, ReferenceAssetsWebPluginManifest } from "@xlr-lib/static-xlrs";
10
5
  import type { Filters } from "../registry";
@@ -160,85 +155,6 @@ describe("Validation", () => {
160
155
  });
161
156
  });
162
157
 
163
- describe("Export Test", () => {
164
- test("Exports Typescript types", () => {
165
- const importMap = new Map([
166
- [
167
- "@player-ui/types",
168
- ["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
169
- ],
170
- ]);
171
-
172
- const sdk = new XLRSDK();
173
- sdk.loadDefinitionsFromModule(Types);
174
- sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
175
- const results = sdk.exportRegistry("TypeScript", importMap);
176
- expect(results[0][0]).toBe("out.d.ts");
177
- expect(results[0][1]).toMatchSnapshot();
178
- });
179
-
180
- test("Exports Typescript Types With Filters", () => {
181
- const importMap = new Map([
182
- [
183
- "@player-ui/types",
184
- ["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
185
- ],
186
- ]);
187
-
188
- const sdk = new XLRSDK();
189
- sdk.loadDefinitionsFromModule(Types);
190
- sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
191
- const results = sdk.exportRegistry("TypeScript", importMap, {
192
- typeFilter: "Transformed",
193
- pluginFilter: "Types",
194
- });
195
- expect(results[0][0]).toBe("out.d.ts");
196
- expect(results[0][1]).toMatchSnapshot();
197
- });
198
-
199
- test("Exports Typescript Types With Transforms", () => {
200
- const importMap = new Map([
201
- [
202
- "@player-ui/types",
203
- ["Expression", "Asset", "Binding", "AssetWrapper", "Schema.DataType"],
204
- ],
205
- ]);
206
-
207
- /**
208
- *
209
- */
210
- const transformFunction: TransformFunction = (input, capability) => {
211
- if (capability === "Assets") {
212
- const ret = { ...input };
213
- if (ret.type === "object") {
214
- ret.properties.transformed = {
215
- required: false,
216
- node: { type: "boolean", const: true },
217
- };
218
- }
219
-
220
- return ret;
221
- }
222
-
223
- return input;
224
- };
225
-
226
- const sdk = new XLRSDK();
227
- sdk.loadDefinitionsFromModule(Types);
228
- sdk.loadDefinitionsFromModule(ReferenceAssetsWebPluginManifest);
229
- const results = sdk.exportRegistry(
230
- "TypeScript",
231
- importMap,
232
- {
233
- pluginFilter: "Types",
234
- },
235
- [transformFunction],
236
- );
237
- expect(results[0][0]).toBe("out.d.ts");
238
- expect(results[0][1]).toMatchSnapshot();
239
- });
240
- });
241
-
242
158
  describe("Or Type Validation", () => {
243
159
  test("Outputs helpful type error messages", () => {
244
160
  const mockAsset = parseTree(`
package/src/sdk.ts CHANGED
@@ -8,7 +8,6 @@ import type {
8
8
  TransformFunction,
9
9
  TSManifest,
10
10
  } from "@xlr-lib/xlr";
11
- import type { TopLevelDeclaration } from "@xlr-lib/xlr-utils";
12
11
  import {
13
12
  computeEffectiveObject,
14
13
  resolveConditional,
@@ -16,14 +15,11 @@ import {
16
15
  } from "@xlr-lib/xlr-utils";
17
16
  import { fillInGenerics } from "@xlr-lib/xlr-utils";
18
17
  import type { Node } from "jsonc-parser";
19
- import { TSWriter } from "@xlr-lib/xlr-converters";
20
18
  import fs from "fs";
21
19
  import path from "path";
22
- import ts from "typescript";
23
20
 
24
21
  import type { XLRRegistry, Filters } from "./registry";
25
22
  import { BasicXLRRegistry } from "./registry";
26
- import type { ExportTypes } from "./types";
27
23
  import { XLRValidator } from "./validator";
28
24
  import { TransformFunctionMap, xlrTransformWalker } from "./utils";
29
25
 
@@ -40,14 +36,12 @@ export interface GetTypeOptions {
40
36
  export class XLRSDK {
41
37
  private registry: XLRRegistry;
42
38
  private validator: XLRValidator;
43
- private tsWriter: TSWriter;
44
39
  private computedNodeCache: Map<string, NodeType>;
45
40
  private externalTransformFunctions: Map<string, TransformFunction>;
46
41
 
47
42
  constructor(customRegistry?: XLRRegistry) {
48
43
  this.registry = customRegistry ?? new BasicXLRRegistry();
49
44
  this.validator = new XLRValidator(this.getType.bind(this));
50
- this.tsWriter = new TSWriter();
51
45
  this.computedNodeCache = new Map();
52
46
  this.externalTransformFunctions = new Map();
53
47
  }
@@ -265,43 +259,6 @@ export class XLRSDK {
265
259
  return this.validator.validateType(rootNode, type);
266
260
  }
267
261
 
268
- /**
269
- * Exports the types loaded into the registry to the specified format
270
- *
271
- * @param exportType - what format to export as
272
- * @param importMap - a map of primitive packages to types exported from that package to add import statements
273
- * @param filters - filter out plugins/capabilities/types you don't want to export
274
- * @param transforms - transforms to apply to types before exporting them
275
- * @returns [filename, content][] - Tuples of filenames and content to write
276
- */
277
- public exportRegistry(
278
- exportType: ExportTypes,
279
- importMap: Map<string, string[]>,
280
- filters?: Filters,
281
- transforms?: Array<TransformFunction>
282
- ): [string, string][] {
283
- const typesToExport = this.registry.list(filters).map((type) => {
284
- const effectiveType =
285
- transforms?.reduce(
286
- (typeAccumulator: NamedType<NodeType>, transformFn) =>
287
- transformFn(
288
- typeAccumulator,
289
- this.registry.info(type.name)?.capability as string
290
- ) as NamedType<NodeType>,
291
- type
292
- ) ?? type;
293
-
294
- return effectiveType;
295
- });
296
-
297
- if (exportType === "TypeScript") {
298
- const outputString = this.exportToTypeScript(typesToExport, importMap);
299
- return [["out.d.ts", outputString]];
300
- }
301
-
302
- throw new Error(`Unknown export format ${exportType}`);
303
- }
304
-
305
262
  /**
306
263
  * Transforms a generated XLR node into its final representation by resolving all `extends` properties.
307
264
  * If `optimize` is set to true the following operations are also performed:
@@ -391,68 +348,4 @@ export class XLRSDK {
391
348
  return xlrTransformWalker(transformMap)(resolvedObject) as NamedType
392
349
  }
393
350
 
394
- private exportToTypeScript(
395
- typesToExport: NamedType[],
396
- importMap: Map<string, string[]>
397
- ): string {
398
- const referencedImports: Set<string> = new Set();
399
- const exportedTypes: Map<string, TopLevelDeclaration> = new Map();
400
- const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
401
-
402
- let resultFile = ts.createSourceFile(
403
- "output.d.ts",
404
- "",
405
- ts.ScriptTarget.ES2017,
406
- false, // setParentNodes
407
- ts.ScriptKind.TS
408
- );
409
-
410
- typesToExport.forEach((typeNode) => {
411
- const { type, referencedTypes, additionalTypes } =
412
- this.tsWriter.convertNamedType(typeNode);
413
- exportedTypes.set(typeNode.name, type);
414
- additionalTypes?.forEach((additionalType, name) =>
415
- exportedTypes.set(name, additionalType)
416
- );
417
- referencedTypes?.forEach((referencedType) =>
418
- referencedImports.add(referencedType)
419
- );
420
- });
421
-
422
- const typesToPrint: Array<string> = [];
423
-
424
- exportedTypes.forEach((type) =>
425
- typesToPrint.push(
426
- printer.printNode(ts.EmitHint.Unspecified, type, resultFile)
427
- )
428
- );
429
-
430
- importMap.forEach((imports, packageName) => {
431
- const applicableImports = imports.filter((i) => referencedImports.has(i));
432
- resultFile = ts.factory.updateSourceFile(resultFile, [
433
- ts.factory.createImportDeclaration(
434
- /* modifiers */ undefined,
435
- ts.factory.createImportClause(
436
- false,
437
- undefined,
438
- ts.factory.createNamedImports(
439
- applicableImports.map((i) =>
440
- ts.factory.createImportSpecifier(
441
- false,
442
- undefined,
443
- ts.factory.createIdentifier(i)
444
- )
445
- )
446
- )
447
- ),
448
- ts.factory.createStringLiteral(packageName)
449
- ),
450
- ...resultFile.statements,
451
- ]);
452
- });
453
-
454
- const headerText = printer.printFile(resultFile);
455
- const nodeText = typesToPrint.join("\n");
456
- return `${headerText}\n${nodeText}`;
457
- }
458
351
  }
package/src/types.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import type { Node } from "jsonc-parser";
2
2
 
3
- /** Support Export Formats */
4
- export type ExportTypes = "TypeScript";
5
-
6
3
  export interface BaseValidationMessage<ErrorType extends string = string> {
7
4
  /** Validation Type */
8
5
  type: ErrorType;
package/types/sdk.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type { NamedType, NodeType, TransformFunction, TSManifest } from "@xlr-lib/xlr";
2
2
  import type { Node } from "jsonc-parser";
3
3
  import type { XLRRegistry, Filters } from "./registry";
4
- import type { ExportTypes } from "./types";
5
4
  export interface GetTypeOptions {
6
5
  /** Resolves `extends` fields in objects */
7
6
  getRawType?: boolean;
@@ -14,7 +13,6 @@ export interface GetTypeOptions {
14
13
  export declare class XLRSDK {
15
14
  private registry;
16
15
  private validator;
17
- private tsWriter;
18
16
  private computedNodeCache;
19
17
  private externalTransformFunctions;
20
18
  constructor(customRegistry?: XLRRegistry);
@@ -87,16 +85,6 @@ export declare class XLRSDK {
87
85
  * @returns `Array<ValidationErrors>`
88
86
  */
89
87
  validateByType(type: NodeType, rootNode: Node): import("./types").ValidationMessage[];
90
- /**
91
- * Exports the types loaded into the registry to the specified format
92
- *
93
- * @param exportType - what format to export as
94
- * @param importMap - a map of primitive packages to types exported from that package to add import statements
95
- * @param filters - filter out plugins/capabilities/types you don't want to export
96
- * @param transforms - transforms to apply to types before exporting them
97
- * @returns [filename, content][] - Tuples of filenames and content to write
98
- */
99
- exportRegistry(exportType: ExportTypes, importMap: Map<string, string[]>, filters?: Filters, transforms?: Array<TransformFunction>): [string, string][];
100
88
  /**
101
89
  * Transforms a generated XLR node into its final representation by resolving all `extends` properties.
102
90
  * If `optimize` is set to true the following operations are also performed:
@@ -106,6 +94,5 @@ export declare class XLRSDK {
106
94
  * - filing in any remaining generics with their default value
107
95
  */
108
96
  private resolveType;
109
- private exportToTypeScript;
110
97
  }
111
98
  //# sourceMappingURL=sdk.d.ts.map
package/types/types.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import type { Node } from "jsonc-parser";
2
- /** Support Export Formats */
3
- export type ExportTypes = "TypeScript";
4
2
  export interface BaseValidationMessage<ErrorType extends string = string> {
5
3
  /** Validation Type */
6
4
  type: ErrorType;