@bedrockio/yada 1.0.30 → 1.0.32
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/dist/cjs/Schema.js +14 -3
- package/dist/cjs/date.js +31 -9
- package/package.json +1 -1
- package/src/Schema.js +11 -2
- package/src/date.js +22 -5
- package/types/Schema.d.ts +5 -0
- package/types/Schema.d.ts.map +1 -1
- package/types/date.d.ts.map +1 -1
package/dist/cjs/Schema.js
CHANGED
|
@@ -202,18 +202,29 @@ class Schema {
|
|
|
202
202
|
const {
|
|
203
203
|
required,
|
|
204
204
|
format,
|
|
205
|
-
tags
|
|
206
|
-
default: defaultValue
|
|
205
|
+
tags
|
|
207
206
|
} = this.meta;
|
|
208
207
|
return {
|
|
209
208
|
required,
|
|
210
|
-
default: defaultValue,
|
|
211
209
|
format,
|
|
212
210
|
...tags,
|
|
211
|
+
...this.getDefault(),
|
|
213
212
|
...this.enumToOpenApi(),
|
|
214
213
|
...this.expandExtra(extra)
|
|
215
214
|
};
|
|
216
215
|
}
|
|
216
|
+
getDefault() {
|
|
217
|
+
const {
|
|
218
|
+
default: defaultValue
|
|
219
|
+
} = this.meta;
|
|
220
|
+
if (typeof defaultValue === 'function') {
|
|
221
|
+
return {};
|
|
222
|
+
} else {
|
|
223
|
+
return {
|
|
224
|
+
default: defaultValue
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
217
228
|
inspect() {
|
|
218
229
|
return JSON.stringify(this.toOpenApi(), null, 2);
|
|
219
230
|
}
|
package/dist/cjs/date.js
CHANGED
|
@@ -111,7 +111,9 @@ class DateSchema extends _Schema.default {
|
|
|
111
111
|
original
|
|
112
112
|
} = options;
|
|
113
113
|
if (typeof original !== 'string') {
|
|
114
|
-
|
|
114
|
+
if (!options.default) {
|
|
115
|
+
throw new _errors.LocalizedError('Must be a string.');
|
|
116
|
+
}
|
|
115
117
|
} else if (!_validator.default.isISO8601(original)) {
|
|
116
118
|
throw new _errors.LocalizedError('Must be in ISO 8601 format.');
|
|
117
119
|
}
|
|
@@ -120,10 +122,11 @@ class DateSchema extends _Schema.default {
|
|
|
120
122
|
timestamp() {
|
|
121
123
|
return this.clone({
|
|
122
124
|
format: 'timestamp'
|
|
123
|
-
}).assert('format', (date, {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
}).assert('format', (date, options) => {
|
|
126
|
+
const {
|
|
127
|
+
original
|
|
128
|
+
} = options;
|
|
129
|
+
if (typeof original !== 'number' && !options.default) {
|
|
127
130
|
throw new _errors.LocalizedError('Must be a timestamp in milliseconds.');
|
|
128
131
|
}
|
|
129
132
|
});
|
|
@@ -131,11 +134,14 @@ class DateSchema extends _Schema.default {
|
|
|
131
134
|
unix() {
|
|
132
135
|
return this.clone({
|
|
133
136
|
format: 'unix timestamp'
|
|
134
|
-
}).assert('format', (date, {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
+
}).assert('format', (date, options) => {
|
|
138
|
+
const {
|
|
139
|
+
original
|
|
140
|
+
} = options;
|
|
137
141
|
if (typeof original !== 'number') {
|
|
138
|
-
|
|
142
|
+
if (!options.default) {
|
|
143
|
+
throw new _errors.LocalizedError('Must be a timestamp in seconds.');
|
|
144
|
+
}
|
|
139
145
|
} else {
|
|
140
146
|
return new Date(original * 1000);
|
|
141
147
|
}
|
|
@@ -153,6 +159,22 @@ class DateSchema extends _Schema.default {
|
|
|
153
159
|
...super.toOpenApi(extra)
|
|
154
160
|
};
|
|
155
161
|
}
|
|
162
|
+
getDefault() {
|
|
163
|
+
const {
|
|
164
|
+
default: defaultValue
|
|
165
|
+
} = this.meta;
|
|
166
|
+
if (defaultValue === Date.now) {
|
|
167
|
+
return {
|
|
168
|
+
default: 'now'
|
|
169
|
+
};
|
|
170
|
+
} else if (typeof defaultValue === 'function') {
|
|
171
|
+
return {
|
|
172
|
+
default: 'custom'
|
|
173
|
+
};
|
|
174
|
+
} else {
|
|
175
|
+
return super.getDefault();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
156
178
|
}
|
|
157
179
|
|
|
158
180
|
/**
|
package/package.json
CHANGED
package/src/Schema.js
CHANGED
|
@@ -190,17 +190,26 @@ export default class Schema {
|
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
toOpenApi(extra) {
|
|
193
|
-
const { required, format, tags
|
|
193
|
+
const { required, format, tags } = this.meta;
|
|
194
194
|
return {
|
|
195
195
|
required,
|
|
196
|
-
default: defaultValue,
|
|
197
196
|
format,
|
|
198
197
|
...tags,
|
|
198
|
+
...this.getDefault(),
|
|
199
199
|
...this.enumToOpenApi(),
|
|
200
200
|
...this.expandExtra(extra),
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
+
getDefault() {
|
|
205
|
+
const { default: defaultValue } = this.meta;
|
|
206
|
+
if (typeof defaultValue === 'function') {
|
|
207
|
+
return {};
|
|
208
|
+
} else {
|
|
209
|
+
return { default: defaultValue };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
204
213
|
inspect() {
|
|
205
214
|
return JSON.stringify(this.toOpenApi(), null, 2);
|
|
206
215
|
}
|
package/src/date.js
CHANGED
|
@@ -101,7 +101,9 @@ class DateSchema extends Schema {
|
|
|
101
101
|
return this.clone({ format }).assert('format', (val, options) => {
|
|
102
102
|
const { original } = options;
|
|
103
103
|
if (typeof original !== 'string') {
|
|
104
|
-
|
|
104
|
+
if (!options.default) {
|
|
105
|
+
throw new LocalizedError('Must be a string.');
|
|
106
|
+
}
|
|
105
107
|
} else if (!validator.isISO8601(original)) {
|
|
106
108
|
throw new LocalizedError('Must be in ISO 8601 format.');
|
|
107
109
|
}
|
|
@@ -111,8 +113,9 @@ class DateSchema extends Schema {
|
|
|
111
113
|
timestamp() {
|
|
112
114
|
return this.clone({ format: 'timestamp' }).assert(
|
|
113
115
|
'format',
|
|
114
|
-
(date,
|
|
115
|
-
|
|
116
|
+
(date, options) => {
|
|
117
|
+
const { original } = options;
|
|
118
|
+
if (typeof original !== 'number' && !options.default) {
|
|
116
119
|
throw new LocalizedError('Must be a timestamp in milliseconds.');
|
|
117
120
|
}
|
|
118
121
|
}
|
|
@@ -122,9 +125,12 @@ class DateSchema extends Schema {
|
|
|
122
125
|
unix() {
|
|
123
126
|
return this.clone({ format: 'unix timestamp' }).assert(
|
|
124
127
|
'format',
|
|
125
|
-
(date,
|
|
128
|
+
(date, options) => {
|
|
129
|
+
const { original } = options;
|
|
126
130
|
if (typeof original !== 'number') {
|
|
127
|
-
|
|
131
|
+
if (!options.default) {
|
|
132
|
+
throw new LocalizedError('Must be a timestamp in seconds.');
|
|
133
|
+
}
|
|
128
134
|
} else {
|
|
129
135
|
return new Date(original * 1000);
|
|
130
136
|
}
|
|
@@ -143,6 +149,17 @@ class DateSchema extends Schema {
|
|
|
143
149
|
...super.toOpenApi(extra),
|
|
144
150
|
};
|
|
145
151
|
}
|
|
152
|
+
|
|
153
|
+
getDefault() {
|
|
154
|
+
const { default: defaultValue } = this.meta;
|
|
155
|
+
if (defaultValue === Date.now) {
|
|
156
|
+
return { default: 'now' };
|
|
157
|
+
} else if (typeof defaultValue === 'function') {
|
|
158
|
+
return { default: 'custom' };
|
|
159
|
+
} else {
|
|
160
|
+
return super.getDefault();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
146
163
|
}
|
|
147
164
|
|
|
148
165
|
/**
|
package/types/Schema.d.ts
CHANGED
package/types/Schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAgWA,4CAEC;AAtVD;;GAEG;AAEH;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,gBAHW,eAAe,GACb,IAAI,CAmBhB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAqCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,IAAI,CAMhB;IAED,2BAUC;IAED;;;;MAOC;IAED,kBAEC;IAED,4BAMC;IAID;;OAEG;IACH,kCAFa,IAAI,CAmChB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAUC;IAED;;;;;;;;MAoCC;CACF;8BAjVY,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC"}
|
package/types/date.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../src/date.js"],"names":[],"mappings":"AAoKA;;GAEG;AACH,+CAEC;AApKD;IACE,cAUC;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,cAY5B;IAED;;OAEG;IACH,SAFW,MAAM,GAAC,MAAM,GAAC,IAAI,cAY5B;IAED;;OAEG;IACH,YAFW,MAAM,GAAC,MAAM,GAAC,IAAI,cAY5B;IAED;;OAEG;IACH,WAFW,MAAM,GAAC,MAAM,GAAC,IAAI,cAY5B;IAED,mBAOC;IAED,qBAOC;IAED;;OAEG;IACH,aAFW,MAAM,GAAG,WAAW,cAa9B;IAED,wBAUC;IAED,mBAcC;CAwBF"}
|