changing Processor to Transformer refactor

This commit is contained in:
Garrett Serack 2019-01-17 13:21:20 -08:00
Родитель 93d9fdcca7
Коммит 11efdeac97
18 изменённых файлов: 96 добавлений и 81 удалений

17
.vscode/tasks.json поставляемый
Просмотреть файл

@ -8,7 +8,22 @@
"command": "rush",
"label": "Rebuild",
"args": [
"rebuild"
"rebuild",
"--verbose"
],
"group": "build",
"isBackground": false,
"problemMatcher": [
"$msCompile",
"$tsc"
]
},
{
"type": "shell",
"command": "rush",
"label": "watch",
"args": [
"watch"
],
"group": {
"kind": "build",

Просмотреть файл

@ -1,5 +1,7 @@
var fs = require('fs');
var cp = require('child_process');
var pt = require('path');
function read(filename) {
const txt =fs.readFileSync(filename, 'utf8')
@ -23,10 +25,12 @@ for( const each of rush.projects ) {
if( project.scripts.watch ) {
console.log(`npm.cmd run watch {cwd: ${__dirname}/../../${projectFolder}}`);
const proc = cp.spawn('npm.cmd', ['run','watch'],{cwd: `${__dirname}/../../${projectFolder}`,shell:true,stdio:"inherit"});
const root = pt.resolve(`${__dirname}/../../${projectFolder}`);
proc.on("error", (c,s) => {
console.log(packageName);
console.error( c);
console.error( s);
console.error( c.replace(/(\w*.*\.ts:)/g, `${root}/$1`));
console.error( s.replace(/(\w*.*\.ts:)/g, `${root}/$1`));
});
proc.on('exit',(c,s)=> {
console.log(packageName);
@ -35,8 +39,8 @@ for( const each of rush.projects ) {
});
proc.on('message',(c,s)=> {
console.log(packageName);
console.error( c);
console.error( s);
console.error( c.replace(/(\w*.*\.ts:)/g, `${root}/$1`));
console.error( s.replace(/(\w*.*\.ts:)/g, `${root}/$1`));
})
}
}

Просмотреть файл

@ -33,4 +33,4 @@
"pwsh": "https://github.com/fearthecowboy/npm-get-powershell/releases/download/0.2.0/pwsh-0.2.0.tgz"
},
"dependencies": {}
}
}

2
perks

@ -1 +1 @@
Subproject commit f744521463c40ee8547b72ae50aa1ab15e88b78c
Subproject commit d74bcacf9f7c9635653647d0385c925fbae906ac

Просмотреть файл

@ -94,18 +94,6 @@
"reviewCategory": "production",
"shouldPublish": true
},
{
"packageName": "@microsoft.azure/autorest-core",
"projectFolder": "src/autorest-core",
"reviewCategory": "production",
"shouldPublish": true
},
{
"packageName": "autorest",
"projectFolder": "src/autorest",
"reviewCategory": "production",
"shouldPublish": true
},
{
"packageName": "@microsoft.azure/object-comparison",
"projectFolder": "perks/libraries/object-comparison",
@ -117,6 +105,19 @@
"projectFolder": "perks/libraries/deduplication",
"reviewCategory": "production",
"shouldPublish": true
},
/* --- project packages --- */
{
"packageName": "@microsoft.azure/autorest-core",
"projectFolder": "src/autorest-core",
"reviewCategory": "production",
"shouldPublish": true
},
{
"packageName": "autorest",
"projectFolder": "src/autorest",
"reviewCategory": "production",
"shouldPublish": true
}
]
}

Просмотреть файл

@ -1,10 +1,10 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Processor, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { clone, Dictionary } from '@microsoft.azure/linq';
import * as oai from '@microsoft.azure/openapi';
import { ConfigurationView } from '../../configuration';
import { PipelinePlugin } from '../common';
export class ComponentKeyRenamer extends Processor<any, oai.Model> {
export class ComponentKeyRenamer extends Transformer<any, oai.Model> {
// oldRefs -> newRefs;
newRefs = new Dictionary<string>();

Просмотреть файл

@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Clone, CreateAssignmentMapping, DataHandle, DataSink, JsonPath, JsonPathComponent, Mapping, QuickDataSource, ToAst, Processor, AnyObject, Node } from '@microsoft.azure/datastore';
import { Clone, CreateAssignmentMapping, DataHandle, DataSink, JsonPath, JsonPathComponent, Mapping, QuickDataSource, ToAst, Transformer, AnyObject, Node } from '@microsoft.azure/datastore';
import { From } from 'linq-es2015';
import { pushAll } from '../../array';
import { ConfigurationView } from '../../autorest-core';
@ -228,7 +228,7 @@ async function composeSwaggers(config: ConfigurationView, overrideInfoTitle: any
}
}
class ExternalRefCleaner extends Processor<any, any> {
class ExternalRefCleaner extends Transformer<any, any> {
async process(targetParent: AnyObject, originalNodes: Iterable<Node>) {
for (const { value, key, pointer, children } of originalNodes) {

Просмотреть файл

@ -1,4 +1,4 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, visit, SimpleProcessor, QuickDataSource } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, visit, TransformerViaPointer, QuickDataSource } from '@microsoft.azure/datastore';
import { ConfigurationView } from '../../configuration';
import { PipelinePlugin } from '../common';
import { Dictionary, items } from '@microsoft.azure/linq';
@ -31,8 +31,7 @@ function getSemverEquivalent(version: string) {
return result;
}
export class EnumDeduplicator extends SimpleProcessor {
export class EnumDeduplicator extends TransformerViaPointer {
protected refs = new Map<string, Array<{ target: AnyObject, pointer: string }>>();
protected enums = new Map<string, Array<{ target: AnyObject, value: AnyObject, key: string, pointer: string, originalNodes: Iterable<Node> }>>();
async visitLeaf(target: AnyObject, value: AnyObject, key: string, pointer: string, originalNodes: Iterable<Node>) {

Просмотреть файл

@ -1,4 +1,4 @@
import { DataSink, DataSource, MultiProcessor, Node, ProxyObject, QuickDataSource, visit, AnyObject, DataHandle } from '@microsoft.azure/datastore';
import { DataSink, DataSource, Transformer, Node, ProxyObject, QuickDataSource, visit, AnyObject, DataHandle } from '@microsoft.azure/datastore';
import { clone, Dictionary, values } from '@microsoft.azure/linq';
import * as oai from '@microsoft.azure/openapi';
@ -48,7 +48,7 @@ import { PipelinePlugin } from '../common';
* - on files that are marked 'x-ms-secondary', this will only pull in things in /components (and it marks them x-ms-secondary-file: true)
*
*/
export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
export class MultiAPIMerger extends Transformer<any, oai.Model> {
opCount: number = 0;
cCount = new Dictionary<number>();
refs = new Dictionary<string>();
@ -194,7 +194,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
const ref = value.$ref;
if (ref && ref.startsWith('#')) {
// change local refs to full ref
value.$ref = `${this.currentInput.originalFullPath}${ref}`;
value.$ref = `${(<DataHandle>this.currentInput).originalFullPath}${ref}`;
}
// now, recurse into this object
@ -207,7 +207,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
const info = <AnyObject>this.generated.info;
// set the document's info that we haven't processed yet.
if (this.overrideTitle) {
info.title = { value: this.overrideTitle, pointer: '/info/title', filename: this.key };
info.title = { value: this.overrideTitle, pointer: '/info/title', filename: this.currentInputFilename };
} else {
const titles = [...this.titles.values()];
@ -217,15 +217,15 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
if (titles.length > 1) {
throw new Error(`The 'title' across provided OpenAPI definitions has to match. Found: ${titles.map(x => `'${x}'`).join(', ')}. Please adjust or provide an override (--title=...).`);
}
info.title = { value: titles[0], pointer: '/info/title', filename: this.key };
info.title = { value: titles[0], pointer: '/info/title', filename: this.currentInputFilename };
}
if (this.overrideDescription) {
info.description = { value: this.overrideDescription, pointer: '/info/description', filename: this.key };
info.description = { value: this.overrideDescription, pointer: '/info/description', filename: this.currentInputFilename };
} else {
const descriptions = [...this.descriptions.values()];
if (descriptions[0]) {
info.description = { value: descriptions[0], pointer: '/info/description', filename: this.key };
info.description = { value: descriptions[0], pointer: '/info/description', filename: this.currentInputFilename };
}
}
const versions = [...this.apiVersions.values()];
@ -260,7 +260,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
const uid = `path:${this.opCount++}`;
// tag the current pointer with a the new location
const originalLocation = `${this.currentInput.originalFullPath}#${pointer}`;
const originalLocation = `${(<DataHandle>this.currentInput).originalFullPath}#${pointer}`;
this.refs[originalLocation] = `#/paths/${uid}`;
// for testing with local refs
@ -271,7 +271,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
operation['x-ms-metadata'] = {
value: {
apiVersions: [this.current.info && this.current.info.version ? this.current.info.version : ''], // track the API version this came from
filename: [this.key], // and the filename
filename: [this.currentInputFilename], // and the filename
path: key, // and here is the path from the operation.
originalLocations: [originalLocation]
}, pointer
@ -300,7 +300,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
const uid = `${type}:${this.cCount[type]++}`;
// tag the current pointer with a the new location
const originalLocation = `${this.currentInput.originalFullPath}#${pointer}`;
const originalLocation = `${(<DataHandle>this.currentInput).originalFullPath}#${pointer}`;
this.refs[originalLocation] = `#/components/${type}/${uid}`;
// for testing with local refs
this.refs[`#${pointer}`] = `#/components/${type}/${uid}`;
@ -309,7 +309,7 @@ export class MultiAPIMerger extends MultiProcessor<any, oai.Model> {
component['x-ms-metadata'] = {
value: {
apiVersions: [this.current.info && this.current.info.version ? this.current.info.version : ''], // track the API version this came from
filename: [this.key], // and the filename
filename: [this.currentInputFilename], // and the filename
name: key, // and here is the name of the component.
originalLocations: [originalLocation],
'x-ms-secondary-file': this.isSecondaryFile

Просмотреть файл

@ -1,4 +1,4 @@
import { AnyObject, DataHandle, DataSink, DataSource, MultiProcessor, Node, Processor, ProxyNode, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Transformer, Node, ProxyNode, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { clone, Dictionary, keys, values } from '@microsoft.azure/linq';
import { areSimilar } from "@microsoft.azure/object-comparison";
import * as oai from '@microsoft.azure/openapi';
@ -31,14 +31,10 @@ function distinct<T>(list: Array<T>): Array<T> {
*
*/
export class NewComposer extends Processor<AnyObject, AnyObject> {
export class NewComposer extends Transformer<AnyObject, AnyObject> {
private uniqueVersion!: boolean;
refs = new Dictionary<string>();
constructor(input: DataHandle) {
super(input);
}
get components(): AnyObject {
if (this.generated.components) {
return this.generated.components;
@ -226,7 +222,7 @@ export class NewComposer extends Processor<AnyObject, AnyObject> {
// for each parameter
for (const { key, value, pointer, children } of nodes) {
paramarray.__push__({ value: JSON.parse(JSON.stringify(value)), pointer, recurse: true, filename: this.key });
paramarray.__push__({ value: JSON.parse(JSON.stringify(value)), pointer, recurse: true, filename: this.currentInputFilename });
}
// if we have more than one api-version in this client
@ -243,7 +239,7 @@ export class NewComposer extends Processor<AnyObject, AnyObject> {
}
};
paramarray.__push__({ value: p, pointer: ptr, recurse: true, filename: this.key });
paramarray.__push__({ value: p, pointer: ptr, recurse: true, filename: this.currentInputFilename });
// }
}

Просмотреть файл

@ -1,4 +1,4 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Processor, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { clone, Dictionary, values } from '@microsoft.azure/linq';
import * as oai from '@microsoft.azure/openapi';
import * as compareVersions from 'compare-versions';
@ -37,7 +37,7 @@ function getSemverEquivalent(version: string) {
return result;
}
export class ProfileFilter extends Processor<any, oai.Model> {
export class ProfileFilter extends Transformer<any, oai.Model> {
filterTargets: Array<{ apiVersion: string; pathRegex: RegExp }> = [];
// sets containing the UIDs of components already visited.

Просмотреть файл

@ -1,4 +1,4 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Processor, ProxyObject, ProxyNode, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, ProxyObject, ProxyNode, visit } from '@microsoft.azure/datastore';
import { ResolveUri } from '@microsoft.azure/uri';
export async function crawlReferences(inputScope: DataSource, filesToCrawl: Array<DataHandle>, sink: DataSink): Promise<Array<DataHandle>> {
@ -23,7 +23,7 @@ export async function crawlReferences(inputScope: DataSource, filesToCrawl: Arra
return result;
}
class RefProcessor extends Processor<any, any> {
class RefProcessor extends Transformer<any, any> {
public newFilesFound: Array<string> = new Array<string>();
private originalFileLocation: string;
@ -74,13 +74,13 @@ class RefProcessor extends Processor<any, any> {
}
}
class SecondaryFileMarker extends Processor<any, any> {
class SecondaryFileMarker extends Transformer<any, any> {
async process(targetParent: AnyObject, originalNodes: Iterable<Node>) {
for (const { value, key, pointer } of originalNodes) {
this.clone(targetParent, key, pointer, value);
if (!targetParent['x-ms-secondary-file']) {
targetParent['x-ms-secondary-file'] = { value: true, pointer, filename: this.key };
targetParent['x-ms-secondary-file'] = { value: true, pointer, filename: this.currentInputFilename };
}
}
}

Просмотреть файл

@ -1,4 +1,4 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Processor, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { clone, Dictionary } from '@microsoft.azure/linq';
import { areSimilar } from '@microsoft.azure/object-comparison';
import * as oai from '@microsoft.azure/openapi';
@ -6,7 +6,7 @@ import * as compareVersions from 'compare-versions';
import { ConfigurationView } from '../../configuration';
import { PipelinePlugin } from '../common';
export class SubsetSchemaDeduplicator extends Processor<any, oai.Model> {
export class SubsetSchemaDeduplicator extends Transformer<any, oai.Model> {
public async process(targetParent: ProxyObject<oai.Model>, originalNodes: Iterable<Node>) {
// initialize certain things ahead of time:

Просмотреть файл

@ -1,8 +1,8 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, parseJsonPointer, Processor, QuickDataSource } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, parseJsonPointer, Transformer, QuickDataSource } from '@microsoft.azure/datastore';
import { ConfigurationView } from '../../configuration';
import { PipelinePlugin } from '../common';
export class OAI3Shaker extends Processor<AnyObject, AnyObject> {
export class OAI3Shaker extends Transformer<AnyObject, AnyObject> {
get components(): AnyObject {
if (this.generated.components) {
return this.generated.components;

Просмотреть файл

@ -1,10 +1,10 @@
import { AnyObject, DataHandle, DataSink, DataSource, Node, Processor, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { AnyObject, DataHandle, DataSink, DataSource, Node, Transformer, ProxyObject, QuickDataSource, visit } from '@microsoft.azure/datastore';
import { clone, Dictionary } from '@microsoft.azure/linq';
import * as oai from '@microsoft.azure/openapi';
import { ConfigurationView } from '../../configuration';
import { PipelinePlugin } from '../common';
export class ApiVersionParameterHandler extends Processor<any, oai.Model> {
export class ApiVersionParameterHandler extends Transformer<any, oai.Model> {
// oldRefs -> newRefs;
apiVersionReferences = new Set<string>();

Просмотреть файл

@ -56,16 +56,16 @@
"tslint-microsoft-contrib": "^5.2.1",
"static-link": "^0.2.4",
"vscode-languageserver": "3.5.1",
"@microsoft.azure/async-io": "^2.1.22",
"@microsoft.azure/extension": "^2.1.19",
"@microsoft.azure/uri": "^2.1.15",
"@microsoft.azure/datastore": "^2.1.31",
"@microsoft.azure/oai2-to-oai3": "^2.1.55",
"@microsoft.azure/async-io": "^2.1.40",
"@microsoft.azure/extension": "^2.1.37",
"@microsoft.azure/uri": "^2.1.33",
"@microsoft.azure/datastore": "^2.1.61",
"@microsoft.azure/oai2-to-oai3": "^2.1.81",
"@microsoft.azure/codegen": "^1.0.36",
"@microsoft.azure/openapi": "^2.1.16",
"@microsoft.azure/linq": "^2.1.14",
"@microsoft.azure/openapi": "^2.1.35",
"@microsoft.azure/linq": "^2.1.37",
"@microsoft.azure/deduplication": "^1.0.0",
"@microsoft.azure/object-comparison": "^2.1.0",
"@microsoft.azure/object-comparison": "^2.1.32",
"compare-versions": "^3.4.0",
"commonmark": "^0.27.0",
"jsonpath": "1.0.0",
@ -76,21 +76,20 @@
"vscode-jsonrpc": "^3.5.0",
"source-map-support": "0.5.9",
"yaml-ast-parser": "0.0.40",
"compare-versions": "^3.4.0",
"z-schema": "^3.19.0"
},
"static-link": {
"entrypoints": [],
"dependencies": {
"vscode-languageserver": "3.5.1",
"@microsoft.azure/async-io": "^2.1.22",
"@microsoft.azure/extension": "^2.1.19",
"@microsoft.azure/datastore": "^2.1.31",
"@microsoft.azure/oai2-to-oai3": "^2.1.55",
"@microsoft.azure/uri": "^2.1.15",
"@microsoft.azure/linq": "^2.1.14",
"@microsoft.azure/async-io": "^2.1.40",
"@microsoft.azure/extension": "^2.1.37",
"@microsoft.azure/datastore": "^2.1.61",
"@microsoft.azure/oai2-to-oai3": "^2.1.81",
"@microsoft.azure/uri": "^2.1.33",
"@microsoft.azure/linq": "^2.1.37",
"@microsoft.azure/codegen": "^1.0.36",
"@microsoft.azure/openapi": "^2.1.16",
"@microsoft.azure/openapi": "^2.1.35",
"@microsoft.azure/deduplication": "^1.0.0",
"commonmark": "^0.27.0",
"jsonpath": "1.0.0",

Просмотреть файл

@ -56,19 +56,19 @@
"tslint-microsoft-contrib": "^5.2.1",
"static-link": "^0.2.4",
"@microsoft.azure/autorest-core": "^3.0.0",
"@microsoft.azure/async-io": "^2.1.22",
"@microsoft.azure/extension": "^2.1.19",
"@microsoft.azure/tasks": "^2.1.21",
"semver": "^5.3.0",
"@microsoft.azure/async-io": "^2.1.40",
"@microsoft.azure/extension": "^2.1.37",
"@microsoft.azure/tasks": "^2.1.39",
"semver": "^5.5.1",
"chalk": "2.3.0"
},
"static-link": {
"entrypoints": [],
"dependencies": {
"@microsoft.azure/async-io": "^2.1.22",
"@microsoft.azure/extension": "^2.1.19",
"@microsoft.azure/tasks": "^2.1.21",
"semver": "^5.3.0",
"@microsoft.azure/async-io": "^2.1.40",
"@microsoft.azure/extension": "^2.1.37",
"@microsoft.azure/tasks": "^2.1.39",
"semver": "^5.5.1",
"chalk": "2.3.0"
},
"patch": "const fs = require(`fs`); let txt = fs.readFileSync('./node_modules/npm/lib/install/action/extract.js','utf8').replace(`const ENABLE_WORKERS = process.platform === 'darwin'`, `const ENABLE_WORKERS = false;`); fs.writeFileSync('./node_modules/npm/lib/install/action/extract.js', txt ); txt = fs.readFileSync(`./node_modules/npm/lib/npm.js`,`utf8`).replace(`var j = parseJSON(fs.readFileSync(`, `var j = require(path.join(__dirname, '../package.json'));` ).replace(`path.join(__dirname, '../package.json')) + '')`,``); fs.writeFileSync(`./node_modules/npm/lib/npm.js`, txt ); txt = fs.readFileSync('./node_modules/npm/lib/pack.js','utf8').replace(`require.main.filename`, `require.resolve('../bin/npm-cli.js')`); fs.writeFileSync('./node_modules/npm/lib/pack.js', txt ); "

Просмотреть файл

@ -1,6 +1,7 @@
{
"compilerOptions": {
"outDir": "dist",
"noErrorTruncation": true,
"noImplicitAny": false,
"module": "commonjs",
"sourceMap": true,