From 80a1842cf19e7d64c7c34f50925fd8677766e4b6 Mon Sep 17 00:00:00 2001 From: John Conley Date: Tue, 8 Aug 2023 17:19:23 -0700 Subject: [PATCH 1/4] fix the obliteration of sourcefile references --- .gitignore | 1 + dprint.json | 4 +- package.json | 3 +- packages/core/package.json | 3 +- packages/core/src/lib/nornir.ts | 5 ++ packages/rest/package.json | 4 +- packages/rest/src/runtime/decorators.mts | 48 ++++++++++++++++++- .../rest/src/transform/controller-meta.ts | 15 ++++-- packages/rest/src/transform/lib.ts | 35 +++++++++----- .../transformers/class-transformer.ts | 9 +++- .../controller-method-transformer.ts | 7 ++- .../transformers/file-transformer.ts | 46 +++++++++++++----- .../transformers/node-transformer.ts | 9 +++- .../processors/chain-route-processor.ts | 40 +++++++++------- .../processors/controller-processor.ts | 15 ++++-- .../processors/provider-processor.ts | 1 + packages/test/__tests__/tsconfig.json | 1 - packages/test/package.json | 7 +-- packages/test/src/controller.ts | 5 ++ packages/test/tsconfig.json | 5 +- plop_templates/utility-lib/package.json | 3 +- pnpm-lock.yaml | 28 +++++------ 22 files changed, 210 insertions(+), 84 deletions(-) diff --git a/.gitignore b/.gitignore index 2fcb7f0..ea83e91 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ report.json .tsbuildinfo cdk.out .env +vitest.config.js.timestamp-* diff --git a/dprint.json b/dprint.json index d2e170b..255a280 100644 --- a/dprint.json +++ b/dprint.json @@ -12,7 +12,9 @@ "**/node_modules", "**/*-lock.json", "**/dist", - "**/bundle" + "**/bundle", + "*.d.ts", + "coverage-final.json" ], "plugins": [ "https://plugins.dprint.dev/typescript-0.83.0.wasm", diff --git a/package.json b/package.json index 17a1d2d..b260816 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "jest-html-reporters": "^3.1.4", "jest-junit": "^15.0.0", "plop": "^3.1.2", - "scripts": "workspace:*", + "scripts": "workspace:^", "syncpack": "^9.8.4", "ts-patch": "^3.0.2", "turbo": "^1.9.2", @@ -42,6 +42,7 @@ "license": "MIT", "packageManager": "pnpm@6.32.4", "private": true, + "repository": "nrfcloud/account-service", "scripts": { "clean": "rm -rf coverage reports node_modules/.cache/turbo && pnpm clean:turbo && pnpm turbo clean:single", "clean:turbo": "rm -rf node_modules/.cache/turbo", diff --git a/packages/core/package.json b/packages/core/package.json index e05cd0c..dbb2ba1 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -5,7 +5,7 @@ "author": "John Conley", "devDependencies": { "@jest/globals": "^29.5.0", - "@nrfcloud/ts-json-schema-transformer": "^1.2.1", + "@nrfcloud/ts-json-schema-transformer": "^1.2.2", "@types/jest": "^29.4.0", "@types/node": "^18.15.11", "esbuild": "^0.17.18", @@ -27,6 +27,7 @@ "dist" ], "license": "MIT", + "repository": "nrfcloud/account-service", "scripts": { "//10": "The following scripts are also available from the scripts package", "//20": "You can also override them by specifying them here", diff --git a/packages/core/src/lib/nornir.ts b/packages/core/src/lib/nornir.ts index 466a1de..ff80c45 100644 --- a/packages/core/src/lib/nornir.ts +++ b/packages/core/src/lib/nornir.ts @@ -44,6 +44,11 @@ class NornirContext { export type ResultMiddleware = (input: Result, registry: AttachmentRegistry) => Output; +/** + * A Nornir is a chain of middleware that can be used to transform an input into an output. + * + * @originator nornir/core + */ export class Nornir { constructor(private readonly context: NornirContext = new NornirContext()) {} diff --git a/packages/rest/package.json b/packages/rest/package.json index e6857fb..663dca3 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -3,7 +3,8 @@ "description": "A nornir library", "version": "1.2.0", "dependencies": { - "@nrfcloud/ts-json-schema-transformer": "^1.2.1", + "@nornir/core": "workspace", + "@nrfcloud/ts-json-schema-transformer": "^1.2.2", "@types/aws-lambda": "^8.10.115", "ajv": "^8.12.0", "openapi-types": "^12.1.0", @@ -14,7 +15,6 @@ }, "devDependencies": { "@jest/globals": "^29.5.0", - "@nornir/core": "workspace:*", "@types/jest": "^29.4.0", "@types/node": "^18.15.11", "eslint": "^8.45.0", diff --git a/packages/rest/src/runtime/decorators.mts b/packages/rest/src/runtime/decorators.mts index 6100204..82fdc8a 100644 --- a/packages/rest/src/runtime/decorators.mts +++ b/packages/rest/src/runtime/decorators.mts @@ -2,7 +2,13 @@ import {Nornir} from "@nornir/core"; import {HttpRequest, HttpResponse} from "./http-event.mjs"; import {InstanceOf} from "ts-morph"; -const UNTRANSFORMED_ERROR = new Error("@nornir/rest decorators have not been transformed. Have you setup ts-patch/ttypescript and added the transformer to your tsconfig.json?"); +const UNTRANSFORMED_ERROR = new Error("nornir/rest decorators have not been transformed. Have you setup ts-patch/ttypescript and added the originator to your tsconfig.json?"); + +/** + * Use to mark a class as a REST controller + * + * @originator nornir/rest + */ export function Controller(_basePath: Path, _apiId?: ApiId) { return (_target: T, _ctx: ClassDecoratorContext): T => { throw UNTRANSFORMED_ERROR; @@ -14,34 +20,74 @@ const routeChainDecorator = {throw UNTRANSFORMED_ERROR}; +/** + * Use to mark a method as a GET route + * + * @originator nornir/rest + */ export function GetChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a POST route + * + * @originator nornir/rest + */ export function PostChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a PUT route + * + * @originator nornir/rest + */ export function PutChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a PATCH route + * + * @originator nornir/rest + */ export function PatchChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a DELETE route + * + * @originator nornir/rest + */ export function DeleteChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a HEAD route + * + * @originator nornir/rest + */ export function HeadChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a method as a OPTIONS route + * + * @originator nornir/rest + */ export function OptionsChain(_path: string) { return routeChainDecorator; } +/** + * Use to mark a static method as an instance provider for a controller + * + * @originator nornir/rest + */ export function Provider() { return >(_target: () => K, _propertyKey: ClassMethodDecoratorContext & {static: true}): never => { throw UNTRANSFORMED_ERROR diff --git a/packages/rest/src/transform/controller-meta.ts b/packages/rest/src/transform/controller-meta.ts index 2a69df5..0cba723 100644 --- a/packages/rest/src/transform/controller-meta.ts +++ b/packages/rest/src/transform/controller-meta.ts @@ -27,7 +27,13 @@ export class ControllerMeta { this.cache.clear(); } - public static create(project: Project, route: ts.ClassDeclaration, basePath: string, apiId: string): ControllerMeta { + public static create( + project: Project, + source: ts.SourceFile, + route: ts.ClassDeclaration, + basePath: string, + apiId: string, + ): ControllerMeta { const name = route.name; if (!name) { throw new Error("Route class must have a name"); @@ -35,7 +41,7 @@ export class ControllerMeta { if (this.cache.has(name)) { throw new Error("Route already exists: " + name.getText()); } - const meta = new ControllerMeta(project, route, name, basePath, apiId); + const meta = new ControllerMeta(project, source, route, name, basePath, apiId); this.cache.set(name, meta); return meta; } @@ -58,6 +64,7 @@ export class ControllerMeta { private constructor( private readonly project: Project, + public readonly source: ts.SourceFile, public readonly route: ts.ClassDeclaration, public readonly identifier: ts.Identifier, public readonly basePath: string, @@ -95,7 +102,7 @@ export class ControllerMeta { private generateRouteHolderCreateStatement() { const nornirRestImport = FileTransformer.getOrCreateImport( - this.route.getSourceFile(), + this.source, "@nornir/rest", "RouteHolder", ); @@ -134,7 +141,7 @@ export class ControllerMeta { } private generateRegisterRouteHolderStatement() { - const routerIdentifier = FileTransformer.getOrCreateImport(this.route.getSourceFile(), "@nornir/rest", "Router"); + const routerIdentifier = FileTransformer.getOrCreateImport(this.source, "@nornir/rest", "Router"); const routerInstance = ts.factory.createCallExpression( ts.factory.createPropertyAccessExpression(routerIdentifier, "get"), [], diff --git a/packages/rest/src/transform/lib.ts b/packages/rest/src/transform/lib.ts index d58428e..9f0814f 100644 --- a/packages/rest/src/transform/lib.ts +++ b/packages/rest/src/transform/lib.ts @@ -1,17 +1,18 @@ -import path from "node:path"; import ts from "typescript"; import { StrictTransformationError } from "./error"; import { Project } from "./project"; -const LIB_PATHS = [ - path.join("node_modules", "@nornir/rest", "dist", "runtime"), - path.join("node_modules", "@nornir/core", "dist"), - path.join("packages", "rest", "dist", "runtime"), - path.join("packages", "core", "dist"), -]; +export function isNornirNode(node: ts.Node) { + return hasOriginator(node, "nornir/core"); +} + +export function isNornirRestNode(node: ts.Node) { + return hasOriginator(node, "nornir/rest"); +} -export function isNornirLib(file: string) { - return LIB_PATHS.some(libPath => file.includes(libPath)); +export function hasOriginator(node: ts.Node, originator: string): boolean { + const jsdoc = ts.getJSDocTags(node); + return jsdoc.some((tag) => tag.tagName.getText() === "originator" && tag.comment === originator); } export function getStringLiteralOrConst(project: Project, node: ts.Expression): string | undefined { @@ -39,14 +40,22 @@ export function separateNornirDecorators( otherDecorators: ts.Decorator[]; nornirDecorators: NornirDecoratorInfo[]; } { - const nornirDecorators: { decorator: ts.Decorator; signature: ts.Signature; declaration: ts.Declaration }[] = []; + const nornirDecorators: { + decorator: ts.Decorator; + signature: ts.Signature; + declaration: ts.Declaration; + }[] = []; const decorators: ts.Decorator[] = []; for (const decorator of originalDecorators) { const signature = project.checker.getResolvedSignature(decorator); - const fileName = signature?.declaration?.getSourceFile().fileName || ""; - if (isNornirLib(fileName) && signature && signature.declaration) { - nornirDecorators.push({ decorator, signature, declaration: signature.declaration }); + const parentDeclaration = signature?.getDeclaration()?.parent; + if (parentDeclaration && signature && signature.declaration && isNornirRestNode(parentDeclaration)) { + nornirDecorators.push({ + decorator, + signature, + declaration: signature.declaration, + }); } else { decorators.push(decorator); } diff --git a/packages/rest/src/transform/transformers/class-transformer.ts b/packages/rest/src/transform/transformers/class-transformer.ts index b811827..57eb9ff 100644 --- a/packages/rest/src/transform/transformers/class-transformer.ts +++ b/packages/rest/src/transform/transformers/class-transformer.ts @@ -4,13 +4,18 @@ import { Project } from "../project"; import { ControllerProcessor } from "./processors/controller-processor"; export abstract class ClassTransformer { - public static transform(project: Project, node: ts.ClassDeclaration, context: ts.TransformationContext): ts.Node { + public static transform( + project: Project, + source: ts.SourceFile, + node: ts.ClassDeclaration, + context: ts.TransformationContext, + ): ts.Node { const originalDecorators = ts.getDecorators(node) || []; if (!originalDecorators) return node; const { nornirDecorators } = separateNornirDecorators(project, originalDecorators); if (nornirDecorators.length === 0) return node; - return ControllerProcessor.process(project, node, nornirDecorators, context); + return ControllerProcessor.process(project, source, node, nornirDecorators, context); } } diff --git a/packages/rest/src/transform/transformers/controller-method-transformer.ts b/packages/rest/src/transform/transformers/controller-method-transformer.ts index f67f48b..30382b9 100644 --- a/packages/rest/src/transform/transformers/controller-method-transformer.ts +++ b/packages/rest/src/transform/transformers/controller-method-transformer.ts @@ -8,6 +8,7 @@ import { ProviderProcessor } from "./processors/provider-processor"; export abstract class ControllerMethodTransformer { private static transform( project: Project, + source: ts.SourceFile, node: ts.MethodDeclaration, controller: ControllerMeta, ): ts.MethodDeclaration { @@ -27,18 +28,19 @@ export abstract class ControllerMethodTransformer { if (!method) return node; - return METHOD_DECORATOR_PROCESSORS[method](methodDecorator, project, node, controller); + return METHOD_DECORATOR_PROCESSORS[method](methodDecorator, project, source, node, controller); } public static transformControllerMethods( project: Project, + source: ts.SourceFile, node: ts.ClassDeclaration, controller: ControllerMeta, context: ts.TransformationContext, ) { return ts.visitEachChild(node, (child) => { if (ts.isMethodDeclaration(child)) { - return ControllerMethodTransformer.transform(project, child, controller); + return ControllerMethodTransformer.transform(project, source, child, controller); } return child; }, context); @@ -48,6 +50,7 @@ export abstract class ControllerMethodTransformer { type Task = ( methodDecorator: NornirDecoratorInfo, project: Project, + source: ts.SourceFile, node: ts.MethodDeclaration, controller: ControllerMeta, ) => ts.MethodDeclaration; diff --git a/packages/rest/src/transform/transformers/file-transformer.ts b/packages/rest/src/transform/transformers/file-transformer.ts index 33c6892..487ad93 100644 --- a/packages/rest/src/transform/transformers/file-transformer.ts +++ b/packages/rest/src/transform/transformers/file-transformer.ts @@ -8,7 +8,7 @@ export abstract class FileTransformer { public static transform(project: Project, context: ts.TransformationContext, file: ts.SourceFile): ts.SourceFile { if (file.isDeclarationFile) return file; // return file; - const transformed = FileTransformer.iterateNode(project, context, file); + const transformed = FileTransformer.iterateNode(project, context, file, file); const nodesToAdd = FileTransformer.getStatementsForFile(file); if (nodesToAdd == undefined) return transformed; @@ -20,6 +20,11 @@ export abstract class FileTransformer { ...transformed.statements, ...nodesToAdd.end, ], + file.isDeclarationFile, + file.referencedFiles, + file.typeReferenceDirectives, + file.hasNoDefaultLib, + file.libReferenceDirectives, ); FileTransformer.FILE_NODE_MAP.delete(file.fileName); @@ -28,31 +33,42 @@ export abstract class FileTransformer { return updated; } - private static FILE_NODE_MAP = new Map(); + private static FILE_NODE_MAP = new Map(); private static iterateNode( project: Project, context: ts.TransformationContext, + source: ts.SourceFile, node: T, - ) { - const visitor = (child: ts.Node): ts.VisitResult => { - const transformed = FileTransformer.tryTransformNode(project, child, context); - return ts.visitEachChild(transformed, visitor, context); - }; - - return ts.visitEachChild(node, visitor, context); + ): T { + return ts.visitEachChild( + FileTransformer.tryTransformNode(project, source, node, context), + (child) => FileTransformer.iterateNode(project, context, source, child), + context, + ) as T; } - private static tryTransformNode(project: Project, node: ts.Node, context: ts.TransformationContext): ts.Node { + private static tryTransformNode( + project: Project, + source: ts.SourceFile, + node: ts.Node, + context: ts.TransformationContext, + ): ts.Node { try { - return NodeTransformer.transform(project, node, context); + return NodeTransformer.transform(project, source, node, context); } catch (error) { if (!(error instanceof Error)) throw error; if (error instanceof TransformationError) throw error; console.error(error); const file: ts.SourceFile = node.getSourceFile(); - const { line, character } = file.getLineAndCharacterOfPosition( + const { + line, + character, + } = file.getLineAndCharacterOfPosition( node.pos, ); error.message += ` - ${file.fileName}:${line + 1}:${character + 1}`; @@ -61,7 +77,10 @@ export abstract class FileTransformer { } public static addStatementToFile(file: ts.SourceFile, statement: ts.Statement, type: "start" | "end") { - const nodes = FileTransformer.FILE_NODE_MAP.get(file.fileName) || { start: [], end: [] }; + const nodes = FileTransformer.FILE_NODE_MAP.get(file.fileName) || { + start: [], + end: [], + }; nodes[type].push(statement); FileTransformer.FILE_NODE_MAP.set(file.fileName, nodes); } @@ -71,6 +90,7 @@ export abstract class FileTransformer { } private static IMPORT_MAP = new Map>>(); + public static getOrCreateImport(file: ts.SourceFile, packageName: string, namedImport: string): ts.Identifier { const imports = FileTransformer.IMPORT_MAP.get(file.fileName) || new Map>(); FileTransformer.IMPORT_MAP.set(file.fileName, imports); diff --git a/packages/rest/src/transform/transformers/node-transformer.ts b/packages/rest/src/transform/transformers/node-transformer.ts index 4e734c8..adfa6ae 100644 --- a/packages/rest/src/transform/transformers/node-transformer.ts +++ b/packages/rest/src/transform/transformers/node-transformer.ts @@ -3,9 +3,14 @@ import { Project } from "../project"; import { ClassTransformer } from "./class-transformer"; export abstract class NodeTransformer { - public static transform(project: Project, node: ts.Node, context: ts.TransformationContext): ts.Node { + public static transform( + project: Project, + source: ts.SourceFile, + node: ts.Node, + context: ts.TransformationContext, + ): ts.Node { if (ts.isClassDeclaration(node)) { - return ClassTransformer.transform(project, node, context); + return ClassTransformer.transform(project, source, node, context); } return node; diff --git a/packages/rest/src/transform/transformers/processors/chain-route-processor.ts b/packages/rest/src/transform/transformers/processors/chain-route-processor.ts index 17d8326..e741607 100644 --- a/packages/rest/src/transform/transformers/processors/chain-route-processor.ts +++ b/packages/rest/src/transform/transformers/processors/chain-route-processor.ts @@ -1,9 +1,8 @@ import { schemaToValidator } from "@nrfcloud/ts-json-schema-transformer/utils"; -import { createWrappedNode, MethodDeclaration, TypeNode, TypeReferenceNode } from "ts-morph"; import { isTypeReference } from "tsutils"; import ts from "typescript"; import { ControllerMeta } from "../../controller-meta"; -import { getStringLiteralOrConst, isNornirLib, NornirDecoratorInfo, separateNornirDecorators } from "../../lib"; +import { getStringLiteralOrConst, isNornirNode, NornirDecoratorInfo, separateNornirDecorators } from "../../lib"; import { Project } from "../../project"; export const ChainMethodDecoratorTypeMap = { @@ -24,30 +23,34 @@ export abstract class ChainRouteProcessor { public static transform( methodDecorator: NornirDecoratorInfo, project: Project, + source: ts.SourceFile, node: ts.MethodDeclaration, controller: ControllerMeta, ): ts.MethodDeclaration { const path = ChainRouteProcessor.getPath(project, methodDecorator); const method = ChainRouteProcessor.getMethod(project, methodDecorator); - const wrappedNode = createWrappedNode(node, { typeChecker: project.checker }) as MethodDeclaration; + // const wrappedNode = createWrappedNode(node, { typeChecker: project.checker }) as MethodDeclaration; - const inputType = ChainRouteProcessor.resolveInputType(wrappedNode); + const inputTypeNode = ChainRouteProcessor.resolveInputType(project, node); + const inputType = project.checker.getTypeFromTypeNode(inputTypeNode); // const outputType = ChainRouteProcessor.resolveOutputType(project, methodSignature); - const inputSchema = project.schemaGenerator.createSchemaFromNodes([inputType.compilerNode as never]); + const inputSchema = project.schemaGenerator.createSchemaFromNodes([inputTypeNode]); const inputValidator = schemaToValidator(inputSchema, project.options.validation); controller.registerRoute(node, { method, path, - input: inputType.getType().compilerType, - output: inputType.getType().compilerType, + input: inputType, + + // FIXME: this should be the output type not the input type + output: inputType, // description, // summary, - filePath: node.getSourceFile().fileName, + filePath: source.fileName, }); controller.addInitializationStatement( @@ -126,23 +129,26 @@ export abstract class ChainRouteProcessor { return ChainMethodDecoratorTypeMap[name as keyof typeof ChainMethodDecoratorTypeMap]; } - private static resolveInputType(method: MethodDeclaration): TypeNode { - const params = method.getParameters(); + private static resolveInputType(project: Project, method: ts.MethodDeclaration): ts.TypeNode { + const params = method.parameters; if (params.length !== 1) { throw new Error("Handler chain must have 1 parameter"); } const [param] = params; - const paramTypePath = param.getType().getSymbol()?.getDeclarations()?.[0].getSourceFile().getFilePath(); - if (!isNornirLib(paramTypePath || "")) { + const paramType = project.checker.getTypeAtLocation(param); + const paramDeclaration = paramType.symbol?.declarations?.[0]; + if (!paramDeclaration || !isNornirNode(paramDeclaration)) { throw new Error("Handler chain input must be a Nornir class"); } - const paramTypeNode = param.getTypeNodeOrThrow() as TypeReferenceNode; - const paramTypeArgs = paramTypeNode.getTypeArguments(); - if (paramTypeArgs.length !== 1) { + + // eslint-disable-next-line unicorn/no-useless-undefined + const paramTypeNode = project.checker.typeToTypeNode(paramType, undefined, undefined) as ts.TypeReferenceNode; + const [paramTypeArg] = paramTypeNode.typeArguments || []; + if (!paramTypeArg) { throw new Error("Handler chain input must have a type argument"); } - return paramTypeArgs[0]; + return paramTypeArg; } private static resolveOutputType(project: Project, methodSignature: ts.Signature): ts.Type { @@ -151,7 +157,7 @@ export abstract class ChainRouteProcessor { if (!returnTypeDeclaration) { throw new Error("Handler chain return type declaration not found"); } - if (!isNornirLib(returnTypeDeclaration.getSourceFile().fileName)) { + if (!isNornirNode(returnTypeDeclaration)) { throw new Error("Handler chain return must be a Nornir class"); } if (!isTypeReference(returnType)) { diff --git a/packages/rest/src/transform/transformers/processors/controller-processor.ts b/packages/rest/src/transform/transformers/processors/controller-processor.ts index 185d932..6fe757b 100644 --- a/packages/rest/src/transform/transformers/processors/controller-processor.ts +++ b/packages/rest/src/transform/transformers/processors/controller-processor.ts @@ -7,14 +7,21 @@ import { ControllerMethodTransformer } from "../controller-method-transformer"; export abstract class ControllerProcessor { public static process( project: Project, + source: ts.SourceFile, node: ts.ClassDeclaration, nornirDecorators: NornirDecoratorInfo[], context: ts.TransformationContext, ): ts.Node { - const { basePath, apiId } = ControllerProcessor.getAruments(project, nornirDecorators); - const routeMeta = ControllerMeta.create(project, node, basePath, apiId); + const { basePath, apiId } = ControllerProcessor.getArguments(project, nornirDecorators); + const routeMeta = ControllerMeta.create(project, source, node, basePath, apiId); - const transformedNode = ControllerMethodTransformer.transformControllerMethods(project, node, routeMeta, context); + const transformedNode = ControllerMethodTransformer.transformControllerMethods( + project, + source, + node, + routeMeta, + context, + ); const transformedModifiers = ts.getModifiers(transformedNode) || []; @@ -32,7 +39,7 @@ export abstract class ControllerProcessor { ); } - private static getAruments(project: Project, nornirDecorators: NornirDecoratorInfo[]): { + private static getArguments(project: Project, nornirDecorators: NornirDecoratorInfo[]): { basePath: string; apiId: string; } { diff --git a/packages/rest/src/transform/transformers/processors/provider-processor.ts b/packages/rest/src/transform/transformers/processors/provider-processor.ts index ff27ea6..4f97af1 100644 --- a/packages/rest/src/transform/transformers/processors/provider-processor.ts +++ b/packages/rest/src/transform/transformers/processors/provider-processor.ts @@ -7,6 +7,7 @@ export abstract class ProviderProcessor { public static transform( methodDecorator: NornirDecoratorInfo, project: Project, + source: ts.SourceFile, node: ts.MethodDeclaration, controller: ControllerMeta, ): ts.MethodDeclaration { diff --git a/packages/test/__tests__/tsconfig.json b/packages/test/__tests__/tsconfig.json index 0ec459a..6aefe25 100644 --- a/packages/test/__tests__/tsconfig.json +++ b/packages/test/__tests__/tsconfig.json @@ -6,7 +6,6 @@ "baseUrl": ".", "outDir": "dist", "rootDir": "src", - "tsBuildInfoFile": "dist/tsconfig.tsbuildinfo", "esModuleInterop": true, "types": [ "jest", diff --git a/packages/test/package.json b/packages/test/package.json index af92dcc..45bd6d9 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -3,12 +3,12 @@ "description": "Sandbox test library for Nornir", "version": "1.0.0", "dependencies": { - "@nornir/core": "workspace:*", - "@nornir/rest": "workspace:*" + "@nornir/core": "workspace", + "@nornir/rest": "workspace" }, "devDependencies": { "@jest/globals": "^29.5.0", - "@nrfcloud/ts-json-schema-transformer": "^1.2.1", + "@nrfcloud/ts-json-schema-transformer": "^1.2.2", "@types/aws-lambda": "^8.10.115", "@types/jest": "^29.4.0", "@types/node": "^18.15.11", @@ -37,6 +37,7 @@ ], "license": "MIT", "private": true, + "repository": "nrfcloud/account-service", "scripts": { "//10": "The following scripts are also available from the scripts package", "//20": "You can also override them by specifying them here", diff --git a/packages/test/src/controller.ts b/packages/test/src/controller.ts index 23ba029..70af300 100644 --- a/packages/test/src/controller.ts +++ b/packages/test/src/controller.ts @@ -8,6 +8,7 @@ import { MimeType, PostChain, } from "@nornir/rest"; +import { assertValid } from "@nrfcloud/ts-json-schema-transformer"; interface RouteGetInput extends HttpRequestEmpty { headers: { @@ -90,6 +91,10 @@ export class TestController { @GetChain("/route") public getRoute(chain: Nornir) { return chain + .use(input => { + assertValid(input); + return input; + }) .use(input => input.headers["content-type"]) .use(contentType => ({ statusCode: HttpStatusCode.Ok, diff --git a/packages/test/tsconfig.json b/packages/test/tsconfig.json index d88cce8..ce8ff6d 100644 --- a/packages/test/tsconfig.json +++ b/packages/test/tsconfig.json @@ -10,9 +10,10 @@ "transform": "@nornir/rest/transform" } ], - "tsBuildInfoFile": "dist/.tsbuildinfo", "outDir": "dist", - "rootDir": "src" + "rootDir": "src", + "composite": false, + "incremental": false }, "include": [ "src/**/*", diff --git a/plop_templates/utility-lib/package.json b/plop_templates/utility-lib/package.json index 02740f9..0cd53c8 100644 --- a/plop_templates/utility-lib/package.json +++ b/plop_templates/utility-lib/package.json @@ -62,5 +62,6 @@ "prepublish": "pnpm build:clean", "test": "pnpm tests" }, - "type": "module" + "type": "module", +"repository": "nrfcloud/account-service" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab0f596..8d905d1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,7 +81,7 @@ importers: specifier: ^3.1.2 version: 3.1.2 scripts: - specifier: workspace:* + specifier: workspace:^ version: link:packages/scripts syncpack: specifier: ^9.8.4 @@ -102,8 +102,8 @@ importers: specifier: ^29.5.0 version: 29.5.0 '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.1 - version: 1.2.1(typescript@5.1.6) + specifier: ^1.2.2 + version: 1.2.2(typescript@5.1.6) '@types/jest': specifier: ^29.4.0 version: 29.4.0 @@ -128,9 +128,12 @@ importers: packages/rest: dependencies: + '@nornir/core': + specifier: workspace + version: link:../core '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.1 - version: 1.2.1(typescript@5.1.6) + specifier: ^1.2.2 + version: 1.2.2(typescript@5.1.6) '@types/aws-lambda': specifier: ^8.10.115 version: 8.10.115 @@ -156,9 +159,6 @@ importers: '@jest/globals': specifier: ^29.5.0 version: 29.5.0 - '@nornir/core': - specifier: workspace:* - version: link:../core '@types/jest': specifier: ^29.4.0 version: 29.4.0 @@ -183,18 +183,18 @@ importers: packages/test: dependencies: '@nornir/core': - specifier: workspace:* + specifier: workspace:^ version: link:../core '@nornir/rest': - specifier: workspace:* + specifier: workspace:^ version: link:../rest devDependencies: '@jest/globals': specifier: ^29.5.0 version: 29.5.0 '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.1 - version: 1.2.1(typescript@5.1.6) + specifier: ^1.2.2 + version: 1.2.2(typescript@5.1.6) '@types/aws-lambda': specifier: ^8.10.115 version: 8.10.115 @@ -2241,8 +2241,8 @@ packages: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 - /@nrfcloud/ts-json-schema-transformer@1.2.1(typescript@5.1.6): - resolution: {integrity: sha512-pmFMH3+DMSWPLVxPU7ooeWrllnFIupXky2MK6UyJhwmRebnsvJru6wz5dPgbNmMEz0O3HzMtkjZ++bMOUX1vHg==} + /@nrfcloud/ts-json-schema-transformer@1.2.2(typescript@5.1.6): + resolution: {integrity: sha512-zv7zKKtJhMu6c318wcDPxM83DSzp9tY7FpjjPn8blHtEQ0cs/NNswoSkUZtH9GYWnQT1pE/H5ddOJ4qxcklLWg==, tarball: https://npm.pkg.github.com/download/@nrfcloud/ts-json-schema-transformer/1.2.2/02ee13e5d21daf36025dc511ee579ef9fb1078fe} engines: {node: '>=18.0.0'} peerDependencies: typescript: '>=5' From 5ca7dc305e25cac058b469073c7c10fb725d775b Mon Sep 17 00:00:00 2001 From: John Conley Date: Tue, 8 Aug 2023 17:24:14 -0700 Subject: [PATCH 2/4] docs(changeset): add originator tag to nornir class --- .changeset/giant-poems-relax.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/giant-poems-relax.md diff --git a/.changeset/giant-poems-relax.md b/.changeset/giant-poems-relax.md new file mode 100644 index 0000000..8a3eef9 --- /dev/null +++ b/.changeset/giant-poems-relax.md @@ -0,0 +1,5 @@ +--- +"@nornir/core": patch +--- + +add originator tag to nornir class From 5cd417af760ecd37f00d3cc865ab16d5ee6272a4 Mon Sep 17 00:00:00 2001 From: John Conley Date: Tue, 8 Aug 2023 17:25:09 -0700 Subject: [PATCH 3/4] docs(changeset): fix issues with source transformation --- .changeset/sweet-planets-return.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sweet-planets-return.md diff --git a/.changeset/sweet-planets-return.md b/.changeset/sweet-planets-return.md new file mode 100644 index 0000000..dce63a8 --- /dev/null +++ b/.changeset/sweet-planets-return.md @@ -0,0 +1,5 @@ +--- +"@nornir/rest": patch +--- + +fix issues with source transformation From 8e988c3a77220383102b5f93f7ba2a9b52797925 Mon Sep 17 00:00:00 2001 From: John Conley Date: Tue, 8 Aug 2023 17:30:19 -0700 Subject: [PATCH 4/4] update schema transformer --- packages/core/package.json | 2 +- packages/rest/package.json | 2 +- packages/test/package.json | 2 +- pnpm-lock.yaml | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index dbb2ba1..fb3d09e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -5,7 +5,7 @@ "author": "John Conley", "devDependencies": { "@jest/globals": "^29.5.0", - "@nrfcloud/ts-json-schema-transformer": "^1.2.2", + "@nrfcloud/ts-json-schema-transformer": "^1.2.3", "@types/jest": "^29.4.0", "@types/node": "^18.15.11", "esbuild": "^0.17.18", diff --git a/packages/rest/package.json b/packages/rest/package.json index 663dca3..08384e1 100644 --- a/packages/rest/package.json +++ b/packages/rest/package.json @@ -4,7 +4,7 @@ "version": "1.2.0", "dependencies": { "@nornir/core": "workspace", - "@nrfcloud/ts-json-schema-transformer": "^1.2.2", + "@nrfcloud/ts-json-schema-transformer": "^1.2.3", "@types/aws-lambda": "^8.10.115", "ajv": "^8.12.0", "openapi-types": "^12.1.0", diff --git a/packages/test/package.json b/packages/test/package.json index 45bd6d9..13eac09 100644 --- a/packages/test/package.json +++ b/packages/test/package.json @@ -8,7 +8,7 @@ }, "devDependencies": { "@jest/globals": "^29.5.0", - "@nrfcloud/ts-json-schema-transformer": "^1.2.2", + "@nrfcloud/ts-json-schema-transformer": "^1.2.3", "@types/aws-lambda": "^8.10.115", "@types/jest": "^29.4.0", "@types/node": "^18.15.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8d905d1..5eeb0d6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -102,8 +102,8 @@ importers: specifier: ^29.5.0 version: 29.5.0 '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.2 - version: 1.2.2(typescript@5.1.6) + specifier: ^1.2.3 + version: 1.2.3(typescript@5.1.6) '@types/jest': specifier: ^29.4.0 version: 29.4.0 @@ -132,8 +132,8 @@ importers: specifier: workspace version: link:../core '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.2 - version: 1.2.2(typescript@5.1.6) + specifier: ^1.2.3 + version: 1.2.3(typescript@5.1.6) '@types/aws-lambda': specifier: ^8.10.115 version: 8.10.115 @@ -183,18 +183,18 @@ importers: packages/test: dependencies: '@nornir/core': - specifier: workspace:^ + specifier: workspace version: link:../core '@nornir/rest': - specifier: workspace:^ + specifier: workspace version: link:../rest devDependencies: '@jest/globals': specifier: ^29.5.0 version: 29.5.0 '@nrfcloud/ts-json-schema-transformer': - specifier: ^1.2.2 - version: 1.2.2(typescript@5.1.6) + specifier: ^1.2.3 + version: 1.2.3(typescript@5.1.6) '@types/aws-lambda': specifier: ^8.10.115 version: 8.10.115 @@ -2241,8 +2241,8 @@ packages: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 - /@nrfcloud/ts-json-schema-transformer@1.2.2(typescript@5.1.6): - resolution: {integrity: sha512-zv7zKKtJhMu6c318wcDPxM83DSzp9tY7FpjjPn8blHtEQ0cs/NNswoSkUZtH9GYWnQT1pE/H5ddOJ4qxcklLWg==, tarball: https://npm.pkg.github.com/download/@nrfcloud/ts-json-schema-transformer/1.2.2/02ee13e5d21daf36025dc511ee579ef9fb1078fe} + /@nrfcloud/ts-json-schema-transformer@1.2.3(typescript@5.1.6): + resolution: {integrity: sha512-64/ipN46E8ol+YYn4TJGH/ZMXcod6EImzxYlmhZpQvi+bE6ssTWPIrpSJxDYFQzzsNKBi5HfIJywC7kUEGwFWQ==, tarball: https://npm.pkg.github.com/download/@nrfcloud/ts-json-schema-transformer/1.2.3/60c0bb34da4ef5a9d9bea1420dd33eeda05caf44} engines: {node: '>=18.0.0'} peerDependencies: typescript: '>=5'