Skip to content

Commit

Permalink
Ds webpack util (#107)
Browse files Browse the repository at this point in the history
* fix: do not ignore util from webpack

Signed-off-by: Dan Selman <[email protected]>

* fix: remove use of util as it does not webpack

Signed-off-by: Dan Selman <[email protected]>

---------

Signed-off-by: Dan Selman <[email protected]>
  • Loading branch information
dselman committed May 9, 2024
1 parent 47f753f commit 82a037e
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 27 deletions.
7 changes: 2 additions & 5 deletions lib/codegen/fromcto/csharp/csharpvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

const { ModelUtil } = require('@accordproject/concerto-core');
const camelCase = require('camelcase');
const util = require('util');
const { throwUnrecognizedType } = require('../../../common/util');

// Types needed for TypeScript generation.
/* eslint-disable no-unused-vars */
Expand Down Expand Up @@ -78,10 +78,7 @@ class CSharpVisitor {
} else if (thing.isScalarDeclaration?.()) {
return this.visitScalarDeclarationField(thing, parameters);
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, {
showHidden: true,
depth: 2
}));
throwUnrecognizedType(thing);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/codegen/fromcto/golang/golangvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

'use strict';

const util = require('util');
const ModelUtil = require('@accordproject/concerto-core').ModelUtil;
const { throwUnrecognizedType } = require('../../../common/util');

/**
* Convert the contents of a ModelManager to Go Lang code.
* All generated code is placed into the 'main' package. Set a
Expand Down Expand Up @@ -56,7 +57,7 @@ class GoLangVisitor {
} else if (thing.isScalarDeclaration?.()) {
return;
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: false, depth: 1 }));
throwUnrecognizedType(thing);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/fromcto/graphql/graphqlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

'use strict';

const util = require('util');
const { ModelUtil } = require('@accordproject/concerto-core');
const { throwUnrecognizedType } = require('../../../common/util');

/**
* Convert the contents of a ModelManager to GraphQL types, based on
Expand Down Expand Up @@ -64,7 +64,7 @@ class GraphQLVisitor {
return;
}
else {
throw new Error('Unrecognised ' + util.inspect(thing, {showHidden: false, depth: 1}) );
throwUnrecognizedType(thing);
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/codegen/fromcto/jsonschema/jsonschemavisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
'use strict';

const debug = require('debug')('concerto-core:jsonschemavisitor');
const util = require('util');
const RecursionDetectionVisitor = require('./recursionvisitor');
const { ModelUtil } = require('@accordproject/concerto-core');
const { throwUnrecognizedType } = require('../../../common/util');
const RecursionDetectionVisitor = require('./recursionvisitor');

/**
* Convert the contents of a {@link ModelManager} to a JSON Schema, returning
Expand Down Expand Up @@ -175,7 +175,7 @@ class JSONSchemaVisitor {
} else if (thing.isEnumValue?.()) {
return this.visitEnumValueDeclaration(thing, parameters);
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null }));
throwUnrecognizedType(thing);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/fromcto/jsonschema/recursionvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const debug = require('debug')('concerto-core:recursiondetectionvisitor');
const util = require('util');
const { throwUnrecognizedType } = require('../../../common/util');

/**
* Detects whether ClassDeclaration contains recursive references.
Expand Down Expand Up @@ -54,7 +54,7 @@ class RecursionDetectionVisitor {
} else if (thing.isRelationship?.()) {
return this.visitRelationshipDeclaration(thing, parameters);
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null }));
throwUnrecognizedType(thing);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/codegen/fromcto/rust/rustvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';
const ModelUtil = require('@accordproject/concerto-core').ModelUtil;
const util = require('util');
const { throwUnrecognizedType } = require('../../../common/util');

// Rust keywords
const keywords = [
Expand Down Expand Up @@ -98,7 +98,7 @@ class RustVisitor {
} else if (thing.isScalarDeclaration?.()) {
return;
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, { showHidden: true, depth: null }));
throwUnrecognizedType(thing);
}
}

Expand Down
7 changes: 2 additions & 5 deletions lib/codegen/fromcto/typescript/typescriptvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const ModelUtil = require('@accordproject/concerto-core').ModelUtil;
const util = require('util');
const { throwUnrecognizedType } = require('../../../common/util');

/**
* Convert the contents of a ModelManager to TypeScript code.
Expand Down Expand Up @@ -55,10 +55,7 @@ class TypescriptVisitor {
} else if (thing.isEnumValue?.()) {
return this.visitEnumValueDeclaration(thing, parameters);
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, {
showHidden: true,
depth: 2
}));
throwUnrecognizedType(thing);
}
}

Expand Down
7 changes: 2 additions & 5 deletions lib/codegen/fromcto/vocabulary/vocabularyvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const VocabularyManager = require('@accordproject/concerto-vocabulary').VocabularyManager;
const util = require('util');
const { throwUnrecognizedType } = require('../../../common/util');
const { ModelUtil } = require('@accordproject/concerto-core');

/**
Expand Down Expand Up @@ -60,10 +60,7 @@ class VocabularyVisitor {
} else if (thing.isValue?.()) {
return this.visitMapValue(thing, parameters);
} else {
throw new Error('Unrecognised type: ' + typeof thing + ', value: ' + util.inspect(thing, {
showHidden: true,
depth: 2
}));
throwUnrecognizedType(thing);
}
}

Expand Down
26 changes: 26 additions & 0 deletions lib/common/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

/**
* Throws an error for an unrecognized type
* @param {*} thing the unrecognized value
*/
function throwUnrecognizedType(thing) {
throw new Error(`Unrecognised type: ${typeof thing}, value: '${thing}'`);
}

module.exports = {
throwUnrecognizedType,
};
2 changes: 1 addition & 1 deletion test/codegen/fromcto/graphql/graphqlvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ describe('GraphQLVisitor', function () {

(() => {
graphQLVisitor.visit(thing, param);
}).should.throw('Unrecognised \'Something of unrecognised type\'');
}).should.throw('Unrecognised type: string, value: \'Something of unrecognised type\'');
});
});

Expand Down
5 changes: 5 additions & 0 deletions types/lib/common/util.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Throws an error for an unrecognized type
* @param {*} thing the unrecognized value
*/
export function throwUnrecognizedType(thing: any): void;

0 comments on commit 82a037e

Please sign in to comment.