Skip to content

Commit

Permalink
add json-transform-core (nodejs)
Browse files Browse the repository at this point in the history
  • Loading branch information
elisherer committed Apr 17, 2024
1 parent c20478e commit 0a5fdd0
Show file tree
Hide file tree
Showing 24 changed files with 11,722 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/docs-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
with:
node-version: 18
cache: npm
cache-dependency-path: './packages/docs/package-lock.json'

- name: Install dependencies
run: npm ci
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/node-test-json-transform-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run Tests

on:
pull_request:
branches:
- main
paths:
- packages/json-transform-core/**
# cancel previous tests if new commit is pushed to PR branch
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

defaults:
run:
working-directory: ./packages/json-transform-core

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
cache-dependency-path: './packages/json-transform-core/package-lock.json'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
2 changes: 1 addition & 1 deletion packages/docs/src/theme/prism-language-transformers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const variable =
/(?<![\])}?!@#$%^&*+\w])(#[a-z_]+[a-z_\d]*|\$(?!\$)((un)?secure|claims)?)(((\.(?![-\w$]+\()[-\w$]+)|(\[[^\]\n]+]))+|(?=[^\w.]|$))/g;
/(?<![\])}?!@#$%^&*+\w])(#[a-z_]+[a-z_\d]*|\$(?!\$))(((\.(?![-\w$]+\()[-\w$]+)|(\[[^\]\n]+]))+|(?=[^\w.]|$))/g;
const number = /-?\b\d+(?:\.\d+)?(?:e[+-]?\d+)?\b/i;
const function_context = {
pattern: /##([a-z]+[a-z_\d]*)(((\.(?![-\w$]+\()[-\w$]+)|(\[[^\]\n]+]))+|(?=[^\w.]|$))/,
Expand Down
3 changes: 3 additions & 0 deletions packages/json-transform-core/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*]
charset=utf-8
indent_size=2
21 changes: 21 additions & 0 deletions packages/json-transform-core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/dist

# misc
.DS_Store

npm-debug.log*
yarn-debug.log*
yarn-error.log*

.idea
6 changes: 6 additions & 0 deletions packages/json-transform-core/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "avoid",
"tabWidth": 2,
"printWidth": 120,
"useTabs": false
}
21 changes: 21 additions & 0 deletions packages/json-transform-core/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024-Present Eli Sherer, Suriel Bendahan, Yagel Bar, PapayaGlobal Inc. and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

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 OR COPYRIGHT HOLDERS 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.
74 changes: 74 additions & 0 deletions packages/json-transform-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# json-transform-core

![](https://img.shields.io/npm/v/@nlighten/json-transform-core.svg)

Core types and utilities for handling JSON transformers

# Installation

`npm install @nlighten/json-transform-core`

# API

```typescript
{
ContextVariablesSchemas: Record<string, TypeSchema>,
getFunctionInlineSignature: (name: string, func: FunctionDescriptor, requiredOnly?: boolean) => string,
getFunctionObjectSignature: (name: string, func: FunctionDescriptor) => string,
functions: { //Functions,
get(name: string) => FunctionDescriptor,
getNames() => string[],
resolveDocsUrl(funcName: string, functionDescriptor ? : FunctionDescriptor) => string,
matchInline(
data: any,
callback?: (
funcName: EmbeddedTransformerFunction,
func: FunctionDescriptor,
value: any,
args: Record<string, any>,
) => any): FunctionDescriptor | null,
matchObject(data: any, extractOutputTypeRecursively ? : boolean):ObjectFunctionMatchResult | undefined,
matchAllObjectFunctionsInLine(line: string) => IterableIterator,
matchAllInlineFunctionsInLine(line: string) => IterableIterator,
},
parseArgs: (func: FunctionDescriptor, args?: string) => {},
type Argument,
type FunctionDescriptor,
EmbeddedTransformerFunction, // enum
EmbeddedTransformerFunctions: EmbeddedTransformerFunction[],
jsonpathJoin: (...args: (string | null | undefined)[]): string,
JsonPathFunctionRegex: RegExp,
parseTransformer: (
definition: any,
targetPath: string,
previousPaths: string[],
paths: string[] = [],
typesMap? : Record<string, TypeSchema>,
additionalContext? : Record<string, TypeSchema>,
) => void,
ParseContext: {
resolve(name: string) => TypeSchema,
},
type ParseMethod,
type HandleFunctionMethod,
transformUtils: { //TransformUtils
setAdditionalContext: (additionalContext: Set<string>) => void,
getAdditionalContext: () => Set<string>,
setSpecialKeys: (specialKeys: Set<string>) => void,
getSpecialKeys: () => Set<string>,
setContextVariablesSchemas: (contextVariablesSchemas: Record<string, TypeSchema>) => void,
getContextVariablesSchemas: () => Record<string, TypeSchema>,
setScopedContextVariablesSchema: (scopedContextVariablesSchema: Record<string, TypeSchema | null>) => void,
getScopedContextVariablesSchema: () => Record<string, TypeSchema | null>,
matchesAnyOfContextVariables: (variableName: string) => boolean,
matchesAnyOfAdditionalContext: (variableName: string) => boolean,
matchesAnyOfSpecialKeys: (variableName: string) => boolean,
variableDetectionRegExpFactory: (flags = "g") => RegExp,
}
}
;

```

# License
[MIT](./LICENSE)
Loading

0 comments on commit 0a5fdd0

Please sign in to comment.