@wildo-ai/zod-decorators 1.1.3 → 1.1.5

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 (57) hide show
  1. package/dist/esm/files/agent-file-formats.d.ts +51 -37
  2. package/dist/esm/files/agent-file-formats.d.ts.map +1 -1
  3. package/dist/esm/files/agent-file-formats.js +54 -47
  4. package/dist/esm/files/agent-file-formats.js.map +1 -1
  5. package/dist/esm/files/unified-registry.d.ts +2 -2
  6. package/dist/esm/files/unified-registry.js +1 -1
  7. package/dist/esm/files/unified-registry.js.map +1 -1
  8. package/dist/esm/index.d.ts +1 -0
  9. package/dist/esm/index.d.ts.map +1 -1
  10. package/dist/esm/index.js +1 -0
  11. package/dist/esm/index.js.map +1 -1
  12. package/dist/esm/testing.d.ts +11 -0
  13. package/dist/esm/testing.d.ts.map +1 -1
  14. package/dist/esm/testing.js +11 -0
  15. package/dist/esm/testing.js.map +1 -1
  16. package/dist/esm/zod-address.d.ts +146 -0
  17. package/dist/esm/zod-address.d.ts.map +1 -0
  18. package/dist/esm/zod-address.js +176 -0
  19. package/dist/esm/zod-address.js.map +1 -0
  20. package/dist/esm/zod-code.d.ts +2 -0
  21. package/dist/esm/zod-code.d.ts.map +1 -1
  22. package/dist/esm/zod-code.js.map +1 -1
  23. package/dist/esm/zod-decorators.types.d.ts +275 -23
  24. package/dist/esm/zod-decorators.types.d.ts.map +1 -1
  25. package/dist/esm/zod-decorators.types.js +152 -4
  26. package/dist/esm/zod-decorators.types.js.map +1 -1
  27. package/dist/esm/zod-duration.d.ts +2 -0
  28. package/dist/esm/zod-duration.d.ts.map +1 -1
  29. package/dist/esm/zod-duration.js.map +1 -1
  30. package/dist/esm/zod-file.d.ts +70 -4
  31. package/dist/esm/zod-file.d.ts.map +1 -1
  32. package/dist/esm/zod-file.js +85 -64
  33. package/dist/esm/zod-file.js.map +1 -1
  34. package/dist/esm/zod-money.d.ts +2 -0
  35. package/dist/esm/zod-money.d.ts.map +1 -1
  36. package/dist/esm/zod-money.js.map +1 -1
  37. package/dist/esm/zod-phone.d.ts +8 -0
  38. package/dist/esm/zod-phone.d.ts.map +1 -1
  39. package/dist/esm/zod-phone.js +6 -1
  40. package/dist/esm/zod-phone.js.map +1 -1
  41. package/dist/esm/zod-utils.shared.d.ts +311 -9
  42. package/dist/esm/zod-utils.shared.d.ts.map +1 -1
  43. package/dist/esm/zod-utils.shared.js +898 -86
  44. package/dist/esm/zod-utils.shared.js.map +1 -1
  45. package/dist/esm/zod-versioned.d.ts.map +1 -1
  46. package/dist/esm/zod-versioned.js.map +1 -1
  47. package/dist/esm/zod.module-override.d.ts +27 -1
  48. package/dist/esm/zod.module-override.d.ts.map +1 -1
  49. package/dist/esm/zod.module-override.js +52 -7
  50. package/dist/esm/zod.module-override.js.map +1 -1
  51. package/dist/tsconfig.build.tsbuildinfo +1 -1
  52. package/package.json +2 -7
  53. package/dist/esm/.native.tsbuildinfo +0 -1
  54. package/dist/esm/companion-exports.d.ts +0 -8
  55. package/dist/esm/companion-exports.d.ts.map +0 -1
  56. package/dist/esm/companion-exports.js +0 -8
  57. package/dist/esm/companion-exports.js.map +0 -1
@@ -0,0 +1,146 @@
1
+ import { AddressSchemaOptions, DecoratorInput, SummaryFieldParams, ZodDecorator, ZodDecorator_ParamsType } from './zod-decorators.types';
2
+ import { z } from 'zod';
3
+ /** A point on the globe, in decimal degrees. */
4
+ export interface AddressCoordinates {
5
+ /** -90 (south pole) to 90 (north pole). */
6
+ latitude: number;
7
+ /** -180 to 180. */
8
+ longitude: number;
9
+ }
10
+ /**
11
+ * A structured postal address.
12
+ *
13
+ * The part names are the ones the framework's existing `AddressSchema` already uses (organisation
14
+ * profiles), so an application meets ONE address vocabulary rather than two. `postalCode` is optional
15
+ * because not every country issues one.
16
+ */
17
+ export interface AddressValue {
18
+ line1: string;
19
+ line2?: string;
20
+ city: string;
21
+ /** Region, state, province or county — whatever the country calls its first subdivision. */
22
+ state?: string;
23
+ postalCode?: string;
24
+ /** ISO 3166-1 alpha-2, stored uppercase. */
25
+ country: string;
26
+ /** An optional geocode. It does NOT take part in identity — see {@link addressComparisonKey}. */
27
+ coordinates?: AddressCoordinates;
28
+ }
29
+ /**
30
+ * The parts of an address value, named once so the factory, the form control and the error routing
31
+ * agree. Each member's value is the key it has in {@link AddressValue}.
32
+ */
33
+ export declare enum AddressPart {
34
+ /** Street and number. Required. */
35
+ LINE1 = "line1",
36
+ /** Building, floor, apartment. Optional. */
37
+ LINE2 = "line2",
38
+ /** Town or city. Required. */
39
+ CITY = "city",
40
+ /** The country's first subdivision (state, province, region, county). Optional. */
41
+ STATE = "state",
42
+ /** Optional because not every country issues one. */
43
+ POSTAL_CODE = "postalCode",
44
+ /** ISO 3166-1 alpha-2. Required. */
45
+ COUNTRY = "country"
46
+ }
47
+ /** The two halves of the optional geocode. Each member's value is its key in {@link AddressCoordinates}. */
48
+ export declare enum AddressCoordinatePart {
49
+ LATITUDE = "latitude",
50
+ LONGITUDE = "longitude"
51
+ }
52
+ /**
53
+ * The dotted path of every editable part inside an address value — the paths a validation issue is
54
+ * reported at (`city`, `coordinates.longitude`). A form routes each part's error to its own control
55
+ * by these, instead of summarising a nested error as one message for the whole field.
56
+ */
57
+ export declare function listAddressPartPaths(): string[];
58
+ /**
59
+ * The canonical spelling of one free-text address part: trimmed, with inner whitespace collapsed to a
60
+ * single space. Applied on parse, so a stored value never carries the typist's accidental spacing.
61
+ */
62
+ export declare function normalizeAddressText(value: string): string;
63
+ /** The canonical spelling of a country code: trimmed and uppercased. */
64
+ export declare function normalizeAddressCountry(value: string): string;
65
+ export declare const AddressCoordinatesSchema: z.ZodObject<{
66
+ latitude: z.ZodNumber;
67
+ longitude: z.ZodNumber;
68
+ }>;
69
+ /**
70
+ * A key under which two SPELLINGS of one address compare equal.
71
+ *
72
+ * Country and postal code are compared exactly after uppercasing (and, for the postal code, removing
73
+ * spaces: `75 002` and `75002` are one code). Every free-text part is compared after case-folding,
74
+ * stripping diacritics and treating any run of punctuation or whitespace as one separator — so
75
+ * `12 Rue de La Paix` and `12 rue de la paix` agree, and `Saint-Étienne` matches `saint etienne`.
76
+ *
77
+ * Coordinates are deliberately NOT part of the key: a geocode describes where a place is, and two
78
+ * geocoders returning slightly different points for one address must not make it two addresses.
79
+ *
80
+ * What it does NOT do, and cannot without a provider (#394): recognise an ABBREVIATION (`rue` vs `r.`),
81
+ * a differently SPLIT value (postal code and city typed into `line1`), or two formats of one street
82
+ * number (`12bis` vs `12 bis`). It recognises spelling, not meaning.
83
+ */
84
+ export declare function addressComparisonKey(value: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>): string;
85
+ /** Whether two addresses are the same place spelled differently (see {@link addressComparisonKey}). */
86
+ export declare function isSameAddress(left: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>, right: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>): boolean;
87
+ export type AddressSchemaShape = {
88
+ line1: z.ZodString;
89
+ line2: z.ZodOptional<z.ZodString>;
90
+ city: z.ZodString;
91
+ state: z.ZodOptional<z.ZodString>;
92
+ postalCode: z.ZodOptional<z.ZodString>;
93
+ country: z.ZodString;
94
+ coordinates: z.ZodOptional<typeof AddressCoordinatesSchema>;
95
+ };
96
+ /**
97
+ * @wildo_source:part:start zod.factories.address facet:layer:shared facet:family:schema-factory
98
+ *
99
+ * z_address() - Creates a structured postal address field.
100
+ *
101
+ * The value is `{ line1, line2?, city, state?, postalCode?, country, coordinates? }`: a parsed,
102
+ * country-aware value the framework renders with its own form and display fields, instead of an
103
+ * opaque `z.string()` nothing can validate, normalise or compare.
104
+ *
105
+ * - Free-text parts are normalised on parse (trimmed, inner whitespace collapsed).
106
+ * - `country` is an ISO 3166-1 alpha-2 code, uppercased on parse; `countriesAllowed` restricts it.
107
+ * - `coordinates` is an optional `{ latitude, longitude }` pair; `withCoordinates` offers it in the form.
108
+ * - `addressComparisonKey` / `isSameAddress` (same package) tell whether two values are one place
109
+ * spelled differently.
110
+ *
111
+ * An address is personal data. Declare its data category and erasure treatment on the field like any
112
+ * other personal field: this factory does not decide either for you.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * import { z_address } from '@wildo-ai/zod-decorators';
117
+ *
118
+ * const shippingAddress = z_address();
119
+ * const siteAddress = z_address({ withCoordinates: true, countriesAllowed: ['FR', 'BE'], defaultCountry: 'FR' });
120
+ * ```
121
+ */
122
+ export declare function createAddressSchema(options?: AddressSchemaOptions): DecoratedAddressSchema;
123
+ /**
124
+ * Return type for address schemas — includes the decorators applicable to a `ZodObject`.
125
+ *
126
+ * No address-specific UI or SPEC decorator exists yet: the form and display fields render from the
127
+ * metadata alone. Adding one later is additive.
128
+ */
129
+ export type DecoratedAddressSchema = z.ZodObject<AddressSchemaShape> & {
130
+ [ZodDecorator.IS_DB_INDEXED](): DecoratedAddressSchema;
131
+ [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedAddressSchema;
132
+ [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedAddressSchema;
133
+ [ZodDecorator.IS_SUMMARY_FIELD](params?: SummaryFieldParams): DecoratedAddressSchema;
134
+ [ZodDecorator.IS_BACKEND_ONLY](params?: ZodDecorator_ParamsType[ZodDecorator.IS_BACKEND_ONLY]): DecoratedAddressSchema;
135
+ [ZodDecorator.IS_WRITE_ONLY_SECRET](params?: ZodDecorator_ParamsType[ZodDecorator.IS_WRITE_ONLY_SECRET]): DecoratedAddressSchema;
136
+ [ZodDecorator.EXCLUDE_FROM_CREATE](): DecoratedAddressSchema;
137
+ [ZodDecorator.EXCLUDE_FROM_UPDATE](): DecoratedAddressSchema;
138
+ addDecorators(decorators: DecoratorInput[]): DecoratedAddressSchema;
139
+ };
140
+ /**
141
+ * Creates a structured postal address schema. Named z_address to indicate it is a Zod helper exported
142
+ * standalone, like `z_money` and `z_phone`.
143
+ */
144
+ export declare function z_address(options?: AddressSchemaOptions): DecoratedAddressSchema;
145
+ /** @wildo_source:part:end zod.factories.address */
146
+ //# sourceMappingURL=zod-address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-address.d.ts","sourceRoot":"","sources":["../../../src/zod-address.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,oBAAoB,EAEpB,cAAc,EAEd,kBAAkB,EAClB,YAAY,EACZ,uBAAuB,EACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,gDAAgD;AAChD,MAAM,WAAW,kBAAkB;IACjC,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,4FAA4F;IAC5F,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,iGAAiG;IACjG,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED;;;GAGG;AACH,oBAAY,WAAW;IACrB,mCAAmC;IACnC,KAAK,UAAU;IACf,4CAA4C;IAC5C,KAAK,UAAU;IACf,8BAA8B;IAC9B,IAAI,SAAS;IACb,mFAAmF;IACnF,KAAK,UAAU;IACf,qDAAqD;IACrD,WAAW,eAAe;IAC1B,oCAAoC;IACpC,OAAO,YAAY;CACpB;AAED,4GAA4G;AAC5G,oBAAY,qBAAqB;IAC/B,QAAQ,aAAa;IACrB,SAAS,cAAc;CACxB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAE/C;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CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,sBAAsB,CAuD9F;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,GAAG;IACrE,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,sBAAsB,CAAC;IACvD,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,sBAAsB,CAAC;IAC3G,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,sBAAsB,CAAC;IACvH,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,sBAAsB,CAAC;IACrF,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,eAAe,CAAC,GAAG,sBAAsB,CAAC;IACvH,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,EAAE,uBAAuB,CAAC,YAAY,CAAC,oBAAoB,CAAC,GAAG,sBAAsB,CAAC;IACjI,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,sBAAsB,CAAC;IAC7D,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,sBAAsB,CAAC;IAC7D,aAAa,CAAC,UAAU,EAAE,cAAc,EAAE,GAAG,sBAAsB,CAAC;CACrE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,sBAAsB,CAEhF;AACD,mDAAmD"}
@@ -0,0 +1,176 @@
1
+ // ============================================================================
2
+ // ADDRESS SCHEMA HELPER (#561)
3
+ // ============================================================================
4
+ import { SCHEMA_METADATA, ZodDecorator, } from './zod-decorators.types.js';
5
+ import { z } from 'zod';
6
+ import { addChainableMethods } from './zod.module-override.js';
7
+ /**
8
+ * The parts of an address value, named once so the factory, the form control and the error routing
9
+ * agree. Each member's value is the key it has in {@link AddressValue}.
10
+ */
11
+ export var AddressPart;
12
+ (function (AddressPart) {
13
+ /** Street and number. Required. */
14
+ AddressPart["LINE1"] = "line1";
15
+ /** Building, floor, apartment. Optional. */
16
+ AddressPart["LINE2"] = "line2";
17
+ /** Town or city. Required. */
18
+ AddressPart["CITY"] = "city";
19
+ /** The country's first subdivision (state, province, region, county). Optional. */
20
+ AddressPart["STATE"] = "state";
21
+ /** Optional because not every country issues one. */
22
+ AddressPart["POSTAL_CODE"] = "postalCode";
23
+ /** ISO 3166-1 alpha-2. Required. */
24
+ AddressPart["COUNTRY"] = "country";
25
+ })(AddressPart || (AddressPart = {}));
26
+ /** The two halves of the optional geocode. Each member's value is its key in {@link AddressCoordinates}. */
27
+ export var AddressCoordinatePart;
28
+ (function (AddressCoordinatePart) {
29
+ AddressCoordinatePart["LATITUDE"] = "latitude";
30
+ AddressCoordinatePart["LONGITUDE"] = "longitude";
31
+ })(AddressCoordinatePart || (AddressCoordinatePart = {}));
32
+ /**
33
+ * The dotted path of every editable part inside an address value — the paths a validation issue is
34
+ * reported at (`city`, `coordinates.longitude`). A form routes each part's error to its own control
35
+ * by these, instead of summarising a nested error as one message for the whole field.
36
+ */
37
+ export function listAddressPartPaths() {
38
+ return [...Object.values(AddressPart), ...Object.values(AddressCoordinatePart).map((part) => `coordinates.${part}`)];
39
+ }
40
+ const ISO_COUNTRY_CODE_PATTERN = /^[A-Z]{2}$/;
41
+ /**
42
+ * The canonical spelling of one free-text address part: trimmed, with inner whitespace collapsed to a
43
+ * single space. Applied on parse, so a stored value never carries the typist's accidental spacing.
44
+ */
45
+ export function normalizeAddressText(value) {
46
+ return value.trim().replace(/\s+/g, ' ');
47
+ }
48
+ /** The canonical spelling of a country code: trimmed and uppercased. */
49
+ export function normalizeAddressCountry(value) {
50
+ return value.trim().toUpperCase();
51
+ }
52
+ export const AddressCoordinatesSchema = z.object({
53
+ latitude: z.number().min(-90).max(90),
54
+ longitude: z.number().min(-180).max(180),
55
+ });
56
+ /**
57
+ * A key under which two SPELLINGS of one address compare equal.
58
+ *
59
+ * Country and postal code are compared exactly after uppercasing (and, for the postal code, removing
60
+ * spaces: `75 002` and `75002` are one code). Every free-text part is compared after case-folding,
61
+ * stripping diacritics and treating any run of punctuation or whitespace as one separator — so
62
+ * `12 Rue de La Paix` and `12 rue de la paix` agree, and `Saint-Étienne` matches `saint etienne`.
63
+ *
64
+ * Coordinates are deliberately NOT part of the key: a geocode describes where a place is, and two
65
+ * geocoders returning slightly different points for one address must not make it two addresses.
66
+ *
67
+ * What it does NOT do, and cannot without a provider (#394): recognise an ABBREVIATION (`rue` vs `r.`),
68
+ * a differently SPLIT value (postal code and city typed into `line1`), or two formats of one street
69
+ * number (`12bis` vs `12 bis`). It recognises spelling, not meaning.
70
+ */
71
+ export function addressComparisonKey(value) {
72
+ const fold = (part) => (part ?? '')
73
+ .normalize('NFKD')
74
+ .replace(/[\u0300-\u036f]/g, '')
75
+ .toLowerCase()
76
+ .replace(/[^\p{L}\p{N}]+/gu, ' ')
77
+ .trim();
78
+ const postalCode = (value.postalCode ?? '').replace(/\s+/g, '').toUpperCase();
79
+ return [
80
+ normalizeAddressCountry(value.country),
81
+ postalCode,
82
+ fold(value.city),
83
+ fold(value.state),
84
+ fold(value.line1),
85
+ fold(value.line2),
86
+ ].join('|');
87
+ }
88
+ /** Whether two addresses are the same place spelled differently (see {@link addressComparisonKey}). */
89
+ export function isSameAddress(left, right) {
90
+ return addressComparisonKey(left) === addressComparisonKey(right);
91
+ }
92
+ /**
93
+ * @wildo_source:part:start zod.factories.address facet:layer:shared facet:family:schema-factory
94
+ *
95
+ * z_address() - Creates a structured postal address field.
96
+ *
97
+ * The value is `{ line1, line2?, city, state?, postalCode?, country, coordinates? }`: a parsed,
98
+ * country-aware value the framework renders with its own form and display fields, instead of an
99
+ * opaque `z.string()` nothing can validate, normalise or compare.
100
+ *
101
+ * - Free-text parts are normalised on parse (trimmed, inner whitespace collapsed).
102
+ * - `country` is an ISO 3166-1 alpha-2 code, uppercased on parse; `countriesAllowed` restricts it.
103
+ * - `coordinates` is an optional `{ latitude, longitude }` pair; `withCoordinates` offers it in the form.
104
+ * - `addressComparisonKey` / `isSameAddress` (same package) tell whether two values are one place
105
+ * spelled differently.
106
+ *
107
+ * An address is personal data. Declare its data category and erasure treatment on the field like any
108
+ * other personal field: this factory does not decide either for you.
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * import { z_address } from '@wildo-ai/zod-decorators';
113
+ *
114
+ * const shippingAddress = z_address();
115
+ * const siteAddress = z_address({ withCoordinates: true, countriesAllowed: ['FR', 'BE'], defaultCountry: 'FR' });
116
+ * ```
117
+ */
118
+ export function createAddressSchema(options = {}) {
119
+ const countriesAllowed = options.countriesAllowed?.map(normalizeAddressCountry);
120
+ for (const code of countriesAllowed ?? []) {
121
+ if (!ISO_COUNTRY_CODE_PATTERN.test(code)) {
122
+ throw new Error(`[z_address] countriesAllowed contains "${code}", which is not an ISO 3166-1 alpha-2 code.`);
123
+ }
124
+ }
125
+ const defaultCountry = options.defaultCountry === undefined ? undefined : normalizeAddressCountry(options.defaultCountry);
126
+ if (defaultCountry !== undefined) {
127
+ // Refused at DECLARATION, not at first render: a form pre-selecting a country the value may not
128
+ // name would be an error the author could only discover by filling the form.
129
+ if (!ISO_COUNTRY_CODE_PATTERN.test(defaultCountry)) {
130
+ throw new Error(`[z_address] defaultCountry "${options.defaultCountry}" is not an ISO 3166-1 alpha-2 code.`);
131
+ }
132
+ if (countriesAllowed && countriesAllowed.length > 0 && !countriesAllowed.includes(defaultCountry)) {
133
+ throw new Error(`[z_address] defaultCountry "${defaultCountry}" is not among countriesAllowed (${countriesAllowed.join(', ')}).`);
134
+ }
135
+ }
136
+ const text = () => z.string().overwrite(normalizeAddressText);
137
+ let country = z.string()
138
+ .overwrite(normalizeAddressCountry)
139
+ .regex(ISO_COUNTRY_CODE_PATTERN, { error: 'Country must be an ISO 3166-1 alpha-2 code' });
140
+ if (countriesAllowed && countriesAllowed.length > 0) {
141
+ country = country.refine((code) => countriesAllowed.includes(code), {
142
+ error: `Country must be one of: ${countriesAllowed.join(', ')}`,
143
+ });
144
+ }
145
+ const addressSchema = z.object({
146
+ line1: text().min(1, { error: 'Address line 1 is required' }).max(100),
147
+ line2: text().max(100).optional(),
148
+ city: text().min(1, { error: 'City is required' }).max(50),
149
+ state: text().max(50).optional(),
150
+ postalCode: text().max(20).optional(),
151
+ country,
152
+ coordinates: AddressCoordinatesSchema.optional(),
153
+ });
154
+ const addressMetadata = {
155
+ isAddress: true,
156
+ withCoordinates: options.withCoordinates === true,
157
+ ...(countriesAllowed && countriesAllowed.length > 0 && { countriesAllowed }),
158
+ ...(defaultCountry !== undefined && { defaultCountry }),
159
+ };
160
+ const existingMetadata = addressSchema[SCHEMA_METADATA] || {};
161
+ addressSchema[SCHEMA_METADATA] = {
162
+ ...existingMetadata,
163
+ addressConfig: addressMetadata,
164
+ };
165
+ addChainableMethods(addressSchema);
166
+ return addressSchema;
167
+ }
168
+ /**
169
+ * Creates a structured postal address schema. Named z_address to indicate it is a Zod helper exported
170
+ * standalone, like `z_money` and `z_phone`.
171
+ */
172
+ export function z_address(options) {
173
+ return createAddressSchema(options);
174
+ }
175
+ /** @wildo_source:part:end zod.factories.address */
176
+ //# sourceMappingURL=zod-address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zod-address.js","sourceRoot":"","sources":["../../../src/zod-address.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,+BAA+B;AAC/B,+EAA+E;AAE/E,OAAO,EAKL,eAAe,EAEf,YAAY,GAEb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,M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AAC;AACjD,CAAC;AAoBD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,OAA8B;IACtD,OAAO,mBAAmB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AACD,mDAAmD","sourcesContent":["// ============================================================================\n// ADDRESS SCHEMA HELPER (#561)\n// ============================================================================\n\nimport {\n AddressSchemaMetadata,\n AddressSchemaOptions,\n CustomFieldMetadata,\n DecoratorInput,\n SCHEMA_METADATA,\n SummaryFieldParams,\n ZodDecorator,\n ZodDecorator_ParamsType,\n} from './zod-decorators.types';\nimport { z } from 'zod';\nimport { addChainableMethods } from './zod.module-override';\n\n/** A point on the globe, in decimal degrees. */\nexport interface AddressCoordinates {\n /** -90 (south pole) to 90 (north pole). */\n latitude: number;\n /** -180 to 180. */\n longitude: number;\n}\n\n/**\n * A structured postal address.\n *\n * The part names are the ones the framework's existing `AddressSchema` already uses (organisation\n * profiles), so an application meets ONE address vocabulary rather than two. `postalCode` is optional\n * because not every country issues one.\n */\nexport interface AddressValue {\n line1: string;\n line2?: string;\n city: string;\n /** Region, state, province or county — whatever the country calls its first subdivision. */\n state?: string;\n postalCode?: string;\n /** ISO 3166-1 alpha-2, stored uppercase. */\n country: string;\n /** An optional geocode. It does NOT take part in identity — see {@link addressComparisonKey}. */\n coordinates?: AddressCoordinates;\n}\n\n/**\n * The parts of an address value, named once so the factory, the form control and the error routing\n * agree. Each member's value is the key it has in {@link AddressValue}.\n */\nexport enum AddressPart {\n /** Street and number. Required. */\n LINE1 = 'line1',\n /** Building, floor, apartment. Optional. */\n LINE2 = 'line2',\n /** Town or city. Required. */\n CITY = 'city',\n /** The country's first subdivision (state, province, region, county). Optional. */\n STATE = 'state',\n /** Optional because not every country issues one. */\n POSTAL_CODE = 'postalCode',\n /** ISO 3166-1 alpha-2. Required. */\n COUNTRY = 'country',\n}\n\n/** The two halves of the optional geocode. Each member's value is its key in {@link AddressCoordinates}. */\nexport enum AddressCoordinatePart {\n LATITUDE = 'latitude',\n LONGITUDE = 'longitude',\n}\n\n/**\n * The dotted path of every editable part inside an address value — the paths a validation issue is\n * reported at (`city`, `coordinates.longitude`). A form routes each part's error to its own control\n * by these, instead of summarising a nested error as one message for the whole field.\n */\nexport function listAddressPartPaths(): string[] {\n return [...Object.values(AddressPart), ...Object.values(AddressCoordinatePart).map((part) => `coordinates.${part}`)];\n}\n\nconst ISO_COUNTRY_CODE_PATTERN = /^[A-Z]{2}$/;\n\n/**\n * The canonical spelling of one free-text address part: trimmed, with inner whitespace collapsed to a\n * single space. Applied on parse, so a stored value never carries the typist's accidental spacing.\n */\nexport function normalizeAddressText(value: string): string {\n return value.trim().replace(/\\s+/g, ' ');\n}\n\n/** The canonical spelling of a country code: trimmed and uppercased. */\nexport function normalizeAddressCountry(value: string): string {\n return value.trim().toUpperCase();\n}\n\nexport const AddressCoordinatesSchema: z.ZodObject<{ latitude: z.ZodNumber; longitude: z.ZodNumber }> = z.object({\n latitude: z.number().min(-90).max(90),\n longitude: z.number().min(-180).max(180),\n});\n\n/**\n * A key under which two SPELLINGS of one address compare equal.\n *\n * Country and postal code are compared exactly after uppercasing (and, for the postal code, removing\n * spaces: `75 002` and `75002` are one code). Every free-text part is compared after case-folding,\n * stripping diacritics and treating any run of punctuation or whitespace as one separator — so\n * `12 Rue de La Paix` and `12 rue de la paix` agree, and `Saint-Étienne` matches `saint etienne`.\n *\n * Coordinates are deliberately NOT part of the key: a geocode describes where a place is, and two\n * geocoders returning slightly different points for one address must not make it two addresses.\n *\n * What it does NOT do, and cannot without a provider (#394): recognise an ABBREVIATION (`rue` vs `r.`),\n * a differently SPLIT value (postal code and city typed into `line1`), or two formats of one street\n * number (`12bis` vs `12 bis`). It recognises spelling, not meaning.\n */\nexport function addressComparisonKey(\n value: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>,\n): string {\n const fold = (part: string | undefined): string => (part ?? '')\n .normalize('NFKD')\n .replace(/[\\u0300-\\u036f]/g, '')\n .toLowerCase()\n .replace(/[^\\p{L}\\p{N}]+/gu, ' ')\n .trim();\n const postalCode = (value.postalCode ?? '').replace(/\\s+/g, '').toUpperCase();\n return [\n normalizeAddressCountry(value.country),\n postalCode,\n fold(value.city),\n fold(value.state),\n fold(value.line1),\n fold(value.line2),\n ].join('|');\n}\n\n/** Whether two addresses are the same place spelled differently (see {@link addressComparisonKey}). */\nexport function isSameAddress(\n left: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>,\n right: Pick<AddressValue, 'line1' | 'line2' | 'city' | 'state' | 'postalCode' | 'country'>,\n): boolean {\n return addressComparisonKey(left) === addressComparisonKey(right);\n}\n\nexport type AddressSchemaShape = {\n line1: z.ZodString;\n line2: z.ZodOptional<z.ZodString>;\n city: z.ZodString;\n state: z.ZodOptional<z.ZodString>;\n postalCode: z.ZodOptional<z.ZodString>;\n country: z.ZodString;\n coordinates: z.ZodOptional<typeof AddressCoordinatesSchema>;\n};\n\n/**\n * @wildo_source:part:start zod.factories.address facet:layer:shared facet:family:schema-factory\n *\n * z_address() - Creates a structured postal address field.\n *\n * The value is `{ line1, line2?, city, state?, postalCode?, country, coordinates? }`: a parsed,\n * country-aware value the framework renders with its own form and display fields, instead of an\n * opaque `z.string()` nothing can validate, normalise or compare.\n *\n * - Free-text parts are normalised on parse (trimmed, inner whitespace collapsed).\n * - `country` is an ISO 3166-1 alpha-2 code, uppercased on parse; `countriesAllowed` restricts it.\n * - `coordinates` is an optional `{ latitude, longitude }` pair; `withCoordinates` offers it in the form.\n * - `addressComparisonKey` / `isSameAddress` (same package) tell whether two values are one place\n * spelled differently.\n *\n * An address is personal data. Declare its data category and erasure treatment on the field like any\n * other personal field: this factory does not decide either for you.\n *\n * @example\n * ```typescript\n * import { z_address } from '@wildo-ai/zod-decorators';\n *\n * const shippingAddress = z_address();\n * const siteAddress = z_address({ withCoordinates: true, countriesAllowed: ['FR', 'BE'], defaultCountry: 'FR' });\n * ```\n */\nexport function createAddressSchema(options: AddressSchemaOptions = {}): DecoratedAddressSchema {\n const countriesAllowed = options.countriesAllowed?.map(normalizeAddressCountry);\n for (const code of countriesAllowed ?? []) {\n if (!ISO_COUNTRY_CODE_PATTERN.test(code)) {\n throw new Error(`[z_address] countriesAllowed contains \"${code}\", which is not an ISO 3166-1 alpha-2 code.`);\n }\n }\n const defaultCountry = options.defaultCountry === undefined ? undefined : normalizeAddressCountry(options.defaultCountry);\n if (defaultCountry !== undefined) {\n // Refused at DECLARATION, not at first render: a form pre-selecting a country the value may not\n // name would be an error the author could only discover by filling the form.\n if (!ISO_COUNTRY_CODE_PATTERN.test(defaultCountry)) {\n throw new Error(`[z_address] defaultCountry \"${options.defaultCountry}\" is not an ISO 3166-1 alpha-2 code.`);\n }\n if (countriesAllowed && countriesAllowed.length > 0 && !countriesAllowed.includes(defaultCountry)) {\n throw new Error(`[z_address] defaultCountry \"${defaultCountry}\" is not among countriesAllowed (${countriesAllowed.join(', ')}).`);\n }\n }\n\n const text = (): z.ZodString => z.string().overwrite(normalizeAddressText);\n let country: z.ZodString = z.string()\n .overwrite(normalizeAddressCountry)\n .regex(ISO_COUNTRY_CODE_PATTERN, { error: 'Country must be an ISO 3166-1 alpha-2 code' });\n if (countriesAllowed && countriesAllowed.length > 0) {\n country = country.refine((code) => countriesAllowed.includes(code), {\n error: `Country must be one of: ${countriesAllowed.join(', ')}`,\n });\n }\n\n const addressSchema = z.object({\n line1: text().min(1, { error: 'Address line 1 is required' }).max(100),\n line2: text().max(100).optional(),\n city: text().min(1, { error: 'City is required' }).max(50),\n state: text().max(50).optional(),\n postalCode: text().max(20).optional(),\n country,\n coordinates: AddressCoordinatesSchema.optional(),\n });\n\n const addressMetadata: AddressSchemaMetadata = {\n isAddress: true,\n withCoordinates: options.withCoordinates === true,\n ...(countriesAllowed && countriesAllowed.length > 0 && { countriesAllowed }),\n ...(defaultCountry !== undefined && { defaultCountry }),\n };\n\n const existingMetadata: CustomFieldMetadata = (addressSchema as any)[SCHEMA_METADATA] || {};\n (addressSchema as any)[SCHEMA_METADATA] = {\n ...existingMetadata,\n addressConfig: addressMetadata,\n };\n\n addChainableMethods(addressSchema);\n\n return addressSchema as DecoratedAddressSchema;\n}\n\n/**\n * Return type for address schemas — includes the decorators applicable to a `ZodObject`.\n *\n * No address-specific UI or SPEC decorator exists yet: the form and display fields render from the\n * metadata alone. Adding one later is additive.\n */\nexport type DecoratedAddressSchema = z.ZodObject<AddressSchemaShape> & {\n [ZodDecorator.IS_DB_INDEXED](): DecoratedAddressSchema;\n [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedAddressSchema;\n [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedAddressSchema;\n [ZodDecorator.IS_SUMMARY_FIELD](params?: SummaryFieldParams): DecoratedAddressSchema;\n [ZodDecorator.IS_BACKEND_ONLY](params?: ZodDecorator_ParamsType[ZodDecorator.IS_BACKEND_ONLY]): DecoratedAddressSchema;\n [ZodDecorator.IS_WRITE_ONLY_SECRET](params?: ZodDecorator_ParamsType[ZodDecorator.IS_WRITE_ONLY_SECRET]): DecoratedAddressSchema;\n [ZodDecorator.EXCLUDE_FROM_CREATE](): DecoratedAddressSchema;\n [ZodDecorator.EXCLUDE_FROM_UPDATE](): DecoratedAddressSchema;\n addDecorators(decorators: DecoratorInput[]): DecoratedAddressSchema;\n};\n\n/**\n * Creates a structured postal address schema. Named z_address to indicate it is a Zod helper exported\n * standalone, like `z_money` and `z_phone`.\n */\nexport function z_address(options?: AddressSchemaOptions): DecoratedAddressSchema {\n return createAddressSchema(options);\n}\n/** @wildo_source:part:end zod.factories.address */\n"]}
@@ -57,6 +57,8 @@ export type DecoratedCodeSchema = z.ZodObject<{
57
57
  language: z.ZodString;
58
58
  }> & {
59
59
  [ZodDecorator.IS_DB_INDEXED](): DecoratedCodeSchema;
60
+ /** Installed at runtime with the other chainable methods; declared here so an authored `.codeUI(…)` typechecks. */
61
+ [ZodDecorator.CODE_UI](params?: ZodDecorator_ParamsType[ZodDecorator.CODE_UI]): DecoratedCodeSchema;
60
62
  [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedCodeSchema;
61
63
  [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedCodeSchema;
62
64
  addDecorators(decorators: DecoratorInput[]): DecoratedCodeSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"zod-code.d.ts","sourceRoot":"","sources":["../../../src/zod-code.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAA4D,iBAAiB,EAAE,YAAY,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAC1L,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB,ySAOtB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC;IAAE,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;IAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAA;CAAE,CAGvF,CAAC;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,GAAE,iBAAsB,GAC9B,mBAAmB,CA6CrB;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,SAAS,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;IACrB,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC;CACvB,CAAC,GAAG;IACH,CAAC,YA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M;QACZ,MAAM,EAAE,IAAI;QACZ,GAAG,EAAE,KAAK;QACV,CAAC,EAAE,GAAG;QACN,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,KAAK;QACV,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,KAAK;QACV,OAAO,EAAE,SAAS;QAClB,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,OAAO;QACd,UAAU,EAAE,YAAY;QACxB,UAAU,EAAE,YAAY;QACxB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,YAAY;KACxB,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AACvD,CAAC","sourcesContent":["\n// ============================================================================\n// CODE SCHEMA HELPER\n// ============================================================================\n\nimport { DecoratorInput, SCHEMA_METADATA, CustomFieldMetadata, CodeSchemaMetadata, CodeSchemaOptions, CodeLanguage, ZodDecorator, ZodDecorator_ParamsType } from \"./zod-decorators.types\";\nimport { z } from \"zod\";\nimport { addChainableMethods } from \"./zod.module-override\";\n\n/**\n * Code value type - represents a code snippet with language information.\n */\nexport interface CodeValue {\n /** The code content */\n content: string;\n /** Programming language for syntax highlighting and validation */\n language: string;\n}\n\n/**\n * Common programming languages for code schema language field.\n * Can be extended with any string value.\n */\nexport const CommonCodeLanguages = [\n 'javascript', 'typescript', 'python', 'java', 'csharp', 'cpp', 'c',\n 'go', 'rust', 'ruby', 'php', 'swift', 'kotlin', 'scala',\n 'html', 'css', 'scss', 'less', 'json', 'yaml', 'xml', 'markdown',\n 'sql', 'graphql', 'bash', 'shell', 'powershell',\n 'dockerfile', 'nginx', 'apache',\n 'plaintext'\n] as const;\n\n/**\n * Zod schema for CodeValue.\n */\nexport const CodeValueSchema: z.ZodObject<{ content: z.ZodString; language: z.ZodString }> = z.object({\n content: z.string(),\n language: z.string(),\n});\n\n/**\n * @wildo_source:part:start zod.factories.code facet:layer:shared facet:family:schema-factory\n *\n * z_code() - Creates code schemas for code snippets with language.\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * const snippet = z_code();\n * const restrictedCode = z_code({\n * allowedLanguages: ['javascript', 'typescript', 'python'],\n * maxLength: 10000\n * });\n *\n * // UI props are now set via .codeUI():\n * z_code().codeUI({ defaultLanguage: 'javascript', syntaxHighlighting: true })\n * z_code().codeUI({ display: { showLineNumbers: true }, edit: { showLineNumbers: false } })\n * ```\n */\n\n/**\n * Creates a code schema with metadata for detection and form component rendering.\n *\n * @param options - Configuration options for code field\n * @returns A Zod object schema with metadata for code detection\n */\nexport function createCodeSchema(\n options: CodeSchemaOptions = {}\n): DecoratedCodeSchema {\n const {\n allowedLanguages,\n maxLength,\n minLength,\n } = options;\n\n // Create the content schema with optional length constraints\n let contentSchema = z.string();\n if (minLength !== undefined) {\n contentSchema = contentSchema.min(minLength);\n }\n if (maxLength !== undefined) {\n contentSchema = contentSchema.max(maxLength);\n }\n\n // Language is stored as a string. Allowed languages restriction is enforced\n // through codeConfig.allowedLanguages metadata - UI components read this\n // to filter available options, same pattern as money currencies.\n const languageSchema = z.string();\n\n // Create the code object schema\n const codeSchema = z.object({\n content: contentSchema,\n language: languageSchema,\n });\n\n const codeMetadata: CodeSchemaMetadata = {\n isCode: true,\n ...(allowedLanguages !== undefined && { allowedLanguages }),\n ...(maxLength !== undefined && { maxLength }),\n ...(minLength !== undefined && { minLength }),\n };\n\n // Initialize or extend SCHEMA_METADATA with code config\n const existingMetadata: CustomFieldMetadata = (codeSchema as any)[SCHEMA_METADATA] || {};\n (codeSchema as any)[SCHEMA_METADATA] = {\n ...existingMetadata,\n codeConfig: codeMetadata,\n };\n\n // Add chainable decorator methods to the code schema instance\n addChainableMethods(codeSchema);\n\n return codeSchema as unknown as DecoratedCodeSchema;\n}\n\n/**\n * Return type for code schemas - includes decorator methods.\n * IS_DB_INDEXED will index internal fields (content, language) for query optimization.\n */\nexport type DecoratedCodeSchema = z.ZodObject<{\n content: z.ZodString;\n language: z.ZodString;\n}> & {\n [ZodDecorator.IS_DB_INDEXED](): DecoratedCodeSchema;\n [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedCodeSchema;\n [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedCodeSchema;\n addDecorators(decorators: DecoratorInput[]): DecoratedCodeSchema;\n};\n\n/**\n * Creates a code schema for code snippets with language information.\n * Named z_code to indicate it's a Zod helper function exported standalone.\n *\n * Code values are stored as: { content: string, language: string }\n * - content: The actual code text\n * - language: Programming language identifier for syntax highlighting\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * // Simple usage\n * z_code() // All languages, default 'plaintext'\n *\n * // With options (structural only)\n * z_code({ allowedLanguages: ['javascript', 'typescript'] })\n * z_code({ maxLength: 5000 })\n *\n * // UI props via .codeUI()\n * z_code().codeUI({ defaultLanguage: 'typescript' })\n * z_code().codeUI({ display: { showLineNumbers: false } })\n * ```\n */\nexport function z_code(options?: CodeSchemaOptions): DecoratedCodeSchema {\n return createCodeSchema(options);\n}\n/** @wildo_source:part:end zod.factories.code */\n\n// ============================================================================\n// UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Get the display name for a code language.\n */\nexport function getLanguageDisplayName(language: CodeLanguage): string {\n const displayNames: Record<string, string> = {\n javascript: 'JavaScript',\n typescript: 'TypeScript',\n python: 'Python',\n java: 'Java',\n csharp: 'C#',\n cpp: 'C++',\n c: 'C',\n go: 'Go',\n rust: 'Rust',\n ruby: 'Ruby',\n php: 'PHP',\n swift: 'Swift',\n kotlin: 'Kotlin',\n scala: 'Scala',\n html: 'HTML',\n css: 'CSS',\n scss: 'SCSS',\n less: 'Less',\n json: 'JSON',\n yaml: 'YAML',\n xml: 'XML',\n markdown: 'Markdown',\n sql: 'SQL',\n graphql: 'GraphQL',\n bash: 'Bash',\n shell: 'Shell',\n powershell: 'PowerShell',\n dockerfile: 'Dockerfile',\n nginx: 'Nginx',\n apache: 'Apache',\n plaintext: 'Plain Text',\n };\n\n return displayNames[language] || language;\n}\n\n/**\n * Check if a language is in the common languages list.\n */\nexport function isCommonLanguage(language: string): language is typeof CommonCodeLanguages[number] {\n return CommonCodeLanguages.includes(language as any);\n}\n\n"]}
1
+ {"version":3,"file":"zod-code.js","sourceRoot":"","sources":["../../../src/zod-code.ts"],"names":[],"mappings":"AACA,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,OAAO,EAAkB,eAAe,EAA4E,YAAY,EAA2B,MAAM,wBAAwB,CAAC;AAC1L,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAY5D;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG;IAClE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO;IACvD,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;I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AAU,EAAE,YAAY;QACxB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,YAAY;KACxB,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,OAAO,mBAAmB,CAAC,QAAQ,CAAC,QAAe,CAAC,CAAC;AACvD,CAAC","sourcesContent":["\n// ============================================================================\n// CODE SCHEMA HELPER\n// ============================================================================\n\nimport { DecoratorInput, SCHEMA_METADATA, CustomFieldMetadata, CodeSchemaMetadata, CodeSchemaOptions, CodeLanguage, ZodDecorator, ZodDecorator_ParamsType } from \"./zod-decorators.types\";\nimport { z } from \"zod\";\nimport { addChainableMethods } from \"./zod.module-override\";\n\n/**\n * Code value type - represents a code snippet with language information.\n */\nexport interface CodeValue {\n /** The code content */\n content: string;\n /** Programming language for syntax highlighting and validation */\n language: string;\n}\n\n/**\n * Common programming languages for code schema language field.\n * Can be extended with any string value.\n */\nexport const CommonCodeLanguages = [\n 'javascript', 'typescript', 'python', 'java', 'csharp', 'cpp', 'c',\n 'go', 'rust', 'ruby', 'php', 'swift', 'kotlin', 'scala',\n 'html', 'css', 'scss', 'less', 'json', 'yaml', 'xml', 'markdown',\n 'sql', 'graphql', 'bash', 'shell', 'powershell',\n 'dockerfile', 'nginx', 'apache',\n 'plaintext'\n] as const;\n\n/**\n * Zod schema for CodeValue.\n */\nexport const CodeValueSchema: z.ZodObject<{ content: z.ZodString; language: z.ZodString }> = z.object({\n content: z.string(),\n language: z.string(),\n});\n\n/**\n * @wildo_source:part:start zod.factories.code facet:layer:shared facet:family:schema-factory\n *\n * z_code() - Creates code schemas for code snippets with language.\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * const snippet = z_code();\n * const restrictedCode = z_code({\n * allowedLanguages: ['javascript', 'typescript', 'python'],\n * maxLength: 10000\n * });\n *\n * // UI props are now set via .codeUI():\n * z_code().codeUI({ defaultLanguage: 'javascript', syntaxHighlighting: true })\n * z_code().codeUI({ display: { showLineNumbers: true }, edit: { showLineNumbers: false } })\n * ```\n */\n\n/**\n * Creates a code schema with metadata for detection and form component rendering.\n *\n * @param options - Configuration options for code field\n * @returns A Zod object schema with metadata for code detection\n */\nexport function createCodeSchema(\n options: CodeSchemaOptions = {}\n): DecoratedCodeSchema {\n const {\n allowedLanguages,\n maxLength,\n minLength,\n } = options;\n\n // Create the content schema with optional length constraints\n let contentSchema = z.string();\n if (minLength !== undefined) {\n contentSchema = contentSchema.min(minLength);\n }\n if (maxLength !== undefined) {\n contentSchema = contentSchema.max(maxLength);\n }\n\n // Language is stored as a string. Allowed languages restriction is enforced\n // through codeConfig.allowedLanguages metadata - UI components read this\n // to filter available options, same pattern as money currencies.\n const languageSchema = z.string();\n\n // Create the code object schema\n const codeSchema = z.object({\n content: contentSchema,\n language: languageSchema,\n });\n\n const codeMetadata: CodeSchemaMetadata = {\n isCode: true,\n ...(allowedLanguages !== undefined && { allowedLanguages }),\n ...(maxLength !== undefined && { maxLength }),\n ...(minLength !== undefined && { minLength }),\n };\n\n // Initialize or extend SCHEMA_METADATA with code config\n const existingMetadata: CustomFieldMetadata = (codeSchema as any)[SCHEMA_METADATA] || {};\n (codeSchema as any)[SCHEMA_METADATA] = {\n ...existingMetadata,\n codeConfig: codeMetadata,\n };\n\n // Add chainable decorator methods to the code schema instance\n addChainableMethods(codeSchema);\n\n return codeSchema as unknown as DecoratedCodeSchema;\n}\n\n/**\n * Return type for code schemas - includes decorator methods.\n * IS_DB_INDEXED will index internal fields (content, language) for query optimization.\n */\nexport type DecoratedCodeSchema = z.ZodObject<{\n content: z.ZodString;\n language: z.ZodString;\n}> & {\n [ZodDecorator.IS_DB_INDEXED](): DecoratedCodeSchema;\n /** Installed at runtime with the other chainable methods; declared here so an authored `.codeUI(…)` typechecks. */\n [ZodDecorator.CODE_UI](params?: ZodDecorator_ParamsType[ZodDecorator.CODE_UI]): DecoratedCodeSchema;\n [ZodDecorator.IS_HIDDEN](params?: ZodDecorator_ParamsType[ZodDecorator.IS_HIDDEN]): DecoratedCodeSchema;\n [ZodDecorator.IS_NOT_EDITABLE](params?: ZodDecorator_ParamsType[ZodDecorator.IS_NOT_EDITABLE]): DecoratedCodeSchema;\n addDecorators(decorators: DecoratorInput[]): DecoratedCodeSchema;\n};\n\n/**\n * Creates a code schema for code snippets with language information.\n * Named z_code to indicate it's a Zod helper function exported standalone.\n *\n * Code values are stored as: { content: string, language: string }\n * - content: The actual code text\n * - language: Programming language identifier for syntax highlighting\n *\n * @example\n * ```typescript\n * import { z_code } from '@wildo-ai/zod-decorators';\n *\n * // Simple usage\n * z_code() // All languages, default 'plaintext'\n *\n * // With options (structural only)\n * z_code({ allowedLanguages: ['javascript', 'typescript'] })\n * z_code({ maxLength: 5000 })\n *\n * // UI props via .codeUI()\n * z_code().codeUI({ defaultLanguage: 'typescript' })\n * z_code().codeUI({ display: { showLineNumbers: false } })\n * ```\n */\nexport function z_code(options?: CodeSchemaOptions): DecoratedCodeSchema {\n return createCodeSchema(options);\n}\n/** @wildo_source:part:end zod.factories.code */\n\n// ============================================================================\n// UTILITY FUNCTIONS\n// ============================================================================\n\n/**\n * Get the display name for a code language.\n */\nexport function getLanguageDisplayName(language: CodeLanguage): string {\n const displayNames: Record<string, string> = {\n javascript: 'JavaScript',\n typescript: 'TypeScript',\n python: 'Python',\n java: 'Java',\n csharp: 'C#',\n cpp: 'C++',\n c: 'C',\n go: 'Go',\n rust: 'Rust',\n ruby: 'Ruby',\n php: 'PHP',\n swift: 'Swift',\n kotlin: 'Kotlin',\n scala: 'Scala',\n html: 'HTML',\n css: 'CSS',\n scss: 'SCSS',\n less: 'Less',\n json: 'JSON',\n yaml: 'YAML',\n xml: 'XML',\n markdown: 'Markdown',\n sql: 'SQL',\n graphql: 'GraphQL',\n bash: 'Bash',\n shell: 'Shell',\n powershell: 'PowerShell',\n dockerfile: 'Dockerfile',\n nginx: 'Nginx',\n apache: 'Apache',\n plaintext: 'Plain Text',\n };\n\n return displayNames[language] || language;\n}\n\n/**\n * Check if a language is in the common languages list.\n */\nexport function isCommonLanguage(language: string): language is typeof CommonCodeLanguages[number] {\n return CommonCodeLanguages.includes(language as any);\n}\n\n"]}