@plasius/schema 1.1.0 → 1.1.1

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 (58) hide show
  1. package/dist/index.cjs +1934 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +391 -0
  4. package/dist/index.d.ts +391 -0
  5. package/dist/index.js +1883 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +18 -6
  8. package/.eslintrc.cjs +0 -7
  9. package/.github/workflows/cd.yml +0 -236
  10. package/.github/workflows/ci.yml +0 -16
  11. package/.nvmrc +0 -1
  12. package/.vscode/launch.json +0 -15
  13. package/CHANGELOG.md +0 -120
  14. package/CODE_OF_CONDUCT.md +0 -79
  15. package/CONTRIBUTING.md +0 -201
  16. package/CONTRIBUTORS.md +0 -27
  17. package/SECURITY.md +0 -17
  18. package/docs/adrs/adr-0001: schema.md +0 -45
  19. package/docs/adrs/adr-template.md +0 -67
  20. package/legal/CLA-REGISTRY.csv +0 -2
  21. package/legal/CLA.md +0 -22
  22. package/legal/CORPORATE_CLA.md +0 -57
  23. package/legal/INDIVIDUAL_CLA.md +0 -91
  24. package/sbom.cdx.json +0 -66
  25. package/src/components.ts +0 -39
  26. package/src/field.builder.ts +0 -239
  27. package/src/field.ts +0 -153
  28. package/src/index.ts +0 -7
  29. package/src/infer.ts +0 -34
  30. package/src/pii.ts +0 -165
  31. package/src/schema.ts +0 -893
  32. package/src/types.ts +0 -156
  33. package/src/validation/countryCode.ISO3166.ts +0 -256
  34. package/src/validation/currencyCode.ISO4217.ts +0 -191
  35. package/src/validation/dateTime.ISO8601.ts +0 -60
  36. package/src/validation/email.RFC5322.ts +0 -9
  37. package/src/validation/generalText.OWASP.ts +0 -39
  38. package/src/validation/index.ts +0 -13
  39. package/src/validation/languageCode.BCP47.ts +0 -299
  40. package/src/validation/name.OWASP.ts +0 -25
  41. package/src/validation/percentage.ISO80000-1.ts +0 -8
  42. package/src/validation/phone.E.164.ts +0 -9
  43. package/src/validation/richtext.OWASP.ts +0 -34
  44. package/src/validation/url.WHATWG.ts +0 -16
  45. package/src/validation/user.MS-GOOGLE-APPLE.ts +0 -31
  46. package/src/validation/uuid.RFC4122.ts +0 -10
  47. package/src/validation/version.SEMVER2.0.0.ts +0 -10
  48. package/tests/field.builder.test.ts +0 -81
  49. package/tests/fields.test.ts +0 -213
  50. package/tests/pii.test.ts +0 -139
  51. package/tests/schema.test.ts +0 -501
  52. package/tests/test-utils.ts +0 -97
  53. package/tests/validate.test.ts +0 -97
  54. package/tests/validation.test.ts +0 -98
  55. package/tsconfig.build.json +0 -19
  56. package/tsconfig.json +0 -7
  57. package/tsup.config.ts +0 -10
  58. package/vitest.config.js +0 -20
@@ -1,91 +0,0 @@
1
- # Individual Contributor License Agreement (CLA)
2
-
3
- **Project:** @plasius/schema (Plasius LTD)
4
- **Version:** 1.0 — 2025‑09‑12
5
- **Contact:** [contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)
6
-
7
- ---
8
-
9
- ## 1. Definitions
10
-
11
- - **"You"** (or **"Contributor"**) means the individual signing this CLA and submitting Contributions to the Project.
12
- - **"Contribution"** means any original work of authorship, including code, documentation, data, designs, or feedback that You submit to the Project in any form (e.g., pull request, issue comment, email, file upload).
13
- - **"Project"** means the @plasius/schema repositories and related materials owned or managed by **Plasius LTD**.
14
-
15
- ## 2. Copyright License Grant
16
-
17
- You hereby grant to Plasius LTD a **perpetual, worldwide, non‑exclusive, transferable, sublicensable, royalty‑free, irrevocable** copyright license to:
18
-
19
- - use, reproduce, publicly display, publicly perform, modify, create derivative works of, and
20
- - distribute Contributions in source and object form,
21
- - and to **sublicense** these rights under any terms Plasius LTD chooses, including proprietary or open‑source licenses.
22
-
23
- ## 3. Patent License Grant
24
-
25
- You hereby grant to Plasius LTD and its sublicensees a **perpetual, worldwide, non‑exclusive, transferable, royalty‑free, irrevocable** patent license to **make, have made, use, offer to sell, sell, import, and otherwise transfer** the Contribution and derivative works thereof, where such license applies only to patent claims that You **own or control** and that would be infringed by Your Contribution or its combination with the Project.
26
-
27
- ## 4. Moral Rights & Attribution
28
-
29
- To the maximum extent permitted by applicable law, You **waive** and agree not to assert any moral rights (e.g., rights of attribution or integrity) in or to the Contribution against Plasius LTD. Plasius LTD may, but is not required to, credit You.
30
-
31
- ## 5. Representations & Warranties
32
-
33
- You represent that:
34
-
35
- 1. **Originality / Rights:** Each Contribution is Your original creation, or You have sufficient rights to submit it and grant the licenses above.
36
- 2. **No Confidential Info:** Contributions **do not** include confidential information or trade secrets of any third party.
37
- 3. **No Infringement:** To the best of Your knowledge, Contributions do not infringe any third‑party IP rights.
38
- 4. **Employment / Contractor Status:** If Your employer or a third party might claim rights in Your Contribution, You have obtained **written permission** to make the Contribution and grant these licenses (attach or reference below), or Your Contribution is made **outside the scope** of your employment and without using your employer’s confidential information or resources.
39
- 5. **Compliance:** You will follow the Project’s policies (e.g., Code of Conduct, Security Policy) and applicable laws.
40
-
41
- ## 6. Third‑Party Code
42
-
43
- If Your Contribution includes code, data, or other material from a third party, You will **identify the material and its license** in the pull request or submission, and ensure it is **compatible** with the Project’s licensing model. You will not submit material subject to terms that require the Project to disclose proprietary source code (e.g., certain copyleft obligations) unless the Project has **pre‑approved** such inclusion in writing.
44
-
45
- ## 7. Scope & Duration
46
-
47
- - This CLA covers **all past and future** Contributions You submit to the Project, unless and until You provide written notice to **revoke** it.
48
- - Revocation is **not retroactive**: rights granted for prior Contributions remain in effect.
49
-
50
- ## 8. Disclaimer
51
-
52
- THE CONTRIBUTION IS PROVIDED “AS IS” WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON‑INFRINGEMENT.
53
-
54
- ## 9. Governing Law & Jurisdiction
55
-
56
- This CLA is governed by the **laws of England and Wales**, and the courts of England and Wales shall have **exclusive jurisdiction** over any dispute arising out of or relating to it.
57
-
58
- ## 10. Entire Agreement
59
-
60
- This CLA is the entire agreement between You and Plasius LTD regarding Contributions. It supersedes any prior discussions relating to Contributions. If any provision is held unenforceable, the remaining provisions remain in full force.
61
-
62
- ---
63
-
64
- ## 11. Contributor Information & Signature
65
-
66
- By signing below, You agree to the terms of this CLA for Your Contributions to the Project.
67
-
68
- **Full Name:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
69
-
70
- **Email:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
71
-
72
- **GitHub Handle:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
73
-
74
- **Address (optional):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
75
-
76
- **Employer (if applicable):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
77
-
78
- **If employed:** ☐ I confirm Contributions are made outside the scope of employment **or** ☐ I have attached my employer’s written permission.
79
-
80
- **Signature:** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
81
-
82
- **Date (YYYY‑MM‑DD):** \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
83
-
84
- _Electronic signatures are accepted. You may type your name in the Signature field and email a PDF copy._
85
-
86
- **Submission:** Please email the signed CLA to **[contributors@plasius.co.uk](mailto:contributors@plasius.co.uk)** with subject line: `CLA – Individual – <GitHubHandle>`.
87
-
88
- **(Optional) Attachments / Notes:**
89
-
90
- - Employer permission letter (if required)
91
- - Third‑party license disclosures (if any)
package/sbom.cdx.json DELETED
@@ -1,66 +0,0 @@
1
- {
2
- "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
- "bomFormat": "CycloneDX",
4
- "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:329219f1-3f86-497c-9d0e-3dc025a3a272",
6
- "version": 1,
7
- "metadata": {
8
- "timestamp": "2025-09-18T14:38:35.724Z",
9
- "lifecycles": [
10
- {
11
- "phase": "build"
12
- }
13
- ],
14
- "tools": [
15
- {
16
- "vendor": "npm",
17
- "name": "cli",
18
- "version": "10.9.3"
19
- }
20
- ],
21
- "component": {
22
- "bom-ref": "@plasius/schema@1.1.0",
23
- "type": "library",
24
- "name": "schema",
25
- "version": "1.1.0",
26
- "scope": "required",
27
- "author": "Plasius LTD",
28
- "description": "Entity schema definition & validation helpers for Plasius ecosystem",
29
- "purl": "pkg:npm/%40plasius/schema@1.1.0",
30
- "properties": [
31
- {
32
- "name": "cdx:npm:package:path",
33
- "value": ""
34
- }
35
- ],
36
- "externalReferences": [
37
- {
38
- "type": "vcs",
39
- "url": "git+https://github.com/Plasius-LTD/schema.git"
40
- },
41
- {
42
- "type": "website",
43
- "url": "https://github.com/Plasius-LTD/schema#readme"
44
- },
45
- {
46
- "type": "issue-tracker",
47
- "url": "https://github.com/Plasius-LTD/schema/issues"
48
- }
49
- ],
50
- "licenses": [
51
- {
52
- "license": {
53
- "id": "Apache-2.0"
54
- }
55
- }
56
- ]
57
- }
58
- },
59
- "components": [],
60
- "dependencies": [
61
- {
62
- "ref": "@plasius/schema@1.1.0",
63
- "dependsOn": []
64
- }
65
- ]
66
- }
package/src/components.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Infer } from "./infer.js";
2
- import { createSchema } from "./schema.js";
3
- import { Schema, SchemaShape } from "./types.js";
4
- // This module provides a registry for component schemas, allowing components to be registered and retrieved by type.
5
- const componentSchemaRegistry = new Map<string, Schema<SchemaShape>>();
6
-
7
- export function createComponentSchema<T extends SchemaShape>(
8
- shape: SchemaShape,
9
- name: string,
10
- version: string,
11
- tableName: string = "",
12
- schemaValidator: (entity: Infer<T>) => boolean = () => true
13
- ): Schema<SchemaShape> {
14
- const schema = createSchema<T>(shape as T, name, {
15
- version: version,
16
- piiEnforcement: "strict",
17
- table: tableName,
18
- schemaValidator,
19
- });
20
- registerComponentSchema(name, schema as Schema<SchemaShape>);
21
- return schema as Schema<SchemaShape>;
22
- }
23
-
24
- export function registerComponentSchema(
25
- type: string,
26
- schema: Schema<SchemaShape>
27
- ) {
28
- componentSchemaRegistry.set(type, schema);
29
- }
30
-
31
- export function getComponentSchema(
32
- type: string
33
- ): Schema<SchemaShape> | undefined {
34
- return componentSchemaRegistry.get(type);
35
- }
36
-
37
- export function getAllComponentSchemas(): [string, Schema<SchemaShape>][] {
38
- return Array.from(componentSchemaRegistry.entries());
39
- }
@@ -1,239 +0,0 @@
1
- type FieldType = "string" | "number" | "boolean" | "object" | "array" | "ref";
2
-
3
- import { type PII } from "./pii.js";
4
- import { getSchemaForType } from "./schema.js";
5
-
6
- export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
7
- _type!: TExternal;
8
- _storageType!: TInternal;
9
- isSystem = false;
10
- isImmutable = false;
11
- isRequired = true;
12
- _validator?: (value: any) => boolean;
13
- _description: string = "";
14
- _version: string = "1.0.0";
15
- _default?: TInternal | (() => TInternal);
16
- _upgrade?: (
17
- value: any,
18
- ctx: {
19
- entityFrom: string;
20
- entityTo: string;
21
- fieldTo: string;
22
- fieldName: string;
23
- }
24
- ) => { ok: boolean; value?: any; error?: string };
25
- _shape?: Record<string, FieldBuilder<any>>;
26
- itemType?: FieldBuilder<any>;
27
- refType?: string;
28
- _pii: PII = {
29
- classification: "none",
30
- action: "none",
31
- logHandling: "plain",
32
- purpose: "an ordinary value",
33
- };
34
- enumValues?: readonly TInternal[];
35
-
36
- constructor(
37
- public type: FieldType,
38
- options: {
39
- shape?: Record<string, FieldBuilder<any>>;
40
- itemType?: FieldBuilder<any>;
41
- refType?: string;
42
- } = {}
43
- ) {
44
- this._shape = options.shape;
45
- this.itemType = options.itemType;
46
- this.refType = options.refType;
47
- }
48
-
49
- immutable(): FieldBuilder<TExternal, TInternal> {
50
- this.isImmutable = true;
51
- return this;
52
- }
53
-
54
- system(): FieldBuilder<TExternal, TInternal> {
55
- this.isSystem = true;
56
- return this;
57
- }
58
-
59
- required(): FieldBuilder<TExternal, TInternal> {
60
- this.isRequired = true;
61
- return this;
62
- }
63
-
64
- optional(): FieldBuilder<TExternal, TInternal> {
65
- this.isRequired = false;
66
- return this;
67
- }
68
-
69
- validator(
70
- fn: (value: TInternal) => boolean
71
- ): FieldBuilder<TExternal, TInternal> {
72
- this._validator = fn;
73
- return this;
74
- }
75
-
76
- description(desc: string): FieldBuilder<TExternal, TInternal> {
77
- this._description = desc;
78
- return this;
79
- }
80
-
81
- default(
82
- value: TInternal | (() => TInternal)
83
- ): FieldBuilder<TExternal, TInternal> {
84
- this._default = value;
85
- // Supplying a default implies the value may be omitted at input time.
86
- // Do not couple defaulting with validation.
87
- this.isRequired = false;
88
- return this;
89
- }
90
-
91
- /**
92
- * Configure an upgrader used when validating older entities against a newer schema.
93
- * The upgrader receives the current field value and version context, and should
94
- * return { ok: true, value } with the upgraded value, or { ok: false, error }.
95
- */
96
- upgrade(
97
- fn: (
98
- value: any,
99
- ctx: {
100
- entityFrom: string;
101
- entityTo: string;
102
- fieldTo: string;
103
- fieldName: string;
104
- }
105
- ) => { ok: boolean; value?: any; error?: string }
106
- ): FieldBuilder<TExternal, TInternal> {
107
- this._upgrade = fn;
108
- return this;
109
- }
110
-
111
- getDefault(): TInternal | undefined {
112
- const v = this._default;
113
- return typeof v === "function" ? (v as () => TInternal)() : v;
114
- }
115
-
116
- version(ver: string): FieldBuilder<TExternal, TInternal> {
117
- this._version = ver;
118
- return this;
119
- }
120
-
121
- /// PID informs the schema PII handling of the manner in
122
- /// which to handle data relating to this field.
123
- PID(pii: PII): FieldBuilder<TExternal, TInternal> {
124
- this._pii = pii;
125
- return this;
126
- }
127
-
128
- min(min: number): FieldBuilder<TExternal, TInternal> {
129
- if (this.type === "number") {
130
- const prevValidator = this._validator;
131
- this._validator = (value: any) => {
132
- const valid = typeof value === "number" && value >= min;
133
- return prevValidator ? prevValidator(value) && valid : valid;
134
- };
135
- } else if (this.type === "string") {
136
- const prevValidator = this._validator;
137
- this._validator = (value: any) => {
138
- const valid = typeof value === "string" && value.length >= min;
139
- return prevValidator ? prevValidator(value) && valid : valid;
140
- };
141
- } else if (this.type === "array") {
142
- const prevValidator = this._validator;
143
- this._validator = (value: any) => {
144
- const valid = Array.isArray(value) && value.length >= min;
145
- return prevValidator ? prevValidator(value) && valid : valid;
146
- };
147
- } else {
148
- throw new Error(
149
- "Min is only supported on number, string, or array fields."
150
- );
151
- }
152
- return this;
153
- }
154
-
155
- max(max: number): FieldBuilder<TExternal, TInternal> {
156
- if (this.type === "number") {
157
- const prevValidator = this._validator;
158
- this._validator = (value: any) => {
159
- const valid = typeof value === "number" && value <= max;
160
- return prevValidator ? prevValidator(value) && valid : valid;
161
- };
162
- } else if (this.type === "string") {
163
- const prevValidator = this._validator;
164
- this._validator = (value: any) => {
165
- const valid = typeof value === "string" && value.length <= max;
166
- return prevValidator ? prevValidator(value) && valid : valid;
167
- };
168
- } else if (this.type === "array") {
169
- const prevValidator = this._validator;
170
- this._validator = (value: any) => {
171
- const valid = Array.isArray(value) && value.length <= max;
172
- return prevValidator ? prevValidator(value) && valid : valid;
173
- };
174
- } else {
175
- throw new Error(
176
- "Max is only supported on number, string, or array fields."
177
- );
178
- }
179
- return this;
180
- }
181
-
182
- pattern(regex: RegExp): FieldBuilder<TExternal, TInternal> {
183
- if (this.type !== "string") {
184
- throw new Error("Pattern is only supported on string fields.");
185
- }
186
- const prevValidator = this._validator;
187
- this._validator = (value: any) => {
188
- const valid = typeof value === "string" && regex.test(value);
189
- return prevValidator ? prevValidator(value) && valid : valid;
190
- };
191
- return this;
192
- }
193
-
194
- enum<const U extends readonly TInternal[]>(
195
- values: U
196
- ): FieldBuilder<U[number]> {
197
- if (
198
- this.type !== "string" &&
199
- this.type !== "number" &&
200
- !(
201
- this.type === "array" &&
202
- (this.itemType?.type === "string" || this.itemType?.type === "number")
203
- )
204
- ) {
205
- throw new Error(
206
- "Enums are only supported on string or number fields or arrays of strings or numbers."
207
- );
208
- }
209
- this.enumValues = values;
210
- return this as any;
211
- }
212
-
213
- /**
214
- * Create a shallow clone with a different external type parameter.
215
- * Note: shape and itemType are passed by reference (shallow). If you need
216
- * deep isolation of nested FieldBuilders, clone them explicitly.
217
- */
218
- as<U>(): FieldBuilder<U, TInternal> {
219
- const clone = new FieldBuilder<U, TInternal>(this.type, {
220
- shape: this._shape,
221
- itemType: this.itemType,
222
- refType: this.refType,
223
- });
224
- clone.enumValues = this.enumValues;
225
- clone.isImmutable = this.isImmutable;
226
- clone.isSystem = this.isSystem;
227
- clone.isRequired = this.isRequired;
228
- clone._description = this._description;
229
- clone._version = this._version;
230
- clone._pii = this._pii;
231
- clone._validator = this._validator as any;
232
- clone._default = this._default as any;
233
- clone._upgrade = this._upgrade;
234
- // refType already provided in constructor options above
235
- return clone;
236
- }
237
- }
238
-
239
- export default FieldBuilder;
package/src/field.ts DELETED
@@ -1,153 +0,0 @@
1
- import { version } from "os";
2
- import { FieldBuilder } from "./field.builder.js";
3
- import { Infer } from "./infer.js";
4
- import { SchemaShape } from "./types.js";
5
- import {
6
- validateCountryCode,
7
- validateDateTimeISO,
8
- validateEmail,
9
- validatePhone,
10
- validateRichText,
11
- validateSafeText,
12
- validateSemVer,
13
- validateUrl,
14
- validateUUID,
15
- } from "./validation/index.js";
16
- import { validateLanguage } from "./validation/languageCode.BCP47.js";
17
-
18
- export const field = {
19
- string: () => new FieldBuilder<string>("string"),
20
- number: () => new FieldBuilder<number>("number"),
21
- boolean: () => new FieldBuilder<boolean>("boolean"),
22
- object: <T extends Record<string, FieldBuilder>>(fields: T) =>
23
- new FieldBuilder<T>("object", { shape: fields }),
24
- array: (itemType: FieldBuilder) => new FieldBuilder("array", { itemType }),
25
- ref: <S extends SchemaShape>(refType: string) =>
26
- new FieldBuilder<Infer<S>>("ref", { refType }),
27
- email: () =>
28
- new FieldBuilder<string>("string")
29
- .validator(validateEmail)
30
- .PID({
31
- classification: "high",
32
- action: "encrypt",
33
- logHandling: "redact",
34
- purpose: "an email address",
35
- })
36
- .description("An email address"),
37
- phone: () =>
38
- new FieldBuilder<string>("string")
39
- .validator(validatePhone)
40
- .PID({
41
- classification: "high",
42
- action: "encrypt",
43
- logHandling: "redact",
44
- purpose: "a phone number",
45
- })
46
- .description("A phone number"),
47
- url: () =>
48
- new FieldBuilder<string>("string")
49
- .validator(validateUrl)
50
- .PID({
51
- classification: "low",
52
- action: "hash",
53
- logHandling: "pseudonym",
54
- purpose: "a URL",
55
- })
56
- .description("A URL"),
57
- uuid: () =>
58
- new FieldBuilder<string>("string")
59
- .PID({
60
- classification: "low",
61
- action: "hash",
62
- logHandling: "pseudonym",
63
- purpose: "a UUID",
64
- })
65
- .validator(validateUUID)
66
- .description("A UUID"),
67
- dateTimeISO: () =>
68
- new FieldBuilder<string>("string")
69
- .PID({
70
- classification: "none",
71
- action: "none",
72
- logHandling: "plain",
73
- purpose: "a date string",
74
- })
75
- .validator(validateDateTimeISO)
76
- .description("A date string in ISO 8601 format"),
77
- dateISO: () =>
78
- new FieldBuilder<string>("string")
79
- .PID({
80
- classification: "none",
81
- action: "none",
82
- logHandling: "plain",
83
- purpose: "a date string",
84
- })
85
- .validator((s) => validateDateTimeISO(s, { mode: "date" }))
86
- .description("A date string in ISO 8601 format (date only)"),
87
- timeISO: () =>
88
- new FieldBuilder<string>("string")
89
- .PID({
90
- classification: "none",
91
- action: "none",
92
- logHandling: "plain",
93
- purpose: "a time string",
94
- })
95
- .validator((s) => validateDateTimeISO(s, { mode: "time" }))
96
- .description("A time string in ISO 8601 format (time only)"),
97
- richText: () =>
98
- new FieldBuilder<string>("string")
99
- .PID({
100
- classification: "low",
101
- action: "clear",
102
- logHandling: "omit",
103
- purpose: "rich text content",
104
- })
105
- .validator(validateRichText)
106
- .description("Rich text content, may include basic HTML formatting"),
107
- generalText: () =>
108
- new FieldBuilder<string>("string")
109
- .PID({
110
- classification: "none",
111
- action: "none",
112
- logHandling: "plain",
113
- purpose: "Plain text content",
114
- })
115
- .validator(validateSafeText)
116
- .description("Standard text content, no HTML allowed"),
117
- latitude: () =>
118
- new FieldBuilder<number>("number")
119
- .PID({
120
- classification: "low",
121
- action: "clear",
122
- logHandling: "omit",
123
- purpose: "Latitude in decimal degrees, WGS 84 (ISO 6709)",
124
- })
125
- .min(-90)
126
- .max(90)
127
- .description("Latitude in decimal degrees, WGS 84 (ISO 6709)"),
128
- longitude: () =>
129
- new FieldBuilder<number>("number")
130
- .PID({
131
- classification: "low",
132
- action: "clear",
133
- logHandling: "omit",
134
- purpose: "Longitude in decimal degrees, WGS 84 (ISO 6709)",
135
- })
136
- .min(-180)
137
- .max(180)
138
- .description("Longitude in decimal degrees, WGS 84 (ISO 6709)"),
139
- version: () =>
140
- new FieldBuilder<string>("string")
141
- .validator(validateSemVer)
142
- .description("A semantic version string, e.g. '1.0.0'"),
143
- countryCode: () =>
144
- new FieldBuilder<string>("string")
145
- .validator(validateCountryCode)
146
- .description("An ISO 3166 country code, e.g. 'US', 'GB', 'FR'"),
147
- languageCode: () =>
148
- new FieldBuilder<string>("string")
149
- .validator(validateLanguage)
150
- .description(
151
- "An BCP 47 structured language code, primarily ISO 639-1 and optionally with ISO 3166-1 alpha-2 country code, e.g. 'en', 'en-US', 'fr', 'fr-FR'"
152
- ),
153
- };
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export type { Infer } from "./infer.js";
2
- export { field } from "./field.js";
3
- export { createSchema, getSchemaForType, getAllSchemas } from "./schema.js";
4
- export type * from "./types.js";
5
- export * from "./components.js";
6
- export * from "./validation/index.js";
7
- export * from "./field.builder.js";
package/src/infer.ts DELETED
@@ -1,34 +0,0 @@
1
- import { SchemaShape } from "./types.js";
2
-
3
- type InferField<T> = T extends { _type: infer U }
4
- ? U
5
- : T extends { type: "string" }
6
- ? string
7
- : T extends { type: "number" }
8
- ? number
9
- : T extends { type: "boolean" }
10
- ? boolean
11
- : T extends { type: "array"; itemType: infer Item }
12
- ? InferField<Item>[]
13
- : T extends { type: "object"; shape: infer Shape extends SchemaShape }
14
- ? InferFromShape<Shape>
15
- : unknown;
16
-
17
- type IsOptional<T> = T extends { optional: true } ? true : false;
18
-
19
- type InferFromShape<S extends SchemaShape> = {
20
- [K in keyof S]: IsOptional<S[K]> extends true
21
- ? InferField<S[K]> | undefined
22
- : InferField<S[K]>;
23
- };
24
-
25
- type InferFromSchema<T extends { shape: SchemaShape }> = InferFromShape<
26
- T["shape"]
27
- >;
28
-
29
- type IsSchema<T> = T extends { shape: SchemaShape } ? true : false;
30
-
31
- export type Infer<T> =
32
- IsSchema<T> extends true
33
- ? InferFromSchema<T & { shape: SchemaShape }>
34
- : InferFromShape<T & SchemaShape>;