@microsoft/rayfin-data 1.20.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 +43 -0
- package/dist/client/DataApi.d.ts +64 -0
- package/dist/client/DataApi.js +109 -0
- package/dist/graphql/GraphQLClient.d.ts +45 -0
- package/dist/graphql/GraphQLClient.js +45 -0
- package/dist/graphql/GraphQLEntityClient.d.ts +48 -0
- package/dist/graphql/GraphQLEntityClient.js +277 -0
- package/dist/graphql/GraphQLQueryBuilder.d.ts +45 -0
- package/dist/graphql/GraphQLQueryBuilder.js +325 -0
- package/dist/graphql/ResponseHandler.d.ts +18 -0
- package/dist/graphql/ResponseHandler.js +66 -0
- package/dist/graphql/types.d.ts +211 -0
- package/dist/graphql/types.js +2 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/dist/utils/serialization.d.ts +33 -0
- package/dist/utils/serialization.js +132 -0
- package/package.json +56 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization utilities for DAB compatibility
|
|
3
|
+
*
|
|
4
|
+
* DAB often returns boolean values as strings ("true"/"false") from database queries.
|
|
5
|
+
* These utilities ensure proper type conversion for TypeScript clients.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Converts a DAB boolean value (which may be a string) to a proper TypeScript boolean
|
|
9
|
+
* @param value - The boolean value from DAB, which could be boolean, string, or undefined
|
|
10
|
+
* @returns A proper TypeScript boolean
|
|
11
|
+
*/
|
|
12
|
+
export declare function deserializeBoolean(value: boolean | string | undefined | null): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Converts a DAB date value (which may be a string) to a proper Date object
|
|
15
|
+
* @param value - The date value from DAB, which could be Date, string, or undefined
|
|
16
|
+
* @returns A proper Date object or undefined
|
|
17
|
+
*/
|
|
18
|
+
export declare function deserializeDate(value: Date | string | undefined | null): Date | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Type guard to check if a value is a DAB string boolean
|
|
21
|
+
*/
|
|
22
|
+
export declare function isDabStringBoolean(value: unknown): value is 'true' | 'false';
|
|
23
|
+
/**
|
|
24
|
+
* Deep transform an object to convert DAB serialized values to proper TypeScript types
|
|
25
|
+
* This recursively processes objects and arrays to convert string booleans and dates
|
|
26
|
+
*/
|
|
27
|
+
export declare function deserializeDabResponse<T = any>(data: any): T;
|
|
28
|
+
/**
|
|
29
|
+
* Transform data for sending to DAB (opposite of deserialize)
|
|
30
|
+
* Converts boolean values to strings if needed for specific DAB configurations
|
|
31
|
+
*/
|
|
32
|
+
export declare function serializeForDab<T = any>(data: T): any;
|
|
33
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Serialization utilities for DAB compatibility
|
|
3
|
+
*
|
|
4
|
+
* DAB often returns boolean values as strings ("true"/"false") from database queries.
|
|
5
|
+
* These utilities ensure proper type conversion for TypeScript clients.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Converts a DAB boolean value (which may be a string) to a proper TypeScript boolean
|
|
9
|
+
* @param value - The boolean value from DAB, which could be boolean, string, or undefined
|
|
10
|
+
* @returns A proper TypeScript boolean
|
|
11
|
+
*/
|
|
12
|
+
export function deserializeBoolean(value) {
|
|
13
|
+
if (typeof value === 'boolean') {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
if (typeof value === 'string') {
|
|
17
|
+
return value.toLowerCase() === 'true';
|
|
18
|
+
}
|
|
19
|
+
return false; // Default for undefined, null, or other types
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts a DAB date value (which may be a string) to a proper Date object
|
|
23
|
+
* @param value - The date value from DAB, which could be Date, string, or undefined
|
|
24
|
+
* @returns A proper Date object or undefined
|
|
25
|
+
*/
|
|
26
|
+
export function deserializeDate(value) {
|
|
27
|
+
if (!value)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (value instanceof Date)
|
|
30
|
+
return value;
|
|
31
|
+
if (typeof value === 'string') {
|
|
32
|
+
const date = new Date(value);
|
|
33
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Type guard to check if a value is a DAB string boolean
|
|
39
|
+
*/
|
|
40
|
+
export function isDabStringBoolean(value) {
|
|
41
|
+
return typeof value === 'string' && (value === 'true' || value === 'false');
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Deep transform an object to convert DAB serialized values to proper TypeScript types
|
|
45
|
+
* This recursively processes objects and arrays to convert string booleans and dates
|
|
46
|
+
*/
|
|
47
|
+
export function deserializeDabResponse(data) {
|
|
48
|
+
if (data === null || data === undefined) {
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(data)) {
|
|
52
|
+
return data.map((item) => deserializeDabResponse(item));
|
|
53
|
+
}
|
|
54
|
+
if (typeof data === 'object') {
|
|
55
|
+
const result = {};
|
|
56
|
+
for (const [key, value] of Object.entries(data)) {
|
|
57
|
+
if (isDabStringBoolean(value)) {
|
|
58
|
+
// Convert string booleans to actual booleans
|
|
59
|
+
result[key] = deserializeBoolean(value);
|
|
60
|
+
}
|
|
61
|
+
else if (typeof value === 'string' && isISODateString(value)) {
|
|
62
|
+
// Convert ISO date strings to Date objects
|
|
63
|
+
result[key] = deserializeDate(value);
|
|
64
|
+
}
|
|
65
|
+
else if (value instanceof Date) {
|
|
66
|
+
// Keep Date objects as-is (don't recursively process them)
|
|
67
|
+
result[key] = value;
|
|
68
|
+
}
|
|
69
|
+
else if (typeof value === 'object') {
|
|
70
|
+
// Recursively process nested objects
|
|
71
|
+
result[key] = deserializeDabResponse(value);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Keep primitive values as-is
|
|
75
|
+
result[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
// For primitive values, return as-is
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if a string looks like an ISO date string
|
|
85
|
+
*/
|
|
86
|
+
function isISODateString(value) {
|
|
87
|
+
// Check for ISO 8601 formats:
|
|
88
|
+
// - Full datetime: "2023-12-25T10:30:00.000Z" or "2023-12-25T10:30:00"
|
|
89
|
+
// - Date only: "2023-12-25" (DAB commonly returns date-only strings)
|
|
90
|
+
const isoDatetimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z?$/;
|
|
91
|
+
const isoDateOnlyRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
92
|
+
return ((isoDatetimeRegex.test(value) || isoDateOnlyRegex.test(value)) &&
|
|
93
|
+
!isNaN(Date.parse(value)));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Transform data for sending to DAB (opposite of deserialize)
|
|
97
|
+
* Converts boolean values to strings if needed for specific DAB configurations
|
|
98
|
+
*/
|
|
99
|
+
export function serializeForDab(data) {
|
|
100
|
+
if (data === null || data === undefined) {
|
|
101
|
+
return data;
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(data)) {
|
|
104
|
+
return data.map((item) => serializeForDab(item));
|
|
105
|
+
}
|
|
106
|
+
if (typeof data === 'object') {
|
|
107
|
+
const result = {};
|
|
108
|
+
for (const [key, value] of Object.entries(data)) {
|
|
109
|
+
if (typeof value === 'boolean') {
|
|
110
|
+
// Keep booleans as booleans for most DAB scenarios
|
|
111
|
+
// Only convert to strings if specifically needed
|
|
112
|
+
result[key] = value;
|
|
113
|
+
}
|
|
114
|
+
else if (value instanceof Date) {
|
|
115
|
+
// Convert Date objects to ISO strings
|
|
116
|
+
result[key] = value.toISOString();
|
|
117
|
+
}
|
|
118
|
+
else if (typeof value === 'object') {
|
|
119
|
+
// Recursively process nested objects
|
|
120
|
+
result[key] = serializeForDab(value);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// Keep other values as-is
|
|
124
|
+
result[key] = value;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
// For primitive values, return as-is
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=serialization.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@microsoft/rayfin-data",
|
|
3
|
+
"version": "1.20.0",
|
|
4
|
+
"description": "Type-safe client library for Data API Builder endpoints",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/**/*.js",
|
|
10
|
+
"dist/**/*.d.ts",
|
|
11
|
+
"!dist/**/__tests__/**",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@microsoft/rayfin-lib": "1.20.0",
|
|
16
|
+
"@microsoft/rayfin-core": "1.20.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^20.0.0",
|
|
20
|
+
"eslint": "^9.28.0",
|
|
21
|
+
"prettier": "^3.5.3",
|
|
22
|
+
"rimraf": "~6.0.1",
|
|
23
|
+
"typescript": "^5.8.3",
|
|
24
|
+
"vitest": "^3.2.3",
|
|
25
|
+
"@vitest/coverage-v8": "~3.2.4"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"dab",
|
|
29
|
+
"data-api-builder",
|
|
30
|
+
"typescript",
|
|
31
|
+
"client",
|
|
32
|
+
"rest",
|
|
33
|
+
"graphql"
|
|
34
|
+
],
|
|
35
|
+
"author": "Microsoft",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"registry": "https://npm.pkg.github.com",
|
|
39
|
+
"access": "restricted"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/microsoft/project-rayfin.git",
|
|
44
|
+
"directory": "packages/typescript-sdk/data"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"build:watch": "tsc --watch",
|
|
49
|
+
"clean": "rimraf dist && rimraf .tsbuildinfo",
|
|
50
|
+
"test": "vitest run",
|
|
51
|
+
"test:watch": "vitest",
|
|
52
|
+
"test:coverage": "vitest run --coverage",
|
|
53
|
+
"test:integration": "vitest run src/__tests__/integration/",
|
|
54
|
+
"test:integration:watch": "vitest src/__tests__/integration/"
|
|
55
|
+
}
|
|
56
|
+
}
|