initial commit
This commit is contained in:
6
packages/db/shared/helpers/decimal-helpers.d.ts
vendored
Normal file
6
packages/db/shared/helpers/decimal-helpers.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import * as z from 'zod';
|
||||
import type { Prisma } from '../../generated/prisma';
|
||||
export declare const DecimalJSLikeSchema: z.ZodType<Prisma.DecimalJsLike>;
|
||||
export declare const DECIMAL_STRING_REGEX: RegExp;
|
||||
export declare const isValidDecimalInput: (v?: null | string | number | Prisma.DecimalJsLike) => v is string | number | Prisma.DecimalJsLike;
|
||||
//# sourceMappingURL=decimal-helpers.d.ts.map
|
||||
1
packages/db/shared/helpers/decimal-helpers.d.ts.map
Normal file
1
packages/db/shared/helpers/decimal-helpers.d.ts.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"decimal-helpers.d.ts","sourceRoot":"","sources":["decimal-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAOrD,eAAO,MAAM,mBAAmB,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAM9D,CAAC;AAGH,eAAO,MAAM,oBAAoB,QAAuE,CAAC;AAEzG,eAAO,MAAM,mBAAmB,GAC9B,IAAI,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,aAAa,KAChD,CAAC,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,aAiBhC,CAAC"}
|
||||
71
packages/db/shared/helpers/decimal-helpers.js
Normal file
71
packages/db/shared/helpers/decimal-helpers.js
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.isValidDecimalInput = exports.DECIMAL_STRING_REGEX = exports.DecimalJSLikeSchema = void 0;
|
||||
const z = __importStar(require("zod"));
|
||||
const decimal_js_1 = __importDefault(require("decimal.js"));
|
||||
// DECIMAL HELPERS
|
||||
//------------------------------------------------------
|
||||
exports.DecimalJSLikeSchema = z.object({
|
||||
d: z.array(z.number()),
|
||||
e: z.number(),
|
||||
s: z.number(),
|
||||
// Zod v3/v4 compatible callable check
|
||||
toFixed: z.custom((v) => typeof v === 'function'),
|
||||
});
|
||||
// Accept canonical decimal strings (+/-, optional fraction, optional exponent), or Infinity/NaN.
|
||||
exports.DECIMAL_STRING_REGEX = /^(?:[+-]?(?:[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?|Infinity)|NaN)$/;
|
||||
const isValidDecimalInput = (v) => {
|
||||
if (v === undefined || v === null)
|
||||
return false;
|
||||
return (
|
||||
// Explicit instance checks first
|
||||
v instanceof decimal_js_1.default ||
|
||||
// If Decimal.js is present and imported by the generator, this symbol exists at runtime
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - Decimal may be undefined when not installed; codegen controls the import
|
||||
(typeof decimal_js_1.default !== 'undefined' && v instanceof decimal_js_1.default) ||
|
||||
(typeof v === 'object' &&
|
||||
'd' in v &&
|
||||
'e' in v &&
|
||||
's' in v &&
|
||||
'toFixed' in v) ||
|
||||
(typeof v === 'string' && exports.DECIMAL_STRING_REGEX.test(v)) ||
|
||||
typeof v === 'number');
|
||||
};
|
||||
exports.isValidDecimalInput = isValidDecimalInput;
|
||||
40
packages/db/shared/helpers/decimal-helpers.ts
Executable file
40
packages/db/shared/helpers/decimal-helpers.ts
Executable file
@@ -0,0 +1,40 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
import type { Prisma } from '../../generated/prisma';
|
||||
|
||||
import Decimal from "decimal.js";
|
||||
|
||||
// DECIMAL HELPERS
|
||||
//------------------------------------------------------
|
||||
|
||||
export const DecimalJSLikeSchema: z.ZodType<Prisma.DecimalJsLike> = z.object({
|
||||
d: z.array(z.number()),
|
||||
e: z.number(),
|
||||
s: z.number(),
|
||||
// Zod v3/v4 compatible callable check
|
||||
toFixed: z.custom<Prisma.DecimalJsLike['toFixed']>((v) => typeof v === 'function'),
|
||||
});
|
||||
|
||||
// Accept canonical decimal strings (+/-, optional fraction, optional exponent), or Infinity/NaN.
|
||||
export const DECIMAL_STRING_REGEX = /^(?:[+-]?(?:[0-9]+(?:.[0-9]+)?(?:[eE][+-]?[0-9]+)?|Infinity)|NaN)$/;
|
||||
|
||||
export const isValidDecimalInput = (
|
||||
v?: null | string | number | Prisma.DecimalJsLike,
|
||||
): v is string | number | Prisma.DecimalJsLike => {
|
||||
if (v === undefined || v === null) return false;
|
||||
return (
|
||||
// Explicit instance checks first
|
||||
v instanceof Decimal ||
|
||||
// If Decimal.js is present and imported by the generator, this symbol exists at runtime
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - Decimal may be undefined when not installed; codegen controls the import
|
||||
(typeof Decimal !== 'undefined' && v instanceof Decimal) ||
|
||||
(typeof v === 'object' &&
|
||||
'd' in v &&
|
||||
'e' in v &&
|
||||
's' in v &&
|
||||
'toFixed' in v) ||
|
||||
(typeof v === 'string' && DECIMAL_STRING_REGEX.test(v)) ||
|
||||
typeof v === 'number'
|
||||
);
|
||||
};
|
||||
16
packages/db/shared/helpers/json-helpers.d.ts
vendored
Normal file
16
packages/db/shared/helpers/json-helpers.d.ts
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as z from 'zod';
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
export type JsonValue = JsonPrimitive | JsonValue[] | {
|
||||
[k: string]: JsonValue;
|
||||
};
|
||||
export type InputJsonValue = JsonPrimitive | InputJsonValue[] | {
|
||||
[k: string]: InputJsonValue | null;
|
||||
};
|
||||
export type NullableJsonInput = JsonValue | 'JsonNull' | 'DbNull' | null;
|
||||
export declare const transformJsonNull: (v?: NullableJsonInput) => JsonValue;
|
||||
export declare const JsonValueSchema: z.ZodType<JsonValue>;
|
||||
export declare const InputJsonValueSchema: z.ZodType<InputJsonValue>;
|
||||
export declare const NullableJsonValue: z.ZodEffects<z.ZodUnion<[z.ZodType<JsonValue, z.ZodTypeDef, JsonValue>, z.ZodLiteral<"DbNull">, z.ZodLiteral<"JsonNull">, z.ZodLiteral<null>]>, string | number | boolean | JsonValue[] | {
|
||||
[k: string]: JsonValue;
|
||||
} | null, JsonValue>;
|
||||
//# sourceMappingURL=json-helpers.d.ts.map
|
||||
1
packages/db/shared/helpers/json-helpers.d.ts.map
Normal file
1
packages/db/shared/helpers/json-helpers.d.ts.map
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"json-helpers.d.ts","sourceRoot":"","sources":["json-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAEzB,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAC7D,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,SAAS,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AACjF,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,cAAc,EAAE,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAAA;CAAE,CAAC;AACvG,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,IAAI,CAAC;AACzE,eAAO,MAAM,iBAAiB,GAAI,IAAI,iBAAiB,cAItD,CAAC;AACF,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAMxB,CAAC;AAC1B,eAAO,MAAM,oBAAoB,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAM7B,CAAC;AAC/B,eAAO,MAAM,iBAAiB;;oBAEgC,CAAC"}
|
||||
58
packages/db/shared/helpers/json-helpers.js
Normal file
58
packages/db/shared/helpers/json-helpers.js
Normal file
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NullableJsonValue = exports.InputJsonValueSchema = exports.JsonValueSchema = exports.transformJsonNull = void 0;
|
||||
const z = __importStar(require("zod"));
|
||||
const transformJsonNull = (v) => {
|
||||
if (v == null || v === 'DbNull')
|
||||
return null;
|
||||
if (v === 'JsonNull')
|
||||
return null;
|
||||
return v;
|
||||
};
|
||||
exports.transformJsonNull = transformJsonNull;
|
||||
exports.JsonValueSchema = z.lazy(() => z.union([
|
||||
z.string(), z.number(), z.boolean(), z.literal(null),
|
||||
z.record(z.string(), z.lazy(() => exports.JsonValueSchema.optional())),
|
||||
z.array(z.lazy(() => exports.JsonValueSchema)),
|
||||
]));
|
||||
exports.InputJsonValueSchema = z.lazy(() => z.union([
|
||||
z.string(), z.number(), z.boolean(),
|
||||
z.record(z.string(), z.lazy(() => z.union([exports.InputJsonValueSchema, z.literal(null)]))),
|
||||
z.array(z.lazy(() => z.union([exports.InputJsonValueSchema, z.literal(null)]))),
|
||||
]));
|
||||
exports.NullableJsonValue = z
|
||||
.union([exports.JsonValueSchema, z.literal('DbNull'), z.literal('JsonNull'), z.literal(null)])
|
||||
.transform((v) => (0, exports.transformJsonNull)(v));
|
||||
28
packages/db/shared/helpers/json-helpers.ts
Executable file
28
packages/db/shared/helpers/json-helpers.ts
Executable file
@@ -0,0 +1,28 @@
|
||||
import * as z from 'zod';
|
||||
|
||||
export type JsonPrimitive = string | number | boolean | null;
|
||||
export type JsonValue = JsonPrimitive | JsonValue[] | { [k: string]: JsonValue };
|
||||
export type InputJsonValue = JsonPrimitive | InputJsonValue[] | { [k: string]: InputJsonValue | null };
|
||||
export type NullableJsonInput = JsonValue | 'JsonNull' | 'DbNull' | null;
|
||||
export const transformJsonNull = (v?: NullableJsonInput) => {
|
||||
if (v == null || v === 'DbNull') return null;
|
||||
if (v === 'JsonNull') return null;
|
||||
return v as JsonValue;
|
||||
};
|
||||
export const JsonValueSchema: z.ZodType<JsonValue> = z.lazy(() =>
|
||||
z.union([
|
||||
z.string(), z.number(), z.boolean(), z.literal(null),
|
||||
z.record(z.string(), z.lazy(() => JsonValueSchema.optional())),
|
||||
z.array(z.lazy(() => JsonValueSchema)),
|
||||
])
|
||||
) as z.ZodType<JsonValue>;
|
||||
export const InputJsonValueSchema: z.ZodType<InputJsonValue> = z.lazy(() =>
|
||||
z.union([
|
||||
z.string(), z.number(), z.boolean(),
|
||||
z.record(z.string(), z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
|
||||
z.array(z.lazy(() => z.union([InputJsonValueSchema, z.literal(null)]))),
|
||||
])
|
||||
) as z.ZodType<InputJsonValue>;
|
||||
export const NullableJsonValue = z
|
||||
.union([JsonValueSchema, z.literal('DbNull'), z.literal('JsonNull'), z.literal(null)])
|
||||
.transform((v) => transformJsonNull(v as NullableJsonInput));
|
||||
Reference in New Issue
Block a user