@dereekb/model 13.6.11 → 13.6.13
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/index.cjs.js +56 -50
- package/index.esm.js +56 -50
- package/package.json +2 -2
- package/src/lib/data/address/address.d.ts +2 -2
- package/src/lib/data/website/link.file.d.ts +3 -3
- package/src/lib/type/type.d.ts +6 -0
package/index.cjs.js
CHANGED
|
@@ -4,6 +4,44 @@ var util = require('@dereekb/util');
|
|
|
4
4
|
var arktype = require('arktype');
|
|
5
5
|
var makeError = require('make-error');
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* ArkType schema for a model key (non-empty string).
|
|
9
|
+
*/ var modelKeyType = arktype.type('string > 0');
|
|
10
|
+
/**
|
|
11
|
+
* ArkType schema for a model id (non-empty string).
|
|
12
|
+
*/ var modelIdType = arktype.type('string > 0');
|
|
13
|
+
/**
|
|
14
|
+
* ArkType schema for target model params with a required `key` field.
|
|
15
|
+
*/ var targetModelParamsType = arktype.type({
|
|
16
|
+
key: modelKeyType
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* ArkType schema for target model id params with a required `id` field.
|
|
20
|
+
*/ var targetModelIdParamsType = arktype.type({
|
|
21
|
+
id: modelIdType
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
function clearable(definition) {
|
|
25
|
+
var result;
|
|
26
|
+
if (typeof definition === 'string') {
|
|
27
|
+
result = "".concat(definition, " | null | undefined");
|
|
28
|
+
} else {
|
|
29
|
+
result = definition.or('null').or('undefined');
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Matches "Date | string.date.parse".
|
|
36
|
+
*
|
|
37
|
+
* This is used for validating and parsing serialized data (e.g., API responses, JSON payloads)
|
|
38
|
+
* and/or runtime Date objects into the corresponding runtime types.
|
|
39
|
+
*
|
|
40
|
+
* If we only used Date, or only used string.date.parse, then using the ArkType gets more specific to
|
|
41
|
+
* those independent cases, and will cause validation errors if you end up passing the object of that type
|
|
42
|
+
* rather than a freshly parsed JSON string POJO of that type.
|
|
43
|
+
*/ var ARKTYPE_DATE_DTO_TYPE = 'Date | string.date.parse';
|
|
44
|
+
|
|
7
45
|
/**
|
|
8
46
|
* Maximum character length for address line fields (line1, line2).
|
|
9
47
|
*/ var ADDRESS_LINE_MAX_LENGTH = 50;
|
|
@@ -26,7 +64,7 @@ var makeError = require('make-error');
|
|
|
26
64
|
* Base ArkType schema for United States address fields without the state.
|
|
27
65
|
*/ var baseUnitedStatesAddressType = arktype.type({
|
|
28
66
|
line1: "0 < string <= ".concat(ADDRESS_LINE_MAX_LENGTH),
|
|
29
|
-
'line2?': "string <= ".concat(ADDRESS_LINE_MAX_LENGTH),
|
|
67
|
+
'line2?': clearable("string <= ".concat(ADDRESS_LINE_MAX_LENGTH)),
|
|
30
68
|
city: "0 < string <= ".concat(ADDRESS_CITY_MAX_LENGTH),
|
|
31
69
|
zip: [
|
|
32
70
|
/^\d{5}(-\d{4})?$/,
|
|
@@ -155,20 +193,26 @@ function _unsupported_iterable_to_array$2(o, minLen) {
|
|
|
155
193
|
/**
|
|
156
194
|
* Regex pattern for file link data — disallows the pipe character since it is used as the encoding separator.
|
|
157
195
|
*/ var WEBSITE_FILE_LINK_DATA_REGEX = /^[^|]+$/;
|
|
196
|
+
/**
|
|
197
|
+
* ArkType schema for a {@link WebsiteFileLinkType} value.
|
|
198
|
+
*/ var websiteFileLinkTypeValueType = arktype.type([
|
|
199
|
+
WEBSITE_FILE_LINK_TYPE_REGEX,
|
|
200
|
+
'&',
|
|
201
|
+
"string <= ".concat(WEBSITE_LINK_TYPE_MAX_LENGTH)
|
|
202
|
+
]);
|
|
203
|
+
/**
|
|
204
|
+
* ArkType schema for a {@link WebsiteFileLinkMimeType} value.
|
|
205
|
+
*/ var websiteFileLinkMimeValueType = arktype.type([
|
|
206
|
+
WEBSITE_FILE_LINK_MIME_TYPE_REGEX,
|
|
207
|
+
'&',
|
|
208
|
+
"string <= ".concat(WEBSITE_FILE_LINK_MIME_TYPE_MAX_LENGTH)
|
|
209
|
+
]);
|
|
158
210
|
/**
|
|
159
211
|
* ArkType schema for a {@link WebsiteFileLink}.
|
|
160
212
|
*/ var websiteFileLinkType = arktype.type({
|
|
161
|
-
'type?':
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
"string <= ".concat(WEBSITE_LINK_TYPE_MAX_LENGTH)
|
|
165
|
-
],
|
|
166
|
-
'mime?': [
|
|
167
|
-
WEBSITE_FILE_LINK_MIME_TYPE_REGEX,
|
|
168
|
-
'&',
|
|
169
|
-
"string <= ".concat(WEBSITE_FILE_LINK_MIME_TYPE_MAX_LENGTH)
|
|
170
|
-
],
|
|
171
|
-
'name?': "string <= ".concat(WEBSITE_FILE_LINK_NAME_MAX_LENGTH),
|
|
213
|
+
'type?': clearable(websiteFileLinkTypeValueType),
|
|
214
|
+
'mime?': clearable(websiteFileLinkMimeValueType),
|
|
215
|
+
'name?': clearable("string <= ".concat(WEBSITE_FILE_LINK_NAME_MAX_LENGTH)),
|
|
172
216
|
data: [
|
|
173
217
|
WEBSITE_FILE_LINK_DATA_REGEX,
|
|
174
218
|
'&',
|
|
@@ -2706,44 +2750,6 @@ function _ts_generator(thisArg, body) {
|
|
|
2706
2750
|
};
|
|
2707
2751
|
}
|
|
2708
2752
|
|
|
2709
|
-
/**
|
|
2710
|
-
* ArkType schema for a model key (non-empty string).
|
|
2711
|
-
*/ var modelKeyType = arktype.type('string > 0');
|
|
2712
|
-
/**
|
|
2713
|
-
* ArkType schema for a model id (non-empty string).
|
|
2714
|
-
*/ var modelIdType = arktype.type('string > 0');
|
|
2715
|
-
/**
|
|
2716
|
-
* ArkType schema for target model params with a required `key` field.
|
|
2717
|
-
*/ var targetModelParamsType = arktype.type({
|
|
2718
|
-
key: modelKeyType
|
|
2719
|
-
});
|
|
2720
|
-
/**
|
|
2721
|
-
* ArkType schema for target model id params with a required `id` field.
|
|
2722
|
-
*/ var targetModelIdParamsType = arktype.type({
|
|
2723
|
-
id: modelIdType
|
|
2724
|
-
});
|
|
2725
|
-
|
|
2726
|
-
function clearable(definition) {
|
|
2727
|
-
var result;
|
|
2728
|
-
if (typeof definition === 'string') {
|
|
2729
|
-
result = "".concat(definition, " | null | undefined");
|
|
2730
|
-
} else {
|
|
2731
|
-
result = definition.or('null').or('undefined');
|
|
2732
|
-
}
|
|
2733
|
-
return result;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
|
-
/**
|
|
2737
|
-
* Matches "Date | string.date.parse".
|
|
2738
|
-
*
|
|
2739
|
-
* This is used for validating and parsing serialized data (e.g., API responses, JSON payloads)
|
|
2740
|
-
* and/or runtime Date objects into the corresponding runtime types.
|
|
2741
|
-
*
|
|
2742
|
-
* If we only used Date, or only used string.date.parse, then using the ArkType gets more specific to
|
|
2743
|
-
* those independent cases, and will cause validation errors if you end up passing the object of that type
|
|
2744
|
-
* rather than a freshly parsed JSON string POJO of that type.
|
|
2745
|
-
*/ var ARKTYPE_DATE_DTO_TYPE = 'Date | string.date.parse';
|
|
2746
|
-
|
|
2747
2753
|
/**
|
|
2748
2754
|
* ArkType schema for a valid ISO 8601 day string (e.g., "2024-01-15").
|
|
2749
2755
|
*/ var iso8601DayStringType = arktype.type('string > 0').narrow(function(val, ctx) {
|
package/index.esm.js
CHANGED
|
@@ -2,6 +2,44 @@ import { US_STATE_CODE_STRING_REGEX, splitJoinRemainder, filterFalsyAndEmptyValu
|
|
|
2
2
|
import { type } from 'arktype';
|
|
3
3
|
import { BaseError } from 'make-error';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* ArkType schema for a model key (non-empty string).
|
|
7
|
+
*/ var modelKeyType = type('string > 0');
|
|
8
|
+
/**
|
|
9
|
+
* ArkType schema for a model id (non-empty string).
|
|
10
|
+
*/ var modelIdType = type('string > 0');
|
|
11
|
+
/**
|
|
12
|
+
* ArkType schema for target model params with a required `key` field.
|
|
13
|
+
*/ var targetModelParamsType = type({
|
|
14
|
+
key: modelKeyType
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* ArkType schema for target model id params with a required `id` field.
|
|
18
|
+
*/ var targetModelIdParamsType = type({
|
|
19
|
+
id: modelIdType
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function clearable(definition) {
|
|
23
|
+
var result;
|
|
24
|
+
if (typeof definition === 'string') {
|
|
25
|
+
result = "".concat(definition, " | null | undefined");
|
|
26
|
+
} else {
|
|
27
|
+
result = definition.or('null').or('undefined');
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Matches "Date | string.date.parse".
|
|
34
|
+
*
|
|
35
|
+
* This is used for validating and parsing serialized data (e.g., API responses, JSON payloads)
|
|
36
|
+
* and/or runtime Date objects into the corresponding runtime types.
|
|
37
|
+
*
|
|
38
|
+
* If we only used Date, or only used string.date.parse, then using the ArkType gets more specific to
|
|
39
|
+
* those independent cases, and will cause validation errors if you end up passing the object of that type
|
|
40
|
+
* rather than a freshly parsed JSON string POJO of that type.
|
|
41
|
+
*/ var ARKTYPE_DATE_DTO_TYPE = 'Date | string.date.parse';
|
|
42
|
+
|
|
5
43
|
/**
|
|
6
44
|
* Maximum character length for address line fields (line1, line2).
|
|
7
45
|
*/ var ADDRESS_LINE_MAX_LENGTH = 50;
|
|
@@ -24,7 +62,7 @@ import { BaseError } from 'make-error';
|
|
|
24
62
|
* Base ArkType schema for United States address fields without the state.
|
|
25
63
|
*/ var baseUnitedStatesAddressType = type({
|
|
26
64
|
line1: "0 < string <= ".concat(ADDRESS_LINE_MAX_LENGTH),
|
|
27
|
-
'line2?': "string <= ".concat(ADDRESS_LINE_MAX_LENGTH),
|
|
65
|
+
'line2?': clearable("string <= ".concat(ADDRESS_LINE_MAX_LENGTH)),
|
|
28
66
|
city: "0 < string <= ".concat(ADDRESS_CITY_MAX_LENGTH),
|
|
29
67
|
zip: [
|
|
30
68
|
/^\d{5}(-\d{4})?$/,
|
|
@@ -153,20 +191,26 @@ function _unsupported_iterable_to_array$2(o, minLen) {
|
|
|
153
191
|
/**
|
|
154
192
|
* Regex pattern for file link data — disallows the pipe character since it is used as the encoding separator.
|
|
155
193
|
*/ var WEBSITE_FILE_LINK_DATA_REGEX = /^[^|]+$/;
|
|
194
|
+
/**
|
|
195
|
+
* ArkType schema for a {@link WebsiteFileLinkType} value.
|
|
196
|
+
*/ var websiteFileLinkTypeValueType = type([
|
|
197
|
+
WEBSITE_FILE_LINK_TYPE_REGEX,
|
|
198
|
+
'&',
|
|
199
|
+
"string <= ".concat(WEBSITE_LINK_TYPE_MAX_LENGTH)
|
|
200
|
+
]);
|
|
201
|
+
/**
|
|
202
|
+
* ArkType schema for a {@link WebsiteFileLinkMimeType} value.
|
|
203
|
+
*/ var websiteFileLinkMimeValueType = type([
|
|
204
|
+
WEBSITE_FILE_LINK_MIME_TYPE_REGEX,
|
|
205
|
+
'&',
|
|
206
|
+
"string <= ".concat(WEBSITE_FILE_LINK_MIME_TYPE_MAX_LENGTH)
|
|
207
|
+
]);
|
|
156
208
|
/**
|
|
157
209
|
* ArkType schema for a {@link WebsiteFileLink}.
|
|
158
210
|
*/ var websiteFileLinkType = type({
|
|
159
|
-
'type?':
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"string <= ".concat(WEBSITE_LINK_TYPE_MAX_LENGTH)
|
|
163
|
-
],
|
|
164
|
-
'mime?': [
|
|
165
|
-
WEBSITE_FILE_LINK_MIME_TYPE_REGEX,
|
|
166
|
-
'&',
|
|
167
|
-
"string <= ".concat(WEBSITE_FILE_LINK_MIME_TYPE_MAX_LENGTH)
|
|
168
|
-
],
|
|
169
|
-
'name?': "string <= ".concat(WEBSITE_FILE_LINK_NAME_MAX_LENGTH),
|
|
211
|
+
'type?': clearable(websiteFileLinkTypeValueType),
|
|
212
|
+
'mime?': clearable(websiteFileLinkMimeValueType),
|
|
213
|
+
'name?': clearable("string <= ".concat(WEBSITE_FILE_LINK_NAME_MAX_LENGTH)),
|
|
170
214
|
data: [
|
|
171
215
|
WEBSITE_FILE_LINK_DATA_REGEX,
|
|
172
216
|
'&',
|
|
@@ -2704,44 +2748,6 @@ function _ts_generator(thisArg, body) {
|
|
|
2704
2748
|
};
|
|
2705
2749
|
}
|
|
2706
2750
|
|
|
2707
|
-
/**
|
|
2708
|
-
* ArkType schema for a model key (non-empty string).
|
|
2709
|
-
*/ var modelKeyType = type('string > 0');
|
|
2710
|
-
/**
|
|
2711
|
-
* ArkType schema for a model id (non-empty string).
|
|
2712
|
-
*/ var modelIdType = type('string > 0');
|
|
2713
|
-
/**
|
|
2714
|
-
* ArkType schema for target model params with a required `key` field.
|
|
2715
|
-
*/ var targetModelParamsType = type({
|
|
2716
|
-
key: modelKeyType
|
|
2717
|
-
});
|
|
2718
|
-
/**
|
|
2719
|
-
* ArkType schema for target model id params with a required `id` field.
|
|
2720
|
-
*/ var targetModelIdParamsType = type({
|
|
2721
|
-
id: modelIdType
|
|
2722
|
-
});
|
|
2723
|
-
|
|
2724
|
-
function clearable(definition) {
|
|
2725
|
-
var result;
|
|
2726
|
-
if (typeof definition === 'string') {
|
|
2727
|
-
result = "".concat(definition, " | null | undefined");
|
|
2728
|
-
} else {
|
|
2729
|
-
result = definition.or('null').or('undefined');
|
|
2730
|
-
}
|
|
2731
|
-
return result;
|
|
2732
|
-
}
|
|
2733
|
-
|
|
2734
|
-
/**
|
|
2735
|
-
* Matches "Date | string.date.parse".
|
|
2736
|
-
*
|
|
2737
|
-
* This is used for validating and parsing serialized data (e.g., API responses, JSON payloads)
|
|
2738
|
-
* and/or runtime Date objects into the corresponding runtime types.
|
|
2739
|
-
*
|
|
2740
|
-
* If we only used Date, or only used string.date.parse, then using the ArkType gets more specific to
|
|
2741
|
-
* those independent cases, and will cause validation errors if you end up passing the object of that type
|
|
2742
|
-
* rather than a freshly parsed JSON string POJO of that type.
|
|
2743
|
-
*/ var ARKTYPE_DATE_DTO_TYPE = 'Date | string.date.parse';
|
|
2744
|
-
|
|
2745
2751
|
/**
|
|
2746
2752
|
* ArkType schema for a valid ISO 8601 day string (e.g., "2024-01-15").
|
|
2747
2753
|
*/ var iso8601DayStringType = type('string > 0').narrow(function(val, ctx) {
|
package/package.json
CHANGED
|
@@ -29,7 +29,7 @@ export declare const unitedStatesAddressWithStateCodeType: import("arktype/inter
|
|
|
29
29
|
line1: string;
|
|
30
30
|
city: string;
|
|
31
31
|
zip: string;
|
|
32
|
-
line2?: string | undefined;
|
|
32
|
+
line2?: string | null | undefined;
|
|
33
33
|
state: string;
|
|
34
34
|
}, {}>;
|
|
35
35
|
export type UnitedStatesAddressWithStateCodeParams = typeof unitedStatesAddressWithStateCodeType.infer;
|
|
@@ -40,7 +40,7 @@ export declare const unitedStatesAddressWithStateStringType: import("arktype/int
|
|
|
40
40
|
line1: string;
|
|
41
41
|
city: string;
|
|
42
42
|
zip: string;
|
|
43
|
-
line2?: string | undefined;
|
|
43
|
+
line2?: string | null | undefined;
|
|
44
44
|
state: string;
|
|
45
45
|
}, {}>;
|
|
46
46
|
export type UnitedStatesAddressWithStateStringParams = typeof unitedStatesAddressWithStateStringType.infer;
|
|
@@ -73,9 +73,9 @@ export interface WebsiteFileLink {
|
|
|
73
73
|
*/
|
|
74
74
|
export declare const websiteFileLinkType: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
75
75
|
data: string;
|
|
76
|
-
type?: string | undefined;
|
|
77
|
-
mime?: string | undefined;
|
|
78
|
-
name?: string | undefined;
|
|
76
|
+
type?: string | null | undefined;
|
|
77
|
+
mime?: string | null | undefined;
|
|
78
|
+
name?: string | null | undefined;
|
|
79
79
|
}, {}>;
|
|
80
80
|
/**
|
|
81
81
|
* A pipe-separated encoded string representation of a {@link WebsiteFileLink}.
|
package/src/lib/type/type.d.ts
CHANGED
|
@@ -35,6 +35,12 @@ export type Clearable<T> = Maybe<T>;
|
|
|
35
35
|
* "phone?": clearable(e164PhoneNumberType), // Type instance
|
|
36
36
|
* "items?": clearable(mySchemaType.array()), // .array() result
|
|
37
37
|
* });
|
|
38
|
+
*
|
|
39
|
+
* // For tuple expressions (e.g. intersections), resolve to a Type first:
|
|
40
|
+
* const zipType = type([/^\d{5}(-\d{4})?$/, '&', `string <= 11`]);
|
|
41
|
+
* const schema2 = type({
|
|
42
|
+
* "zip?": clearable(zipType),
|
|
43
|
+
* });
|
|
38
44
|
* ```
|
|
39
45
|
*
|
|
40
46
|
* @param definition The ArkType definition string or Type instance to make clearable.
|