@getcommunity/gc-validators 0.0.271-alpha.25 → 0.0.271-alpha.27
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/base/index.cjs +9 -27
- package/dist/base/index.d.cts +2 -2
- package/dist/base/index.d.mts +4 -4
- package/dist/base/index.mjs +5 -5
- package/dist/components/blocks/index.cjs +5 -4
- package/dist/components/blocks/index.d.cts +1 -1
- package/dist/components/blocks/index.d.mts +1 -1
- package/dist/components/blocks/index.mjs +5 -4
- package/dist/components/brand/index.cjs +3 -2
- package/dist/components/brand/index.d.cts +1 -1
- package/dist/components/brand/index.d.mts +1 -1
- package/dist/components/brand/index.mjs +3 -2
- package/dist/components/forms/index.cjs +2 -1
- package/dist/components/forms/index.d.cts +280 -280
- package/dist/components/forms/index.d.mts +280 -280
- package/dist/components/forms/index.mjs +2 -1
- package/dist/components/shared/index.cjs +5 -4
- package/dist/components/shared/index.d.cts +1 -1
- package/dist/components/shared/index.d.mts +1 -1
- package/dist/components/shared/index.mjs +5 -4
- package/dist/components/slideshow/index.d.cts +280 -280
- package/dist/components/slideshow/index.d.mts +280 -280
- package/dist/components/utm/index.d.mts +1 -1
- package/dist/constants/index.cjs +45 -43
- package/dist/constants/index.mjs +4 -2
- package/dist/{document-TlMeVEGy.d.cts → document-3h6g5Qqr.d.cts} +1 -1
- package/dist/{document-DjM6F56Q.cjs → document-AqtoEbX8.cjs} +19 -24
- package/dist/{document-aEa-gTmH.mjs → document-BCbxKqGE.mjs} +20 -19
- package/dist/{document-kvIqz0p6.mjs → document-BWso8VC7.mjs} +62 -56
- package/dist/{document-CwIvc2p7.cjs → document-DJJFS5o8.cjs} +2 -1
- package/dist/{document-CDavjuJ-.mjs → document-DRyRy2Mw.mjs} +2 -1
- package/dist/{document-CAkRm1Y_.d.mts → document-DqE9ISOk.d.mts} +2 -2
- package/dist/{document-DOVZwQRq.cjs → document-DwkycUz9.cjs} +74 -62
- package/dist/email-ByTEdUjg.cjs +13 -0
- package/dist/email-Cnyi5Neo.mjs +6 -0
- package/dist/entities/audit-log/index.cjs +44 -41
- package/dist/entities/audit-log/index.d.cts +3 -2
- package/dist/entities/audit-log/index.d.mts +4 -3
- package/dist/entities/audit-log/index.mjs +6 -3
- package/dist/entities/blog-page/index.d.cts +1 -1
- package/dist/entities/blog-page/index.d.mts +1 -1
- package/dist/entities/blog-post/index.cjs +10 -9
- package/dist/entities/blog-post/index.d.cts +1 -1
- package/dist/entities/blog-post/index.d.mts +1 -1
- package/dist/entities/blog-post/index.mjs +4 -3
- package/dist/entities/careers-page/index.d.cts +1 -1
- package/dist/entities/careers-page/index.d.mts +1 -1
- package/dist/entities/category/index.cjs +15 -13
- package/dist/entities/category/index.d.cts +7 -6
- package/dist/entities/category/index.d.mts +7 -6
- package/dist/entities/category/index.mjs +11 -9
- package/dist/entities/client/index.cjs +23 -22
- package/dist/entities/client/index.d.cts +1 -1
- package/dist/entities/client/index.d.mts +1 -1
- package/dist/entities/client/index.mjs +16 -15
- package/dist/entities/client-content-pillar/index.cjs +14 -13
- package/dist/entities/client-content-pillar/index.d.cts +1 -1
- package/dist/entities/client-content-pillar/index.d.mts +1 -1
- package/dist/entities/client-content-pillar/index.mjs +12 -11
- package/dist/entities/client-media-platform/index.cjs +18 -16
- package/dist/entities/client-media-platform/index.d.cts +1 -1
- package/dist/entities/client-media-platform/index.d.mts +1 -1
- package/dist/entities/client-media-platform/index.mjs +13 -11
- package/dist/entities/client-project/index.cjs +47 -41
- package/dist/entities/client-project/index.d.cts +1 -1
- package/dist/entities/client-project/index.d.mts +1 -1
- package/dist/entities/client-project/index.mjs +11 -5
- package/dist/entities/client-report/index.cjs +18 -16
- package/dist/entities/client-report/index.d.cts +1 -1
- package/dist/entities/client-report/index.d.mts +1 -1
- package/dist/entities/client-report/index.mjs +14 -12
- package/dist/entities/client-styleguide/index.cjs +14 -13
- package/dist/entities/client-styleguide/index.d.cts +1 -1
- package/dist/entities/client-styleguide/index.d.mts +1 -1
- package/dist/entities/client-styleguide/index.mjs +11 -10
- package/dist/entities/client-user/index.cjs +7 -7
- package/dist/entities/client-user/index.d.cts +1 -1
- package/dist/entities/client-user/index.d.mts +1 -1
- package/dist/entities/client-user/index.mjs +5 -5
- package/dist/entities/comment/index.cjs +18 -16
- package/dist/entities/comment/index.d.cts +1 -1
- package/dist/entities/comment/index.d.mts +1 -1
- package/dist/entities/comment/index.mjs +12 -10
- package/dist/entities/content-pillar/index.cjs +20 -18
- package/dist/entities/content-pillar/index.d.cts +1 -1
- package/dist/entities/content-pillar/index.d.mts +1 -1
- package/dist/entities/content-pillar/index.mjs +15 -13
- package/dist/entities/faq-page/index.cjs +2 -1
- package/dist/entities/faq-page/index.d.cts +2 -2
- package/dist/entities/faq-page/index.d.mts +3 -3
- package/dist/entities/faq-page/index.mjs +2 -1
- package/dist/entities/formatter/index.d.cts +5 -5
- package/dist/entities/formatter/index.d.mts +5 -5
- package/dist/entities/gcflytour/index.cjs +21 -19
- package/dist/entities/gcflytour/index.d.cts +1 -1
- package/dist/entities/gcflytour/index.d.mts +1 -1
- package/dist/entities/gcflytour/index.mjs +17 -15
- package/dist/entities/gcflytour-snap/index.cjs +20 -18
- package/dist/entities/gcflytour-snap/index.d.cts +1 -1
- package/dist/entities/gcflytour-snap/index.d.mts +1 -1
- package/dist/entities/gcflytour-snap/index.mjs +16 -14
- package/dist/entities/landing-page/index.d.cts +2 -2
- package/dist/entities/landing-page/index.d.mts +3 -3
- package/dist/entities/lead/index.cjs +25 -23
- package/dist/entities/lead/index.mjs +15 -13
- package/dist/entities/media-content-type/index.cjs +21 -19
- package/dist/entities/media-content-type/index.d.cts +7 -6
- package/dist/entities/media-content-type/index.d.mts +7 -6
- package/dist/entities/media-content-type/index.mjs +17 -15
- package/dist/entities/media-creative-format/index.cjs +19 -17
- package/dist/entities/media-creative-format/index.d.cts +7 -6
- package/dist/entities/media-creative-format/index.d.mts +7 -6
- package/dist/entities/media-creative-format/index.mjs +15 -13
- package/dist/entities/media-medium/index.cjs +19 -17
- package/dist/entities/media-medium/index.d.cts +7 -6
- package/dist/entities/media-medium/index.d.mts +7 -6
- package/dist/entities/media-medium/index.mjs +15 -13
- package/dist/entities/media-platform/index.cjs +27 -24
- package/dist/entities/media-platform/index.d.cts +1 -1
- package/dist/entities/media-platform/index.d.mts +1 -1
- package/dist/entities/media-platform/index.mjs +23 -20
- package/dist/entities/monday-workspace/index.cjs +17 -15
- package/dist/entities/monday-workspace/index.d.cts +1 -1
- package/dist/entities/monday-workspace/index.d.mts +1 -1
- package/dist/entities/monday-workspace/index.mjs +11 -9
- package/dist/entities/newsletter-signup/index.cjs +25 -23
- package/dist/entities/newsletter-signup/index.mjs +13 -11
- package/dist/entities/policy-page/index.cjs +2 -1
- package/dist/entities/policy-page/index.d.cts +1 -1
- package/dist/entities/policy-page/index.d.mts +2 -2
- package/dist/entities/policy-page/index.mjs +2 -1
- package/dist/entities/product/index.cjs +1 -1
- package/dist/entities/product/index.d.cts +1 -1
- package/dist/entities/product/index.d.mts +1 -1
- package/dist/entities/product/index.mjs +1 -1
- package/dist/entities/product-highlight/index.cjs +1 -1
- package/dist/entities/product-highlight/index.d.cts +1 -1
- package/dist/entities/product-highlight/index.d.mts +1 -1
- package/dist/entities/product-highlight/index.mjs +1 -1
- package/dist/entities/resume/index.cjs +43 -40
- package/dist/entities/resume/index.mjs +16 -13
- package/dist/entities/sharpspring/index.cjs +9 -8
- package/dist/entities/sharpspring/index.mjs +6 -5
- package/dist/entities/tag/index.cjs +15 -13
- package/dist/entities/tag/index.d.cts +6 -5
- package/dist/entities/tag/index.d.mts +7 -6
- package/dist/entities/tag/index.mjs +11 -9
- package/dist/entities/team-member/index.cjs +11 -9
- package/dist/entities/team-member/index.d.cts +2 -2
- package/dist/entities/team-member/index.d.mts +2 -2
- package/dist/entities/team-member/index.mjs +7 -4
- package/dist/entities/team-page/index.d.cts +1 -1
- package/dist/entities/team-page/index.d.mts +1 -1
- package/dist/entities/teamwork/index.cjs +12 -11
- package/dist/entities/teamwork/index.d.mts +1 -1
- package/dist/entities/teamwork/index.mjs +7 -6
- package/dist/entities/trend/index.cjs +2 -2
- package/dist/entities/trend/index.d.cts +1 -1
- package/dist/entities/trend/index.d.mts +1 -1
- package/dist/entities/trend/index.mjs +2 -2
- package/dist/entities/up-auth/index.cjs +18 -15
- package/dist/entities/up-auth/index.d.cts +1 -1
- package/dist/entities/up-auth/index.d.mts +1 -1
- package/dist/entities/up-auth/index.mjs +6 -3
- package/dist/entities/up-permission/index.cjs +1 -1
- package/dist/entities/up-permission/index.d.cts +1 -1
- package/dist/entities/up-permission/index.d.mts +1 -1
- package/dist/entities/up-permission/index.mjs +1 -1
- package/dist/entities/up-role/index.cjs +1 -1
- package/dist/entities/up-role/index.d.cts +1 -1
- package/dist/entities/up-role/index.d.mts +1 -1
- package/dist/entities/up-role/index.mjs +1 -1
- package/dist/entities/up-user/index.cjs +2 -1
- package/dist/entities/up-user/index.d.cts +2 -2
- package/dist/entities/up-user/index.d.mts +2 -2
- package/dist/entities/up-user/index.mjs +2 -2
- package/dist/entities/upload/index.cjs +11 -11
- package/dist/entities/upload/index.mjs +7 -7
- package/dist/entities/url-redirect/index.cjs +5 -4
- package/dist/entities/url-redirect/index.d.cts +3 -2
- package/dist/entities/url-redirect/index.d.mts +3 -2
- package/dist/entities/url-redirect/index.mjs +4 -3
- package/dist/entities/user-account/index.cjs +10 -11
- package/dist/entities/user-account/index.d.cts +2 -2
- package/dist/entities/user-account/index.d.mts +2 -2
- package/dist/entities/user-account/index.mjs +10 -11
- package/dist/entities/utm-link-builder/index.cjs +30 -36
- package/dist/entities/utm-link-builder/index.d.cts +6 -6
- package/dist/entities/utm-link-builder/index.d.mts +6 -6
- package/dist/entities/utm-link-builder/index.mjs +22 -28
- package/dist/entities/utm-tracking-link/index.cjs +110 -104
- package/dist/entities/utm-tracking-link/index.d.cts +2 -2
- package/dist/entities/utm-tracking-link/index.d.mts +2 -2
- package/dist/entities/utm-tracking-link/index.mjs +68 -68
- package/dist/error-messages-9ZhRqNGW.mjs +10 -0
- package/dist/error-messages-C0I1kOur.cjs +51 -0
- package/dist/generators/index.cjs +231 -0
- package/dist/generators/index.d.cts +19 -0
- package/dist/generators/index.d.mts +19 -0
- package/dist/generators/index.mjs +226 -0
- package/dist/index-BOxQLeAK.d.cts +317 -0
- package/dist/index-BSYaAtme.d.mts +486 -0
- package/dist/index-BT8Pa9XY.d.mts +317 -0
- package/dist/{index-DXo7B4ng.d.mts → index-Bjjp-2Sa.d.mts} +20 -99
- package/dist/{index-DXUuI-fJ.d.cts → index-C1GoH-4v.d.cts} +91 -76
- package/dist/{index-D_YPjLxv.d.cts → index-CBW5QmNu.d.cts} +4 -3
- package/dist/index-COpLbpQC.d.cts +486 -0
- package/dist/{index-DEm89ERm.d.mts → index-ClQOYhKi.d.mts} +94 -79
- package/dist/index-Cqmmzi2g.d.mts +944 -0
- package/dist/{index-B_L_83Q2.d.cts → index-D7QXaSOY.d.cts} +19 -98
- package/dist/index-DG_Lwaa7.d.cts +1324 -0
- package/dist/{index-D3KnOYr7.d.mts → index-DKFW5ay8.d.mts} +4 -3
- package/dist/index-Dvu63a8_.d.mts +1324 -0
- package/dist/index-WN2TBKki.d.cts +944 -0
- package/dist/limits-CKGuEuKA.mjs +37 -0
- package/dist/{regex-Cl5goNwp.cjs → limits-CW6iJ7kB.cjs} +0 -102
- package/dist/number-Bt4nZKCU.cjs +19 -0
- package/dist/number-OMFRufFt.mjs +6 -0
- package/dist/pagination-D5l_UjyM.mjs +7 -0
- package/dist/pagination-DWZDPzR4.cjs +20 -0
- package/dist/permissions/index.cjs +2 -2
- package/dist/permissions/index.d.cts +1 -1
- package/dist/permissions/index.d.mts +1 -1
- package/dist/permissions/index.mjs +2 -2
- package/dist/phone-C9TNVDm_.mjs +8 -0
- package/dist/phone-D_ZLG1Qv.cjs +21 -0
- package/dist/{query-DHY-nlUQ.mjs → query-BR5Ze6T2.mjs} +7 -11
- package/dist/{query-DelNcssC.cjs → query-qQ_HLlxx.cjs} +13 -29
- package/dist/regex-BEFTMiHO.cjs +51 -0
- package/dist/regex-pSdcbWzV.mjs +10 -0
- package/dist/relation-Bd-xUcj8.cjs +33 -0
- package/dist/relation-DMhLjp7K.mjs +8 -0
- package/dist/{relationships-HTBNe0F-.cjs → relationships-DjHwYd4r.cjs} +23 -9
- package/dist/{relationships-C6xfgdwR.mjs → relationships-yPO5SILR.mjs} +7 -5
- package/dist/slug-BUtm1t-B.mjs +7 -0
- package/dist/slug-cWXTZEIT.cjs +14 -0
- package/dist/sort-CI87SH1y.cjs +33 -0
- package/dist/sort-D3WwshqQ.mjs +14 -0
- package/dist/{strapi-DvyAfgFF.mjs → strapi-B2cNPAao.mjs} +1 -1
- package/dist/{strapi-QFDWi4vD.cjs → strapi-RlhF30B7.cjs} +1 -1
- package/dist/string-BHHnD2Qu.mjs +42 -0
- package/dist/string-Yn-6xiAZ.cjs +97 -0
- package/dist/urls-UOvhCu0z.mjs +14 -0
- package/dist/urls-og5upHgL.cjs +27 -0
- package/dist/utilities/index.cjs +1 -1
- package/dist/utilities/index.d.cts +6 -6
- package/dist/utilities/index.d.mts +6 -6
- package/dist/utilities/index.mjs +1 -1
- package/dist/utm-BqkYlpua.cjs +47 -0
- package/dist/utm-ZUwmBoR2.mjs +28 -0
- package/dist/validators/index.cjs +36 -0
- package/dist/validators/index.d.cts +94 -0
- package/dist/validators/index.d.mts +94 -0
- package/dist/validators/index.mjs +10 -0
- package/package.json +29 -2
- package/dist/index-B3VtiObV.d.mts +0 -317
- package/dist/index-BxEBUjx2.d.mts +0 -486
- package/dist/index-CQP_vcmO.d.cts +0 -317
- package/dist/index-CRoWUxGV.d.cts +0 -1324
- package/dist/index-DYSlcIkJ.d.mts +0 -945
- package/dist/index-Dmtom8iC.d.cts +0 -945
- package/dist/index-auU0DaW5.d.cts +0 -486
- package/dist/index-oCLNrzIj.d.mts +0 -1324
- package/dist/regex-BnKGcdS4.mjs +0 -55
- package/dist/validators-Bc9Is5Sr.cjs +0 -222
- package/dist/validators-P5E_3qzc.mjs +0 -95
- /package/dist/{abac-DPd9oLKR.mjs → abac-BPxkvVVy.mjs} +0 -0
- /package/dist/{abac-BeKQtxIF.cjs → abac-YYI2Ckwv.cjs} +0 -0
- /package/dist/{constants-Htf-MeCA.mjs → constants-C4cy6LoY.mjs} +0 -0
- /package/dist/{constants-f1GP2eiq.cjs → constants-D6DsS_A0.cjs} +0 -0
- /package/dist/{document-DaICHS9G.cjs → document-B4FY2KXQ.cjs} +0 -0
- /package/dist/{document-c3GNPelp.mjs → document-De-prPhc.mjs} +0 -0
- /package/dist/{document-CbE38CzE.d.mts → document-DxjJgk8X.d.mts} +0 -0
- /package/dist/{index-DLICmJ_-.d.mts → index-BSEaV9wd.d.mts} +0 -0
- /package/dist/{json-BrVkpLbC.d.mts → json--oetJLQY.d.mts} +0 -0
- /package/dist/{media-upload-DKeA1eD-.d.mts → media-upload-DBG7YyU4.d.mts} +0 -0
- /package/dist/{strapi-BDLWeEyv.mjs → strapi-CE9bz7Kc.mjs} +0 -0
- /package/dist/{strapi-C4HuWGb_.cjs → strapi-D8C1C0D7.cjs} +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
//#region src/constants/error-messages.ts
|
|
2
|
+
const ERROR_MESSAGE_ROBOT = "It appears you are a robot, please try again.";
|
|
3
|
+
const ERROR_MESSAGE_COMMA_SEPPARATED_URLS = `Please enter a list of URLs separated by commas.`;
|
|
4
|
+
const ERROR_MESSAGE_INVALID_URL = `Please enter a valid URL.`;
|
|
5
|
+
const ERROR_MESSAGE_UTM_URL = `Please enter a valid URL with UTM parameters.`;
|
|
6
|
+
const ERROR_MESSAGE_URL_NO_QUERY_PARAMS = `Please remove any query parameters from the URL.`;
|
|
7
|
+
const ERROR_MESSAGE_ONE_PROJECT_STATUS = `You can only select one project status.`;
|
|
8
|
+
const ERROR_MESSAGE_URL_PREFIX = `Please enter a valid URL starting with http or https.`;
|
|
9
|
+
//#endregion
|
|
10
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_COMMA_SEPPARATED_URLS", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return ERROR_MESSAGE_COMMA_SEPPARATED_URLS;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_INVALID_URL", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return ERROR_MESSAGE_INVALID_URL;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_ONE_PROJECT_STATUS", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function() {
|
|
25
|
+
return ERROR_MESSAGE_ONE_PROJECT_STATUS;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_ROBOT", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function() {
|
|
31
|
+
return ERROR_MESSAGE_ROBOT;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_URL_NO_QUERY_PARAMS", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function() {
|
|
37
|
+
return ERROR_MESSAGE_URL_NO_QUERY_PARAMS;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_URL_PREFIX", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function() {
|
|
43
|
+
return ERROR_MESSAGE_URL_PREFIX;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
Object.defineProperty(exports, "ERROR_MESSAGE_UTM_URL", {
|
|
47
|
+
enumerable: true,
|
|
48
|
+
get: function() {
|
|
49
|
+
return ERROR_MESSAGE_UTM_URL;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_chunk = require("../chunk-CKQMccvm.cjs");
|
|
3
|
+
const require_regex = require("../regex-BEFTMiHO.cjs");
|
|
4
|
+
let valibot = require("valibot");
|
|
5
|
+
valibot = require_chunk.__toESM(valibot, 1);
|
|
6
|
+
let randexp = require("randexp");
|
|
7
|
+
randexp = require_chunk.__toESM(randexp, 1);
|
|
8
|
+
//#region src/generators/index.ts
|
|
9
|
+
function generateValid(opts) {
|
|
10
|
+
const includeOptionalProb = opts?.includeOptionalProb ?? .7;
|
|
11
|
+
const maxAttempts = opts?.maxAttempts ?? 30;
|
|
12
|
+
const hooks = opts?.hooks ?? {};
|
|
13
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
14
|
+
const raw = _genWithHooks(opts.schema, { includeOptionalProb }, hooks, []);
|
|
15
|
+
const value = opts.overrides ? deepMerge(raw, opts.overrides) : raw;
|
|
16
|
+
const res = valibot.safeParse(opts.schema, value);
|
|
17
|
+
if (res.success) {
|
|
18
|
+
const output = res.output;
|
|
19
|
+
for (const field of opts.excludedFields ?? []) delete output[field];
|
|
20
|
+
return output;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
throw new Error("generateValid could not satisfy schema");
|
|
24
|
+
}
|
|
25
|
+
function _genWithHooks(schema, ctx, hooks, path) {
|
|
26
|
+
const val = _gen(schema, ctx, path);
|
|
27
|
+
const key = path[path.length - 1];
|
|
28
|
+
const pathKey = path.join(".");
|
|
29
|
+
if (hooks[pathKey]) return hooks[pathKey](val, schema, path);
|
|
30
|
+
if (key && hooks[key]) return hooks[key](val, schema, path);
|
|
31
|
+
return val;
|
|
32
|
+
}
|
|
33
|
+
function _gen(schema, ctx, path = []) {
|
|
34
|
+
switch (schema?.type) {
|
|
35
|
+
case "object": {
|
|
36
|
+
const out = {};
|
|
37
|
+
const entries = schema.entries ?? {};
|
|
38
|
+
for (const [key, sub] of Object.entries(entries)) {
|
|
39
|
+
const isOptional = sub?.type === "optional";
|
|
40
|
+
if (isOptional && Math.random() > ctx.includeOptionalProb) continue;
|
|
41
|
+
out[key] = _gen(isOptional ? unwrapOptional(sub) : sub, ctx, [...path, key]);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
case "array": {
|
|
46
|
+
const item = schema.item ?? schema.items;
|
|
47
|
+
const min = getArrayMin(schema) ?? 0;
|
|
48
|
+
const len = randInt(min, Math.max(min, Math.min(5, getArrayMax(schema) ?? 3)));
|
|
49
|
+
return Array.from({ length: len }, () => _gen(item, ctx, [...path, String(len)]));
|
|
50
|
+
}
|
|
51
|
+
case "tuple": return (schema.items ?? schema.entries ?? []).map((s, i) => _gen(s, ctx, [...path, String(i)]));
|
|
52
|
+
case "union": {
|
|
53
|
+
const options = schema.options ?? schema.variants ?? [];
|
|
54
|
+
for (const opt of shuffle([...options])) {
|
|
55
|
+
const val = _gen(opt, ctx, path);
|
|
56
|
+
if (valibot.safeParse(opt, val).success) return val;
|
|
57
|
+
}
|
|
58
|
+
return _gen(options[0], ctx, path);
|
|
59
|
+
}
|
|
60
|
+
case "literal": return schema.literal;
|
|
61
|
+
case "enum": return randomItem(schema.options ?? schema.values ?? schema.variants ?? []);
|
|
62
|
+
case "picklist": return randomItem(schema.options ?? schema.values ?? schema.variants ?? []);
|
|
63
|
+
case "record": {
|
|
64
|
+
const keySchema = schema.key ?? schema.keySchema ?? valibot.string();
|
|
65
|
+
const valueSchema = schema.value ?? schema.valueSchema ?? valibot.unknown();
|
|
66
|
+
const count = randInt(1, 3);
|
|
67
|
+
const obj = {};
|
|
68
|
+
for (let i = 0; i < count; i++) {
|
|
69
|
+
const k = String(_gen(keySchema, ctx, [...path, "key"]));
|
|
70
|
+
obj[k] = _gen(valueSchema, ctx, [...path, k]);
|
|
71
|
+
}
|
|
72
|
+
return obj;
|
|
73
|
+
}
|
|
74
|
+
case "string":
|
|
75
|
+
const stringPipe = schema?.pipe || [];
|
|
76
|
+
for (const p of stringPipe) {
|
|
77
|
+
if (p?.type === "iso_date") {
|
|
78
|
+
const [min, max] = getDateBounds(schema);
|
|
79
|
+
return new Date(randInt(min.getTime(), max.getTime())).toISOString().split("T")[0];
|
|
80
|
+
}
|
|
81
|
+
if (p?.type === "iso_datetime") {
|
|
82
|
+
const [min, max] = getDateBounds(schema);
|
|
83
|
+
return new Date(randInt(min.getTime(), max.getTime())).toISOString();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return makeString(schema);
|
|
87
|
+
case "number":
|
|
88
|
+
schema.pipe;
|
|
89
|
+
return makeNumber(schema);
|
|
90
|
+
case "boolean": return Math.random() < .5;
|
|
91
|
+
case "bigint": {
|
|
92
|
+
const n = makeNumber(schema);
|
|
93
|
+
return BigInt(Math.trunc(n));
|
|
94
|
+
}
|
|
95
|
+
case "date": {
|
|
96
|
+
const [min, max] = getDateBounds(schema);
|
|
97
|
+
return new Date(randInt(min.getTime(), max.getTime()));
|
|
98
|
+
}
|
|
99
|
+
case "nullable": {
|
|
100
|
+
const inner = schema.wrapped ?? schema.inner ?? schema.item;
|
|
101
|
+
return Math.random() < .2 ? null : _gen(inner, ctx, path);
|
|
102
|
+
}
|
|
103
|
+
case "optional": return _gen(unwrapOptional(schema), ctx, path);
|
|
104
|
+
default: return {};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function unwrapOptional(s) {
|
|
108
|
+
return s.wrapped ?? s.inner ?? s.item ?? s.schema ?? s;
|
|
109
|
+
}
|
|
110
|
+
function getChecks(schema) {
|
|
111
|
+
return Array.isArray(schema?.pipe) ? schema.pipe : [];
|
|
112
|
+
}
|
|
113
|
+
function getArrayMin(schema) {
|
|
114
|
+
const min = getChecks(schema).find((c) => c?.type === "min_length")?.requirement;
|
|
115
|
+
return typeof min === "number" ? min : void 0;
|
|
116
|
+
}
|
|
117
|
+
function getArrayMax(schema) {
|
|
118
|
+
const max = getChecks(schema).find((c) => c?.type === "max_length")?.requirement;
|
|
119
|
+
return typeof max === "number" ? max : void 0;
|
|
120
|
+
}
|
|
121
|
+
function makeString(schema) {
|
|
122
|
+
const checks = getChecks(schema);
|
|
123
|
+
const has = (k) => checks.some((c) => c?.type === k);
|
|
124
|
+
if (has("email")) return `${boundedAscii(5, 10).toLowerCase()}@${boundedAscii(3, 8).toLowerCase()}.com`;
|
|
125
|
+
if (has("url")) return `https://${boundedAscii(3, 8).toLowerCase()}.dev/${boundedAscii(3, 10)}`;
|
|
126
|
+
if (has("uuid")) return cryptoLikeRandomUUID();
|
|
127
|
+
if (checks.some((c) => c?.message?.includes("valid phone number"))) return `+1${fromPool("0123456789", 10)}`;
|
|
128
|
+
const minLen = checks.find((c) => c?.type === "min_length")?.requirement ?? 0;
|
|
129
|
+
const maxLen = checks.find((c) => c?.type === "max_length")?.requirement ?? Math.max(8, minLen + 8);
|
|
130
|
+
const targetLen = clamp(randInt(minLen, Math.max(minLen, Math.min(24, maxLen))), minLen, maxLen);
|
|
131
|
+
const rx = checks.find((c) => c?.type === "regex")?.requirement;
|
|
132
|
+
if (rx) {
|
|
133
|
+
pickPoolForRegex(rx);
|
|
134
|
+
const rxp = new randexp.default(rx);
|
|
135
|
+
for (let i = 0; i < 80; i++) {
|
|
136
|
+
const limit = randInt(minLen, Math.min(maxLen, targetLen));
|
|
137
|
+
let candidate = rxp.gen();
|
|
138
|
+
if (candidate.length > limit) candidate = candidate.slice(0, limit);
|
|
139
|
+
if (rx.test(candidate) && candidate.length >= minLen && candidate.length <= maxLen) return candidate;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return boundedAscii(minLen, targetLen);
|
|
143
|
+
}
|
|
144
|
+
function makeNumber(schema) {
|
|
145
|
+
const checks = getChecks(schema);
|
|
146
|
+
let min = checks.find((c) => c?.type === "min_value")?.requirement ?? 0;
|
|
147
|
+
let max = checks.find((c) => c?.type === "max_value")?.requirement ?? 1e3;
|
|
148
|
+
if (min > max) [min, max] = [max, min];
|
|
149
|
+
return checks.some((c) => c?.type === "number" || c?.type === "int") ? randInt(Math.ceil(min), Math.floor(max)) : randFloat(min, max);
|
|
150
|
+
}
|
|
151
|
+
function getDateBounds(schema) {
|
|
152
|
+
const checks = getChecks(schema);
|
|
153
|
+
const min = checks.find((c) => c?.type === "min_value")?.requirement;
|
|
154
|
+
const max = checks.find((c) => c?.type === "max_value")?.requirement;
|
|
155
|
+
return [min instanceof Date ? min : /* @__PURE__ */ new Date(Date.now() - 365 * 24 * 3600 * 1e3), max instanceof Date ? max : new Date(Date.now() + 365 * 24 * 3600 * 1e3)];
|
|
156
|
+
}
|
|
157
|
+
const ABC = "abcdefghijklmnopqrstuvwxyz";
|
|
158
|
+
const NUM = "0123456789";
|
|
159
|
+
const ALNUM = ABC + ABC.toUpperCase() + NUM;
|
|
160
|
+
const VALUE_SAFE = ALNUM + "._-";
|
|
161
|
+
function pickPoolForRegex(rx) {
|
|
162
|
+
const src = rx.source;
|
|
163
|
+
if (/^\^?[\(\[]?[A-Za-z0-9._-]+\+[\)\]]\??\$?$/.test(src) || require_regex.REGEX_UTM_VALUE.test(src)) return VALUE_SAFE;
|
|
164
|
+
if (/\[0-9\]|\\d/.test(src)) {
|
|
165
|
+
if (!/[a-zA-Z]/.test(src)) return NUM;
|
|
166
|
+
return ALNUM;
|
|
167
|
+
}
|
|
168
|
+
if (/\[a-z]/.test(src) && /\[A-Z]/.test(src)) return ALNUM;
|
|
169
|
+
if (/\[a-z]/.test(src)) return ABC;
|
|
170
|
+
if (/\[A-Z]/.test(src)) return ABC.toUpperCase();
|
|
171
|
+
return ALNUM;
|
|
172
|
+
}
|
|
173
|
+
function fromPool(pool, len) {
|
|
174
|
+
let s = "";
|
|
175
|
+
for (let i = 0; i < len; i++) s += pool[randInt(0, pool.length - 1)];
|
|
176
|
+
return s;
|
|
177
|
+
}
|
|
178
|
+
function boundedAscii(min, max) {
|
|
179
|
+
const len = randInt(min, Math.max(min, max));
|
|
180
|
+
let s = "";
|
|
181
|
+
for (let i = 0; i < len; i++) s += ALNUM[randInt(0, ALNUM.length - 1)];
|
|
182
|
+
return s;
|
|
183
|
+
}
|
|
184
|
+
function cryptoLikeRandomUUID() {
|
|
185
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
186
|
+
const s = [];
|
|
187
|
+
const hex = "0123456789abcdef";
|
|
188
|
+
for (let i = 0; i < 36; i++) s[i] = hex[randInt(0, 15)];
|
|
189
|
+
s[14] = "4";
|
|
190
|
+
s[19] = hex[parseInt(s[19], 16) & 3 | 8];
|
|
191
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
192
|
+
return s.join("");
|
|
193
|
+
}
|
|
194
|
+
function randInt(min, max) {
|
|
195
|
+
const lo = Math.ceil(min);
|
|
196
|
+
return Math.floor(Math.random() * (Math.floor(max) - lo + 1)) + lo;
|
|
197
|
+
}
|
|
198
|
+
function randFloat(min, max) {
|
|
199
|
+
return Math.random() * (max - min) + min;
|
|
200
|
+
}
|
|
201
|
+
function randomItem(arr) {
|
|
202
|
+
return arr[randInt(0, arr.length - 1)];
|
|
203
|
+
}
|
|
204
|
+
function shuffle(arr) {
|
|
205
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
|
206
|
+
const j = randInt(0, i);
|
|
207
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
208
|
+
}
|
|
209
|
+
return arr;
|
|
210
|
+
}
|
|
211
|
+
function deepMerge(a, b) {
|
|
212
|
+
if (Array.isArray(a) && Array.isArray(b)) return b;
|
|
213
|
+
if (isPlain(a) && isPlain(b)) {
|
|
214
|
+
const out = { ...a };
|
|
215
|
+
for (const [k, v] of Object.entries(b)) {
|
|
216
|
+
if (v === void 0) continue;
|
|
217
|
+
out[k] = k in a ? deepMerge(a[k], v) : v;
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
return b ?? a;
|
|
222
|
+
}
|
|
223
|
+
function isPlain(x) {
|
|
224
|
+
return typeof x === "object" && x !== null && !Array.isArray(x);
|
|
225
|
+
}
|
|
226
|
+
function clamp(n, lo, hi) {
|
|
227
|
+
return Math.max(lo, Math.min(hi, n));
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
exports.boundedAscii = boundedAscii;
|
|
231
|
+
exports.generateValid = generateValid;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/generators/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate a random valid value for a given Valibot schema.
|
|
6
|
+
* Tuned to hit 100% validity for the user's CreateCampaign* schemas.
|
|
7
|
+
*/
|
|
8
|
+
type Hook = (input: unknown, schema: any, path: string[]) => unknown;
|
|
9
|
+
declare function generateValid<T, O = unknown>(opts: {
|
|
10
|
+
schema: v.BaseSchema<T, T, v.BaseIssue<O>>;
|
|
11
|
+
overrides?: Partial<T>;
|
|
12
|
+
excludedFields?: (keyof T)[];
|
|
13
|
+
includeOptionalProb?: number;
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
hooks?: Record<string, Hook>;
|
|
16
|
+
}): T;
|
|
17
|
+
declare function boundedAscii(min: number, max: number): string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { boundedAscii, generateValid };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
|
|
3
|
+
//#region src/generators/index.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Generate a random valid value for a given Valibot schema.
|
|
6
|
+
* Tuned to hit 100% validity for the user's CreateCampaign* schemas.
|
|
7
|
+
*/
|
|
8
|
+
type Hook = (input: unknown, schema: any, path: string[]) => unknown;
|
|
9
|
+
declare function generateValid<T, O = unknown>(opts: {
|
|
10
|
+
schema: v.BaseSchema<T, T, v.BaseIssue<O>>;
|
|
11
|
+
overrides?: Partial<T>;
|
|
12
|
+
excludedFields?: (keyof T)[];
|
|
13
|
+
includeOptionalProb?: number;
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
hooks?: Record<string, Hook>;
|
|
16
|
+
}): T;
|
|
17
|
+
declare function boundedAscii(min: number, max: number): string;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { boundedAscii, generateValid };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { s as REGEX_UTM_VALUE } from "../regex-pSdcbWzV.mjs";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import RandExp from "randexp";
|
|
4
|
+
//#region src/generators/index.ts
|
|
5
|
+
function generateValid(opts) {
|
|
6
|
+
const includeOptionalProb = opts?.includeOptionalProb ?? .7;
|
|
7
|
+
const maxAttempts = opts?.maxAttempts ?? 30;
|
|
8
|
+
const hooks = opts?.hooks ?? {};
|
|
9
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
10
|
+
const raw = _genWithHooks(opts.schema, { includeOptionalProb }, hooks, []);
|
|
11
|
+
const value = opts.overrides ? deepMerge(raw, opts.overrides) : raw;
|
|
12
|
+
const res = v.safeParse(opts.schema, value);
|
|
13
|
+
if (res.success) {
|
|
14
|
+
const output = res.output;
|
|
15
|
+
for (const field of opts.excludedFields ?? []) delete output[field];
|
|
16
|
+
return output;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
throw new Error("generateValid could not satisfy schema");
|
|
20
|
+
}
|
|
21
|
+
function _genWithHooks(schema, ctx, hooks, path) {
|
|
22
|
+
const val = _gen(schema, ctx, path);
|
|
23
|
+
const key = path[path.length - 1];
|
|
24
|
+
const pathKey = path.join(".");
|
|
25
|
+
if (hooks[pathKey]) return hooks[pathKey](val, schema, path);
|
|
26
|
+
if (key && hooks[key]) return hooks[key](val, schema, path);
|
|
27
|
+
return val;
|
|
28
|
+
}
|
|
29
|
+
function _gen(schema, ctx, path = []) {
|
|
30
|
+
switch (schema?.type) {
|
|
31
|
+
case "object": {
|
|
32
|
+
const out = {};
|
|
33
|
+
const entries = schema.entries ?? {};
|
|
34
|
+
for (const [key, sub] of Object.entries(entries)) {
|
|
35
|
+
const isOptional = sub?.type === "optional";
|
|
36
|
+
if (isOptional && Math.random() > ctx.includeOptionalProb) continue;
|
|
37
|
+
out[key] = _gen(isOptional ? unwrapOptional(sub) : sub, ctx, [...path, key]);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
case "array": {
|
|
42
|
+
const item = schema.item ?? schema.items;
|
|
43
|
+
const min = getArrayMin(schema) ?? 0;
|
|
44
|
+
const len = randInt(min, Math.max(min, Math.min(5, getArrayMax(schema) ?? 3)));
|
|
45
|
+
return Array.from({ length: len }, () => _gen(item, ctx, [...path, String(len)]));
|
|
46
|
+
}
|
|
47
|
+
case "tuple": return (schema.items ?? schema.entries ?? []).map((s, i) => _gen(s, ctx, [...path, String(i)]));
|
|
48
|
+
case "union": {
|
|
49
|
+
const options = schema.options ?? schema.variants ?? [];
|
|
50
|
+
for (const opt of shuffle([...options])) {
|
|
51
|
+
const val = _gen(opt, ctx, path);
|
|
52
|
+
if (v.safeParse(opt, val).success) return val;
|
|
53
|
+
}
|
|
54
|
+
return _gen(options[0], ctx, path);
|
|
55
|
+
}
|
|
56
|
+
case "literal": return schema.literal;
|
|
57
|
+
case "enum": return randomItem(schema.options ?? schema.values ?? schema.variants ?? []);
|
|
58
|
+
case "picklist": return randomItem(schema.options ?? schema.values ?? schema.variants ?? []);
|
|
59
|
+
case "record": {
|
|
60
|
+
const keySchema = schema.key ?? schema.keySchema ?? v.string();
|
|
61
|
+
const valueSchema = schema.value ?? schema.valueSchema ?? v.unknown();
|
|
62
|
+
const count = randInt(1, 3);
|
|
63
|
+
const obj = {};
|
|
64
|
+
for (let i = 0; i < count; i++) {
|
|
65
|
+
const k = String(_gen(keySchema, ctx, [...path, "key"]));
|
|
66
|
+
obj[k] = _gen(valueSchema, ctx, [...path, k]);
|
|
67
|
+
}
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
case "string":
|
|
71
|
+
const stringPipe = schema?.pipe || [];
|
|
72
|
+
for (const p of stringPipe) {
|
|
73
|
+
if (p?.type === "iso_date") {
|
|
74
|
+
const [min, max] = getDateBounds(schema);
|
|
75
|
+
return new Date(randInt(min.getTime(), max.getTime())).toISOString().split("T")[0];
|
|
76
|
+
}
|
|
77
|
+
if (p?.type === "iso_datetime") {
|
|
78
|
+
const [min, max] = getDateBounds(schema);
|
|
79
|
+
return new Date(randInt(min.getTime(), max.getTime())).toISOString();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return makeString(schema);
|
|
83
|
+
case "number":
|
|
84
|
+
schema.pipe;
|
|
85
|
+
return makeNumber(schema);
|
|
86
|
+
case "boolean": return Math.random() < .5;
|
|
87
|
+
case "bigint": {
|
|
88
|
+
const n = makeNumber(schema);
|
|
89
|
+
return BigInt(Math.trunc(n));
|
|
90
|
+
}
|
|
91
|
+
case "date": {
|
|
92
|
+
const [min, max] = getDateBounds(schema);
|
|
93
|
+
return new Date(randInt(min.getTime(), max.getTime()));
|
|
94
|
+
}
|
|
95
|
+
case "nullable": {
|
|
96
|
+
const inner = schema.wrapped ?? schema.inner ?? schema.item;
|
|
97
|
+
return Math.random() < .2 ? null : _gen(inner, ctx, path);
|
|
98
|
+
}
|
|
99
|
+
case "optional": return _gen(unwrapOptional(schema), ctx, path);
|
|
100
|
+
default: return {};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function unwrapOptional(s) {
|
|
104
|
+
return s.wrapped ?? s.inner ?? s.item ?? s.schema ?? s;
|
|
105
|
+
}
|
|
106
|
+
function getChecks(schema) {
|
|
107
|
+
return Array.isArray(schema?.pipe) ? schema.pipe : [];
|
|
108
|
+
}
|
|
109
|
+
function getArrayMin(schema) {
|
|
110
|
+
const min = getChecks(schema).find((c) => c?.type === "min_length")?.requirement;
|
|
111
|
+
return typeof min === "number" ? min : void 0;
|
|
112
|
+
}
|
|
113
|
+
function getArrayMax(schema) {
|
|
114
|
+
const max = getChecks(schema).find((c) => c?.type === "max_length")?.requirement;
|
|
115
|
+
return typeof max === "number" ? max : void 0;
|
|
116
|
+
}
|
|
117
|
+
function makeString(schema) {
|
|
118
|
+
const checks = getChecks(schema);
|
|
119
|
+
const has = (k) => checks.some((c) => c?.type === k);
|
|
120
|
+
if (has("email")) return `${boundedAscii(5, 10).toLowerCase()}@${boundedAscii(3, 8).toLowerCase()}.com`;
|
|
121
|
+
if (has("url")) return `https://${boundedAscii(3, 8).toLowerCase()}.dev/${boundedAscii(3, 10)}`;
|
|
122
|
+
if (has("uuid")) return cryptoLikeRandomUUID();
|
|
123
|
+
if (checks.some((c) => c?.message?.includes("valid phone number"))) return `+1${fromPool("0123456789", 10)}`;
|
|
124
|
+
const minLen = checks.find((c) => c?.type === "min_length")?.requirement ?? 0;
|
|
125
|
+
const maxLen = checks.find((c) => c?.type === "max_length")?.requirement ?? Math.max(8, minLen + 8);
|
|
126
|
+
const targetLen = clamp(randInt(minLen, Math.max(minLen, Math.min(24, maxLen))), minLen, maxLen);
|
|
127
|
+
const rx = checks.find((c) => c?.type === "regex")?.requirement;
|
|
128
|
+
if (rx) {
|
|
129
|
+
pickPoolForRegex(rx);
|
|
130
|
+
const rxp = new RandExp(rx);
|
|
131
|
+
for (let i = 0; i < 80; i++) {
|
|
132
|
+
const limit = randInt(minLen, Math.min(maxLen, targetLen));
|
|
133
|
+
let candidate = rxp.gen();
|
|
134
|
+
if (candidate.length > limit) candidate = candidate.slice(0, limit);
|
|
135
|
+
if (rx.test(candidate) && candidate.length >= minLen && candidate.length <= maxLen) return candidate;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return boundedAscii(minLen, targetLen);
|
|
139
|
+
}
|
|
140
|
+
function makeNumber(schema) {
|
|
141
|
+
const checks = getChecks(schema);
|
|
142
|
+
let min = checks.find((c) => c?.type === "min_value")?.requirement ?? 0;
|
|
143
|
+
let max = checks.find((c) => c?.type === "max_value")?.requirement ?? 1e3;
|
|
144
|
+
if (min > max) [min, max] = [max, min];
|
|
145
|
+
return checks.some((c) => c?.type === "number" || c?.type === "int") ? randInt(Math.ceil(min), Math.floor(max)) : randFloat(min, max);
|
|
146
|
+
}
|
|
147
|
+
function getDateBounds(schema) {
|
|
148
|
+
const checks = getChecks(schema);
|
|
149
|
+
const min = checks.find((c) => c?.type === "min_value")?.requirement;
|
|
150
|
+
const max = checks.find((c) => c?.type === "max_value")?.requirement;
|
|
151
|
+
return [min instanceof Date ? min : /* @__PURE__ */ new Date(Date.now() - 365 * 24 * 3600 * 1e3), max instanceof Date ? max : new Date(Date.now() + 365 * 24 * 3600 * 1e3)];
|
|
152
|
+
}
|
|
153
|
+
const ABC = "abcdefghijklmnopqrstuvwxyz";
|
|
154
|
+
const NUM = "0123456789";
|
|
155
|
+
const ALNUM = ABC + ABC.toUpperCase() + NUM;
|
|
156
|
+
const VALUE_SAFE = ALNUM + "._-";
|
|
157
|
+
function pickPoolForRegex(rx) {
|
|
158
|
+
const src = rx.source;
|
|
159
|
+
if (/^\^?[\(\[]?[A-Za-z0-9._-]+\+[\)\]]\??\$?$/.test(src) || REGEX_UTM_VALUE.test(src)) return VALUE_SAFE;
|
|
160
|
+
if (/\[0-9\]|\\d/.test(src)) {
|
|
161
|
+
if (!/[a-zA-Z]/.test(src)) return NUM;
|
|
162
|
+
return ALNUM;
|
|
163
|
+
}
|
|
164
|
+
if (/\[a-z]/.test(src) && /\[A-Z]/.test(src)) return ALNUM;
|
|
165
|
+
if (/\[a-z]/.test(src)) return ABC;
|
|
166
|
+
if (/\[A-Z]/.test(src)) return ABC.toUpperCase();
|
|
167
|
+
return ALNUM;
|
|
168
|
+
}
|
|
169
|
+
function fromPool(pool, len) {
|
|
170
|
+
let s = "";
|
|
171
|
+
for (let i = 0; i < len; i++) s += pool[randInt(0, pool.length - 1)];
|
|
172
|
+
return s;
|
|
173
|
+
}
|
|
174
|
+
function boundedAscii(min, max) {
|
|
175
|
+
const len = randInt(min, Math.max(min, max));
|
|
176
|
+
let s = "";
|
|
177
|
+
for (let i = 0; i < len; i++) s += ALNUM[randInt(0, ALNUM.length - 1)];
|
|
178
|
+
return s;
|
|
179
|
+
}
|
|
180
|
+
function cryptoLikeRandomUUID() {
|
|
181
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
182
|
+
const s = [];
|
|
183
|
+
const hex = "0123456789abcdef";
|
|
184
|
+
for (let i = 0; i < 36; i++) s[i] = hex[randInt(0, 15)];
|
|
185
|
+
s[14] = "4";
|
|
186
|
+
s[19] = hex[parseInt(s[19], 16) & 3 | 8];
|
|
187
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
188
|
+
return s.join("");
|
|
189
|
+
}
|
|
190
|
+
function randInt(min, max) {
|
|
191
|
+
const lo = Math.ceil(min);
|
|
192
|
+
return Math.floor(Math.random() * (Math.floor(max) - lo + 1)) + lo;
|
|
193
|
+
}
|
|
194
|
+
function randFloat(min, max) {
|
|
195
|
+
return Math.random() * (max - min) + min;
|
|
196
|
+
}
|
|
197
|
+
function randomItem(arr) {
|
|
198
|
+
return arr[randInt(0, arr.length - 1)];
|
|
199
|
+
}
|
|
200
|
+
function shuffle(arr) {
|
|
201
|
+
for (let i = arr.length - 1; i > 0; i--) {
|
|
202
|
+
const j = randInt(0, i);
|
|
203
|
+
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
204
|
+
}
|
|
205
|
+
return arr;
|
|
206
|
+
}
|
|
207
|
+
function deepMerge(a, b) {
|
|
208
|
+
if (Array.isArray(a) && Array.isArray(b)) return b;
|
|
209
|
+
if (isPlain(a) && isPlain(b)) {
|
|
210
|
+
const out = { ...a };
|
|
211
|
+
for (const [k, v] of Object.entries(b)) {
|
|
212
|
+
if (v === void 0) continue;
|
|
213
|
+
out[k] = k in a ? deepMerge(a[k], v) : v;
|
|
214
|
+
}
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
return b ?? a;
|
|
218
|
+
}
|
|
219
|
+
function isPlain(x) {
|
|
220
|
+
return typeof x === "object" && x !== null && !Array.isArray(x);
|
|
221
|
+
}
|
|
222
|
+
function clamp(n, lo, hi) {
|
|
223
|
+
return Math.max(lo, Math.min(hi, n));
|
|
224
|
+
}
|
|
225
|
+
//#endregion
|
|
226
|
+
export { boundedAscii, generateValid };
|