tersejson 0.1.0 → 0.2.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/README.md +47 -4
- package/dist/{client-BQAZg7I8.d.mts → client-CFGvusCj.d.mts} +1 -1
- package/dist/{client-DOOGwp_p.d.ts → client-hUXNNGcN.d.ts} +1 -1
- package/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs.map +1 -1
- package/dist/{express-LSVylWpN.d.ts → express-Da7WcJtt.d.ts} +1 -1
- package/dist/{express-BoL__Ao6.d.mts → express-O5w2NBTf.d.mts} +1 -1
- package/dist/express.d.mts +2 -2
- package/dist/express.d.ts +2 -2
- package/dist/graphql-C3PTnqnZ.d.mts +81 -0
- package/dist/graphql-DmtweJgh.d.ts +81 -0
- package/dist/graphql-client-2H4FjmRc.d.mts +123 -0
- package/dist/graphql-client-BXGtWqe9.d.ts +123 -0
- package/dist/graphql-client.d.mts +2 -0
- package/dist/graphql-client.d.ts +2 -0
- package/dist/graphql-client.js +215 -0
- package/dist/graphql-client.js.map +1 -0
- package/dist/graphql-client.mjs +207 -0
- package/dist/graphql-client.mjs.map +1 -0
- package/dist/graphql.d.mts +3 -0
- package/dist/graphql.d.ts +3 -0
- package/dist/graphql.js +304 -0
- package/dist/graphql.js.map +1 -0
- package/dist/graphql.mjs +296 -0
- package/dist/graphql.mjs.map +1 -0
- package/dist/index.d.mts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +400 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +398 -4
- package/dist/index.mjs.map +1 -1
- package/dist/integrations.js.map +1 -1
- package/dist/integrations.mjs.map +1 -1
- package/dist/{types-CzaGQaV7.d.mts → types-BTonKlz8.d.mts} +56 -1
- package/dist/{types-CzaGQaV7.d.ts → types-BTonKlz8.d.ts} +56 -1
- package/package.json +44 -3
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { h as isGraphQLTersePayload } from './types-BTonKlz8.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TerseJSON GraphQL Client
|
|
5
|
+
*
|
|
6
|
+
* Apollo Client Link and utilities for expanding GraphQL responses.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options for GraphQL client processing
|
|
10
|
+
*/
|
|
11
|
+
interface GraphQLTerseClientOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Use Proxy for lazy expansion (more memory efficient)
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
useProxy?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Enable debug logging
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Processes a GraphQL terse response, expanding compressed arrays
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { processGraphQLResponse } from 'tersejson/graphql-client';
|
|
29
|
+
*
|
|
30
|
+
* const response = await fetch('/graphql', {
|
|
31
|
+
* method: 'POST',
|
|
32
|
+
* headers: {
|
|
33
|
+
* 'Content-Type': 'application/json',
|
|
34
|
+
* 'accept-terse': 'true',
|
|
35
|
+
* },
|
|
36
|
+
* body: JSON.stringify({ query: '{ users { firstName lastName } }' }),
|
|
37
|
+
* }).then(r => r.json());
|
|
38
|
+
*
|
|
39
|
+
* const expanded = processGraphQLResponse(response);
|
|
40
|
+
* console.log(expanded.data.users[0].firstName); // Works transparently
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function processGraphQLResponse<T = unknown>(response: unknown, options?: GraphQLTerseClientOptions): T;
|
|
44
|
+
/**
|
|
45
|
+
* Type for Apollo Link (avoiding direct dependency)
|
|
46
|
+
*/
|
|
47
|
+
interface ApolloLinkLike {
|
|
48
|
+
request(operation: {
|
|
49
|
+
getContext: () => Record<string, unknown>;
|
|
50
|
+
setContext: (ctx: Record<string, unknown>) => void;
|
|
51
|
+
}, forward: (operation: unknown) => {
|
|
52
|
+
map: (fn: (result: unknown) => unknown) => unknown;
|
|
53
|
+
}): unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates an Apollo Client Link for TerseJSON
|
|
57
|
+
*
|
|
58
|
+
* This link automatically adds the accept-terse header and processes
|
|
59
|
+
* terse responses transparently.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { ApolloClient, InMemoryCache, HttpLink, from } from '@apollo/client';
|
|
64
|
+
* import { createTerseLink } from 'tersejson/graphql-client';
|
|
65
|
+
*
|
|
66
|
+
* const terseLink = createTerseLink({ debug: true });
|
|
67
|
+
*
|
|
68
|
+
* const httpLink = new HttpLink({
|
|
69
|
+
* uri: '/graphql',
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const client = new ApolloClient({
|
|
73
|
+
* link: from([terseLink, httpLink]),
|
|
74
|
+
* cache: new InMemoryCache(),
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Usage is completely transparent
|
|
78
|
+
* const { data } = await client.query({
|
|
79
|
+
* query: gql`
|
|
80
|
+
* query GetUsers {
|
|
81
|
+
* users { firstName lastName email }
|
|
82
|
+
* }
|
|
83
|
+
* `,
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* console.log(data.users[0].firstName); // Just works!
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function createTerseLink(options?: GraphQLTerseClientOptions): ApolloLinkLike;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a fetch wrapper for GraphQL requests
|
|
92
|
+
*
|
|
93
|
+
* Useful for non-Apollo GraphQL clients or direct fetch usage.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { createGraphQLFetch } from 'tersejson/graphql-client';
|
|
98
|
+
*
|
|
99
|
+
* const gqlFetch = createGraphQLFetch({ debug: true });
|
|
100
|
+
*
|
|
101
|
+
* const result = await gqlFetch('/graphql', {
|
|
102
|
+
* query: `{ users { firstName lastName } }`,
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* console.log(result.data.users[0].firstName);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function createGraphQLFetch(options?: GraphQLTerseClientOptions): <T = unknown>(url: string, body: {
|
|
109
|
+
query: string;
|
|
110
|
+
variables?: Record<string, unknown>;
|
|
111
|
+
operationName?: string;
|
|
112
|
+
}, init?: RequestInit) => Promise<T>;
|
|
113
|
+
|
|
114
|
+
type graphqlClient_GraphQLTerseClientOptions = GraphQLTerseClientOptions;
|
|
115
|
+
declare const graphqlClient_createGraphQLFetch: typeof createGraphQLFetch;
|
|
116
|
+
declare const graphqlClient_createTerseLink: typeof createTerseLink;
|
|
117
|
+
declare const graphqlClient_isGraphQLTersePayload: typeof isGraphQLTersePayload;
|
|
118
|
+
declare const graphqlClient_processGraphQLResponse: typeof processGraphQLResponse;
|
|
119
|
+
declare namespace graphqlClient {
|
|
120
|
+
export { type graphqlClient_GraphQLTerseClientOptions as GraphQLTerseClientOptions, graphqlClient_createGraphQLFetch as createGraphQLFetch, graphqlClient_createTerseLink as createTerseLink, processGraphQLResponse as default, graphqlClient_isGraphQLTersePayload as isGraphQLTersePayload, graphqlClient_processGraphQLResponse as processGraphQLResponse };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { type GraphQLTerseClientOptions as G, createGraphQLFetch as a, createTerseLink as c, graphqlClient as g, processGraphQLResponse as p };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { h as isGraphQLTersePayload } from './types-BTonKlz8.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TerseJSON GraphQL Client
|
|
5
|
+
*
|
|
6
|
+
* Apollo Client Link and utilities for expanding GraphQL responses.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options for GraphQL client processing
|
|
10
|
+
*/
|
|
11
|
+
interface GraphQLTerseClientOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Use Proxy for lazy expansion (more memory efficient)
|
|
14
|
+
* @default true
|
|
15
|
+
*/
|
|
16
|
+
useProxy?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Enable debug logging
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Processes a GraphQL terse response, expanding compressed arrays
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* import { processGraphQLResponse } from 'tersejson/graphql-client';
|
|
29
|
+
*
|
|
30
|
+
* const response = await fetch('/graphql', {
|
|
31
|
+
* method: 'POST',
|
|
32
|
+
* headers: {
|
|
33
|
+
* 'Content-Type': 'application/json',
|
|
34
|
+
* 'accept-terse': 'true',
|
|
35
|
+
* },
|
|
36
|
+
* body: JSON.stringify({ query: '{ users { firstName lastName } }' }),
|
|
37
|
+
* }).then(r => r.json());
|
|
38
|
+
*
|
|
39
|
+
* const expanded = processGraphQLResponse(response);
|
|
40
|
+
* console.log(expanded.data.users[0].firstName); // Works transparently
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function processGraphQLResponse<T = unknown>(response: unknown, options?: GraphQLTerseClientOptions): T;
|
|
44
|
+
/**
|
|
45
|
+
* Type for Apollo Link (avoiding direct dependency)
|
|
46
|
+
*/
|
|
47
|
+
interface ApolloLinkLike {
|
|
48
|
+
request(operation: {
|
|
49
|
+
getContext: () => Record<string, unknown>;
|
|
50
|
+
setContext: (ctx: Record<string, unknown>) => void;
|
|
51
|
+
}, forward: (operation: unknown) => {
|
|
52
|
+
map: (fn: (result: unknown) => unknown) => unknown;
|
|
53
|
+
}): unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates an Apollo Client Link for TerseJSON
|
|
57
|
+
*
|
|
58
|
+
* This link automatically adds the accept-terse header and processes
|
|
59
|
+
* terse responses transparently.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { ApolloClient, InMemoryCache, HttpLink, from } from '@apollo/client';
|
|
64
|
+
* import { createTerseLink } from 'tersejson/graphql-client';
|
|
65
|
+
*
|
|
66
|
+
* const terseLink = createTerseLink({ debug: true });
|
|
67
|
+
*
|
|
68
|
+
* const httpLink = new HttpLink({
|
|
69
|
+
* uri: '/graphql',
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* const client = new ApolloClient({
|
|
73
|
+
* link: from([terseLink, httpLink]),
|
|
74
|
+
* cache: new InMemoryCache(),
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* // Usage is completely transparent
|
|
78
|
+
* const { data } = await client.query({
|
|
79
|
+
* query: gql`
|
|
80
|
+
* query GetUsers {
|
|
81
|
+
* users { firstName lastName email }
|
|
82
|
+
* }
|
|
83
|
+
* `,
|
|
84
|
+
* });
|
|
85
|
+
*
|
|
86
|
+
* console.log(data.users[0].firstName); // Just works!
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare function createTerseLink(options?: GraphQLTerseClientOptions): ApolloLinkLike;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a fetch wrapper for GraphQL requests
|
|
92
|
+
*
|
|
93
|
+
* Useful for non-Apollo GraphQL clients or direct fetch usage.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { createGraphQLFetch } from 'tersejson/graphql-client';
|
|
98
|
+
*
|
|
99
|
+
* const gqlFetch = createGraphQLFetch({ debug: true });
|
|
100
|
+
*
|
|
101
|
+
* const result = await gqlFetch('/graphql', {
|
|
102
|
+
* query: `{ users { firstName lastName } }`,
|
|
103
|
+
* });
|
|
104
|
+
*
|
|
105
|
+
* console.log(result.data.users[0].firstName);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function createGraphQLFetch(options?: GraphQLTerseClientOptions): <T = unknown>(url: string, body: {
|
|
109
|
+
query: string;
|
|
110
|
+
variables?: Record<string, unknown>;
|
|
111
|
+
operationName?: string;
|
|
112
|
+
}, init?: RequestInit) => Promise<T>;
|
|
113
|
+
|
|
114
|
+
type graphqlClient_GraphQLTerseClientOptions = GraphQLTerseClientOptions;
|
|
115
|
+
declare const graphqlClient_createGraphQLFetch: typeof createGraphQLFetch;
|
|
116
|
+
declare const graphqlClient_createTerseLink: typeof createTerseLink;
|
|
117
|
+
declare const graphqlClient_isGraphQLTersePayload: typeof isGraphQLTersePayload;
|
|
118
|
+
declare const graphqlClient_processGraphQLResponse: typeof processGraphQLResponse;
|
|
119
|
+
declare namespace graphqlClient {
|
|
120
|
+
export { type graphqlClient_GraphQLTerseClientOptions as GraphQLTerseClientOptions, graphqlClient_createGraphQLFetch as createGraphQLFetch, graphqlClient_createTerseLink as createTerseLink, processGraphQLResponse as default, graphqlClient_isGraphQLTersePayload as isGraphQLTersePayload, graphqlClient_processGraphQLResponse as processGraphQLResponse };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { type GraphQLTerseClientOptions as G, createGraphQLFetch as a, createTerseLink as c, graphqlClient as g, processGraphQLResponse as p };
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
// src/types.ts
|
|
6
|
+
function isGraphQLTersePayload(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && "data" in value && "__terse__" in value && typeof value.__terse__ === "object" && value.__terse__ !== null && "v" in value.__terse__ && "k" in value.__terse__ && "paths" in value.__terse__;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// src/core.ts
|
|
11
|
+
function createTerseProxy(compressed, keyMap) {
|
|
12
|
+
const originalToShort = new Map(
|
|
13
|
+
Object.entries(keyMap).map(([short, original]) => [original, short])
|
|
14
|
+
);
|
|
15
|
+
const handler = {
|
|
16
|
+
get(target, prop) {
|
|
17
|
+
if (typeof prop === "symbol") {
|
|
18
|
+
return Reflect.get(target, prop);
|
|
19
|
+
}
|
|
20
|
+
const shortKey = originalToShort.get(prop);
|
|
21
|
+
const actualKey = shortKey ?? prop;
|
|
22
|
+
const value = target[actualKey];
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return value.map((item) => {
|
|
25
|
+
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
26
|
+
return createTerseProxy(item, keyMap);
|
|
27
|
+
}
|
|
28
|
+
return item;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (typeof value === "object" && value !== null) {
|
|
32
|
+
return createTerseProxy(value, keyMap);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
},
|
|
36
|
+
has(target, prop) {
|
|
37
|
+
if (typeof prop === "symbol") {
|
|
38
|
+
return Reflect.has(target, prop);
|
|
39
|
+
}
|
|
40
|
+
const shortKey = originalToShort.get(prop);
|
|
41
|
+
return (shortKey ?? prop) in target;
|
|
42
|
+
},
|
|
43
|
+
ownKeys(target) {
|
|
44
|
+
return Object.keys(target).map((shortKey) => keyMap[shortKey] ?? shortKey);
|
|
45
|
+
},
|
|
46
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
47
|
+
if (typeof prop === "symbol") {
|
|
48
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
49
|
+
}
|
|
50
|
+
const shortKey = originalToShort.get(prop);
|
|
51
|
+
const actualKey = shortKey ?? prop;
|
|
52
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, actualKey);
|
|
53
|
+
if (descriptor) {
|
|
54
|
+
return { ...descriptor, enumerable: true, configurable: true };
|
|
55
|
+
}
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
return new Proxy(compressed, handler);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/graphql-client.ts
|
|
63
|
+
var DEFAULT_OPTIONS = {
|
|
64
|
+
useProxy: true,
|
|
65
|
+
debug: false
|
|
66
|
+
};
|
|
67
|
+
function getAtPath(obj, path) {
|
|
68
|
+
const parts = path.split(/\.|\[(\d+)\]/).filter(Boolean);
|
|
69
|
+
let current = obj;
|
|
70
|
+
for (const part of parts) {
|
|
71
|
+
if (current === null || current === void 0) return void 0;
|
|
72
|
+
const isIndex = /^\d+$/.test(part);
|
|
73
|
+
if (isIndex) {
|
|
74
|
+
current = current[parseInt(part, 10)];
|
|
75
|
+
} else {
|
|
76
|
+
current = current[part];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return current;
|
|
80
|
+
}
|
|
81
|
+
function setAtPath(obj, path, value) {
|
|
82
|
+
const parts = path.split(/\.|\[(\d+)\]/).filter(Boolean);
|
|
83
|
+
let current = obj;
|
|
84
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
85
|
+
const part = parts[i];
|
|
86
|
+
const isIndex = /^\d+$/.test(part);
|
|
87
|
+
if (isIndex) {
|
|
88
|
+
current = current[parseInt(part, 10)];
|
|
89
|
+
} else {
|
|
90
|
+
current = current[part];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const lastPart = parts[parts.length - 1];
|
|
94
|
+
const isLastIndex = /^\d+$/.test(lastPart);
|
|
95
|
+
if (isLastIndex) {
|
|
96
|
+
current[parseInt(lastPart, 10)] = value;
|
|
97
|
+
} else {
|
|
98
|
+
current[lastPart] = value;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function expandObject(obj, keyMap, maxDepth = 10, currentDepth = 0) {
|
|
102
|
+
if (currentDepth >= maxDepth) return obj;
|
|
103
|
+
const shortToKey = new Map(
|
|
104
|
+
Object.entries(keyMap).map(([short, original]) => [short, original])
|
|
105
|
+
);
|
|
106
|
+
const expanded = {};
|
|
107
|
+
for (const [shortKey, value] of Object.entries(obj)) {
|
|
108
|
+
const originalKey = shortToKey.get(shortKey) ?? shortKey;
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
expanded[originalKey] = value.map((item) => {
|
|
111
|
+
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
112
|
+
return expandObject(item, keyMap, maxDepth, currentDepth + 1);
|
|
113
|
+
}
|
|
114
|
+
return item;
|
|
115
|
+
});
|
|
116
|
+
} else if (typeof value === "object" && value !== null) {
|
|
117
|
+
expanded[originalKey] = expandObject(
|
|
118
|
+
value,
|
|
119
|
+
keyMap,
|
|
120
|
+
maxDepth,
|
|
121
|
+
currentDepth + 1
|
|
122
|
+
);
|
|
123
|
+
} else {
|
|
124
|
+
expanded[originalKey] = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return expanded;
|
|
128
|
+
}
|
|
129
|
+
function wrapArrayWithProxies(array, keyMap) {
|
|
130
|
+
return array.map((item) => createTerseProxy(item, keyMap));
|
|
131
|
+
}
|
|
132
|
+
function expandArray(array, keyMap) {
|
|
133
|
+
return array.map((item) => expandObject(item, keyMap));
|
|
134
|
+
}
|
|
135
|
+
function processGraphQLResponse(response, options = {}) {
|
|
136
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
137
|
+
if (!isGraphQLTersePayload(response)) {
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
const terseResponse = response;
|
|
141
|
+
const { data, __terse__, ...rest } = terseResponse;
|
|
142
|
+
const { k: keyMap, paths } = __terse__;
|
|
143
|
+
if (config.debug) {
|
|
144
|
+
console.log("[tersejson/graphql-client] Processing terse response");
|
|
145
|
+
console.log("[tersejson/graphql-client] Paths:", paths);
|
|
146
|
+
console.log("[tersejson/graphql-client] Key map:", keyMap);
|
|
147
|
+
}
|
|
148
|
+
const clonedData = JSON.parse(JSON.stringify(data));
|
|
149
|
+
const result = { data: clonedData, ...rest };
|
|
150
|
+
for (const path of paths) {
|
|
151
|
+
const array = getAtPath(result, path);
|
|
152
|
+
if (!array || !Array.isArray(array)) {
|
|
153
|
+
if (config.debug) {
|
|
154
|
+
console.warn(`[tersejson/graphql-client] Path not found or not array: ${path}`);
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (config.useProxy) {
|
|
159
|
+
const proxied = wrapArrayWithProxies(array, keyMap);
|
|
160
|
+
setAtPath(result, path, proxied);
|
|
161
|
+
} else {
|
|
162
|
+
const expanded = expandArray(array, keyMap);
|
|
163
|
+
setAtPath(result, path, expanded);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
function createTerseLink(options = {}) {
|
|
169
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
170
|
+
return {
|
|
171
|
+
request(operation, forward) {
|
|
172
|
+
operation.setContext({
|
|
173
|
+
...operation.getContext(),
|
|
174
|
+
headers: {
|
|
175
|
+
...operation.getContext().headers || {},
|
|
176
|
+
"accept-terse": "true"
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
return forward(operation).map((result) => {
|
|
180
|
+
if (isGraphQLTersePayload(result)) {
|
|
181
|
+
if (config.debug) {
|
|
182
|
+
console.log("[tersejson/apollo] Processing terse response");
|
|
183
|
+
}
|
|
184
|
+
return processGraphQLResponse(result, config);
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function createGraphQLFetch(options = {}) {
|
|
192
|
+
const config = { ...DEFAULT_OPTIONS, ...options };
|
|
193
|
+
return async function graphqlFetch(url, body, init = {}) {
|
|
194
|
+
const headers = new Headers(init.headers);
|
|
195
|
+
headers.set("Content-Type", "application/json");
|
|
196
|
+
headers.set("accept-terse", "true");
|
|
197
|
+
const response = await fetch(url, {
|
|
198
|
+
...init,
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers,
|
|
201
|
+
body: JSON.stringify(body)
|
|
202
|
+
});
|
|
203
|
+
const data = await response.json();
|
|
204
|
+
return processGraphQLResponse(data, config);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
var graphql_client_default = processGraphQLResponse;
|
|
208
|
+
|
|
209
|
+
exports.createGraphQLFetch = createGraphQLFetch;
|
|
210
|
+
exports.createTerseLink = createTerseLink;
|
|
211
|
+
exports.default = graphql_client_default;
|
|
212
|
+
exports.isGraphQLTersePayload = isGraphQLTersePayload;
|
|
213
|
+
exports.processGraphQLResponse = processGraphQLResponse;
|
|
214
|
+
//# sourceMappingURL=graphql-client.js.map
|
|
215
|
+
//# sourceMappingURL=graphql-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts","../src/core.ts","../src/graphql-client.ts"],"names":[],"mappings":";;;;;AAsOO,SAAS,sBAAsB,KAAA,EAA+C;AACnF,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,MAAA,IAAU,KAAA,IACV,WAAA,IAAe,KAAA,IACf,OAAQ,KAAA,CAA+B,cAAc,QAAA,IACpD,KAAA,CAA+B,SAAA,KAAc,IAAA,IAC9C,GAAA,IAAQ,KAAA,CAA+B,aACvC,GAAA,IAAQ,KAAA,CAA+B,SAAA,IACvC,OAAA,IAAY,KAAA,CAA+B,SAAA;AAE/C;;;ACqKO,SAAS,gBAAA,CACd,YACA,MAAA,EACG;AAEH,EAAA,MAAM,kBAAkB,IAAI,GAAA;AAAA,IAC1B,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,KAAA,EAAO,QAAQ,CAAA,KAAM,CAAC,QAAA,EAAU,KAAK,CAAC;AAAA,GACrE;AAEA,EAAA,MAAM,OAAA,GAAiD;AAAA,IACrD,GAAA,CAAI,QAAQ,IAAA,EAAuB;AACjC,MAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC5B,QAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,MAAA,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Ae,YAAA,CACpB,GAAA,EACA,IAAA,EACA,IAAA,GAAoB,EAAC,EACT;AACZ,IAAA,MAAM,OAAA,GAAU,IAAI,OAAA,CAAQ,IAAA,CAAK,OAAO,CAAA;AACxC,IAAA,OAAA,CAAQ,GAAA,CAAI,gBAAgB,kBAAkB,CAAA;AAC9C,IAAA,OAAA,CAAQ,GAAA,CAAI,gBAAgB,MAAM,CAAA;AAElC,IAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,MAChC,GAAG,IAAA;AAAA,MACH,MAAA,EAAQ,MAAA;AAAA,MACR,OAAA;AAAA,MACA,IAAA,EAAM,IAAA,CAAK,SAAA,CAAU,IAAI;AAAA,KAC1B,CAAA;AAED,IAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK;AAEjC,IAAA,OAAO,sBAAA,CAA0B,MAAM,MAAM,CAAA;AAAA,EAC/C,CAAA;AACF;AAMA,IAAO,sBAAA,GAAQ","file":"graphql-client.js","sourcesContent":["/**\n * TerseJSON Types\n *\n * Defines the wire format and configuration options for transparent\n * JSON key compression.\n */\n\n/**\n * The compressed format sent over the wire\n */\nexport interface TersePayload<T = unknown> {\n /** Marker to identify this as a TerseJSON payload */\n __terse__: true;\n /** Version for future compatibility */\n v: 1;\n /** Key mapping: short key -> original key */\n k: Record<string, string>;\n /** The compressed data with short keys */\n d: T;\n /** Pattern used for key generation (for debugging/info) */\n p?: string;\n}\n\n/**\n * Built-in key pattern presets\n */\nexport type KeyPatternPreset =\n | 'alpha' // a, b, c, ... z, aa, ab (default)\n | 'numeric' // 0, 1, 2, ... 9, 10, 11\n | 'alphanumeric' // a1, a2, ... a9, b1, b2\n | 'short' // _, __, ___, a, b (shortest possible)\n | 'prefixed'; // k0, k1, k2 (with 'k' prefix)\n\n/**\n * Custom key generator function\n */\nexport type KeyGenerator = (index: number) => string;\n\n/**\n * Key pattern configuration\n */\nexport type KeyPattern =\n | KeyPatternPreset\n | { prefix: string; style?: 'numeric' | 'alpha' }\n | KeyGenerator;\n\n/**\n * How to handle nested structures\n */\nexport type NestedHandling =\n | 'deep' // Compress all nested objects/arrays (default)\n | 'shallow' // Only compress top-level array\n | 'arrays' // Only compress nested arrays, not single objects\n | number; // Specific depth limit (1 = shallow, Infinity = deep)\n\n/**\n * Compression options\n */\nexport interface CompressOptions {\n /**\n * Minimum key length to consider for compression\n * Keys shorter than this won't be shortened\n * @default 3\n */\n minKeyLength?: number;\n\n /**\n * Maximum depth to traverse for nested objects\n * @default 10\n */\n maxDepth?: number;\n\n /**\n * Key pattern to use for generating short keys\n * @default 'alpha'\n */\n keyPattern?: KeyPattern;\n\n /**\n * How to handle nested objects and arrays\n * @default 'deep'\n */\n nestedHandling?: NestedHandling;\n\n /**\n * Only compress keys that appear in all objects (homogeneous)\n * @default false\n */\n homogeneousOnly?: boolean;\n\n /**\n * Keys to always exclude from compression\n */\n excludeKeys?: string[];\n\n /**\n * Keys to always include in compression (even if short)\n */\n includeKeys?: string[];\n}\n\n/**\n * Configuration options for the Express middleware\n */\nexport interface TerseMiddlewareOptions extends CompressOptions {\n /**\n * Minimum array length to trigger compression\n * @default 2\n */\n minArrayLength?: number;\n\n /**\n * Custom function to determine if a response should be compressed\n * Return false to skip compression for specific responses\n */\n shouldCompress?: (data: unknown, req: unknown) => boolean;\n\n /**\n * Custom header name for signaling terse responses\n * @default 'x-terse-json'\n */\n headerName?: string;\n\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n}\n\n/**\n * Configuration options for the client\n */\nexport interface TerseClientOptions {\n /**\n * Custom header name to check for terse responses\n * @default 'x-terse-json'\n */\n headerName?: string;\n\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n\n /**\n * Automatically expand terse responses\n * @default true\n */\n autoExpand?: boolean;\n}\n\n/**\n * Type helper to preserve original types through compression\n */\nexport type Tersed<T> = T;\n\n/**\n * Check if a value is a TersePayload\n */\nexport function isTersePayload(value: unknown): value is TersePayload {\n return (\n typeof value === 'object' &&\n value !== null &&\n '__terse__' in value &&\n (value as TersePayload).__terse__ === true &&\n 'v' in value &&\n 'k' in value &&\n 'd' in value\n );\n}\n\n/**\n * GraphQL terse metadata (attached to response)\n */\nexport interface GraphQLTerseMetadata {\n /** Version for compatibility */\n v: 1;\n /** Key mapping: short key -> original key */\n k: Record<string, string>;\n /** JSON paths to compressed arrays (e.g., [\"data.users\", \"data.products\"]) */\n paths: string[];\n}\n\n/**\n * GraphQL response with terse compression\n */\nexport interface GraphQLTerseResponse<T = unknown> {\n /** The compressed data with short keys in arrays */\n data: T;\n /** GraphQL errors (untouched) */\n errors?: Array<{ message: string; [key: string]: unknown }>;\n /** GraphQL extensions (untouched) */\n extensions?: Record<string, unknown>;\n /** Terse metadata */\n __terse__: GraphQLTerseMetadata;\n}\n\n/**\n * GraphQL middleware options\n */\nexport interface GraphQLTerseOptions extends CompressOptions {\n /**\n * Minimum array length to trigger compression\n * @default 2\n */\n minArrayLength?: number;\n\n /**\n * Custom function to determine if a path should be compressed\n * Return false to skip compression for specific paths\n */\n shouldCompress?: (data: unknown, path: string) => boolean;\n\n /**\n * Paths to exclude from compression (e.g., [\"data.config\"])\n */\n excludePaths?: string[];\n\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n}\n\n/**\n * Check if a value is a GraphQL terse response\n */\nexport function isGraphQLTersePayload(value: unknown): value is GraphQLTerseResponse {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'data' in value &&\n '__terse__' in value &&\n typeof (value as GraphQLTerseResponse).__terse__ === 'object' &&\n (value as GraphQLTerseResponse).__terse__ !== null &&\n 'v' in (value as GraphQLTerseResponse).__terse__ &&\n 'k' in (value as GraphQLTerseResponse).__terse__ &&\n 'paths' in (value as GraphQLTerseResponse).__terse__\n );\n}\n","/**\n * TerseJSON Core\n *\n * The core compression and expansion algorithms.\n */\n\nimport {\n TersePayload,\n isTersePayload,\n KeyPattern,\n KeyGenerator,\n NestedHandling,\n CompressOptions,\n} from './types';\n\n// ============================================================================\n// KEY PATTERN GENERATORS\n// ============================================================================\n\n/**\n * Alpha pattern: a, b, c, ... z, aa, ab, ...\n */\nfunction alphaGenerator(index: number): string {\n let key = '';\n let remaining = index;\n\n do {\n key = String.fromCharCode(97 + (remaining % 26)) + key;\n remaining = Math.floor(remaining / 26) - 1;\n } while (remaining >= 0);\n\n return key;\n}\n\n/**\n * Numeric pattern: 0, 1, 2, ... 9, 10, 11, ...\n */\nfunction numericGenerator(index: number): string {\n return String(index);\n}\n\n/**\n * Alphanumeric pattern: a1, a2, ... a9, b1, b2, ...\n */\nfunction alphanumericGenerator(index: number): string {\n const letterIndex = Math.floor(index / 9);\n const numIndex = (index % 9) + 1;\n return alphaGenerator(letterIndex) + numIndex;\n}\n\n/**\n * Short pattern: uses shortest possible keys\n * _, a, b, ..., z, aa, ab, ...\n */\nfunction shortGenerator(index: number): string {\n if (index === 0) return '_';\n return alphaGenerator(index - 1);\n}\n\n/**\n * Prefixed pattern: k0, k1, k2, ...\n */\nfunction prefixedGenerator(prefix: string, style: 'numeric' | 'alpha' = 'numeric'): KeyGenerator {\n return (index: number) => {\n if (style === 'alpha') {\n return prefix + alphaGenerator(index);\n }\n return prefix + index;\n };\n}\n\n/**\n * Creates a key generator from a pattern configuration\n */\nexport function createKeyGenerator(pattern: KeyPattern): { generator: KeyGenerator; name: string } {\n // If it's already a function, use it directly\n if (typeof pattern === 'function') {\n return { generator: pattern, name: 'custom' };\n }\n\n // If it's a preset string\n if (typeof pattern === 'string') {\n switch (pattern) {\n case 'alpha':\n return { generator: alphaGenerator, name: 'alpha' };\n case 'numeric':\n return { generator: numericGenerator, name: 'numeric' };\n case 'alphanumeric':\n return { generator: alphanumericGenerator, name: 'alphanumeric' };\n case 'short':\n return { generator: shortGenerator, name: 'short' };\n case 'prefixed':\n return { generator: prefixedGenerator('k'), name: 'prefixed:k' };\n default:\n return { generator: alphaGenerator, name: 'alpha' };\n }\n }\n\n // If it's a prefix config object\n if (typeof pattern === 'object' && 'prefix' in pattern) {\n return {\n generator: prefixedGenerator(pattern.prefix, pattern.style || 'numeric'),\n name: `prefixed:${pattern.prefix}`,\n };\n }\n\n return { generator: alphaGenerator, name: 'alpha' };\n}\n\n/**\n * Resolves nested handling to a numeric depth\n */\nfunction resolveNestedDepth(handling: NestedHandling | undefined, maxDepth: number): number {\n if (handling === undefined || handling === 'deep') {\n return maxDepth;\n }\n if (handling === 'shallow') {\n return 1;\n }\n if (handling === 'arrays') {\n return maxDepth; // Special handling in collect/compress functions\n }\n if (typeof handling === 'number') {\n return handling;\n }\n return maxDepth;\n}\n\n// Legacy generateShortKey removed - use createKeyGenerator instead\n\ninterface CollectKeysOptions {\n minKeyLength: number;\n maxDepth: number;\n nestedHandling: NestedHandling;\n excludeKeys?: string[];\n includeKeys?: string[];\n homogeneousOnly?: boolean;\n}\n\n/**\n * Collects all unique keys from an array of objects\n */\nfunction collectKeys(\n data: Record<string, unknown>[],\n options: CollectKeysOptions,\n currentDepth: number = 0\n): Set<string> {\n const keys = new Set<string>();\n const { minKeyLength, maxDepth, nestedHandling, excludeKeys, includeKeys } = options;\n\n if (currentDepth >= maxDepth) return keys;\n\n // For homogeneous mode, track key counts\n const keyCounts = new Map<string, number>();\n\n for (const item of data) {\n if (typeof item !== 'object' || item === null) continue;\n\n for (const key of Object.keys(item)) {\n // Skip excluded keys\n if (excludeKeys?.includes(key)) continue;\n\n // Include if in includeKeys, or if meets minKeyLength\n const shouldInclude = includeKeys?.includes(key) || key.length >= minKeyLength;\n\n if (shouldInclude) {\n keys.add(key);\n keyCounts.set(key, (keyCounts.get(key) || 0) + 1);\n }\n\n // Handle nested structures based on nestedHandling option\n const value = item[key];\n\n if (nestedHandling === 'shallow') {\n // Don't process nested structures\n continue;\n }\n\n if (Array.isArray(value) && value.length > 0 && isCompressibleArray(value)) {\n // Nested array of objects - always process\n const nestedKeys = collectKeys(\n value as Record<string, unknown>[],\n options,\n currentDepth + 1\n );\n nestedKeys.forEach(k => keys.add(k));\n } else if (\n nestedHandling !== 'arrays' &&\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n // Single nested object - skip if nestedHandling is 'arrays'\n const nestedKeys = collectKeys(\n [value as Record<string, unknown>],\n options,\n currentDepth + 1\n );\n nestedKeys.forEach(k => keys.add(k));\n }\n }\n }\n\n // If homogeneous mode, only keep keys that appear in ALL objects\n if (options.homogeneousOnly && data.length > 0) {\n for (const [key, count] of keyCounts) {\n if (count < data.length) {\n keys.delete(key);\n }\n }\n }\n\n return keys;\n}\n\n/**\n * Checks if an array is compressible (array of objects with consistent structure)\n */\nexport function isCompressibleArray(data: unknown): data is Record<string, unknown>[] {\n if (!Array.isArray(data) || data.length === 0) return false;\n\n // Check if all items are objects\n return data.every(\n item => typeof item === 'object' && item !== null && !Array.isArray(item)\n );\n}\n\n/**\n * Compresses an object using the key mapping\n */\nfunction compressObject(\n obj: Record<string, unknown>,\n keyToShort: Map<string, string>,\n maxDepth: number,\n currentDepth: number = 0\n): Record<string, unknown> {\n if (currentDepth >= maxDepth) return obj;\n\n const compressed: Record<string, unknown> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n const shortKey = keyToShort.get(key) ?? key;\n\n if (Array.isArray(value) && isCompressibleArray(value)) {\n // Recursively compress nested arrays\n compressed[shortKey] = value.map(item =>\n compressObject(\n item as Record<string, unknown>,\n keyToShort,\n maxDepth,\n currentDepth + 1\n )\n );\n } else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {\n // Compress single nested objects too\n compressed[shortKey] = compressObject(\n value as Record<string, unknown>,\n keyToShort,\n maxDepth,\n currentDepth + 1\n );\n } else {\n compressed[shortKey] = value;\n }\n }\n\n return compressed;\n}\n\n/**\n * Expands an object using the key mapping\n */\nfunction expandObject(\n obj: Record<string, unknown>,\n shortToKey: Map<string, string>,\n maxDepth: number,\n currentDepth: number = 0\n): Record<string, unknown> {\n if (currentDepth >= maxDepth) return obj;\n\n const expanded: Record<string, unknown> = {};\n\n for (const [shortKey, value] of Object.entries(obj)) {\n const originalKey = shortToKey.get(shortKey) ?? shortKey;\n\n if (Array.isArray(value)) {\n expanded[originalKey] = value.map(item => {\n if (typeof item === 'object' && item !== null && !Array.isArray(item)) {\n return expandObject(\n item as Record<string, unknown>,\n shortToKey,\n maxDepth,\n currentDepth + 1\n );\n }\n return item;\n });\n } else if (typeof value === 'object' && value !== null) {\n expanded[originalKey] = expandObject(\n value as Record<string, unknown>,\n shortToKey,\n maxDepth,\n currentDepth + 1\n );\n } else {\n expanded[originalKey] = value;\n }\n }\n\n return expanded;\n}\n\n// Re-export CompressOptions from types for backwards compatibility\nexport type { CompressOptions } from './types';\n\n/**\n * Compresses an array of objects by replacing keys with short aliases\n */\nexport function compress<T extends Record<string, unknown>[]>(\n data: T,\n options: CompressOptions = {}\n): TersePayload<unknown[]> {\n const {\n minKeyLength = 3,\n maxDepth = 10,\n keyPattern = 'alpha',\n nestedHandling = 'deep',\n homogeneousOnly = false,\n excludeKeys,\n includeKeys,\n } = options;\n\n // Create key generator\n const { generator, name: patternName } = createKeyGenerator(keyPattern);\n\n // Resolve nested depth\n const effectiveDepth = resolveNestedDepth(nestedHandling, maxDepth);\n\n // Collect all unique keys\n const allKeys = collectKeys(data, {\n minKeyLength,\n maxDepth: effectiveDepth,\n nestedHandling,\n excludeKeys,\n includeKeys,\n homogeneousOnly,\n });\n\n // Sort keys by frequency of use (most used first) for optimal compression\n // For now, just sort alphabetically for deterministic output\n const sortedKeys = Array.from(allKeys).sort();\n\n // Create bidirectional mapping\n const keyToShort = new Map<string, string>();\n const keyMap: Record<string, string> = {};\n\n sortedKeys.forEach((key, index) => {\n const shortKey = generator(index);\n // Only use short key if it's actually shorter\n if (shortKey.length < key.length) {\n keyToShort.set(key, shortKey);\n keyMap[shortKey] = key;\n }\n });\n\n // Compress the data\n const compressed = data.map(item =>\n compressObject(item, keyToShort, effectiveDepth)\n );\n\n return {\n __terse__: true,\n v: 1,\n k: keyMap,\n d: compressed,\n p: patternName,\n };\n}\n\n/**\n * Expands a TersePayload back to its original form\n */\nexport function expand<T = unknown>(payload: TersePayload): T {\n const shortToKey = new Map(\n Object.entries(payload.k).map(([short, original]) => [short, original])\n );\n\n if (Array.isArray(payload.d)) {\n return payload.d.map(item => {\n if (typeof item === 'object' && item !== null && !Array.isArray(item)) {\n return expandObject(item as Record<string, unknown>, shortToKey, 10);\n }\n return item;\n }) as T;\n }\n\n if (typeof payload.d === 'object' && payload.d !== null) {\n return expandObject(payload.d as Record<string, unknown>, shortToKey, 10) as T;\n }\n\n return payload.d as T;\n}\n\n/**\n * Creates a Proxy that transparently maps original keys to short keys\n * This is the magic that makes client-side access seamless\n */\nexport function createTerseProxy<T extends Record<string, unknown>>(\n compressed: Record<string, unknown>,\n keyMap: Record<string, string> // short -> original\n): T {\n // Create reverse map: original -> short\n const originalToShort = new Map(\n Object.entries(keyMap).map(([short, original]) => [original, short])\n );\n\n const handler: ProxyHandler<Record<string, unknown>> = {\n get(target, prop: string | symbol) {\n if (typeof prop === 'symbol') {\n return Reflect.get(target, prop);\n }\n\n // Check if accessing by original key name\n const shortKey = originalToShort.get(prop);\n const actualKey = shortKey ?? prop;\n const value = target[actualKey];\n\n // Recursively proxy nested objects/arrays\n if (Array.isArray(value)) {\n return value.map(item => {\n if (typeof item === 'object' && item !== null && !Array.isArray(item)) {\n return createTerseProxy(item as Record<string, unknown>, keyMap);\n }\n return item;\n });\n }\n\n if (typeof value === 'object' && value !== null) {\n return createTerseProxy(value as Record<string, unknown>, keyMap);\n }\n\n return value;\n },\n\n has(target, prop: string | symbol) {\n if (typeof prop === 'symbol') {\n return Reflect.has(target, prop);\n }\n const shortKey = originalToShort.get(prop);\n return (shortKey ?? prop) in target;\n },\n\n ownKeys(target) {\n // Return original key names\n return Object.keys(target).map(shortKey => keyMap[shortKey] ?? shortKey);\n },\n\n getOwnPropertyDescriptor(target, prop: string | symbol) {\n if (typeof prop === 'symbol') {\n return Reflect.getOwnPropertyDescriptor(target, prop);\n }\n const shortKey = originalToShort.get(prop);\n const actualKey = shortKey ?? prop;\n const descriptor = Object.getOwnPropertyDescriptor(target, actualKey);\n if (descriptor) {\n return { ...descriptor, enumerable: true, configurable: true };\n }\n return undefined;\n },\n };\n\n return new Proxy(compressed, handler) as T;\n}\n\n/**\n * Wraps TersePayload data with Proxies for transparent access\n */\nexport function wrapWithProxy<T>(payload: TersePayload): T {\n if (Array.isArray(payload.d)) {\n return payload.d.map(item => {\n if (typeof item === 'object' && item !== null && !Array.isArray(item)) {\n return createTerseProxy(item as Record<string, unknown>, payload.k);\n }\n return item;\n }) as T;\n }\n\n if (typeof payload.d === 'object' && payload.d !== null) {\n return createTerseProxy(payload.d as Record<string, unknown>, payload.k) as T;\n }\n\n return payload.d as T;\n}\n\n// Re-export for convenience\nexport { isTersePayload };\n","/**\n * TerseJSON GraphQL Client\n *\n * Apollo Client Link and utilities for expanding GraphQL responses.\n */\n\nimport { GraphQLTerseResponse, isGraphQLTersePayload } from './types';\nimport { createTerseProxy } from './core';\n\n/**\n * Options for GraphQL client processing\n */\nexport interface GraphQLTerseClientOptions {\n /**\n * Use Proxy for lazy expansion (more memory efficient)\n * @default true\n */\n useProxy?: boolean;\n\n /**\n * Enable debug logging\n * @default false\n */\n debug?: boolean;\n}\n\nconst DEFAULT_OPTIONS: Required<GraphQLTerseClientOptions> = {\n useProxy: true,\n debug: false,\n};\n\n/**\n * Gets a value at a path in an object\n */\nfunction getAtPath(obj: unknown, path: string): unknown {\n const parts = path.split(/\\.|\\[(\\d+)\\]/).filter(Boolean);\n let current: unknown = obj;\n\n for (const part of parts) {\n if (current === null || current === undefined) return undefined;\n const isIndex = /^\\d+$/.test(part);\n if (isIndex) {\n current = (current as unknown[])[parseInt(part, 10)];\n } else {\n current = (current as Record<string, unknown>)[part];\n }\n }\n\n return current;\n}\n\n/**\n * Sets a value at a path in an object (mutates the object)\n */\nfunction setAtPath(obj: Record<string, unknown>, path: string, value: unknown): void {\n const parts = path.split(/\\.|\\[(\\d+)\\]/).filter(Boolean);\n let current: unknown = obj;\n\n for (let i = 0; i < parts.length - 1; i++) {\n const part = parts[i];\n const isIndex = /^\\d+$/.test(part);\n if (isIndex) {\n current = (current as unknown[])[parseInt(part, 10)];\n } else {\n current = (current as Record<string, unknown>)[part];\n }\n }\n\n const lastPart = parts[parts.length - 1];\n const isLastIndex = /^\\d+$/.test(lastPart);\n if (isLastIndex) {\n (current as unknown[])[parseInt(lastPart, 10)] = value;\n } else {\n (current as Record<string, unknown>)[lastPart] = value;\n }\n}\n\n/**\n * Expands an object using the key mapping\n */\nfunction expandObject(\n obj: Record<string, unknown>,\n keyMap: Record<string, string>,\n maxDepth: number = 10,\n currentDepth: number = 0\n): Record<string, unknown> {\n if (currentDepth >= maxDepth) return obj;\n\n const shortToKey = new Map(\n Object.entries(keyMap).map(([short, original]) => [short, original])\n );\n\n const expanded: Record<string, unknown> = {};\n\n for (const [shortKey, value] of Object.entries(obj)) {\n const originalKey = shortToKey.get(shortKey) ?? shortKey;\n\n if (Array.isArray(value)) {\n expanded[originalKey] = value.map(item => {\n if (typeof item === 'object' && item !== null && !Array.isArray(item)) {\n return expandObject(item as Record<string, unknown>, keyMap, maxDepth, currentDepth + 1);\n }\n return item;\n });\n } else if (typeof value === 'object' && value !== null) {\n expanded[originalKey] = expandObject(\n value as Record<string, unknown>,\n keyMap,\n maxDepth,\n currentDepth + 1\n );\n } else {\n expanded[originalKey] = value;\n }\n }\n\n return expanded;\n}\n\n/**\n * Wraps an array with Proxies for transparent key access\n */\nfunction wrapArrayWithProxies<T extends Record<string, unknown>>(\n array: Record<string, unknown>[],\n keyMap: Record<string, string>\n): T[] {\n return array.map(item => createTerseProxy<T>(item, keyMap));\n}\n\n/**\n * Expands an array to its original form\n */\nfunction expandArray(\n array: Record<string, unknown>[],\n keyMap: Record<string, string>\n): Record<string, unknown>[] {\n return array.map(item => expandObject(item, keyMap));\n}\n\n/**\n * Processes a GraphQL terse response, expanding compressed arrays\n *\n * @example\n * ```typescript\n * import { processGraphQLResponse } from 'tersejson/graphql-client';\n *\n * const response = await fetch('/graphql', {\n * method: 'POST',\n * headers: {\n * 'Content-Type': 'application/json',\n * 'accept-terse': 'true',\n * },\n * body: JSON.stringify({ query: '{ users { firstName lastName } }' }),\n * }).then(r => r.json());\n *\n * const expanded = processGraphQLResponse(response);\n * console.log(expanded.data.users[0].firstName); // Works transparently\n * ```\n */\nexport function processGraphQLResponse<T = unknown>(\n response: unknown,\n options: GraphQLTerseClientOptions = {}\n): T {\n const config = { ...DEFAULT_OPTIONS, ...options };\n\n // If not a terse response, return as-is\n if (!isGraphQLTersePayload(response)) {\n return response as T;\n }\n\n const terseResponse = response as GraphQLTerseResponse;\n const { data, __terse__, ...rest } = terseResponse;\n const { k: keyMap, paths } = __terse__;\n\n if (config.debug) {\n console.log('[tersejson/graphql-client] Processing terse response');\n console.log('[tersejson/graphql-client] Paths:', paths);\n console.log('[tersejson/graphql-client] Key map:', keyMap);\n }\n\n // Clone the data to avoid mutating\n const clonedData = JSON.parse(JSON.stringify(data));\n const result: Record<string, unknown> = { data: clonedData, ...rest };\n\n // Process each compressed path\n for (const path of paths) {\n const array = getAtPath(result, path) as Record<string, unknown>[] | undefined;\n\n if (!array || !Array.isArray(array)) {\n if (config.debug) {\n console.warn(`[tersejson/graphql-client] Path not found or not array: ${path}`);\n }\n continue;\n }\n\n if (config.useProxy) {\n // Wrap with proxies for lazy expansion\n const proxied = wrapArrayWithProxies(array, keyMap);\n setAtPath(result, path, proxied);\n } else {\n // Fully expand the array\n const expanded = expandArray(array, keyMap);\n setAtPath(result, path, expanded);\n }\n }\n\n return result as T;\n}\n\n/**\n * Type for Apollo Link (avoiding direct dependency)\n */\ninterface ApolloLinkLike {\n request(\n operation: { getContext: () => Record<string, unknown>; setContext: (ctx: Record<string, unknown>) => void },\n forward: (operation: unknown) => { map: (fn: (result: unknown) => unknown) => unknown }\n ): unknown;\n}\n\n/**\n * Creates an Apollo Client Link for TerseJSON\n *\n * This link automatically adds the accept-terse header and processes\n * terse responses transparently.\n *\n * @example\n * ```typescript\n * import { ApolloClient, InMemoryCache, HttpLink, from } from '@apollo/client';\n * import { createTerseLink } from 'tersejson/graphql-client';\n *\n * const terseLink = createTerseLink({ debug: true });\n *\n * const httpLink = new HttpLink({\n * uri: '/graphql',\n * });\n *\n * const client = new ApolloClient({\n * link: from([terseLink, httpLink]),\n * cache: new InMemoryCache(),\n * });\n *\n * // Usage is completely transparent\n * const { data } = await client.query({\n * query: gql`\n * query GetUsers {\n * users { firstName lastName email }\n * }\n * `,\n * });\n *\n * console.log(data.users[0].firstName); // Just works!\n * ```\n */\nexport function createTerseLink(options: GraphQLTerseClientOptions = {}): ApolloLinkLike {\n const config = { ...DEFAULT_OPTIONS, ...options };\n\n return {\n request(operation, forward) {\n // Add accept-terse header to the request\n operation.setContext({\n ...operation.getContext(),\n headers: {\n ...((operation.getContext().headers as Record<string, string>) || {}),\n 'accept-terse': 'true',\n },\n });\n\n // Forward the operation and process the response\n return forward(operation).map((result: unknown) => {\n if (isGraphQLTersePayload(result)) {\n if (config.debug) {\n console.log('[tersejson/apollo] Processing terse response');\n }\n return processGraphQLResponse(result, config);\n }\n return result;\n });\n },\n };\n}\n\n/**\n * Creates a fetch wrapper for GraphQL requests\n *\n * Useful for non-Apollo GraphQL clients or direct fetch usage.\n *\n * @example\n * ```typescript\n * import { createGraphQLFetch } from 'tersejson/graphql-client';\n *\n * const gqlFetch = createGraphQLFetch({ debug: true });\n *\n * const result = await gqlFetch('/graphql', {\n * query: `{ users { firstName lastName } }`,\n * });\n *\n * console.log(result.data.users[0].firstName);\n * ```\n */\nexport function createGraphQLFetch(options: GraphQLTerseClientOptions = {}) {\n const config = { ...DEFAULT_OPTIONS, ...options };\n\n return async function graphqlFetch<T = unknown>(\n url: string,\n body: { query: string; variables?: Record<string, unknown>; operationName?: string },\n init: RequestInit = {}\n ): Promise<T> {\n const headers = new Headers(init.headers);\n headers.set('Content-Type', 'application/json');\n headers.set('accept-terse', 'true');\n\n const response = await fetch(url, {\n ...init,\n method: 'POST',\n headers,\n body: JSON.stringify(body),\n });\n\n const data = await response.json();\n\n return processGraphQLResponse<T>(data, config);\n };\n}\n\n// Re-export type guard for convenience\nexport { isGraphQLTersePayload } from './types';\n\n// Default export\nexport default processGraphQLResponse;\n"]}
|