@graphql-mesh/json-selection 0.0.0-stage → 0.0.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/cjs/arrow-methods.js +58 -0
- package/cjs/index.js +13 -0
- package/cjs/package.json +1 -0
- package/cjs/selection.js +1096 -0
- package/cjs/types.js +5 -0
- package/esm/arrow-methods.js +53 -0
- package/esm/index.js +2 -0
- package/esm/selection.js +1084 -0
- package/esm/types.js +4 -0
- package/package.json +40 -3
- package/typings/arrow-methods.d.cts +18 -0
- package/typings/arrow-methods.d.ts +18 -0
- package/typings/index.d.cts +5 -0
- package/typings/index.d.ts +5 -0
- package/typings/selection.d.cts +46 -0
- package/typings/selection.d.ts +46 -0
- package/typings/types.d.cts +18 -0
- package/typings/types.d.ts +18 -0
- package/README.md +0 -3
package/esm/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/json-selection",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared JSONSelection parser and evaluator for Mesh Connectors mappings",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"tslib": "^2.4.0"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "ardatan/graphql-mesh",
|
|
12
|
+
"directory": "packages/json-selection"
|
|
13
|
+
},
|
|
14
|
+
"author": "Arda TANRIKULU <ardatanrikulu@gmail.com>",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22.18.0"
|
|
18
|
+
},
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
|
+
"typescript": {
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.cts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
42
|
+
}
|
|
6
43
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peel and apply trailing no-arg Connectors arrow methods (`->first` / `->last` / `->size`).
|
|
3
|
+
*
|
|
4
|
+
* Used by string interpolation for `$request.headers.x->first` without depending on the
|
|
5
|
+
* full JSONSelection evaluator (and without creating a connect <-> string-interpolation cycle).
|
|
6
|
+
*/
|
|
7
|
+
export declare const NO_ARG_ARROW_METHODS: Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Peel trailing Connectors-style `->first` / `->last` / `->size` (no args) from a key.
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitArrowMethods(rawKey: string): {
|
|
12
|
+
key: string;
|
|
13
|
+
arrowMethods: string[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Apply peeled `->first` / `->last` / `->size` methods to a looked-up value.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyArrowMethods(methods: readonly string[], value: any): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Peel and apply trailing no-arg Connectors arrow methods (`->first` / `->last` / `->size`).
|
|
3
|
+
*
|
|
4
|
+
* Used by string interpolation for `$request.headers.x->first` without depending on the
|
|
5
|
+
* full JSONSelection evaluator (and without creating a connect <-> string-interpolation cycle).
|
|
6
|
+
*/
|
|
7
|
+
export declare const NO_ARG_ARROW_METHODS: Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Peel trailing Connectors-style `->first` / `->last` / `->size` (no args) from a key.
|
|
10
|
+
*/
|
|
11
|
+
export declare function splitArrowMethods(rawKey: string): {
|
|
12
|
+
key: string;
|
|
13
|
+
arrowMethods: string[];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Apply peeled `->first` / `->last` / `->size` methods to a looked-up value.
|
|
17
|
+
*/
|
|
18
|
+
export declare function applyArrowMethods(methods: readonly string[], value: any): any;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { JSONSelectionExtras, JSONSelectionVars } from './types.cjs';
|
|
2
|
+
export { applySelection, evalPath, evalMatchMethod, evalConnectorsVarExpr, lookupVar, } from './selection.cjs';
|
|
3
|
+
export { NO_ARG_ARROW_METHODS, splitArrowMethods, applyArrowMethods } from './arrow-methods.cjs';
|
|
4
|
+
/** @deprecated Use {@link JSONSelectionExtras}. Kept for Connect transport re-exports. */
|
|
5
|
+
export type { JSONSelectionExtras as ConnectSelectionExtras } from './types.cjs';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { JSONSelectionExtras, JSONSelectionVars } from './types.js';
|
|
2
|
+
export { applySelection, evalPath, evalMatchMethod, evalConnectorsVarExpr, lookupVar, } from './selection.js';
|
|
3
|
+
export { NO_ARG_ARROW_METHODS, splitArrowMethods, applyArrowMethods } from './arrow-methods.js';
|
|
4
|
+
/** @deprecated Use {@link JSONSelectionExtras}. Kept for Connect transport re-exports. */
|
|
5
|
+
export type { JSONSelectionExtras as ConnectSelectionExtras } from './types.js';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure JSONSelection evaluator shared by Connect transport, stitch resolveTo,
|
|
3
|
+
* and string-interpolation arrow helpers.
|
|
4
|
+
*/
|
|
5
|
+
import type { JSONSelectionExtras, JSONSelectionVars } from './types.cjs';
|
|
6
|
+
export declare function evalConnectorsVarExpr(expr: string, vars: JSONSelectionVars): any;
|
|
7
|
+
export declare function lookupVar(path: string, vars: JSONSelectionVars): any;
|
|
8
|
+
/** `.foo`, `["a.b"]`, `['x']` path segments after `$args` / `$this`. */
|
|
9
|
+
export declare function tokenizeVarPath(rest: string): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Minimal selection evaluator:
|
|
12
|
+
* - `id name` field picks
|
|
13
|
+
* - `alias: path` aliases
|
|
14
|
+
* - nested `field { a b }`
|
|
15
|
+
* - `$` / `$root` for root
|
|
16
|
+
* - `$status`
|
|
17
|
+
* - `$response.headers.x` (Apollo multi-value array; use `->first`)
|
|
18
|
+
* - `$ <fields>` - merge root with mapped fields (Mesh `exposeResponseMetadata`)
|
|
19
|
+
*
|
|
20
|
+
* Mesh-only `_response` fields (url / statusText / full headers map) are filled after
|
|
21
|
+
* selection - Apollo has no `$request.url` / `$statusText` / whole-headers var.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applySelection(selection: string, root: any, extras: JSONSelectionExtras): any;
|
|
24
|
+
export declare function evalPath(path: string, root: any, extras: JSONSelectionExtras): any;
|
|
25
|
+
/** Index of the `)` that closes `s[openIdx]` (`(`), or -1. */
|
|
26
|
+
export declare function findBalancedParenClose(s: string, openIdx: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Split `left->method` / `left->method(args)` on the last `->` outside parentheses.
|
|
29
|
+
*/
|
|
30
|
+
export declare function splitConnectorsMethodCall(path: string): {
|
|
31
|
+
left: string;
|
|
32
|
+
method: string;
|
|
33
|
+
args: string;
|
|
34
|
+
} | null;
|
|
35
|
+
/**
|
|
36
|
+
* Federation Connectors `$->get("key")` / `$args->get("special-key")` / `arr->get(0)`.
|
|
37
|
+
* Preferred over `$["key"]` which Apollo Router's selection parser rejects with Eof.
|
|
38
|
+
*/
|
|
39
|
+
export declare function evalGetMethod(left: any, rawArgs: string): any;
|
|
40
|
+
/** Parse a Connectors method arg literal (`"x"`, `'x'`, `0`, `true`) or raw string. */
|
|
41
|
+
export declare function parseConnectorsLiteralArg(rawArgs: string): any;
|
|
42
|
+
/**
|
|
43
|
+
* Federation Connectors `$x->match([key, value], …, [@, default])`.
|
|
44
|
+
* Values may be nested exprs (e.g. `$.petType->match(...)`) for discriminator defaults.
|
|
45
|
+
*/
|
|
46
|
+
export declare function evalMatchMethod(left: any, rawArgs: string, root?: any, extras?: JSONSelectionExtras, vars?: JSONSelectionVars): any;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure JSONSelection evaluator shared by Connect transport, stitch resolveTo,
|
|
3
|
+
* and string-interpolation arrow helpers.
|
|
4
|
+
*/
|
|
5
|
+
import type { JSONSelectionExtras, JSONSelectionVars } from './types.js';
|
|
6
|
+
export declare function evalConnectorsVarExpr(expr: string, vars: JSONSelectionVars): any;
|
|
7
|
+
export declare function lookupVar(path: string, vars: JSONSelectionVars): any;
|
|
8
|
+
/** `.foo`, `["a.b"]`, `['x']` path segments after `$args` / `$this`. */
|
|
9
|
+
export declare function tokenizeVarPath(rest: string): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Minimal selection evaluator:
|
|
12
|
+
* - `id name` field picks
|
|
13
|
+
* - `alias: path` aliases
|
|
14
|
+
* - nested `field { a b }`
|
|
15
|
+
* - `$` / `$root` for root
|
|
16
|
+
* - `$status`
|
|
17
|
+
* - `$response.headers.x` (Apollo multi-value array; use `->first`)
|
|
18
|
+
* - `$ <fields>` - merge root with mapped fields (Mesh `exposeResponseMetadata`)
|
|
19
|
+
*
|
|
20
|
+
* Mesh-only `_response` fields (url / statusText / full headers map) are filled after
|
|
21
|
+
* selection - Apollo has no `$request.url` / `$statusText` / whole-headers var.
|
|
22
|
+
*/
|
|
23
|
+
export declare function applySelection(selection: string, root: any, extras: JSONSelectionExtras): any;
|
|
24
|
+
export declare function evalPath(path: string, root: any, extras: JSONSelectionExtras): any;
|
|
25
|
+
/** Index of the `)` that closes `s[openIdx]` (`(`), or -1. */
|
|
26
|
+
export declare function findBalancedParenClose(s: string, openIdx: number): number;
|
|
27
|
+
/**
|
|
28
|
+
* Split `left->method` / `left->method(args)` on the last `->` outside parentheses.
|
|
29
|
+
*/
|
|
30
|
+
export declare function splitConnectorsMethodCall(path: string): {
|
|
31
|
+
left: string;
|
|
32
|
+
method: string;
|
|
33
|
+
args: string;
|
|
34
|
+
} | null;
|
|
35
|
+
/**
|
|
36
|
+
* Federation Connectors `$->get("key")` / `$args->get("special-key")` / `arr->get(0)`.
|
|
37
|
+
* Preferred over `$["key"]` which Apollo Router's selection parser rejects with Eof.
|
|
38
|
+
*/
|
|
39
|
+
export declare function evalGetMethod(left: any, rawArgs: string): any;
|
|
40
|
+
/** Parse a Connectors method arg literal (`"x"`, `'x'`, `0`, `true`) or raw string. */
|
|
41
|
+
export declare function parseConnectorsLiteralArg(rawArgs: string): any;
|
|
42
|
+
/**
|
|
43
|
+
* Federation Connectors `$x->match([key, value], …, [@, default])`.
|
|
44
|
+
* Values may be nested exprs (e.g. `$.petType->match(...)`) for discriminator defaults.
|
|
45
|
+
*/
|
|
46
|
+
export declare function evalMatchMethod(left: any, rawArgs: string, root?: any, extras?: JSONSelectionExtras, vars?: JSONSelectionVars): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime values available to JSONSelection evaluation.
|
|
3
|
+
*/
|
|
4
|
+
export type JSONSelectionVars = {
|
|
5
|
+
args: Record<string, any>;
|
|
6
|
+
thisValue: any;
|
|
7
|
+
env: Record<string, string | undefined>;
|
|
8
|
+
context: any;
|
|
9
|
+
config?: Record<string, any>;
|
|
10
|
+
batch?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
/** Runtime values available to JSONSelection / errors mapping. */
|
|
13
|
+
export type JSONSelectionExtras = {
|
|
14
|
+
status?: number;
|
|
15
|
+
responseHeaders?: Headers;
|
|
16
|
+
/** Virtual connectors / path templates: resolve `$args` / `$this` in selections. */
|
|
17
|
+
vars?: JSONSelectionVars;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime values available to JSONSelection evaluation.
|
|
3
|
+
*/
|
|
4
|
+
export type JSONSelectionVars = {
|
|
5
|
+
args: Record<string, any>;
|
|
6
|
+
thisValue: any;
|
|
7
|
+
env: Record<string, string | undefined>;
|
|
8
|
+
context: any;
|
|
9
|
+
config?: Record<string, any>;
|
|
10
|
+
batch?: Record<string, any>;
|
|
11
|
+
};
|
|
12
|
+
/** Runtime values available to JSONSelection / errors mapping. */
|
|
13
|
+
export type JSONSelectionExtras = {
|
|
14
|
+
status?: number;
|
|
15
|
+
responseHeaders?: Headers;
|
|
16
|
+
/** Virtual connectors / path templates: resolve `$args` / `$this` in selections. */
|
|
17
|
+
vars?: JSONSelectionVars;
|
|
18
|
+
};
|
package/README.md
DELETED