mad-data-parser 0.0.1 → 0.0.2-beta.12
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/.vscode/launch.json +40 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mad-data-parser-0.0.2-beta.12.tgz +0 -0
- package/dist/package.json +28 -0
- package/dist/parser/parseJsonPaths.d.ts +11 -3
- package/dist/parser/parseJsonPaths.d.ts.map +1 -1
- package/dist/parser/parseJsonPaths.js +127 -68
- package/dist/parser/parseJsonPaths.js.map +1 -1
- package/dist/utils/graphql/index.d.ts +2 -2
- package/dist/utils/graphql/index.d.ts.map +1 -1
- package/dist/utils/graphql/index.js +2 -1
- package/dist/utils/graphql/index.js.map +1 -1
- package/dist/utils/graphql-tag/collocated/gql.d.ts +47 -0
- package/dist/utils/graphql-tag/collocated/gql.d.ts.map +1 -0
- package/dist/utils/graphql-tag/collocated/gql.js +133 -0
- package/dist/utils/graphql-tag/collocated/gql.js.map +1 -0
- package/dist/utils/graphql-tag/collocated/guards.d.ts +4 -0
- package/dist/utils/graphql-tag/collocated/guards.d.ts.map +1 -0
- package/dist/utils/graphql-tag/collocated/guards.js +13 -0
- package/dist/utils/graphql-tag/collocated/guards.js.map +1 -0
- package/dist/utils/graphql-tag/collocated/stringifyDocument.d.ts +2 -0
- package/dist/utils/graphql-tag/collocated/stringifyDocument.d.ts.map +1 -0
- package/dist/utils/graphql-tag/collocated/stringifyDocument.js +38 -0
- package/dist/utils/graphql-tag/collocated/stringifyDocument.js.map +1 -0
- package/dist/utils/graphql-tag/collocated/types.d.ts +19 -0
- package/dist/utils/graphql-tag/collocated/types.d.ts.map +1 -0
- package/dist/utils/graphql-tag/collocated/types.js +2 -0
- package/dist/utils/graphql-tag/collocated/types.js.map +1 -0
- package/dist/utils/graphql-tag/index.d.ts +5 -0
- package/dist/utils/graphql-tag/index.d.ts.map +1 -0
- package/dist/utils/graphql-tag/index.js +5 -0
- package/dist/utils/graphql-tag/index.js.map +1 -0
- package/dist/utils/jsonPath/guards.d.ts +1 -1
- package/dist/utils/jsonPath/index.d.ts +3 -3
- package/dist/utils/jsonPath/index.js +3 -3
- package/dist/utils/jsonPath/visitor.d.ts +2 -2
- package/dist/utils/jsonPath/visitor.js +3 -3
- package/dist/version.txt +1 -0
- package/nodemon.json +1 -1
- package/package.json +24 -11
- package/var/cache/schema.graphql +35655 -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/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/.swcrc
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/swcrc",
|
|
3
|
-
"jsc": {
|
|
4
|
-
"parser": {
|
|
5
|
-
"syntax": "typescript",
|
|
6
|
-
"tsx": false,
|
|
7
|
-
"decorators": false
|
|
8
|
-
},
|
|
9
|
-
"transform": {
|
|
10
|
-
"hidden": {
|
|
11
|
-
"jest": true
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"target": "es2022",
|
|
15
|
-
"keepClassNames": true,
|
|
16
|
-
"baseUrl": "./",
|
|
17
|
-
"paths": {
|
|
18
|
-
"~/*": [
|
|
19
|
-
"src/*"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"module": {
|
|
24
|
-
"type": "es6",
|
|
25
|
-
"noInterop": false
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { afterAll, beforeAll, describe, expect, it, test, xit } from '@jest/globals'
|
|
2
|
-
import { createFormatter, type DataOutput } from '../output'
|
|
3
|
-
|
|
4
|
-
describe('Data: Output', () => {
|
|
5
|
-
describe('Format Currency', () => {
|
|
6
|
-
const baseDataOutput:DataOutput = {
|
|
7
|
-
__typename: 'DataOutput',
|
|
8
|
-
type: 'currency',
|
|
9
|
-
currencyFormat: '$ #.###,00 USD',
|
|
10
|
-
}
|
|
11
|
-
const inputData = [1,2,3,4,5]
|
|
12
|
-
it('should format currency array with index and indexMax', () => {
|
|
13
|
-
const formatFn = createFormatter({
|
|
14
|
-
...baseDataOutput,
|
|
15
|
-
array: true,
|
|
16
|
-
index: 1,
|
|
17
|
-
indexMax: 3,
|
|
18
|
-
lineBreak: true,
|
|
19
|
-
spaces: true,
|
|
20
|
-
separator: '|',
|
|
21
|
-
})
|
|
22
|
-
const result = [
|
|
23
|
-
'$ 1,00 USD',
|
|
24
|
-
'$ 2,00 USD',
|
|
25
|
-
'$ 3,00 USD',
|
|
26
|
-
].join("| \n");
|
|
27
|
-
const formated = formatFn(inputData)
|
|
28
|
-
expect(formated).toBe(result)
|
|
29
|
-
})
|
|
30
|
-
it('should format currency single data with index and lineBreak', () => {
|
|
31
|
-
const formatFn = createFormatter({
|
|
32
|
-
...baseDataOutput,
|
|
33
|
-
array: false,
|
|
34
|
-
index: 2
|
|
35
|
-
})
|
|
36
|
-
const formated = formatFn(inputData)
|
|
37
|
-
expect(formated).toBe('$ 2,00 USD')
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
describe('Format Unit', () => {
|
|
41
|
-
const baseDataOutput:DataOutput = {
|
|
42
|
-
__typename: 'DataOutput',
|
|
43
|
-
type: 'unit',
|
|
44
|
-
unitSuffix: 'm³',
|
|
45
|
-
}
|
|
46
|
-
const inputData = 2
|
|
47
|
-
it('should format unit single data with index and lineBreak', () => {
|
|
48
|
-
const formatFn = createFormatter({
|
|
49
|
-
...baseDataOutput,
|
|
50
|
-
array: false,
|
|
51
|
-
index: 2
|
|
52
|
-
})
|
|
53
|
-
const formated = formatFn(2)
|
|
54
|
-
expect(formated).toBe('2.00 m³')
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
})
|
package/example/data/data.ts
DELETED
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import type { DataTable } from "example/data/types";
|
|
2
|
-
|
|
3
|
-
export const data:DataTable = {
|
|
4
|
-
columns:[
|
|
5
|
-
{ label: 'Finish', key: 'finish', sort: null, columnSize: 'auto',},
|
|
6
|
-
{ label: 'SKU', key: 'sku', sort: null, columnSize: 'auto' },
|
|
7
|
-
{ label: 'In Stock', key: 'inStock', sort: null },
|
|
8
|
-
{ label: 'Next', key: 'nextShipment', sort: null, type: 'link', columnSize: 'auto' },
|
|
9
|
-
{ label: 'MSRP', key: 'msrp', align: 'right', sort: null, columnSize: '92' },
|
|
10
|
-
{ label: 'Price', key: 'price', align: 'right', sort: null, columnSize: '92' },
|
|
11
|
-
{ label: 'Shipping', key: 'shipping', align: 'right', columnSize: '92' },
|
|
12
|
-
{ label: 'Date', key: 'date', align: 'right', sort: null, type: 'date', columnSize: '92' },
|
|
13
|
-
{ label: 'Custom', key: 'img', align: 'right', sort: null, type: 'image', columnSize: '92' },
|
|
14
|
-
{ label: '', key: 'cta', align: 'right', type: 'cta' },
|
|
15
|
-
],
|
|
16
|
-
values: [
|
|
17
|
-
{
|
|
18
|
-
subheading: { value: 'AB8 Stainless Steel / Outdoor', swatch: 'stainless-steel' },
|
|
19
|
-
rows: [
|
|
20
|
-
{
|
|
21
|
-
id: '1',
|
|
22
|
-
finish: { value: 'Painted: Natural', swatch: 'natural', status: 'New' },
|
|
23
|
-
sku: 'ESF.O.MHA.50.NA',
|
|
24
|
-
inStock: { value: '22', stock: 'INS' },
|
|
25
|
-
nextShipment: 'Ask about',
|
|
26
|
-
// msrp: '$1,195',
|
|
27
|
-
// price: '$1,498',
|
|
28
|
-
// shipping: '$249',
|
|
29
|
-
msrp: 1195,
|
|
30
|
-
price: 1498,
|
|
31
|
-
shipping: 249,
|
|
32
|
-
date: new Date('2025-10-30'),
|
|
33
|
-
img: { imgSource: '/images/studio/manhattan-50-natural.png' , value: 'Manhattan 50 Natural' },
|
|
34
|
-
cta: 'Shop',
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: '2',
|
|
38
|
-
finish: { value: 'Painted: Graphite', swatch: 'graphite', bold: true },
|
|
39
|
-
sku: 'ESF.O.MHA.50.GH',
|
|
40
|
-
inStock: { value: '0', stock: 'INT' },
|
|
41
|
-
nextShipment: '1 / 2 weeks',
|
|
42
|
-
// msrp: '$99,995',
|
|
43
|
-
// price: '$1,498',
|
|
44
|
-
// shipping: '$249',
|
|
45
|
-
msrp: 99_995,
|
|
46
|
-
price: 1_498,
|
|
47
|
-
shipping: 249,
|
|
48
|
-
cta: 'Shop'
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: '3',
|
|
52
|
-
finish: { value: 'Painted: Bone', swatch: 'bone' },
|
|
53
|
-
sku: 'ESF.O.MHA.50.BO',
|
|
54
|
-
inStock: { value: '0', stock: 'ARS' },
|
|
55
|
-
nextShipment: '2 / 1 days',
|
|
56
|
-
// msrp: '$2,995',
|
|
57
|
-
// price: '$1,498',
|
|
58
|
-
// shipping: '$249',
|
|
59
|
-
msrp: 2995,
|
|
60
|
-
price: 1498,
|
|
61
|
-
shipping: 249,
|
|
62
|
-
cta: 'Shop'
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: '4',
|
|
66
|
-
finish: { value: 'Raw: Ash', swatch: 'ash' },
|
|
67
|
-
sku: 'ESF.O.MHA.50.AS',
|
|
68
|
-
inStock: { value: '0', stock: 'MTO' },
|
|
69
|
-
nextShipment: '4 / 5 days',
|
|
70
|
-
// msrp: '$2,995',
|
|
71
|
-
// price: '$1,498',
|
|
72
|
-
// shipping: '$249',
|
|
73
|
-
msrp: 3995,
|
|
74
|
-
price: 1498,
|
|
75
|
-
shipping: 249,
|
|
76
|
-
cta: 'Shop'
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
id: '5',
|
|
80
|
-
finish: { value: 'Raw: Carbon', swatch: 'carbon' },
|
|
81
|
-
sku: 'ESF.O.MHA.50.CA',
|
|
82
|
-
inStock: { value: '2', type: 'stock', stock: 'INS' },
|
|
83
|
-
nextShipment: '3 / 5 weeks',
|
|
84
|
-
// msrp: '$2,995',
|
|
85
|
-
// price: '$1,498',
|
|
86
|
-
// shipping: '$249',
|
|
87
|
-
msrp: 3995,
|
|
88
|
-
price: 1498,
|
|
89
|
-
shipping: 249,
|
|
90
|
-
cta: 'Pre-Order'
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
id: '6',
|
|
94
|
-
finish: { value: 'Raw: Linen', swatch: 'linen' },
|
|
95
|
-
sku: 'ESF.O.MHA.50.LI',
|
|
96
|
-
inStock: { value: '43', type: 'stock', stock: 'INS' },
|
|
97
|
-
nextShipment: 'Ask about',
|
|
98
|
-
// msrp: '$2,995',
|
|
99
|
-
// price: '$1,498',
|
|
100
|
-
// shipping: '$249',
|
|
101
|
-
msrp: 4995,
|
|
102
|
-
price: 1498,
|
|
103
|
-
shipping: 249,
|
|
104
|
-
cta: { value: 'Enquiry', type: 'cta_secondary' }
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
id: '7',
|
|
108
|
-
finish: { value: 'Teak', swatch: 'teak' },
|
|
109
|
-
sku: 'ESF.O.MHA.50.TN',
|
|
110
|
-
inStock: { value: '0', stock: 'ARS' },
|
|
111
|
-
nextShipment: 'Ask about',
|
|
112
|
-
// msrp: '$2,995',
|
|
113
|
-
// price: '$1,498',
|
|
114
|
-
// shipping: '$249',
|
|
115
|
-
msrp: 4995,
|
|
116
|
-
price: 1498,
|
|
117
|
-
shipping: 249,
|
|
118
|
-
cta: 'Shop'
|
|
119
|
-
},
|
|
120
|
-
]
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
subheading: { value: 'AB8 Black / Outdoor', swatch: 'black' },
|
|
124
|
-
rows: [
|
|
125
|
-
{
|
|
126
|
-
id: '1',
|
|
127
|
-
finish: { value: 'Painted: Natural', swatch: 'natural' },
|
|
128
|
-
sku: 'ESF.O.MHA.50.NA.B',
|
|
129
|
-
inStock: { value: '0', stock: 'ARS' },
|
|
130
|
-
nextShipment: 'Ask about',
|
|
131
|
-
// msrp: '$2,995',
|
|
132
|
-
// price: '$1,498',
|
|
133
|
-
// shipping: '$249',
|
|
134
|
-
msrp: 2995,
|
|
135
|
-
price: 1498,
|
|
136
|
-
shipping: 249,
|
|
137
|
-
cta: 'Shop'
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
id: '2',
|
|
141
|
-
finish: { value: 'Painted: Graphite', swatch: 'graphite' },
|
|
142
|
-
sku: 'ESF.O.MHA.50.GH.B',
|
|
143
|
-
inStock: { value: '56', type: 'stock', stock: 'INS' },
|
|
144
|
-
nextShipment: 'Ask about',
|
|
145
|
-
// msrp: '$2,995',
|
|
146
|
-
// price: '$1,498',
|
|
147
|
-
// shipping: '$249',
|
|
148
|
-
msrp: 2995,
|
|
149
|
-
price: 1498,
|
|
150
|
-
shipping: 249,
|
|
151
|
-
cta: 'Shop'
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
id: '3',
|
|
155
|
-
finish: { value: 'Painted: Bone', swatch: 'bone' },
|
|
156
|
-
sku: 'ESF.O.MHA.50.BO.B',
|
|
157
|
-
inStock: { value: '1', type: 'stock', stock: 'INS' },
|
|
158
|
-
nextShipment: '2 / 5 days',
|
|
159
|
-
// msrp: '$2,995',
|
|
160
|
-
// price: '$1,498',
|
|
161
|
-
// shipping: '$249',
|
|
162
|
-
msrp: 2995,
|
|
163
|
-
price: 1498,
|
|
164
|
-
shipping: 249,
|
|
165
|
-
cta: 'Shop'
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
id: '4',
|
|
169
|
-
finish: { value: 'Raw: Ash', swatch: 'ash' },
|
|
170
|
-
sku: 'ESF.O.MHA.50.AS.B',
|
|
171
|
-
inStock: { value: '0', stock: 'ARS' },
|
|
172
|
-
nextShipment: '4 / 5 days',
|
|
173
|
-
// msrp: '$2,995',
|
|
174
|
-
// price: '$1,498',
|
|
175
|
-
// shipping: '$249',
|
|
176
|
-
msrp: 2995,
|
|
177
|
-
price: 1498,
|
|
178
|
-
shipping: 249,
|
|
179
|
-
cta: 'Shop'
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
id: '5',
|
|
183
|
-
finish: { value: 'Raw: Carbon', swatch: 'carbon' },
|
|
184
|
-
sku: 'ESF.O.MHA.50.CA.B',
|
|
185
|
-
inStock: { value: '0', stock: 'INT' },
|
|
186
|
-
nextShipment: '3 / 5 weeks',
|
|
187
|
-
// msrp: '$2,995',
|
|
188
|
-
// price: '$1,498',
|
|
189
|
-
// shipping: '$249',
|
|
190
|
-
msrp: 2995,
|
|
191
|
-
price: 1498,
|
|
192
|
-
shipping: 249,
|
|
193
|
-
cta: 'Pre-Order'
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
id: '6',
|
|
197
|
-
finish: { value: 'Raw: Linen', swatch: 'linen' },
|
|
198
|
-
sku: 'ESF.O.MHA.50.LI.B',
|
|
199
|
-
inStock: { value: '0', stock: 'INT' },
|
|
200
|
-
nextShipment: '3 / 5 weeks',
|
|
201
|
-
// msrp: '$2,995',
|
|
202
|
-
// price: '$1,498',
|
|
203
|
-
// shipping: '$249',
|
|
204
|
-
msrp: 2995,
|
|
205
|
-
price: 1498,
|
|
206
|
-
shipping: 249,
|
|
207
|
-
cta: { value: 'Enquiry', type: 'cta_secondary' }
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
id: '7',
|
|
211
|
-
finish: { value: 'Teak', swatch: 'teak' },
|
|
212
|
-
sku: 'ESF.O.MHA.50.TN.B',
|
|
213
|
-
inStock: { value: '0', stock: 'MTO' },
|
|
214
|
-
nextShipment: 'Ask about',
|
|
215
|
-
// msrp: '$2,995',
|
|
216
|
-
// price: '$1,498',
|
|
217
|
-
// shipping: '$249',
|
|
218
|
-
msrp: 2995,
|
|
219
|
-
price: 1498,
|
|
220
|
-
shipping: 249,
|
|
221
|
-
cta: 'Shop'
|
|
222
|
-
},
|
|
223
|
-
]
|
|
224
|
-
}
|
|
225
|
-
]
|
|
226
|
-
}
|
package/example/data/output.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import format from 'number-format.js'
|
|
2
|
-
export type DataType = 'string' | 'unit' | 'currency' | 'date' | 'number'
|
|
3
|
-
export type StringFormat = 'text' | 'markdown' | 'html'
|
|
4
|
-
|
|
5
|
-
export interface DataOutput{
|
|
6
|
-
__typename?: 'DataOutput'
|
|
7
|
-
id?: string
|
|
8
|
-
type: DataType
|
|
9
|
-
stringFormat?: StringFormat
|
|
10
|
-
currencyFormat?: string
|
|
11
|
-
unitSuffix?: string
|
|
12
|
-
array?: boolean
|
|
13
|
-
index?: number
|
|
14
|
-
indexMax?: number
|
|
15
|
-
lineBreak?: boolean
|
|
16
|
-
spaces?: boolean
|
|
17
|
-
separator?: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
type DataValue = string | number | Date
|
|
22
|
-
type DataValueInput = DataValue | DataValue[]
|
|
23
|
-
type FormatFunction = (value?: DataValue) => string|undefined
|
|
24
|
-
|
|
25
|
-
export function createFormatter<T extends DataValueInput>(data: DataOutput): (value: T) => string| undefined | void
|
|
26
|
-
{
|
|
27
|
-
let fnFormat: FormatFunction = () => void(0)
|
|
28
|
-
switch (data.type) {
|
|
29
|
-
case 'currency':
|
|
30
|
-
fnFormat = formatCurrency.bind(null, data)
|
|
31
|
-
break;
|
|
32
|
-
case 'unit':
|
|
33
|
-
fnFormat = formatUnit.bind(null, data)
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
const lineBreak = data.lineBreak ?? false
|
|
37
|
-
const spaces = data.spaces ?? false
|
|
38
|
-
const separator = `${data.separator ?? ','}${spaces ? ' ' : ''}${lineBreak ? '\n' : ''}`
|
|
39
|
-
|
|
40
|
-
return function(value: T): string| undefined | void {
|
|
41
|
-
if(typeof value === 'undefined') return undefined
|
|
42
|
-
const index = Math.max(data.index ?? 1, 1) - 1
|
|
43
|
-
if(data.array) {
|
|
44
|
-
const _value = data.array ? [value].flat() : value as DataValue[]
|
|
45
|
-
const defaultMax = Math.min(_value.length, 5)
|
|
46
|
-
const indexMax = Math.min(1 + (data.indexMax ?? defaultMax), _value.length) - 1
|
|
47
|
-
// console.log(index, indexMax)
|
|
48
|
-
const result = _value.slice(index, indexMax).map(fnFormat).join(separator)
|
|
49
|
-
// return lineBreak ? `${result}\n` : result;
|
|
50
|
-
return result;
|
|
51
|
-
}
|
|
52
|
-
const _value: DataValue|undefined = Array.isArray(value) ? value[index] : value as DataValue
|
|
53
|
-
return fnFormat(_value)
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function formatCurrency<T extends DataValue>(data: DataOutput, value?: T): string|undefined {
|
|
58
|
-
if(data.type !== 'currency') return undefined
|
|
59
|
-
if (value === undefined) return undefined
|
|
60
|
-
if(value instanceof Date) return undefined
|
|
61
|
-
const _value = typeof value === 'string' ? Number(value) : value as number
|
|
62
|
-
return format(data.currencyFormat ?? '#.###,00', _value)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function formatUnit<T extends DataValue>(data: DataOutput, value?: T): string|undefined {
|
|
66
|
-
if(data.type !== 'unit') return undefined
|
|
67
|
-
if (value === undefined) return undefined
|
|
68
|
-
if(value instanceof Date) return undefined
|
|
69
|
-
const _value = typeof value === 'string' ? Number(value) : value as number
|
|
70
|
-
const strValue = format('###.00', _value)
|
|
71
|
-
return `${strValue} ${data.unitSuffix ?? ''}`
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
package/example/data/types.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type TableCellTypeT = 'text' | 'link' | 'currency' | 'number' | 'cta' | 'cta_secondary' | 'stock' | 'swatch' | 'icon' | 'image' | 'date'
|
|
6
|
-
export type TableColumnSizeT = 'auto' | '80' | '92' | '100' | '120'
|
|
7
|
-
export type TableColumnAlignT = 'left' | 'right' | 'center'
|
|
8
|
-
export type TableColumnSortT = 'asc' | 'desc' | null
|
|
9
|
-
export type UiStatusCode = 'INS' | 'LOW' | 'INT' | 'ARS' | 'MTO' | 'PRE'
|
|
10
|
-
export type UiStampStatusT = 'Preview' | 'Limited' | 'New' | 'Updated' | 'Discontinued' | 'Unavailable' | 'Run-Out' | 'Seconds'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type OutputFormatTypeT = 'string' | 'unit' | 'currency' | 'date' | 'number' | 'media' //| 'date-distance'
|
|
15
|
-
export type StringFormatTypeT = 'text' | 'html' | 'markdown'
|
|
16
|
-
export type MediaFormatTypeT = 'images' | 'videos' | 'documents'
|
|
17
|
-
|
|
18
|
-
export type CurrencyFormatTypeT = 'currency_01' | 'currency_02' | 'currency_03' | 'currency_04' | 'currency_05' | 'currency_06' | 'currency_07'
|
|
19
|
-
export type DateFormatTypeT = 'iso_8601' | 'date_02' | 'date_03' | 'date_04' | 'date_05' | 'store_config'
|
|
20
|
-
export type MediaAspectT = 'screen' | 'landscape_plus' | 'landscape' | 'square' | 'portrait_plus' | 'portrait' | 'banner' | 'original' | 'auto'
|
|
21
|
-
export type SizeT = 'small' | 'medium' | 'large'
|
|
22
|
-
|
|
23
|
-
interface DataSettingOutput {
|
|
24
|
-
__typename: 'DataSettingOutput'
|
|
25
|
-
type: OutputFormatTypeT
|
|
26
|
-
fallback?: string
|
|
27
|
-
stringFormat?: StringFormatTypeT
|
|
28
|
-
mediaType?: MediaFormatTypeT
|
|
29
|
-
aspectRatio?: MediaAspectT
|
|
30
|
-
size?: SizeT
|
|
31
|
-
unitSuffix?: string
|
|
32
|
-
decimals?: number
|
|
33
|
-
imperial?: boolean
|
|
34
|
-
conversionFormula?: number
|
|
35
|
-
unitSuffixImperial?: string
|
|
36
|
-
decimalsImperial?: number
|
|
37
|
-
currencyFormat?: CurrencyFormatTypeT
|
|
38
|
-
dateFormat?: DateFormatTypeT
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export type DataValue = string | number | Date | null | undefined
|
|
42
|
-
|
|
43
|
-
export interface CellConfig {
|
|
44
|
-
value: DataValue
|
|
45
|
-
type?: TableCellTypeT
|
|
46
|
-
swatch?: string
|
|
47
|
-
icon?: string // Presence implies type: 'icon'
|
|
48
|
-
stock?: UiStatusCode // Presence implies type: 'stock'
|
|
49
|
-
status?: UiStampStatusT
|
|
50
|
-
subheading?: boolean
|
|
51
|
-
bold?: boolean
|
|
52
|
-
imgSource?: string // Presence implies type: 'image'
|
|
53
|
-
wrap?: boolean
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type CellValue = DataValue | CellConfig
|
|
57
|
-
|
|
58
|
-
export interface TableColumn {
|
|
59
|
-
label: string
|
|
60
|
-
key: string
|
|
61
|
-
align?: TableColumnAlignT
|
|
62
|
-
sort?: TableColumnSortT
|
|
63
|
-
type?: TableCellTypeT
|
|
64
|
-
bold?: boolean
|
|
65
|
-
wrap?: boolean
|
|
66
|
-
columnSize?: TableColumnSizeT
|
|
67
|
-
imgSource?: string
|
|
68
|
-
outputFormat?: DataSettingOutput
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export interface TableRow extends Record<string, CellValue> {
|
|
77
|
-
id: string
|
|
78
|
-
}
|
|
79
|
-
export interface TableValues {
|
|
80
|
-
subheading?: string | CellConfig
|
|
81
|
-
rows: TableRow[]
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export function isCellConfig(cell?: CellValue): cell is CellConfig {
|
|
86
|
-
return typeof cell === 'object' && !!cell && 'value' in cell
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export interface DataTable {
|
|
90
|
-
columns: TableColumn[]
|
|
91
|
-
values: TableValues[]
|
|
92
|
-
}
|
package/example/example.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
type GraphQLObjectType,
|
|
5
|
-
print,
|
|
6
|
-
} from 'graphql'
|
|
7
|
-
import jp from 'jsonpath'
|
|
8
|
-
import { loadRemoteSchema } from './loadSchema'
|
|
9
|
-
import * as JSONPath from '../src/utils/jsonPath'
|
|
10
|
-
|
|
11
|
-
import { parseJsonPaths } from '../src/parser/parseJsonPaths'
|
|
12
|
-
import { jsonPathsData } from './jsonPaths.data'
|
|
13
|
-
async function main() {
|
|
14
|
-
const jsonPaths: Array<JSONPath.ASTNode[]> = jsonPathsData.map(jp.parse.bind(jp))
|
|
15
|
-
const schema = await loadRemoteSchema({
|
|
16
|
-
authToken: process.env.GRAPHQL_AUTH_TOKEN ,
|
|
17
|
-
endpoint: process.env.GRAPHQL_ENDPOINT ?? '',
|
|
18
|
-
})
|
|
19
|
-
const rootType = schema.getType('PageProduct') as GraphQLObjectType
|
|
20
|
-
const doc = parseJsonPaths(jsonPaths, rootType)
|
|
21
|
-
|
|
22
|
-
console.log(print(doc))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
void main()
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export const jsonPathsData = [
|
|
2
|
-
'$.bundles[0].products[?(@.__typename == "PageProduct")].configPageInfo[-1:].internalName',
|
|
3
|
-
'$.bundles[0].products[?(@.__typename == "PageProduct")].configPageInfo[*].mediaStudio',
|
|
4
|
-
'$.bundles[0].products[?(@.__typename == "PageProduct")].configPageInfo[*].mediaStudio.metaproperties.nodes[?(@.name=="Asset_Type_1")].options[*].displayLabel',
|
|
5
|
-
'$.modelSpecs[0].efficiency',
|
|
6
|
-
'$.bundles[0].products[?(@.__typename == "PageProduct")].configPageInfo[0].mediaStudio.metaproperties.nodes[?(@.name=="Asset_Type_1")].options[*].displayLabel',
|
|
7
|
-
'$.bundles[0].products[?(@.__typename == "PageProduct")].configPageInfo[1].mediaStudio.metaproperties.nodes[?(@.name=="Asset_Type_1")].options[*].displayLabel',
|
|
8
|
-
'$.availableOn[*]',
|
|
9
|
-
'$.modelSpecs[*].efficiency[?(@.__typename == "ContentDisclaimer")].disclaimer.raw',
|
|
10
|
-
'$.modelSpecs[0].efficiency[?(@.__typename == "SpecEfficiency")].efficiency[0].burnerModel[?(@.__typename == "SpecEfficiencyEthanol")].burnTimeMax',
|
|
11
|
-
"$.configPageInfo[?(@.internalName == 'foo')].internalName",
|
|
12
|
-
'$.modelSpecs[0].efficiency[?(@.disclaimer === "foo")]'
|
|
13
|
-
]
|
package/example/loadSchema.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { loadSchema, type LoadSchemaOptions } from '@graphql-tools/load'
|
|
2
|
-
import { UrlLoader, type LoadFromUrlOptions } from '@graphql-tools/url-loader'
|
|
3
|
-
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'
|
|
4
|
-
import { printSchema } from 'graphql'
|
|
5
|
-
import fs from 'fs'
|
|
6
|
-
|
|
7
|
-
export async function loadRemoteSchema(options: {
|
|
8
|
-
authToken?: string,
|
|
9
|
-
endpoint: string,
|
|
10
|
-
}) {
|
|
11
|
-
const graphqlFile = process.cwd() + '/var/cache/schema.graphql'
|
|
12
|
-
if(fs.existsSync(graphqlFile)) {
|
|
13
|
-
const schema = await loadSchema(graphqlFile, { loaders: [new GraphQLFileLoader()] })
|
|
14
|
-
return schema
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const { authToken, endpoint } = options;
|
|
19
|
-
const urlLoader = new UrlLoader()
|
|
20
|
-
const initOpts: LoadFromUrlOptions & LoadSchemaOptions = {
|
|
21
|
-
assumeValidSDL: true,
|
|
22
|
-
assumeValid: true,
|
|
23
|
-
noLocation: true,
|
|
24
|
-
noSource: true,
|
|
25
|
-
loaders: [urlLoader],
|
|
26
|
-
// maxTokens: 1e3,
|
|
27
|
-
// handleAsSDL: false,
|
|
28
|
-
}
|
|
29
|
-
const schema = await loadSchema(endpoint, initOpts)
|
|
30
|
-
fs.writeFileSync(graphqlFile, printSchema(schema))
|
|
31
|
-
return schema
|
|
32
|
-
}
|
package/src/index.ts
DELETED