schematox 1.2.3 → 1.2.4-alpha

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 (2) hide show
  1. package/package.json +1 -2
  2. package/src/struct.ts +21 -11
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "schematox",
3
- "version": "1.2.3",
3
+ "version": "1.2.4-alpha",
4
4
  "scripts": {
5
5
  "build": "tsc",
6
- "prepublishOnly": "npm run build && bash release-check.sh",
7
6
  "test": "jest",
8
7
  "test:watch": "jest --watch",
9
8
  "test:coverage": "jest --coverage",
package/src/struct.ts CHANGED
@@ -115,19 +115,29 @@ export function object<T extends Record<string, StructShape<Schema>>>(of: T) {
115
115
  return makeStruct(schema)
116
116
  }
117
117
 
118
+ export function record<T extends StructShape<Schema>>(
119
+ of: T,
120
+ key?: undefined
121
+ ): Struct<{ type: 'record'; of: T['__schema'] }>
122
+
118
123
  export function record<
119
124
  T extends StructShape<Schema>,
120
- U extends StructShape<StringSchema> | undefined,
121
- >(of: T, key?: U) {
122
- return makeStruct(
123
- key
124
- ? {
125
- type: 'record',
126
- of: of.__schema as T['__schema'],
127
- key: key.__schema as (typeof key)['__schema'],
128
- }
129
- : { type: 'record', of: of.__schema as T['__schema'] }
130
- )
125
+ U extends StructShape<StringSchema>,
126
+ >(
127
+ of: T,
128
+ key: U
129
+ ): Struct<{ type: 'record'; of: T['__schema']; key: U['__schema'] }>
130
+
131
+ export function record(of: StructShape<any>, key?: StructShape<any>) {
132
+ if (key !== undefined) {
133
+ return makeStruct({
134
+ type: 'record',
135
+ of: of.__schema,
136
+ key: key.__schema,
137
+ })
138
+ }
139
+
140
+ return makeStruct({ type: 'record', of: of.__schema })
131
141
  }
132
142
 
133
143
  export function tuple<