mad-data-parser 0.0.1 → 0.0.2-beta.11
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/index.d.ts +2 -0
- package/index.js +2 -0
- package/mad-data-parser-0.0.2-beta.11.tgz +0 -0
- package/package.json +14 -38
- package/parser/parseJsonPaths.d.ts +12 -0
- package/parser/parseJsonPaths.d.ts.map +1 -0
- package/parser/parseJsonPaths.js +161 -0
- package/parser/parseJsonPaths.js.map +1 -0
- package/{dist/utils → utils}/graphql/index.d.ts +2 -2
- package/utils/graphql/index.d.ts.map +1 -0
- package/{dist/utils → utils}/graphql/index.js +2 -1
- package/utils/graphql/index.js.map +1 -0
- package/utils/graphql-tag/collocated/gql.d.ts +47 -0
- package/utils/graphql-tag/collocated/gql.d.ts.map +1 -0
- package/utils/graphql-tag/collocated/gql.js +133 -0
- package/utils/graphql-tag/collocated/gql.js.map +1 -0
- package/utils/graphql-tag/collocated/guards.d.ts +4 -0
- package/utils/graphql-tag/collocated/guards.d.ts.map +1 -0
- package/utils/graphql-tag/collocated/guards.js +13 -0
- package/utils/graphql-tag/collocated/guards.js.map +1 -0
- package/utils/graphql-tag/collocated/stringifyDocument.d.ts +2 -0
- package/utils/graphql-tag/collocated/stringifyDocument.d.ts.map +1 -0
- package/utils/graphql-tag/collocated/stringifyDocument.js +38 -0
- package/utils/graphql-tag/collocated/stringifyDocument.js.map +1 -0
- package/utils/graphql-tag/collocated/types.d.ts +19 -0
- package/utils/graphql-tag/collocated/types.d.ts.map +1 -0
- package/utils/graphql-tag/collocated/types.js.map +1 -0
- package/utils/graphql-tag/index.d.ts +5 -0
- package/utils/graphql-tag/index.d.ts.map +1 -0
- package/utils/graphql-tag/index.js +5 -0
- package/utils/graphql-tag/index.js.map +1 -0
- package/{dist/utils → utils}/jsonPath/guards.d.ts +1 -1
- package/utils/jsonPath/index.d.ts +4 -0
- package/utils/jsonPath/index.js +4 -0
- package/utils/jsonPath/types.js +2 -0
- package/{dist/utils → utils}/jsonPath/visitor.d.ts +2 -2
- package/{dist/utils → utils}/jsonPath/visitor.js +3 -3
- package/version.txt +1 -0
- package/.env.example +0 -0
- package/.swcrc +0 -27
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/parser/parseJsonPaths.d.ts +0 -4
- package/dist/parser/parseJsonPaths.d.ts.map +0 -1
- package/dist/parser/parseJsonPaths.js +0 -116
- package/dist/parser/parseJsonPaths.js.map +0 -1
- package/dist/utils/graphql/index.d.ts.map +0 -1
- package/dist/utils/graphql/index.js.map +0 -1
- package/dist/utils/jsonPath/index.d.ts +0 -4
- package/dist/utils/jsonPath/index.js +0 -4
- 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.map → index.d.ts.map} +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/utils/jsonPath → utils/graphql-tag/collocated}/types.js +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.map +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.map +0 -0
- /package/{dist/utils → utils}/jsonPath/visitor.d.ts.map +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,37 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import type { BaseNode, IdentifierNode, ASTNode, NumericLiteralNode, FilterExpressionNode, ScriptExpressionNode, StringLiteralNode, WildcardNode, SliceNode, RootNode } from "./types"
|
|
3
|
-
|
|
4
|
-
export function isAstNode(node: unknown): node is ASTNode {
|
|
5
|
-
return typeof node === 'object' && node !== null && 'expression' in node && typeof node.expression === 'object' && node.expression !== null && 'type' in node.expression && typeof node.expression.type === 'string'
|
|
6
|
-
}
|
|
7
|
-
export function isBaseNode(node: ASTNode): node is BaseNode {
|
|
8
|
-
return isAstNode(node) && 'operation' in node && typeof node.operation === 'string' && 'scope' in node && typeof node.scope === 'string'
|
|
9
|
-
}
|
|
10
|
-
export function isIdentifierNode(node: ASTNode): node is IdentifierNode {
|
|
11
|
-
return isBaseNode(node) && node.operation === 'member' && node.expression.type === 'identifier'
|
|
12
|
-
}
|
|
13
|
-
export function isNumericLiteralNode(node: ASTNode): node is NumericLiteralNode {
|
|
14
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'numeric_literal'
|
|
15
|
-
}
|
|
16
|
-
export function isFilterExpressionNode(node: ASTNode): node is FilterExpressionNode {
|
|
17
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'filter_expression'
|
|
18
|
-
}
|
|
19
|
-
export function isScriptExpressionNode(node: ASTNode): node is ScriptExpressionNode {
|
|
20
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'script_expression'
|
|
21
|
-
}
|
|
22
|
-
export function isStringLiteralNode(node: ASTNode): node is StringLiteralNode {
|
|
23
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'string_literal'
|
|
24
|
-
}
|
|
25
|
-
export function isWildcardNode(node: ASTNode): node is WildcardNode {
|
|
26
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'wildcard'
|
|
27
|
-
}
|
|
28
|
-
export function isSliceNode(node: ASTNode): node is SliceNode {
|
|
29
|
-
return isBaseNode(node) && node.operation === 'subscript' && node.expression.type === 'slice'
|
|
30
|
-
}
|
|
31
|
-
export function isRootNode(node: ASTNode): node is RootNode {
|
|
32
|
-
return isAstNode(node) && node.expression.type === 'root' && node.expression.value === '$'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isJSONPath(nodes: unknown): nodes is ASTNode[] {
|
|
36
|
-
return Array.isArray(nodes) && nodes.every(node => isAstNode(node))
|
|
37
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export interface ASTNode {
|
|
2
|
-
expression: Expression
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export type ExpressionType = 'root' | 'identifier' | 'numeric_literal' | 'filter_expression' | 'script_expression' | 'string_literal' | 'wildcard' | 'slice'
|
|
6
|
-
export type ExpressionValue = string | number | undefined
|
|
7
|
-
|
|
8
|
-
interface BuildExpression<T extends ExpressionType = ExpressionType, V extends ExpressionValue = ExpressionValue> {
|
|
9
|
-
type: T
|
|
10
|
-
value: V
|
|
11
|
-
}
|
|
12
|
-
/** expression types */
|
|
13
|
-
export type Expression = BuildExpression<ExpressionType, ExpressionValue>
|
|
14
|
-
export type RootExpression = BuildExpression<'root', '$'>
|
|
15
|
-
export type IdentifierExpression = BuildExpression<'identifier', string>
|
|
16
|
-
export type NumericLiteralExpression = BuildExpression<'numeric_literal', number>
|
|
17
|
-
export type FilterExpressionExpression = BuildExpression<'filter_expression', `?(${string})`>
|
|
18
|
-
export type ScriptExpressionExpression = BuildExpression<'script_expression', string>
|
|
19
|
-
export type StringLiteralExpression = BuildExpression<'string_literal', string>
|
|
20
|
-
export type WildcardExpression = BuildExpression<'wildcard', '*'>
|
|
21
|
-
export type SliceExpression = BuildExpression<'slice', `${number|''}:${number|''}`>
|
|
22
|
-
|
|
23
|
-
/** node types */
|
|
24
|
-
export interface RootNode extends ASTNode {
|
|
25
|
-
expression: RootExpression
|
|
26
|
-
}
|
|
27
|
-
export interface BaseNode<T extends 'member' | 'subscript' = 'member'|'subscript'> extends ASTNode {
|
|
28
|
-
operation: T
|
|
29
|
-
scope: 'child' | 'descendant' | 'parent'
|
|
30
|
-
}
|
|
31
|
-
export interface IdentifierNode extends BaseNode<'member'> {
|
|
32
|
-
expression: IdentifierExpression
|
|
33
|
-
}
|
|
34
|
-
export interface NumericLiteralNode extends BaseNode<'subscript'> {
|
|
35
|
-
expression: NumericLiteralExpression
|
|
36
|
-
}
|
|
37
|
-
export interface FilterExpressionNode extends BaseNode<'subscript'> {
|
|
38
|
-
expression: FilterExpressionExpression
|
|
39
|
-
}
|
|
40
|
-
export interface ScriptExpressionNode extends BaseNode<'subscript'> {
|
|
41
|
-
expression: ScriptExpressionExpression
|
|
42
|
-
}
|
|
43
|
-
export interface StringLiteralNode extends BaseNode<'subscript'> {
|
|
44
|
-
expression: StringLiteralExpression
|
|
45
|
-
}
|
|
46
|
-
export interface WildcardNode extends BaseNode<'subscript'> {
|
|
47
|
-
expression: WildcardExpression
|
|
48
|
-
}
|
|
49
|
-
export interface SliceNode extends BaseNode<'subscript'> {
|
|
50
|
-
expression: SliceExpression
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
@@ -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
|