New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@typespec/rest

Package Overview
Dependencies
Maintainers
1
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typespec/rest - npm Package Compare versions

Comparing version 0.44.0-dev.2 to 0.44.0-dev.4

19

dist/src/lib.d.ts

@@ -20,4 +20,7 @@ declare const restLib: import("@typespec/compiler").TypeSpecLibrary<{

};
"shared-route-unspecified-action-name": {
readonly default: import("@typespec/compiler").CallableMessage<["decoratorName"]>;
};
}, Record<string, any>>;
declare const reportDiagnostic: <C extends "not-key-type" | "resource-missing-key" | "resource-missing-error" | "duplicate-key" | "duplicate-parent-key" | "invalid-action-name", M extends keyof {
declare const reportDiagnostic: <C extends "not-key-type" | "resource-missing-key" | "resource-missing-error" | "duplicate-key" | "duplicate-parent-key" | "invalid-action-name" | "shared-route-unspecified-action-name", M extends keyof {
"not-key-type": {

@@ -41,2 +44,5 @@ readonly default: "Cannot copy keys from a non-key type (KeysOf<T> or ParentKeysOf<T>)";

};
"shared-route-unspecified-action-name": {
readonly default: import("@typespec/compiler").CallableMessage<["decoratorName"]>;
};
}[C]>(program: import("@typespec/compiler").Program, diag: import("@typespec/compiler").DiagnosticReport<{

@@ -61,3 +67,6 @@ "not-key-type": {

};
}, C, M>) => void, createDiagnostic: <C extends "not-key-type" | "resource-missing-key" | "resource-missing-error" | "duplicate-key" | "duplicate-parent-key" | "invalid-action-name", M extends keyof {
"shared-route-unspecified-action-name": {
readonly default: import("@typespec/compiler").CallableMessage<["decoratorName"]>;
};
}, C, M>) => void, createDiagnostic: <C extends "not-key-type" | "resource-missing-key" | "resource-missing-error" | "duplicate-key" | "duplicate-parent-key" | "invalid-action-name" | "shared-route-unspecified-action-name", M extends keyof {
"not-key-type": {

@@ -81,2 +90,5 @@ readonly default: "Cannot copy keys from a non-key type (KeysOf<T> or ParentKeysOf<T>)";

};
"shared-route-unspecified-action-name": {
readonly default: import("@typespec/compiler").CallableMessage<["decoratorName"]>;
};
}[C]>(diag: import("@typespec/compiler").DiagnosticReport<{

@@ -101,4 +113,7 @@ "not-key-type": {

};
"shared-route-unspecified-action-name": {
readonly default: import("@typespec/compiler").CallableMessage<["decoratorName"]>;
};
}, C, M>) => import("@typespec/compiler").Diagnostic, createStateSymbol: (name: string) => symbol;
export { restLib, reportDiagnostic, createDiagnostic, createStateSymbol };
//# sourceMappingURL=lib.d.ts.map

@@ -41,2 +41,8 @@ import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler";

},
"shared-route-unspecified-action-name": {
severity: "error",
messages: {
default: paramMessage `An operation marked as '@sharedRoute' must have an explicit collection action name passed to '${"decoratorName"}'.`,
},
},
},

@@ -43,0 +49,0 @@ };

@@ -68,5 +68,33 @@ import { DecoratorContext, Interface, Model, ModelProperty, Operation, Program, Scalar, Type } from "@typespec/compiler";

export declare function getActionSegment(program: Program, entity: Type): string | undefined;
/**
* Provides details about an action or collection action.
*/
export interface ActionDetails {
/**
* The name of the action
*/
name: string;
/**
* Identifies whether the action's name was generated from the original
* operation name or if it was explicitly specified.
*/
kind: "automatic" | "specified";
}
export declare function $action(context: DecoratorContext, entity: Operation, name?: string): void;
/**
* Gets the ActionDetails for the specified operation if it has previously been marked with @action.
*/
export declare function getActionDetails(program: Program, operation: Operation): ActionDetails | undefined;
/**
* @deprecated Use getActionDetails instead.
*/
export declare function getAction(program: Program, operation: Operation): string | null | undefined;
export declare function $collectionAction(context: DecoratorContext, entity: Operation, resourceType: Model, name?: string): void;
/**
* Gets the ActionDetails for the specified operation if it has previously been marked with @collectionAction.
*/
export declare function getCollectionActionDetails(program: Program, operation: Operation): ActionDetails | undefined;
/**
* @deprecated Use getCollectionActionDetails instead.
*/
export declare function getCollectionAction(program: Program, operation: Operation): string | null | undefined;

@@ -73,0 +101,0 @@ export declare function $resourceLocation(context: DecoratorContext, entity: Model, resourceType: Model): void;

@@ -37,3 +37,5 @@ import { $list, createDiagnosticCollector, setTypeSpecNamespace, } from "@typespec/compiler";

const resourceOperation = getResourceOperation(program, operation);
return ((_b = (_a = getOperationVerb(program, operation)) !== null && _a !== void 0 ? _a : (resourceOperation && resourceOperationToVerb[resourceOperation.operation])) !== null && _b !== void 0 ? _b : (getAction(program, operation) || getCollectionAction(program, operation) ? "post" : undefined));
return ((_b = (_a = getOperationVerb(program, operation)) !== null && _a !== void 0 ? _a : (resourceOperation && resourceOperationToVerb[resourceOperation.operation])) !== null && _b !== void 0 ? _b : (getActionDetails(program, operation) || getCollectionActionDetails(program, operation)
? "post"
: undefined));
}

@@ -271,3 +273,6 @@ function autoRouteProducer(program, operation, parentSegments, overloadBase, options) {

function makeActionName(op, name) {
return lowerCaseFirstChar(name || op.name);
return {
name: lowerCaseFirstChar(name || op.name),
kind: name ? "specified" : "automatic",
};
}

@@ -291,8 +296,18 @@ const actionsSegmentKey = createStateSymbol("actionSegment");

const action = makeActionName(entity, name);
context.call($actionSegment, entity, action);
context.call($actionSegment, entity, action.name);
context.program.stateMap(actionsKey).set(entity, action);
}
export function getAction(program, operation) {
/**
* Gets the ActionDetails for the specified operation if it has previously been marked with @action.
*/
export function getActionDetails(program, operation) {
return program.stateMap(actionsKey).get(operation);
}
/**
* @deprecated Use getActionDetails instead.
*/
export function getAction(program, operation) {
var _a;
return (_a = getActionDetails(program, operation)) === null || _a === void 0 ? void 0 : _a.name;
}
const collectionActionsKey = createStateSymbol("collectionActions");

@@ -310,8 +325,20 @@ export function $collectionAction(context, entity, resourceType, name) {

const action = makeActionName(entity, name);
context.call($actionSegment, entity, action);
context.program.stateMap(collectionActionsKey).set(entity, `${segment}/${action}`);
context.call($actionSegment, entity, action.name);
// Update the final name and store it
action.name = `${segment}/${action.name}`;
context.program.stateMap(collectionActionsKey).set(entity, action);
}
export function getCollectionAction(program, operation) {
/**
* Gets the ActionDetails for the specified operation if it has previously been marked with @collectionAction.
*/
export function getCollectionActionDetails(program, operation) {
return program.stateMap(collectionActionsKey).get(operation);
}
/**
* @deprecated Use getCollectionActionDetails instead.
*/
export function getCollectionAction(program, operation) {
var _a;
return (_a = getCollectionActionDetails(program, operation)) === null || _a === void 0 ? void 0 : _a.name;
}
const resourceLocationsKey = createStateSymbol("resourceLocations");

@@ -318,0 +345,0 @@ export function $resourceLocation(context, entity, resourceType) {

import { DuplicateTracker, getKeyName, getTypeName, listServices, navigateTypesInNamespace, } from "@typespec/compiler";
import { isSharedRoute } from "@typespec/http";
import { reportDiagnostic } from "./lib.js";
import { getParentResource, getResourceTypeKey } from "./resource.js";
import { getActionDetails, getCollectionActionDetails } from "./rest.js";
function checkForDuplicateResourceKeyNames(program) {

@@ -49,2 +51,26 @@ const seenTypes = new Set();

}
function checkForSharedRouteUnnamedActions(program) {
for (const service of listServices(program)) {
// If the model type is defined under the service namespace, check that the
// parent resource type(s) don't have the same key name as the
// current resource type.
navigateTypesInNamespace(service.type, {
operation: (op) => {
var _a;
const actionDetails = getActionDetails(program, op);
if (isSharedRoute(program, op) &&
((actionDetails === null || actionDetails === void 0 ? void 0 : actionDetails.kind) === "automatic" ||
((_a = getCollectionActionDetails(program, op)) === null || _a === void 0 ? void 0 : _a.kind) === "automatic")) {
reportDiagnostic(program, {
code: "shared-route-unspecified-action-name",
target: op,
format: {
decoratorName: actionDetails ? "@action" : "@collectionAction",
},
});
}
},
});
}
}
export function $onValidate(program) {

@@ -54,3 +80,6 @@ // Make sure any defined resource types don't have any conflicts with parent

checkForDuplicateResourceKeyNames(program);
// Ensure that all shared routes with an `@action` decorator have an
// explicitly named action
checkForSharedRouteUnnamedActions(program);
}
//# sourceMappingURL=validate.js.map

2

package.json
{
"name": "@typespec/rest",
"version": "0.44.0-dev.2",
"version": "0.44.0-dev.4",
"author": "Microsoft Corporation",

@@ -5,0 +5,0 @@ "description": "TypeSpec REST protocol binding",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc