@openpronoun/zod 0.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.
- package/README.md +58 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @openpronoun/zod
|
|
2
|
+
|
|
3
|
+
[Zod](https://zod.dev) schemas and inferred TypeScript types for the
|
|
4
|
+
[OpenPronoun](https://openpronoun.org) data model. A hand-written, idiomatic
|
|
5
|
+
mirror of the canonical [`@openpronoun/schema`](../schema) JSON Schema, kept
|
|
6
|
+
honest by a parity test that checks both validators agree across the
|
|
7
|
+
[`@openpronoun/conformance`](../conformance) fixtures.
|
|
8
|
+
|
|
9
|
+
Use this in TypeScript code that wants runtime validation plus types from one
|
|
10
|
+
import; use `@openpronoun/schema` directly when you need the portable,
|
|
11
|
+
cross-language JSON Schema.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install @openpronoun/zod zod
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`zod` is a peer dependency (v4).
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import {
|
|
25
|
+
pronounPreferenceSchema,
|
|
26
|
+
type PronounPreference,
|
|
27
|
+
} from "@openpronoun/zod";
|
|
28
|
+
|
|
29
|
+
const result = pronounPreferenceSchema.safeParse([
|
|
30
|
+
{ subjective: "she", objective: "her", possessive_adjective: "her",
|
|
31
|
+
possessive_pronoun: "hers", reflexive: "herself" },
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
if (result.success) {
|
|
35
|
+
const prefs: PronounPreference = result.data;
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Exports
|
|
40
|
+
|
|
41
|
+
Schemas: `pronounPreferenceSchema`, `pronounEntrySchema`, `pronounSetSchema`
|
|
42
|
+
(`fullPronounSetSchema`, `compactPronounSetSchema`), `specialPreferenceSchema`,
|
|
43
|
+
`customEntrySchema`, and the `SPECIAL_TYPES` tuple.
|
|
44
|
+
|
|
45
|
+
Types: `PronounPreference`, `PronounEntry`, `PronounSet`, `SpecialPreference`,
|
|
46
|
+
`CustomEntry`.
|
|
47
|
+
|
|
48
|
+
## Relationship to the JSON Schema
|
|
49
|
+
|
|
50
|
+
`@openpronoun/schema` (JSON Schema) is canonical and language-agnostic. This Zod
|
|
51
|
+
port is an authoring convenience for TypeScript and is **not** the source of
|
|
52
|
+
truth. `test/parity.test.ts` asserts the two stay in agreement over the
|
|
53
|
+
conformance fixtures plus a shared reject set.
|
|
54
|
+
|
|
55
|
+
One intentional difference: special preferences here are strict (a special entry
|
|
56
|
+
may not carry pronoun-form fields), whereas the JSON Schema is looser on that
|
|
57
|
+
pathological case. Both validators agree on every conformance fixture; if you
|
|
58
|
+
need byte-for-byte JSON Schema semantics, validate with `@openpronoun/schema`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** A standard pronoun set in full keys. */
|
|
3
|
+
export declare const fullPronounSetSchema: z.ZodObject<{
|
|
4
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
5
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
6
|
+
context: z.ZodOptional<z.ZodString>;
|
|
7
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
8
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
language: z.ZodOptional<z.ZodString>;
|
|
11
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
12
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
subjective: z.ZodString;
|
|
15
|
+
objective: z.ZodString;
|
|
16
|
+
possessive_adjective: z.ZodString;
|
|
17
|
+
possessive_pronoun: z.ZodString;
|
|
18
|
+
reflexive: z.ZodString;
|
|
19
|
+
}, z.core.$strict>;
|
|
20
|
+
/** A standard pronoun set in compact keys. */
|
|
21
|
+
export declare const compactPronounSetSchema: z.ZodObject<{
|
|
22
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
23
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
24
|
+
context: z.ZodOptional<z.ZodString>;
|
|
25
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
26
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
language: z.ZodOptional<z.ZodString>;
|
|
29
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
30
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
31
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
sub: z.ZodString;
|
|
33
|
+
obj: z.ZodString;
|
|
34
|
+
p_a: z.ZodString;
|
|
35
|
+
p_pn: z.ZodString;
|
|
36
|
+
ref: z.ZodString;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
/** A standard pronoun set (either key style). */
|
|
39
|
+
export declare const pronounSetSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
40
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
context: z.ZodOptional<z.ZodString>;
|
|
43
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
44
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
46
|
+
language: z.ZodOptional<z.ZodString>;
|
|
47
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
48
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
49
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
50
|
+
subjective: z.ZodString;
|
|
51
|
+
objective: z.ZodString;
|
|
52
|
+
possessive_adjective: z.ZodString;
|
|
53
|
+
possessive_pronoun: z.ZodString;
|
|
54
|
+
reflexive: z.ZodString;
|
|
55
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
56
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
57
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
58
|
+
context: z.ZodOptional<z.ZodString>;
|
|
59
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
60
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
61
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
language: z.ZodOptional<z.ZodString>;
|
|
63
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
64
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
65
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
sub: z.ZodString;
|
|
67
|
+
obj: z.ZodString;
|
|
68
|
+
p_a: z.ZodString;
|
|
69
|
+
p_pn: z.ZodString;
|
|
70
|
+
ref: z.ZodString;
|
|
71
|
+
}, z.core.$strict>]>;
|
|
72
|
+
/** The non-set special preferences. */
|
|
73
|
+
export declare const SPECIAL_TYPES: readonly ["any", "none", "ask", "unspecified"];
|
|
74
|
+
/** A special preference: any / none / ask / unspecified. */
|
|
75
|
+
export declare const specialPreferenceSchema: z.ZodObject<{
|
|
76
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
context: z.ZodOptional<z.ZodString>;
|
|
79
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
80
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
81
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
language: z.ZodOptional<z.ZodString>;
|
|
83
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
84
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
86
|
+
type: z.ZodEnum<{
|
|
87
|
+
any: "any";
|
|
88
|
+
none: "none";
|
|
89
|
+
ask: "ask";
|
|
90
|
+
unspecified: "unspecified";
|
|
91
|
+
}>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
/**
|
|
94
|
+
* A custom entry: requires `display`, and may additionally carry pronoun-form
|
|
95
|
+
* fields (a merged or partially specified set).
|
|
96
|
+
*/
|
|
97
|
+
export declare const customEntrySchema: z.ZodObject<{
|
|
98
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
context: z.ZodOptional<z.ZodString>;
|
|
101
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
102
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
103
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
104
|
+
language: z.ZodOptional<z.ZodString>;
|
|
105
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
106
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
107
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
type: z.ZodLiteral<"custom">;
|
|
109
|
+
display: z.ZodString;
|
|
110
|
+
subjective: z.ZodOptional<z.ZodString>;
|
|
111
|
+
objective: z.ZodOptional<z.ZodString>;
|
|
112
|
+
possessive_adjective: z.ZodOptional<z.ZodString>;
|
|
113
|
+
possessive_pronoun: z.ZodOptional<z.ZodString>;
|
|
114
|
+
reflexive: z.ZodOptional<z.ZodString>;
|
|
115
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
116
|
+
obj: z.ZodOptional<z.ZodString>;
|
|
117
|
+
p_a: z.ZodOptional<z.ZodString>;
|
|
118
|
+
p_pn: z.ZodOptional<z.ZodString>;
|
|
119
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
120
|
+
}, z.core.$strict>;
|
|
121
|
+
/** A single entry: a standard set, a special preference, or a custom entry. */
|
|
122
|
+
export declare const pronounEntrySchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
123
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
124
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
125
|
+
context: z.ZodOptional<z.ZodString>;
|
|
126
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
127
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
128
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
language: z.ZodOptional<z.ZodString>;
|
|
130
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
131
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
type: z.ZodEnum<{
|
|
134
|
+
any: "any";
|
|
135
|
+
none: "none";
|
|
136
|
+
ask: "ask";
|
|
137
|
+
unspecified: "unspecified";
|
|
138
|
+
}>;
|
|
139
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
140
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
141
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
142
|
+
context: z.ZodOptional<z.ZodString>;
|
|
143
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
144
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
145
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
146
|
+
language: z.ZodOptional<z.ZodString>;
|
|
147
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
148
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
149
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
+
type: z.ZodLiteral<"custom">;
|
|
151
|
+
display: z.ZodString;
|
|
152
|
+
subjective: z.ZodOptional<z.ZodString>;
|
|
153
|
+
objective: z.ZodOptional<z.ZodString>;
|
|
154
|
+
possessive_adjective: z.ZodOptional<z.ZodString>;
|
|
155
|
+
possessive_pronoun: z.ZodOptional<z.ZodString>;
|
|
156
|
+
reflexive: z.ZodOptional<z.ZodString>;
|
|
157
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
158
|
+
obj: z.ZodOptional<z.ZodString>;
|
|
159
|
+
p_a: z.ZodOptional<z.ZodString>;
|
|
160
|
+
p_pn: z.ZodOptional<z.ZodString>;
|
|
161
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodObject<{
|
|
163
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
164
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
165
|
+
context: z.ZodOptional<z.ZodString>;
|
|
166
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
167
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
168
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
169
|
+
language: z.ZodOptional<z.ZodString>;
|
|
170
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
171
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
172
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
173
|
+
subjective: z.ZodString;
|
|
174
|
+
objective: z.ZodString;
|
|
175
|
+
possessive_adjective: z.ZodString;
|
|
176
|
+
possessive_pronoun: z.ZodString;
|
|
177
|
+
reflexive: z.ZodString;
|
|
178
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
179
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
180
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
181
|
+
context: z.ZodOptional<z.ZodString>;
|
|
182
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
183
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
184
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
185
|
+
language: z.ZodOptional<z.ZodString>;
|
|
186
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
187
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
188
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
189
|
+
sub: z.ZodString;
|
|
190
|
+
obj: z.ZodString;
|
|
191
|
+
p_a: z.ZodString;
|
|
192
|
+
p_pn: z.ZodString;
|
|
193
|
+
ref: z.ZodString;
|
|
194
|
+
}, z.core.$strict>]>]>;
|
|
195
|
+
/** A pronoun preference: one or more entries, in user-preferred order. */
|
|
196
|
+
export declare const pronounPreferenceSchema: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
197
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
198
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
199
|
+
context: z.ZodOptional<z.ZodString>;
|
|
200
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
201
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
202
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
203
|
+
language: z.ZodOptional<z.ZodString>;
|
|
204
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
205
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
206
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
207
|
+
type: z.ZodEnum<{
|
|
208
|
+
any: "any";
|
|
209
|
+
none: "none";
|
|
210
|
+
ask: "ask";
|
|
211
|
+
unspecified: "unspecified";
|
|
212
|
+
}>;
|
|
213
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
214
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
215
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
216
|
+
context: z.ZodOptional<z.ZodString>;
|
|
217
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
218
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
219
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
220
|
+
language: z.ZodOptional<z.ZodString>;
|
|
221
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
222
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
223
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
224
|
+
type: z.ZodLiteral<"custom">;
|
|
225
|
+
display: z.ZodString;
|
|
226
|
+
subjective: z.ZodOptional<z.ZodString>;
|
|
227
|
+
objective: z.ZodOptional<z.ZodString>;
|
|
228
|
+
possessive_adjective: z.ZodOptional<z.ZodString>;
|
|
229
|
+
possessive_pronoun: z.ZodOptional<z.ZodString>;
|
|
230
|
+
reflexive: z.ZodOptional<z.ZodString>;
|
|
231
|
+
sub: z.ZodOptional<z.ZodString>;
|
|
232
|
+
obj: z.ZodOptional<z.ZodString>;
|
|
233
|
+
p_a: z.ZodOptional<z.ZodString>;
|
|
234
|
+
p_pn: z.ZodOptional<z.ZodString>;
|
|
235
|
+
ref: z.ZodOptional<z.ZodString>;
|
|
236
|
+
}, z.core.$strict>, z.ZodUnion<readonly [z.ZodObject<{
|
|
237
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
238
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
239
|
+
context: z.ZodOptional<z.ZodString>;
|
|
240
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
241
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
242
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
243
|
+
language: z.ZodOptional<z.ZodString>;
|
|
244
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
245
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
246
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
247
|
+
subjective: z.ZodString;
|
|
248
|
+
objective: z.ZodString;
|
|
249
|
+
possessive_adjective: z.ZodString;
|
|
250
|
+
possessive_pronoun: z.ZodString;
|
|
251
|
+
reflexive: z.ZodString;
|
|
252
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
253
|
+
ranking: z.ZodOptional<z.ZodNumber>;
|
|
254
|
+
rnk: z.ZodOptional<z.ZodNumber>;
|
|
255
|
+
context: z.ZodOptional<z.ZodString>;
|
|
256
|
+
ctx: z.ZodOptional<z.ZodString>;
|
|
257
|
+
privacy: z.ZodOptional<z.ZodNumber>;
|
|
258
|
+
pvc: z.ZodOptional<z.ZodNumber>;
|
|
259
|
+
language: z.ZodOptional<z.ZodString>;
|
|
260
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
261
|
+
exclude: z.ZodOptional<z.ZodBoolean>;
|
|
262
|
+
exc: z.ZodOptional<z.ZodBoolean>;
|
|
263
|
+
sub: z.ZodString;
|
|
264
|
+
obj: z.ZodString;
|
|
265
|
+
p_a: z.ZodString;
|
|
266
|
+
p_pn: z.ZodString;
|
|
267
|
+
ref: z.ZodString;
|
|
268
|
+
}, z.core.$strict>]>]>>;
|
|
269
|
+
export type PronounSet = z.infer<typeof pronounSetSchema>;
|
|
270
|
+
export type SpecialPreference = z.infer<typeof specialPreferenceSchema>;
|
|
271
|
+
export type CustomEntry = z.infer<typeof customEntrySchema>;
|
|
272
|
+
export type PronounEntry = z.infer<typeof pronounEntrySchema>;
|
|
273
|
+
export type PronounPreference = z.infer<typeof pronounPreferenceSchema>;
|
|
274
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAiDxB,2CAA2C;AAC3C,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;kBAAgD,CAAC;AAElF,8CAA8C;AAC9C,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;kBAAmD,CAAC;AAExF,iDAAiD;AACjD,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAA2D,CAAC;AAEzF,uCAAuC;AACvC,eAAO,MAAM,aAAa,gDAAiD,CAAC;AAE5E,4DAA4D;AAC5D,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;kBAGlC,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;kBAc5B,CAAC;AAEH,+EAA+E;AAC/E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sBAI7B,CAAC;AAEH,0EAA0E;AAC1E,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAAqC,CAAC;AAE1E,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAC1D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAC9D,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod mirror of the canonical OpenPronoun JSON Schema (`@openpronoun/schema`).
|
|
4
|
+
*
|
|
5
|
+
* This is a hand-written, idiomatic Zod port kept in sync with
|
|
6
|
+
* `pronoun-set.schema.json` via the parity test (see `test/parity.test.ts`),
|
|
7
|
+
* which checks that both validators agree across the `@openpronoun/conformance`
|
|
8
|
+
* fixtures. The JSON Schema remains the canonical, cross-language artifact;
|
|
9
|
+
* this package exists for TypeScript ergonomics (inferred types + nicer errors).
|
|
10
|
+
*
|
|
11
|
+
* Intentional difference from the JSON Schema: special preferences here are
|
|
12
|
+
* strict (no stray pronoun-form fields), whereas the JSON Schema is looser on
|
|
13
|
+
* that pathological case. Both agree on every conformance fixture.
|
|
14
|
+
*/
|
|
15
|
+
const nonEmpty = z.string().min(1);
|
|
16
|
+
const iso6391 = z.string().regex(/^[a-z]{2}$/, "expected an ISO 639-1 code");
|
|
17
|
+
/** Optional per-entry metadata, in both full and compact key styles. */
|
|
18
|
+
const metadata = {
|
|
19
|
+
ranking: z.number().int().optional(),
|
|
20
|
+
rnk: z.number().int().optional(),
|
|
21
|
+
context: z.string().optional(),
|
|
22
|
+
ctx: z.string().optional(),
|
|
23
|
+
privacy: z.number().int().min(0).optional(),
|
|
24
|
+
pvc: z.number().int().min(0).optional(),
|
|
25
|
+
language: iso6391.optional(),
|
|
26
|
+
lang: iso6391.optional(),
|
|
27
|
+
exclude: z.boolean().optional(),
|
|
28
|
+
exc: z.boolean().optional(),
|
|
29
|
+
};
|
|
30
|
+
const fullForms = {
|
|
31
|
+
subjective: nonEmpty,
|
|
32
|
+
objective: nonEmpty,
|
|
33
|
+
possessive_adjective: nonEmpty,
|
|
34
|
+
possessive_pronoun: nonEmpty,
|
|
35
|
+
reflexive: nonEmpty,
|
|
36
|
+
};
|
|
37
|
+
const compactForms = {
|
|
38
|
+
sub: nonEmpty,
|
|
39
|
+
obj: nonEmpty,
|
|
40
|
+
p_a: nonEmpty,
|
|
41
|
+
p_pn: nonEmpty,
|
|
42
|
+
ref: nonEmpty,
|
|
43
|
+
};
|
|
44
|
+
/** A standard pronoun set in full keys. */
|
|
45
|
+
export const fullPronounSetSchema = z.strictObject({ ...fullForms, ...metadata });
|
|
46
|
+
/** A standard pronoun set in compact keys. */
|
|
47
|
+
export const compactPronounSetSchema = z.strictObject({ ...compactForms, ...metadata });
|
|
48
|
+
/** A standard pronoun set (either key style). */
|
|
49
|
+
export const pronounSetSchema = z.union([fullPronounSetSchema, compactPronounSetSchema]);
|
|
50
|
+
/** The non-set special preferences. */
|
|
51
|
+
export const SPECIAL_TYPES = ["any", "none", "ask", "unspecified"];
|
|
52
|
+
/** A special preference: any / none / ask / unspecified. */
|
|
53
|
+
export const specialPreferenceSchema = z.strictObject({
|
|
54
|
+
type: z.enum(SPECIAL_TYPES),
|
|
55
|
+
...metadata,
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* A custom entry: requires `display`, and may additionally carry pronoun-form
|
|
59
|
+
* fields (a merged or partially specified set).
|
|
60
|
+
*/
|
|
61
|
+
export const customEntrySchema = z.strictObject({
|
|
62
|
+
type: z.literal("custom"),
|
|
63
|
+
display: nonEmpty,
|
|
64
|
+
subjective: nonEmpty.optional(),
|
|
65
|
+
objective: nonEmpty.optional(),
|
|
66
|
+
possessive_adjective: nonEmpty.optional(),
|
|
67
|
+
possessive_pronoun: nonEmpty.optional(),
|
|
68
|
+
reflexive: nonEmpty.optional(),
|
|
69
|
+
sub: nonEmpty.optional(),
|
|
70
|
+
obj: nonEmpty.optional(),
|
|
71
|
+
p_a: nonEmpty.optional(),
|
|
72
|
+
p_pn: nonEmpty.optional(),
|
|
73
|
+
ref: nonEmpty.optional(),
|
|
74
|
+
...metadata,
|
|
75
|
+
});
|
|
76
|
+
/** A single entry: a standard set, a special preference, or a custom entry. */
|
|
77
|
+
export const pronounEntrySchema = z.union([
|
|
78
|
+
specialPreferenceSchema,
|
|
79
|
+
customEntrySchema,
|
|
80
|
+
pronounSetSchema,
|
|
81
|
+
]);
|
|
82
|
+
/** A pronoun preference: one or more entries, in user-preferred order. */
|
|
83
|
+
export const pronounPreferenceSchema = z.array(pronounEntrySchema).min(1);
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;GAYG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AAQ,EAAE;IACxB,IAAI,EAAE,QAAQ,CAAC,QAAQ,EAAE;IACzB,GAAG,EAAE,QAAQ,CAAC,QAAQ,EAAE;IACxB,GAAG,QAAQ;CACZ,CAAC,CAAC;AAEH,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC;IACxC,uBAAuB;IACvB,iBAAiB;IACjB,gBAAgB;CACjB,CAAC,CAAC;AAEH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openpronoun/zod",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Zod schemas and inferred TypeScript types mirroring the OpenPronoun data model (@openpronoun/schema).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc -p tsconfig.json",
|
|
22
|
+
"typecheck": "tsc --noEmit",
|
|
23
|
+
"test": "vitest run"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"zod": "^4"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"zod": "^4",
|
|
30
|
+
"vitest": "^3",
|
|
31
|
+
"ajv": "^8",
|
|
32
|
+
"typescript": "^5",
|
|
33
|
+
"@types/node": "^22",
|
|
34
|
+
"@openpronoun/schema": "*",
|
|
35
|
+
"@openpronoun/conformance": "*"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
}
|
|
40
|
+
}
|