@othree.io/auditor 2.0.0 → 2.1.0
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/README.md +60 -63
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -25
- package/lib/index.js.map +1 -1
- package/lib/validation-error.d.ts +8 -0
- package/lib/validation-error.d.ts.map +1 -0
- package/lib/validation-error.js +14 -0
- package/lib/validation-error.js.map +1 -0
- package/lib/zod.d.ts +8 -18
- package/lib/zod.d.ts.map +1 -1
- package/lib/zod.js +16 -40
- package/lib/zod.js.map +1 -1
- package/package.json +1 -6
- package/vitest.config.mts +0 -1
- package/lib/validator.d.ts +0 -10
- package/lib/validator.d.ts.map +0 -1
- package/lib/validator.js +0 -22
- package/lib/validator.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,93 +1,90 @@
|
|
|
1
|
-
# auditor
|
|
1
|
+
# @othree.io/auditor
|
|
2
2
|
|
|
3
|
+
A functional validation library built on [Zod](https://zod.dev). Validation results are returned as `Optional<T>` from [`@othree.io/optional`](https://www.npmjs.com/package/@othree.io/optional), so invalid input never throws — you get either a filled `Optional` with the parsed value or an empty one carrying a `ValidationError`.
|
|
3
4
|
|
|
5
|
+
## Install
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
|
8
|
-
|
|
9
|
-
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
|
10
|
-
|
|
11
|
-
## Add your files
|
|
12
|
-
|
|
13
|
-
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
|
14
|
-
- [ ] [Add files using the command line](https://docs.gitlab.com/topics/git/add_files/#add-files-to-a-git-repository) or push an existing Git repository with the following command:
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
cd existing_repo
|
|
18
|
-
git remote add origin https://gitlab.com/othree.oss/auditor.git
|
|
19
|
-
git branch -M main
|
|
20
|
-
git push -uf origin main
|
|
7
|
+
```bash
|
|
8
|
+
npm install @othree.io/auditor
|
|
21
9
|
```
|
|
22
10
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- [ ] [Set up project integrations](https://gitlab.com/othree.oss/auditor/-/settings/integrations)
|
|
11
|
+
Peer dependencies:
|
|
26
12
|
|
|
27
|
-
|
|
13
|
+
```bash
|
|
14
|
+
npm install zod @othree.io/optional
|
|
15
|
+
```
|
|
28
16
|
|
|
29
|
-
|
|
30
|
-
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
|
31
|
-
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
|
32
|
-
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
|
33
|
-
- [ ] [Set auto-merge](https://docs.gitlab.com/user/project/merge_requests/auto_merge/)
|
|
17
|
+
## Usage
|
|
34
18
|
|
|
35
|
-
|
|
19
|
+
### `zodValidate`
|
|
36
20
|
|
|
37
|
-
|
|
21
|
+
Creates a curried validation function from any Zod schema. Returns `Optional<T>` — filled on success, empty with a `ValidationError` on failure.
|
|
38
22
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
|
43
|
-
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
|
23
|
+
```typescript
|
|
24
|
+
import { z } from 'zod'
|
|
25
|
+
import { zodValidate } from '@othree.io/auditor'
|
|
44
26
|
|
|
45
|
-
|
|
27
|
+
const UserSchema = z.object({
|
|
28
|
+
name: z.string().min(1),
|
|
29
|
+
age: z.number().int().nonnegative(),
|
|
30
|
+
}).strict()
|
|
46
31
|
|
|
47
|
-
|
|
32
|
+
type User = z.infer<typeof UserSchema>
|
|
48
33
|
|
|
49
|
-
|
|
34
|
+
const validateUser = zodValidate(UserSchema)
|
|
50
35
|
|
|
51
|
-
|
|
36
|
+
const result = validateUser({ name: 'Alice', age: 30 })
|
|
52
37
|
|
|
53
|
-
|
|
38
|
+
if (result.isPresent) {
|
|
39
|
+
console.log(result.get()) // { name: 'Alice', age: 30 }
|
|
40
|
+
} else {
|
|
41
|
+
console.log(result.getError().errors)
|
|
42
|
+
// e.g. { name: ['String must contain at least 1 character(s)'] }
|
|
43
|
+
}
|
|
44
|
+
```
|
|
54
45
|
|
|
55
|
-
|
|
56
|
-
Choose a self-explaining name for your project.
|
|
46
|
+
### Built-in constraints
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
|
48
|
+
The library exports common string constraints ready to use with `zodValidate`:
|
|
60
49
|
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
| Constraint | Description |
|
|
51
|
+
|------------------|------------------------------------------------------|
|
|
52
|
+
| `NonEmptyString` | Trims whitespace, requires at least 1 character |
|
|
53
|
+
| `CountryISOCode` | Two uppercase letters (e.g. `US`, `MX`) |
|
|
54
|
+
| `LanguageCode` | Two lowercase letters (e.g. `en`, `es`) |
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
```typescript
|
|
57
|
+
import { zodValidate, NonEmptyString, CountryISOCode, LanguageCode } from '@othree.io/auditor'
|
|
66
58
|
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
zodValidate(NonEmptyString)(' hello ') // Optional('hello')
|
|
60
|
+
zodValidate(CountryISOCode)('US') // Optional('US')
|
|
61
|
+
zodValidate(LanguageCode)('es') // Optional('es')
|
|
62
|
+
zodValidate(LanguageCode)('BAD') // Empty(ValidationError)
|
|
63
|
+
```
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
|
65
|
+
### `ValidationError`
|
|
72
66
|
|
|
73
|
-
|
|
74
|
-
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
|
67
|
+
When validation fails, the `Optional` carries a `ValidationError` with per-field error messages:
|
|
75
68
|
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
```typescript
|
|
70
|
+
import { ValidationError } from '@othree.io/auditor'
|
|
78
71
|
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
const error = new ValidationError({
|
|
73
|
+
email: ['Required'],
|
|
74
|
+
age: ['Expected number, received string'],
|
|
75
|
+
})
|
|
81
76
|
|
|
82
|
-
|
|
77
|
+
error.name // 'ValidationError'
|
|
78
|
+
error.errors // { email: ['Required'], age: ['Expected number, received string'] }
|
|
79
|
+
```
|
|
83
80
|
|
|
84
|
-
|
|
81
|
+
## Scripts
|
|
85
82
|
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
```bash
|
|
84
|
+
npm test # run tests with 100% coverage threshold
|
|
85
|
+
npm run build # compile TypeScript to lib/
|
|
86
|
+
```
|
|
88
87
|
|
|
89
88
|
## License
|
|
90
|
-
For open source projects, say how it is licensed.
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
|
90
|
+
ISC
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export *
|
|
1
|
+
export * from './validation-error';
|
|
2
|
+
export * from './zod';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,OAAO,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -10,33 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
15
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
38
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports
|
|
40
|
-
__exportStar(require("./
|
|
41
|
-
exports.zod = __importStar(require("./zod"));
|
|
17
|
+
__exportStar(require("./validation-error"), exports);
|
|
18
|
+
__exportStar(require("./zod"), exports);
|
|
42
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,wCAAqB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type FieldsValidationErrors = Record<string, Array<string>>;
|
|
2
|
+
export declare class ValidationError extends Error {
|
|
3
|
+
static readonly ERROR = "ValidationError";
|
|
4
|
+
readonly errors: FieldsValidationErrors;
|
|
5
|
+
constructor(validationErrors: FieldsValidationErrors);
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=validation-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-error.d.ts","sourceRoot":"","sources":["../src/validation-error.ts"],"names":[],"mappings":"AAAA,KAAK,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AAE3D,qBAAa,eAAgB,SAAQ,KAAK;IACtC,MAAM,CAAC,QAAQ,CAAC,KAAK,qBAAoB;IACzC,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAA;gBAE3B,gBAAgB,EAAE,sBAAsB;CAMvD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = void 0;
|
|
4
|
+
class ValidationError extends Error {
|
|
5
|
+
constructor(validationErrors) {
|
|
6
|
+
super(JSON.stringify(validationErrors));
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
this.name = ValidationError.ERROR;
|
|
9
|
+
this.errors = validationErrors;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.ValidationError = ValidationError;
|
|
13
|
+
ValidationError.ERROR = 'ValidationError';
|
|
14
|
+
//# sourceMappingURL=validation-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-error.js","sourceRoot":"","sources":["../src/validation-error.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAgB,SAAQ,KAAK;IAItC,YAAY,gBAAwC;QAChD,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAA;QACvC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACjD,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC,KAAK,CAAA;QACjC,IAAI,CAAC,MAAM,GAAG,gBAAgB,CAAA;IAClC,CAAC;;AATL,0CAUC;AATmB,qBAAK,GAAG,iBAAiB,CAAA"}
|
package/lib/zod.d.ts
CHANGED
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import { z, ZodType } from 'zod';
|
|
1
|
+
import { ZodError, z, ZodType } from 'zod';
|
|
2
2
|
import { Optional } from '@othree.io/optional';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export declare const zodValidate: <T>(constraints: ZodType<T>) => (input: T) => Optional<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Non-empty string constraint
|
|
13
|
-
*/
|
|
3
|
+
import { ValidationError } from './validation-error';
|
|
4
|
+
export declare const toValidationError: (deps: {
|
|
5
|
+
ValidationError: new (errors: Record<string, Array<string>>) => ValidationError;
|
|
6
|
+
}) => (error: ZodError) => ValidationError;
|
|
7
|
+
export declare const zodValidate: <T>(deps: {
|
|
8
|
+
constraints: ZodType<T>;
|
|
9
|
+
}) => (input: T) => Optional<T>;
|
|
14
10
|
export declare const NonEmptyString: z.ZodString;
|
|
15
|
-
/**
|
|
16
|
-
* Country ISO Code constraint
|
|
17
|
-
*/
|
|
18
11
|
export declare const CountryISOCode: z.ZodString;
|
|
19
|
-
/**
|
|
20
|
-
* Language code constraint
|
|
21
|
-
*/
|
|
22
12
|
export declare const LanguageCode: z.ZodString;
|
|
23
13
|
//# sourceMappingURL=zod.d.ts.map
|
package/lib/zod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAqB,MAAM,KAAK,CAAA;AAC5D,OAAO,EAAQ,QAAQ,EAAC,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAA;AAElD,eAAO,MAAM,iBAAiB,GAAI,MAAM;IACpC,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,eAAe,CAAA;CAClF,MAAM,OAAO,QAAQ,oBAarB,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,CAAC,EAAE,MAAM;IACjC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CAC1B,MAAM,OAAO,CAAC,KAAG,QAAQ,CAAC,CAAC,CAG3B,CAAA;AAED,eAAO,MAAM,cAAc,aAA2B,CAAA;AACtD,eAAO,MAAM,cAAc,aAAiE,CAAA;AAC5F,eAAO,MAAM,YAAY,aAA8D,CAAA"}
|
package/lib/zod.js
CHANGED
|
@@ -1,54 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LanguageCode = exports.CountryISOCode = exports.NonEmptyString = exports.zodValidate = void 0;
|
|
3
|
+
exports.LanguageCode = exports.CountryISOCode = exports.NonEmptyString = exports.zodValidate = exports.toValidationError = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const optional_1 = require("@othree.io/optional");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
* @param {ZodError} error - ZodError instance containing validation errors.
|
|
11
|
-
* @returns {ValidationError} Returns a ValidationError instance.
|
|
12
|
-
*/
|
|
13
|
-
const toValidationError = (error) => {
|
|
14
|
-
return new excuses_1.ValidationError(error.issues.reduce((errors, issue) => {
|
|
6
|
+
const validation_error_1 = require("./validation-error");
|
|
7
|
+
const toValidationError = (deps) => (error) => {
|
|
8
|
+
const errors = error.issues.reduce((acc, issue) => {
|
|
15
9
|
if (issue.code === 'unrecognized_keys') {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
}, errors);
|
|
10
|
+
issue.keys.forEach(key => {
|
|
11
|
+
acc[key] = [`Unrecognized key: ${key}`];
|
|
12
|
+
});
|
|
13
|
+
return acc;
|
|
22
14
|
}
|
|
23
15
|
const path = issue.path.length === 0 ? 'input' : issue.path.join('.');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}, {}));
|
|
16
|
+
acc[path] = [issue.message];
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
return new deps.ValidationError(errors);
|
|
29
20
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
* @param {ZodType<T>} constraints - ZodType constraints.
|
|
35
|
-
* @returns {Function} Returns a function that accepts an input of type T and returns a filled Optional<T> if valid
|
|
36
|
-
*/
|
|
37
|
-
const zodValidate = (constraints) => (input) => {
|
|
38
|
-
const maybeInput = constraints.safeParse(input);
|
|
39
|
-
return (maybeInput.success) ? (0, optional_1.Optional)(maybeInput.data) : (0, optional_1.Empty)(toValidationError(maybeInput.error));
|
|
21
|
+
exports.toValidationError = toValidationError;
|
|
22
|
+
const zodValidate = (deps) => (input) => {
|
|
23
|
+
const maybeInput = deps.constraints.safeParse(input);
|
|
24
|
+
return (maybeInput.success) ? (0, optional_1.Optional)(maybeInput.data) : (0, optional_1.Empty)((0, exports.toValidationError)({ ValidationError: validation_error_1.ValidationError })(maybeInput.error));
|
|
40
25
|
};
|
|
41
26
|
exports.zodValidate = zodValidate;
|
|
42
|
-
/**
|
|
43
|
-
* Non-empty string constraint
|
|
44
|
-
*/
|
|
45
27
|
exports.NonEmptyString = zod_1.z.string().trim().min(1);
|
|
46
|
-
/**
|
|
47
|
-
* Country ISO Code constraint
|
|
48
|
-
*/
|
|
49
28
|
exports.CountryISOCode = exports.NonEmptyString.regex(/^[A-Z]{2}/g, 'Invalid country ISO code');
|
|
50
|
-
/**
|
|
51
|
-
* Language code constraint
|
|
52
|
-
*/
|
|
53
29
|
exports.LanguageCode = exports.NonEmptyString.regex(/^[a-z]{2}/g, 'Invalid language code');
|
|
54
30
|
//# sourceMappingURL=zod.js.map
|
package/lib/zod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":";;;AAAA,6BAA4D;AAC5D,kDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"zod.js","sourceRoot":"","sources":["../src/zod.ts"],"names":[],"mappings":";;;AAAA,6BAA4D;AAC5D,kDAAmD;AACnD,yDAAkD;AAE3C,MAAM,iBAAiB,GAAG,CAAC,IAEjC,EAAE,EAAE,CAAC,CAAC,KAAe,EAAE,EAAE;IACtB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAkC,EAAE,KAAK,EAAE,EAAE;QAC7E,IAAI,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;YACrC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;gBACrB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,qBAAqB,GAAG,EAAE,CAAC,CAAA;YAC3C,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;QACd,CAAC;QACD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACrE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QAC3B,OAAO,GAAG,CAAA;IACd,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;AAC3C,CAAC,CAAA;AAfY,QAAA,iBAAiB,qBAe7B;AAEM,MAAM,WAAW,GAAG,CAAI,IAE9B,EAAE,EAAE,CAAC,CAAC,KAAQ,EAAe,EAAE;IAC5B,MAAM,UAAU,GAA0B,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAC3E,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,mBAAQ,EAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,gBAAK,EAAI,IAAA,yBAAiB,EAAC,EAAC,eAAe,EAAf,kCAAe,EAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AACjI,CAAC,CAAA;AALY,QAAA,WAAW,eAKvB;AAEY,QAAA,cAAc,GAAG,OAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AACzC,QAAA,cAAc,GAAG,sBAAc,CAAC,KAAK,CAAC,YAAY,EAAE,0BAA0B,CAAC,CAAA;AAC/E,QAAA,YAAY,GAAG,sBAAc,CAAC,KAAK,CAAC,YAAY,EAAE,uBAAuB,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@othree.io/auditor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Auditor",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,16 +14,11 @@
|
|
|
14
14
|
"author": "othree",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@othree.io/excuses": "^1.1.0",
|
|
18
17
|
"@othree.io/optional": "^2.3.1",
|
|
19
|
-
"validate.js": "^0.13.1",
|
|
20
18
|
"zod": "^4.1.12"
|
|
21
19
|
},
|
|
22
20
|
"devDependencies": {
|
|
23
21
|
"@vitest/coverage-istanbul": "^4.0.4",
|
|
24
|
-
"docdash": "^2.0.1",
|
|
25
|
-
"jsdoc": "^4.0.2",
|
|
26
|
-
"jsdoc-plugin-typescript": "^3.2.0",
|
|
27
22
|
"semantic-release": "^24.2.9",
|
|
28
23
|
"semantic-release-monorepo": "^8.0.2",
|
|
29
24
|
"typescript": "^5.9.3",
|
package/vitest.config.mts
CHANGED
package/lib/validator.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ValidateJS } from 'validate.js';
|
|
2
|
-
import { Optional } from '@othree.io/optional';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a validation function using the provided ValidateJS instance.
|
|
5
|
-
*
|
|
6
|
-
* @param {ValidateJS} validateJs - Instance of ValidateJS library.
|
|
7
|
-
* @returns {Function} Returns a function that accepts constraints and then another function that accepts an input of type T and returns a filled Optional<T> if valid.
|
|
8
|
-
*/
|
|
9
|
-
export declare const validate: (validateJs: ValidateJS) => (constraints: any) => <T>(input: T) => Optional<T>;
|
|
10
|
-
//# sourceMappingURL=validator.d.ts.map
|
package/lib/validator.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,QAAQ,EAAM,MAAM,qBAAqB,CAAA;AAGjD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GAAI,YAAY,UAAU,MAAM,aAAa,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,KAAG,QAAQ,CAAC,CAAC,CAUlG,CAAA"}
|
package/lib/validator.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.validate = void 0;
|
|
4
|
-
const optional_1 = require("@othree.io/optional");
|
|
5
|
-
const excuses_1 = require("@othree.io/excuses");
|
|
6
|
-
/**
|
|
7
|
-
* Generates a validation function using the provided ValidateJS instance.
|
|
8
|
-
*
|
|
9
|
-
* @param {ValidateJS} validateJs - Instance of ValidateJS library.
|
|
10
|
-
* @returns {Function} Returns a function that accepts constraints and then another function that accepts an input of type T and returns a filled Optional<T> if valid.
|
|
11
|
-
*/
|
|
12
|
-
const validate = (validateJs) => (constraints) => (input) => {
|
|
13
|
-
return (0, optional_1.Try)(() => {
|
|
14
|
-
const maybeErrors = (0, optional_1.Optional)(validateJs.validate(input, constraints));
|
|
15
|
-
if (maybeErrors.isPresent) {
|
|
16
|
-
throw new excuses_1.ValidationError(maybeErrors.get());
|
|
17
|
-
}
|
|
18
|
-
return input;
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
exports.validate = validate;
|
|
22
|
-
//# sourceMappingURL=validator.js.map
|
package/lib/validator.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;;AACA,kDAAiD;AACjD,gDAAkD;AAElD;;;;;GAKG;AACI,MAAM,QAAQ,GAAG,CAAC,UAAsB,EAAE,EAAE,CAAC,CAAC,WAAgB,EAAE,EAAE,CAAC,CAAI,KAAQ,EAAe,EAAE;IACnG,OAAO,IAAA,cAAG,EAAC,GAAG,EAAE;QACZ,MAAM,WAAW,GAAG,IAAA,mBAAQ,EAAM,UAAU,CAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAA;QAE1E,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC;YACxB,MAAM,IAAI,yBAAe,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAA;QAChD,CAAC;QAED,OAAO,KAAK,CAAA;IAChB,CAAC,CAAC,CAAA;AACN,CAAC,CAAA;AAVY,QAAA,QAAQ,YAUpB"}
|