@graphql-mesh/string-interpolation 0.1.1-alpha-112a2a51f.0 → 0.3.0
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/CHANGELOG.md +13 -2
- package/dist/index.js +16 -13
- package/dist/index.mjs +16 -13
- package/dist/package.json +3 -4
- package/dist/resolver-data-factory.d.ts +2 -2
- package/package.json +3 -4
- package/src/index.ts +3 -2
- package/src/interpolator.js +2 -2
- package/src/resolver-data-factory.ts +14 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
# @graphql-mesh/string-interpolation
|
|
2
2
|
|
|
3
|
-
## 0.
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 13b9b30f7: Add interpolation strings to the generated MeshContext type
|
|
8
|
+
|
|
9
|
+
## 0.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 974e703e2: No longer import entire lodash library but instead individual smaller packages
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
6
16
|
|
|
7
|
-
-
|
|
17
|
+
- 974e703e2: Cleanup dependencies
|
|
18
|
+
- 974e703e2: Use deeper lodash imports to have better treeshaking and avoid using eval
|
|
8
19
|
|
|
9
20
|
## 0.1.0
|
|
10
21
|
|
package/dist/index.js
CHANGED
|
@@ -4,10 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const lodashGet = _interopDefault(require('lodash.get'));
|
|
8
8
|
const JsonPointer = _interopDefault(require('json-pointer'));
|
|
9
9
|
const dayjs = _interopDefault(require('dayjs'));
|
|
10
|
-
const objectHash = _interopDefault(require('object-hash'));
|
|
11
10
|
|
|
12
11
|
const defaultOptions = {
|
|
13
12
|
delimiter: ['{', '}'],
|
|
@@ -142,7 +141,7 @@ class Interpolator {
|
|
|
142
141
|
}
|
|
143
142
|
applyData(key, data) {
|
|
144
143
|
const [prop, ptr] = key.split('#');
|
|
145
|
-
const propData =
|
|
144
|
+
const propData = lodashGet(data, prop);
|
|
146
145
|
if (ptr) {
|
|
147
146
|
try {
|
|
148
147
|
return JsonPointer.get(propData, ptr);
|
|
@@ -190,18 +189,21 @@ function getInterpolationKeys(...interpolationStrings) {
|
|
|
190
189
|
function parseInterpolationStrings(interpolationStrings, argTypeMap) {
|
|
191
190
|
const interpolationKeys = getInterpolationKeys(...interpolationStrings);
|
|
192
191
|
const args = {};
|
|
193
|
-
const contextVariables =
|
|
192
|
+
const contextVariables = {};
|
|
194
193
|
for (const interpolationKey of interpolationKeys) {
|
|
195
194
|
const interpolationKeyParts = interpolationKey.split('.');
|
|
196
195
|
const varName = interpolationKeyParts[interpolationKeyParts.length - 1];
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
const initialObject = interpolationKeyParts[0];
|
|
197
|
+
const argType = argTypeMap && varName in argTypeMap ? argTypeMap[varName] : interpolationKeyParts.length > 2 ? 'JSON' : 'ID';
|
|
198
|
+
switch (initialObject) {
|
|
199
|
+
case 'args':
|
|
200
|
+
args[varName] = {
|
|
201
|
+
type: argType,
|
|
202
|
+
};
|
|
203
|
+
break;
|
|
204
|
+
case 'context':
|
|
205
|
+
contextVariables[varName] = `Scalars['${argType}']`;
|
|
206
|
+
break;
|
|
205
207
|
}
|
|
206
208
|
}
|
|
207
209
|
return {
|
|
@@ -225,8 +227,9 @@ function getInterpolatedHeadersFactory(nonInterpolatedHeaders = {}) {
|
|
|
225
227
|
};
|
|
226
228
|
}
|
|
227
229
|
|
|
230
|
+
const hashCode = (s) => s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0);
|
|
228
231
|
function hashObject(value) {
|
|
229
|
-
return
|
|
232
|
+
return hashCode(JSON.stringify(value)).toString();
|
|
230
233
|
}
|
|
231
234
|
const stringInterpolator = new Interpolator({
|
|
232
235
|
delimiter: ['{', '}'],
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import lodashGet from 'lodash.get';
|
|
2
2
|
import JsonPointer from 'json-pointer';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
|
-
import objectHash from 'object-hash';
|
|
5
4
|
|
|
6
5
|
const defaultOptions = {
|
|
7
6
|
delimiter: ['{', '}'],
|
|
@@ -136,7 +135,7 @@ class Interpolator {
|
|
|
136
135
|
}
|
|
137
136
|
applyData(key, data) {
|
|
138
137
|
const [prop, ptr] = key.split('#');
|
|
139
|
-
const propData =
|
|
138
|
+
const propData = lodashGet(data, prop);
|
|
140
139
|
if (ptr) {
|
|
141
140
|
try {
|
|
142
141
|
return JsonPointer.get(propData, ptr);
|
|
@@ -184,18 +183,21 @@ function getInterpolationKeys(...interpolationStrings) {
|
|
|
184
183
|
function parseInterpolationStrings(interpolationStrings, argTypeMap) {
|
|
185
184
|
const interpolationKeys = getInterpolationKeys(...interpolationStrings);
|
|
186
185
|
const args = {};
|
|
187
|
-
const contextVariables =
|
|
186
|
+
const contextVariables = {};
|
|
188
187
|
for (const interpolationKey of interpolationKeys) {
|
|
189
188
|
const interpolationKeyParts = interpolationKey.split('.');
|
|
190
189
|
const varName = interpolationKeyParts[interpolationKeyParts.length - 1];
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
190
|
+
const initialObject = interpolationKeyParts[0];
|
|
191
|
+
const argType = argTypeMap && varName in argTypeMap ? argTypeMap[varName] : interpolationKeyParts.length > 2 ? 'JSON' : 'ID';
|
|
192
|
+
switch (initialObject) {
|
|
193
|
+
case 'args':
|
|
194
|
+
args[varName] = {
|
|
195
|
+
type: argType,
|
|
196
|
+
};
|
|
197
|
+
break;
|
|
198
|
+
case 'context':
|
|
199
|
+
contextVariables[varName] = `Scalars['${argType}']`;
|
|
200
|
+
break;
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
return {
|
|
@@ -219,8 +221,9 @@ function getInterpolatedHeadersFactory(nonInterpolatedHeaders = {}) {
|
|
|
219
221
|
};
|
|
220
222
|
}
|
|
221
223
|
|
|
224
|
+
const hashCode = (s) => s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0);
|
|
222
225
|
function hashObject(value) {
|
|
223
|
-
return
|
|
226
|
+
return hashCode(JSON.stringify(value)).toString();
|
|
224
227
|
}
|
|
225
228
|
const stringInterpolator = new Interpolator({
|
|
226
229
|
delimiter: ['{', '}'],
|
package/dist/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/string-interpolation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Dynamic string manipulation",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "*"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"dayjs": "1.11.
|
|
10
|
+
"dayjs": "1.11.3",
|
|
11
11
|
"json-pointer": "0.6.2",
|
|
12
|
-
"lodash": "
|
|
13
|
-
"object-hash": "3.0.0"
|
|
12
|
+
"lodash.get": "4.4.2"
|
|
14
13
|
},
|
|
15
14
|
"repository": {
|
|
16
15
|
"type": "git",
|
|
@@ -9,11 +9,11 @@ export declare type ResolverData<TParent = any, TArgs = any, TContext = any, TRe
|
|
|
9
9
|
};
|
|
10
10
|
export declare type ResolverDataBasedFactory<T> = (data: ResolverData) => T;
|
|
11
11
|
export declare function getInterpolationKeys(...interpolationStrings: string[]): any[];
|
|
12
|
-
export declare function parseInterpolationStrings(interpolationStrings: string
|
|
12
|
+
export declare function parseInterpolationStrings(interpolationStrings: Iterable<string>, argTypeMap?: Record<string, string | GraphQLInputType>): {
|
|
13
13
|
args: Record<string, {
|
|
14
14
|
type: string | GraphQLInputType;
|
|
15
15
|
}>;
|
|
16
|
-
contextVariables: string
|
|
16
|
+
contextVariables: Record<string, string>;
|
|
17
17
|
};
|
|
18
18
|
export declare function getInterpolatedStringFactory(nonInterpolatedString: string): ResolverDataBasedFactory<string>;
|
|
19
19
|
export declare function getInterpolatedHeadersFactory(nonInterpolatedHeaders?: Record<string, string>): ResolverDataBasedFactory<Record<string, string>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/string-interpolation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Dynamic string manipulation",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,9 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"json-pointer": "0.6.2",
|
|
27
|
-
"dayjs": "1.11.
|
|
28
|
-
"
|
|
29
|
-
"lodash": "^4.17.21"
|
|
27
|
+
"dayjs": "1.11.3",
|
|
28
|
+
"lodash.get": "4.4.2"
|
|
30
29
|
},
|
|
31
30
|
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
32
31
|
"repository": {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Interpolator } from './interpolator';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const hashCode = (s: string) => s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0);
|
|
4
5
|
|
|
5
6
|
export function hashObject(value: any): string {
|
|
6
|
-
return
|
|
7
|
+
return hashCode(JSON.stringify(value)).toString();
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export { Interpolator };
|
package/src/interpolator.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultOptions } from './statics/DefaultOptions';
|
|
2
|
-
import
|
|
2
|
+
import lodashGet from 'lodash.get';
|
|
3
3
|
import { defaultModifiers } from './modifiers';
|
|
4
4
|
import JsonPointer from 'json-pointer';
|
|
5
5
|
|
|
@@ -137,7 +137,7 @@ export class Interpolator {
|
|
|
137
137
|
|
|
138
138
|
applyData(key, data) {
|
|
139
139
|
const [prop, ptr] = key.split('#');
|
|
140
|
-
const propData =
|
|
140
|
+
const propData = lodashGet(data, prop);
|
|
141
141
|
if (ptr) {
|
|
142
142
|
try {
|
|
143
143
|
return JsonPointer.get(propData, ptr);
|
|
@@ -19,24 +19,29 @@ export function getInterpolationKeys(...interpolationStrings: string[]) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function parseInterpolationStrings(
|
|
22
|
-
interpolationStrings: string
|
|
22
|
+
interpolationStrings: Iterable<string>,
|
|
23
23
|
argTypeMap?: Record<string, string | GraphQLInputType>
|
|
24
24
|
) {
|
|
25
25
|
const interpolationKeys = getInterpolationKeys(...interpolationStrings);
|
|
26
26
|
|
|
27
27
|
const args: Record<string, { type: string | GraphQLInputType }> = {};
|
|
28
|
-
const contextVariables: string
|
|
28
|
+
const contextVariables: Record<string, string> = {};
|
|
29
29
|
|
|
30
30
|
for (const interpolationKey of interpolationKeys) {
|
|
31
31
|
const interpolationKeyParts = interpolationKey.split('.');
|
|
32
32
|
const varName = interpolationKeyParts[interpolationKeyParts.length - 1];
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
const initialObject = interpolationKeyParts[0];
|
|
34
|
+
const argType =
|
|
35
|
+
argTypeMap && varName in argTypeMap ? argTypeMap[varName] : interpolationKeyParts.length > 2 ? 'JSON' : 'ID';
|
|
36
|
+
switch (initialObject) {
|
|
37
|
+
case 'args':
|
|
38
|
+
args[varName] = {
|
|
39
|
+
type: argType,
|
|
40
|
+
};
|
|
41
|
+
break;
|
|
42
|
+
case 'context':
|
|
43
|
+
contextVariables[varName] = `Scalars['${argType}']`;
|
|
44
|
+
break;
|
|
40
45
|
}
|
|
41
46
|
}
|
|
42
47
|
|