@wildo-ai/zod-decorators 1.0.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.
Files changed (94) hide show
  1. package/dist/esm/__mocks__/mime.d.ts +12 -0
  2. package/dist/esm/__mocks__/mime.d.ts.map +1 -0
  3. package/dist/esm/__mocks__/mime.js +75 -0
  4. package/dist/esm/__mocks__/mime.js.map +1 -0
  5. package/dist/esm/commons.d.ts +26 -0
  6. package/dist/esm/commons.d.ts.map +1 -0
  7. package/dist/esm/commons.js +41 -0
  8. package/dist/esm/commons.js.map +1 -0
  9. package/dist/esm/currencies.shared.schemas.d.ts +208 -0
  10. package/dist/esm/currencies.shared.schemas.d.ts.map +1 -0
  11. package/dist/esm/currencies.shared.schemas.js +228 -0
  12. package/dist/esm/currencies.shared.schemas.js.map +1 -0
  13. package/dist/esm/files/agent-file-formats.d.ts +99 -0
  14. package/dist/esm/files/agent-file-formats.d.ts.map +1 -0
  15. package/dist/esm/files/agent-file-formats.js +163 -0
  16. package/dist/esm/files/agent-file-formats.js.map +1 -0
  17. package/dist/esm/files/extension-nature-map.d.ts +12 -0
  18. package/dist/esm/files/extension-nature-map.d.ts.map +1 -0
  19. package/dist/esm/files/extension-nature-map.js +63 -0
  20. package/dist/esm/files/extension-nature-map.js.map +1 -0
  21. package/dist/esm/files/file-extensions.enum.d.ts +58 -0
  22. package/dist/esm/files/file-extensions.enum.d.ts.map +1 -0
  23. package/dist/esm/files/file-extensions.enum.js +65 -0
  24. package/dist/esm/files/file-extensions.enum.js.map +1 -0
  25. package/dist/esm/files/mime-registry.d.ts +72 -0
  26. package/dist/esm/files/mime-registry.d.ts.map +1 -0
  27. package/dist/esm/files/mime-registry.js +174 -0
  28. package/dist/esm/files/mime-registry.js.map +1 -0
  29. package/dist/esm/files/unified-registry.d.ts +112 -0
  30. package/dist/esm/files/unified-registry.d.ts.map +1 -0
  31. package/dist/esm/files/unified-registry.js +190 -0
  32. package/dist/esm/files/unified-registry.js.map +1 -0
  33. package/dist/esm/index.d.ts +29 -0
  34. package/dist/esm/index.d.ts.map +1 -0
  35. package/dist/esm/index.js +36 -0
  36. package/dist/esm/index.js.map +1 -0
  37. package/dist/esm/testing/decorated-test-schemas.d.ts +27 -0
  38. package/dist/esm/testing/decorated-test-schemas.d.ts.map +1 -0
  39. package/dist/esm/testing/decorated-test-schemas.js +26 -0
  40. package/dist/esm/testing/decorated-test-schemas.js.map +1 -0
  41. package/dist/esm/testing.d.ts +6 -0
  42. package/dist/esm/testing.d.ts.map +1 -0
  43. package/dist/esm/testing.js +6 -0
  44. package/dist/esm/testing.js.map +1 -0
  45. package/dist/esm/zod-bigdecimal.d.ts +193 -0
  46. package/dist/esm/zod-bigdecimal.d.ts.map +1 -0
  47. package/dist/esm/zod-bigdecimal.js +274 -0
  48. package/dist/esm/zod-bigdecimal.js.map +1 -0
  49. package/dist/esm/zod-code.d.ts +95 -0
  50. package/dist/esm/zod-code.d.ts.map +1 -0
  51. package/dist/esm/zod-code.js +160 -0
  52. package/dist/esm/zod-code.js.map +1 -0
  53. package/dist/esm/zod-color.d.ts +8 -0
  54. package/dist/esm/zod-color.d.ts.map +1 -0
  55. package/dist/esm/zod-color.js +88 -0
  56. package/dist/esm/zod-color.js.map +1 -0
  57. package/dist/esm/zod-decorators.types.d.ts +2207 -0
  58. package/dist/esm/zod-decorators.types.d.ts.map +1 -0
  59. package/dist/esm/zod-decorators.types.js +771 -0
  60. package/dist/esm/zod-decorators.types.js.map +1 -0
  61. package/dist/esm/zod-duration.d.ts +128 -0
  62. package/dist/esm/zod-duration.d.ts.map +1 -0
  63. package/dist/esm/zod-duration.js +174 -0
  64. package/dist/esm/zod-duration.js.map +1 -0
  65. package/dist/esm/zod-file.d.ts +219 -0
  66. package/dist/esm/zod-file.d.ts.map +1 -0
  67. package/dist/esm/zod-file.js +469 -0
  68. package/dist/esm/zod-file.js.map +1 -0
  69. package/dist/esm/zod-money.d.ts +223 -0
  70. package/dist/esm/zod-money.d.ts.map +1 -0
  71. package/dist/esm/zod-money.js +293 -0
  72. package/dist/esm/zod-money.js.map +1 -0
  73. package/dist/esm/zod-phone.d.ts +75 -0
  74. package/dist/esm/zod-phone.d.ts.map +1 -0
  75. package/dist/esm/zod-phone.js +116 -0
  76. package/dist/esm/zod-phone.js.map +1 -0
  77. package/dist/esm/zod-range.d.ts +87 -0
  78. package/dist/esm/zod-range.d.ts.map +1 -0
  79. package/dist/esm/zod-range.js +138 -0
  80. package/dist/esm/zod-range.js.map +1 -0
  81. package/dist/esm/zod-utils.shared.d.ts +783 -0
  82. package/dist/esm/zod-utils.shared.d.ts.map +1 -0
  83. package/dist/esm/zod-utils.shared.js +2647 -0
  84. package/dist/esm/zod-utils.shared.js.map +1 -0
  85. package/dist/esm/zod-versioned.d.ts +150 -0
  86. package/dist/esm/zod-versioned.d.ts.map +1 -0
  87. package/dist/esm/zod-versioned.js +172 -0
  88. package/dist/esm/zod-versioned.js.map +1 -0
  89. package/dist/esm/zod.module-override.d.ts +413 -0
  90. package/dist/esm/zod.module-override.d.ts.map +1 -0
  91. package/dist/esm/zod.module-override.js +1093 -0
  92. package/dist/esm/zod.module-override.js.map +1 -0
  93. package/dist/tsconfig.build.tsbuildinfo +1 -0
  94. package/package.json +63 -0
@@ -0,0 +1,116 @@
1
+ // ============================================================================
2
+ // PHONE SCHEMA HELPER
3
+ // ============================================================================
4
+ import { SCHEMA_METADATA } from './zod-decorators.types.js';
5
+ import { z } from 'zod';
6
+ import { addChainableMethods } from './zod.module-override.js';
7
+ import { parsePhoneNumberFromString, isValidPhoneNumber, getCountries as getCountriesFromLib, getCountryCallingCode, } from 'libphonenumber-js';
8
+ /** Returns country codes (e.g. "US", "FR") for form components. */
9
+ export function getCountries() {
10
+ return getCountriesFromLib();
11
+ }
12
+ /** Default country when parsing numbers without country code */
13
+ const DEFAULT_COUNTRY = 'US';
14
+ /**
15
+ * Parse a phone string to PhoneNumber or undefined.
16
+ *
17
+ * @param value - Raw input (E.164, national, or partial)
18
+ * @param defaultCountry - Country code (e.g. "US", "FR") for numbers without +prefix
19
+ * @returns PhoneNumber or undefined if invalid
20
+ */
21
+ export function parsePhone(value, defaultCountry) {
22
+ if (!value || typeof value !== 'string')
23
+ return undefined;
24
+ const trimmed = value.trim();
25
+ if (!trimmed)
26
+ return undefined;
27
+ const country = defaultCountry ?? DEFAULT_COUNTRY;
28
+ return parsePhoneNumberFromString(trimmed, { defaultCountry: country });
29
+ }
30
+ /**
31
+ * Validate a phone number string.
32
+ *
33
+ * @param value - Phone string to validate
34
+ * @param defaultCountry - Country code (e.g. "US", "FR") for numbers without +prefix
35
+ * @returns true if valid
36
+ */
37
+ export function isValidPhone(value, defaultCountry) {
38
+ if (!value || typeof value !== 'string')
39
+ return false;
40
+ const trimmed = value.trim();
41
+ if (!trimmed)
42
+ return false;
43
+ const country = defaultCountry ?? DEFAULT_COUNTRY;
44
+ return isValidPhoneNumber(trimmed, { defaultCountry: country });
45
+ }
46
+ /**
47
+ * Format a phone number for display.
48
+ *
49
+ * @param value - E.164 or parseable phone string
50
+ * @param defaultCountry - Country code (e.g. "US", "FR") for numbers without +prefix
51
+ * @param format - 'international' | 'national' (default: international)
52
+ * @returns Formatted string or original if unparseable
53
+ */
54
+ export function formatPhoneNumber(value, defaultCountry, format = 'international') {
55
+ const parsed = parsePhone(value, defaultCountry);
56
+ if (!parsed)
57
+ return value;
58
+ return format === 'national' ? parsed.formatNational() : parsed.formatInternational();
59
+ }
60
+ /**
61
+ * Get country calling code (e.g., "1" for US).
62
+ *
63
+ * @param country - Country code (e.g. "US", "FR")
64
+ */
65
+ export function getPhoneCountryCode(country) {
66
+ return getCountryCallingCode(country);
67
+ }
68
+ /**
69
+ * Creates a phone schema with metadata for detection and form component rendering.
70
+ * Values are stored as E.164 strings. Empty string passes validation.
71
+ *
72
+ * @param options - Configuration options for phone field
73
+ * @returns A Zod string schema with metadata for phone detection
74
+ */
75
+ export function createPhoneSchema(options = {}) {
76
+ const { defaultCountry = DEFAULT_COUNTRY } = options;
77
+ const phoneMetadata = {
78
+ isPhone: true,
79
+ defaultCountry,
80
+ };
81
+ const country = defaultCountry;
82
+ const phoneSchema = z
83
+ .string()
84
+ .transform((s) => s?.trim() ?? '')
85
+ .refine((val) => val === '' || isValidPhone(val, country), {
86
+ message: 'Invalid phone number',
87
+ })
88
+ .transform((val) => {
89
+ if (val === '')
90
+ return '';
91
+ const parsed = parsePhone(val, country);
92
+ return parsed?.format('E.164') ?? val;
93
+ });
94
+ const existingMetadata = phoneSchema[SCHEMA_METADATA] || {};
95
+ phoneSchema[SCHEMA_METADATA] = {
96
+ ...existingMetadata,
97
+ phoneConfig: phoneMetadata,
98
+ };
99
+ addChainableMethods(phoneSchema);
100
+ return phoneSchema;
101
+ }
102
+ /**
103
+ * Creates a phone schema for E.164 phone numbers.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * import { z_phone } from '@wildo-ai/zod-decorators';
108
+ *
109
+ * z_phone()
110
+ * z_phone({ defaultCountry: 'FR' })
111
+ * ```
112
+ */
113
+ export function z_phone(options) {
114
+ return createPhoneSchema(options);
115
+ }
116
+ //# sourceMappingURL=zod-phone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-phone.js","sourceRoot":"","sources":["../../src/zod-phone.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAW/E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,EAClB,YAAY,IAAI,mBAAmB,EAEnC,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,mEAAmE;AACnE,MAAM,UAAU,YAAY;IAC1B,OAAO,mBAAmB,EAAc,CAAC;AAC3C,CAAC;AAQD,gEAAgE;AAChE,MAAM,e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ZodDecorator_ParamsType } from "./zod-decorators.types.js";
2
+ import { z } from "zod";
3
+ /**
4
+ * z_range() - Creates range schemas for number, date, datetime, or time ranges.
5
+ *
6
+ * This is a standalone Zod helper function (cannot be added to frozen Zod module at runtime).
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { z_range } from '@wildo-ai/saas-models';
11
+ *
12
+ * const priceRange = z_range('number', { min: 0, max: 1000 });
13
+ * const dateRange = z_range('date');
14
+ * const timeRange = z_range('time');
15
+ *
16
+ * // With decorators (chainable)
17
+ * z_range('number').numberUI({ edit: { editMode: 'SLIDER' } })
18
+ * z_range('date', { min: new Date() }).isHidden({ edit: true })
19
+ * ```
20
+ */
21
+ /**
22
+ * Creates a range object schema with `from` and `to` fields.
23
+ * Stores metadata for easy detection and form component rendering.
24
+ *
25
+ * @param type - The type of values in the range
26
+ * @param options - Configuration options for optionality and constraints
27
+ * @returns A Zod object schema with metadata for range detection
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Simple number range (both optional)
32
+ * const priceRange = z.range('number');
33
+ * // Infers: { from?: number; to?: number }
34
+ *
35
+ * // Date range with required 'from'
36
+ * const eventRange = z.range('date', { fromOptional: false });
37
+ * // Infers: { from: Date; to?: Date }
38
+ *
39
+ * // Number range with min/max constraints
40
+ * const ageRange = z.range('number', { min: 0, max: 120 });
41
+ * // Infers: { from?: number; to?: number }
42
+ * // Metadata includes min: 0, max: 120 for UI hints
43
+ *
44
+ * // Both required with constraints
45
+ * const salaryRange = z.range('number', {
46
+ * fromOptional: false,
47
+ * toOptional: false,
48
+ * min: 0,
49
+ * });
50
+ * // Infers: { from: number; to: number }
51
+ * ```
52
+ */
53
+ export declare function createRangeSchema<T extends RangeType>(type: T, options?: RangeSchemaOptions): DecoratedRangeSchema;
54
+ /**
55
+ * Return type for range schemas - includes decorator methods.
56
+ * Note: IS_FOREIGN_KEY is not applicable to range objects.
57
+ * IS_DB_INDEXED will index internal fields (from, to) for range query optimization.
58
+ */
59
+ export type DecoratedRangeSchema = z.ZodObject<any> & {
60
+ [ZodDecorator.IS_DB_INDEXED](): DecoratedRangeSchema;
61
+ [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedRangeSchema;
62
+ [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedRangeSchema;
63
+ addDecorators(decorators: DecoratorInput[]): DecoratedRangeSchema;
64
+ };
65
+ /**
66
+ * Creates a range object schema with `from` and `to` fields.
67
+ * Named z_range to indicate it's a Zod helper function exported standalone.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * import { z_range } from '@wildo-ai/saas-models';
72
+ *
73
+ * // Simple usage
74
+ * z_range('number') // { from?: number; to?: number }
75
+ * z_range('date') // { from?: Date; to?: Date }
76
+ *
77
+ * // With options
78
+ * z_range('number', { fromOptional: false, min: 0 })
79
+ * z_range('datetime', { toOptional: false })
80
+ *
81
+ * // With decorators (chainable)
82
+ * z_range('number').numberUI({ edit: { editMode: 'SLIDER' } })
83
+ * z_range('date', { min: new Date() }).isHidden({ edit: true })
84
+ * ```
85
+ */
86
+ export declare function z_range<T extends RangeType | `${RangeType}`>(type: T, options?: RangeSchemaOptions): DecoratedRangeSchema;
87
+ //# sourceMappingURL=zod-range.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-range.d.ts","sourceRoot":"","sources":["../../src/zod-range.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAA6D,kBAAkB,EAAE,SAAS,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACzL,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,SAAS,EACnD,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,kBAAuB,GAC/B,oBAAoB,CAmEtB;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG;IACpD,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,oBAAoB,CAAC;IACrD,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,oBAAoB,CAAC;IACzG,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,oBAAoB,CAAC;IACrH,aAAa,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,oBAAoB,CAAC;CACnE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,OAAO,CAAC,CAAC,SAAS,SAAS,GAAG,GAAG,SAAS,EAAE,EAC1D,IAAI,EAAE,CAAC,EACP,OAAO,CAAC,EAAE,kBAAkB,GAC3B,oBAAoB,CAEtB"}
@@ -0,0 +1,138 @@
1
+ // ============================================================================
2
+ // RANGE SCHEMA HELPER
3
+ // ============================================================================
4
+ import { SCHEMA_METADATA, RangeType, ZodDecorator } from "./zod-decorators.types.js";
5
+ import { z } from "zod";
6
+ import { addChainableMethods } from "./zod.module-override.js";
7
+ import { BigDecimalValueSchema } from "./zod-bigdecimal.js";
8
+ import { MoneyValueSchema } from "./zod-money.js";
9
+ /**
10
+ * z_range() - Creates range schemas for number, date, datetime, or time ranges.
11
+ *
12
+ * This is a standalone Zod helper function (cannot be added to frozen Zod module at runtime).
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { z_range } from '@wildo-ai/saas-models';
17
+ *
18
+ * const priceRange = z_range('number', { min: 0, max: 1000 });
19
+ * const dateRange = z_range('date');
20
+ * const timeRange = z_range('time');
21
+ *
22
+ * // With decorators (chainable)
23
+ * z_range('number').numberUI({ edit: { editMode: 'SLIDER' } })
24
+ * z_range('date', { min: new Date() }).isHidden({ edit: true })
25
+ * ```
26
+ */
27
+ /**
28
+ * Creates a range object schema with `from` and `to` fields.
29
+ * Stores metadata for easy detection and form component rendering.
30
+ *
31
+ * @param type - The type of values in the range
32
+ * @param options - Configuration options for optionality and constraints
33
+ * @returns A Zod object schema with metadata for range detection
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * // Simple number range (both optional)
38
+ * const priceRange = z.range('number');
39
+ * // Infers: { from?: number; to?: number }
40
+ *
41
+ * // Date range with required 'from'
42
+ * const eventRange = z.range('date', { fromOptional: false });
43
+ * // Infers: { from: Date; to?: Date }
44
+ *
45
+ * // Number range with min/max constraints
46
+ * const ageRange = z.range('number', { min: 0, max: 120 });
47
+ * // Infers: { from?: number; to?: number }
48
+ * // Metadata includes min: 0, max: 120 for UI hints
49
+ *
50
+ * // Both required with constraints
51
+ * const salaryRange = z.range('number', {
52
+ * fromOptional: false,
53
+ * toOptional: false,
54
+ * min: 0,
55
+ * });
56
+ * // Infers: { from: number; to: number }
57
+ * ```
58
+ */
59
+ export function createRangeSchema(type, options = {}) {
60
+ const { fromOptional = true, toOptional = true, min, max, } = options;
61
+ // Create the base schema for the value type
62
+ let baseSchema;
63
+ switch (type) {
64
+ case RangeType.NUMBER:
65
+ baseSchema = z.number();
66
+ break;
67
+ case RangeType.DATE:
68
+ baseSchema = z.date();
69
+ break;
70
+ case RangeType.DATETIME:
71
+ baseSchema = z.iso.datetime();
72
+ break;
73
+ case RangeType.TIME:
74
+ baseSchema = z.iso.time();
75
+ break;
76
+ case RangeType.BIGDECIMAL:
77
+ baseSchema = BigDecimalValueSchema;
78
+ break;
79
+ case RangeType.MONEY:
80
+ baseSchema = MoneyValueSchema;
81
+ break;
82
+ default:
83
+ throw new Error(`Unknown range type: ${type}`);
84
+ }
85
+ // Create from/to schemas based on optionality
86
+ const fromSchema = fromOptional ? baseSchema.optional() : baseSchema;
87
+ const toSchema = toOptional ? baseSchema.optional() : baseSchema;
88
+ // Create the object schema
89
+ const rangeSchema = z.object({
90
+ from: fromSchema,
91
+ to: toSchema,
92
+ });
93
+ // Store range metadata in SCHEMA_METADATA.rangeConfig
94
+ const rangeMetadata = {
95
+ isRange: true,
96
+ type,
97
+ fromOptional,
98
+ toOptional,
99
+ ...(min !== undefined && { min }),
100
+ ...(max !== undefined && { max }),
101
+ };
102
+ // Initialize or extend SCHEMA_METADATA with range config
103
+ const existingMetadata = rangeSchema[SCHEMA_METADATA] || {};
104
+ rangeSchema[SCHEMA_METADATA] = {
105
+ ...existingMetadata,
106
+ rangeType: type,
107
+ rangeConfig: rangeMetadata,
108
+ };
109
+ // Add chainable decorator methods to the range schema instance
110
+ // This allows: z_range('number').numberUI({ edit: { editMode: 'SLIDER' } }).isHidden()
111
+ addChainableMethods(rangeSchema);
112
+ return rangeSchema;
113
+ }
114
+ /**
115
+ * Creates a range object schema with `from` and `to` fields.
116
+ * Named z_range to indicate it's a Zod helper function exported standalone.
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * import { z_range } from '@wildo-ai/saas-models';
121
+ *
122
+ * // Simple usage
123
+ * z_range('number') // { from?: number; to?: number }
124
+ * z_range('date') // { from?: Date; to?: Date }
125
+ *
126
+ * // With options
127
+ * z_range('number', { fromOptional: false, min: 0 })
128
+ * z_range('datetime', { toOptional: false })
129
+ *
130
+ * // With decorators (chainable)
131
+ * z_range('number').numberUI({ edit: { editMode: 'SLIDER' } })
132
+ * z_range('date', { min: new Date() }).isHidden({ edit: true })
133
+ * ```
134
+ */
135
+ export function z_range(type, options) {
136
+ return createRangeSchema(type, options);
137
+ }
138
+ //# sourceMappingURL=zod-range.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-range.js","sourceRoot":"","sources":["../../src/zod-range.ts"],"names":[],"mappings":"AACA,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E,OAAO,EAAkB,eAAe,EAAgE,SAAS,EAAE,YAAY,EA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