@plasius/schema 1.0.17 → 1.1.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.
@@ -2,6 +2,21 @@ name: CD (Publish to npm)
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: "Version bump type"
8
+ required: true
9
+ type: choice
10
+ default: patch
11
+ options:
12
+ - patch
13
+ - minor
14
+ - major
15
+ - none
16
+ preid:
17
+ description: "Pre-release id (e.g. beta, rc). Leave blank for stable"
18
+ required: false
19
+ type: string
5
20
 
6
21
  permissions:
7
22
  contents: write
@@ -22,9 +37,91 @@ jobs:
22
37
  node-version-file: '.nvmrc'
23
38
  cache: 'npm'
24
39
 
40
+ - name: Bump version & decide publish flags
41
+ id: pkg
42
+ env:
43
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
44
+ BUMP: ${{ inputs.bump }}
45
+ PREID: ${{ inputs.preid }}
46
+ run: |
47
+ set -euo pipefail
48
+ git config user.name "github-actions[bot]"
49
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
50
+
51
+ # Decide bump command
52
+ BUMP_CMD=""
53
+ case "${BUMP:-patch}" in
54
+ major|minor|patch)
55
+ if [ -n "${PREID:-}" ]; then
56
+ # Convert to pre* if preid provided
57
+ case "${BUMP}" in
58
+ major) BUMP_CMD="npm version premajor --preid ${PREID} -m 'chore: release v%s [skip ci]'" ;;
59
+ minor) BUMP_CMD="npm version preminor --preid ${PREID} -m 'chore: release v%s [skip ci]'" ;;
60
+ patch) BUMP_CMD="npm version prepatch --preid ${PREID} -m 'chore: release v%s [skip ci]'" ;;
61
+ esac
62
+ else
63
+ BUMP_CMD="npm version ${BUMP} -m 'chore: release v%s [skip ci]'"
64
+ fi
65
+ ;;
66
+ none)
67
+ # No version bump; use existing version
68
+ BUMP_CMD="echo"
69
+ ;;
70
+ *)
71
+ echo "Unknown bump type: ${BUMP}" >&2
72
+ exit 1
73
+ ;;
74
+ esac
75
+
76
+ if [ "${BUMP}" = "none" ]; then
77
+ CURRENT_VER=$(node -p "require('./package.json').version")
78
+ NEW_VER="v${CURRENT_VER}"
79
+ else
80
+ # shellcheck disable=SC2086
81
+ NEW_VER=$(sh -lc "$BUMP_CMD")
82
+ fi
83
+
84
+ echo "New version: $NEW_VER"
85
+ git push --follow-tags
86
+
87
+ # Expose tag (vX.Y.Z) and version (X.Y.Z) for later steps
88
+ VER_NO_V=${NEW_VER#v}
89
+ echo "tag=$NEW_VER" >> "$GITHUB_OUTPUT"
90
+ echo "version=$VER_NO_V" >> "$GITHUB_OUTPUT"
91
+
92
+ NAME=$(node -p "require('./package.json').name")
93
+ echo "name=$NAME" >> "$GITHUB_OUTPUT"
94
+ if npm view "$NAME" version >/dev/null 2>&1; then
95
+ echo "flags=" >> "$GITHUB_OUTPUT"
96
+ else
97
+ echo "flags=--access public" >> "$GITHUB_OUTPUT"
98
+ fi
99
+
25
100
  - name: Install deps (CI)
26
101
  run: npm ci
27
102
 
103
+ - name: Test (coverage)
104
+ run: npm run test -- --coverage
105
+
106
+ - name: Upload coverage to Codecov
107
+ uses: codecov/codecov-action@v4
108
+ with:
109
+ token: ${{ secrets.CODECOV_TOKEN }}
110
+ files: ./coverage/lcov.info
111
+ flags: unittests
112
+ fail_ci_if_error: true
113
+
114
+ - name: Build
115
+ run: npm run build --if-present
116
+
117
+ - name: Generate SBOM (CycloneDX)
118
+ run: npm sbom --sbom-format=cyclonedx --sbom-type=library --omit dev > sbom.cdx.json
119
+
120
+ - name: Attest SBOM (GitHub Artifact Attestations)
121
+ uses: actions/attest-build-provenance@v3
122
+ with:
123
+ subject-path: sbom.cdx.json
124
+
28
125
  - name: Update CHANGELOG.md (move Unreleased to new version)
29
126
  env:
30
127
  VERSION: ${{ steps.pkg.outputs.version }}
@@ -111,53 +208,6 @@ jobs:
111
208
  git commit -m "docs(changelog): release v${VERSION}"
112
209
  git push
113
210
 
114
- - name: Test (coverage)
115
- run: npm run test -- --coverage
116
-
117
- - name: Upload coverage to Codecov
118
- uses: codecov/codecov-action@v4
119
- with:
120
- token: ${{ secrets.CODECOV_TOKEN }}
121
- files: ./coverage/lcov.info
122
- flags: unittests
123
- fail_ci_if_error: true
124
-
125
- - name: Build
126
- run: npm run build --if-present
127
-
128
- - name: Generate SBOM (CycloneDX)
129
- run: npm sbom --sbom-format=cyclonedx --sbom-type=library --omit dev > sbom.cdx.json
130
-
131
- - name: Attest SBOM (GitHub Artifact Attestations)
132
- uses: actions/attest-build-provenance@v3
133
- with:
134
- subject-path: sbom.cdx.json
135
-
136
- - name: Bump version & decide publish flags
137
- id: pkg
138
- env:
139
- NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
140
- run: |
141
- set -euo pipefail
142
- git config user.name "github-actions[bot]"
143
- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
144
- NEW_VER=$(npm version patch -m "chore: release v%s [skip ci]")
145
- echo "New version: $NEW_VER"
146
- git push --follow-tags
147
-
148
- # Expose tag (vX.Y.Z) and version (X.Y.Z) for later steps
149
- VER_NO_V=${NEW_VER#v}
150
- echo "tag=$NEW_VER" >> "$GITHUB_OUTPUT"
151
- echo "version=$VER_NO_V" >> "$GITHUB_OUTPUT"
152
-
153
- NAME=$(node -p "require('./package.json').name")
154
- echo "name=$NAME" >> "$GITHUB_OUTPUT"
155
- if npm view "$NAME" version >/dev/null 2>&1; then
156
- echo "flags=" >> "$GITHUB_OUTPUT"
157
- else
158
- echo "flags=--access public" >> "$GITHUB_OUTPUT"
159
- fi
160
-
161
211
  - name: Create GitHub Release from tag (first-party)
162
212
  env:
163
213
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
package/CHANGELOG.md CHANGED
@@ -21,24 +21,50 @@ The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/
21
21
  - **Security**
22
22
  - (placeholder)
23
23
 
24
- ## [] - 2025-09-17
24
+ ## [1.1.0] - 2025-09-18
25
25
 
26
26
  - **Added**
27
- - chore: Code coverage added
27
+ - field().upgrade() function now added to allow upgrades of older data sets to newer data.
28
+ - min/max/pattern/default FieldBuilder elements added for validation.
29
+ - Added new validator for language code BCP 47 format.
30
+ - Added new validator options for ISO DATE TIME filtering to Date or Time or Both
31
+ - Added new pre-built field() types including PII flags and validators for:
32
+ - email
33
+ - phone
34
+ - url
35
+ - uuid
36
+ - dateTimeISO
37
+ - dateISO
38
+ - timeISO
39
+ - richText
40
+ - generalText
41
+ - latitude
42
+ - longitude
43
+ - version
44
+ - countryCode
45
+ - languageCode
46
+ - New field().xxx tests for the above types.
28
47
 
29
48
  - **Changed**
30
- - (placeholder)
49
+ - Updated CD Pipeline to accept a new param for version Major, Minor or Patch update
31
50
 
32
51
  - **Fixed**
33
- - (placeholder)
52
+ - validateISODateTime for dateTime now accepts string matches that might not be the same as the date.toISOString() return value but are still valid ISO Date Time Strings.
34
53
 
35
54
  - **Security**
36
55
  - (placeholder)
37
56
 
38
- ## [1.0.13] - 2025-09-16
57
+ ## [1.0.18] - 2025-09-17
58
+
59
+ - **Fixed**
60
+ - CD pipeline reorder fix to restore CHANGELOG.md versions
61
+
62
+ ## [1.0.17] - 2025-09-17
39
63
 
40
64
  - **Added**
41
- - (placeholder) Add new validators, field helpers, or PII utilities here.
65
+ - chore: Code coverage added
66
+
67
+ ## [1.0.13] - 2025-09-16
42
68
 
43
69
  - **Changed**
44
70
  - ./src/schema.ts Added comments defining functionality on all externally facing functions.
@@ -46,9 +72,6 @@ The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/
46
72
  - **Fixed**
47
73
  - ./src/schema.ts Validation no longer mutates the input, internal system fields are set only on result if not previously present.
48
74
 
49
- - **Security**
50
- - (placeholder)
51
-
52
75
  ---
53
76
 
54
77
  ## [1.0.0] - 2025-09-16
@@ -89,7 +112,9 @@ The format is based on **[Keep a Changelog](https://keepachangelog.com/en/1.1.0/
89
112
 
90
113
  ---
91
114
 
92
- [Unreleased]: https://github.com/Plasius-LTD/schema/compare/v...HEAD
115
+ [Unreleased]: https://github.com/Plasius-LTD/schema/compare/v1.1.0...HEAD
93
116
  [1.0.0]: https://github.com/Plasius-LTD/schema/releases/tag/v1.0.0
94
117
  [1.0.13]: https://github.com/Plasius-LTD/schema/releases/tag/v1.0.13
95
- []: https://github.com/Plasius-LTD/schema/releases/tag/v
118
+ [1.0.17]: https://github.com/Plasius-LTD/schema/releases/tag/v1.0.17
119
+ [1.0.18]: https://github.com/Plasius-LTD/schema/releases/tag/v1.0.18
120
+ [1.1.0]: https://github.com/Plasius-LTD/schema/releases/tag/v1.1.0
package/README.md CHANGED
@@ -38,10 +38,149 @@ This ensures your local development environment matches the version used in CI/C
38
38
 
39
39
  ## Usage Example
40
40
 
41
- ```js
41
+ ### Imports
42
+
43
+ ```ts
44
+ import {
45
+ // core
46
+ createSchema,
47
+ field,
48
+ getSchemaForType,
49
+ getAllSchemas
50
+ } from "@plasius/schema";
51
+ ```
52
+
53
+ ### 1) Define fields with the `field()` builder
54
+
55
+ > Below uses the fluent builder exported via `field`/`field.builder`.
56
+
57
+ ```ts
58
+ const UserFields = {
59
+ id: field.string().uuid().required().description("Unique user id"),
60
+ email: field.email().required(),
61
+ name: field.name().optional(),
62
+ age: field.number().int().min(0).optional(),
63
+ roles: field.array(field.string().enum(["admin", "user"]))
64
+ .default(["user"]).description("RBAC roles"),
65
+ createdAt: field.dateTimeISO().default(() => new Date()),
66
+ };
67
+ ```
68
+
69
+ Common methods (non‑exhaustive): `.required()`, `.optional()`, `.default(v|fn)`, `.description(text)`, and type‑specific helpers like `.email()`, `.uuid()`, `.min()`, `.max()`, `.enum([...])`.
70
+
71
+ ### 2) Create a **versioned** schema (enforces `type` + `version`)
72
+
73
+ ```ts
74
+ export const UserSchema = createSchema({
75
+ entityType: "user",
76
+ version: "1.0.0",
77
+ fields: UserFields,
78
+ });
42
79
 
80
+ // Strongly-typed entity from a schema definition
81
+ export type User = Infer<typeof UserSchema>;
43
82
  ```
44
83
 
84
+ Schemas are discoverable at runtime if you register them during module init:
85
+
86
+ ```ts
87
+ // later in app code
88
+ const s = getSchemaForType("user"); // returns UserSchema
89
+ const all = getAllSchemas(); // Map<string, Map<string, Schema>> or similar
90
+ ```
91
+
92
+ ### 3) Validate data against the schema
93
+
94
+ ```ts
95
+ const raw = {
96
+ type: "user",
97
+ version: "1.0.0",
98
+ id: crypto.randomUUID(),
99
+ email: "alice@example.com",
100
+ };
101
+
102
+ const result = UserSchemavalidate(raw);
103
+ if (result.valid && result.errors.length == 0) {
104
+ // result.value is typed as User
105
+ const user: User = result.value;
106
+ } else {
107
+ // result.errors: ValidationError[] (path/code/message)
108
+ console.error(result.errors);
109
+ }
110
+ ```
111
+
112
+ > If your validation layer also exposes a throwing variant (e.g. `validateOrThrow(UserSchema, raw)`), you can use that in places where exceptions are preferred.
113
+
114
+ ### 4) Version enforcement in action
115
+
116
+ If either `type` or `version` doesn’t match the schema, validation fails.
117
+
118
+ ```ts
119
+ const wrong = { type: "User", version: "2.0.0", id: "123", email: "x@x" };
120
+ const bad = UserSchema.validate(wrong);
121
+ // bad.valid === false; errors will include mismatches for type/version
122
+ ```
123
+
124
+ ### 5) Evolving your schema
125
+
126
+ Keep new versions side‑by‑side and migrate at edges:
127
+
128
+ ```ts
129
+ export const UserV2 = createSchema({
130
+ entityType: "user",
131
+ version: "2.0.0",
132
+ fields: {
133
+ ...UserFields,
134
+ displayName: field.string().min(1).max(100).optional(),
135
+ },
136
+ });
137
+ ```
138
+
139
+ > Write a small migration function in your app to transform `User (1.0.0)` → `User (2.0.0)` where needed.
140
+
141
+ ### 6) Field-level upgrades
142
+
143
+ The schema supports a new `.upgrade()` method on fields to define field-level upgrade logic. This is useful when tightening restrictions on a field, such as reducing maximum length, strengthening format constraints, or normalizing values, without changing the field’s overall shape.
144
+
145
+ For example, suppose a `displayName` field previously allowed strings up to 60 characters, but you want to reduce the max length to 55 characters and normalize whitespace by trimming and collapsing spaces. You can define an upgrader function that attempts to fix old values to meet the new constraints:
146
+
147
+ ```ts
148
+ const UserV3Fields = {
149
+ ...UserFields,
150
+ displayName: field.string().max(55).optional()
151
+ .upgrade((oldValue) => {
152
+ if (typeof oldValue !== "string") {
153
+ return { ok: false, error: "Expected string" };
154
+ }
155
+ // Normalize whitespace: trim and collapse multiple spaces
156
+ const normalized = oldValue.trim().replace(/\s+/g, " ");
157
+ if (normalized.length > 55) {
158
+ return { ok: false, error: "Display name too long after normalization" };
159
+ }
160
+ return { ok: true, value: normalized };
161
+ }),
162
+ };
163
+
164
+ export const UserV3 = createSchema({
165
+ entityType: "user",
166
+ version: "3.0.0",
167
+ fields: UserV3Fields,
168
+ });
169
+ ```
170
+
171
+ Other typical upgrade strategies include:
172
+
173
+ - Clamping numeric values to new min/max bounds
174
+ - Remapping enum values to new sets or keys
175
+ - Normalizing whitespace or case in strings
176
+ - Converting deprecated flag values to new formats
177
+
178
+ During validation, if the entity version is less than the schema version and the field's value fails validation, the upgrader function will be invoked to attempt to transform the old value into a valid new value. If the upgrade succeeds and the transformed value passes validation, the upgraded value is used. If the upgrade fails or the transformed value still does not validate, validation errors will be returned.
179
+
180
+ **Note:** Field-level upgrades only run when the schema version is greater than the entity version and the field validation initially fails. This provides a convenient way to handle incremental field changes without requiring full schema migrations.
181
+
182
+ You can still write schema-level migration functions for larger or more complex changes that affect multiple fields or require more extensive transformation logic. Field-level upgrades complement these by handling simpler, localized upgrades directly within the schema definition.
183
+
45
184
  ---
46
185
 
47
186
  ## Contributing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plasius/schema",
3
- "version": "1.0.17",
3
+ "version": "1.1.0",
4
4
  "description": "Entity schema definition & validation helpers for Plasius ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
package/sbom.cdx.json CHANGED
@@ -2,10 +2,10 @@
2
2
  "$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
3
3
  "bomFormat": "CycloneDX",
4
4
  "specVersion": "1.5",
5
- "serialNumber": "urn:uuid:43d0373e-dc7f-4ab2-8ccd-d33f85227d3f",
5
+ "serialNumber": "urn:uuid:329219f1-3f86-497c-9d0e-3dc025a3a272",
6
6
  "version": 1,
7
7
  "metadata": {
8
- "timestamp": "2025-09-17T15:25:09.276Z",
8
+ "timestamp": "2025-09-18T14:38:35.724Z",
9
9
  "lifecycles": [
10
10
  {
11
11
  "phase": "build"
@@ -19,14 +19,14 @@
19
19
  }
20
20
  ],
21
21
  "component": {
22
- "bom-ref": "@plasius/schema@1.0.16",
22
+ "bom-ref": "@plasius/schema@1.1.0",
23
23
  "type": "library",
24
24
  "name": "schema",
25
- "version": "1.0.16",
25
+ "version": "1.1.0",
26
26
  "scope": "required",
27
27
  "author": "Plasius LTD",
28
28
  "description": "Entity schema definition & validation helpers for Plasius ecosystem",
29
- "purl": "pkg:npm/%40plasius/schema@1.0.16",
29
+ "purl": "pkg:npm/%40plasius/schema@1.1.0",
30
30
  "properties": [
31
31
  {
32
32
  "name": "cdx:npm:package:path",
@@ -59,7 +59,7 @@
59
59
  "components": [],
60
60
  "dependencies": [
61
61
  {
62
- "ref": "@plasius/schema@1.0.16",
62
+ "ref": "@plasius/schema@1.1.0",
63
63
  "dependsOn": []
64
64
  }
65
65
  ]
@@ -11,7 +11,17 @@ export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
11
11
  isRequired = true;
12
12
  _validator?: (value: any) => boolean;
13
13
  _description: string = "";
14
- _version: string = "1.0";
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 };
15
25
  _shape?: Record<string, FieldBuilder<any>>;
16
26
  itemType?: FieldBuilder<any>;
17
27
  refType?: string;
@@ -68,6 +78,41 @@ export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
68
78
  return this;
69
79
  }
70
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
+
71
116
  version(ver: string): FieldBuilder<TExternal, TInternal> {
72
117
  this._version = ver;
73
118
  return this;
@@ -80,6 +125,72 @@ export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
80
125
  return this;
81
126
  }
82
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
+
83
194
  enum<const U extends readonly TInternal[]>(
84
195
  values: U
85
196
  ): FieldBuilder<U[number]> {
@@ -99,10 +210,16 @@ export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
99
210
  return this as any;
100
211
  }
101
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
+ */
102
218
  as<U>(): FieldBuilder<U, TInternal> {
103
219
  const clone = new FieldBuilder<U, TInternal>(this.type, {
104
220
  shape: this._shape,
105
221
  itemType: this.itemType,
222
+ refType: this.refType,
106
223
  });
107
224
  clone.enumValues = this.enumValues;
108
225
  clone.isImmutable = this.isImmutable;
@@ -112,6 +229,9 @@ export class FieldBuilder<TExternal = unknown, TInternal = TExternal> {
112
229
  clone._version = this._version;
113
230
  clone._pii = this._pii;
114
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
115
235
  return clone;
116
236
  }
117
237
  }