@learncard/helpers 1.0.19 → 1.1.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/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 {};
@@ -100,6 +100,7 @@ var require_types_cjs_development = __commonJS({
100
100
  LCNNotificationTypeEnumValidator: () => LCNNotificationTypeEnumValidator,
101
101
  LCNNotificationValidator: () => LCNNotificationValidator,
102
102
  LCNProfileConnectionStatusEnum: () => LCNProfileConnectionStatusEnum,
103
+ LCNProfileQueryValidator: () => LCNProfileQueryValidator,
103
104
  LCNProfileValidator: () => LCNProfileValidator,
104
105
  LCNSigningAuthorityForUserValidator: () => LCNSigningAuthorityForUserValidator,
105
106
  LCNSigningAuthorityValidator: () => LCNSigningAuthorityValidator,
@@ -125,7 +126,6 @@ var require_types_cjs_development = __commonJS({
125
126
  RubricCriterionValidator: () => RubricCriterionValidator,
126
127
  SentCredentialInfoValidator: () => SentCredentialInfoValidator,
127
128
  ServiceValidator: () => ServiceValidator,
128
- StringQuery: () => StringQuery,
129
129
  UnsignedAchievementCredentialValidator: () => UnsignedAchievementCredentialValidator,
130
130
  UnsignedVCValidator: () => UnsignedVCValidator,
131
131
  UnsignedVPValidator: () => UnsignedVPValidator,
@@ -3876,6 +3876,35 @@ var require_types_cjs_development = __commonJS({
3876
3876
  var PaginatedEncryptedCredentialRecordsValidator = PaginationResponseValidator.extend({
3877
3877
  records: EncryptedCredentialRecordValidator.array()
3878
3878
  });
3879
+ var parseRegexString = /* @__PURE__ */ __name2((regexStr) => {
3880
+ const match = regexStr.match(/^\/(.*)\/([gimsuy]*)$/);
3881
+ if (!match)
3882
+ throw new Error("Invalid RegExp string format");
3883
+ return { pattern: match[1], flags: match[2] };
3884
+ }, "parseRegexString");
3885
+ var RegExpValidator = mod.instanceof(RegExp).or(
3886
+ mod.string().refine(
3887
+ (str) => {
3888
+ try {
3889
+ parseRegexString(str);
3890
+ return true;
3891
+ } catch (e) {
3892
+ return false;
3893
+ }
3894
+ },
3895
+ {
3896
+ message: "Invalid RegExp string format. Must be in format '/pattern/flags'"
3897
+ }
3898
+ ).transform((str) => {
3899
+ const { pattern, flags } = parseRegexString(str);
3900
+ try {
3901
+ return new RegExp(pattern, flags);
3902
+ } catch (error) {
3903
+ throw new Error(`Invalid RegExp: ${error.message}`);
3904
+ }
3905
+ })
3906
+ );
3907
+ var StringQuery = mod.string().or(mod.object({ $in: mod.string().array() })).or(mod.object({ $regex: RegExpValidator }));
3879
3908
  var LCNProfileValidator = mod.object({
3880
3909
  profileId: mod.string().min(3).max(40),
3881
3910
  displayName: mod.string().default(""),
@@ -3890,6 +3919,16 @@ var require_types_cjs_development = __commonJS({
3890
3919
  type: mod.string().optional(),
3891
3920
  notificationsWebhook: mod.string().url().startsWith("http").optional()
3892
3921
  });
3922
+ var LCNProfileQueryValidator = mod.object({
3923
+ profileId: StringQuery,
3924
+ displayName: StringQuery,
3925
+ shortBio: StringQuery,
3926
+ bio: StringQuery,
3927
+ email: StringQuery,
3928
+ websiteLink: StringQuery,
3929
+ isServiceProfile: mod.boolean(),
3930
+ type: StringQuery
3931
+ }).partial();
3893
3932
  var PaginatedLCNProfilesValidator = PaginationResponseValidator.extend({
3894
3933
  records: LCNProfileValidator.array()
3895
3934
  });
@@ -3930,7 +3969,6 @@ var require_types_cjs_development = __commonJS({
3930
3969
  meta: mod.record(mod.any()).optional(),
3931
3970
  claimPermissions: BoostPermissionsValidator.optional()
3932
3971
  });
3933
- var StringQuery = mod.string().or(mod.object({ $in: mod.string().array() })).or(mod.object({ $regex: mod.instanceof(RegExp) }));
3934
3972
  var BoostQueryValidator = mod.object({
3935
3973
  uri: StringQuery,
3936
3974
  name: StringQuery,
@@ -3946,7 +3984,8 @@ var require_types_cjs_development = __commonJS({
3946
3984
  var BoostRecipientValidator = mod.object({
3947
3985
  to: LCNProfileValidator,
3948
3986
  from: mod.string(),
3949
- received: mod.string().optional()
3987
+ received: mod.string().optional(),
3988
+ uri: mod.string().optional()
3950
3989
  });
3951
3990
  var PaginatedBoostRecipientsValidator = PaginationResponseValidator.extend({
3952
3991
  records: BoostRecipientValidator.array()
@@ -4150,7 +4189,35 @@ var isHex = /* @__PURE__ */ __name((str) => /^[0-9a-f]+$/i.test(str), "isHex");
4150
4189
  var isEncrypted = /* @__PURE__ */ __name((item) => {
4151
4190
  return import_types.JWEValidator.safeParse(item).success;
4152
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
+ };
4153
4219
  export {
4220
+ RegExpTransformer,
4154
4221
  isEncrypted,
4155
4222
  isHex
4156
4223
  };