@konker.dev/neverthrow-r-schema 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Konrad Markus <mail@konker.dev>
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12
+ SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14
+ OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @konker.dev/neverthrow-r-schema
2
+
3
+ Standard Schema adapters for `neverthrow` and `@konker.dev/neverthrow-r`.
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Asynchronous Standard Schema adapters.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ResultAsyncR, ResultR } from '@konker.dev/neverthrow-r/types';
7
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
8
+ import { type Result, ResultAsync } from 'neverthrow';
9
+ import { type SchemaOptions, type SchemaValidationError } from './common.js';
10
+ type AndParseAsync<I, O> = {
11
+ <E>(r: Result<I, E>): ResultAsync<O, E | SchemaValidationError>;
12
+ <E>(r: ResultAsync<I, E>): ResultAsync<O, E | SchemaValidationError>;
13
+ };
14
+ /**
15
+ * Builds an async parser for a Standard Schema.
16
+ *
17
+ * @remarks
18
+ * Accepts sync outcomes, promises, and thenables. Thrown validators and
19
+ * rejected validations are converted into `SchemaValidationError` values.
20
+ */
21
+ export declare const parseAsync: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => (input: I) => ResultAsync<O, SchemaValidationError>;
22
+ /**
23
+ * Parses the success value of a plain neverthrow chain, returning a
24
+ * `ResultAsync`.
25
+ *
26
+ * @remarks
27
+ * Accepts either `Result` or `ResultAsync`, so it can bridge a sync chain into
28
+ * async validation or continue an already-async chain.
29
+ */
30
+ export declare const andParseAsync: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => AndParseAsync<I, O>;
31
+ /**
32
+ * Parses the success value of a `ResultR`, returning a `ResultAsyncR`.
33
+ */
34
+ export declare const andParseAsyncR: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => <R, E>(rr: ResultR<R, I, E>) => ResultAsyncR<R, O, E | SchemaValidationError>;
35
+ /**
36
+ * Parses the success value of a `ResultAsyncR`, preserving the async reader
37
+ * chain.
38
+ */
39
+ export declare const andThenParseAsyncR: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => <R, E>(rr: ResultAsyncR<R, I, E>) => ResultAsyncR<R, O, E | SchemaValidationError>;
40
+ export {};
41
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../src/async.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAY,KAAK,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAE3B,MAAM,aAAa,CAAC;AAErB,KA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YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAEnC,CAAC"}
package/dist/async.js ADDED
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Asynchronous Standard Schema adapters.
3
+ *
4
+ * @module
5
+ */
6
+ import { errAsync, ResultAsync } from 'neverthrow';
7
+ import { EXCEPTION_MESSAGE, fromStandardSchemaResult, isPromiseLike, REJECTION_MESSAGE, schemaValidationError, } from './common.js';
8
+ /**
9
+ * Builds an async parser for a Standard Schema.
10
+ *
11
+ * @remarks
12
+ * Accepts sync outcomes, promises, and thenables. Thrown validators and
13
+ * rejected validations are converted into `SchemaValidationError` values.
14
+ */
15
+ export const parseAsync = (schema, options) => (input) => {
16
+ try {
17
+ const outcome = schema['~standard'].validate(input, options?.validationOptions);
18
+ return ResultAsync.fromPromise(Promise.resolve(outcome), (cause) => schemaValidationError(REJECTION_MESSAGE, [], cause)).andThen((resolvedOutcome) => fromStandardSchemaResult(resolvedOutcome, options));
19
+ }
20
+ catch (cause) {
21
+ return errAsync(schemaValidationError(EXCEPTION_MESSAGE, [], cause));
22
+ }
23
+ };
24
+ /**
25
+ * Parses the success value of a plain neverthrow chain, returning a
26
+ * `ResultAsync`.
27
+ *
28
+ * @remarks
29
+ * Accepts either `Result` or `ResultAsync`, so it can bridge a sync chain into
30
+ * async validation or continue an already-async chain.
31
+ */
32
+ export const andParseAsync = (schema, options) => ((r) => isPromiseLike(r)
33
+ ? r.andThen(parseAsync(schema, options))
34
+ : r.asyncAndThen(parseAsync(schema, options)));
35
+ /**
36
+ * Parses the success value of a `ResultR`, returning a `ResultAsyncR`.
37
+ */
38
+ export const andParseAsyncR = (schema, options) => (rr) => (r) => rr(r).asyncAndThen(parseAsync(schema, options));
39
+ /**
40
+ * Parses the success value of a `ResultAsyncR`, preserving the async reader
41
+ * chain.
42
+ */
43
+ export const andThenParseAsyncR = (schema, options) => (rr) => (r) => rr(r).andThen(parseAsync(schema, options));
44
+ //# sourceMappingURL=async.js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CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAwB,CAAC;AAE9F;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,CAAO,MAA8B,EAAE,OAAuB,EAAE,EAAE,CAClE,CAAO,EAAoB,EAAiD,EAAE,CAC9E,CAAC,CAAC,EAAE,EAAE,CACJ,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAO,MAA8B,EAAE,OAAuB,EAAE,EAAE,CAClE,CAAO,EAAyB,EAAiD,EAAE,CACnF,CAAC,CAAC,EAAE,EAAE,CACJ,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Shared Standard Schema error and conversion helpers.
3
+ *
4
+ * @module
5
+ */
6
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
7
+ import { type Result } from 'neverthrow';
8
+ /** Default message used when Standard Schema returns validation issues. */
9
+ export declare const DEFAULT_VALIDATION_MESSAGE = "Schema validation failed";
10
+ /** Message used when sync parsing receives an async validation result. */
11
+ export declare const ASYNC_SCHEMA_MESSAGE = "Schema validation returned a Promise; use parseAsync";
12
+ /** Message used when a schema validator throws before returning an outcome. */
13
+ export declare const EXCEPTION_MESSAGE = "Schema validation threw";
14
+ /** Message used when an async schema validation rejects. */
15
+ export declare const REJECTION_MESSAGE = "Schema validation rejected";
16
+ /** Tagged error returned by all Standard Schema helpers in this package. */
17
+ export type SchemaValidationError = {
18
+ readonly tag: 'SchemaValidationError';
19
+ readonly message: string;
20
+ readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
21
+ readonly cause?: unknown;
22
+ };
23
+ /**
24
+ * Options shared by all helpers.
25
+ *
26
+ * @remarks
27
+ * `message` customises normal validation failures only. Strict sync-contract
28
+ * failures, thrown validators, and rejected validators keep their fixed
29
+ * diagnostic messages.
30
+ *
31
+ * `validationOptions` is passed through to `schema["~standard"].validate` by
32
+ * helpers that call the validator. It is accepted but unused by
33
+ * {@link fromStandardSchemaResult}.
34
+ */
35
+ export type SchemaOptions = {
36
+ readonly message?: string;
37
+ readonly validationOptions?: StandardSchemaV1.Options;
38
+ };
39
+ /** @internal */
40
+ export declare const schemaValidationError: (message: string, issues: ReadonlyArray<StandardSchemaV1.Issue>, cause?: unknown) => SchemaValidationError;
41
+ /** @internal */
42
+ export declare const isPromiseLike: (value: unknown) => value is PromiseLike<unknown>;
43
+ /**
44
+ * Converts an already-resolved Standard Schema outcome into a neverthrow
45
+ * `Result`.
46
+ */
47
+ export declare const fromStandardSchemaResult: <O>(outcome: StandardSchemaV1.Result<O>, options?: SchemaOptions) => Result<O, SchemaValidationError>;
48
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAElD,2EAA2E;AAC3E,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AAErE,0EAA0E;AAC1E,eAAO,MAAM,oBAAoB,yDAAyD,CAAC;AAE3F,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB,4BAA4B,CAAC;AAE3D,4DAA4D;AAC5D,eAAO,MAAM,iBAAiB,+BAA+B,CAAC;AAE9D,4EAA4E;AAC5E,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,GAAG,EAAE,uBAAuB,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,iBAAiB,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC;CACvD,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,qBAAqB,GAChC,SAAS,MAAM,EACf,QAAQ,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAC7C,QAAQ,OAAO,KACd,qBAKD,CAAC;AAEH,gBAAgB;AAChB,eAAO,MAAM,aAAa,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAAW,CAAC,OAAO,CACyB,CAAC;AAErG;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GAAI,CAAC,EACxC,SAAS,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC,EACnC,UAAU,aAAa,KACtB,MAAM,CAAC,CAAC,EAAE,qBAAqB,CAMjC,CAAC"}
package/dist/common.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Shared Standard Schema error and conversion helpers.
3
+ *
4
+ * @module
5
+ */
6
+ import { err, ok } from 'neverthrow';
7
+ /** Default message used when Standard Schema returns validation issues. */
8
+ export const DEFAULT_VALIDATION_MESSAGE = 'Schema validation failed';
9
+ /** Message used when sync parsing receives an async validation result. */
10
+ export const ASYNC_SCHEMA_MESSAGE = 'Schema validation returned a Promise; use parseAsync';
11
+ /** Message used when a schema validator throws before returning an outcome. */
12
+ export const EXCEPTION_MESSAGE = 'Schema validation threw';
13
+ /** Message used when an async schema validation rejects. */
14
+ export const REJECTION_MESSAGE = 'Schema validation rejected';
15
+ /** @internal */
16
+ export const schemaValidationError = (message, issues, cause) => ({
17
+ tag: 'SchemaValidationError',
18
+ message,
19
+ issues,
20
+ cause,
21
+ });
22
+ /** @internal */
23
+ export const isPromiseLike = (value) => typeof value === 'object' && value !== null && 'then' in value && typeof value.then === 'function';
24
+ /**
25
+ * Converts an already-resolved Standard Schema outcome into a neverthrow
26
+ * `Result`.
27
+ */
28
+ export const fromStandardSchemaResult = (outcome, options) => {
29
+ if (outcome.issues !== undefined) {
30
+ return err(schemaValidationError(options?.message ?? DEFAULT_VALIDATION_MESSAGE, outcome.issues));
31
+ }
32
+ return ok(outcome.value);
33
+ };
34
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,YAAY,CAAC;AAElD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;AAErE,0EAA0E;AAC1E,MAAM,CAAC,MAAM,oBAAoB,GAAG,sDAAsD,CAAC;AAE3F,+EAA+E;AAC/E,MAAM,CAAC,MAAM,iBAAiB,GAAG,yBAAyB,CAAC;AAE3D,4DAA4D;AAC5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AA2B9D,gBAAgB;AAChB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAAe,EACf,MAA6C,EAC7C,KAAe,EACQ,EAAE,CAAC,CAAC;IAC3B,GAAG,EAAE,uBAAuB;IAC5B,OAAO;IACP,MAAM;IACN,KAAK;CACN,CAAC,CAAC;AAEH,gBAAgB;AAChB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAc,EAAiC,EAAE,CAC7E,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC;AAErG;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,OAAmC,EACnC,OAAuB,EACW,EAAE;IACpC,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,GAAG,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IACpG,CAAC;IAED,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './async.js';
2
+ export * from './common.js';
3
+ export * from './sync.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export * from './async.js';
2
+ export * from './common.js';
3
+ export * from './sync.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
package/dist/sync.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Synchronous Standard Schema adapters.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ResultR } from '@konker.dev/neverthrow-r/types';
7
+ import type { StandardSchemaV1 } from '@standard-schema/spec';
8
+ import { type Result } from 'neverthrow';
9
+ import { type SchemaOptions, type SchemaValidationError } from './common.js';
10
+ /**
11
+ * Builds a sync parser for a Standard Schema.
12
+ *
13
+ * @remarks
14
+ * Use this only with schemas whose `validate` method returns synchronously. If
15
+ * validation returns a promise or thenable, the result is an `Err` with
16
+ * {@link ASYNC_SCHEMA_MESSAGE}.
17
+ */
18
+ export declare const parse: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => (input: I) => Result<O, SchemaValidationError>;
19
+ /** Parses the success value of a plain neverthrow `Result`. */
20
+ export declare const andParse: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => <E>(r: Result<I, E>) => Result<O, E | SchemaValidationError>;
21
+ /** Parses the success value of a `ResultR`. */
22
+ export declare const andParseR: <I, O>(schema: StandardSchemaV1<I, O>, options?: SchemaOptions) => <R, E>(rr: ResultR<R, I, E>) => ResultR<R, O, E | SchemaValidationError>;
23
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAO,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAE3B,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,GACf,CAAC,EAAE,CAAC,EAAE,QAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,aAAa,MAC7D,OAAO,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,qBAAqB,CAY1C,CAAC;AAEJ,+DAA+D;AAC/D,eAAO,MAAM,QAAQ,GAClB,CAAC,EAAE,CAAC,EAAE,QAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,aAAa,MAC7D,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,qBAAqB,CACtB,CAAC;AAEtC,+CAA+C;AAC/C,eAAO,MAAM,SAAS,GACnB,CAAC,EAAE,CAAC,EAAE,QAAQ,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,aAAa,MAC7D,CAAC,EAAE,CAAC,EAAE,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,qBAAqB,CAE9B,CAAC"}
package/dist/sync.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Synchronous Standard Schema adapters.
3
+ *
4
+ * @module
5
+ */
6
+ import { err } from 'neverthrow';
7
+ import { ASYNC_SCHEMA_MESSAGE, EXCEPTION_MESSAGE, fromStandardSchemaResult, isPromiseLike, schemaValidationError, } from './common.js';
8
+ /**
9
+ * Builds a sync parser for a Standard Schema.
10
+ *
11
+ * @remarks
12
+ * Use this only with schemas whose `validate` method returns synchronously. If
13
+ * validation returns a promise or thenable, the result is an `Err` with
14
+ * {@link ASYNC_SCHEMA_MESSAGE}.
15
+ */
16
+ export const parse = (schema, options) => (input) => {
17
+ try {
18
+ const outcome = schema['~standard'].validate(input, options?.validationOptions);
19
+ if (isPromiseLike(outcome)) {
20
+ return err(schemaValidationError(ASYNC_SCHEMA_MESSAGE, []));
21
+ }
22
+ return fromStandardSchemaResult(outcome, options);
23
+ }
24
+ catch (cause) {
25
+ return err(schemaValidationError(EXCEPTION_MESSAGE, [], cause));
26
+ }
27
+ };
28
+ /** Parses the success value of a plain neverthrow `Result`. */
29
+ export const andParse = (schema, options) => (r) => r.andThen(parse(schema, options));
30
+ /** Parses the success value of a `ResultR`. */
31
+ export const andParseR = (schema, options) => (rr) => (r) => rr(r).andThen(parse(schema, options));
32
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,GAAG,EAAe,MAAM,YAAY,CAAC;AAE9C,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EAGb,qB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
+ "license": "ISC",
7
+ "description": "Standard Schema adapters for neverthrow and @konker.dev/neverthrow-r.",
8
+ "homepage": "https://konker.dev/",
9
+ "keywords": [
10
+ "node",
11
+ "neverthrow",
12
+ "neverthrow-r",
13
+ "standard-schema",
14
+ "typescript",
15
+ "functional-programming"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/konker/konker.dev/packages/neverthrow-r-schema"
20
+ },
21
+ "exports": {
22
+ "./package.json": "./package.json",
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ },
27
+ "./async": {
28
+ "types": "./dist/async.d.ts",
29
+ "import": "./dist/async.js"
30
+ },
31
+ "./common": {
32
+ "types": "./dist/common.d.ts",
33
+ "import": "./dist/common.js"
34
+ },
35
+ "./sync": {
36
+ "types": "./dist/sync.d.ts",
37
+ "import": "./dist/sync.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "dist/**/*",
42
+ "!dist/**/*.test.*"
43
+ ],
44
+ "main": "dist/index.js",
45
+ "devDependencies": {
46
+ "@arethetypeswrong/cli": "^0.18.2",
47
+ "@effect/language-service": "^0.86.1",
48
+ "@eslint/compat": "^2.0.1",
49
+ "@eslint/js": "^9.39.2",
50
+ "@konker.dev/common-config": "^0.8.0",
51
+ "@types/node": "^25.8.0",
52
+ "@vitest/coverage-istanbul": "^4.1.6",
53
+ "aws-sdk-client-mock": "^4.1.0",
54
+ "aws-sdk-client-mock-vitest": "^7.0.1",
55
+ "eslint": "^9.39.2",
56
+ "eslint-plugin-fp": "^2.3.0",
57
+ "eslint-plugin-prettier": "^5.5.5",
58
+ "eslint-plugin-simple-import-sort": "^12.1.1",
59
+ "eslint-plugin-sort-destructure-keys": "^2.0.0",
60
+ "leasot": "^14.4.0",
61
+ "madge": "^8.0.0",
62
+ "prettier": "^3.8.3",
63
+ "tsx": "^4.22.1",
64
+ "type-coverage": "^2.29.7",
65
+ "typedoc": "^0.28.15",
66
+ "typedoc-plugin-markdown": "^4.4.0",
67
+ "typescript": "^5.9.3",
68
+ "typescript-eslint": "^8.52.0",
69
+ "vitest": "^4.1.6",
70
+ "zod": "^3.23.0"
71
+ },
72
+ "dependencies": {
73
+ "@standard-schema/spec": "^1.0.0",
74
+ "neverthrow": "^8.2.0",
75
+ "@konker.dev/neverthrow-r": "0.0.1"
76
+ },
77
+ "scripts": {
78
+ "test": "vitest run --coverage",
79
+ "clean": "rm -rf dist && rm -f tsconfig.tsbuildinfo",
80
+ "typecheck": "tsc --noEmit",
81
+ "build": "pnpm run clean && tsc",
82
+ "type-coverage-check": "type-coverage --detail --at-least 97",
83
+ "circular-check": "madge --extensions ts --circular --no-color --no-spinner --warning src",
84
+ "eslint-check": "eslint --max-warnings=0 '**/*.{ts,js,json}'",
85
+ "eslint-fix": "npx eslint --fix||true",
86
+ "generated-exports-check": "npx --package=@konker.dev/common-config generate-exports-verify `pwd`",
87
+ "docs-generate": "typedoc",
88
+ "generated-docs-check": "pnpm run docs-generate && git diff --exit-code docs/reference",
89
+ "exports-check": "NPM_CONFIG_CACHE=.npm-cache attw --pack . --ignore-rules=cjs-resolves-to-esm --profile=esm-only",
90
+ "fixme-check": "leasot --exit-nicely --skip-unsupported src",
91
+ "prettier-check": "npx prettier --check --ignore-path .gitignore --ignore-path .prettierignore '**/*.{css,html,js,ts,json,md,yaml,yml}'",
92
+ "prettier-fix": "pnpm run prettier-check --write",
93
+ "lint-check": "pnpm run eslint-check && pnpm run prettier-check && pnpm run circular-check && pnpm run fixme-check",
94
+ "lint-fix": "pnpm run eslint-fix && pnpm run prettier-fix",
95
+ "pre-push": "pnpm run lint-check && pnpm run typecheck",
96
+ "codecov": "npx --package=@konker.dev/common-config codecov-upload `pwd` '@konker.dev/neverthrow-r-schema'",
97
+ "ci": "pnpm run lint-check && pnpm run typecheck && pnpm run type-coverage-check && pnpm run test && pnpm run build && pnpm run generated-exports-check && pnpm run generated-docs-check && pnpm run exports-check && pnpm run fixme-check",
98
+ "cd": "pnpm run build && npx --package=@konker.dev/common-config npm-publish-if-version-not-exists `pwd`"
99
+ }
100
+ }