@vectora/contracts 1.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/LICENSE.md +25 -0
- package/dist/events/auth/index.d.ts +1 -0
- package/dist/events/auth/index.js +17 -0
- package/dist/events/auth/verification-request.interface.d.ts +5 -0
- package/dist/events/auth/verification-request.interface.js +2 -0
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.js +17 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/proto/index.d.ts +1 -0
- package/dist/proto/index.js +17 -0
- package/dist/proto/paths.d.ts +18 -0
- package/dist/proto/paths.js +27 -0
- package/dist/utils/data-transformer.util.d.ts +55 -0
- package/dist/utils/data-transformer.util.js +141 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +17 -0
- package/gen/go/mapbox-direction-v1.pb.go +621 -0
- package/gen/go/mapbox-geocode-v1.pb.go +473 -0
- package/gen/go/mapbox-matrix-v1.pb.go +337 -0
- package/gen/go/mapbox-optimization-v1.pb.go +422 -0
- package/gen/go/mapbox-search-v1.pb.go +699 -0
- package/gen/ts/common-geocode-v1.ts +368 -0
- package/gen/ts/common-pagination-v1.ts +713 -0
- package/gen/ts/fleet-truck-v1.ts +1102 -0
- package/gen/ts/fleet-unit-v1.ts +9 -0
- package/gen/ts/google/protobuf/field_mask.ts +295 -0
- package/gen/ts/google/protobuf/wrappers.ts +544 -0
- package/gen/ts/identify-account-v1.ts +9 -0
- package/gen/ts/identify-auth-v1.ts +9 -0
- package/gen/ts/identify-company-v1.ts +1025 -0
- package/gen/ts/identify-role-v1.ts +9 -0
- package/gen/ts/identify-user-v1.ts +9 -0
- package/gen/ts/mapbox-direction-v1.ts +718 -0
- package/gen/ts/mapbox-geocode-v1.ts +511 -0
- package/gen/ts/mapbox-matrix-v1.ts +369 -0
- package/gen/ts/mapbox-optimization-v1.ts +472 -0
- package/gen/ts/mapbox-search-v1.ts +803 -0
- package/gen/ts/shipments-freight-v1.ts +9 -0
- package/gen/ts/shipments-loads-v1.ts +9 -0
- package/gen/ts/shipments-rate-v1.ts +9 -0
- package/gen/ts/shipments-stop-v1.ts +9 -0
- package/package.json +40 -0
- package/proto/common-geocode-v1.proto +10 -0
- package/proto/common-pagination-v1.proto +39 -0
- package/proto/fleet-truck-v1.proto +145 -0
- package/proto/fleet-unit-v1.proto +3 -0
- package/proto/identify-account-v1.proto +3 -0
- package/proto/identify-auth-v1.proto +3 -0
- package/proto/identify-company-v1.proto +114 -0
- package/proto/identify-role-v1.proto +3 -0
- package/proto/identify-user-v1.proto +3 -0
- package/proto/mapbox-direction-v1.proto +61 -0
- package/proto/mapbox-geocode-v1.proto +47 -0
- package/proto/mapbox-matrix-v1.proto +34 -0
- package/proto/mapbox-optimization-v1.proto +43 -0
- package/proto/mapbox-search-v1.proto +68 -0
- package/proto/shipments-freight-v1.proto +3 -0
- package/proto/shipments-loads-v1.proto +3 -0
- package/proto/shipments-rate-v1.proto +3 -0
- package/proto/shipments-stop-v1.proto +3 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) 2026 Vectora Inc. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software and associated documentation files (the "Software") are the
|
|
4
|
+
exclusive property of Vectora Inc.
|
|
5
|
+
|
|
6
|
+
The Software is published for the internal use of Vectora Inc. projects and
|
|
7
|
+
is not intended for public use, redistribution, or modification.
|
|
8
|
+
|
|
9
|
+
PERMISSIONS:
|
|
10
|
+
|
|
11
|
+
- Use of this Software is strictly limited to authorized employees and
|
|
12
|
+
systems of Vectora Inc.
|
|
13
|
+
- No part of this Software may be copied, modified, distributed, or
|
|
14
|
+
sub-licensed to any third party without express written permission
|
|
15
|
+
from Vectora Inc.
|
|
16
|
+
|
|
17
|
+
RESTRICTIONS:
|
|
18
|
+
|
|
19
|
+
- You may not use this Software in any project not owned or managed
|
|
20
|
+
by Vectora Inc.
|
|
21
|
+
- You may not reverse engineer, decompile, or disassemble the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
|
25
|
+
ANY CLAIM, DAMAGES OR OTHER LIABILITY.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./verification-request.interface";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./verification-request.interface"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./auth";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./auth"), exports);
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./events"), exports);
|
|
18
|
+
__exportStar(require("./proto"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./paths";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./paths"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare const PROTO_PATHS: {
|
|
2
|
+
readonly AUTH: string;
|
|
3
|
+
readonly ACCOUNT: string;
|
|
4
|
+
readonly USER: string;
|
|
5
|
+
readonly COMPANY: string;
|
|
6
|
+
readonly ROLE: string;
|
|
7
|
+
readonly SHIPMENTS: string;
|
|
8
|
+
readonly SHIPMENTS_RATES: string;
|
|
9
|
+
readonly SHIPMENTS_STOPS: string;
|
|
10
|
+
readonly SHIPMENTS_FREIGHT: string;
|
|
11
|
+
readonly FLEET_TRUCKS: string;
|
|
12
|
+
readonly FLEET_UNITS: string;
|
|
13
|
+
readonly GEOCODE: string;
|
|
14
|
+
readonly DIRECTION: string;
|
|
15
|
+
readonly MATRIX: string;
|
|
16
|
+
readonly OPTIMIZATION: string;
|
|
17
|
+
readonly SEARCH: string;
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROTO_PATHS = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
exports.PROTO_PATHS = {
|
|
7
|
+
// * Identify
|
|
8
|
+
AUTH: (0, path_1.join)(__dirname, "../../proto/ts/identify-auth-v1.proto"),
|
|
9
|
+
ACCOUNT: (0, path_1.join)(__dirname, "../../proto/ts/identify-account-v1.proto"),
|
|
10
|
+
USER: (0, path_1.join)(__dirname, "../../proto/ts/identify-user-v1.proto"),
|
|
11
|
+
COMPANY: (0, path_1.join)(__dirname, "../../proto/ts/identify-company-v1.proto"),
|
|
12
|
+
ROLE: (0, path_1.join)(__dirname, "../../proto/ts/identify-role-v1.proto"),
|
|
13
|
+
// * shipments
|
|
14
|
+
SHIPMENTS: (0, path_1.join)(__dirname, "../../proto/ts/shipments-loads-v1.proto"),
|
|
15
|
+
SHIPMENTS_RATES: (0, path_1.join)(__dirname, "../../proto/ts/shipments-rate-v1.proto"),
|
|
16
|
+
SHIPMENTS_STOPS: (0, path_1.join)(__dirname, "../../proto/ts/shipments-stop-v1.proto"),
|
|
17
|
+
SHIPMENTS_FREIGHT: (0, path_1.join)(__dirname, "../../proto/ts/shipments-freight-v1.proto"),
|
|
18
|
+
// * fleet
|
|
19
|
+
FLEET_TRUCKS: (0, path_1.join)(__dirname, "../../proto/ts/fleet-truck-v1.proto"),
|
|
20
|
+
FLEET_UNITS: (0, path_1.join)(__dirname, "../../proto/ts/fleet-unit-v1.proto"),
|
|
21
|
+
// * geocode
|
|
22
|
+
GEOCODE: (0, path_1.join)(__dirname, "../../proto/ts/mapbox-geocode-v1.proto"),
|
|
23
|
+
DIRECTION: (0, path_1.join)(__dirname, "../../proto/ts/mapbox-direction-v1.proto"),
|
|
24
|
+
MATRIX: (0, path_1.join)(__dirname, "../../proto/ts/mapbox-matrix-v1.proto"),
|
|
25
|
+
OPTIMIZATION: (0, path_1.join)(__dirname, "../../proto/ts/mapbox-optimization-v1.proto"),
|
|
26
|
+
SEARCH: (0, path_1.join)(__dirname, "../../proto/ts/mapbox-search-v1.proto"),
|
|
27
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DataTransformer Utility
|
|
3
|
+
* * A universal bridge between JS/TypeORM (camelCase) and gRPC (snake_case + FieldMask).
|
|
4
|
+
* * Features:
|
|
5
|
+
* - Automatic FieldMask generation (including deep nested paths).
|
|
6
|
+
* - Auto-detection and unwrapping of Google Protobuf Wrappers (StringValue, Int32Value, etc.).
|
|
7
|
+
* - Bidirectional conversion between JS Date/ISO-strings and gRPC Timestamps.
|
|
8
|
+
* - Support for nested objects and repeated fields (arrays).
|
|
9
|
+
*/
|
|
10
|
+
export declare class DataTransformer {
|
|
11
|
+
/**
|
|
12
|
+
* Detects if an object is a Google Protobuf Wrapper (e.g., StringValue).
|
|
13
|
+
*/
|
|
14
|
+
private static isWrapper;
|
|
15
|
+
/**
|
|
16
|
+
* Detects if an object is a gRPC Timestamp.
|
|
17
|
+
*/
|
|
18
|
+
private static isTimestamp;
|
|
19
|
+
private static toSnakeCase;
|
|
20
|
+
private static toCamelCase;
|
|
21
|
+
/**
|
|
22
|
+
* normalizeRequest
|
|
23
|
+
* Prepares a JS DTO for gRPC transmission and generates a FieldMask.
|
|
24
|
+
* * @param dto - Flat or nested JS object (e.g., from an API Controller).
|
|
25
|
+
* @param prefix - Internal use for recursive path building.
|
|
26
|
+
* * @example
|
|
27
|
+
* const { data, updateMask } = DataTransformer.normalizeRequest({
|
|
28
|
+
* legalName: "Apple",
|
|
29
|
+
* dbaName: null,
|
|
30
|
+
* createdAt: "2026-02-12T10:00:00Z",
|
|
31
|
+
* equipment: [1, 2]
|
|
32
|
+
* });
|
|
33
|
+
* * // Result 'data': { legalName: "Apple", dbaName: undefined, createdAt: {seconds: 1770890400...}, equipment: {items: [1,2]} }
|
|
34
|
+
* // Result 'updateMask': { paths: ["legal_name", "dba_name", "created_at", "equipment"] }
|
|
35
|
+
*/
|
|
36
|
+
static normalizeRequest<T>(dto: any, prefix?: string): {
|
|
37
|
+
data: T;
|
|
38
|
+
updateMask: {
|
|
39
|
+
paths: string[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* normalizeResponse
|
|
44
|
+
* Converts a gRPC response back to a JS/TypeORM Entity format.
|
|
45
|
+
* * @param source - The gRPC message received.
|
|
46
|
+
* @param updateMask - The FieldMask for partial updates.
|
|
47
|
+
* * @example
|
|
48
|
+
* const entity = DataTransformer.normalizeResponse(grpcResponse, grpcResponse.updateMask);
|
|
49
|
+
* * // Input: { dbaName: {value: "Test"}, createdAt: {seconds: 1770890400}, equipment: {items: [1]} }
|
|
50
|
+
* // Output: { dbaName: "Test", createdAt: Date(...), equipment: [1] }
|
|
51
|
+
*/
|
|
52
|
+
static normalizeResponse<T>(source: any, updateMask?: {
|
|
53
|
+
paths: string[];
|
|
54
|
+
}): Partial<T>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataTransformer = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* DataTransformer Utility
|
|
6
|
+
* * A universal bridge between JS/TypeORM (camelCase) and gRPC (snake_case + FieldMask).
|
|
7
|
+
* * Features:
|
|
8
|
+
* - Automatic FieldMask generation (including deep nested paths).
|
|
9
|
+
* - Auto-detection and unwrapping of Google Protobuf Wrappers (StringValue, Int32Value, etc.).
|
|
10
|
+
* - Bidirectional conversion between JS Date/ISO-strings and gRPC Timestamps.
|
|
11
|
+
* - Support for nested objects and repeated fields (arrays).
|
|
12
|
+
*/
|
|
13
|
+
class DataTransformer {
|
|
14
|
+
/**
|
|
15
|
+
* Detects if an object is a Google Protobuf Wrapper (e.g., StringValue).
|
|
16
|
+
*/
|
|
17
|
+
static isWrapper(obj) {
|
|
18
|
+
return (obj !== null &&
|
|
19
|
+
typeof obj === "object" &&
|
|
20
|
+
!Array.isArray(obj) &&
|
|
21
|
+
Object.keys(obj).length === 1 &&
|
|
22
|
+
"value" in obj);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Detects if an object is a gRPC Timestamp.
|
|
26
|
+
*/
|
|
27
|
+
static isTimestamp(obj) {
|
|
28
|
+
return (obj !== null &&
|
|
29
|
+
typeof obj === "object" &&
|
|
30
|
+
"seconds" in obj &&
|
|
31
|
+
typeof obj.seconds === "number");
|
|
32
|
+
}
|
|
33
|
+
static toSnakeCase(str) {
|
|
34
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
35
|
+
}
|
|
36
|
+
static toCamelCase(str) {
|
|
37
|
+
return str.replace(/(_\w)/g, (m) => m[1].toUpperCase());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* normalizeRequest
|
|
41
|
+
* Prepares a JS DTO for gRPC transmission and generates a FieldMask.
|
|
42
|
+
* * @param dto - Flat or nested JS object (e.g., from an API Controller).
|
|
43
|
+
* @param prefix - Internal use for recursive path building.
|
|
44
|
+
* * @example
|
|
45
|
+
* const { data, updateMask } = DataTransformer.normalizeRequest({
|
|
46
|
+
* legalName: "Apple",
|
|
47
|
+
* dbaName: null,
|
|
48
|
+
* createdAt: "2026-02-12T10:00:00Z",
|
|
49
|
+
* equipment: [1, 2]
|
|
50
|
+
* });
|
|
51
|
+
* * // Result 'data': { legalName: "Apple", dbaName: undefined, createdAt: {seconds: 1770890400...}, equipment: {items: [1,2]} }
|
|
52
|
+
* // Result 'updateMask': { paths: ["legal_name", "dba_name", "created_at", "equipment"] }
|
|
53
|
+
*/
|
|
54
|
+
static normalizeRequest(dto, prefix = "") {
|
|
55
|
+
const data = {};
|
|
56
|
+
const paths = [];
|
|
57
|
+
for (const key in dto) {
|
|
58
|
+
let value = dto[key];
|
|
59
|
+
if (value === undefined)
|
|
60
|
+
continue;
|
|
61
|
+
const snakeKey = this.toSnakeCase(key);
|
|
62
|
+
const fullPath = prefix ? `${prefix}.${snakeKey}` : snakeKey;
|
|
63
|
+
// 1. Date / ISO String detection
|
|
64
|
+
if (value instanceof Date ||
|
|
65
|
+
(typeof value === "string" &&
|
|
66
|
+
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:/.test(value))) {
|
|
67
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
68
|
+
if (!isNaN(date.getTime())) {
|
|
69
|
+
paths.push(fullPath);
|
|
70
|
+
data[key] = { seconds: Math.floor(date.getTime() / 1000), nanos: 0 };
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// 2. Arrays (Repeated fields)
|
|
75
|
+
if (Array.isArray(value)) {
|
|
76
|
+
paths.push(fullPath);
|
|
77
|
+
// Special case for EquipmentInput pattern in your proto
|
|
78
|
+
data[key] = key === "equipment" ? { items: value } : value;
|
|
79
|
+
}
|
|
80
|
+
// 3. Nested Objects
|
|
81
|
+
else if (value !== null && typeof value === "object") {
|
|
82
|
+
const nested = this.normalizeRequest(value, fullPath);
|
|
83
|
+
data[key] = nested.data;
|
|
84
|
+
paths.push(...nested.updateMask.paths);
|
|
85
|
+
}
|
|
86
|
+
// 4. Primitives
|
|
87
|
+
else {
|
|
88
|
+
paths.push(fullPath);
|
|
89
|
+
data[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { data: data, updateMask: { paths } };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* normalizeResponse
|
|
96
|
+
* Converts a gRPC response back to a JS/TypeORM Entity format.
|
|
97
|
+
* * @param source - The gRPC message received.
|
|
98
|
+
* @param updateMask - The FieldMask for partial updates.
|
|
99
|
+
* * @example
|
|
100
|
+
* const entity = DataTransformer.normalizeResponse(grpcResponse, grpcResponse.updateMask);
|
|
101
|
+
* * // Input: { dbaName: {value: "Test"}, createdAt: {seconds: 1770890400}, equipment: {items: [1]} }
|
|
102
|
+
* // Output: { dbaName: "Test", createdAt: Date(...), equipment: [1] }
|
|
103
|
+
*/
|
|
104
|
+
static normalizeResponse(source, updateMask) {
|
|
105
|
+
if (!source)
|
|
106
|
+
return {};
|
|
107
|
+
const result = {};
|
|
108
|
+
// Use mask paths if provided, otherwise fallback to all source keys
|
|
109
|
+
const paths = updateMask?.paths ?? Object.keys(source).map(this.toSnakeCase);
|
|
110
|
+
for (const path of paths) {
|
|
111
|
+
const parts = path.split(".");
|
|
112
|
+
let currentSrc = source;
|
|
113
|
+
let currentRes = result;
|
|
114
|
+
for (let i = 0; i < parts.length; i++) {
|
|
115
|
+
const camelKey = this.toCamelCase(parts[i]);
|
|
116
|
+
if (i === parts.length - 1) {
|
|
117
|
+
let val = currentSrc?.[camelKey];
|
|
118
|
+
// Unwrap nested logic
|
|
119
|
+
if (val && typeof val === "object" && "items" in val) {
|
|
120
|
+
val = val.items; // EquipmentInput
|
|
121
|
+
}
|
|
122
|
+
else if (this.isWrapper(val)) {
|
|
123
|
+
val = val.value; // google.protobuf.Wrappers
|
|
124
|
+
}
|
|
125
|
+
else if (this.isTimestamp(val)) {
|
|
126
|
+
val = new Date(Number(val.seconds) * 1000); // Timestamp
|
|
127
|
+
}
|
|
128
|
+
currentRes[camelKey] = val ?? null;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
currentRes[camelKey] = currentRes[camelKey] || {};
|
|
132
|
+
currentRes = currentRes[camelKey];
|
|
133
|
+
currentSrc = currentSrc?.[camelKey];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
delete result.id; // Primary keys should not be updated via normalization
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.DataTransformer = DataTransformer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./data-transformer.util";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./data-transformer.util"), exports);
|