Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
node_modules/
typings/
cache/
*.js
*.d.ts
dist/
*.log.*
*.log
*.tgz
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/
typings/
cache/
src/
.travis.yml
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"tsc": "tsc",
"typings": "typings",
"prepublish": "typings install && tsc",
"prepublish": "tsc -p src",
"test": "node cxsd-cli.js --help"
},
"author": "Juha Järvi",
Expand All @@ -30,14 +30,17 @@
"typescript"
],
"dependencies": {
"bluebird": "^3.4.1",
"cget": "~0.0.5",
"commander": "~2.9.0",
"cxml": "~0.1.0",
"node-expat": "~2.3.15"
"@types/bluebird": "^3.5.18",
"@types/commander": "^2.11.0",
"@types/node": "^8.0.47",
"bluebird": "^3.4.7",
"cget": "^0.2.1",
"commander": "^2.11.0",
"cxml": "~0.1.1",
"node-expat": "^2.3.16"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^1.3.2"
"tslint": "^5.8.0",
"typescript": "^2.5.3"
}
}
4 changes: 2 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ function handleConvert(urlRemote: string, opts: { [key: string]: any }) {
Cache.patchRequest();
}

var jsCache = new Cache(opts['outJs'] || 'xmlns', '_index.js');
var tsCache = new Cache(opts['outTs'] || 'xmlns', '_index.d.ts');
var jsCache = new Cache(opts['outJs'] || 'xmlns', { indexName: '_index.js' });
var tsCache = new Cache(opts['outTs'] || 'xmlns', { indexName: '_index.d.ts' });

var loader = new Loader(xsdContext, fetchOptions);

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/schema/exporter/Exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export abstract class Exporter extends Transform<Exporter, boolean, State> {

var outName = this.getOutName(doc.namespace.name);

return(this.state.cache.ifCached(outName).then((isCached: boolean) => {
return((this.state.cache.isCached(outName) as Promise<boolean>).then((isCached: boolean) => {
if(isCached) return(null)

return(this.state.cache.store(
Expand Down
12 changes: 7 additions & 5 deletions tsconfig.json → src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "dist",
"target": "es5"
"noImplicitThis": true,
"outDir": "../dist",
"removeComments": false,
"target": "es5",
"lib": ["es6"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be just: [ "es5", "es2015.collection" ]

},
"files": [
"typings/index.d.ts",
"typings-custom/node-expat.d.ts",
"node-expat.d.ts",

"src/cli.ts"
"cli.ts"
]
}
25 changes: 20 additions & 5 deletions src/xsd/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,35 @@

import * as Promise from 'bluebird';

import {Address, FetchOptions, Cache, CacheResult, util} from 'cget';
import {FetchOptions, Cache, CacheResult} from 'cget';

import {Context} from './Context';
import {Namespace} from './Namespace';
import {Source} from './Source';
import {Parser} from './Parser';

/** Copy all members of src object to dst object. */

export function extend(dst: {[key: string]: any}, src: {[key: string]: any}) {
for(var key of Object.keys(src)) {
dst[key] = src[key];
}
return(dst);
}

/** Make shallow clone of object. */

export function clone(src: Object) {
return(extend({}, src));
}


/** Loader handles caching schema definitions and calling parser stages. */

export class Loader {
constructor(context: Context, options?: FetchOptions) {
this.context = context;
this.options = util.clone(options);
this.options = clone(options || {});
this.parser = new Parser(context);
}

Expand All @@ -31,15 +47,14 @@ export class Loader {
}

importFile(urlRemote: string, namespace?: Namespace) {
var options = this.options;
options.address = new Address(urlRemote);
const options = this.options;

var source = Loader.sourceTbl[urlRemote];

if(!source) {
source = new Source(urlRemote, this.context, namespace);

Loader.cache.fetch(options).then((cached: CacheResult) => {
Loader.cache.fetch(urlRemote, options).then((cached: CacheResult) => {
source.updateUrl(urlRemote, cached.address.url);

return(this.parser.init(cached, source, this));
Expand Down
4 changes: 2 additions & 2 deletions src/xsd/types/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export class Attribute extends MemberBase {
var attribute = this.resolveMember(state, 'attribute') as Attribute;
}

use: string = null;
default: XmlAttribute = null;
use: string | null = null;
default: XmlAttribute | null = null;
}
11 changes: 6 additions & 5 deletions src/xsd/types/AttributeGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ export class AttributeGroup extends types.Base {
}

resolve(state: State) {
var attributeGroup: AttributeGroup = this;
let attributeGroup: AttributeGroup = this;
let ref: QName = null;

if(this.ref) {
var ref = new QName(this.ref, state.source);
ref = new QName(this.ref, state.source);
attributeGroup = this.scope.lookup(ref, 'attributeGroup') as AttributeGroup;
}

Expand All @@ -38,7 +39,7 @@ export class AttributeGroup extends types.Base {
}
}

id: string = null;
name: string = null;
ref: string = null;
id: string | null = null;
name: string | null = null;
ref: string | null = null;
}
4 changes: 2 additions & 2 deletions src/xsd/types/DerivationBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ export class DerivationBase extends types.Base {
this.scope.addAllToParent('attributeGroup');
}

id: string = null;
base: string = null;
id: string | null = null;
base: string | null = null;
}
6 changes: 3 additions & 3 deletions src/xsd/types/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export class Element extends MemberBase implements ElementLike {
minOccurs: string = "1";
maxOccurs: string = "1";

default: string = null;
default: string | null = null;

/** Abstract elements are disallowed in the XML document,
* and another member of the same substitution group should be used. */
abstract: string = null; // boolean
substitutionGroup: string = null;
abstract: string | null = null; // boolean
substitutionGroup: string | null = null;

substitutes: Element;
isSubstituted: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/xsd/types/MemberBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ export class MemberBase extends TypedBase {
return(false);
}

id: string = null;
name: string = null;
ref: string = null;
type: string = null;
id: string | null = null
name: string | null = null
ref: string | null = null
type: string | null = null

min: number;
max: number;
Expand Down
16 changes: 9 additions & 7 deletions src/xsd/types/TypeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {QName} from '../QName';
import {NamedTypeMember} from '../Scope';
import * as schema from '../../schema';

export interface TypeBaseChild extends TypeBase {}

export class TypeBase extends Base {
init(state: State) {
if(!this.scope) this.scope = state.getScope();
Expand Down Expand Up @@ -37,9 +39,9 @@ export class TypeBase extends Base {

/** Find parent type inheriting from a base type. */

getParent(base: BaseClass, breakAtContent: boolean) {
var next: TypeBase | QName = this;
var type: TypeBase | QName;
getParent(base: BaseClass, breakAtContent: boolean): TypeBase {
var next: TypeBaseChild | QName = this;
var type: TypeBaseChild | QName;
/** Maximum iterations in case type inheritance forms a loop. */
var iter = 100;

Expand All @@ -48,11 +50,11 @@ export class TypeBase extends Base {

if(!(type instanceof TypeBase)) break;
else if(type instanceof base) return(type);
else if(breakAtContent && type.scope && (
type.scope.dumpTypes('attribute') ||
type.scope.dumpTypes('attributeGroup')
else if(breakAtContent && (type as TypeBase).scope && (
(type as TypeBase).scope.dumpTypes('attribute') ||
(type as TypeBase).scope.dumpTypes('attributeGroup')
)) break;
else next = type.parent;
else next = (type as TypeBase).parent;
}

return(null);
Expand Down
11 changes: 0 additions & 11 deletions typings.json

This file was deleted.

Loading