@adaptic/backend-legacy 0.0.70 → 0.0.72
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/client.cjs +1 -1
- package/config/jwtConfig.cjs +52 -0
- package/config/jwtConfig.d.ts +16 -0
- package/config/jwtConfig.d.ts.map +1 -0
- package/config/jwtConfig.js.map +1 -0
- package/config/metrics.cjs +261 -0
- package/config/metrics.d.ts +88 -0
- package/config/metrics.d.ts.map +1 -0
- package/config/metrics.js.map +1 -0
- package/config/persisted-queries.cjs +122 -0
- package/config/persisted-queries.d.ts +40 -0
- package/config/persisted-queries.d.ts.map +1 -0
- package/config/persisted-queries.js.map +1 -0
- package/config/tracing.cjs +128 -0
- package/config/tracing.d.ts +24 -0
- package/config/tracing.d.ts.map +1 -0
- package/config/tracing.js.map +1 -0
- package/middleware/audit-logger.cjs +223 -0
- package/middleware/audit-logger.d.ts +85 -0
- package/middleware/audit-logger.d.ts.map +1 -0
- package/middleware/audit-logger.js.map +1 -0
- package/middleware/auth.cjs +44 -0
- package/middleware/auth.d.ts +6 -0
- package/middleware/auth.d.ts.map +1 -0
- package/middleware/auth.js.map +1 -0
- package/middleware/graphql-validation-plugin.cjs +164 -0
- package/middleware/graphql-validation-plugin.d.ts +37 -0
- package/middleware/graphql-validation-plugin.d.ts.map +1 -0
- package/middleware/graphql-validation-plugin.js.map +1 -0
- package/middleware/index.cjs +46 -0
- package/middleware/index.d.ts +13 -0
- package/middleware/index.d.ts.map +1 -0
- package/middleware/index.js.map +1 -0
- package/middleware/input-validator.cjs +220 -0
- package/middleware/input-validator.d.ts +63 -0
- package/middleware/input-validator.d.ts.map +1 -0
- package/middleware/input-validator.js.map +1 -0
- package/middleware/query-complexity.cjs +182 -0
- package/middleware/query-complexity.d.ts +56 -0
- package/middleware/query-complexity.d.ts.map +1 -0
- package/middleware/query-complexity.js.map +1 -0
- package/middleware/rate-limiter.cjs +112 -0
- package/middleware/rate-limiter.d.ts +16 -0
- package/middleware/rate-limiter.d.ts.map +1 -0
- package/middleware/rate-limiter.js.map +1 -0
- package/middleware/soft-delete.cjs +175 -0
- package/middleware/soft-delete.d.ts +146 -0
- package/middleware/soft-delete.d.ts.map +1 -0
- package/middleware/soft-delete.js.map +1 -0
- package/middleware/types.cjs +17 -0
- package/middleware/types.d.ts +87 -0
- package/middleware/types.d.ts.map +1 -0
- package/middleware/types.js.map +1 -0
- package/middleware/validation-examples.cjs +403 -0
- package/middleware/validation-examples.d.ts +76 -0
- package/middleware/validation-examples.d.ts.map +1 -0
- package/middleware/validation-examples.js.map +1 -0
- package/package.json +5 -1
- package/utils/index.cjs +75 -0
- package/utils/index.d.ts +20 -0
- package/utils/index.d.ts.map +1 -0
- package/utils/index.js.map +1 -0
- package/utils/logger.cjs +31 -0
- package/utils/logger.d.ts +9 -0
- package/utils/logger.d.ts.map +1 -0
- package/utils/logger.js.map +1 -0
- package/validators/allocation-validator.cjs +85 -0
- package/validators/allocation-validator.d.ts +32 -0
- package/validators/allocation-validator.d.ts.map +1 -0
- package/validators/allocation-validator.js.map +1 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Soft Delete Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for soft-delete behavior on critical models.
|
|
5
|
+
* Instead of removing records from the database, a `deletedAt` timestamp
|
|
6
|
+
* is set, and query helpers filter out soft-deleted records by default.
|
|
7
|
+
*
|
|
8
|
+
* Models with soft delete support: User, BrokerageAccount, Trade, Action
|
|
9
|
+
*
|
|
10
|
+
* Usage patterns:
|
|
11
|
+
* 1. Use `softDeleteFilter()` in where clauses to exclude deleted records
|
|
12
|
+
* 2. Use `softDeleteRecord()` to soft-delete a record (set deletedAt)
|
|
13
|
+
* 3. Use `hardDelete()` for permanent administrative deletion
|
|
14
|
+
* 4. Pass `includeDeleted: true` to admin queries to see all records
|
|
15
|
+
*
|
|
16
|
+
* Note: Prisma 6 removed the $use() middleware API. Soft delete behavior
|
|
17
|
+
* is implemented via utility functions called from resolvers and services.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Models that support soft deletion via the deletedAt field.
|
|
21
|
+
* Only these models have the deletedAt column in the database.
|
|
22
|
+
*/
|
|
23
|
+
declare const SOFT_DELETE_MODELS: Set<string>;
|
|
24
|
+
/**
|
|
25
|
+
* Returns a where clause filter that excludes soft-deleted records.
|
|
26
|
+
* Can be spread into any Prisma where clause for soft-delete-aware queries.
|
|
27
|
+
*
|
|
28
|
+
* @param includeDeleted - When true, returns an empty filter (includes deleted records)
|
|
29
|
+
* @returns An object to spread into a Prisma where clause
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Exclude soft-deleted users (default)
|
|
34
|
+
* const users = await prisma.user.findMany({
|
|
35
|
+
* where: { role: 'USER', ...softDeleteFilter() },
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Include soft-deleted users (admin query)
|
|
39
|
+
* const allUsers = await prisma.user.findMany({
|
|
40
|
+
* where: { role: 'USER', ...softDeleteFilter(true) },
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function softDeleteFilter(includeDeleted?: boolean): {
|
|
45
|
+
deletedAt?: null;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Returns a where clause filter for finding only soft-deleted records.
|
|
49
|
+
* Useful for admin interfaces that need to list deleted records for restoration.
|
|
50
|
+
*
|
|
51
|
+
* @returns An object to spread into a Prisma where clause
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Find only soft-deleted users
|
|
56
|
+
* const deletedUsers = await prisma.user.findMany({
|
|
57
|
+
* where: { ...deletedOnlyFilter() },
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function deletedOnlyFilter(): {
|
|
62
|
+
deletedAt: {
|
|
63
|
+
not: null;
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Checks whether a given model supports soft deletion.
|
|
68
|
+
*
|
|
69
|
+
* @param modelName - The Prisma model name (PascalCase)
|
|
70
|
+
* @returns True if the model has a deletedAt field
|
|
71
|
+
*/
|
|
72
|
+
declare function isSoftDeleteModel(modelName: string): boolean;
|
|
73
|
+
/** Minimal Prisma delegate interface for soft-delete operations */
|
|
74
|
+
interface PrismaModelDelegate {
|
|
75
|
+
update: (args: {
|
|
76
|
+
where: {
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
data: {
|
|
80
|
+
deletedAt: Date;
|
|
81
|
+
};
|
|
82
|
+
}) => Promise<unknown>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Soft-deletes a record by setting its deletedAt timestamp.
|
|
86
|
+
* This is the recommended way to "delete" records in soft-delete-enabled models.
|
|
87
|
+
*
|
|
88
|
+
* @param delegate - The Prisma model delegate (e.g., prisma.user)
|
|
89
|
+
* @param id - The record ID to soft-delete
|
|
90
|
+
* @param modelName - The model name for logging purposes
|
|
91
|
+
* @returns The updated record
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Soft-delete a user
|
|
96
|
+
* await softDeleteRecord(prisma.user, 'user-123', 'User');
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function softDeleteRecord(delegate: PrismaModelDelegate, id: string, modelName: string): Promise<unknown>;
|
|
100
|
+
/** Minimal Prisma delegate interface for restore operations */
|
|
101
|
+
interface PrismaRestoreDelegate {
|
|
102
|
+
update: (args: {
|
|
103
|
+
where: {
|
|
104
|
+
id: string;
|
|
105
|
+
};
|
|
106
|
+
data: {
|
|
107
|
+
deletedAt: null;
|
|
108
|
+
};
|
|
109
|
+
}) => Promise<unknown>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Restores a soft-deleted record by clearing its deletedAt timestamp.
|
|
113
|
+
*
|
|
114
|
+
* @param delegate - The Prisma model delegate (e.g., prisma.user)
|
|
115
|
+
* @param id - The record ID to restore
|
|
116
|
+
* @param modelName - The model name for logging purposes
|
|
117
|
+
* @returns The updated record
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* // Restore a soft-deleted user
|
|
122
|
+
* await restoreRecord(prisma.user, 'user-123', 'User');
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
declare function restoreRecord(delegate: PrismaRestoreDelegate, id: string, modelName: string): Promise<unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* Permanently deletes a record from the database.
|
|
128
|
+
* This bypasses soft delete and removes the row entirely.
|
|
129
|
+
* Should only be used for administrative cleanup operations.
|
|
130
|
+
*
|
|
131
|
+
* @param prisma - The Prisma client instance (with $executeRawUnsafe)
|
|
132
|
+
* @param model - The model name (PascalCase)
|
|
133
|
+
* @param id - The record ID to permanently delete
|
|
134
|
+
* @returns The number of rows deleted
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Permanently delete a soft-deleted user
|
|
139
|
+
* const deleted = await hardDelete(prisma, 'User', 'user-123');
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function hardDelete(prisma: {
|
|
143
|
+
$executeRawUnsafe: (query: string, ...values: unknown[]) => Promise<number>;
|
|
144
|
+
}, model: string, id: string): Promise<number>;
|
|
145
|
+
export { SOFT_DELETE_MODELS, softDeleteFilter, deletedOnlyFilter, isSoftDeleteModel, softDeleteRecord, restoreRecord, hardDelete, };
|
|
146
|
+
//# sourceMappingURL=soft-delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"soft-delete.d.ts","sourceRoot":"","sources":["../../src/middleware/soft-delete.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;GAGG;AACH,QAAA,MAAM,kB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|
|
2
|
+
/**
|
|
3
|
+
* Type definitions for validation middleware
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidationError = isValidationError;
|
|
7
|
+
const graphql_1 = require("graphql");
|
|
8
|
+
/**
|
|
9
|
+
* Type guard to check if an error is a ValidationError
|
|
10
|
+
*/
|
|
11
|
+
function isValidationError(error) {
|
|
12
|
+
var _a;
|
|
13
|
+
return (error instanceof graphql_1.GraphQLError &&
|
|
14
|
+
((_a = error.extensions) === null || _a === void 0 ? void 0 : _a.code) === 'BAD_USER_INPUT' &&
|
|
15
|
+
'validationErrors' in (error.extensions || {}));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for validation middleware
|
|
3
|
+
*/
|
|
4
|
+
import { GraphQLError } from 'graphql';
|
|
5
|
+
import { ValidationErrorDetail } from './input-validator';
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for the validation plugin
|
|
8
|
+
*/
|
|
9
|
+
export interface ValidationPluginOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to skip validation for specific operations
|
|
12
|
+
*/
|
|
13
|
+
skipOperations?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* Custom validation rules to add to the default set
|
|
16
|
+
*/
|
|
17
|
+
customRules?: FieldValidationRule[];
|
|
18
|
+
/**
|
|
19
|
+
* Whether to log validation errors for debugging
|
|
20
|
+
*/
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Field validation rule definition
|
|
25
|
+
*/
|
|
26
|
+
export interface FieldValidationRule {
|
|
27
|
+
/**
|
|
28
|
+
* Regular expression pattern to match field names
|
|
29
|
+
*/
|
|
30
|
+
pattern: RegExp;
|
|
31
|
+
/**
|
|
32
|
+
* Validation function to apply to matching fields
|
|
33
|
+
* @param value - The field value to validate
|
|
34
|
+
* @param fieldName - The name of the field being validated
|
|
35
|
+
*/
|
|
36
|
+
validator: (value: unknown, fieldName: string) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Human-readable description of what this rule validates
|
|
39
|
+
*/
|
|
40
|
+
description: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* GraphQL operation context with validation information
|
|
44
|
+
*/
|
|
45
|
+
export interface ValidationContext {
|
|
46
|
+
/**
|
|
47
|
+
* The GraphQL operation being executed
|
|
48
|
+
*/
|
|
49
|
+
operation: {
|
|
50
|
+
operation: 'query' | 'mutation' | 'subscription';
|
|
51
|
+
name?: {
|
|
52
|
+
value: string;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The request variables
|
|
57
|
+
*/
|
|
58
|
+
request: {
|
|
59
|
+
variables?: Record<string, unknown>;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Result of a validation check
|
|
64
|
+
*/
|
|
65
|
+
export interface ValidationResult {
|
|
66
|
+
/**
|
|
67
|
+
* Whether validation passed
|
|
68
|
+
*/
|
|
69
|
+
valid: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Array of validation errors (empty if valid)
|
|
72
|
+
*/
|
|
73
|
+
errors: ValidationErrorDetail[];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Type guard to check if an error is a ValidationError
|
|
77
|
+
*/
|
|
78
|
+
export declare function isValidationError(error: unknown): error is GraphQLError;
|
|
79
|
+
/**
|
|
80
|
+
* Type-safe validator function signature
|
|
81
|
+
*/
|
|
82
|
+
export type Validator<T> = (value: T, fieldName: string) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Validation constraint types
|
|
85
|
+
*/
|
|
86
|
+
export type ValidationConstraint = 'isNumber' | 'isString' | 'range' | 'positive' | 'negative' | 'notEmpty' | 'email' | 'url' | 'minimum' | 'maximum' | 'sum' | 'comparison' | 'userLimit' | 'maxLength' | 'custom';
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/middleware/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B;;OAEG;IACH,WAAW,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAEpC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAEvD;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,EAAE;QACT,SAAS,EAAE,OAAO,GAAG,UAAU,GAAG,cAAc,CAAC;QACjD,IAAI,CAAC,EAAE;YACL,KAAK,EAAE,MAAM,CAAC;SACf,CAAC;KACH,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE;QACP,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,EAAE,qBAAqB,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAMvE;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B,UAAU,GACV,UAAU,GACV,OAAO,GACP,UAAU,GACV,UAAU,GACV,UAAU,GACV,OAAO,GACP,KAAK,GACL,SAAS,GACT,SAAS,GACT,KAAK,GACL,YAAY,GACZ,WAAW,GACX,WAAW,GACX,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/middleware/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAuFH,8CAMC;AA3FD,qCAAuC;AAkFvC;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAc;;IAC9C,OAAO,CACL,KAAK,YAAY,sBAAY;QAC7B,CAAA,MAAA,KAAK,CAAC,UAAU,0CAAE,IAAI,MAAK,gBAAgB;QAC3C,kBAAkB,IAAI,CAAC,KAAK,CAAC,UAAU,IAAI,EAAE,CAAC,CAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Example usage of validation functions in custom resolvers
|
|
4
|
+
*
|
|
5
|
+
* This file demonstrates how to use the validation utilities
|
|
6
|
+
* in custom resolver implementations.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
+
}) : function(o, v) {
|
|
22
|
+
o["default"] = v;
|
|
23
|
+
});
|
|
24
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
25
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
+
};
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
48
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
49
|
+
};
|
|
50
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
51
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.CustomValidators = exports.ValidationExamplesResolver = void 0;
|
|
55
|
+
const TypeGraphQL = __importStar(require("type-graphql"));
|
|
56
|
+
const input_validator_1 = require("./input-validator.cjs");
|
|
57
|
+
/**
|
|
58
|
+
* Example: Portfolio allocation input with validation
|
|
59
|
+
*/
|
|
60
|
+
let PortfolioAllocationInput = class PortfolioAllocationInput {
|
|
61
|
+
};
|
|
62
|
+
__decorate([
|
|
63
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
64
|
+
__metadata("design:type", Number)
|
|
65
|
+
], PortfolioAllocationInput.prototype, "equitiesPct", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
68
|
+
__metadata("design:type", Number)
|
|
69
|
+
], PortfolioAllocationInput.prototype, "optionsPct", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
72
|
+
__metadata("design:type", Number)
|
|
73
|
+
], PortfolioAllocationInput.prototype, "cryptoPct", void 0);
|
|
74
|
+
__decorate([
|
|
75
|
+
TypeGraphQL.Field(() => String),
|
|
76
|
+
__metadata("design:type", String)
|
|
77
|
+
], PortfolioAllocationInput.prototype, "portfolioName", void 0);
|
|
78
|
+
PortfolioAllocationInput = __decorate([
|
|
79
|
+
TypeGraphQL.InputType()
|
|
80
|
+
], PortfolioAllocationInput);
|
|
81
|
+
/**
|
|
82
|
+
* Example: Trade configuration input with validation
|
|
83
|
+
*/
|
|
84
|
+
let TradeConfigurationInput = class TradeConfigurationInput {
|
|
85
|
+
};
|
|
86
|
+
__decorate([
|
|
87
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
88
|
+
__metadata("design:type", Number)
|
|
89
|
+
], TradeConfigurationInput.prototype, "tradeAllocationPct", void 0);
|
|
90
|
+
__decorate([
|
|
91
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
92
|
+
__metadata("design:type", Number)
|
|
93
|
+
], TradeConfigurationInput.prototype, "minPercentageChange", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
TypeGraphQL.Field(() => TypeGraphQL.Float),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], TradeConfigurationInput.prototype, "volumeThreshold", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
TypeGraphQL.Field(() => TypeGraphQL.Int),
|
|
100
|
+
__metadata("design:type", Number)
|
|
101
|
+
], TradeConfigurationInput.prototype, "quantity", void 0);
|
|
102
|
+
TradeConfigurationInput = __decorate([
|
|
103
|
+
TypeGraphQL.InputType()
|
|
104
|
+
], TradeConfigurationInput);
|
|
105
|
+
/**
|
|
106
|
+
* Example resolver demonstrating manual validation in custom resolvers
|
|
107
|
+
*
|
|
108
|
+
* Note: With the validation plugin enabled, these validations happen
|
|
109
|
+
* automatically. This example shows how to add ADDITIONAL custom validation
|
|
110
|
+
* logic beyond the automatic pattern-based validation.
|
|
111
|
+
*/
|
|
112
|
+
let ValidationExamplesResolver = class ValidationExamplesResolver {
|
|
113
|
+
/**
|
|
114
|
+
* Example 1: Basic field validation in a mutation
|
|
115
|
+
*/
|
|
116
|
+
async updatePortfolioAllocation(input) {
|
|
117
|
+
// The validation plugin will automatically validate:
|
|
118
|
+
// - equitiesPct (0-100)
|
|
119
|
+
// - optionsPct (0-100)
|
|
120
|
+
// - cryptoPct (0-100)
|
|
121
|
+
// - portfolioName (non-empty)
|
|
122
|
+
// Add custom business logic validation
|
|
123
|
+
const totalAllocation = input.equitiesPct + input.optionsPct + input.cryptoPct;
|
|
124
|
+
if (totalAllocation !== 100) {
|
|
125
|
+
throw new input_validator_1.ValidationError('Total allocation must equal 100%', [
|
|
126
|
+
{
|
|
127
|
+
field: 'totalAllocation',
|
|
128
|
+
value: totalAllocation,
|
|
129
|
+
message: 'Sum of equitiesPct, optionsPct, and cryptoPct must equal 100',
|
|
130
|
+
constraint: 'sum',
|
|
131
|
+
},
|
|
132
|
+
]);
|
|
133
|
+
}
|
|
134
|
+
// Resolver implementation...
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Example 2: Batch validation using validateFields
|
|
139
|
+
*/
|
|
140
|
+
async updateTradeConfiguration(input) {
|
|
141
|
+
// The validation plugin handles basic validation automatically.
|
|
142
|
+
// Use validateFields for additional custom validations.
|
|
143
|
+
try {
|
|
144
|
+
(0, input_validator_1.validateFields)([
|
|
145
|
+
// Custom validation: minPercentageChange should be less than tradeAllocationPct
|
|
146
|
+
() => {
|
|
147
|
+
if (input.minPercentageChange >= input.tradeAllocationPct) {
|
|
148
|
+
throw new input_validator_1.ValidationError('Invalid configuration', [
|
|
149
|
+
{
|
|
150
|
+
field: 'minPercentageChange',
|
|
151
|
+
value: input.minPercentageChange,
|
|
152
|
+
message: 'Must be less than tradeAllocationPct',
|
|
153
|
+
constraint: 'comparison',
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// ValidationError is automatically formatted by Apollo Server
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
// Resolver implementation...
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Example 3: Conditional validation based on business logic
|
|
169
|
+
*/
|
|
170
|
+
async createTrade(quantity, isPremiumUser) {
|
|
171
|
+
// Basic validation happens automatically via plugin
|
|
172
|
+
// Add conditional validation based on user type
|
|
173
|
+
if (!isPremiumUser && quantity > 1000) {
|
|
174
|
+
throw new input_validator_1.ValidationError('Quantity limit exceeded', [
|
|
175
|
+
{
|
|
176
|
+
field: 'quantity',
|
|
177
|
+
value: quantity,
|
|
178
|
+
message: 'Non-premium users are limited to 1000 units per trade',
|
|
179
|
+
constraint: 'userLimit',
|
|
180
|
+
},
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
// Resolver implementation...
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Example 4: Validating related fields together
|
|
188
|
+
*/
|
|
189
|
+
async setTradingThresholds(minPrice, maxPrice, targetPrice) {
|
|
190
|
+
// Automatic validation ensures all are positive numbers
|
|
191
|
+
// Custom validation for related fields
|
|
192
|
+
if (minPrice >= maxPrice) {
|
|
193
|
+
throw new input_validator_1.ValidationError('Invalid price range', [
|
|
194
|
+
{
|
|
195
|
+
field: 'minPrice',
|
|
196
|
+
value: minPrice,
|
|
197
|
+
message: 'minPrice must be less than maxPrice',
|
|
198
|
+
constraint: 'range',
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
if (targetPrice < minPrice || targetPrice > maxPrice) {
|
|
203
|
+
throw new input_validator_1.ValidationError('Invalid target price', [
|
|
204
|
+
{
|
|
205
|
+
field: 'targetPrice',
|
|
206
|
+
value: targetPrice,
|
|
207
|
+
message: 'targetPrice must be between minPrice and maxPrice',
|
|
208
|
+
constraint: 'range',
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
// Resolver implementation...
|
|
213
|
+
return true;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Example 5: Using manual validation for non-standard field names
|
|
217
|
+
*/
|
|
218
|
+
async updateCustomSettings(customAllocation, customQuantity) {
|
|
219
|
+
// These field names don't match the automatic validation patterns,
|
|
220
|
+
// so we validate manually
|
|
221
|
+
(0, input_validator_1.validatePercentage)(customAllocation, 'customAllocation');
|
|
222
|
+
(0, input_validator_1.validatePositiveNumber)(customQuantity, 'customQuantity');
|
|
223
|
+
// Resolver implementation...
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Example 6: Accumulating multiple validation errors
|
|
228
|
+
*/
|
|
229
|
+
async bulkUpdateAllocations(allocations) {
|
|
230
|
+
// Validate each allocation
|
|
231
|
+
// The plugin validates each item's fields automatically
|
|
232
|
+
// Add custom cross-item validation
|
|
233
|
+
const totalItems = allocations.length;
|
|
234
|
+
if (totalItems === 0) {
|
|
235
|
+
throw new input_validator_1.ValidationError('Empty allocations array', [
|
|
236
|
+
{
|
|
237
|
+
field: 'allocations',
|
|
238
|
+
value: totalItems,
|
|
239
|
+
message: 'Must provide at least one allocation',
|
|
240
|
+
constraint: 'notEmpty',
|
|
241
|
+
},
|
|
242
|
+
]);
|
|
243
|
+
}
|
|
244
|
+
if (totalItems > 100) {
|
|
245
|
+
throw new input_validator_1.ValidationError('Too many allocations', [
|
|
246
|
+
{
|
|
247
|
+
field: 'allocations',
|
|
248
|
+
value: totalItems,
|
|
249
|
+
message: 'Maximum 100 allocations per request',
|
|
250
|
+
constraint: 'maxLength',
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
}
|
|
254
|
+
// Resolver implementation...
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
exports.ValidationExamplesResolver = ValidationExamplesResolver;
|
|
259
|
+
__decorate([
|
|
260
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
261
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
262
|
+
__metadata("design:type", Function),
|
|
263
|
+
__metadata("design:paramtypes", [PortfolioAllocationInput]),
|
|
264
|
+
__metadata("design:returntype", Promise)
|
|
265
|
+
], ValidationExamplesResolver.prototype, "updatePortfolioAllocation", null);
|
|
266
|
+
__decorate([
|
|
267
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
268
|
+
__param(0, TypeGraphQL.Arg('input')),
|
|
269
|
+
__metadata("design:type", Function),
|
|
270
|
+
__metadata("design:paramtypes", [TradeConfigurationInput]),
|
|
271
|
+
__metadata("design:returntype", Promise)
|
|
272
|
+
], ValidationExamplesResolver.prototype, "updateTradeConfiguration", null);
|
|
273
|
+
__decorate([
|
|
274
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
275
|
+
__param(0, TypeGraphQL.Arg('quantity')),
|
|
276
|
+
__param(1, TypeGraphQL.Arg('isPremiumUser')),
|
|
277
|
+
__metadata("design:type", Function),
|
|
278
|
+
__metadata("design:paramtypes", [Number, Boolean]),
|
|
279
|
+
__metadata("design:returntype", Promise)
|
|
280
|
+
], ValidationExamplesResolver.prototype, "createTrade", null);
|
|
281
|
+
__decorate([
|
|
282
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
283
|
+
__param(0, TypeGraphQL.Arg('minPrice')),
|
|
284
|
+
__param(1, TypeGraphQL.Arg('maxPrice')),
|
|
285
|
+
__param(2, TypeGraphQL.Arg('targetPrice')),
|
|
286
|
+
__metadata("design:type", Function),
|
|
287
|
+
__metadata("design:paramtypes", [Number, Number, Number]),
|
|
288
|
+
__metadata("design:returntype", Promise)
|
|
289
|
+
], ValidationExamplesResolver.prototype, "setTradingThresholds", null);
|
|
290
|
+
__decorate([
|
|
291
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
292
|
+
__param(0, TypeGraphQL.Arg('customAllocation')),
|
|
293
|
+
__param(1, TypeGraphQL.Arg('customQuantity')),
|
|
294
|
+
__metadata("design:type", Function),
|
|
295
|
+
__metadata("design:paramtypes", [Number, Number]),
|
|
296
|
+
__metadata("design:returntype", Promise)
|
|
297
|
+
], ValidationExamplesResolver.prototype, "updateCustomSettings", null);
|
|
298
|
+
__decorate([
|
|
299
|
+
TypeGraphQL.Mutation(() => Boolean),
|
|
300
|
+
__param(0, TypeGraphQL.Arg('allocations', () => [PortfolioAllocationInput])),
|
|
301
|
+
__metadata("design:type", Function),
|
|
302
|
+
__metadata("design:paramtypes", [Array]),
|
|
303
|
+
__metadata("design:returntype", Promise)
|
|
304
|
+
], ValidationExamplesResolver.prototype, "bulkUpdateAllocations", null);
|
|
305
|
+
exports.ValidationExamplesResolver = ValidationExamplesResolver = __decorate([
|
|
306
|
+
TypeGraphQL.Resolver()
|
|
307
|
+
], ValidationExamplesResolver);
|
|
308
|
+
/**
|
|
309
|
+
* Example: Reusable validation functions for complex business rules
|
|
310
|
+
*/
|
|
311
|
+
class CustomValidators {
|
|
312
|
+
/**
|
|
313
|
+
* Validates that portfolio allocations sum to 100%
|
|
314
|
+
*/
|
|
315
|
+
static validatePortfolioAllocationSum(equities, options, crypto) {
|
|
316
|
+
const total = equities + options + crypto;
|
|
317
|
+
if (Math.abs(total - 100) > 0.01) {
|
|
318
|
+
// Allow small floating point errors
|
|
319
|
+
throw new input_validator_1.ValidationError('Invalid portfolio allocation', [
|
|
320
|
+
{
|
|
321
|
+
field: 'totalAllocation',
|
|
322
|
+
value: total,
|
|
323
|
+
message: 'Total allocation must equal 100%',
|
|
324
|
+
constraint: 'sum',
|
|
325
|
+
},
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Validates that a price is within acceptable market bounds
|
|
331
|
+
*/
|
|
332
|
+
static validateMarketPrice(price, fieldName) {
|
|
333
|
+
(0, input_validator_1.validatePositiveNumber)(price, fieldName);
|
|
334
|
+
// Additional market-specific validation
|
|
335
|
+
if (price > 1000000) {
|
|
336
|
+
throw new input_validator_1.ValidationError('Price exceeds maximum', [
|
|
337
|
+
{
|
|
338
|
+
field: fieldName,
|
|
339
|
+
value: price,
|
|
340
|
+
message: 'Price cannot exceed $1,000,000',
|
|
341
|
+
constraint: 'maximum',
|
|
342
|
+
},
|
|
343
|
+
]);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Validates Greeks values are within expected ranges
|
|
348
|
+
*/
|
|
349
|
+
static validateGreeks(delta, gamma, theta, vega) {
|
|
350
|
+
(0, input_validator_1.validateFields)([
|
|
351
|
+
() => {
|
|
352
|
+
if (delta < -1 || delta > 1) {
|
|
353
|
+
throw new input_validator_1.ValidationError('Invalid delta', [
|
|
354
|
+
{
|
|
355
|
+
field: 'delta',
|
|
356
|
+
value: delta,
|
|
357
|
+
message: 'Delta must be between -1 and 1',
|
|
358
|
+
constraint: 'range',
|
|
359
|
+
},
|
|
360
|
+
]);
|
|
361
|
+
}
|
|
362
|
+
},
|
|
363
|
+
() => {
|
|
364
|
+
if (gamma < 0) {
|
|
365
|
+
throw new input_validator_1.ValidationError('Invalid gamma', [
|
|
366
|
+
{
|
|
367
|
+
field: 'gamma',
|
|
368
|
+
value: gamma,
|
|
369
|
+
message: 'Gamma must be non-negative',
|
|
370
|
+
constraint: 'minimum',
|
|
371
|
+
},
|
|
372
|
+
]);
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
() => {
|
|
376
|
+
if (theta > 0) {
|
|
377
|
+
throw new input_validator_1.ValidationError('Invalid theta', [
|
|
378
|
+
{
|
|
379
|
+
field: 'theta',
|
|
380
|
+
value: theta,
|
|
381
|
+
message: 'Theta must be negative or zero',
|
|
382
|
+
constraint: 'maximum',
|
|
383
|
+
},
|
|
384
|
+
]);
|
|
385
|
+
}
|
|
386
|
+
},
|
|
387
|
+
() => {
|
|
388
|
+
if (vega < 0) {
|
|
389
|
+
throw new input_validator_1.ValidationError('Invalid vega', [
|
|
390
|
+
{
|
|
391
|
+
field: 'vega',
|
|
392
|
+
value: vega,
|
|
393
|
+
message: 'Vega must be non-negative',
|
|
394
|
+
constraint: 'minimum',
|
|
395
|
+
},
|
|
396
|
+
]);
|
|
397
|
+
}
|
|
398
|
+
},
|
|
399
|
+
]);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
exports.CustomValidators = CustomValidators;
|
|
403
|
+
//# sourceMappingURL=validation-examples.js.map
|