Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:

- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
71 changes: 65 additions & 6 deletions .github/workflows/deno-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches: [ main ]
pull_request: {}

permissions:
contents: read

jobs:

check:
Expand All @@ -13,20 +16,76 @@ jobs:
strategy:
matrix:
deno-version:
- v1.18
- v1.20
- v1.22
- v1.40
- v2.0
- v2.1
- v2.2
- v2.3
- v2.4
- v2.5
- canary
fail-fast: false # run each branch to completion

steps:
- name: Checkout source
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: deno/${{ matrix.deno-version }}-${{ github.sha }}

- name: Use Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: ${{ matrix.deno-version }}

- name: 'Possibly reset lockfile'
run: deno install || rm deno.lock

- name: Run test suite
run: deno test --allow-read=test test/*.js
run: deno task test

dry-run:
runs-on: ubuntu-latest

steps:
- name: Checkout source
uses: actions/checkout@v5

- name: Use stable Deno
uses: denoland/setup-deno@v2

- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: deno/publish-${{ github.sha }}

- name: Check publish rules
run: time deno publish --dry-run --allow-dirty

publish:
runs-on: ubuntu-latest
needs: check
if: github.event_name == 'push'

permissions:
contents: read
id-token: write

steps:
- name: Checkout source
uses: actions/checkout@v5

- name: Use stable Deno
uses: denoland/setup-deno@v2

- name: Cache Deno deps
uses: actions/cache@v4
with:
path: ~/.cache/deno
key: deno/publish-${{ github.sha }}
- name: Publish now
run: deno publish
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
![Test CI](https://github.com/danopia/deno-jmespath/workflows/CI/badge.svg?branch=main)
![Test CI](https://github.com/danopia/jmespath/workflows/CI/badge.svg?branch=main)

# deno.land/x/jmespath
# JSR package `@cloudydeno/jmespath`

A jmespath-ts fork, repackaged and ported to Deno.
The `src/` directory is published to deno.land.
A jmespath-ts fork, repackaged and ported to be Deno-first.
The `src/` directory is published [to JSR](https://jsr.io/@cloudydeno/jmespath).
The `test/` directory contains the upstream unit tests.


```javascript
// deno add jsr:@cloudydeno/jmespath

import { search, compile } from '@cloudydeno/jmespath';
```

This library should be useful for JSON-heavy APIs such as AWS.

In the process of porting,
Expand Down
20 changes: 20 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@cloudydeno/jmespath",
"version": "1.0.0",
"license": "MPL-2.0",
"exports": "./src/index.ts",
"imports": {
"@std/assert": "jsr:@std/assert@^1",
"@std/path": "jsr:@std/path@^1"
},
"tasks": {
"test": "deno test --allow-read=test test/*.js"
},
"publish": {
"exclude": [
".editorconfig",
".github",
"test"
]
}
}
31 changes: 31 additions & 0 deletions deno.lock

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

8 changes: 4 additions & 4 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ given a JMESPath expression.
### `search(data: JSONValue, expression: string): JSONValue`

```javascript
import { search } from "https://deno.land/x/jmespath/index.ts";
import { search } from "jsr:@cloudydeno/jmespath";

search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]")

Expand All @@ -31,7 +31,7 @@ The JMESPath language can do *a lot* more than select an element
from a list. Here are a few more examples:

```javascript
import { search } from "https://deno.land/x/jmespath/index.ts";
import { search } from "jsr:@cloudydeno/jmespath";

/* --- EXAMPLE 1 --- */

Expand Down Expand Up @@ -82,7 +82,7 @@ search(JSON_DOCUMENT, "foo[?age > `30`]");
Extend the list of built in JMESpath expressions with your own functions.

```javascript
import {search, registerFunction, TYPE_NUMBER} from "https://deno.land/x/jmespath/index.ts";
import {search, registerFunction, TYPE_NUMBER} from "jsr:@cloudydeno/jmespath";


search({ foo: 60, bar: 10 }, 'divide(foo, bar)')
Expand All @@ -109,7 +109,7 @@ function takes a JMESPath expression and returns an abstract syntax tree that
can be used by the TreeInterpreter function

```javascript
import { compile, TreeInterpreter } from "https://deno.land/x/jmespath/index.ts";
import { compile, TreeInterpreter } from "jsr:@cloudydeno/jmespath";

const ast = compile('foo.bar');

Expand Down
2 changes: 1 addition & 1 deletion src/Runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Runtime {
private validateArgs(name: string, args: any[], signature: InputSignature[]): void {
let pluralized: boolean;
this.validateInputSignatures(name, signature);
const numberOfRequiredArgs = signature.filter(argSignature => !argSignature.optional ?? false).length;
const numberOfRequiredArgs = signature.filter(argSignature => !argSignature.optional).length;
const lastArgIsVariadic = signature[signature.length - 1]?.variadic ?? false;
const tooFewArgs = args.length < numberOfRequiredArgs;
const tooManyArgs = args.length > signature.length;
Expand Down
2 changes: 1 addition & 1 deletion src/TreeInterpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,5 @@ export class TreeInterpreter {
}
}

export const TreeInterpreterInstance = new TreeInterpreter();
export const TreeInterpreterInstance: TreeInterpreter = new TreeInterpreter();
export default TreeInterpreterInstance;
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import Parser from './Parser.ts';
import Lexer from './Lexer.ts';
import TreeInterpreterInst from './TreeInterpreter.ts';
import type { ASTNode, LexerToken } from './Lexer.ts';
import { InputArgument, RuntimeFunction, InputSignature } from './Runtime.ts';
import { InputArgument, type RuntimeFunction, type InputSignature } from './Runtime.ts';

export {
type ASTNode,
type Token,
type LexerToken,
} from './Lexer.ts';

export type { FunctionSignature, RuntimeFunction, InputSignature } from './Runtime.ts';
export type ObjectDict<T = unknown> = Record<string, T | undefined>;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const isFalse = (obj: unknown): boolean => {
}
if (isObject(obj)) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (Object.hasOwn(obj, key)) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import { search } from '../src/index.ts';

import { basename, join } from 'https://deno.land/std@0.140.0/path/mod.ts';
import { basename } from '@std/path/basename';
import { join } from '@std/path/join';
import { describe, it, expect, each } from './deno-shim.js';

// Compliance tests that aren't supported yet.
Expand Down
4 changes: 2 additions & 2 deletions test/compliance/syntax.json
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
},
{
"expression": "\"foo",
"error": "Unexpected end of JSON input"
"error": "Unterminated string in JSON at position 4 (line 1 column 5)"
}
]
},
Expand Down Expand Up @@ -523,7 +523,7 @@
{
"comment": "Literal char not escaped",
"expression": "foo[?bar==`[\"foo`bar\"]`]",
"error": "Unexpected end of JSON input"
"error": "Unterminated string in JSON at position 5 (line 1 column 6)"
},
{
"comment": "Literal char escaped",
Expand Down
8 changes: 4 additions & 4 deletions test/deno-shim.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
assertEquals, assertStrictEquals,
assertThrows, assertStringIncludes,
} from "https://deno.land/std@0.140.0/testing/asserts.ts";
import { assertEquals } from "@std/assert/equals";
import { assertStrictEquals } from "@std/assert/strict-equals";
import { assertThrows } from "@std/assert/throws";
import { assertStringIncludes } from "@std/assert/string-includes";

const suiteStack = [];

Expand Down