@nmtjs/type 0.15.0-beta.39 → 0.15.0-beta.40
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/types/base.d.ts +3 -1
- package/dist/types/base.js +24 -0
- package/dist/types/base.js.map +1 -1
- package/package.json +4 -3
- package/src/types/base.ts +40 -1
package/dist/types/base.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1
2
|
import type { ZodMiniAny, ZodMiniArray, ZodMiniBoolean, ZodMiniDefault, ZodMiniEnum, ZodMiniIntersection, ZodMiniLiteral, ZodMiniNever, ZodMiniNullable, ZodMiniNumber, ZodMiniObject, ZodMiniOptional, ZodMiniRecord, ZodMiniString, ZodMiniType, ZodMiniUnion } from 'zod/mini';
|
|
2
3
|
import { core } from 'zod/mini';
|
|
3
4
|
export type PrimitiveValueType = string | number | boolean | null;
|
|
@@ -24,7 +25,7 @@ export type BaseTypeAny<EncodedZodType extends SimpleZodType = SimpleZodType, De
|
|
|
24
25
|
export declare const typesRegistry: core.$ZodRegistry<TypeMetadata<any>, core.$ZodType<unknown, unknown, core.$ZodTypeInternals<unknown, unknown>>>;
|
|
25
26
|
export declare const NeemataTypeError: core.$constructor<core.$ZodError<unknown>, core.$ZodIssue[]>;
|
|
26
27
|
export type NeemataTypeError = core.$ZodError;
|
|
27
|
-
export declare abstract class BaseType<EncodeZodType extends SimpleZodType = SimpleZodType, DecodeZodType extends ZodType = EncodeZodType, Props extends TypeProps = TypeProps, RawEncodeZodType extends SimpleZodType = EncodeZodType, RawDecodeZodType extends ZodType = DecodeZodType> {
|
|
28
|
+
export declare abstract class BaseType<EncodeZodType extends SimpleZodType = SimpleZodType, DecodeZodType extends ZodType = EncodeZodType, Props extends TypeProps = TypeProps, RawEncodeZodType extends SimpleZodType = EncodeZodType, RawDecodeZodType extends ZodType = DecodeZodType> implements StandardSchemaV1<DecodeZodType['_zod']['input'], EncodeZodType['_zod']['output']> {
|
|
28
29
|
readonly encodeZodType: EncodeZodType;
|
|
29
30
|
readonly decodeZodType: DecodeZodType;
|
|
30
31
|
readonly encodeRawZodType: RawEncodeZodType;
|
|
@@ -47,6 +48,7 @@ export declare abstract class BaseType<EncodeZodType extends SimpleZodType = Sim
|
|
|
47
48
|
meta(newMetadata: TypeMetadata): this;
|
|
48
49
|
encode(data: this['encodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['encodeZodType']['_zod']['output'];
|
|
49
50
|
decode(data: this['decodeZodType']['_zod']['input'], context?: core.ParseContext<core.$ZodIssue>): this['decodeZodType']['_zod']['output'];
|
|
51
|
+
'~standard': StandardSchemaV1.Props<this['decodeZodType']['_zod']['input'], this['encodeZodType']['_zod']['output']>;
|
|
50
52
|
}
|
|
51
53
|
export declare class OptionalType<Type extends BaseTypeAny = BaseTypeAny> extends BaseType<ZodMiniOptional<Type['encodeZodType']>, ZodMiniOptional<Type['decodeZodType']>, {
|
|
52
54
|
inner: Type;
|
package/dist/types/base.js
CHANGED
|
@@ -51,6 +51,30 @@ export class BaseType {
|
|
|
51
51
|
decode(data, context = {}) {
|
|
52
52
|
return this.decodeZodType.parse(data, { reportInput: true, ...context });
|
|
53
53
|
}
|
|
54
|
+
'~standard' = {
|
|
55
|
+
validate: (input, options) => {
|
|
56
|
+
try {
|
|
57
|
+
const value = this.decode(input, options?.libraryOptions?.context);
|
|
58
|
+
return { value };
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
if (e instanceof core.$ZodError) {
|
|
62
|
+
const issues = e.issues.map((issue) => ({
|
|
63
|
+
message: issue.message,
|
|
64
|
+
path: issue.path.length > 0 ? issue.path : undefined,
|
|
65
|
+
}));
|
|
66
|
+
return { issues };
|
|
67
|
+
}
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
types: {
|
|
72
|
+
input: undefined,
|
|
73
|
+
output: undefined,
|
|
74
|
+
},
|
|
75
|
+
vendor: 'neemata-type',
|
|
76
|
+
version: 1,
|
|
77
|
+
};
|
|
54
78
|
}
|
|
55
79
|
export class OptionalType extends BaseType {
|
|
56
80
|
static factory(type) {
|
package/dist/types/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/types/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/types/base.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAkDvE,MAAM,CAAC,MAAM,aAAa,GAAG,QAAQ,EAAgB,CAAA;AAErD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAA;AAG9C,MAAM,OAAgB,QAAQ;IAYnB,aAAa,CAAe;IAC5B,aAAa,CAAe;IAC5B,gBAAgB,CAAmB;IACnC,gBAAgB,CAAmB;IACnC,KAAK,CAAO;IACZ,MAAM,CAAY;IAE3B,YAAY,EACV,aAAa,EACb,aAAa,GAAG,aAAyC,EACzD,KAAK,GAAG,EAAW,EACnB,MAAM,GAAG,EAAyB,GAMnC,EAAE;QACD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAElC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAAA,CACpD;IAED,QAAQ,GAAuB;QAC7B,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAAA,CAClC;IAED,QAAQ,GAAuB;QAC7B,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IAAA,CAClC;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ACvB,CAAC,CAAA;IAAA,CACH;CACF;AAED,MAAM,OAAO,YAEX,SAAQ,QAIT;IACC,MAAM,CAAC,OAAO,CAA6B,IAAO,EAAE;QAClD,OAAO,IAAI,YAAY,CAAI;YACzB,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;YAC3C,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;YAC3C,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;SACvB,CAAC,CAAA;IAAA,CACH;CACF;AAED,MAAM,OAAO,WAEX,SAAQ,QAIT;IACC,MAAM,CAAC,OAAO,CAA6B,IAAO,EAAE,YAAiB,EAAE;QACrE,OAAO,IAAI,WAAW,CAAI;YACxB,aAAa,EAAE,QAAQ,CACrB,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,YAAY,CAAC,IAAI,YAAY,CACnD;YACD,aAAa,EAAE,QAAQ,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC;YACzD,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE;SACvB,CAAC,CAAA;IAAA,CACH;CACF"}
|
package/package.json
CHANGED
|
@@ -15,24 +15,25 @@
|
|
|
15
15
|
"./temporal-polyfill": "./dist/temporal/polyfill.js"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@standard-schema/spec": "^1.1.0",
|
|
18
19
|
"temporal-spec": "^0.3.0"
|
|
19
20
|
},
|
|
20
21
|
"peerDependencies": {
|
|
21
22
|
"temporal-polyfill": "^0.3.0",
|
|
22
23
|
"zod": "^4.3.5",
|
|
23
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
24
|
+
"@nmtjs/common": "0.15.0-beta.40"
|
|
24
25
|
},
|
|
25
26
|
"devDependencies": {
|
|
26
27
|
"temporal-polyfill": "^0.3.0",
|
|
27
28
|
"zod": "^4.3.5",
|
|
28
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
29
|
+
"@nmtjs/common": "0.15.0-beta.40"
|
|
29
30
|
},
|
|
30
31
|
"peerDependenciesMeta": {
|
|
31
32
|
"temporal-polyfill": {
|
|
32
33
|
"optional": true
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
|
-
"version": "0.15.0-beta.
|
|
36
|
+
"version": "0.15.0-beta.40",
|
|
36
37
|
"scripts": {
|
|
37
38
|
"clean-build": "rm -rf ./dist"
|
|
38
39
|
}
|
package/src/types/base.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec'
|
|
1
2
|
import type {
|
|
2
3
|
ZodMiniAny,
|
|
3
4
|
ZodMiniArray,
|
|
@@ -77,7 +78,12 @@ export abstract class BaseType<
|
|
|
77
78
|
Props extends TypeProps = TypeProps,
|
|
78
79
|
RawEncodeZodType extends SimpleZodType = EncodeZodType,
|
|
79
80
|
RawDecodeZodType extends ZodType = DecodeZodType,
|
|
80
|
-
>
|
|
81
|
+
> implements
|
|
82
|
+
StandardSchemaV1<
|
|
83
|
+
DecodeZodType['_zod']['input'],
|
|
84
|
+
EncodeZodType['_zod']['output']
|
|
85
|
+
>
|
|
86
|
+
{
|
|
81
87
|
readonly encodeZodType: EncodeZodType
|
|
82
88
|
readonly decodeZodType: DecodeZodType
|
|
83
89
|
readonly encodeRawZodType!: RawEncodeZodType
|
|
@@ -155,6 +161,39 @@ export abstract class BaseType<
|
|
|
155
161
|
): this['decodeZodType']['_zod']['output'] {
|
|
156
162
|
return this.decodeZodType.parse(data, { reportInput: true, ...context })
|
|
157
163
|
}
|
|
164
|
+
|
|
165
|
+
'~standard': StandardSchemaV1.Props<
|
|
166
|
+
this['decodeZodType']['_zod']['input'],
|
|
167
|
+
this['encodeZodType']['_zod']['output']
|
|
168
|
+
> = {
|
|
169
|
+
validate: (
|
|
170
|
+
input: unknown,
|
|
171
|
+
options?: StandardSchemaV1.Options | undefined,
|
|
172
|
+
) => {
|
|
173
|
+
try {
|
|
174
|
+
const value = this.decode(
|
|
175
|
+
input,
|
|
176
|
+
(options?.libraryOptions as any)?.context,
|
|
177
|
+
)
|
|
178
|
+
return { value }
|
|
179
|
+
} catch (e) {
|
|
180
|
+
if (e instanceof core.$ZodError) {
|
|
181
|
+
const issues: StandardSchemaV1.Issue[] = e.issues.map((issue) => ({
|
|
182
|
+
message: issue.message,
|
|
183
|
+
path: issue.path.length > 0 ? issue.path : undefined,
|
|
184
|
+
}))
|
|
185
|
+
return { issues }
|
|
186
|
+
}
|
|
187
|
+
throw e
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
types: {
|
|
191
|
+
input: undefined as unknown as this['decodeZodType']['_zod']['input'],
|
|
192
|
+
output: undefined as unknown as this['encodeZodType']['_zod']['output'],
|
|
193
|
+
},
|
|
194
|
+
vendor: 'neemata-type',
|
|
195
|
+
version: 1,
|
|
196
|
+
}
|
|
158
197
|
}
|
|
159
198
|
|
|
160
199
|
export class OptionalType<
|