@palmares/schemas 0.1.21 → 0.1.22
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/CHANGELOG.md +9 -0
- package/package.json +10 -4
- package/.turbo/turbo-build$colon$watch.log +0 -24
- package/.turbo/turbo-build.log +0 -13
- package/.turbo/turbo-build:watch.log +0 -26
- package/__tests__/.drizzle/migrations/0000_skinny_harrier.sql +0 -22
- package/__tests__/.drizzle/migrations/meta/0000_snapshot.json +0 -156
- package/__tests__/.drizzle/migrations/meta/_journal.json +0 -13
- package/__tests__/.drizzle/schema.ts +0 -35
- package/__tests__/drizzle.config.ts +0 -11
- package/__tests__/eslint.config.js +0 -10
- package/__tests__/manage.ts +0 -5
- package/__tests__/node_modules/.bin/drizzle-kit +0 -17
- package/__tests__/node_modules/.bin/node-gyp +0 -17
- package/__tests__/node_modules/.bin/tsc +0 -17
- package/__tests__/node_modules/.bin/tsserver +0 -17
- package/__tests__/node_modules/.bin/tsx +0 -17
- package/__tests__/package.json +0 -34
- package/__tests__/sqlite.db +0 -0
- package/__tests__/src/core/array.test.ts +0 -131
- package/__tests__/src/core/boolean.test.ts +0 -66
- package/__tests__/src/core/datetime.test.ts +0 -102
- package/__tests__/src/core/index.ts +0 -35
- package/__tests__/src/core/model.test.ts +0 -260
- package/__tests__/src/core/models.ts +0 -50
- package/__tests__/src/core/numbers.test.ts +0 -177
- package/__tests__/src/core/object.test.ts +0 -218
- package/__tests__/src/core/string.test.ts +0 -222
- package/__tests__/src/core/test.test.ts +0 -59
- package/__tests__/src/core/types.test.ts +0 -97
- package/__tests__/src/core/union.test.ts +0 -99
- package/__tests__/src/settings.ts +0 -69
- package/__tests__/tsconfig.json +0 -11
- package/src/adapter/fields/array.ts +0 -31
- package/src/adapter/fields/boolean.ts +0 -43
- package/src/adapter/fields/datetime.ts +0 -43
- package/src/adapter/fields/index.ts +0 -72
- package/src/adapter/fields/number.ts +0 -43
- package/src/adapter/fields/object.ts +0 -52
- package/src/adapter/fields/string.ts +0 -43
- package/src/adapter/fields/union.ts +0 -43
- package/src/adapter/index.ts +0 -37
- package/src/adapter/types.ts +0 -276
- package/src/compile.ts +0 -14
- package/src/conf.ts +0 -30
- package/src/constants.ts +0 -7
- package/src/domain.ts +0 -15
- package/src/exceptions.ts +0 -17
- package/src/index.ts +0 -318
- package/src/middleware.ts +0 -52
- package/src/model.ts +0 -518
- package/src/parsers/convert-from-number.ts +0 -13
- package/src/parsers/convert-from-string.ts +0 -19
- package/src/parsers/index.ts +0 -2
- package/src/schema/array.ts +0 -825
- package/src/schema/boolean.ts +0 -792
- package/src/schema/datetime.ts +0 -704
- package/src/schema/index.ts +0 -5
- package/src/schema/number.ts +0 -929
- package/src/schema/object.ts +0 -799
- package/src/schema/schema.ts +0 -1179
- package/src/schema/string.ts +0 -941
- package/src/schema/types.ts +0 -154
- package/src/schema/union.ts +0 -724
- package/src/types.ts +0 -66
- package/src/utils.ts +0 -389
- package/src/validators/array.ts +0 -183
- package/src/validators/boolean.ts +0 -52
- package/src/validators/datetime.ts +0 -121
- package/src/validators/number.ts +0 -178
- package/src/validators/object.ts +0 -56
- package/src/validators/schema.ts +0 -142
- package/src/validators/string.ts +0 -278
- package/src/validators/types.ts +0 -1
- package/src/validators/union.ts +0 -52
- package/src/validators/utils.ts +0 -226
- package/tsconfig.json +0 -9
- package/tsconfig.types.json +0 -10
@@ -1,69 +0,0 @@
|
|
1
|
-
import ConsoleLogging from '@palmares/console-logging';
|
2
|
-
import CoreDomain, { defineSettings } from '@palmares/core';
|
3
|
-
import DatabasesDomain from '@palmares/databases';
|
4
|
-
import DrizzleEngine from '@palmares/drizzle-engine';
|
5
|
-
import { drizzle as drizzleBetterSqlite3 } from '@palmares/drizzle-engine/better-sqlite3';
|
6
|
-
import JestTestAdapter from '@palmares/jest-tests';
|
7
|
-
import LoggingDomain from '@palmares/logging';
|
8
|
-
import NodeStd from '@palmares/node-std';
|
9
|
-
import SchemasDomain from '@palmares/schemas';
|
10
|
-
import TestsDomain from '@palmares/tests';
|
11
|
-
import { ZodSchemaAdapter } from '@palmares/zod-schema';
|
12
|
-
import Database from 'better-sqlite3';
|
13
|
-
import { dirname, resolve } from 'path';
|
14
|
-
|
15
|
-
import CustomCoreDomain from './core';
|
16
|
-
//import * as schema from '../.drizzle/schema';
|
17
|
-
|
18
|
-
const database = new Database('sqlite.db');
|
19
|
-
|
20
|
-
const args = DrizzleEngine.new({
|
21
|
-
output: './.drizzle/schema.ts',
|
22
|
-
type: 'better-sqlite3',
|
23
|
-
drizzle: drizzleBetterSqlite3(database)
|
24
|
-
});
|
25
|
-
export const db = args[1].instance.instance;
|
26
|
-
export default defineSettings({
|
27
|
-
basePath: dirname(resolve(__dirname)),
|
28
|
-
settingsLocation: __filename,
|
29
|
-
std: NodeStd,
|
30
|
-
installedDomains: [
|
31
|
-
[
|
32
|
-
LoggingDomain,
|
33
|
-
{
|
34
|
-
logger: ConsoleLogging
|
35
|
-
}
|
36
|
-
],
|
37
|
-
// Domain Core, required for palmares to work
|
38
|
-
[
|
39
|
-
CoreDomain,
|
40
|
-
{
|
41
|
-
appName: 'example'
|
42
|
-
}
|
43
|
-
],
|
44
|
-
[
|
45
|
-
TestsDomain,
|
46
|
-
{
|
47
|
-
testAdapter: JestTestAdapter
|
48
|
-
}
|
49
|
-
],
|
50
|
-
[
|
51
|
-
SchemasDomain,
|
52
|
-
{
|
53
|
-
schemaAdapter: ZodSchemaAdapter
|
54
|
-
}
|
55
|
-
],
|
56
|
-
[
|
57
|
-
DatabasesDomain,
|
58
|
-
{
|
59
|
-
databases: {
|
60
|
-
default: {
|
61
|
-
engine: args
|
62
|
-
}
|
63
|
-
}
|
64
|
-
}
|
65
|
-
],
|
66
|
-
// We have just created this custom domain, and it defines our routes.
|
67
|
-
CustomCoreDomain
|
68
|
-
]
|
69
|
-
});
|
package/__tests__/tsconfig.json
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"extends": "../../../tsconfig.json",
|
3
|
-
"compilerOptions": {
|
4
|
-
"declaration": true,
|
5
|
-
"module": "ESNext",
|
6
|
-
"moduleResolution": "Bundler",
|
7
|
-
"outDir": "./dist",
|
8
|
-
"types": ["node"]
|
9
|
-
},
|
10
|
-
"include": ["./src/**/*", "manage.drizzle.ts", "manage.sequelize.ts", "./src/core/types.test.ts"]
|
11
|
-
}
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
|
3
|
-
import type { WithFallback } from '../../utils';
|
4
|
-
import type { ArrayAdapterTranslateArgs } from '../types';
|
5
|
-
|
6
|
-
export function arrayFieldAdapter<
|
7
|
-
TTranslate extends ArrayFieldAdapter['translate'],
|
8
|
-
TToString extends ArrayFieldAdapter['toString'],
|
9
|
-
TFormatError extends ArrayFieldAdapter['formatError'],
|
10
|
-
TParse extends ArrayFieldAdapter['parse']
|
11
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
12
|
-
class CustomArrayFieldAdapter extends ArrayFieldAdapter {
|
13
|
-
translate = args.translate;
|
14
|
-
toString = args.toString as TToString;
|
15
|
-
formatError = args.formatError as TFormatError;
|
16
|
-
parse = args.parse as TParse;
|
17
|
-
}
|
18
|
-
|
19
|
-
return CustomArrayFieldAdapter as typeof ArrayFieldAdapter & {
|
20
|
-
new (): ArrayFieldAdapter & {
|
21
|
-
translate: TTranslate;
|
22
|
-
toString: TToString;
|
23
|
-
formatError: TFormatError;
|
24
|
-
parse: TParse;
|
25
|
-
};
|
26
|
-
};
|
27
|
-
}
|
28
|
-
|
29
|
-
export class ArrayFieldAdapter extends FieldAdapter {
|
30
|
-
translate(_fieldAdapter: FieldAdapter, _args: ArrayAdapterTranslateArgs): any | WithFallback<'array'> {}
|
31
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { BooleanAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function booleanFieldAdapter<
|
9
|
-
TTranslate extends BooleanFieldAdapter['translate'],
|
10
|
-
TToString extends BooleanFieldAdapter['toString'],
|
11
|
-
TFormatError extends BooleanFieldAdapter['formatError'],
|
12
|
-
TParse extends BooleanFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomBooleanFieldAdapter extends BooleanFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomBooleanFieldAdapter as typeof BooleanFieldAdapter & {
|
22
|
-
new (): BooleanFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class BooleanFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: BooleanAdapterTranslateArgs): any | WithFallback<'boolean'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: BooleanAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { DatetimeAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function datetimeFieldAdapter<
|
9
|
-
TTranslate extends DatetimeFieldAdapter['translate'],
|
10
|
-
TToString extends DatetimeFieldAdapter['toString'],
|
11
|
-
TFormatError extends DatetimeFieldAdapter['formatError'],
|
12
|
-
TParse extends DatetimeFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomDatetimeFieldAdapter extends DatetimeFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomDatetimeFieldAdapter as typeof DatetimeFieldAdapter & {
|
22
|
-
new (): DatetimeFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class DatetimeFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: DatetimeAdapterTranslateArgs): any | WithFallback<'datetime'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: DatetimeAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
}
|
@@ -1,72 +0,0 @@
|
|
1
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
2
|
-
|
3
|
-
import type { SupportedSchemas } from '../../types';
|
4
|
-
import type { WithFallback } from '../../utils';
|
5
|
-
import type { SchemaAdapter } from '../index';
|
6
|
-
import type { AdapterToStringArgs, AdapterTranslateArgs, ErrorCodes } from '../types';
|
7
|
-
|
8
|
-
export function fieldAdapter<
|
9
|
-
TTranslate extends FieldAdapter['translate'],
|
10
|
-
TToString extends FieldAdapter['toString'],
|
11
|
-
TFormatError extends FieldAdapter['formatError'],
|
12
|
-
TParse extends FieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomFieldAdapter extends FieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomFieldAdapter as typeof FieldAdapter & {
|
22
|
-
new (): FieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
export class FieldAdapter {
|
31
|
-
translate(
|
32
|
-
_fieldAdapter: FieldAdapter,
|
33
|
-
_args: AdapterTranslateArgs<SupportedSchemas>,
|
34
|
-
_base?: any
|
35
|
-
): any | WithFallback<SupportedSchemas> {
|
36
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'translate' });
|
37
|
-
}
|
38
|
-
|
39
|
-
parse(
|
40
|
-
_adapter: SchemaAdapter,
|
41
|
-
_fieldAdapter: FieldAdapter,
|
42
|
-
_schema: any,
|
43
|
-
_value: any,
|
44
|
-
_args: Omit<AdapterTranslateArgs<SupportedSchemas>, 'withFallback'>
|
45
|
-
): Promise<{ errors: any; parsed: any }> {
|
46
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
47
|
-
}
|
48
|
-
|
49
|
-
toString(
|
50
|
-
_adapter: SchemaAdapter,
|
51
|
-
_fieldAdapter: FieldAdapter,
|
52
|
-
_args: AdapterToStringArgs,
|
53
|
-
_base?: any
|
54
|
-
): Promise<string> {
|
55
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'toString' });
|
56
|
-
}
|
57
|
-
|
58
|
-
// eslint-disable-next-line ts/require-await
|
59
|
-
async formatError(
|
60
|
-
_adapter: SchemaAdapter,
|
61
|
-
_fieldAdapter: FieldAdapter,
|
62
|
-
_schema: any,
|
63
|
-
_error: any,
|
64
|
-
_metadata?: any
|
65
|
-
): Promise<{
|
66
|
-
message: string;
|
67
|
-
path: (string | number)[];
|
68
|
-
code: ErrorCodes;
|
69
|
-
}> {
|
70
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'formatError' });
|
71
|
-
}
|
72
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { NumberAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function numberFieldAdapter<
|
9
|
-
TTranslate extends NumberFieldAdapter['translate'],
|
10
|
-
TToString extends NumberFieldAdapter['toString'],
|
11
|
-
TFormatError extends NumberFieldAdapter['formatError'],
|
12
|
-
TParse extends NumberFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomNumberFieldAdapter extends NumberFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomNumberFieldAdapter as typeof NumberFieldAdapter & {
|
22
|
-
new (): NumberFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class NumberFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: NumberAdapterTranslateArgs): any | WithFallback<'number'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: NumberAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
}
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { ObjectAdapterToStringArgs, ObjectAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function objectFieldAdapter<
|
9
|
-
TTranslate extends ObjectFieldAdapter['translate'],
|
10
|
-
TToString extends ObjectFieldAdapter['toString'],
|
11
|
-
TFormatError extends ObjectFieldAdapter['formatError'],
|
12
|
-
TParse extends ObjectFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomObjectFieldAdapter extends ObjectFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomObjectFieldAdapter as typeof ObjectFieldAdapter & {
|
22
|
-
new (): ObjectFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class ObjectFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: ObjectAdapterTranslateArgs): any | WithFallback<'object'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: ObjectAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
|
44
|
-
toString(
|
45
|
-
_adapter: SchemaAdapter,
|
46
|
-
_fieldAdapter: FieldAdapter,
|
47
|
-
_args: ObjectAdapterToStringArgs,
|
48
|
-
_base?: any
|
49
|
-
): Promise<string> {
|
50
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'toString' });
|
51
|
-
}
|
52
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { StringAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function stringFieldAdapter<
|
9
|
-
TTranslate extends StringFieldAdapter['translate'],
|
10
|
-
TToString extends StringFieldAdapter['toString'],
|
11
|
-
TFormatError extends StringFieldAdapter['formatError'],
|
12
|
-
TParse extends StringFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomStringFieldAdapter extends StringFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomStringFieldAdapter as typeof StringFieldAdapter & {
|
22
|
-
new (): StringFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class StringFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: StringAdapterTranslateArgs): any | WithFallback<'string'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: StringAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { FieldAdapter } from '.';
|
2
|
-
import { SchemaAdapterNotImplementedError } from '../../exceptions';
|
3
|
-
|
4
|
-
import type { SchemaAdapter } from '..';
|
5
|
-
import type { WithFallback } from '../../utils';
|
6
|
-
import type { UnionAdapterTranslateArgs } from '../types';
|
7
|
-
|
8
|
-
export function unionFieldAdapter<
|
9
|
-
TTranslate extends UnionFieldAdapter['translate'],
|
10
|
-
TToString extends UnionFieldAdapter['toString'],
|
11
|
-
TFormatError extends UnionFieldAdapter['formatError'],
|
12
|
-
TParse extends UnionFieldAdapter['parse']
|
13
|
-
>(args: { translate: TTranslate; toString?: TToString; formatError?: TFormatError; parse?: TParse }) {
|
14
|
-
class CustomUnionFieldAdapter extends UnionFieldAdapter {
|
15
|
-
translate = args.translate;
|
16
|
-
toString = args.toString as TToString;
|
17
|
-
formatError = args.formatError as TFormatError;
|
18
|
-
parse = args.parse as TParse;
|
19
|
-
}
|
20
|
-
|
21
|
-
return CustomUnionFieldAdapter as typeof UnionFieldAdapter & {
|
22
|
-
new (): UnionFieldAdapter & {
|
23
|
-
translate: TTranslate;
|
24
|
-
toString: TToString;
|
25
|
-
formatError: TFormatError;
|
26
|
-
parse: TParse;
|
27
|
-
};
|
28
|
-
};
|
29
|
-
}
|
30
|
-
|
31
|
-
export class UnionFieldAdapter extends FieldAdapter {
|
32
|
-
translate(_fieldAdapter: FieldAdapter, _args: UnionAdapterTranslateArgs): any | WithFallback<'union'> {}
|
33
|
-
|
34
|
-
parse(
|
35
|
-
_adapter: SchemaAdapter,
|
36
|
-
_fieldAdapter: FieldAdapter,
|
37
|
-
_result: any,
|
38
|
-
_value: any,
|
39
|
-
_args: UnionAdapterTranslateArgs
|
40
|
-
): Promise<{ errors: any; parsed: any }> {
|
41
|
-
throw new SchemaAdapterNotImplementedError({ className: this.constructor.name, functionName: 'parse' });
|
42
|
-
}
|
43
|
-
}
|
package/src/adapter/index.ts
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
import { SchemaAdapterNotImplementedError } from '../exceptions';
|
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';
|
11
|
-
import type { ErrorCodes } from './types';
|
12
|
-
|
13
|
-
export class SchemaAdapter {
|
14
|
-
$$type = '$PSchemaAdapter';
|
15
|
-
name!: string;
|
16
|
-
field!: FieldAdapter;
|
17
|
-
number?: NumberFieldAdapter;
|
18
|
-
object!: ObjectFieldAdapter;
|
19
|
-
union?: UnionFieldAdapter;
|
20
|
-
string?: StringFieldAdapter;
|
21
|
-
array?: ArrayFieldAdapter;
|
22
|
-
boolean?: BooleanFieldAdapter;
|
23
|
-
datetime?: DatetimeFieldAdapter;
|
24
|
-
adapterInstance: any;
|
25
|
-
|
26
|
-
// eslint-disable-next-line ts/require-await
|
27
|
-
async formatError(
|
28
|
-
_error: any,
|
29
|
-
_metadata?: any
|
30
|
-
): Promise<{
|
31
|
-
message: string;
|
32
|
-
path: (string | number)[];
|
33
|
-
code: ErrorCodes;
|
34
|
-
}> {
|
35
|
-
throw new SchemaAdapterNotImplementedError({ className: 'SchemaAdapter', functionName: 'formatError' });
|
36
|
-
}
|
37
|
-
}
|