Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@wmfs/j2119

wmfs3.6kMIT1.29.0

A general-purpose validator generator that uses RFC2119-style assertions as input.

tymly, package

readme

j2119

Tymly Package npm (scoped) CircleCI codecov Dependabot badge Commitizen friendly JavaScript Style Guide license

A general-purpose validator generator that uses RFC2119-style assertions as input.

This package is derived from Amazon Web Services Labs' awslabs/j2119.

Usage

There is only one outward-facing function, J2119Validator.

const J2119Validator = require('@wmfs/j2119')

const validator = J2119Validator(schema-filename, ...[schema-extension-filenames])
  • schema-filename is the name of a file containing text in the J2119 syntax described below.
  • schema-extension-filenames are zero or more names of files containing extensions to the schema, using the same J2119 syntax.

J2219Validator returns a validator, which can be re-used, and should be, since its construction is moderately expensive. If the schema files can not be read, then the function will throw an exception.

validate

const problems = validator.validate(json)
  • source is the JSON object to be validated.

    validate returns a string array of error messages describing any problems it found. If the array is empty, then there were no problems. The error messages are human-readable and have the general form <json-path to error site> <description of error>.

root

const root = validator.root

root returns the root "role" in the J2119 schema, a string that is useful in making user-friendly error messages.

J2119 Syntax

J2119's operations are driven by a set of assertions containing the words "MUST" and "MAY" used in the style found in IETF RFCs, and specified in RFC 2119. It is organized in lines, each terminated with a single full stop. There are three formalisms, "roles", "types" and "constraints". For example:

A Message MUST have an object-array field named "Paragraphs"; each member is a "Paragraph".

In the above assertion, "Message" and "Paragraph" are roles, "string-array" is a type; the whole line says that a JSON node with the role "Message" is required to have a field named "Paragraphs" whose value is a JSON array containing only object values. It further says that when validating the object members of the array, they are considered to have the role "Paragraph".

The first line of the J2119 schema must be of the following form:

This document specifies a JSON object called a "Message".

This gives the root object the role "Message". Descendant nodes can be given roles based on their parentage (as in the first J2119 example above) and the presence or value of certain fields, and nodes can have multiple roles simultaneously.

The J2119 syntax was invented for the purpose of constructing a validator for one specific JSON DSL (the Amazon States Language) and, at time of writing, there is no claim that it is suitable as a general-purpose JSON schema facility. At this point, the best way to understand J2119 is by example. In the test fixtures directory of this package there is a file AWL.j2119, which may be considered a complete worked example of how to specify a DSL.

Schema Extensions

As WMFS were adapting this code from the AWS Labs original, it became apparent we had a couple of small extensions to ASL which caused our validation to fail. Rather than drop additional rules into the ASL definition, we defined our assertions as extensions. Extensions are organized exactly as above, except that the first line of a J2119 schema extension have the form:

This document specifies an extension to a JSON object called a "Message".

The object name must match that in the root schema. See the file TymlyExtension.j2119 for an example of a DSL extension.

To Do

At time of writing, the AWS Labs' package carries the following TODO

At the moment, the J2119 syntax is parsed via the brute-force application of overly complex regular expressions. It is in serious need of modularization, a real modern parser architecture, and perhaps the application of some natural-language processing techniques.

Aside from that, the framework of roles, conditionals, and constraints is simple enough and performs at acceptable speed.

Contributing

Bug reports and pull requests are welcome on GitHub. Please be aware of our Code of Conduct

License

Licensed under the terms of the MIT license. Copyright (c) 2018, 2024 West Midlands Fire Service

changelog

1.29.0 (2025-04-01)

Build system dependencies :hammer:

  • deps: update dependency luxon to v3.6.1 (#346) (d0e201c)

1.28.0 (2025-03-31)

Build system dependencies :hammer:

  • deps: update dependency luxon to v3.6.0 (#345) (1afc596)

1.27.0 (2025-02-25)

Build system dependencies :hammer:

  • deps-dev: [sc-29160] Resolve issue with semantic-release changelog notes (#340) (0e62e1b)
  • deps-dev: update dependency mocha to v11 (#338) (9910b90)
  • deps-dev: update dependency mocha to v11.1.0 (#341) (ecf3ebe)
  • deps-dev: update dependency semantic-release to v24.2.1 (#339) (c6fe812)
  • deps-dev: update dependency semantic-release to v24.2.2 (#342) (e4919c2)
  • deps-dev: update dependency semantic-release to v24.2.3 (#343) (0304edf)
  • deps: update dependency xregexp to v5.1.2 (#344) (c3a83bd)

1.26.0 (2024-11-04)

1.25.1 (2024-09-16)

Bug Fixes

  • Check for grandchild roles before recursing into grandchildren. (#331) (8611ec3)

1.25.0 (2023-03-13)

🛠 Builds

  • deps-dev: update dependency semantic-release to v20.1.1 (46d35f6)
  • deps: update dependency luxon to v3.3.0 (36baf4d)

1.24.0 (2023-02-17)

🛠 Builds

  • deps-dev: update dependency @semantic-release/changelog to v6.0.2 (08bdb53)
  • deps-dev: update dependency chai to v4.3.7 (e698034)
  • deps-dev: update dependency mocha to v10.2.0 (4433da7)
  • deps-dev: update dependency semantic-release to v20 (9e1f2be)
  • deps-dev: update dependency semantic-release to v20.0.1 (2b5a305)
  • deps-dev: update dependency semantic-release to v20.0.2 (cc9d192)
  • deps-dev: update dependency semantic-release to v20.0.3 (4100347)
  • deps-dev: update dependency semantic-release to v20.0.4 (d2b887d)
  • deps-dev: update dependency semantic-release to v20.1.0 (dcfb47d)
  • deps: update dependency luxon to v3.2.1 [security] (2a3c76d)

1.23.0 (2022-11-02)

🛠 Builds

  • deps: update dependency luxon to v3 (43979c1)

1.22.0 (2022-11-02)

🛠 Builds

  • deps-dev: update dependency chai to v4.3.5 (bdb1a17)
  • deps-dev: update dependency chai to v4.3.6 (3274c9b)
  • deps-dev: update dependency mocha to v10 (f4acece)
  • deps-dev: update dependency mocha to v10.1.0 (2ba524d)
  • deps-dev: update dependency mocha to v9.2.1 (90ee18f)
  • deps-dev: update dependency mocha to v9.2.2 (740b958)
  • deps-dev: update dependency semantic-release to v19.0.3 (b78dac7)
  • deps-dev: update dependency semantic-release to v19.0.5 (6166051)
  • deps-dev: update dependency standard to v17 (c90df2e)
  • deps: update dependency xregexp to v5.1.1 (2f1751e)

1.21.0 (2022-01-25)

🛠 Builds

  • deps-dev: update dependency @semantic-release/changelog to v6 (3104e30)
  • deps-dev: update dependency @semantic-release/git to v10 (ba279eb)
  • deps-dev: update dependency @semantic-release/git to v9.0.1 (8557a4d)
  • deps-dev: update dependency mocha to v9.1.0 (c47fc8a)
  • deps-dev: update dependency mocha to v9.1.1 (6ec27b4)
  • deps-dev: update dependency mocha to v9.1.2 (0ad9dfb)
  • deps-dev: update dependency mocha to v9.1.3 (0b668a9)
  • deps-dev: update dependency mocha to v9.1.4 (b8ffab8)
  • deps-dev: update dependency mocha to v9.2.0 (0539713)
  • deps-dev: update dependency semantic-release to v17.4.5 (75e2108)
  • deps-dev: update dependency semantic-release to v17.4.6 (cd710bf)
  • deps-dev: update dependency semantic-release to v17.4.7 (880e720)
  • deps-dev: update dependency semantic-release to v18 (389f19f)
  • deps-dev: update dependency semantic-release to v18.0.1 (8e850f2)
  • deps-dev: update dependency semantic-release to v19 (7ac771f)
  • deps-dev: update dependency standard to v16.0.4 (255c9f0)
  • deps-dev: update semantic-release monorepo (3c9c0c0)
  • deps: update dependency luxon to v1.28.0 (9a64da9)

1.20.0 (2021-08-05)

🐛 Bug Fixes

  • named backreference properties now appear on the results "groups" (2f77e4a)
  • named backreference properties now appear on the results "groups" (afe13f2)

🛠 Builds

  • deps: update dependency xregexp to v5 (905414e)
  • deps-dev: bump codecov from 3.8.2 to 3.8.3 (9ae41b9)
  • deps-dev: bump mocha from 8.4.0 to 9.0.0 (17d24df)
  • deps-dev: bump mocha from 9.0.0 to 9.0.1 (e914963)
  • deps-dev: bump mocha from 9.0.1 to 9.0.2 (cc7989f)
  • deps-dev: bump mocha from 9.0.2 to 9.0.3 (cd975ed)
  • deps-dev: bump semantic-release from 17.4.3 to 17.4.4 (3e30c61)

♻️ Chores

  • add renovate config [ch6600] (e557e93)

1.19.0 (2021-05-26)

🛠 Builds

  • deps: bump luxon from 1.26.0 to 1.27.0 (d882736)
  • deps-dev: bump chai from 4.3.0 to 4.3.1 (1cd9641)
  • deps-dev: bump chai from 4.3.1 to 4.3.2 (4d63694)
  • deps-dev: bump chai from 4.3.2 to 4.3.3 (11a35b2)
  • deps-dev: bump chai from 4.3.3 to 4.3.4 (6d987ce)
  • deps-dev: bump codecov from 3.8.1 to 3.8.2 (f58bd37)
  • deps-dev: bump mocha from 8.3.0 to 8.3.1 (e3841d9)
  • deps-dev: bump mocha from 8.3.1 to 8.3.2 (5675e6b)
  • deps-dev: bump mocha from 8.3.2 to 8.4.0 (368e65f)
  • deps-dev: bump semantic-release from 17.3.9 to 17.4.0 (bf90693)
  • deps-dev: bump semantic-release from 17.4.0 to 17.4.1 (06b812d)
  • deps-dev: bump semantic-release from 17.4.1 to 17.4.2 (c7cc8e6)
  • deps-dev: bump semantic-release from 17.4.2 to 17.4.3 (f98a5f5)

1.18.0 (2021-02-17)

🛠 Builds

  • deps: bump luxon from 1.25.0 to 1.26.0 (761e037)
  • deps-dev: bump chai from 4.2.0 to 4.3.0 (9dabed9)
  • deps-dev: bump mocha from 8.2.1 to 8.3.0 (f7faaef)
  • deps-dev: bump semantic-release from 17.3.1 to 17.3.2 (9285e12)
  • deps-dev: bump semantic-release from 17.3.2 to 17.3.3 (635868e)
  • deps-dev: bump semantic-release from 17.3.3 to 17.3.4 (ac87327)
  • deps-dev: bump semantic-release from 17.3.4 to 17.3.5 (4927c18)
  • deps-dev: bump semantic-release from 17.3.5 to 17.3.6 (833f564)
  • deps-dev: bump semantic-release from 17.3.6 to 17.3.7 (73a3dd0)
  • deps-dev: bump semantic-release from 17.3.7 to 17.3.8 (38ac6c7)
  • deps-dev: bump semantic-release from 17.3.8 to 17.3.9 (eb99be3)

1.17.0 (2021-01-06)

🛠 Builds

  • deps: bump xregexp from 4.3.0 to 4.4.1 (b0d251a)

1.16.0 (2021-01-06)

🛠 Builds

  • deps: bump n-readlines from 1.0.0 to 1.0.1 (201cf50)
  • deps-dev: bump codecov from 3.7.2 to 3.8.0 (0b0f152)
  • deps-dev: bump codecov from 3.8.0 to 3.8.1 (992c8a7)
  • deps-dev: bump cz-conventional-changelog from 3.2.0 to 3.2.1 (4b2c12d)
  • deps-dev: bump cz-conventional-changelog from 3.2.1 to 3.3.0 (e0d161f)
  • deps-dev: bump mocha from 8.1.1 to 8.1.2 (1f51644)
  • deps-dev: bump mocha from 8.1.2 to 8.1.3 (20770ca)
  • deps-dev: bump mocha from 8.1.3 to 8.2.0 (6848af0)
  • deps-dev: bump mocha from 8.2.0 to 8.2.1 (48ab475)
  • deps-dev: bump semantic-release from 17.1.1 to 17.1.2 (5d8fcc2)
  • deps-dev: bump semantic-release from 17.1.2 to 17.2.0 (8be3422)
  • deps-dev: bump semantic-release from 17.2.0 to 17.2.1 (33ef96a)
  • deps-dev: bump semantic-release from 17.2.1 to 17.2.2 (42c424c)
  • deps-dev: bump semantic-release from 17.2.2 to 17.2.3 (f455378)
  • deps-dev: bump semantic-release from 17.2.3 to 17.2.4 (9965a6b)
  • deps-dev: bump semantic-release from 17.2.4 to 17.3.0 (5e09c95)
  • deps-dev: bump semantic-release from 17.3.0 to 17.3.1 (4c95b37)
  • deps-dev: bump standard from 14.3.4 to 15.0.0 (577a440)
  • deps-dev: bump standard from 15.0.0 to 15.0.1 (bbde662)
  • deps-dev: bump standard from 15.0.1 to 16.0.0 (6e4dc00)
  • deps-dev: bump standard from 16.0.0 to 16.0.1 (5bb0d5f)
  • deps-dev: bump standard from 16.0.1 to 16.0.2 (6e04b56)
  • deps-dev: bump standard from 16.0.2 to 16.0.3 (06ad3ff)

⚙️ Continuous Integrations

  • circle: add parallelism for unit tests [ch2766] (b00e000)
  • circle: authenticate Docker image pull [ch2767] (f74fe28)
  • circle: cache dependencies [ch2770] (8c03857)
  • circle: separate linting job [ch1009] (7e3c96a)
  • circle: update build environment variable context name [ch2771] (6b811e2)

1.15.0 (2020-08-24)

🛠 Builds

  • deps: bump luxon from 1.24.1 to 1.25.0 (20bc017)
  • deps-dev: bump codecov from 3.6.5 to 3.7.0 (e6b1e81)
  • deps-dev: bump codecov from 3.7.0 to 3.7.1 (249dc01)
  • deps-dev: bump codecov from 3.7.1 to 3.7.2 (1bc96a2)
  • deps-dev: bump mocha from 7.1.2 to 7.2.0 (b6a7e90)
  • deps-dev: bump mocha from 7.2.0 to 8.0.1 (6691ce9)
  • deps-dev: bump mocha from 8.0.1 to 8.1.0 (d1bd289)
  • deps-dev: bump mocha from 8.1.0 to 8.1.1 (8df57e5)
  • deps-dev: bump nyc from 15.0.1 to 15.1.0 (24ba704)
  • deps-dev: bump semantic-release from 17.0.7 to 17.0.8 (c5e7b21)
  • deps-dev: bump semantic-release from 17.0.8 to 17.1.0 (47d6b8f)
  • deps-dev: bump semantic-release from 17.1.0 to 17.1.1 (ad9a067)
  • deps-dev: bump standard from 14.3.3 to 14.3.4 (a7ef217)

⚙️ Continuous Integrations

  • circle: separate lint job [ch1009] (9e0d412)
  • circle: use updated circle node image [skip ci] (c3e2d52)

1.14.0 (2020-05-11)

🛠 Builds

  • deps: bump luxon from 1.23.0 to 1.24.1 (018caed)
  • deps-dev: bump cz-conventional-changelog from 3.1.0 to 3.2.0 (04069f5)
  • deps-dev: bump mocha from 7.1.1 to 7.1.2 (fd76181)
  • deps-dev: bump semantic-release from 17.0.4 to 17.0.5 (0fcea53)
  • deps-dev: bump semantic-release from 17.0.5 to 17.0.6 (ccf5097)
  • deps-dev: bump semantic-release from 17.0.6 to 17.0.7 (544407c)

1.13.0 (2020-04-05)

🛠 Builds

  • deps: bump luxon from 1.22.2 to 1.23.0 (2847685)
  • deps-dev: bump nyc from 15.0.0 to 15.0.1 (591224c)

1.12.0 (2020-04-02)

🛠 Builds

  • deps: bump luxon from 1.22.0 to 1.22.2 (bd0543e)
  • deps-dev: bump @semantic-release/changelog from 5.0.0 to 5.0.1 (4e900e2)
  • deps-dev: bump @semantic-release/git from 7.0.18 to 9.0.0 (23c1818)
  • deps-dev: bump conventional-changelog-metahub from 4.0.0 to 4.0.1 (943fa49)
  • deps-dev: bump mocha from 7.0.1 to 7.1.0 (4b3d06a)
  • deps-dev: bump mocha from 7.1.0 to 7.1.1 (75c69b7)
  • deps-dev: bump semantic-release from 15.14.0 to 17.0.3 (3d079cc)
  • deps-dev: bump semantic-release from 17.0.3 to 17.0.4 (5c48a41)
  • deps-dev: bump standard from 14.3.1 to 14.3.2 (3bf60da)
  • deps-dev: bump standard from 14.3.2 to 14.3.3 (f783dc0)

⚙️ Continuous Integrations

  • circle: add context env var config to config.yml (407f70f)

1.11.0 (2020-02-12)

🛠 Builds

  • deps: bump xregexp from 4.2.4 to 4.3.0 (412b658)
  • deps-dev: bump @semantic-release/changelog from 3.0.6 to 5.0.0 (da5d66f)
  • deps-dev: bump codecov from 3.6.2 to 3.6.3 (0cb90dd)
  • deps-dev: bump codecov from 3.6.3 to 3.6.4 (b982d3b)
  • deps-dev: bump codecov from 3.6.4 to 3.6.5 (028d315)
  • deps-dev: bump cz-conventional-changelog from 3.0.2 to 3.1.0 (5e342e0)

1.10.0 (2020-01-27)

🛠 Builds

  • deps: bump luxon from 1.21.3 to 1.22.0 (f204a5f)
  • deps-dev: bump codecov from 3.6.1 to 3.6.2 (50d2ed5)
  • deps-dev: bump conventional-changelog-metahub from 3.0.0 to 4.0.0 (caef555)
  • deps-dev: bump mocha from 7.0.0 to 7.0.1 (ffcc2e4)
  • deps-dev: update standard requirement from 12.0.1 to 14.3.1 (49c2c14)

💎 Styles

  • standard --fix (0986b50)
  • Unexpected lexical declaration in case block (c7b90f1)

1.9.0 (2020-01-06)

🛠 Builds

  • deps: bump luxon from 1.16.0 to 1.21.3 (40168eb)
  • deps-dev: bump mocha from 6.2.2 to 7.0.0 (541fd88)
  • deps-dev: bump packages (272e620)
  • deps-dev: update @semantic-release/git requirement (91d9e4a)
  • deps-dev: update dev dependancies (06c90cc)
  • deps-dev: update nyc requirement from 13.1.0 to 14.1.1 (a93ee1e)

📚 Documentation

⚙️ Continuous Integrations

  • circle: Add CircleCI config (7d80a19)
  • travis: Remove Travis config (f8c3ba7)

1.8.0 (2019-06-26)

🛠 Builds

  • deps: update luxon requirement from 1.8.1 to 1.16.0 (e25d81a)
  • deps: update xregexp requirement from 4.2.0 to 4.2.4 (de80b4c)
  • deps-dev: update @semantic-release/git requirement (a02778e)
  • deps-dev: update codecov requirement from 3.1.0 to 3.5.0 (72ffeb7)
  • deps-dev: update mocha requirement from 5.2.0 to 6.1.4 (c4b1cbd)
  • deps-dev: update semantic-release requirement (83d6d3d)

1.7.1 (2019-01-10)

🐛 Bug Fixes

  • Allow integer values in Float fields (269a212), closes #37

🛠 Builds

1.7.0 (2018-12-04)

🛠 Builds

  • deps: Update luxon from 1.6.2 to 1.8.1 (781fc7c)
  • release: Update semantic-release and release config (5e315ee)