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

Add json schema pointer #20

Merged
merged 3 commits into from
Sep 8, 2023
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
2 changes: 2 additions & 0 deletions packages/parser/json-schema-pointer/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/*.js
**/*.mjs
8 changes: 8 additions & 0 deletions packages/parser/json-schema-pointer/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type { import("eslint").ESLint.ConfigData } */
module.exports = {
extends: '@cuaklabs/eslint-config',
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
};
11 changes: 11 additions & 0 deletions packages/parser/json-schema-pointer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# node modules
/node_modules/

# Test coverage report
/coverage

# Compiled files
/lib/

# Turborepo files
.turbo/
9 changes: 9 additions & 0 deletions packages/parser/json-schema-pointer/.lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"*.js": [
"prettier --write"
],
"*.ts": [
"prettier --write",
"eslint"
]
}
20 changes: 20 additions & 0 deletions packages/parser/json-schema-pointer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

<!--
## [UNRELEASED]

### Added
### Changed
### Deprecated
### Removed
### Fixed
### Security
### Docs
-->



24 changes: 24 additions & 0 deletions packages/parser/json-schema-pointer/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
3 changes: 3 additions & 0 deletions packages/parser/json-schema-pointer/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { tsGlobalConfig } from '@cuaklabs/jest-config';

export default tsGlobalConfig;
3 changes: 3 additions & 0 deletions packages/parser/json-schema-pointer/jest.js.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { jsGlobalConfig } from '@cuaklabs/jest-config';

export default jsGlobalConfig;
53 changes: 53 additions & 0 deletions packages/parser/json-schema-pointer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"author": "Roberto Pintos López (https://github.com/notaphplover)",
"description": "JSON Schema parser",
"devDependencies": {
"@cuaklabs/json-schema-types": "workspace:*",
"@jest/globals": "29.6.4",
"@types/glob": "8.1.0",
"@types/node": "18.17.14",
"@typescript-eslint/eslint-plugin": "6.6.0",
"@typescript-eslint/parser": "6.6.0",
"eslint": "8.48.0",
"eslint-import-resolver-typescript": "3.6.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jest": "27.2.3",
"eslint-plugin-prettier": "5.0.0",
"jest": "29.6.4",
"jest-mock": "29.6.3",
"prettier": "3.0.3",
"rimraf": "5.0.1",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.2.2"
},
"bugs": {
"url": "https://github.com/cuaklabs/ajstt/issues"
},
"homepage": "https://github.com/cuaklabs/ajstt#readme",
"license": "See license in \"LICENSE\" file",
"exports": "./lib/index.js",
"main": "lib/index.js",
"name": "@cuaklabs/json-schema-pointer",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/cuaklabs/ajstt.git"
},
"scripts": {
"build": "tsc --build tsconfig.json",
"build:clean": "rimraf lib",
"format": "prettier --write ./src/**/*.ts",
"lint": "eslint --ext ts --ignore-path .gitignore ./src",
"prebuild": "pnpm run build:clean",
"test:ts": "jest --config=jest.config.mjs --runInBand",
"test:integration": "pnpm run test --selectProjects Integration",
"test": "jest --config=jest.js.config.mjs --runInBand",
"test:coverage": "pnpm run test --coverage",
"test:uncommitted": "pnpm run test:ts --changedSince=HEAD",
"test:unit": "pnpm run test --selectProjects Unit"
},
"version": "0.1.0"
}
3 changes: 3 additions & 0 deletions packages/parser/json-schema-pointer/prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '@cuaklabs/prettier-config';

export default config;
3 changes: 3 additions & 0 deletions packages/parser/json-schema-pointer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { resolveJsonPointer } from './resolveJsonPointer';

export { resolveJsonPointer };
232 changes: 232 additions & 0 deletions packages/parser/json-schema-pointer/src/resolveJsonPointer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import { beforeAll, describe, expect, it } from '@jest/globals';

import { JsonValue } from '@cuaklabs/json-schema-types';

import { resolveJsonPointer } from './resolveJsonPointer';

describe(resolveJsonPointer.name, () => {
describe.each<[string, JsonValue, JsonValue | undefined]>([
[
'',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
],
[
'/foo',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
['bar', 'baz'],
],
[
'/foo/0',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
'bar',
],
[
'/',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
0,
],
[
'/a~1b',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
1,
],
[
'/c%d',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
2,
],
[
'/e^f',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
3,
],
[
'/g|h',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
4,
],
[
'/i\\j',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
5,
],
[
'/k"l',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
6,
],
[
'/ ',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
7,
],
[
'/m~0n',
{
'': 0,
' ': 7,
'a/b': 1,
'c%d': 2,
'e^f': 3,
foo: ['bar', 'baz'],
'g|h': 4,
'i\\j': 5,
'k"l': 6,
'm~n': 8,
},
8,
],
])(
'having a "%s" pointer',
(
pointer: string,
json: JsonValue,
expectedResult: JsonValue | undefined,
) => {
describe('when called', () => {
let result: unknown;

beforeAll(() => {
result = resolveJsonPointer(json, pointer);
});

it('should return the expected result', () => {
expect(result).toStrictEqual(expectedResult);
});
});
},
);
});
Loading