@palmares/schemas 0.1.18 → 0.1.20
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 +1 -19
- package/CHANGELOG.md +22 -0
- package/dist/cjs/src/adapter/fields/array.js +5 -10
- package/dist/cjs/src/adapter/fields/boolean.js +5 -10
- package/dist/cjs/src/adapter/fields/datetime.js +5 -10
- package/dist/cjs/src/adapter/fields/index.js +1 -1
- package/dist/cjs/src/adapter/fields/number.js +3 -8
- package/dist/cjs/src/adapter/fields/object.js +3 -8
- package/dist/cjs/src/adapter/fields/string.js +3 -8
- package/dist/cjs/src/adapter/fields/union.js +3 -8
- package/dist/cjs/src/adapter/index.js +1 -1
- package/dist/cjs/src/compile.js +1 -1
- package/dist/cjs/src/domain.js +2 -3
- package/dist/cjs/src/index.js +49 -92
- package/dist/cjs/src/middleware.js +1 -3
- package/dist/cjs/src/model.js +10 -15
- package/dist/cjs/src/parsers/convert-from-number.js +1 -6
- package/dist/cjs/src/parsers/convert-from-string.js +1 -6
- package/dist/cjs/src/parsers/index.js +4 -9
- package/dist/cjs/src/schema/array.js +7 -12
- package/dist/cjs/src/schema/boolean.js +7 -12
- package/dist/cjs/src/schema/datetime.js +5 -10
- package/dist/cjs/src/schema/index.js +2 -7
- package/dist/cjs/src/schema/number.js +3 -8
- package/dist/cjs/src/schema/object.js +6 -11
- package/dist/cjs/src/schema/schema.js +1 -1
- package/dist/cjs/src/schema/string.js +3 -8
- package/dist/cjs/src/schema/union.js +5 -10
- package/dist/cjs/src/utils.js +10 -15
- package/dist/cjs/src/validators/utils.js +1 -1
- package/dist/cjs/tsconfig.types.tsbuildinfo +1 -1
- package/dist/cjs/types/adapter/fields/array.d.ts +3 -3
- package/dist/cjs/types/adapter/fields/array.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/boolean.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/boolean.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/datetime.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/datetime.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/index.d.ts +3 -3
- package/dist/cjs/types/adapter/fields/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/number.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/number.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/object.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/object.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/string.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/string.d.ts.map +1 -1
- package/dist/cjs/types/adapter/fields/union.d.ts +4 -4
- package/dist/cjs/types/adapter/fields/union.d.ts.map +1 -1
- package/dist/cjs/types/adapter/index.d.ts +9 -9
- package/dist/cjs/types/adapter/index.d.ts.map +1 -1
- package/dist/cjs/types/adapter/types.d.ts +1 -1
- package/dist/cjs/types/adapter/types.d.ts.map +1 -1
- package/dist/cjs/types/compile.d.ts +2 -2
- package/dist/cjs/types/compile.d.ts.map +1 -1
- package/dist/cjs/types/conf.d.ts +1 -1
- package/dist/cjs/types/conf.d.ts.map +1 -1
- package/dist/cjs/types/domain.d.ts +1 -2
- package/dist/cjs/types/domain.d.ts.map +1 -1
- package/dist/cjs/types/index.d.ts +21 -20
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/middleware.d.ts +2 -2
- package/dist/cjs/types/middleware.d.ts.map +1 -1
- package/dist/cjs/types/model.d.ts +3 -3
- package/dist/cjs/types/model.d.ts.map +1 -1
- package/dist/cjs/types/parsers/convert-from-number.d.ts +2 -2
- package/dist/cjs/types/parsers/convert-from-number.d.ts.map +1 -1
- package/dist/cjs/types/parsers/convert-from-string.d.ts +2 -2
- package/dist/cjs/types/parsers/convert-from-string.d.ts.map +1 -1
- package/dist/cjs/types/parsers/index.d.ts +2 -2
- package/dist/cjs/types/parsers/index.d.ts.map +1 -1
- package/dist/cjs/types/schema/array.d.ts +2 -2
- package/dist/cjs/types/schema/array.d.ts.map +1 -1
- package/dist/cjs/types/schema/boolean.d.ts +2 -2
- package/dist/cjs/types/schema/boolean.d.ts.map +1 -1
- package/dist/cjs/types/schema/datetime.d.ts +2 -2
- package/dist/cjs/types/schema/datetime.d.ts.map +1 -1
- package/dist/cjs/types/schema/index.d.ts +1 -1
- package/dist/cjs/types/schema/index.d.ts.map +1 -1
- package/dist/cjs/types/schema/number.d.ts +2 -2
- package/dist/cjs/types/schema/number.d.ts.map +1 -1
- package/dist/cjs/types/schema/object.d.ts +3 -3
- package/dist/cjs/types/schema/object.d.ts.map +1 -1
- package/dist/cjs/types/schema/schema.d.ts +4 -4
- package/dist/cjs/types/schema/schema.d.ts.map +1 -1
- package/dist/cjs/types/schema/string.d.ts +2 -2
- package/dist/cjs/types/schema/string.d.ts.map +1 -1
- package/dist/cjs/types/schema/types.d.ts +7 -7
- package/dist/cjs/types/schema/types.d.ts.map +1 -1
- package/dist/cjs/types/schema/union.d.ts +3 -3
- package/dist/cjs/types/schema/union.d.ts.map +1 -1
- package/dist/cjs/types/types.d.ts +2 -2
- package/dist/cjs/types/types.d.ts.map +1 -1
- package/dist/cjs/types/utils.d.ts +4 -4
- package/dist/cjs/types/utils.d.ts.map +1 -1
- package/dist/cjs/types/validators/array.d.ts +2 -2
- package/dist/cjs/types/validators/array.d.ts.map +1 -1
- package/dist/cjs/types/validators/datetime.d.ts +1 -1
- package/dist/cjs/types/validators/datetime.d.ts.map +1 -1
- package/dist/cjs/types/validators/number.d.ts +1 -1
- package/dist/cjs/types/validators/number.d.ts.map +1 -1
- package/dist/cjs/types/validators/object.d.ts +1 -1
- package/dist/cjs/types/validators/object.d.ts.map +1 -1
- package/dist/cjs/types/validators/schema.d.ts +4 -4
- package/dist/cjs/types/validators/schema.d.ts.map +1 -1
- package/dist/cjs/types/validators/string.d.ts +1 -1
- package/dist/cjs/types/validators/string.d.ts.map +1 -1
- package/dist/cjs/types/validators/union.d.ts +1 -1
- package/dist/cjs/types/validators/union.d.ts.map +1 -1
- package/dist/cjs/types/validators/utils.d.ts +2 -2
- package/dist/cjs/types/validators/utils.d.ts.map +1 -1
- package/dist/esm/src/adapter/fields/array.js +2 -2
- package/dist/esm/src/adapter/fields/boolean.js +2 -2
- package/dist/esm/src/adapter/fields/datetime.js +2 -2
- package/dist/esm/src/adapter/fields/index.js +1 -1
- package/dist/esm/src/adapter/fields/number.js +2 -2
- package/dist/esm/src/adapter/fields/object.js +2 -2
- package/dist/esm/src/adapter/fields/string.js +2 -2
- package/dist/esm/src/adapter/fields/union.js +2 -2
- package/dist/esm/src/adapter/index.js +1 -1
- package/dist/esm/src/compile.js +1 -1
- package/dist/esm/src/domain.js +1 -2
- package/dist/esm/src/index.js +21 -20
- package/dist/esm/src/middleware.js +1 -1
- package/dist/esm/src/model.js +3 -3
- package/dist/esm/src/parsers/convert-from-number.js +1 -1
- package/dist/esm/src/parsers/convert-from-string.js +1 -1
- package/dist/esm/src/parsers/index.js +2 -2
- package/dist/esm/src/schema/array.js +3 -3
- package/dist/esm/src/schema/boolean.js +3 -3
- package/dist/esm/src/schema/datetime.js +2 -2
- package/dist/esm/src/schema/index.js +1 -1
- package/dist/esm/src/schema/number.js +2 -2
- package/dist/esm/src/schema/object.js +3 -3
- package/dist/esm/src/schema/schema.js +1 -1
- package/dist/esm/src/schema/string.js +2 -2
- package/dist/esm/src/schema/union.js +3 -3
- package/dist/esm/src/utils.js +3 -3
- package/dist/esm/src/validators/utils.js +1 -1
- package/package.json +5 -5
- package/src/adapter/fields/array.ts +4 -4
- package/src/adapter/fields/boolean.ts +4 -4
- package/src/adapter/fields/datetime.ts +4 -4
- package/src/adapter/fields/index.ts +3 -3
- package/src/adapter/fields/number.ts +4 -4
- package/src/adapter/fields/object.ts +4 -4
- package/src/adapter/fields/string.ts +4 -4
- package/src/adapter/fields/union.ts +4 -4
- package/src/adapter/index.ts +9 -9
- package/src/adapter/types.ts +1 -1
- package/src/compile.ts +2 -2
- package/src/conf.ts +1 -1
- package/src/domain.ts +1 -3
- package/src/index.ts +21 -20
- package/src/middleware.ts +2 -2
- package/src/model.ts +3 -3
- package/src/parsers/convert-from-number.ts +2 -2
- package/src/parsers/convert-from-string.ts +3 -3
- package/src/parsers/index.ts +2 -2
- package/src/schema/array.ts +3 -3
- package/src/schema/boolean.ts +3 -3
- package/src/schema/datetime.ts +2 -2
- package/src/schema/index.ts +1 -1
- package/src/schema/number.ts +2 -2
- package/src/schema/object.ts +4 -4
- package/src/schema/schema.ts +4 -4
- package/src/schema/string.ts +2 -2
- package/src/schema/types.ts +7 -7
- package/src/schema/union.ts +4 -4
- package/src/types.ts +2 -2
- package/src/utils.ts +5 -5
- package/src/validators/array.ts +2 -2
- package/src/validators/boolean.ts +1 -1
- package/src/validators/datetime.ts +2 -2
- package/src/validators/number.ts +2 -2
- package/src/validators/object.ts +1 -1
- package/src/validators/schema.ts +4 -4
- package/src/validators/string.ts +2 -2
- package/src/validators/union.ts +1 -1
- package/src/validators/utils.ts +2 -2
- package/__tests__/node_modules/.bin/node-gyp +0 -17
package/dist/esm/src/index.js
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
import SchemaAdapter from './adapter';
|
2
|
-
import SchemaDomain from './domain';
|
1
|
+
import { SchemaAdapter } from './adapter';
|
2
|
+
import { schemasDomain as SchemaDomain } from './domain';
|
3
3
|
import { modelSchema } from './model';
|
4
|
-
import ArraySchema,
|
5
|
-
import BooleanSchema,
|
6
|
-
import DatetimeSchema,
|
7
|
-
import NumberSchema,
|
8
|
-
import ObjectSchema,
|
9
|
-
import Schema,
|
10
|
-
import StringSchema,
|
11
|
-
import UnionSchema,
|
12
|
-
export {
|
13
|
-
export {
|
14
|
-
export {
|
15
|
-
export {
|
16
|
-
export {
|
17
|
-
export {
|
18
|
-
export {
|
19
|
-
export {
|
4
|
+
import { ArraySchema, array } from './schema/array';
|
5
|
+
import { BooleanSchema, boolean } from './schema/boolean';
|
6
|
+
import { DatetimeSchema, datetime } from './schema/datetime';
|
7
|
+
import { NumberSchema, number } from './schema/number';
|
8
|
+
import { ObjectSchema, object } from './schema/object';
|
9
|
+
import { Schema, schema } from './schema/schema';
|
10
|
+
import { StringSchema, string } from './schema/string';
|
11
|
+
import { UnionSchema, union } from './schema/union';
|
12
|
+
export { FieldAdapter, fieldAdapter } from './adapter/fields';
|
13
|
+
export { NumberFieldAdapter, numberFieldAdapter } from './adapter/fields/number';
|
14
|
+
export { ObjectFieldAdapter, objectFieldAdapter } from './adapter/fields/object';
|
15
|
+
export { UnionFieldAdapter, unionFieldAdapter } from './adapter/fields/union';
|
16
|
+
export { StringFieldAdapter, stringFieldAdapter } from './adapter/fields/string';
|
17
|
+
export { ArrayFieldAdapter, arrayFieldAdapter } from './adapter/fields/array';
|
18
|
+
export { BooleanFieldAdapter, booleanFieldAdapter } from './adapter/fields/boolean';
|
19
|
+
export { DatetimeFieldAdapter, datetimeFieldAdapter } from './adapter/fields/datetime';
|
20
20
|
export { setDefaultAdapter, getDefaultAdapter } from './conf';
|
21
21
|
export * from './adapter/types';
|
22
22
|
export * from './schema';
|
23
23
|
export { SchemaAdapter, NumberSchema, ObjectSchema, UnionSchema, StringSchema, ArraySchema, BooleanSchema, DatetimeSchema, Schema };
|
24
24
|
export { schema, number, object, union, string, array, datetime, boolean };
|
25
|
-
export {
|
26
|
-
export {
|
25
|
+
export { compile } from './compile';
|
26
|
+
export { schemaHandler } from './middleware';
|
27
27
|
export { modelSchema };
|
28
|
+
export { SchemaDomain };
|
28
29
|
export default SchemaDomain;
|
29
30
|
export function getSchemasWithDefaultAdapter() {
|
30
31
|
return {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Response } from '@palmares/server';
|
2
2
|
/**
|
3
3
|
* Validates the request body and returns a response automatically, don't need to do anything else.
|
4
|
-
*/ export
|
4
|
+
*/ export function schemaHandler(input, output) {
|
5
5
|
return async (request)=>{
|
6
6
|
const data = await request.json();
|
7
7
|
const validatedData = await input.validate(data, {
|
package/dist/esm/src/model.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { AutoField, BigAutoField, BooleanField, CharField, DateField, DecimalField, EnumField, ForeignKeyField, IntegerField, TextField, TranslatableField, UuidField } from '@palmares/databases';
|
2
2
|
import { TranslatableFieldNotImplementedError } from './exceptions';
|
3
3
|
import { number } from './schema';
|
4
|
-
import ArraySchema from './schema/array';
|
4
|
+
import { ArraySchema } from './schema/array';
|
5
5
|
import { boolean } from './schema/boolean';
|
6
6
|
import { datetime } from './schema/datetime';
|
7
|
-
import ObjectSchema from './schema/object';
|
8
|
-
import Schema from './schema/schema';
|
7
|
+
import { ObjectSchema } from './schema/object';
|
8
|
+
import { Schema } from './schema/schema';
|
9
9
|
import { string } from './schema/string';
|
10
10
|
import { union } from './schema/union';
|
11
11
|
async function getSchemaFromModelField(model, field, parent, definedFields, engineInstanceName, options) {
|
@@ -1,2 +1,2 @@
|
|
1
|
-
export {
|
2
|
-
export {
|
1
|
+
export { convertFromNumberBuilder } from './convert-from-number';
|
2
|
+
export { convertFromStringBuilder } from './convert-from-string';
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { defaultTransform, defaultTransformToAdapter, shouldRunDataOnComplexSchemas, transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas } from '../utils';
|
3
3
|
import { arrayValidation, maxLength, minLength, nonEmpty } from '../validators/array';
|
4
4
|
import { nullable, optional } from '../validators/schema';
|
5
|
-
import Validator from '../validators/utils';
|
6
|
-
export
|
5
|
+
import { Validator } from '../validators/utils';
|
6
|
+
export class ArraySchema extends Schema {
|
7
7
|
fieldType = 'array';
|
8
8
|
__schemas;
|
9
9
|
__type = {
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import Schema from './schema';
|
2
|
-
import convertFromStringBuilder from '../parsers/convert-from-string';
|
1
|
+
import { Schema } from './schema';
|
2
|
+
import { convertFromStringBuilder } from '../parsers/convert-from-string';
|
3
3
|
import { defaultTransform, defaultTransformToAdapter } from '../utils';
|
4
4
|
import { booleanValidation } from '../validators/boolean';
|
5
5
|
import { is, nullable, optional } from '../validators/schema';
|
6
|
-
export
|
6
|
+
export class BooleanSchema extends Schema {
|
7
7
|
fieldType = 'boolean';
|
8
8
|
__allowString;
|
9
9
|
__allowNumber;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { defaultTransform, defaultTransformToAdapter } from '../utils';
|
3
3
|
import { above, allowStringParser, below, datetimeValidation } from '../validators/datetime';
|
4
4
|
import { nullable, optional } from '../validators/schema';
|
5
|
-
export
|
5
|
+
export class DatetimeSchema extends Schema {
|
6
6
|
fieldType = 'datetime';
|
7
7
|
__allowString;
|
8
8
|
__above;
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { DEFAULT_NUMBER_INTEGER_EXCEPTION, DEFAULT_NUMBER_MAX_EXCEPTION, DEFAULT_NUMBER_MIN_EXCEPTION } from '../constants';
|
3
3
|
import { convertFromStringBuilder } from '../parsers';
|
4
4
|
import { defaultTransform, defaultTransformToAdapter } from '../utils';
|
5
5
|
import { decimalPlaces, integer, max, maxDigits, min, numberValidation } from '../validators/number';
|
6
6
|
import { is, nullable, optional } from '../validators/schema';
|
7
|
-
export
|
7
|
+
export class NumberSchema extends Schema {
|
8
8
|
fieldType = 'number';
|
9
9
|
__allowString;
|
10
10
|
__is;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { defaultTransform, defaultTransformToAdapter, shouldRunDataOnComplexSchemas, transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas } from '../utils';
|
3
3
|
import { objectValidation } from '../validators/object';
|
4
|
-
import Validator from '../validators/utils';
|
5
|
-
export
|
4
|
+
import { Validator } from '../validators/utils';
|
5
|
+
export class ObjectSchema extends Schema {
|
6
6
|
fieldType = 'object';
|
7
7
|
__data;
|
8
8
|
__cachedDataAsEntries;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { getDefaultAdapter } from '../conf';
|
2
2
|
import { formatErrorFromParseMethod } from '../utils';
|
3
|
-
export
|
3
|
+
export class Schema {
|
4
4
|
fieldType = 'schema';
|
5
5
|
// Those functions will assume control of the validation process on adapters, instead of the schema.
|
6
6
|
// Why this is used? The idea is that the Schema has NO idea
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { defaultTransform, defaultTransformToAdapter } from '../utils';
|
3
3
|
import { is, nullable, optional } from '../validators/schema';
|
4
4
|
import { email, endsWith, includes, maxLength, minLength, regex, startsWith, stringValidation, uuid } from '../validators/string';
|
5
|
-
export
|
5
|
+
export class StringSchema extends Schema {
|
6
6
|
fieldType = 'string';
|
7
7
|
__is;
|
8
8
|
__email;
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import Schema from './schema';
|
1
|
+
import { Schema } from './schema';
|
2
2
|
import { defaultTransform, defaultTransformToAdapter, transformSchemaAndCheckIfShouldBeHandledByFallbackOnComplexSchemas } from '../utils';
|
3
3
|
import { unionValidation } from '../validators/union';
|
4
|
-
import Validator from '../validators/utils';
|
5
|
-
export
|
4
|
+
import { Validator } from '../validators/utils';
|
5
|
+
export class UnionSchema extends Schema {
|
6
6
|
fieldType = 'union';
|
7
7
|
__type = {
|
8
8
|
message: 'Invalid type',
|
package/dist/esm/src/utils.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
import SchemaAdapter from './adapter';
|
1
|
+
import { SchemaAdapter } from './adapter';
|
2
2
|
import { getDefaultAdapter } from './conf';
|
3
3
|
import { checkType, nullable, optional } from './validators/schema';
|
4
|
-
import Validator from './validators/utils';
|
4
|
+
import { Validator } from './validators/utils';
|
5
5
|
/**
|
6
6
|
* The usage of this is that imagine that the library doesn't support a specific feature that we support on
|
7
7
|
* our schema definition, it can return an instance of this class and with this instance we are able to
|
8
8
|
* fallback to our default implementation of the schema validation.
|
9
|
-
*/ export
|
9
|
+
*/ export class WithFallback {
|
10
10
|
fallbackFor;
|
11
11
|
transformedSchema;
|
12
12
|
adapterType;
|
@@ -27,7 +27,7 @@ const typeByPriority = Object.entries(priorityByType).reduce((acc, [key, value])
|
|
27
27
|
*
|
28
28
|
* That's what this solve, it's a better approach than repeating the same code 3 times on the schema. It's also
|
29
29
|
* more powerful, because if we need to add any extra priorities we can do that easily without changing the schema.
|
30
|
-
*/ export
|
30
|
+
*/ export class Validator {
|
31
31
|
child;
|
32
32
|
parent;
|
33
33
|
fallbackNamesAdded = new Set();
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@palmares/schemas",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.20",
|
4
4
|
"description": "This defines a default schema definition for validation of data, it abstract popular schema validation libraries like zod, yup, valibot and others\"",
|
5
5
|
"main": "./dist/cjs/src/index.js",
|
6
6
|
"module": "./dist/esm/src/index.js",
|
@@ -34,10 +34,10 @@
|
|
34
34
|
"url": "https://github.com/palmaresHQ/palmares/issues"
|
35
35
|
},
|
36
36
|
"homepage": "https://github.com/palmaresHQ/palmares#readme",
|
37
|
-
"
|
38
|
-
"@palmares/core": "0.1.
|
39
|
-
"@palmares/databases": "0.1.
|
40
|
-
"@palmares/server": "0.1.
|
37
|
+
"peerDependencies": {
|
38
|
+
"@palmares/core": "0.1.13",
|
39
|
+
"@palmares/databases": "0.1.16",
|
40
|
+
"@palmares/server": "0.1.13"
|
41
41
|
},
|
42
42
|
"scripts": {
|
43
43
|
"clear": "rimraf ./dist",
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
|
3
|
-
import type WithFallback from '../../utils';
|
4
|
-
import type { ArrayAdapterTranslateArgs
|
3
|
+
import type { WithFallback } from '../../utils';
|
4
|
+
import type { ArrayAdapterTranslateArgs } from '../types';
|
5
5
|
|
6
6
|
export function arrayFieldAdapter<
|
7
7
|
TTranslate extends ArrayFieldAdapter['translate'],
|
@@ -26,6 +26,6 @@ export function arrayFieldAdapter<
|
|
26
26
|
};
|
27
27
|
}
|
28
28
|
|
29
|
-
export
|
29
|
+
export class ArrayFieldAdapter extends FieldAdapter {
|
30
30
|
translate(_fieldAdapter: FieldAdapter, _args: ArrayAdapterTranslateArgs): any | WithFallback<'array'> {}
|
31
31
|
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { BooleanAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function booleanFieldAdapter<
|
@@ -28,7 +28,7 @@ export function booleanFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class BooleanFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: BooleanAdapterTranslateArgs): any | WithFallback<'boolean'> {}
|
33
33
|
|
34
34
|
parse(
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { DatetimeAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function datetimeFieldAdapter<
|
@@ -28,7 +28,7 @@ export function datetimeFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class DatetimeFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: DatetimeAdapterTranslateArgs): any | WithFallback<'datetime'> {}
|
33
33
|
|
34
34
|
parse(
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
2
2
|
|
3
3
|
import type { SupportedSchemas } from '../../types';
|
4
|
-
import type WithFallback from '../../utils';
|
5
|
-
import type SchemaAdapter from '../index';
|
4
|
+
import type { WithFallback } from '../../utils';
|
5
|
+
import type { SchemaAdapter } from '../index';
|
6
6
|
import type { AdapterToStringArgs, AdapterTranslateArgs, ErrorCodes } from '../types';
|
7
7
|
|
8
8
|
export function fieldAdapter<
|
@@ -27,7 +27,7 @@ export function fieldAdapter<
|
|
27
27
|
};
|
28
28
|
};
|
29
29
|
}
|
30
|
-
export
|
30
|
+
export class FieldAdapter {
|
31
31
|
translate(
|
32
32
|
_fieldAdapter: FieldAdapter,
|
33
33
|
_args: AdapterTranslateArgs<SupportedSchemas>,
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { NumberAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function numberFieldAdapter<
|
@@ -28,7 +28,7 @@ export function numberFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class NumberFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: NumberAdapterTranslateArgs): any | WithFallback<'number'> {}
|
33
33
|
|
34
34
|
parse(
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { ObjectAdapterToStringArgs, ObjectAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function objectFieldAdapter<
|
@@ -28,7 +28,7 @@ export function objectFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class ObjectFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: ObjectAdapterTranslateArgs): any | WithFallback<'object'> {}
|
33
33
|
|
34
34
|
parse(
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { StringAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function stringFieldAdapter<
|
@@ -28,7 +28,7 @@ export function stringFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class StringFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: StringAdapterTranslateArgs): any | WithFallback<'string'> {}
|
33
33
|
|
34
34
|
parse(
|
@@ -1,8 +1,8 @@
|
|
1
|
-
import FieldAdapter from '.';
|
1
|
+
import { FieldAdapter } from '.';
|
2
2
|
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
3
|
|
4
|
-
import type SchemaAdapter from '..';
|
5
|
-
import type WithFallback from '../../utils';
|
4
|
+
import type { SchemaAdapter } from '..';
|
5
|
+
import type { WithFallback } from '../../utils';
|
6
6
|
import type { UnionAdapterTranslateArgs } from '../types';
|
7
7
|
|
8
8
|
export function unionFieldAdapter<
|
@@ -28,7 +28,7 @@ export function unionFieldAdapter<
|
|
28
28
|
};
|
29
29
|
}
|
30
30
|
|
31
|
-
export
|
31
|
+
export class UnionFieldAdapter extends FieldAdapter {
|
32
32
|
translate(_fieldAdapter: FieldAdapter, _args: UnionAdapterTranslateArgs): any | WithFallback<'union'> {}
|
33
33
|
|
34
34
|
parse(
|
package/src/adapter/index.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
import { SchemaAdapterNotImplementedError } from '../exceptions';
|
2
2
|
|
3
|
-
import type FieldAdapter from './fields';
|
4
|
-
import type ArrayFieldAdapter from './fields/array';
|
5
|
-
import type BooleanFieldAdapter from './fields/boolean';
|
6
|
-
import type DatetimeFieldAdapter from './fields/datetime';
|
7
|
-
import type NumberFieldAdapter from './fields/number';
|
8
|
-
import type ObjectFieldAdapter from './fields/object';
|
9
|
-
import type StringFieldAdapter from './fields/string';
|
10
|
-
import type UnionFieldAdapter from './fields/union';
|
3
|
+
import type { FieldAdapter } from './fields';
|
4
|
+
import type { ArrayFieldAdapter } from './fields/array';
|
5
|
+
import type { BooleanFieldAdapter } from './fields/boolean';
|
6
|
+
import type { DatetimeFieldAdapter } from './fields/datetime';
|
7
|
+
import type { NumberFieldAdapter } from './fields/number';
|
8
|
+
import type { ObjectFieldAdapter } from './fields/object';
|
9
|
+
import type { StringFieldAdapter } from './fields/string';
|
10
|
+
import type { UnionFieldAdapter } from './fields/union';
|
11
11
|
import type { ErrorCodes } from './types';
|
12
12
|
|
13
|
-
export
|
13
|
+
export class SchemaAdapter {
|
14
14
|
field!: FieldAdapter;
|
15
15
|
number?: NumberFieldAdapter;
|
16
16
|
object!: ObjectFieldAdapter;
|
package/src/adapter/types.ts
CHANGED
package/src/compile.ts
CHANGED
@@ -2,9 +2,9 @@ import { getDefaultStd } from '@palmares/core';
|
|
2
2
|
|
3
3
|
import { getDefaultAdapter } from './conf';
|
4
4
|
|
5
|
-
import type Schema from './schema/schema';
|
5
|
+
import type { Schema } from './schema/schema';
|
6
6
|
|
7
|
-
export
|
7
|
+
export async function compile(schemas: Record<string, Schema<any, any>>) {
|
8
8
|
const schemasAsEntries = Object.entries(schemas);
|
9
9
|
const adapter = getDefaultAdapter();
|
10
10
|
const std = getDefaultStd();
|
package/src/conf.ts
CHANGED
package/src/domain.ts
CHANGED
@@ -4,7 +4,7 @@ import { getDefaultAdapter, setDefaultAdapter } from './conf';
|
|
4
4
|
|
5
5
|
import type { SchemasSettingsType } from './types';
|
6
6
|
|
7
|
-
const schemasDomain = domain('@palmares/schemas', '', {
|
7
|
+
export const schemasDomain = domain('@palmares/schemas', '', {
|
8
8
|
commands: {},
|
9
9
|
// eslint-disable-next-line ts/require-await
|
10
10
|
load: async (settings: SchemasSettingsType) => {
|
@@ -13,5 +13,3 @@ const schemasDomain = domain('@palmares/schemas', '', {
|
|
13
13
|
return undefined;
|
14
14
|
}
|
15
15
|
});
|
16
|
-
|
17
|
-
export default schemasDomain;
|
package/src/index.ts
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
import SchemaAdapter from './adapter';
|
2
|
-
import SchemaDomain from './domain';
|
1
|
+
import { SchemaAdapter } from './adapter';
|
2
|
+
import { schemasDomain as SchemaDomain } from './domain';
|
3
3
|
import { modelSchema } from './model';
|
4
|
-
import ArraySchema,
|
5
|
-
import BooleanSchema,
|
6
|
-
import DatetimeSchema,
|
7
|
-
import NumberSchema,
|
8
|
-
import ObjectSchema,
|
9
|
-
import Schema,
|
10
|
-
import StringSchema,
|
11
|
-
import UnionSchema,
|
4
|
+
import { ArraySchema, array } from './schema/array';
|
5
|
+
import { BooleanSchema, boolean } from './schema/boolean';
|
6
|
+
import { DatetimeSchema, datetime } from './schema/datetime';
|
7
|
+
import { NumberSchema, number } from './schema/number';
|
8
|
+
import { ObjectSchema, object } from './schema/object';
|
9
|
+
import { Schema, schema } from './schema/schema';
|
10
|
+
import { StringSchema, string } from './schema/string';
|
11
|
+
import { UnionSchema, union } from './schema/union';
|
12
12
|
|
13
13
|
import type { DefinitionsOfSchemaType, ExtractTypeFromObjectOfSchemas } from './schema/types';
|
14
14
|
import type { Narrow } from '@palmares/core';
|
15
15
|
import type { Model, ModelFields } from '@palmares/databases';
|
16
16
|
|
17
|
-
export {
|
18
|
-
export {
|
19
|
-
export {
|
20
|
-
export {
|
21
|
-
export {
|
22
|
-
export {
|
23
|
-
export {
|
24
|
-
export {
|
17
|
+
export { FieldAdapter, fieldAdapter } from './adapter/fields';
|
18
|
+
export { NumberFieldAdapter, numberFieldAdapter } from './adapter/fields/number';
|
19
|
+
export { ObjectFieldAdapter, objectFieldAdapter } from './adapter/fields/object';
|
20
|
+
export { UnionFieldAdapter, unionFieldAdapter } from './adapter/fields/union';
|
21
|
+
export { StringFieldAdapter, stringFieldAdapter } from './adapter/fields/string';
|
22
|
+
export { ArrayFieldAdapter, arrayFieldAdapter } from './adapter/fields/array';
|
23
|
+
export { BooleanFieldAdapter, booleanFieldAdapter } from './adapter/fields/boolean';
|
24
|
+
export { DatetimeFieldAdapter, datetimeFieldAdapter } from './adapter/fields/datetime';
|
25
25
|
|
26
26
|
export type { Infer as infer } from './types';
|
27
27
|
export { setDefaultAdapter, getDefaultAdapter } from './conf';
|
@@ -39,10 +39,11 @@ export {
|
|
39
39
|
Schema
|
40
40
|
};
|
41
41
|
export { schema, number, object, union, string, array, datetime, boolean };
|
42
|
-
export {
|
43
|
-
export {
|
42
|
+
export { compile } from './compile';
|
43
|
+
export { schemaHandler } from './middleware';
|
44
44
|
|
45
45
|
export { modelSchema };
|
46
|
+
export { SchemaDomain };
|
46
47
|
|
47
48
|
export default SchemaDomain;
|
48
49
|
|
package/src/middleware.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import { Response } from '@palmares/server';
|
2
2
|
|
3
|
-
import type Schema from './schema/schema';
|
3
|
+
import type { Schema } from './schema/schema';
|
4
4
|
import type { Infer } from './types';
|
5
5
|
import type { Request } from '@palmares/server';
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Validates the request body and returns a response automatically, don't need to do anything else.
|
9
9
|
*/
|
10
|
-
export
|
10
|
+
export function schemaHandler<
|
11
11
|
TInput extends Schema<any, any>,
|
12
12
|
TOutput extends Schema<
|
13
13
|
{ input: Infer<TInput, 'output'>; internal: any; output: any; representation: any; validate: any },
|
package/src/model.ts
CHANGED
@@ -19,11 +19,11 @@ import {
|
|
19
19
|
|
20
20
|
import { TranslatableFieldNotImplementedError } from './exceptions';
|
21
21
|
import { number } from './schema';
|
22
|
-
import ArraySchema from './schema/array';
|
22
|
+
import { ArraySchema } from './schema/array';
|
23
23
|
import { boolean } from './schema/boolean';
|
24
24
|
import { datetime } from './schema/datetime';
|
25
|
-
import ObjectSchema from './schema/object';
|
26
|
-
import Schema from './schema/schema';
|
25
|
+
import { ObjectSchema } from './schema/object';
|
26
|
+
import { Schema } from './schema/schema';
|
27
27
|
import { string } from './schema/string';
|
28
28
|
import { union } from './schema/union';
|
29
29
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import type Schema from '../schema/schema';
|
1
|
+
import type { Schema } from '../schema/schema';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* This will convert a value from a number to any other type.
|
@@ -6,7 +6,7 @@ import type Schema from '../schema/schema';
|
|
6
6
|
* @param callback
|
7
7
|
* @returns
|
8
8
|
*/
|
9
|
-
export
|
9
|
+
export function convertFromNumberBuilder(
|
10
10
|
callback: (value: number) => Awaited<ReturnType<Parameters<Schema['__parsers']['high']['set']>[1]>>
|
11
11
|
) {
|
12
12
|
return (value: any) => callback(value);
|