Giter Club home page Giter Club logo

fontoxpath's Introduction

fontoxpath Build Status NPM version bundle size Coverage Status Known Vulnerabilities CodeFactor

A minimalistic XPath 3.1 and XQuery 3.1 engine for (XML) nodes with XQuery Update Facility 3.0 support.

Demo page

How to use

Querying XML

evaluateXPath(xpathExpression, contextNode, domFacade, variables, returnType, options);

The following are convenience functions for a specific returnType.

evaluateXPathToArray(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToAsyncIterator(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToBoolean(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToFirstNode(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToMap(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToNodes(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToNumber(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToNumbers(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToString(xpathExpression, contextNode, domFacade, variables, options);
evaluateXPathToStrings(xpathExpression, contextNode, domFacade, variables, options);
  • xpathExpression <String> The query to evaluate.
  • contextNode <Node> The node in which context the xpathExpression will be evaluated. Defaults to null.
  • domFacade <IDomFacade> An IDomFacade implementation which will be used for querying the DOM. Defaults to an implementation which uses properties and methods on the contextNode as described in the DOM spec.
  • variables <Object> The properties of variables are available variables within the xpathExpression. Defaults to an empty Object. Can only be used to set variables in the global namespace.
  • returnType <number> Determines the type of the result. Defaults to evaluateXPath.ANY_TYPE. Possible values:
    • evaluateXPath.ALL_RESULTS_TYPE Returns the result of the query, can be anything depending on the query. This will always be an array, and the result can be mixed: contain both nodes and strings for example.
    • evaluateXPath.NUMBER_TYPE Resolve to a number, like count((1,2,3)) resolves to 3.
    • evaluateXPath.STRING_TYPE Resolve to a string, like //someElement[1] resolves to the text content of the first someElement.
    • evaluateXPath.BOOLEAN_TYPE Resolves to a boolean true or false, uses the effective boolean value to determine the result. count(1) resolves to true, count(()) resolves to false.
    • evaluateXPath.NODES_TYPE Resolve to all nodes Node[] the XPath resolves to. Returns nodes in the order the XPath would. Meaning (//a, //b) resolves to all A nodes, followed by all B nodes. //*[self::a or self::b] resolves to A and B nodes in document order.
    • evaluateXPath.FIRST_NODE_TYPE Resolves to the first Node node.NODES_TYPE would have resolved to.
    • evaluateXPath.STRINGS_TYPE Resolve to an array of strings string[].
    • evaluateXPath.MAP_TYPE Resolve to an Object, as a map.
    • evaluateXPath.ARRAY_TYPE Resolve to an array [].
    • evaluateXPath.ASYNC_ITERATOR_TYPE
    • evaluateXPath.NUMBERS_TYPE Resolve to an array of numbers number[].
    • evaluateXPath.ANY_TYPE Returns the result of the query, can be anything depending on the query. Note that the return type is determined dynamically, not statically: XPaths returning empty sequences will return empty arrays and not null, like one might expect. This is deprecated, use evaluateXPath.ALL_RESULTS_TYPE instead, since that is more predictable.
  • options <Object> Options used to modify the behavior. The following options are available:
    • namespaceResolver <function(string):string?> By default, the namespaces in scope of the context item (if it is a node) are used. This is fine for most queries if you can assume how your XML uses prefixes. Use this function to override those namespaces to remove that assumption. This function will be called with a prefix (the empty string for the default namespaceURI) and should return a namespaceURI (or null for the null namespace).
    • nodesFactory INodesFactory A INodesFactory implementation which will be used for creating nodes.
    • language string The query language to use. Defaults to evaluateXPath.XPATH_3_1_LANGUAGE. Possible values:
      • evaluateXPath.XPATH_3_1_LANGUAGE Evaluate xpathExpression according the XPath spec.
      • evaluateXPath.XQUERY_3_1_LANGUAGE Evaluate xpathExpression according the XQuery spec.
    • moduleImports <Object<string, string>
    • debug <boolean> If a debug trace should be tracked, see debugging for more information.
    • logger <Object> Object with functions used to override the standard logger.
      • trace: <function(string):void> The logger for the trace() function. The argument is the string of the original message.
    • defaultFunctionNamespaceURI <string> To modify or change the default function namespaceURI. Defaults to http://www.w3.org/2005/xpath-functions. Defining the default function namespaceURI in the xpath expression overwrites this option.
    • functionNameResolver <({prefix, localName}, arity) => {namespaceURI, localName}> To influence the function name resolving algorithm. Useful to extend the protected namespaces, such as the fn namespace.

Example

const {
	evaluateXPath,
	evaluateXPathToBoolean,
	evaluateXPathToString,
	evaluateXPathToFirstNode,
	evaluateXPathToNumber,
} = require('fontoxpath');

const documentNode = new DOMParser().parseFromString('<xml/>', 'text/xml');

console.log(evaluateXPathToBoolean('/xml => exists()', documentNode));
// Outputs: true

console.log(evaluateXPathToString('$foo', null, null, { foo: 'bar' }));
// Outputs: "bar"

// We pass the documentNode so the default INodesFactory can be used.
console.log(
	evaluateXPathToFirstNode('<foo>bar</foo>', documentNode, null, null, {
		language: evaluateXPath.XQUERY_3_1_LANGUAGE,
	}).outerHTML
);
// Outputs: "<foo>bar</foo>"

// We pass the Math namespaceURI for the pi() function to be used
console.log(
	evaluateXPathToNumber(
		'pi()',
		documentNode,
		undefined,
		{},
		{
			language: evaluateXPath.XQUERY_3_1_LANGUAGE,
			defaultFunctionNamespaceURI: 'http://www.w3.org/2005/xpath-functions/math',
		}
	)
);
// Outputs: Math.PI (3.14...)

Creating typed values

When having to pass JavaScript values as variables to an evaluateXPath call you can create a typed value of it to ensure it will be used as that specific type.

If you do not do this and instead pass a plain JavaScript value as variable it will get converted automatically into a type which fits but you will not be able to control the exact type.

const integerValueFactory = createTypedValueFactory('xs:integer');
const integerValue = integerValueFactory(123, domFacade);

// Will return true as we specified it to be an xs:integer
evaluateXPathToBoolean('$value instance of xs:integer', null, null, {
	value: typedValue,
}),

// Will return false as JavaScript numbers are by default converted to an xs:double
evaluateXPathToBoolean('$value instance of xs:integer', null, null, {
	value: 123,
}),

Debugging

FontoXPath can output a basic trace for an error if the debug option is set to true. This is disabled by default because of performance reasons.

evaluateXPathToBoolean(`
if (true()) then
  zero-or-one((1, 2))
else
  (1, 2, 3)
`, null, null, null, {debug: true});

// Throws:
1: if (true()) then
2:   zero-or-one((1, 2))
     ^^^^^^^^^^^^^^^^^^^
3: else
4:   (1, 2, 3)

Error: FORG0003: The argument passed to fn:zero-or-one contained more than one item.
  at <functionCallExpr>:2:3 - 2:22
  at <ifThenElseExpr>:1:1 - 4:12

Besides errors, the fn:trace function can be used to output information to the developer console.

Performance

FontoXPath can use the Performance API to provide some insight in the speed of XPaths. To use it, first give FontoXPath an implementation of the Performance interface:

import { profiler } from 'fontoxpath';

profiler.setPerformanceImplementation(window.performance); // or global.performance or self.performance, depending on you surroundings

// And start profiling all XPath / XQuery usage

profiler.startProfiling();

At some point, you may want to get a summary of all evaluated XPaths:

const summary = profiler.getPerformanceSummary();

This summary contains an array of XPaths, their execution times, their total runtime and their average runtime. Starting a performance profile will also output measurements on the timeline of the performance profiler of the browser.

Modifying XML

To modify XML you can use XQuery Update Facility 3.0 as following

evaluateUpdatingExpressionSync(xpathExpression, contextNode, domFacade, variables, options);

The arguments are the same as evaluateXPath. This returns an Object, the object has a xdmValue and pendingUpdateList. The xdmValue is the result of query as if it was run using evaluateXPath with evaluateXPath.ANY_TYPE as returnType. The pendingUpdateList is an <Object[]> in which each entry represents an update primitive where the type identifies the update primitive.

The pending update list can be executed using

executePendingUpdateList(pendingUpdateList, domFacade, nodesFactory, documentWriter);
  • pendingUpdateList <Object[]> The pending update list returned by evaluateUpdatingExpression.
  • domFacade <IDomFacade> See evaluateXPath. The default will use nodes from the pendingUpdateList.
  • nodesFactory INodesFactory A INodesFactory implementation which will be used for creating nodes. Defaults to an implementation which uses properties and methods of nodes from the pendingUpdateList.
  • documentWriter <IDocumentWriter> An IDocumentWriter implementation which will be used for modifying a DOM. Defaults to an implementation which uses properties and methods of nodes from the pendingUpdateList.

Example

const { evaluateUpdatingExpression, executePendingUpdateList } = require('fontoxpath');
const documentNode = new DOMParser().parseFromString('<xml/>', 'text/xml');

const result = evaluateUpdatingExpressionSync('replace node /xml with <foo/>', documentNode)

executePendingUpdateList(result.pendingUpdateList);
console.log(documentNode.documentElement.outerHTML);
// Outputs: "<foo/>";

An example of using XQUF with XQuery modules:

registerXQueryModule(`
module namespace my-custom-namespace = "my-custom-uri";
(:~
	Insert attribute somewhere
	~:)
declare %public %updating function my-custom-namespace:do-something ($ele as element()) as xs:boolean {
	if ($ele/@done) then false() else
	(insert node
	attribute done {"true"}
	into $ele, true())
};
`);
// At some point:
const contextNode = null;
const pendingUpdatesAndXdmValue = evaluateUpdatingExpressionSync(
	'ns:do-something(.)',
	contextNode,
	null,
	null,
	{ moduleImports: { ns: 'my-custom-uri' } }
);

console.log(pendingUpdatesAndXdmValue.xdmValue); // this is true or false, see function

executePendingUpdateList(pendingUpdatesAndXdmValue.pendingUpdateList, null, null, null);

// At this point the context node will have its attribute set

Global functions

To register custom functions. They are registered globally.

registerCustomXPathFunction(name, signature, returnType, callback);
  • name {namespaceURI: string, localName: string} The function name.
  • signature string[] The arguments of the function.
  • returnType string The return type of the function.
  • callback function The function itself.

Example:

const fontoxpath = require('fontoxpath');

// Register a function called 'there' in the 'hello' namespace:
fontoxpath.registerCustomXPathFunction(
	{ namespaceURI: 'hello', localName: 'there' },
	['xs:string'],
	'xs:string',
	(_, str) => `Hello there, ${str}`
);

// and call it, using the BracedUriLiteral syntax (Q{})
const out = fontoxpath.evaluateXPathToString('Q{hello}there("General Kenobi")');

// Or by using a prefix instead:
const URI_BY_PREFIX = { hi: 'hello' };
const out2 = fontoxpath.evaluateXPathToString('hi:there("General Kenobi")', null, null, null, {
	namespaceResolver: (prefix) => URI_BY_PREFIX[prefix],
});

Including modules

Use the registerXQueryModule function to register an XQuery module. Registered modules will be globally available, but will have to be imported before they can be used.

Example:

const fontoxpath = require('fontoxpath');

fontoxpath.registerXQueryModule(`
	module namespace test = "https://www.example.org/test1";

	declare %public function test:hello($a) {
		"Hello " || $a
	};
`);

// Import the module using the XQuery way:
fontoxpath.evaluateXPathToString(
	`
	import module namespace test = "https://www.example.org/test1";
	(: Invoke the test:hello function :)
	test:hello('there')
	`,
	null,
	null,
	null,
	{ language: fontoxpath.evaluateXPath.XQUERY_3_1_LANGUAGE }
);

// Or by using the moduleImports API, which can be used in XPath contexts as well
fontoxpath.evaluateXPathToString(
	`
	(: Invoke the test:hello function :)
	test:hello('there')
	`,
	null,
	null,
	null,
	{ moduleImports: { test: 'https://www.example.org/test1' } }
);

Typescript

We support TypeScript; and expose a minimal Node type. You can use generic types to get the type of the DOM implementation you are using without having to cast it.

const myNodes = evaluateXPathToNodes<slimdom.Node>('<foo>bar</foo>', null, null, null, {
	language: evaluateXPath.XQUERY_3_1_LANGUAGE,
});

// Type of myNodes is: slimdom.Node[] .

Compiling queries to JavaScript for better execution performance

⚠️ Warning: this functionality considered experimental. ⚠️

FontoXPath supports compiling a small but useful subset of XPath 3.1 to pure JavaScript code. Query execution performance benefits from this: execution speed can be 2 to 7 times higher than when using evaluateXPath, according to our benchmarks.

Two API's provide this functionality:

  • compileXPathToJavaScript Compiles a query and its return type to JavaScript code. This result should be evaluated to a function, for example with new Function.
  • executeJavaScriptCompiledXPath Evaluates a to a function evaluated compiled query (see the example below) and applies it to the given context node, returning its resulting value.

Supported functionality

Here is a list of supported functionality so you can determine if compiling to JavaScript is suitable for your project. These functionalities are supported:

  • Absolute and relative path expressions, including an arbitrary amount of steps.
  • child, self, parent and attribute axes.
  • NodeTests: NameTest, ElementTest, Wildcard and TextTest.
  • Predicates (the [ and ] in /xml[child::title]).
  • Logical operators (and and or).
  • Compares (compare string to string and node to string).
  • Return types evaluateXPath.NODES_TYPE, evaluateXPath.BOOLEAN_TYPE, evaluateXPath.FIRST_NODE_TYPE, evaluateXPath.STRING, evaluateXPath.ANY.

Functions, XQuery and other more advanced features are not supported (yet).

Example usage:

import {
	compileXPathToJavaScript,
	CompiledXPathFunction,
	evaluateXPath,
	executeJavaScriptCompiledXPath,
} from 'fontoxpath';

const documentNode = new DOMParser().parseFromString('<p>Beep beep.</p>', 'text/xml');

const compiledXPathResult = compileXPathToJavaScript(
	'/child::p/text()',
	evaluateXPath.BOOLEAN_TYPE
);
if (compiledXPathResult.isAstAccepted === true) {
	// Query is compiled succesfully, it can be evaluated.
	const evalFunction = new Function(compiledXPathResult.code) as CompiledXPathFunction;

	console.log(executeJavaScriptCompiledXPath(evalFunction, documentNode));
	// Outputs: true
} else {
	// Not supported by JS codegen (yet).
}
Ideas to improve the example to better fit your project:
  • If a query could not be compiled to JavaScript, fall back on the stable evaluateXPath function.
  • Add caching so compiling and new Function does not have happen more than once per unique query.
  • Store compiled code to disk.

Features

Note that this engine assumes XPath 1.0 compatibility mode turned off.

Not all XPath 3.1 functions are implemented yet. We accept pull requests for missing features. A full list of supported queries can be found on the playground. Select the 'Report on which functions are implemented' example to get a full dynamic report!

The following features are unavailable at this moment, but will be implemented at some point in time (and even sooner if you can help!):

  • Some DateTime related functions
  • Collation related functions (fn:compare#3)
  • Some other miscellaneous functions
  • XML parsing
  • The treat as operator
  • Some parts of FLWOR expressions

For all available features, see the unit tests, or just try it out on the Demo page.

Extensions to the spec

FontoXPath implements a single function that is public API: fontoxpath:version() as xs:string. It resides in the 'http://fontoxml.com/fontoxpath' namespace. Call it to check what version of FontoXPath you are running.

Compatibility

This engine is pretty DOM-agnostic, it has a good track record with the browser DOM implementations and slimdom.js. There are a number of known issues with other DOM implementations such as xmldom because it does not follow the DOM spec on some features including namespaces.

When using namespaces in general, be sure to not use the HTML DOM since it does not always implement namespaces how you'd expect!

Contribution

If you have any questions on how to use FontoXPath, or if you are running into problems, just file a github issue! If you are looking to contribute, we have a Contribution Guide that should help you in getting your development environment set up.

fontoxpath's People

Contributors

abbasi-waqas avatar bwrrp avatar code-factor avatar crodriguezq avatar dependabot[bot] avatar devatwork avatar drex04 avatar drrataplan avatar evandervalk avatar fhaftmann avatar greenkeeper[bot] avatar hectorpeeters avatar hubgit avatar jarivm avatar jcentrena avatar josverburg avatar koltharius avatar lironer avatar luisgallego-fonto avatar martinn1996 avatar mehmetscoskun avatar mtimmerije avatar mvanbutselaar avatar rebp avatar rrthomas avatar thomasbrekelmans avatar thomasgravekamp avatar wvbe avatar ymor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fontoxpath's Issues

getBucketForSelector returns `null` for `(self::note)[@conref]`

Selector buckets can be used as a cheap pre-filtering for selectors. Fonto uses them extensively for all sorts of optimizations.

Unfortunately, it seems that the (self::note)[@conref] returns null as its bucket, indicating that it can match 'any' node.

This is wrong. This is likely caused by the XQueryX refactoring.

Optimize XPaths with the form `(self::text() | following::text)[1]`

When we run this XPath, we currently seem to perform a full document scan for the following axis part. We should not have to. The set from following is always after the self set, the union operator returns its results in a sorted fashion, and can just return the self item, or the first item of the following set if the self set is empty.

An in-range update of slimdom is breaking the build 🚨

The devDependency slimdom was updated from 2.2.1 to 2.3.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

slimdom is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for 2.3.0

This release contains a bugfix and a few new features:

  • Serializing nodes to well-formed XML no longer throws when it encounters a prefixed element that explicitly resets the default namespace (using xmlns=""). This works around a bug in the DOM Parsing specification.
  • The textContent property has been implemented for all nodes.
  • The prepend, append, before, after, replaceWith and remove methods have been implemented for nodes that support them.
  • The wholeText property for text nodes has been implemented.
  • The slimdom package now includes TypeScript typings.
  • Updated devDependencies to their latest versions.
Commits

The new version differs by 15 commits.

  • 8e03e57 2.3.0
  • 1d11719 Add npmrc
  • 809869e Implement Text#wholeText
  • 6495e4d Also write coverage report to disk
  • 67914e3 Update devDependencies to their latest versions
  • 2937eec Add support for newer DOM mutation methods
  • 2ff56a3 Add unimplemented methods from DOM-Parsing spec to list of missing features
  • f99c1b4 Add work-around for w3c/DOM-Parsing#48
  • 60aa1f1 Add failing test for default namespace redeclaration spec bug
  • 7a49cb4 Update to latest DOM Parsing spec text
  • 2f42bf5 Implement textContent
  • 4db09e4 Add tests for unsafe functions to restore coverage
  • c354a6b Update to latest spec
  • fe51381 Use terser instead of babel-minify
  • 859eeb2 Use api-extractor and api-documenter

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

XQuery functions do not convert their return value to the desired return type

XQuery function should convert the return value of a function to the desired return type as stated in 3.1.5.2 Function Conversion Rules of the XQuery spec.

This can be observed with the following XQuery module:

declare %public function local:test ($node as node()) as xs:string {
	if ($node instance of text()) then
    	$node
    else
    	string($node)
};

let $nodes := //tip | //tip/text()
return $nodes/local:test(.)

In goes a mixed sequence of text() and element() nodes. Only the element nodes are cast explicitly to an xs:string, text nodes are returned as is. Then, the "/" operator starts complaining:

Error: XPTY0018: The path operator should either return nodes or non-nodes. Mixed sequences are not allowed.

Playground example

Custom XPath function context

Hi,
We are currently looking into seeing how feasible it is to add xforms functions as custom xpath functions with your library. We have had some good results with functions that are satisfied by their function arguments, however those such as current() are proving a bit more difficult.

I've created an example here: https://runkit.com/ymor/runkit-npm-slimdom-sax-parser/1.0.0

I was wondering if its possible to add any further information to the context that get's passed in to the custom function? In this example the original Node that the xpath is to be applied on would be useful.
Thanks.

Q{}name matches namespaced element

Selectors using the Q{}name syntax seem to match nodes with non-null namespaces. I think this should only match Element nodes with localName === "name" and namespaceURI === null?

Registering an XQuery module with a syntax error does not point to the position of the error

Registering an XQuery module with a syntax error does not point to the position of where this error is found. This does work when parsing an XPath query.

Try, for example, to register the following XQuery module:

declare %public function local:test () as xs:string {
	let $error := "not-so-obvious error ->",
	return $error
}

Registering that module will result in the following error message:

AssertionError: Unable to load all files: SyntaxError: Expected " ", "$", "(:", "\n", "\r", or "\t" but "r" found.
    at Context.eval (<webpack>)

Make fontoxpath namespace-aware

Just like slimdom#1.0.0 (the DOM implementation FontoXML uses), fontoxpath is largely ignorant of namespaces. We should implement it: add additional API for a namespace resolver, so that we can use prefixes.
We should default it to making the fn / array / math / map / etc prefixes resolve to the 'normal' namespaces, unless the provided namespace manager says anything different.

This can also bring us QNames.

Order of XPath returns different results when comparing untypedAtomic to date.

An in-range update of @microsoft/api-extractor is breaking the build 🚨

The devDependency @microsoft/api-extractor was updated from 7.1.5 to 7.1.6.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@microsoft/api-extractor is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @microsoft/api-extractor is breaking the build 🚨

The devDependency @microsoft/api-extractor was updated from 7.0.36 to 7.0.37.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@microsoft/api-extractor is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @microsoft/api-extractor is breaking the build 🚨

The devDependency @microsoft/api-extractor was updated from 7.0.27 to 7.0.28.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@microsoft/api-extractor is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Unable to return xs:date or xs:datetime from a custom xpath function

If you register a custom function that returns an xs:date or xs:datetime, you receive the following error at runtime:

Values of the type "${type}" can not be adapted to equivalent XPath values.

Would it be possible to update the case statement to allow dates and datetimes to be returned from custom functions?
Thanks.

Publish FontoXPath to npm

We are making a better XPath test page, which is the only thing blocking a nice NPM release.

We should use a pre-publish hook to build / minify the engine, and remove it from the repository.

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.16.4 to 1.17.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for Prettier 1.17: More quotes options and support for shared configs

🔗 Release Notes

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of prettier is breaking the build 🚨

The devDependency prettier was updated from 1.17.1 to 1.18.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

prettier is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for 1.18.0

🔗 Release Notes

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @microsoft/api-extractor is breaking the build 🚨

The devDependency @microsoft/api-extractor was updated from 7.0.14 to 7.0.15.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@microsoft/api-extractor is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Simple map operator does not work on arrays

When using the simple map operator on arrays, the result is invalid. Doing so in the xpath playground returns the source code of the specified function as string in an array.

Steps to reproduce:
["test"]!string()

Result:
["function(t,n,r,o){return zt(t,n,r,Ot(e),o)}"]

Expected result:
["test"]

Ordering from './/' descendant selector is wrong and different then 'descendant::'

An in-range update of @microsoft/api-extractor is breaking the build 🚨

The devDependency @microsoft/api-extractor was updated from 7.2.1 to 7.2.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@microsoft/api-extractor is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

wrong results when using xpath with attributes

Hello,
In order to try fontoxpath, I created a small test.
The results were not as expected, though they were correct at the Demo page.
The xpath should return all Icons which do not have a tooltip. The expected results here is to get 3 of the Icons (all, but the first one which has a tooltip with value 'test') , but instead all Icons are returned.
I would appreciate your analysis. following is the mocha test.

Thanks,
Gaia

var fontoxpath = require('fontoxpath');
var domParser = require('xmldom').DOMParser;
var assert = require('assert');

describe("fontoxpath functionallity", function() {
it('icons with not tooltip', function() {
var xpath_str = "//core:Icon[(not(@ToolTip) or normalize-space(@ToolTip)='')]";
var xml_str = "<TEST xmlns:core="a.b.core">" +
"<core:Icon tooltip="test"></core:Icon>\n" +
"<core:Icon ></core:Icon>\n" +
"<core:Icon tooltip=" "></core:Icon>\n" +
"<core:Icon tooltip=""></core:Icon>\n" +
""
var parser = new domParser();
var document = parser.parseFromString(xml_str);

    var nodes = fontoxpath.evaluateXPathToNodes(xpath_str, document, fontoxpath.domFacade, null, {namespaceResolver: function (prefix)
        {
            var NAMESPACES = {
                "core": "a.b.core"
            };
            return NAMESPACES[prefix];
        }});
    assert.ok(nodes.length === 3, "expected 3 got " + nodes.length);//result is 4
});

});

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Document the Q{http://fontoxml.com/fontoxpath}version function

FontoXPath defines a couple of 'custom' functions. These are documented nowhere, but they might be useful in some cases.

IIRC:

fontoxpath:version#0
fontoxpath:evaluate#2
fontoxpath:sleep#2 (which could remain private. It's mostly used for testing)

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 12.0.10 to 12.0.11.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Remove asynchronous compilation of XPaths

This code is notoriously unstable and has stopped working a couple of times now. We at Fonto rarely use it because selector parsing is not that hard anyway and we want to have more control on when different parts of the codebase are executed.

We should remove it and remove the hard-to-test code related to asynchronous compilation (webworkers, indexedDB, etc).

Cannot find module './xPathParser.raw'

I cloned the repository, tried to run npm start and npm run test and got the same error:
Error: Cannot find module './xPathParser.raw';

There is a line in .gitignore:

/src/parsing/xPathParser.raw.ts

Clearly, src/parsing doesn't contain any file with that name:
https://github.com/FontoXML/fontoxpath/tree/39c7039bb4dd0883170b98eca225f6c4e619c78b/src/parsing

I guess it is some typescript code that should be compiled to xPathParser.raw.
But it doesn't exist in the repository.

Where can I find it?

An in-range update of slimdom-sax-parser is breaking the build 🚨

The devDependency slimdom-sax-parser was updated from 1.1.3 to 1.2.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

slimdom-sax-parser is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 7 commits.

  • c933834 Never not update README and tests
  • 1c82fc1 Time on a README is never wasted
  • bac2ae1 Release 1.2.0, Updating README, adding some JSDoc
  • 7153e50 Organizing code
  • bf477f9 Clean up some ns code
  • 87d0dc0 Finish position tracking for all tested scenarios
  • 9c56b60 Dabble with position tracking + code cleanup and better tests along the way

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Empty function definitions should not be able to be parsed

Enable asynchronous XPath expressions

JavaScript has one downside: it is single threaded. Async calls can never me 'made synchronous' again. At Fonto, we have some use cases for async functions (ie. resolving references, loading documents, etc.).

We could make XPath functions return promises, but that would need a second implementation, since we also want to be able to run XPath queries synchronously, because the async overhead is not insignificant.

map:for-each is implemented incorrectly

map:for-each should return the concatenation of all of the results of the callback function, but we return a map with the same keys, but the result of the callback function applied to the original value.

It also seems that not all QT3 tests are running, the tests for map:for-each, for instance, should be failing, but they are not evaluated.

An in-range update of fs-extra is breaking the build 🚨

The devDependency fs-extra was updated from 8.0.1 to 8.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

fs-extra is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 9 commits.

  • b7df7cc 8.1.0
  • 40c3d68 Use graceful-fs everywhere (#700)
  • 9f1c029 Travis config tweaks (#693)
  • 713c606 Add package-lock.json to .gitignore (#691)
  • 31e177a Clarify docs for remove*() (#690)
  • fff04cb Use files array in package.json instead of .npmignore (#692)
  • 7a8424e Update CI configs to test new Node versions (#683)
  • f3a2eed Upgrade to standard v12 (#685)
  • fa661f3 Add support for fs.realpath.native in envs that support it (#682)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Optimize PathSelector mergeSortedSequences

This function merges locally sorted sequences, it does this using a merge sort algorithm. For the case of ['path', ['descendant-or-self', ...], ['child', ...]], the sequences are even always globally sorted on the first result. We should be able to use this to our advantage, preventing a sort for the first item.

Because the ordering of further items in the separate sequences are not guaranteed to be in the global ordering, we would have to use position compares at a later point, but only up to the sequence from which we have yielded.

The current implementation forces a full document scan for queries like (//*)[1], because it is compiled to (/descendant-or-self::*/child::*)[1]. The new implementation would make it of constant complexity, yielding the very first node.

Another optimization would be rewriting (//*) to (/descendant::*), but the better sorting approach would also apply to all queries like (/descendant::elementName/parent::parentName).

This rule should apply to all expressions of the form [sorted]/[peer], but not for expressions of the form [sorted]/[subtree]: (/descendant::*/descendant::*[last()])[1] != (/descendant::*!descendant::*[last()])[1]

memory leak in nodeValueCache

The nodeValueCache.js files mentions why weak maps are a great choice for what we're doing there, but a normal map is used.

This causes a memory leak when one is working with loads of nodes with different lifetimes than the application...

An in-range update of sinon is breaking the build 🚨

The devDependency sinon was updated from 7.2.3 to 7.2.4.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 13 commits.

  • 06fc27d Update docs/changelog.md and set new release id in docs/_config.yml
  • 54da371 Add release documentation for v7.2.4
  • e5de1fe 7.2.4
  • d158672 Update CHANGELOG.md and AUTHORS for new release
  • 1431c78 minor package updates
  • 37c955d Merge pull request #1979 from fatso83/update-npm-deps
  • fc2a32a Merge pull request #1975 from ehmicky/master
  • 85f2fcd Update eslint-plugin-mocha
  • 707e068 Fix high prio audit warnings
  • 8282bc0 Update nise to use @sinonjs/text-encoding
  • c1d9625 Make all properties non-enumerable in spies, stubs, mocks and fakes
  • 894951c Merge pull request #1973 from mgred/default-sandbox-example
  • 876aebb docs(sandbox): add example for default sandbox

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Run QT3 (or all tests) tests in node

The CI environment is slow, especially for the QT3 tests... We can speed it up by running the tests in NodeJS.

I tried to implement this but I ran into issues with datetime subtraction. See the 'node-tests' branch,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.