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

@atomist/rug

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atomist/rug - npm Package Compare versions

Comparing version 1.0.0-m.3 to 1.0.0-m.4

operations/GitProjectLoader.js

10

model/Core.ts

@@ -25,3 +25,2 @@ /*

import { CommonViewOperations } from "./CommonViewOperations";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { Directory } from "./Directory";

@@ -35,4 +34,2 @@ import { DockerFile } from "./DockerFile";

import { FileUpdate } from "./FileUpdate";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { Impact } from "./Impact";

@@ -48,4 +45,2 @@ import { JavaClassOrInterface } from "./JavaClassOrInterface";

import { Line } from "./Line";
import { MutableContainer } from "./MutableContainer";
import { MutableTerminal } from "./MutableTerminal";
import { MutableView } from "./MutableView";

@@ -78,3 +73,2 @@ import { OverwritableText } from "./OverwritableText";

export { CommonViewOperations };
export { ContainerTreeNodeView };
export { Directory };

@@ -88,4 +82,2 @@ export { DockerFile };

export { FileUpdate };
export { FormatInfoProvider };
export { FormatInfoProviderSupport };
export { Impact };

@@ -101,4 +93,2 @@ export { JavaClassOrInterface };

export { Line };
export { MutableContainer };
export { MutableTerminal };
export { MutableView };

@@ -105,0 +95,0 @@ export { OverwritableText };

42

model/CSharpFile.ts

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { CSharpFile };

@@ -31,20 +27,33 @@

*/
interface CSharpFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface CSharpFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { JavaFile };

@@ -31,20 +27,33 @@

*/
interface JavaFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface JavaFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -63,3 +63,10 @@ /*

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -19,3 +19,3 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { FileArtifactBacked } from "./FileArtifactBacked";
import { File } from "./File";
import { Project } from "./Project";

@@ -80,5 +80,5 @@

*
* @property {FileArtifactBacked[]} files
* @property {File[]} files
*/
readonly files: FileArtifactBacked[];
readonly files: File[];

@@ -85,0 +85,0 @@ /**

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { PythonFile };

@@ -31,20 +27,33 @@

*/
interface PythonFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface PythonFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { ScalaFile };

@@ -31,20 +27,33 @@

*/
interface ScalaFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface ScalaFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { XmlFile };

@@ -31,20 +27,33 @@

*/
interface XmlFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface XmlFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -19,8 +19,4 @@ /*

import { ProjectContext } from "@atomist/rug/operations/ProjectEditor";
import { ContainerTreeNodeView } from "./ContainerTreeNodeView";
import { FormatInfoProviderSupport } from "./FormatInfoProviderSupport";
import { FormatInfoProvider } from "./FormatInfoProvider";
import { CommonViewOperations } from "./CommonViewOperations";
import { MutableView } from "./MutableView";
export { YamlFile };

@@ -31,20 +27,33 @@

*/
interface YamlFile extends ContainerTreeNodeView, FormatInfoProviderSupport, FormatInfoProvider, CommonViewOperations, MutableView {
interface YamlFile extends TreeNode {
/**
* Append
* Children
*
* @param arg0 {string}
* @returns {TreeNode[]}
*/
append(arg0: string): void;
children(): TreeNode[];
/**
* Set the value of the given key
* Return the format info for the start of this structure in the file or null if not available
*
* @param key {string} The match key whose content you want
* @param value {string} The new value
* @property {FormatInfo} formatInfo
*/
set(key: string, value: string): void;
readonly formatInfo: FormatInfo;
/**
* Tags attached to the node
*
* @returns {string[]}
*/
nodeType(): string[];
/**
* Return the parent node
*
* @returns {TreeNode}
*/
parent(): TreeNode;
/**
* Update the whole value

@@ -56,3 +65,10 @@ *

/**
* Node content
*
* @returns {string}
*/
value(): string;
}

@@ -11,9 +11,13 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
// used by annotation functions
function set_metadata(obj, key, value) {
Object.defineProperty(obj, key, {
var target = obj;
if (obj.prototype !== undefined) {
// should only be true for class Decorators
target = obj.prototype;
}
Object.defineProperty(target, key, {
value: value,
writable: false,
enumerable: false,
configurable: true,
configurable: false,
});

@@ -36,14 +40,19 @@ }

return function (target, propertyKey) {
var params = get_metadata(target, "__parameters");
if (params == null) {
params = [];
}
var copy = __assign({}, details);
copy.name = propertyKey;
copy.decorated = true;
params.push(copy);
set_metadata(target, "__parameters", params);
declareParameter(target, propertyKey, details);
};
}
exports.Parameter = Parameter;
function declareParameter(target, propertyKey, details) {
var params = get_metadata(target, "__parameters");
if (params == null) {
params = [];
}
var copy = __assign({}, details);
copy.name = propertyKey;
copy.decorated = true;
params.push(copy);
set_metadata(target, "__parameters", params);
return target;
}
exports.declareParameter = declareParameter;
/**

@@ -54,59 +63,151 @@ * Map a local field to some other configuration item in a different system

return function (target, localKey) {
var params = get_metadata(target, "__mappedParameters");
if (params == null) {
params = [];
declareMappedParameter(target, localKey, foreignKey);
};
}
exports.MappedParameter = MappedParameter;
function declareMappedParameter(target, localKey, foreignKey) {
var params = get_metadata(target, "__mappedParameters");
if (params == null) {
params = [];
}
var param = { localKey: localKey, foreignKey: foreignKey };
params.push(param);
set_metadata(target, "__mappedParameters", params);
return target;
}
exports.declareMappedParameter = declareMappedParameter;
function ResponseHandler(nameOrDescription, description) {
return function (obj) {
// for backwards compatibility
if (description === undefined) {
declareResponseHandler(obj, nameOrDescription);
}
var param = { localKey: localKey, foreignKey: foreignKey };
params.push(param);
set_metadata(target, "__mappedParameters", params);
else {
declareResponseHandler(obj, description, nameOrDescription);
}
};
}
exports.MappedParameter = MappedParameter;
exports.ResponseHandler = ResponseHandler;
function declareResponseHandler(obj, description, name) {
declareRug(obj, "response-handler", description, name);
return obj;
}
exports.declareResponseHandler = declareResponseHandler;
function CommandHandler(nameOrDescription, description) {
return function (obj) {
// for backwards compatibility
if (description === undefined) {
declareCommandHandler(obj, nameOrDescription);
}
else {
declareCommandHandler(obj, description, nameOrDescription);
}
};
}
exports.CommandHandler = CommandHandler;
function IntegrationTest(description) {
return function (obj) {
if (typeof description === "string") {
declareCommandHandler(obj, description);
declareIntegrationTest(obj, { description: description, kind: "integration" });
}
else {
declareCommandHandler(obj, description.description);
declareIntegrationTest(obj, description);
}
};
}
exports.IntegrationTest = IntegrationTest;
/**
* Decorator for editors. Use this instead of implementing the editor interface.
* Describe to whom this rug is visible (not to be confused by ACLs)
* This stuff is not enforced, but specifies developer intent.
*
* @param obj - a rug
* @param scope
*/
function ruglike(fn, kind, msg) {
return function (nameOrDescription, description) {
// tslint:disable-next-line:ban-types
return function (ctr) {
if (typeof ctr.prototype[fn] !== "function") {
throw new Error("" + msg);
}
if (description === undefined) {
set_metadata(ctr.prototype, "__description", nameOrDescription);
}
else {
set_metadata(ctr.prototype, "__description", description);
set_metadata(ctr.prototype, "__name", nameOrDescription);
}
ctr.prototype.__kind = kind;
};
function setScope(obj, scope) {
set_metadata(obj, "__scope", scope);
return obj;
}
exports.setScope = setScope;
function declareIntegrationTest(obj, descriptor) {
set_metadata(obj, "__test", descriptor);
}
exports.declareIntegrationTest = declareIntegrationTest;
function declareCommandHandler(obj, description, name) {
declareRug(obj, "command-handler", description, name);
return obj;
}
exports.declareCommandHandler = declareCommandHandler;
function Generator(nameOrDescription, description) {
return function (obj) {
// for backwards compatibility
if (description === undefined) {
declareGenerator(obj, nameOrDescription);
}
else {
declareGenerator(obj, description, nameOrDescription);
}
};
}
var Generator = ruglike("populate", "generator", "populate must be a function with first parameter = Project");
exports.Generator = Generator;
var Editor = ruglike("edit", "editor", "edit must be a function with first parameter = Project");
function declareGenerator(obj, description, name) {
declareRug(obj, "generator", description, name);
return obj;
}
exports.declareGenerator = declareGenerator;
function Editor(nameOrDescription, description) {
return function (obj) {
// for backwards compatibility
if (description === undefined) {
declareEditor(obj, nameOrDescription);
}
else {
declareEditor(obj, description, nameOrDescription);
}
};
}
exports.Editor = Editor;
var CommandHandler = ruglike("handle", "command-handler", "handle must be a function with first parameter = HandlerContext");
exports.CommandHandler = CommandHandler;
var ResponseHandler = ruglike("handle", "response-handler", "handle must be a function with first parameter = Response<T>");
exports.ResponseHandler = ResponseHandler;
var EventHandler = function (name, description, expression) {
// tslint:disable-next-line:ban-types
return function (ctr) {
if (typeof ctr.prototype.handle !== "function") {
throw new Error("handle must be a function with first parameter = Match<R,N>");
function declareEditor(obj, description, name) {
declareRug(obj, "editor", description, name);
return obj;
}
exports.declareEditor = declareEditor;
function declareRug(obj, kind, description, name) {
if (name === undefined) {
set_metadata(obj, "__description", description);
}
else {
set_metadata(obj, "__description", description);
set_metadata(obj, "__name", name);
}
set_metadata(obj, "__kind", kind);
}
function EventHandler(nameOrDescription, descriptionOrExpression, expression) {
return function (obj) {
if (expression !== undefined) {
if (typeof descriptionOrExpression === "string") {
declareEventHandler(obj, descriptionOrExpression, expression, nameOrDescription);
}
else {
throw Error("When three parameters are passed, the second must be a description");
}
}
set_metadata(ctr.prototype, "__name", name);
set_metadata(ctr.prototype, "__description", description);
set_metadata(ctr.prototype, "__kind", "event-handler");
if (typeof expression === "string") {
set_metadata(ctr.prototype, "__expression", expression);
}
else {
set_metadata(ctr.prototype, "__expression", expression.expression);
declareEventHandler(obj, nameOrDescription, descriptionOrExpression);
}
};
};
}
exports.EventHandler = EventHandler;
function declareEventHandler(obj, description, expression, name) {
declareRug(obj, "event-handler", description, name);
if (typeof expression === "string") {
set_metadata(obj, "__expression", expression);
}
else {
set_metadata(obj, "__expression", expression.expression);
}
return obj;
}
exports.declareEventHandler = declareEventHandler;
/**

@@ -121,6 +222,11 @@ * Decorator for tags. Sets tags on the class

return function (target) {
set_metadata(target.prototype, "__tags", tags);
declareTags(target, tags);
};
}
exports.Tags = Tags;
function declareTags(target, tags) {
set_metadata(target, "__tags", tags);
return target;
}
exports.declareTags = declareTags;
function Intent() {

@@ -132,6 +238,11 @@ var intent = [];

return function (target) {
set_metadata(target.prototype, "__intent", intent);
declareIntent(target, intent);
};
}
exports.Intent = Intent;
function declareIntent(target, intent) {
set_metadata(target, "__intent", intent);
return target;
}
exports.declareIntent = declareIntent;
function Secrets() {

@@ -143,10 +254,11 @@ var secrets = [];

return function (target) {
var current = get_metadata(target.prototype, "__secrets");
if (current == null) {
current = [];
}
set_metadata(target.prototype, "__secrets", current.concat(secrets));
declareSecrets(target, secrets);
};
}
exports.Secrets = Secrets;
function declareSecrets(target, secrets) {
set_metadata(target, "__secrets", secrets);
return target;
}
exports.declareSecrets = declareSecrets;
// for parameters to ResponseHandlers to do response body coercion

@@ -153,0 +265,0 @@ function ParseJson(target, propertyKey, parameterIndex) {

import { PathExpression } from "../tree/PathExpression";
import { BaseParameter } from "./RugOperation";
// used by annotation functions
function set_metadata(obj: any, key: string, value: any) {
Object.defineProperty(obj, key,
let target = obj;
if (obj.prototype !== undefined) {
// should only be true for class Decorators
target = obj.prototype;
}
Object.defineProperty(target, key,
{

@@ -12,3 +15,3 @@ value,

enumerable: false,
configurable: true,
configurable: false,
});

@@ -31,88 +34,180 @@ }

*/
function Parameter(details: BaseParameter) {
export function Parameter(details: BaseParameter) {
return (target: any, propertyKey: string) => {
let params = get_metadata(target, "__parameters");
if (params == null) {
params = [];
}
const copy: any = { ...details };
copy.name = propertyKey;
copy.decorated = true;
params.push(copy);
set_metadata(target, "__parameters", params);
declareParameter(target, propertyKey, details);
};
}
export function declareParameter(target: any, propertyKey: string, details: BaseParameter) {
let params = get_metadata(target, "__parameters");
if (params == null) {
params = [];
}
const copy: any = { ...details };
copy.name = propertyKey;
copy.decorated = true;
params.push(copy);
set_metadata(target, "__parameters", params);
return target;
}
/**
* Map a local field to some other configuration item in a different system
*/
function MappedParameter(foreignKey: string) {
export function MappedParameter(foreignKey: string) {
return (target: any, localKey: string) => {
let params = get_metadata(target, "__mappedParameters");
if (params == null) {
params = [];
declareMappedParameter(target, localKey, foreignKey);
};
}
export function declareMappedParameter(target: any, localKey: string, foreignKey: string) {
let params = get_metadata(target, "__mappedParameters");
if (params == null) {
params = [];
}
const param = { localKey, foreignKey };
params.push(param);
set_metadata(target, "__mappedParameters", params);
return target;
}
export function ResponseHandler(nameOrDescription: string, description?: string) {
return (obj: object) => {
// for backwards compatibility
if (description === undefined) {
declareResponseHandler(obj, nameOrDescription);
} else {
declareResponseHandler(obj, description, nameOrDescription);
}
const param = { localKey, foreignKey };
params.push(param);
set_metadata(target, "__mappedParameters", params);
};
}
export function declareResponseHandler(obj: object, description: string, name?: string) {
declareRug(obj, "response-handler", description, name);
return obj;
}
export function CommandHandler(nameOrDescription: string, description?: string) {
return (obj: any) => {
// for backwards compatibility
if (description === undefined) {
declareCommandHandler(obj, nameOrDescription);
} else {
declareCommandHandler(obj, description, nameOrDescription);
}
};
}
type TestKind = "integration";
interface TestDescriptor {
description: string;
kind: TestKind;
}
export function IntegrationTest(description: string | TestDescriptor) {
return (obj: any) => {
if (typeof description === "string") {
declareCommandHandler(obj, description);
declareIntegrationTest(obj, { description, kind: "integration" });
} else {
declareCommandHandler(obj, description.description);
declareIntegrationTest(obj, description);
}
};
}
/**
* Decorator for editors. Use this instead of implementing the editor interface.
* Describe to whom this rug is visible (not to be confused by ACLs)
* This stuff is not enforced, but specifies developer intent.
*
* @param obj - a rug
* @param scope
*/
export function setScope(obj: any, scope: Scope) {
set_metadata(obj, "__scope", scope);
return obj;
}
type Scope = "archive";
function ruglike(fn: string, kind: string, msg: string) {
return (nameOrDescription: string, description?: string) => {
// tslint:disable-next-line:ban-types
return (ctr: Function) => {
if (typeof ctr.prototype[fn] !== "function") {
throw new Error(`${msg}`);
}
if (description === undefined) {
set_metadata(ctr.prototype, "__description", nameOrDescription);
} else {
set_metadata(ctr.prototype, "__description", description);
set_metadata(ctr.prototype, "__name", nameOrDescription);
}
ctr.prototype.__kind = kind;
};
export function declareIntegrationTest(obj: any, descriptor: TestDescriptor) {
set_metadata(obj, "__test", descriptor);
}
export function declareCommandHandler(obj: any, description: string, name?: string) {
declareRug(obj, "command-handler", description, name);
return obj;
}
export function Generator(nameOrDescription: string, description?: string) {
return (obj: any) => {
// for backwards compatibility
if (description === undefined) {
declareGenerator(obj, nameOrDescription);
} else {
declareGenerator(obj, description, nameOrDescription);
}
};
}
const Generator = ruglike(
"populate",
"generator",
"populate must be a function with first parameter = Project");
export function declareGenerator(obj: any, description: string, name?: string) {
declareRug(obj, "generator", description, name);
return obj;
}
const Editor = ruglike(
"edit",
"editor",
"edit must be a function with first parameter = Project");
export function Editor(nameOrDescription: string, description?: string) {
return (obj: object) => {
// for backwards compatibility
if (description === undefined) {
declareEditor(obj, nameOrDescription);
} else {
declareEditor(obj, description, nameOrDescription);
}
};
}
const CommandHandler = ruglike(
"handle",
"command-handler",
"handle must be a function with first parameter = HandlerContext");
const ResponseHandler = ruglike(
"handle",
"response-handler",
"handle must be a function with first parameter = Response<T>");
export function declareEditor(obj: object, description: string, name?: string) {
declareRug(obj, "editor", description, name);
return obj;
}
const EventHandler = (name: string, description: string, expression: PathExpression<any, any> | string) => {
// tslint:disable-next-line:ban-types
return (ctr: Function) => {
if (typeof ctr.prototype.handle !== "function") {
throw new Error("handle must be a function with first parameter = Match<R,N>");
}
set_metadata(ctr.prototype, "__name", name);
set_metadata(ctr.prototype, "__description", description);
set_metadata(ctr.prototype, "__kind", "event-handler");
if (typeof expression === "string") {
set_metadata(ctr.prototype, "__expression", expression);
type RugKind = "editor" | "generator" | "command-handler" | "response-handler" | "event-handler";
function declareRug(obj: any, kind: RugKind, description: string, name?: string) {
if (name === undefined) {
set_metadata(obj, "__description", description);
} else {
set_metadata(obj, "__description", description);
set_metadata(obj, "__name", name);
}
set_metadata(obj, "__kind", kind);
}
export function EventHandler(
nameOrDescription: string,
descriptionOrExpression: string | PathExpression<any, any>,
expression?: PathExpression<any, any> | string) {
return (obj: object) => {
if (expression !== undefined) {
if (typeof descriptionOrExpression === "string") {
declareEventHandler(obj, descriptionOrExpression, expression, nameOrDescription);
} else {
throw Error("When three parameters are passed, the second must be a description");
}
} else {
set_metadata(ctr.prototype, "__expression", expression.expression);
declareEventHandler(obj, nameOrDescription, descriptionOrExpression);
}
};
};
}
export function declareEventHandler(
obj: any, description: string, expression: string | PathExpression<any, any>, name?: string) {
declareRug(obj, "event-handler", description, name);
if (typeof expression === "string") {
set_metadata(obj, "__expression", expression);
} else {
set_metadata(obj, "__expression", expression.expression);
}
return obj;
}
/**

@@ -122,32 +217,38 @@ * Decorator for tags. Sets tags on the class

function Tags(...tags: string[]) {
export function Tags(...tags: string[]) {
return (target: any) => {
set_metadata(target.prototype, "__tags", tags);
declareTags(target, tags);
};
}
function Intent(...intent: string[]) {
export function declareTags(target: any, tags: string[]) {
set_metadata(target, "__tags", tags);
return target;
}
export function Intent(...intent: string[]) {
return (target: any) => {
set_metadata(target.prototype, "__intent", intent);
declareIntent(target, intent);
};
}
function Secrets(...secrets: string[]) {
export function declareIntent(target: any, intent: string[]) {
set_metadata(target, "__intent", intent);
return target;
}
export function Secrets(...secrets: string[]) {
return (target: any) => {
let current = get_metadata(target.prototype, "__secrets");
if (current == null) {
current = [];
}
set_metadata(target.prototype, "__secrets", current.concat(secrets));
declareSecrets(target, secrets);
};
}
export function declareSecrets(target: any, secrets: string[]) {
set_metadata(target, "__secrets", secrets);
return target;
}
// for parameters to ResponseHandlers to do response body coercion
function ParseJson(target: object, propertyKey: string | symbol, parameterIndex: number) {
export function ParseJson(target: object, propertyKey: string | symbol, parameterIndex: number) {
set_metadata(target, "__coercion", "JSON");
}
export { Parameter, Secrets, Tags, Intent, MappedParameter };
export { Editor, Generator };
export { ParseJson };
export { ResponseHandler, CommandHandler, EventHandler };

@@ -31,2 +31,8 @@ "use strict";

exports.Presentable = Presentable;
var Identifiable = (function () {
function Identifiable() {
}
return Identifiable;
}());
exports.Identifiable = Identifiable;
/**

@@ -45,3 +51,3 @@ * Get an editor instruction to run a GitHub Pull Request

/**
* Get an editor instruction to run a GitHub Pull Request
* Get an editor instruction to run on a new GitHub branch
*/

@@ -220,8 +226,11 @@ var GitHubBranch = (function () {

}());
// GITHUB_REPO_OWNER is deprecated; instead use GITHUB_OWNER
MappedParameters.GITHUB_REPO_OWNER = "atomist://github/repository/owner";
MappedParameters.GITHUB_OWNER = "atomist://github/repository/owner";
MappedParameters.GITHUB_REPOSITORY = "atomist://github/repository";
MappedParameters.GITHUB_WEBHOOK_URL = "atomist://github_webhook_url";
MappedParameters.GITHUB_API_URL = "atomist://github_api_url";
MappedParameters.SLACK_CHANNEL = "atomist://slack/channel";
MappedParameters.SLACK_TEAM = "atomist://slack/team";
MappedParameters.SLACK_USER = "atomist://slack/user";
MappedParameters.GITHUB_WEBHOOK_URL = "atomist://github_webhook_url";
exports.MappedParameters = MappedParameters;

@@ -42,2 +42,7 @@ import {

export class Identifiable<T extends InstructionKind> {
public instruction: Instruction<T> | PresentableGenerate | PresentableEdit;
public id?: string;
}
// Location to a project.

@@ -73,3 +78,3 @@ // in the future, we could add things like github urls, orgs etc.

/**
* Get an editor instruction to run a GitHub Pull Request
* Get an editor instruction to run on a new GitHub branch
*/

@@ -83,2 +88,3 @@ export class GitHubBranch implements EditorTarget<"github-branch"> {

target?: EditorTarget<EditorTargetKind>;
commitMessage?: string;
}

@@ -116,3 +122,3 @@

export interface HandleResponse<T> {
handle(response: Response<T>): EventPlan | CommandPlan;
handle(response: Response<T>, ctx?: HandlerContext): EventPlan | CommandPlan;
}

@@ -229,3 +235,3 @@

public body: string;
public instructions?: Array<Presentable<any>> = [];
public instructions?: Array<Identifiable<any>> = [];

@@ -241,3 +247,3 @@ public addAddress?(address: MessageAddress): this {

public addAction?(instruction: Presentable<any>): this {
public addAction?(instruction: Identifiable<any>): this {
this.instructions.push(instruction);

@@ -313,8 +319,12 @@ return this;

export abstract class MappedParameters {
// GITHUB_REPO_OWNER is deprecated; instead use GITHUB_OWNER
public static readonly GITHUB_REPO_OWNER: string = "atomist://github/repository/owner";
public static readonly GITHUB_OWNER: string = "atomist://github/repository/owner";
public static readonly GITHUB_REPOSITORY: string = "atomist://github/repository";
public static readonly GITHUB_WEBHOOK_URL: string = "atomist://github_webhook_url";
public static readonly GITHUB_API_URL: string = "atomist://github_api_url";
public static readonly SLACK_CHANNEL: string = "atomist://slack/channel";
public static readonly SLACK_TEAM: string = "atomist://slack/team";
public static readonly SLACK_USER: string = "atomist://slack/user";
public static readonly GITHUB_WEBHOOK_URL: string = "atomist://github_webhook_url";
}

@@ -18,1 +18,14 @@ "use strict";

exports.createEventHandler = createEventHandler;
function createCommandHandler(name, description, handle, tags, intent) {
if (tags === void 0) { tags = []; }
if (intent === void 0) { intent = []; }
return {
__kind: "command-handler",
__name: name,
__description: description,
__tags: tags,
__intent: intent,
handle: handle,
};
}
exports.createCommandHandler = createCommandHandler;
import { Match } from "../tree/PathExpression";
import { EventPlan } from "./Handlers";
import { HandlerContext, CommandPlan, EventPlan } from "./Handlers";

@@ -19,1 +19,15 @@ /**

}
export function createCommandHandler(name: string, description: string,
handle: (HandlerContext) => CommandPlan,
tags: string[] = [],
intent: string[] = []) {
return {
__kind: "command-handler",
__name: name,
__description: description,
__tags: tags,
__intent: intent,
handle,
};
}
import { Project } from "../model/Core";
import { PathExpressionEngine } from "../tree/PathExpression";
import { RugOperation } from "./RugOperation";
import { GitProjectLoader } from "./GitProjectLoader";

@@ -11,2 +11,13 @@ export interface ProjectContext {

pathExpressionEngine: PathExpressionEngine;
/**
* RepoResolver to use in loading repositories.
*/
gitProjectLoader: GitProjectLoader;
/**
* Create an empty project
*/
emptyProject();
}

@@ -21,8 +32,1 @@

}
/**
* Edits projects
*/
export interface ProjectEditor extends RugOperation, EditProject {
}
import { Project } from "../model/Core";
import { RugOperation } from "./RugOperation";
interface PopulateProject {
export interface PopulateProject {
populate(emptyProject: Project, params?: {});
}
/**
* Top level interface for all project generators
*/
interface ProjectGenerator extends RugOperation, PopulateProject {
}
export { ProjectGenerator, PopulateProject };

@@ -11,3 +11,3 @@ "use strict";

}());
Pattern.url = "@java_package";
Pattern.url = "@url";
Pattern.any = "@any";

@@ -14,0 +14,0 @@ // tslint:disable-next-line:variable-name

@@ -17,3 +17,3 @@ import { PathExpression, PathExpressionEngine } from "../tree/PathExpression";

abstract class Pattern {
public static url: string = "@java_package";
public static url: string = "@url";
public static any: string = "@any";

@@ -54,3 +54,2 @@ // tslint:disable-next-line:variable-name

readonly minLength?: number;
readonly tags?: string[];
}

@@ -57,0 +56,0 @@

{
"name": "@atomist/rug",
"version": "1.0.0-m.3",
"version": "1.0.0-m.4",
"description": "TypeScript model for Atomist Rugs, see http://docs.atomist.com/",

@@ -5,0 +5,0 @@ "repository": {

@@ -36,2 +36,7 @@ /*

/**
* Return a distinct project instance that contains all the files from the initial project.
*/
projectStartingWith(project: Project): Project;
/**
* Add this node to the root context so it can

@@ -42,3 +47,10 @@ * be matched by path expressions other than event handler expressions

setRootContext(n: GraphNode): void;
/**
* May be null if setRootContext has not been called
*/
getRootContext(): GraphNode;
/**
* Define the given repo

@@ -45,0 +57,0 @@ */

@@ -18,5 +18,5 @@ /*

import { Project } from "../../model/Project";
import { ProjectEditor } from "../../operations/ProjectEditor";
import { ProjectGenerator } from "../../operations/ProjectGenerator";
import { Result } from "../Result";
import { EditProject } from "../../operations/ProjectEditor"
import { PopulateProject } from "../../operations/ProjectGenerator"
import { ScenarioWorld } from "../ScenarioWorld";

@@ -39,3 +39,3 @@ import "./WellKnownSteps";

*/
editor(name: string): ProjectEditor;
editor(name: string): EditProject;

@@ -45,3 +45,3 @@ /**

*/
generator(name: string): ProjectGenerator;
generator(name: string): PopulateProject;

@@ -51,3 +51,3 @@ /**

*/
editWith(ed: ProjectEditor, params: {});
editWith(ed: EditProject, params?: {});

@@ -57,3 +57,3 @@ /**

*/
generateWith(gen: ProjectGenerator, projectName: string, params: {});
generateWith(gen: PopulateProject, projectName: string, params?: {});

@@ -60,0 +60,0 @@ /**

@@ -13,14 +13,1 @@ "use strict";

exports.PathExpression = PathExpression;
/**
* Dynamic type for a microgrammar. Pass to PathExpression.addType method
*/
var Microgrammar = (function () {
function Microgrammar(name, grammar, submatchers) {
if (submatchers === void 0) { submatchers = {}; }
this.name = name;
this.grammar = grammar;
this.submatchers = submatchers;
}
return Microgrammar;
}());
exports.Microgrammar = Microgrammar;

@@ -1,2 +0,1 @@

import { HandlerContext } from "../operations/Handlers";

@@ -7,8 +6,5 @@

*/
interface Match<R extends GraphNode,N extends GraphNode> extends HandlerContext {
interface Match<R extends GraphNode, N extends GraphNode> extends HandlerContext {
root: R;
matches: N[];
}

@@ -20,3 +16,3 @@

class PathExpression<R extends GraphNode, N extends GraphNode> {
constructor(readonly expression: string) {}
constructor(readonly expression: string) { }
}

@@ -32,3 +28,3 @@

*/
start: PointFormatInfo
start: PointFormatInfo;

@@ -38,3 +34,3 @@ /**

*/
end: PointFormatInfo
end: PointFormatInfo;
}

@@ -50,7 +46,7 @@

*/
offset: number
offset: number;
lineNumberFrom1: number
lineNumberFrom1: number;
columnNumberFrom1: number
columnNumberFrom1: number;

@@ -60,3 +56,3 @@ /**

*/
indentDepth: number
indentDepth: number;

@@ -66,3 +62,3 @@ /**

*/
indent: String
indent: string;
}

@@ -72,5 +68,5 @@

nodeName(): string
nodeName(): string;
nodeTags(): string[]
nodeTags(): string[];

@@ -84,3 +80,3 @@ }

children(): TreeNode[]
children(): TreeNode[];
}

@@ -93,3 +89,3 @@

*/
address(): string
address(): string;
}

@@ -110,3 +106,3 @@

*/
parent(): TreeNode
parent(): TreeNode;
}

@@ -120,6 +116,10 @@

/**
* Information about the position of this node in the current file, if available.
*/
formatInfo: FormatInfo;
/**
* String value of this node. If the node is a container,
* will be built from the values of its descendants.
*/
value(): string
value(): string;

@@ -130,13 +130,9 @@ /**

*/
update(newValue: string): void
update(newValue: string): void;
/**
* Information about the position of this node in the current file, if available.
*/
formatInfo: FormatInfo
}
interface TypeProvider extends DynamicType {
typeName: string
find(context: TreeNode): TreeNode[]
typeName: string;
find(context: TreeNode): TreeNode[];
}

@@ -152,3 +148,3 @@

*/
addType(dt: DynamicType): PathExpressionEngine
addType(dt: DynamicType): PathExpressionEngine;

@@ -159,3 +155,3 @@ /**

evaluate<R extends GraphNode,N extends GraphNode>(root: R, expr: PathExpression<R,N> | string): Match<R,N>
evaluate<R extends GraphNode, N extends GraphNode>(root: R, expr: PathExpression<R, N> | string): Match<R, N>;

@@ -165,3 +161,3 @@ /**

*/
with<N extends GraphNode>(root: GraphNode, expr: PathExpression<GraphNode,N> | string, f: (n: N) => void): void
with<N extends GraphNode>(root: GraphNode, expr: PathExpression<GraphNode, N> | string, f: (n: N) => void): void;

@@ -171,3 +167,3 @@ /**

*/
scalar<R extends GraphNode,N extends GraphNode>(root: R, expr: PathExpression<R,N> | string): N
scalar<R extends GraphNode, N extends GraphNode>(root: R, expr: PathExpression<R, N> | string): N;

@@ -177,3 +173,3 @@ /**

*/
as<N extends GraphNode>(root, name: string): N
as<N extends GraphNode>(root, name: string): N;

@@ -184,3 +180,3 @@ /**

*/
children<N extends GraphNode>(root, name: string): N[]
children<N extends GraphNode>(root, name: string): N[];
}

@@ -191,2 +187,3 @@

*/
// tslint:disable-next-line:no-empty-interface
interface DynamicType {

@@ -196,26 +193,14 @@

import { MicroMatcher } from "./Microgrammars"
/**
* Dynamic type for a microgrammar. Pass to PathExpression.addType method
*/
class Microgrammar implements DynamicType {
constructor(public name: string,
public grammar: string,
public submatchers: {[matcherName: string]: MicroMatcher} = {}) {}
}
export {Match}
export {PathExpression}
export {PathExpressionEngine}
export {GraphNode}
export {Addressed}
export {AddressedGraphNode}
export {TreeNode}
export {ParentAwareTreeNode}
export {TextTreeNode}
export {FormatInfo}
export {DynamicType}
export {PointFormatInfo}
export {TypeProvider}
export {Microgrammar}
export { Match };
export { PathExpression };
export { PathExpressionEngine };
export { GraphNode };
export { Addressed };
export { AddressedGraphNode };
export { TreeNode };
export { ParentAwareTreeNode };
export { TextTreeNode };
export { FormatInfo };
export { DynamicType };
export { PointFormatInfo };
export { TypeProvider };

@@ -49,5 +49,5 @@ "use strict";

};
//-------------------------------------------------------------
// -------------------------------------------------------------
// Additional convenience methods
//-------------------------------------------------------------
// -------------------------------------------------------------
TransformingPathExpressionEngine.prototype.withExpression = function (root, pe, f) {

@@ -54,0 +54,0 @@ this.with(root, pe.expression, f);

import { PathExpressionEngine, PathExpression, Match, DynamicType, GraphNode, TreeNode } from "./PathExpression";
import { DynamicType, GraphNode, Match, PathExpression, PathExpressionEngine, TreeNode } from "./PathExpression";

@@ -11,5 +11,5 @@ /**

constructor(protected delegate: PathExpressionEngine,
private nodeTransform: (TreeNode) => TreeNode) {}
private nodeTransform: (TreeNode) => TreeNode) { }
addType(dt: DynamicType): this {
public addType(dt: DynamicType): this {
this.delegate = this.delegate.addType(dt);

@@ -21,7 +21,7 @@ return this;

// because they're in Scala
evaluate<R extends TreeNode,N extends TreeNode>(root: R, expr: PathExpression<R,N> | string): Match<R,N> {
let m1 = this.delegate.evaluate(root, expr);
let m2 = {
public evaluate<R extends TreeNode, N extends TreeNode>(root: R, expr: PathExpression<R, N> | string): Match<R, N> {
const m1 = this.delegate.evaluate(root, expr);
const m2 = {
root: this.nodeTransform(m1.root) as R,
matches: m1.matches.map(n => this.nodeTransform(n)) as any,
matches: m1.matches.map((n) => this.nodeTransform(n)) as any,
pathExpressionEngine: m1.pathExpressionEngine,

@@ -34,15 +34,15 @@ teamId: m1.teamId,

with<N extends TreeNode>(root: TreeNode, expr: PathExpression<GraphNode,N> | string,
f: (n: N) => void): void {
this.delegate.with(root, expr, n => {
let transformed = this.nodeTransform(n);
f(transformed as N);
})
public with<N extends TreeNode>(root: TreeNode, expr: PathExpression<GraphNode, N> | string,
f: (n: N) => void): void {
this.delegate.with(root, expr, (n) => {
const transformed = this.nodeTransform(n);
f(transformed as N);
});
}
scalar<R extends TreeNode,N extends TreeNode>(root: R, expr: PathExpression<R,N> | string): N {
return this.nodeTransform(this.delegate.scalar<R,N>(root, expr)) as N;
public scalar<R extends TreeNode, N extends TreeNode>(root: R, expr: PathExpression<R, N> | string): N {
return this.nodeTransform(this.delegate.scalar<R, N>(root, expr)) as N;
}
as<N extends TreeNode>(root, name: string): N {
public as<N extends TreeNode>(root, name: string): N {
return this.nodeTransform(this.delegate.as<N>(root, name)) as N;

@@ -52,16 +52,14 @@ }

// Find the children of the current node of this time
children<N extends TreeNode>(root, name: string): N[] {
public children<N extends TreeNode>(root, name: string): N[] {
return this.delegate.children<N>(root, name)
.map(n => this.nodeTransform(n) as N);
.map((n) => this.nodeTransform(n) as N);
}
//-------------------------------------------------------------
// Additional convenience methods
//-------------------------------------------------------------
withExpression<N extends TreeNode>(root: TreeNode, pe: PathExpression<any,N>,
f: (n: N) => void): void {
this.with(root, pe.expression, f);
}
// -------------------------------------------------------------
// Additional convenience methods
// -------------------------------------------------------------
public withExpression<N extends TreeNode>(root: TreeNode, pe: PathExpression<any, N>,
f: (n: N) => void): void {
this.with(root, pe.expression, f);
}
}

@@ -18,3 +18,3 @@ /**

else if (nodeTest(parent)) {
//console.log(`Gotcha: Parent is ${parent}`)
// console.log(`Gotcha: Parent is ${parent}`)
// TODO what if it's not unique - need position, but then parent.children may reinitialize.

@@ -27,8 +27,9 @@ // Not if a mutable container, admittedly

}
else
else {
return null;
}
}
exports.findPathFromAncestor = findPathFromAncestor;
function findPathFromAncestorWithTag(n, tag) {
var r = findPathFromAncestor(n, function (n) { return n.nodeTags().contains(tag); });
var r = findPathFromAncestor(n, function (node) { return node.nodeTags().contains(tag); });
return r;

@@ -47,3 +48,3 @@ }

else if (nodeTest(parent)) {
//console.log(`Gotcha: Parent is ${parent}`)
// console.log(`Gotcha: Parent is ${parent}`)
return parent;

@@ -54,4 +55,5 @@ }

}
else
else {
return null;
}
}

@@ -63,3 +65,3 @@ exports.findAncestor = findAncestor;

function findAncestorWithTag(n, tag) {
var r = findAncestor(n, function (n) { return n.nodeTags().indexOf(tag) != -1; });
var r = findAncestor(n, function (node) { return node.nodeTags().indexOf(tag) !== -1; });
return r;

@@ -69,4 +71,5 @@ }

function nodeAndTagsStringifier(tn) {
if (tn.children().length == 0)
if (tn.children().length === 0) {
return tn.nodeName() + ":[" + tn.value() + "]";
}
return tn.nodeName() + ":[" + tn.nodeTags().join(", ") + "]";

@@ -77,4 +80,5 @@ }

if (maxLen === void 0) { maxLen = 30; }
if (tn.children().length == 0 || tn.value().length < maxLen)
if (tn.children().length === 0 || tn.value().length < maxLen) {
return tn.nodeName() + ":[" + tn.value() + "]";
}
return tn.nodeName() + ":len=" + tn.value().length;

@@ -115,3 +119,3 @@ }

tags: value.nodeTags().join(","),
structure: nodeStringifier(value)
structure: nodeStringifier(value),
};

@@ -124,3 +128,3 @@ }

tags: value.nodeTags().join(","),
toString: value + ""
toString: value + "",
};

@@ -127,0 +131,0 @@ }

@@ -6,33 +6,30 @@ /**

import { TreeNode, TextTreeNode, ParentAwareTreeNode } from "./PathExpression"
import { ParentAwareTreeNode, TextTreeNode, TreeNode } from "./PathExpression";
export function hasTag(n: TreeNode, t: string): boolean {
return n.nodeTags().indexOf(t) > -1
return n.nodeTags().indexOf(t) > -1;
}
export function findPathFromAncestor(n: ParentAwareTreeNode, nodeTest: (TextTreeNode) => boolean): string {
let parent = n.parent() as any // Makes checking for parent function later easy
const parent = n.parent() as any; // Makes checking for parent function later easy
if (parent == null) {
// We couldn't resolve the path
return null
}
else if (nodeTest(parent)) {
//console.log(`Gotcha: Parent is ${parent}`)
return null;
} else if (nodeTest(parent)) {
// console.log(`Gotcha: Parent is ${parent}`)
// TODO what if it's not unique - need position, but then parent.children may reinitialize.
// Not if a mutable container, admittedly
return `/${n.nodeName()}`
return `/${n.nodeName()}`;
} else if (parent.parent()) { // Essentially an instanceof, which we can't do on an interface
return findPathFromAncestor(parent as ParentAwareTreeNode, nodeTest) + `/${n.nodeName()}`;
} else {
return null;
}
else if (parent.parent()) { // Essentially an instanceof, which we can't do on an interface
return findPathFromAncestor(parent as ParentAwareTreeNode, nodeTest) + `/${n.nodeName()}`
}
else
return null
}
export function findPathFromAncestorWithTag(n: ParentAwareTreeNode, tag: String): string {
let r = findPathFromAncestor(
export function findPathFromAncestorWithTag(n: ParentAwareTreeNode, tag: string): string {
const r = findPathFromAncestor(
n,
n => n.nodeTags().contains(tag))
return r
(node) => node.nodeTags().contains(tag));
return r;
}

@@ -45,15 +42,13 @@

export function findAncestor<N extends TreeNode>(n: ParentAwareTreeNode, nodeTest: (N) => boolean): N {
let parent = n.parent() as any // Makes checking for parent function later easy
const parent = n.parent() as any; // Makes checking for parent function later easy
if (parent == null) {
return null
return null;
} else if (nodeTest(parent)) {
// console.log(`Gotcha: Parent is ${parent}`)
return parent as N;
} else if (parent.parent()) { // Essentially an instanceof, which we can't do on an interface
return findAncestor(parent as ParentAwareTreeNode, nodeTest) as N;
} else {
return null;
}
else if (nodeTest(parent)) {
//console.log(`Gotcha: Parent is ${parent}`)
return parent as N
}
else if (parent.parent()) { // Essentially an instanceof, which we can't do on an interface
return findAncestor(parent as ParentAwareTreeNode, nodeTest) as N
}
else
return null
}

@@ -65,16 +60,15 @@

export function findAncestorWithTag<N extends TreeNode>(n: ParentAwareTreeNode, tag: string): N {
let r = findAncestor<N>(
const r = findAncestor<N>(
n,
n => n.nodeTags().indexOf(tag) != -1
)
return r
(node) => node.nodeTags().indexOf(tag) !== -1,
);
return r;
}
export type NodeStringifier = (TextTreeNode) => string;
export type NodeStringifier = (TextTreeNode) => string
export function nodeAndTagsStringifier(tn: TextTreeNode): string {
if (tn.children().length == 0)
return `${tn.nodeName()}:[${tn.value()}]`;
if (tn.children().length === 0) {
return `${tn.nodeName()}:[${tn.value()}]`;
}
return `${tn.nodeName()}:[${tn.nodeTags().join(", ")}]`;

@@ -84,30 +78,28 @@ }

export function nodeAndValueStringifier(tn: TextTreeNode, maxLen: number = 30): string {
if (tn.children().length == 0 || tn.value().length < maxLen)
return `${tn.nodeName()}:[${tn.value()}]`;
if (tn.children().length === 0 || tn.value().length < maxLen) {
return `${tn.nodeName()}:[${tn.value()}]`;
}
return `${tn.nodeName()}:len=${tn.value().length}`;
}
function stringifyInternal(tn: TextTreeNode, nodeStringifier: NodeStringifier): string[] {
const shorterString = nodeStringifier(tn)
const shorterString = nodeStringifier(tn);
const lines = [ shorterString ].concat(
const lines = [shorterString].concat(
// oh for flatMap...
flatten(tn.children()
.filter(k => (<TextTreeNode> k).value().length > 0)
.map(k => stringifyInternal(k as TextTreeNode, nodeStringifier)))
.filter((k) => (k as TextTreeNode).value().length > 0)
.map((k) => stringifyInternal(k as TextTreeNode, nodeStringifier))),
);
return lines.filter(l => l.length > 0).map(l => " " + l);
return lines.filter((l) => l.length > 0).map((l) => " " + l);
}
// TODO move to a utility module
export const flatten = arr => arr.reduce(
(acc, val) => acc.concat(
Array.isArray(val) ? flatten(val) : val
),
[]
export const flatten = (arr) => arr.reduce(
(acc, val) => acc.concat(
Array.isArray(val) ? flatten(val) : val,
),
[],
);
/**

@@ -120,3 +112,2 @@ * Pretty string dump

/**

@@ -127,22 +118,21 @@ * Use as replacer argument in JSON.stringify.

export function nodeReplacer(nodeStringifier: NodeStringifier = nodeAndValueStringifier) {
return function(key, value) {
if (value.nodeTags && value.value && value.children) {
// TextTreeNode
return {
__kind__: "TextTreeNode",
name: value.nodeName(),
tags: value.nodeTags().join(","),
structure: nodeStringifier(value)
}
}
else if (value.nodeTags) {
return {
__kind__: "GraphNode",
name: value.nodeName(),
tags: value.nodeTags().join(","),
toString: value + ""
}
}
return value;
}
return (key, value) => {
if (value.nodeTags && value.value && value.children) {
// TextTreeNode
return {
__kind__: "TextTreeNode",
name: value.nodeName(),
tags: value.nodeTags().join(","),
structure: nodeStringifier(value),
};
} else if (value.nodeTags) {
return {
__kind__: "GraphNode",
name: value.nodeName(),
tags: value.nodeTags().join(","),
toString: value + "",
};
}
return value;
};
}
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