@learncard/helpers 1.0.20 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/helpers.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // Generated by dts-bundle-generator v6.13.0
2
2
 
3
+ import { DataTransformer } from '@trpc/server';
4
+
3
5
  declare const JWEValidator: z.ZodObject<{
4
6
  protected: z.ZodString;
5
7
  iv: z.ZodString;
@@ -165,5 +167,9 @@ export type JWE = z.infer<typeof JWEValidator>;
165
167
  export declare const isHex: (str: string) => boolean;
166
168
  /** Determines whether or not an object is an encrypted JWE */
167
169
  export declare const isEncrypted: (item: Record<string, any>) => item is JWE;
170
+ /**
171
+ * tRPC data transformer that handles RegExp serialization/deserialization
172
+ */
173
+ export declare const RegExpTransformer: DataTransformer;
168
174
 
169
175
  export {};
@@ -3984,7 +3984,8 @@ var require_types_cjs_development = __commonJS({
3984
3984
  var BoostRecipientValidator = mod.object({
3985
3985
  to: LCNProfileValidator,
3986
3986
  from: mod.string(),
3987
- received: mod.string().optional()
3987
+ received: mod.string().optional(),
3988
+ uri: mod.string().optional()
3988
3989
  });
3989
3990
  var PaginatedBoostRecipientsValidator = PaginationResponseValidator.extend({
3990
3991
  records: BoostRecipientValidator.array()
@@ -4188,7 +4189,35 @@ var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
4188
4189
  var isEncrypted = /* @__PURE__ */ __name((item) => {
4189
4190
  return import_types.JWEValidator.safeParse(item).success;
4190
4191
  }, "isEncrypted");
4192
+ var RegExpTransformer = {
4193
+ serialize(object) {
4194
+ return JSON.stringify(object, (_key, value) => {
4195
+ if (value instanceof RegExp)
4196
+ return value.toString();
4197
+ return value;
4198
+ });
4199
+ },
4200
+ deserialize(object) {
4201
+ if (typeof object !== "string")
4202
+ return object;
4203
+ return JSON.parse(object, (_key, value) => {
4204
+ if (typeof value === "string") {
4205
+ const match = value.match(/^\/(.*)\/([gimsuy]*)$/);
4206
+ if (match) {
4207
+ try {
4208
+ return new RegExp(match[1], match[2]);
4209
+ } catch (error) {
4210
+ console.warn(`Failed to parse RegExp: ${error}`);
4211
+ return value;
4212
+ }
4213
+ }
4214
+ }
4215
+ return value;
4216
+ });
4217
+ }
4218
+ };
4191
4219
  export {
4220
+ RegExpTransformer,
4192
4221
  isEncrypted,
4193
4222
  isHex
4194
4223
  };