mad-data-parser 0.0.1 → 0.0.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mad-data-parser-0.0.2-beta.2.tgz +0 -0
- package/package.json +5 -33
- package/version.txt +1 -0
- package/.env.example +0 -0
- package/.swcrc +0 -27
- package/example/data/__tests__/output.ts +0 -57
- package/example/data/data.ts +0 -226
- package/example/data/output.ts +0 -74
- package/example/data/types.ts +0 -92
- package/example/example.ts +0 -26
- package/example/jsonPaths.data.ts +0 -13
- package/example/loadSchema.ts +0 -32
- package/jest.config.d.ts +0 -6
- package/jest.config.ts +0 -241
- package/nodemon.json +0 -27
- package/register.setup.jest.d.ts +0 -2
- package/register.setup.jest.ts +0 -19
- package/src/index.ts +0 -2
- package/src/parser/parseJsonPaths.ts +0 -136
- package/src/utils/graphql/index.ts +0 -51
- package/src/utils/jsonPath/guards.ts +0 -37
- package/src/utils/jsonPath/index.ts +0 -3
- package/src/utils/jsonPath/types.ts +0 -56
- package/src/utils/jsonPath/visitor.ts +0 -108
- package/src/utils/ts/helpers.ts +0 -13
- package/tsconfig.build.json +0 -19
- package/tsconfig.jest.json +0 -18
- package/tsconfig.json +0 -36
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.d.ts.map → index.d.ts.map} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/parser → parser}/parseJsonPaths.d.ts +0 -0
- /package/{dist/parser → parser}/parseJsonPaths.d.ts.map +0 -0
- /package/{dist/parser → parser}/parseJsonPaths.js +0 -0
- /package/{dist/parser → parser}/parseJsonPaths.js.map +0 -0
- /package/{dist/utils → utils}/graphql/index.d.ts +0 -0
- /package/{dist/utils → utils}/graphql/index.d.ts.map +0 -0
- /package/{dist/utils → utils}/graphql/index.js +0 -0
- /package/{dist/utils → utils}/graphql/index.js.map +0 -0
- /package/{dist/utils → utils}/jsonPath/guards.d.ts +0 -0
- /package/{dist/utils → utils}/jsonPath/guards.d.ts.map +0 -0
- /package/{dist/utils → utils}/jsonPath/guards.js +0 -0
- /package/{dist/utils → utils}/jsonPath/guards.js.map +0 -0
- /package/{dist/utils → utils}/jsonPath/index.d.ts +0 -0
- /package/{dist/utils → utils}/jsonPath/index.d.ts.map +0 -0
- /package/{dist/utils → utils}/jsonPath/index.js +0 -0
- /package/{dist/utils → utils}/jsonPath/index.js.map +0 -0
- /package/{dist/utils → utils}/jsonPath/types.d.ts +0 -0
- /package/{dist/utils → utils}/jsonPath/types.d.ts.map +0 -0
- /package/{dist/utils → utils}/jsonPath/types.js +0 -0
- /package/{dist/utils → utils}/jsonPath/types.js.map +0 -0
- /package/{dist/utils → utils}/jsonPath/visitor.d.ts +0 -0
- /package/{dist/utils → utils}/jsonPath/visitor.d.ts.map +0 -0
- /package/{dist/utils → utils}/jsonPath/visitor.js +0 -0
- /package/{dist/utils → utils}/jsonPath/visitor.js.map +0 -0
- /package/{dist/utils → utils}/ts/helpers.d.ts +0 -0
- /package/{dist/utils → utils}/ts/helpers.d.ts.map +0 -0
- /package/{dist/utils → utils}/ts/helpers.js +0 -0
- /package/{dist/utils → utils}/ts/helpers.js.map +0 -0
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { ASTNode, ExpressionType, RootNode, IdentifierNode, NumericLiteralNode, FilterExpressionNode, ScriptExpressionNode, StringLiteralNode, WildcardNode, SliceNode } from "./types"
|
|
2
|
-
import { isJSONPath } from "./guards"
|
|
3
|
-
import { isAstNode } from "./guards"
|
|
4
|
-
import { snakeToPascalCase, type SnakeToPascalCase } from "~/utils/ts/helpers"
|
|
5
|
-
|
|
6
|
-
export const BREAK = Symbol('BREAK')
|
|
7
|
-
|
|
8
|
-
type Kind = {
|
|
9
|
-
root: RootNode
|
|
10
|
-
identifier: IdentifierNode
|
|
11
|
-
numeric_literal: NumericLiteralNode
|
|
12
|
-
filter_expression: FilterExpressionNode
|
|
13
|
-
script_expression: ScriptExpressionNode
|
|
14
|
-
string_literal: StringLiteralNode
|
|
15
|
-
wildcard: WildcardNode
|
|
16
|
-
slice: SliceNode
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/** visitor types */
|
|
21
|
-
export type VisitorFn = (node: ASTNode, parent: ASTNode|null, index: Array<number>, ancestors: ASTNode[]) => ASTNode|typeof BREAK|undefined|null|void
|
|
22
|
-
export type TypedVisitorFn<T extends ExpressionType = ExpressionType> = (node: Kind[T], parent: ASTNode|null, index: Array<number>, ancestors: ASTNode[]) => ASTNode|typeof BREAK|undefined|null|void
|
|
23
|
-
export interface IVisitor {
|
|
24
|
-
enter?:VisitorFn;
|
|
25
|
-
leave?:VisitorFn;
|
|
26
|
-
}
|
|
27
|
-
export type NodeVisitor = {
|
|
28
|
-
[T in ExpressionType as `${'leave' | ''}${SnakeToPascalCase<T>}`]?: TypedVisitorFn<T>;
|
|
29
|
-
} & IVisitor
|
|
30
|
-
|
|
31
|
-
function doVisit(nodes: ASTNode[]|Array<ASTNode[]>, visitor: IVisitor):void {
|
|
32
|
-
if (isJSONPath(nodes)){
|
|
33
|
-
nodes = [nodes]
|
|
34
|
-
}
|
|
35
|
-
for (const jsonPath of nodes) {
|
|
36
|
-
let parent: ASTNode|null = null
|
|
37
|
-
let ancestors: ASTNode[] = []
|
|
38
|
-
let path: Array<number> = []
|
|
39
|
-
for (let i = 0; i < jsonPath.length; i++) {
|
|
40
|
-
const _node = jsonPath[i]!
|
|
41
|
-
let node: ASTNode = _node
|
|
42
|
-
path.push(i)
|
|
43
|
-
const enterResult = visitor.enter?.(node, parent, path, ancestors)
|
|
44
|
-
if(enterResult === BREAK) {
|
|
45
|
-
break
|
|
46
|
-
}
|
|
47
|
-
if(isAstNode(enterResult)) {
|
|
48
|
-
node = enterResult
|
|
49
|
-
}
|
|
50
|
-
parent = node
|
|
51
|
-
ancestors.push(node)
|
|
52
|
-
jsonPath[i] = node
|
|
53
|
-
}
|
|
54
|
-
parent = ancestors.pop() ?? null
|
|
55
|
-
path.pop()
|
|
56
|
-
for (let i = jsonPath.length - 1; i >= 0; i--) {
|
|
57
|
-
const _node = jsonPath[i]!
|
|
58
|
-
let node: ASTNode = _node
|
|
59
|
-
parent = ancestors.pop() ?? null
|
|
60
|
-
path.pop()
|
|
61
|
-
const leaveResult = visitor.leave?.(node, parent, path, ancestors)
|
|
62
|
-
if(leaveResult === BREAK) {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
if(isAstNode(leaveResult)) {
|
|
66
|
-
node = leaveResult
|
|
67
|
-
}
|
|
68
|
-
jsonPath[i] = node
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
function makeVisitor(visitor: NodeVisitor): IVisitor {
|
|
75
|
-
const visitorCall = function (type:'enter'|'leave', ...[node, ...rest]: Parameters<TypedVisitorFn>): ReturnType<TypedVisitorFn> {
|
|
76
|
-
let result: ReturnType<TypedVisitorFn>
|
|
77
|
-
//call leave node method
|
|
78
|
-
if (type === 'leave') {
|
|
79
|
-
const methodName = `${type}${snakeToPascalCase(node.expression.type) as SnakeToPascalCase<ExpressionType>}` as keyof NodeVisitor
|
|
80
|
-
result = visitor[methodName]?.(node as any,...rest)
|
|
81
|
-
if(result === BREAK) {
|
|
82
|
-
return result
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
//call original visitor
|
|
86
|
-
if (type in visitor) {
|
|
87
|
-
result = (visitor as IVisitor)[type as keyof IVisitor]?.(node, ...rest)
|
|
88
|
-
if(result === BREAK) {
|
|
89
|
-
return result
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
//call enter enter node method
|
|
93
|
-
if (type === 'enter') {
|
|
94
|
-
const methodName = `${snakeToPascalCase(node.expression.type) as SnakeToPascalCase<ExpressionType>}` as keyof NodeVisitor
|
|
95
|
-
result = visitor[methodName]?.(node as any,...rest)
|
|
96
|
-
}
|
|
97
|
-
return result
|
|
98
|
-
}
|
|
99
|
-
const result: IVisitor = {
|
|
100
|
-
enter: visitorCall.bind(null, 'enter') as VisitorFn,
|
|
101
|
-
leave: visitorCall.bind(null, 'leave') as VisitorFn,
|
|
102
|
-
}
|
|
103
|
-
return result
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function visit(nodes: ASTNode[]|Array<ASTNode[]>, visitor: NodeVisitor):void{
|
|
107
|
-
doVisit(nodes, makeVisitor(visitor))
|
|
108
|
-
}
|
package/src/utils/ts/helpers.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type SnakeToCamelCase<S extends string> = S extends `${infer T}_${infer U}` ?
|
|
2
|
-
`${T}${Capitalize<SnakeToCamelCase<U>>}` : S
|
|
3
|
-
export type SnakeToPascalCase<S extends string> = Capitalize<SnakeToCamelCase<S>>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function snakeToCamelCase(str: string): SnakeToCamelCase<string>
|
|
7
|
-
{
|
|
8
|
-
return str.split('_').map(s => s.charAt(0).toUpperCase() + s.slice(1)).join('') as SnakeToCamelCase<string>
|
|
9
|
-
}
|
|
10
|
-
export function snakeToPascalCase(str: string): SnakeToPascalCase<string>
|
|
11
|
-
{
|
|
12
|
-
return snakeToCamelCase(str).charAt(0).toUpperCase() + snakeToCamelCase(str).slice(1) as SnakeToPascalCase<string>
|
|
13
|
-
}
|
package/tsconfig.build.json
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "./src/",
|
|
5
|
-
"rootDir": "./src/",
|
|
6
|
-
"outDir": "./dist/",
|
|
7
|
-
"paths": {
|
|
8
|
-
"~/*": [
|
|
9
|
-
"./*"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"tsc-alias": {
|
|
14
|
-
"resolveFullPaths": true
|
|
15
|
-
},
|
|
16
|
-
"include": [
|
|
17
|
-
"./src/**/*.ts",
|
|
18
|
-
]
|
|
19
|
-
}
|
package/tsconfig.jest.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"noImplicitAny": false,
|
|
6
|
-
"isolatedModules": false,
|
|
7
|
-
"module": "ES2020",
|
|
8
|
-
"moduleResolution": "Bundler",
|
|
9
|
-
"verbatimModuleSyntax": true,
|
|
10
|
-
"paths": {
|
|
11
|
-
"~/*": ["./src/*"]
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"dist/"
|
|
17
|
-
]
|
|
18
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"extends": "@tsconfig/node20/tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"allowImportingTsExtensions": false,
|
|
6
|
-
"esModuleInterop": true,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"target": "es2022",
|
|
9
|
-
"module" : "ES2020",
|
|
10
|
-
"baseUrl": "./",
|
|
11
|
-
"allowJs": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"moduleDetection": "force",
|
|
14
|
-
"moduleResolution": "Bundler",
|
|
15
|
-
"verbatimModuleSyntax": true,
|
|
16
|
-
"strict": true,
|
|
17
|
-
"noUncheckedIndexedAccess": true,
|
|
18
|
-
"noImplicitOverride": true,
|
|
19
|
-
"lib": ["ES2022"],
|
|
20
|
-
"outDir": "./dist",
|
|
21
|
-
"rootDir": ".",
|
|
22
|
-
"declaration": true,
|
|
23
|
-
"declarationMap": true,
|
|
24
|
-
"sourceMap": true,
|
|
25
|
-
"types": ["node"],
|
|
26
|
-
"paths": {
|
|
27
|
-
"~/*": [
|
|
28
|
-
"./src/*"
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"include": [
|
|
33
|
-
"./src/**/*.ts",
|
|
34
|
-
"./examples/**/*.ts"
|
|
35
|
-
]
|
|
36
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|