tersejson 0.1.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/LICENSE +21 -0
- package/README.md +476 -0
- package/dist/analytics.d.mts +186 -0
- package/dist/analytics.d.ts +186 -0
- package/dist/analytics.js +226 -0
- package/dist/analytics.js.map +1 -0
- package/dist/analytics.mjs +217 -0
- package/dist/analytics.mjs.map +1 -0
- package/dist/client-BQAZg7I8.d.mts +138 -0
- package/dist/client-DOOGwp_p.d.ts +138 -0
- package/dist/client.d.mts +2 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +200 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +188 -0
- package/dist/client.mjs.map +1 -0
- package/dist/express-BoL__Ao6.d.mts +67 -0
- package/dist/express-LSVylWpN.d.ts +67 -0
- package/dist/express.d.mts +4 -0
- package/dist/express.d.ts +4 -0
- package/dist/express.js +522 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +512 -0
- package/dist/express.mjs.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +1001 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +985 -0
- package/dist/index.mjs.map +1 -0
- package/dist/integrations-7WeFO1Lk.d.mts +264 -0
- package/dist/integrations-7WeFO1Lk.d.ts +264 -0
- package/dist/integrations.d.mts +1 -0
- package/dist/integrations.d.ts +1 -0
- package/dist/integrations.js +381 -0
- package/dist/integrations.js.map +1 -0
- package/dist/integrations.mjs +367 -0
- package/dist/integrations.mjs.map +1 -0
- package/dist/types-CzaGQaV7.d.mts +134 -0
- package/dist/types-CzaGQaV7.d.ts +134 -0
- package/package.json +87 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TerseJSON Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the wire format and configuration options for transparent
|
|
5
|
+
* JSON key compression.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The compressed format sent over the wire
|
|
9
|
+
*/
|
|
10
|
+
interface TersePayload<T = unknown> {
|
|
11
|
+
/** Marker to identify this as a TerseJSON payload */
|
|
12
|
+
__terse__: true;
|
|
13
|
+
/** Version for future compatibility */
|
|
14
|
+
v: 1;
|
|
15
|
+
/** Key mapping: short key -> original key */
|
|
16
|
+
k: Record<string, string>;
|
|
17
|
+
/** The compressed data with short keys */
|
|
18
|
+
d: T;
|
|
19
|
+
/** Pattern used for key generation (for debugging/info) */
|
|
20
|
+
p?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Built-in key pattern presets
|
|
24
|
+
*/
|
|
25
|
+
type KeyPatternPreset = 'alpha' | 'numeric' | 'alphanumeric' | 'short' | 'prefixed';
|
|
26
|
+
/**
|
|
27
|
+
* Custom key generator function
|
|
28
|
+
*/
|
|
29
|
+
type KeyGenerator = (index: number) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Key pattern configuration
|
|
32
|
+
*/
|
|
33
|
+
type KeyPattern = KeyPatternPreset | {
|
|
34
|
+
prefix: string;
|
|
35
|
+
style?: 'numeric' | 'alpha';
|
|
36
|
+
} | KeyGenerator;
|
|
37
|
+
/**
|
|
38
|
+
* How to handle nested structures
|
|
39
|
+
*/
|
|
40
|
+
type NestedHandling = 'deep' | 'shallow' | 'arrays' | number;
|
|
41
|
+
/**
|
|
42
|
+
* Compression options
|
|
43
|
+
*/
|
|
44
|
+
interface CompressOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Minimum key length to consider for compression
|
|
47
|
+
* Keys shorter than this won't be shortened
|
|
48
|
+
* @default 3
|
|
49
|
+
*/
|
|
50
|
+
minKeyLength?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Maximum depth to traverse for nested objects
|
|
53
|
+
* @default 10
|
|
54
|
+
*/
|
|
55
|
+
maxDepth?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Key pattern to use for generating short keys
|
|
58
|
+
* @default 'alpha'
|
|
59
|
+
*/
|
|
60
|
+
keyPattern?: KeyPattern;
|
|
61
|
+
/**
|
|
62
|
+
* How to handle nested objects and arrays
|
|
63
|
+
* @default 'deep'
|
|
64
|
+
*/
|
|
65
|
+
nestedHandling?: NestedHandling;
|
|
66
|
+
/**
|
|
67
|
+
* Only compress keys that appear in all objects (homogeneous)
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
homogeneousOnly?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Keys to always exclude from compression
|
|
73
|
+
*/
|
|
74
|
+
excludeKeys?: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Keys to always include in compression (even if short)
|
|
77
|
+
*/
|
|
78
|
+
includeKeys?: string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration options for the Express middleware
|
|
82
|
+
*/
|
|
83
|
+
interface TerseMiddlewareOptions extends CompressOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Minimum array length to trigger compression
|
|
86
|
+
* @default 2
|
|
87
|
+
*/
|
|
88
|
+
minArrayLength?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Custom function to determine if a response should be compressed
|
|
91
|
+
* Return false to skip compression for specific responses
|
|
92
|
+
*/
|
|
93
|
+
shouldCompress?: (data: unknown, req: unknown) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Custom header name for signaling terse responses
|
|
96
|
+
* @default 'x-terse-json'
|
|
97
|
+
*/
|
|
98
|
+
headerName?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Enable debug logging
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
debug?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Configuration options for the client
|
|
107
|
+
*/
|
|
108
|
+
interface TerseClientOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Custom header name to check for terse responses
|
|
111
|
+
* @default 'x-terse-json'
|
|
112
|
+
*/
|
|
113
|
+
headerName?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Enable debug logging
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
debug?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Automatically expand terse responses
|
|
121
|
+
* @default true
|
|
122
|
+
*/
|
|
123
|
+
autoExpand?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Type helper to preserve original types through compression
|
|
127
|
+
*/
|
|
128
|
+
type Tersed<T> = T;
|
|
129
|
+
/**
|
|
130
|
+
* Check if a value is a TersePayload
|
|
131
|
+
*/
|
|
132
|
+
declare function isTersePayload(value: unknown): value is TersePayload;
|
|
133
|
+
|
|
134
|
+
export { type CompressOptions as C, type KeyPattern as K, type NestedHandling as N, type TersePayload as T, type TerseMiddlewareOptions as a, type TerseClientOptions as b, type KeyPatternPreset as c, type KeyGenerator as d, type Tersed as e, isTersePayload as i };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TerseJSON Types
|
|
3
|
+
*
|
|
4
|
+
* Defines the wire format and configuration options for transparent
|
|
5
|
+
* JSON key compression.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The compressed format sent over the wire
|
|
9
|
+
*/
|
|
10
|
+
interface TersePayload<T = unknown> {
|
|
11
|
+
/** Marker to identify this as a TerseJSON payload */
|
|
12
|
+
__terse__: true;
|
|
13
|
+
/** Version for future compatibility */
|
|
14
|
+
v: 1;
|
|
15
|
+
/** Key mapping: short key -> original key */
|
|
16
|
+
k: Record<string, string>;
|
|
17
|
+
/** The compressed data with short keys */
|
|
18
|
+
d: T;
|
|
19
|
+
/** Pattern used for key generation (for debugging/info) */
|
|
20
|
+
p?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Built-in key pattern presets
|
|
24
|
+
*/
|
|
25
|
+
type KeyPatternPreset = 'alpha' | 'numeric' | 'alphanumeric' | 'short' | 'prefixed';
|
|
26
|
+
/**
|
|
27
|
+
* Custom key generator function
|
|
28
|
+
*/
|
|
29
|
+
type KeyGenerator = (index: number) => string;
|
|
30
|
+
/**
|
|
31
|
+
* Key pattern configuration
|
|
32
|
+
*/
|
|
33
|
+
type KeyPattern = KeyPatternPreset | {
|
|
34
|
+
prefix: string;
|
|
35
|
+
style?: 'numeric' | 'alpha';
|
|
36
|
+
} | KeyGenerator;
|
|
37
|
+
/**
|
|
38
|
+
* How to handle nested structures
|
|
39
|
+
*/
|
|
40
|
+
type NestedHandling = 'deep' | 'shallow' | 'arrays' | number;
|
|
41
|
+
/**
|
|
42
|
+
* Compression options
|
|
43
|
+
*/
|
|
44
|
+
interface CompressOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Minimum key length to consider for compression
|
|
47
|
+
* Keys shorter than this won't be shortened
|
|
48
|
+
* @default 3
|
|
49
|
+
*/
|
|
50
|
+
minKeyLength?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Maximum depth to traverse for nested objects
|
|
53
|
+
* @default 10
|
|
54
|
+
*/
|
|
55
|
+
maxDepth?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Key pattern to use for generating short keys
|
|
58
|
+
* @default 'alpha'
|
|
59
|
+
*/
|
|
60
|
+
keyPattern?: KeyPattern;
|
|
61
|
+
/**
|
|
62
|
+
* How to handle nested objects and arrays
|
|
63
|
+
* @default 'deep'
|
|
64
|
+
*/
|
|
65
|
+
nestedHandling?: NestedHandling;
|
|
66
|
+
/**
|
|
67
|
+
* Only compress keys that appear in all objects (homogeneous)
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
homogeneousOnly?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Keys to always exclude from compression
|
|
73
|
+
*/
|
|
74
|
+
excludeKeys?: string[];
|
|
75
|
+
/**
|
|
76
|
+
* Keys to always include in compression (even if short)
|
|
77
|
+
*/
|
|
78
|
+
includeKeys?: string[];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Configuration options for the Express middleware
|
|
82
|
+
*/
|
|
83
|
+
interface TerseMiddlewareOptions extends CompressOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Minimum array length to trigger compression
|
|
86
|
+
* @default 2
|
|
87
|
+
*/
|
|
88
|
+
minArrayLength?: number;
|
|
89
|
+
/**
|
|
90
|
+
* Custom function to determine if a response should be compressed
|
|
91
|
+
* Return false to skip compression for specific responses
|
|
92
|
+
*/
|
|
93
|
+
shouldCompress?: (data: unknown, req: unknown) => boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Custom header name for signaling terse responses
|
|
96
|
+
* @default 'x-terse-json'
|
|
97
|
+
*/
|
|
98
|
+
headerName?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Enable debug logging
|
|
101
|
+
* @default false
|
|
102
|
+
*/
|
|
103
|
+
debug?: boolean;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Configuration options for the client
|
|
107
|
+
*/
|
|
108
|
+
interface TerseClientOptions {
|
|
109
|
+
/**
|
|
110
|
+
* Custom header name to check for terse responses
|
|
111
|
+
* @default 'x-terse-json'
|
|
112
|
+
*/
|
|
113
|
+
headerName?: string;
|
|
114
|
+
/**
|
|
115
|
+
* Enable debug logging
|
|
116
|
+
* @default false
|
|
117
|
+
*/
|
|
118
|
+
debug?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Automatically expand terse responses
|
|
121
|
+
* @default true
|
|
122
|
+
*/
|
|
123
|
+
autoExpand?: boolean;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Type helper to preserve original types through compression
|
|
127
|
+
*/
|
|
128
|
+
type Tersed<T> = T;
|
|
129
|
+
/**
|
|
130
|
+
* Check if a value is a TersePayload
|
|
131
|
+
*/
|
|
132
|
+
declare function isTersePayload(value: unknown): value is TersePayload;
|
|
133
|
+
|
|
134
|
+
export { type CompressOptions as C, type KeyPattern as K, type NestedHandling as N, type TersePayload as T, type TerseMiddlewareOptions as a, type TerseClientOptions as b, type KeyPatternPreset as c, type KeyGenerator as d, type Tersed as e, isTersePayload as i };
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tersejson",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Transparent JSON key compression for Express APIs. Reduce bandwidth by up to 80% with zero code changes.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"json",
|
|
7
|
+
"compression",
|
|
8
|
+
"express",
|
|
9
|
+
"middleware",
|
|
10
|
+
"bandwidth",
|
|
11
|
+
"optimization",
|
|
12
|
+
"api",
|
|
13
|
+
"rest",
|
|
14
|
+
"keys",
|
|
15
|
+
"minify"
|
|
16
|
+
],
|
|
17
|
+
"author": "Tim Carter",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/timclausendev-web/tersejson"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://tersejson.com",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./express": {
|
|
34
|
+
"types": "./dist/express.d.ts",
|
|
35
|
+
"import": "./dist/express.mjs",
|
|
36
|
+
"require": "./dist/express.js"
|
|
37
|
+
},
|
|
38
|
+
"./client": {
|
|
39
|
+
"types": "./dist/client.d.ts",
|
|
40
|
+
"import": "./dist/client.mjs",
|
|
41
|
+
"require": "./dist/client.js"
|
|
42
|
+
},
|
|
43
|
+
"./integrations": {
|
|
44
|
+
"types": "./dist/integrations.d.ts",
|
|
45
|
+
"import": "./dist/integrations.mjs",
|
|
46
|
+
"require": "./dist/integrations.js"
|
|
47
|
+
},
|
|
48
|
+
"./analytics": {
|
|
49
|
+
"types": "./dist/analytics.d.ts",
|
|
50
|
+
"import": "./dist/analytics.mjs",
|
|
51
|
+
"require": "./dist/analytics.js"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup",
|
|
59
|
+
"dev": "tsup --watch",
|
|
60
|
+
"test": "vitest",
|
|
61
|
+
"test:run": "vitest run",
|
|
62
|
+
"lint": "eslint src/",
|
|
63
|
+
"typecheck": "tsc --noEmit",
|
|
64
|
+
"prepublishOnly": "npm run build"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/express": "^4.17.21",
|
|
68
|
+
"@types/node": "^20.11.0",
|
|
69
|
+
"eslint": "^8.56.0",
|
|
70
|
+
"express": "^4.18.2",
|
|
71
|
+
"sharp": "^0.34.5",
|
|
72
|
+
"tsup": "^8.0.1",
|
|
73
|
+
"typescript": "^5.3.3",
|
|
74
|
+
"vitest": "^1.2.0"
|
|
75
|
+
},
|
|
76
|
+
"peerDependencies": {
|
|
77
|
+
"express": ">=4.0.0"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"express": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"engines": {
|
|
85
|
+
"node": ">=16.0.0"
|
|
86
|
+
}
|
|
87
|
+
}
|