aws-service-stack 0.18.362 → 0.18.364

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.
@@ -0,0 +1,12 @@
1
+ import { z, ZodType } from "zod";
2
+ type InvalidConfig = boolean | string[];
3
+ export declare class EntityMockBuilder<T extends ZodType<any, any, any>> {
4
+ private readonly schema;
5
+ private readonly invalid;
6
+ private seed;
7
+ constructor(schema: T, invalid?: InvalidConfig);
8
+ build(): z.infer<T>;
9
+ private buildFromZod;
10
+ private shouldInvalidate;
11
+ }
12
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EntityMockBuilder = void 0;
4
+ const zod_1 = require("zod");
5
+ class EntityMockBuilder {
6
+ schema;
7
+ invalid;
8
+ seed = 1;
9
+ constructor(schema, invalid = true) {
10
+ this.schema = schema;
11
+ this.invalid = invalid;
12
+ }
13
+ build() {
14
+ return this.buildFromZod(this.schema, this.invalid);
15
+ }
16
+ buildFromZod(schema, invalidConfig, path = []) {
17
+ // Optional / Nullable unwrap
18
+ if (schema instanceof zod_1.ZodOptional || schema instanceof zod_1.ZodNullable) {
19
+ const inner = schema._def.innerType;
20
+ return this.buildFromZod(inner, invalidConfig, path);
21
+ }
22
+ if (schema instanceof zod_1.ZodString) {
23
+ return this.shouldInvalidate(path, invalidConfig) ? "INVALID" : `valid_${path.join("_")}`;
24
+ }
25
+ if (schema instanceof zod_1.ZodNumber) {
26
+ return this.shouldInvalidate(path, invalidConfig) ? -1 : 1;
27
+ }
28
+ if (schema instanceof zod_1.ZodBoolean) {
29
+ return !this.shouldInvalidate(path, invalidConfig);
30
+ }
31
+ if (schema instanceof zod_1.ZodArray) {
32
+ const elementSchema = schema.element;
33
+ return [this.buildFromZod(elementSchema, invalidConfig, path.concat(["0"]))];
34
+ }
35
+ if (schema instanceof zod_1.ZodObject) {
36
+ const obj = {};
37
+ const shape = schema.shape;
38
+ for (const key in shape) {
39
+ obj[key] = this.buildFromZod(shape[key], invalidConfig, path.concat([key]));
40
+ }
41
+ return obj;
42
+ }
43
+ return null;
44
+ }
45
+ shouldInvalidate(path, invalidConfig) {
46
+ if (invalidConfig === false) {
47
+ const x = Math.sin(this.seed++) * 10000;
48
+ return x - Math.floor(x) > 0.5;
49
+ }
50
+ if (Array.isArray(invalidConfig)) {
51
+ return invalidConfig.includes(path.join("."));
52
+ }
53
+ return false;
54
+ }
55
+ }
56
+ exports.EntityMockBuilder = EntityMockBuilder;
57
+ //# sourceMappingURL=data.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.util.js","sourceRoot":"","sources":["../../src/utils/data.util.ts"],"names":[],"mappings":";;;AAAA,6BAAkH;AAIlH,MAAa,iBAAiB;IAIT;IACA;IAJX,IAAI,GAAG,CAAC,CAAC;IAEjB,YACmB,MAAS,EACT,UAAyB,IAAI;QAD7B,WAAM,GAAN,MAAM,CAAG;QACT,YAAO,GAAP,OAAO,CAAsB;IAC7C,CAAC;IAEJ,KAAK;QACH,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAe,CAAC;IACpE,CAAC;IAEO,YAAY,CAAC,MAA8B,EAAE,aAA4B,EAAE,OAAiB,EAAE;QACpG,6BAA6B;QAC7B,IAAI,MAAM,YAAY,iBAAW,IAAI,MAAM,YAAY,iBAAW,EAAE,CAAC;YACnE,MAAM,KAAK,GAAI,MAAc,CAAC,IAAI,CAAC,SAAmC,CAAC;YACvE,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,MAAM,YAAY,eAAS,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,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AAG,GAAG,CAAC;QACjC,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,CAAC;YACjC,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA1DD,8CA0DC","sourcesContent":["import { z, ZodArray, ZodBoolean, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodString, ZodType } from \"zod\";\n\ntype InvalidConfig = boolean | string[];\n\nexport class EntityMockBuilder<T extends ZodType<any, any, any>> {\n private seed = 1;\n\n constructor(\n private readonly schema: T,\n private readonly invalid: InvalidConfig = true,\n ) {}\n\n build(): z.infer<T> {\n return this.buildFromZod(this.schema, this.invalid) as z.infer<T>;\n }\n\n private buildFromZod(schema: ZodType<any, any, any>, invalidConfig: InvalidConfig, path: string[] = []): any {\n // Optional / Nullable unwrap\n if (schema instanceof ZodOptional || schema instanceof ZodNullable) {\n const inner = (schema as any)._def.innerType as ZodType<any, any, any>;\n return this.buildFromZod(inner, invalidConfig, path);\n }\n\n if (schema instanceof ZodString) {\n return this.shouldInvalidate(path, invalidConfig) ? \"INVALID\" : `valid_${path.join(\"_\")}`;\n }\n\n if (schema instanceof ZodNumber) {\n return this.shouldInvalidate(path, invalidConfig) ? -1 : 1;\n }\n\n if (schema instanceof ZodBoolean) {\n return !this.shouldInvalidate(path, invalidConfig);\n }\n\n if (schema instanceof ZodArray) {\n const elementSchema = (schema as ZodArray<any>).element as ZodType<any, any, any>;\n return [this.buildFromZod(elementSchema, invalidConfig, path.concat([\"0\"]))];\n }\n\n if (schema instanceof ZodObject) {\n const obj: any = {};\n const shape = (schema as ZodObject<any>).shape;\n for (const key in shape) {\n obj[key] = this.buildFromZod(shape[key], invalidConfig, path.concat([key]));\n }\n return obj;\n }\n\n return null;\n }\n\n private shouldInvalidate(path: string[], invalidConfig: InvalidConfig): boolean {\n if (invalidConfig === false) {\n const x = Math.sin(this.seed++) * 10000;\n return x - Math.floor(x) > 0.5;\n }\n if (Array.isArray(invalidConfig)) {\n return invalidConfig.includes(path.join(\".\"));\n }\n return false;\n }\n}\n"]}
@@ -3,3 +3,16 @@ export declare function isValidDate(dateStr: string): boolean;
3
3
  export declare function isSameYearMonth(date1: string | Date | Dayjs, date2: string | Date | Dayjs): boolean;
4
4
  export declare function isCurrentMonth(date: string | Date | Dayjs): boolean;
5
5
  export declare function isFutureMonth(date: string): boolean;
6
+ export declare function addSecondToDate(date: string | Date | Dayjs): Dayjs;
7
+ /**
8
+ * Returns the oldest date string from a list of date strings.
9
+ * @param dateStrList List of date strings (ISO or other formats supported by dayjs).
10
+ * @returns The oldest date string, or an empty string if the list is empty.
11
+ */
12
+ export declare function minDateStr(dateStrList: any[]): string;
13
+ /**
14
+ * Returns the newest date string from a list of date strings.
15
+ * @param dateStrList List of date strings (ISO or other formats supported by dayjs).
16
+ * @returns The newest date string, or an empty string if the list is empty.
17
+ */
18
+ export declare function maxDateStr(dateStrList: any[]): string;
@@ -7,6 +7,9 @@ exports.isValidDate = isValidDate;
7
7
  exports.isSameYearMonth = isSameYearMonth;
8
8
  exports.isCurrentMonth = isCurrentMonth;
9
9
  exports.isFutureMonth = isFutureMonth;
10
+ exports.addSecondToDate = addSecondToDate;
11
+ exports.minDateStr = minDateStr;
12
+ exports.maxDateStr = maxDateStr;
10
13
  const dayjs_1 = __importDefault(require("dayjs"));
11
14
  function isValidDate(dateStr) {
12
15
  const d = new Date(dateStr);
@@ -31,4 +34,36 @@ function isFutureMonth(date) {
31
34
  // Compare year-month
32
35
  return inputYear > currentYear || (inputYear === currentYear && inputMonth > currentMonth);
33
36
  }
37
+ function addSecondToDate(date) {
38
+ return (0, dayjs_1.default)(date).add(1, "second");
39
+ }
40
+ /**
41
+ * Returns the oldest date string from a list of date strings.
42
+ * @param dateStrList List of date strings (ISO or other formats supported by dayjs).
43
+ * @returns The oldest date string, or an empty string if the list is empty.
44
+ */
45
+ function minDateStr(dateStrList) {
46
+ return minMaxDateStr(dateStrList, false);
47
+ }
48
+ /**
49
+ * Returns the newest date string from a list of date strings.
50
+ * @param dateStrList List of date strings (ISO or other formats supported by dayjs).
51
+ * @returns The newest date string, or an empty string if the list is empty.
52
+ */
53
+ function maxDateStr(dateStrList) {
54
+ return minMaxDateStr(dateStrList, true);
55
+ }
56
+ function minMaxDateStr(dateStrList, isMax) {
57
+ if (!dateStrList || dateStrList.length === 0)
58
+ return "";
59
+ const filtered = dateStrList.filter((d) => !!d);
60
+ if (filtered.length === 0)
61
+ return "";
62
+ return filtered.reduce((newestDate, current) => {
63
+ if (isMax)
64
+ return (0, dayjs_1.default)(current).isAfter((0, dayjs_1.default)(newestDate)) ? current : newestDate;
65
+ else
66
+ return (0, dayjs_1.default)(current).isBefore((0, dayjs_1.default)(newestDate)) ? newestDate : current;
67
+ });
68
+ }
34
69
  //# sourceMappingURL=date.util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"date.util.js","sourceRoot":"","sources":["../../src/utils/date.util.ts"],"names":[],"mappings":";;;;;AACA,kCAGC;AAED,0CAIC;AAED,wCAEC;AAED,sCAYC;AA5BD,kDAAqC;AACrC,SAAgB,WAAW,CAAC,OAAe;IACzC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,eAAe,CAAC,KAA4B,EAAE,KAA4B;IACxF,MAAM,EAAE,GAAG,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC;IACxB,MAAM,EAAE,GAAG,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC;IACxB,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC;AAED,SAAgB,cAAc,CAAC,IAA2B;IACxD,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC;IAEzB,yBAAyB;IACzB,MAAM,SAAS,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IAC1C,MAAM,UAAU,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,oBAAoB;IAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC;IACxC,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAEtC,qBAAqB;IACrB,OAAO,SAAS,GAAG,WAAW,IAAI,CAAC,SAAS,KAAK,WAAW,IAAI,UAAU,GAAG,YAAY,CAAC,CAAC;AAC7F,CAAC","sourcesContent":["import dayjs, { Dayjs } from \"dayjs\";\nexport function isValidDate(dateStr: string): boolean {\n const d = new Date(dateStr);\n return !Number.isNaN(d.getTime());\n}\n\nexport function isSameYearMonth(date1: string | Date | Dayjs, date2: string | Date | Dayjs): boolean {\n const d1 = dayjs(date1);\n const d2 = dayjs(date2);\n return d1.isSame(d2, \"month\") && d1.isSame(d2, \"year\");\n}\n\nexport function isCurrentMonth(date: string | Date | Dayjs): boolean {\n return isSameYearMonth(date, new Date());\n}\n\nexport function isFutureMonth(date: string): boolean {\n const inputDate = new Date(date);\n const today = new Date();\n\n // Extract year and month\n const inputYear = inputDate.getFullYear();\n const inputMonth = inputDate.getMonth(); // 0-based (0 = Jan)\n const currentYear = today.getFullYear();\n const currentMonth = today.getMonth();\n\n // Compare year-month\n return inputYear > currentYear || (inputYear === currentYear && inputMonth > currentMonth);\n}\n"]}
1
+ {"version":3,"file":"date.util.js","sourceRoot":"","sources":["../../src/utils/date.util.ts"],"names":[],"mappings":";;;;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C,IAA2B;IACzD,OAAO,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AACD;;;;GAIG;AACH,SAAgB,UAAU,CAAC,WAAkB;IAC3C,OAAO,aAAa,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,SAAgB,UAAU,CAAC,WAAkB;IAC3C,OAAO,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,aAAa,CAAC,WAAkB,EAAE,KAAc;IACvD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAExD,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAErC,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE;QAC7C,IAAI,KAAK;YAAE,OAAO,IAAA,eAAK,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAA,eAAK,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;;YAC9E,OAAO,IAAA,eAAK,EAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,IAAA,eAAK,EAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;IAChF,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import dayjs, { Dayjs } from \"dayjs\";\n\nexport function isValidDate(dateStr: string): boolean {\n const d = new Date(dateStr);\n return !Number.isNaN(d.getTime());\n}\n\nexport function isSameYearMonth(date1: string | Date | Dayjs, date2: string | Date | Dayjs): boolean {\n const d1 = dayjs(date1);\n const d2 = dayjs(date2);\n return d1.isSame(d2, \"month\") && d1.isSame(d2, \"year\");\n}\n\nexport function isCurrentMonth(date: string | Date | Dayjs): boolean {\n return isSameYearMonth(date, new Date());\n}\n\nexport function isFutureMonth(date: string): boolean {\n const inputDate = new Date(date);\n const today = new Date();\n\n // Extract year and month\n const inputYear = inputDate.getFullYear();\n const inputMonth = inputDate.getMonth(); // 0-based (0 = Jan)\n const currentYear = today.getFullYear();\n const currentMonth = today.getMonth();\n\n // Compare year-month\n return inputYear > currentYear || (inputYear === currentYear && inputMonth > currentMonth);\n}\n\nexport function addSecondToDate(date: string | Date | Dayjs): Dayjs {\n return dayjs(date).add(1, \"second\");\n}\n/**\n * Returns the oldest date string from a list of date strings.\n * @param dateStrList List of date strings (ISO or other formats supported by dayjs).\n * @returns The oldest date string, or an empty string if the list is empty.\n */\nexport function minDateStr(dateStrList: any[]): string {\n return minMaxDateStr(dateStrList, false);\n}\n\n/**\n * Returns the newest date string from a list of date strings.\n * @param dateStrList List of date strings (ISO or other formats supported by dayjs).\n * @returns The newest date string, or an empty string if the list is empty.\n */\nexport function maxDateStr(dateStrList: any[]): string {\n return minMaxDateStr(dateStrList, true);\n}\n\nfunction minMaxDateStr(dateStrList: any[], isMax: boolean): string {\n if (!dateStrList || dateStrList.length === 0) return \"\";\n\n const filtered = dateStrList.filter((d) => !!d);\n if (filtered.length === 0) return \"\";\n\n return filtered.reduce((newestDate, current) => {\n if (isMax) return dayjs(current).isAfter(dayjs(newestDate)) ? current : newestDate;\n else return dayjs(current).isBefore(dayjs(newestDate)) ? newestDate : current;\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-service-stack",
3
- "version": "0.18.362",
3
+ "version": "0.18.364",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "chinggis.systems",