Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #2

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules/
dist/
.vscode
17 changes: 17 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"loader": "ts-node/esm",
"extensions": [
"ts",
"tsx"
],
"spec": [
"src/**/*.test.*"
],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"watch-files": [
"src"
]
}
54 changes: 53 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,63 @@ For development you will need to get the latest `woql.json` from the
terminusdb repository. Assuming you have wget installed, you can run:

```
$ npm run woql-get
$ npm run woqlget
```

After which you can build the new `woql.ts` file by running

```
$ npx src/generate.ts
```

## Usage example

The WOQL below query identifies document identifiers that are not subdocuments.

```javascript
const woqlStr = `
and(triple(doc, "rdf:type", type),
not(quad(type, "sys:subdocument", unbound, "schema")),
)
`
const woql = parseWoqlString(woqlStr);
const postBody = prepareWoqlHttpPostBody(woql);
const result = await terminusClient.sendCustomRequest("POST", `http://localhost:6363/api/woql/admin/sandbox/local/branch/main`, postBody);
```


## Syntax options for variables

The WOQL DSL parser and WOQL transformer supports new WOQL authoring styles. Variables can now be declared in multiple ways, and the DSL even support undeclared variables.

* Variables get assigned through the new `(var1, var2, var3...) => { ... }`
* Undeclared variables are supported for the DSL (similar to datalog variables)
* Variables support the `v:` prefix to maintain backwards compatibility

### Examples

```javascript
(doc, type, unbound) =>
and(
triple(doc, "rdf:type", type),
not(quad(type, "sys:subdocument", unbound, "schema")),
)
```

```javascript
and(
triple(doc, "rdf:type", type),
not(quad(type, "sys:subdocument", unbound, "schema")),
)
```

```javascript
and(
triple("v:doc", "rdf:type", "v:type"),
not(quad("v:type", "sys:subdocument", "v:unbound", "schema")),
)
```

## Unimplemented key functionality

* As (for CSV Get handling to support previous functionality)
1 change: 1 addition & 0 deletions dist/generate.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
3 changes: 3 additions & 0 deletions dist/generate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/generate.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './syntax.js';
export * from './lib/index.js';
export * as WOQL from './syntax.js';
4 changes: 4 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions dist/lib/AstTransformation/JsWoqlAstTransformer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Node } from 'acorn';
import type { Query } from '../../syntax.js';
export declare class AstJsWoqlTransformer {
transform(node: Node): Query;
private visitNodeValue;
private visitNode;
private visitIdentifier;
private visitLiteral;
private readonly literalExceptions;
private currentCallExpression;
private visitCallExpression;
private readonly registeredVariableNames;
private visitArrowFunctionExpression;
}
247 changes: 247 additions & 0 deletions dist/lib/AstTransformation/JsWoqlAstTransformer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/lib/AstTransformation/JsWoqlAstTransformer.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions dist/lib/AstTransformation/JsWoqlAstTransformer.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Query } from '../../syntax.js';
export interface MockData {
textWoql: string;
woqlAst: Query;
}
Loading