@palmares/schemas 0.1.19 → 0.1.21
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/.turbo/turbo-build.log +4 -13
- package/CHANGELOG.md +22 -0
- package/dist/cjs/src/adapter/index.js +2 -0
- package/dist/cjs/src/conf.js +3 -4
- package/dist/cjs/src/model.js +34 -38
- package/dist/cjs/src/schema/array.js +1 -0
- package/dist/cjs/src/schema/object.js +2 -8
- package/dist/cjs/src/schema/schema.js +1 -0
- package/dist/cjs/src/utils.js +12 -14
- package/dist/cjs/src/validators/utils.js +1 -0
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
- package/dist/cjs/types/adapter/index.d.ts +2 -0
- package/dist/cjs/types/adapter/index.d.ts.map +1 -1
- package/dist/cjs/types/conf.d.ts +3 -0
- package/dist/cjs/types/conf.d.ts.map +1 -1
- package/dist/cjs/types/domain.d.ts +3 -0
- package/dist/cjs/types/domain.d.ts.map +1 -1
- package/dist/cjs/types/model.d.ts +2 -2
- package/dist/cjs/types/model.d.ts.map +1 -1
- package/dist/cjs/types/schema/array.d.ts +1 -0
- package/dist/cjs/types/schema/array.d.ts.map +1 -1
- package/dist/cjs/types/schema/object.d.ts.map +1 -1
- package/dist/cjs/types/schema/schema.d.ts +1 -0
- package/dist/cjs/types/schema/schema.d.ts.map +1 -1
- package/dist/cjs/types/utils.d.ts +2 -1
- package/dist/cjs/types/utils.d.ts.map +1 -1
- package/dist/cjs/types/validators/utils.d.ts +1 -0
- package/dist/cjs/types/validators/utils.d.ts.map +1 -1
- package/dist/esm/src/adapter/index.js +2 -0
- package/dist/esm/src/conf.js +3 -4
- package/dist/esm/src/model.js +32 -30
- package/dist/esm/src/schema/array.js +1 -0
- package/dist/esm/src/schema/object.js +2 -1
- package/dist/esm/src/schema/schema.js +1 -0
- package/dist/esm/src/utils.js +9 -6
- package/dist/esm/src/validators/utils.js +1 -0
- package/package.json +5 -5
- package/src/adapter/index.ts +2 -0
- package/src/conf.ts +7 -4
- package/src/model.ts +68 -57
- package/src/schema/array.ts +1 -0
- package/src/schema/object.ts +2 -1
- package/src/schema/schema.ts +1 -0
- package/src/utils.ts +12 -6
- package/src/validators/utils.ts +1 -0
package/src/schema/object.ts
CHANGED
@@ -110,7 +110,8 @@ export class ObjectSchema<
|
|
110
110
|
}
|
111
111
|
}
|
112
112
|
};
|
113
|
-
|
113
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
114
|
+
if (valueToTransform?.['$$type'] === '$PSchema') promises.push(awaitableTransformer());
|
114
115
|
}
|
115
116
|
|
116
117
|
await Promise.all(promises);
|
package/src/schema/schema.ts
CHANGED
@@ -27,6 +27,7 @@ export class Schema<
|
|
27
27
|
},
|
28
28
|
TDefinitions extends DefinitionsOfSchemaType = DefinitionsOfSchemaType
|
29
29
|
> {
|
30
|
+
protected $$type = '$PSchema';
|
30
31
|
protected fieldType = 'schema';
|
31
32
|
// Those functions will assume control of the validation process on adapters, instead of the schema.
|
32
33
|
// Why this is used? The idea is that the Schema has NO idea
|
package/src/utils.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { SchemaAdapter } from './adapter';
|
2
1
|
import { getDefaultAdapter } from './conf';
|
3
2
|
import { checkType, nullable, optional } from './validators/schema';
|
4
3
|
import { Validator } from './validators/utils';
|
5
4
|
|
5
|
+
import type { SchemaAdapter } from './adapter';
|
6
6
|
import type { FieldAdapter } from './adapter/fields';
|
7
7
|
import type { ValidationDataBasedOnType } from './adapter/types';
|
8
8
|
import type { Schema } from './schema/schema';
|
@@ -15,6 +15,7 @@ import type { FallbackFunctionsType, SupportedSchemas } from './types';
|
|
15
15
|
* fallback to our default implementation of the schema validation.
|
16
16
|
*/
|
17
17
|
export class WithFallback<TType extends SupportedSchemas> {
|
18
|
+
protected $$type = '$PWithFallback';
|
18
19
|
fallbackFor: Set<
|
19
20
|
| keyof Omit<ValidationDataBasedOnType<TType>, 'withFallback' | 'parsers'>
|
20
21
|
| keyof ValidationDataBasedOnType<TType>['parsers']
|
@@ -185,7 +186,8 @@ export async function defaultTransform<TType extends SupportedSchemas>(
|
|
185
186
|
};
|
186
187
|
|
187
188
|
const appendRequiredFallbacks = () => {
|
188
|
-
|
189
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
190
|
+
const hasFallbacks = schemaWithPrivateFields.__rootFallbacksValidator?.['$$type'] === '$PValidator';
|
189
191
|
if (hasFallbacks) {
|
190
192
|
Validator.createAndAppendFallback(schema, optional(schemaWithPrivateFields.__optional));
|
191
193
|
Validator.createAndAppendFallback(schema, nullable(schemaWithPrivateFields.__nullable));
|
@@ -224,7 +226,8 @@ export async function defaultTransform<TType extends SupportedSchemas>(
|
|
224
226
|
if (options.shouldAddStringVersion)
|
225
227
|
stringVersion = await fieldAdapter.toString(adapter, adapter.field, validationDataForStringVersion);
|
226
228
|
|
227
|
-
|
229
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
230
|
+
if ((translatedSchemaOrWithFallback as WithFallback<any>)?.['$$type'] === '$PWithFallback') {
|
228
231
|
appendRootFallback();
|
229
232
|
for (const fallback of translatedSchemaOrWithFallback.fallbackFor) {
|
230
233
|
checkIfShouldAppendFallbackAndAppend(fallback);
|
@@ -272,15 +275,18 @@ export async function defaultTransformToAdapter(
|
|
272
275
|
const isTransformedSchemasEmpty = Object.keys(transformedSchemas).length <= 0;
|
273
276
|
if (isTransformedSchemasEmpty) {
|
274
277
|
const adapterInstanceToUse =
|
275
|
-
|
276
|
-
|
278
|
+
// eslint-disable-next-line ts/no-unnecessary-condition
|
279
|
+
(options.schemaAdapter as SchemaAdapter)?.['$$type'] === '$PSchemaAdapter'
|
280
|
+
? options.schemaAdapter
|
281
|
+
: getDefaultAdapter();
|
282
|
+
schema['__transformedSchemas'][(adapterInstanceToUse as SchemaAdapter).name] = {
|
277
283
|
transformed: false,
|
278
284
|
adapter: adapterInstanceToUse,
|
279
285
|
schemas: []
|
280
286
|
};
|
281
287
|
}
|
282
288
|
|
283
|
-
const schemaAdapterNameToUse = options.schemaAdapter?.
|
289
|
+
const schemaAdapterNameToUse = options.schemaAdapter?.name || Object.keys(transformedSchemas)[0];
|
284
290
|
const isACustomSchemaAdapterAndNotYetDefined =
|
285
291
|
// eslint-disable-next-line ts/no-unnecessary-condition
|
286
292
|
transformedSchemas[schemaAdapterNameToUse] === undefined && options.schemaAdapter !== undefined;
|
package/src/validators/utils.ts
CHANGED
@@ -43,6 +43,7 @@ const typeByPriority = Object.entries(priorityByType).reduce(
|
|
43
43
|
* more powerful, because if we need to add any extra priorities we can do that easily without changing the schema.
|
44
44
|
*/
|
45
45
|
export class Validator {
|
46
|
+
protected $$type = '$PValidator';
|
46
47
|
child?: Validator;
|
47
48
|
parent?: Validator;
|
48
49
|
fallbackNamesAdded = new Set();
|