xscrape 1.2.0 → 1.3.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/README.md CHANGED
@@ -21,7 +21,7 @@ Effect Schema, allowing you to use your preferred validation tool.
21
21
  | ---------------------------------------------------- | ------------------- | ------------------------------------------------------------------ |
22
22
  | [Zod](https://github.com/colinhacks/zod) | ✅ Supported | Default schema tool for `xscrape` |
23
23
  | [Effect/Schema](https://github.com/Effect-TS/effect) | ✅ Supported | Support for Effect/Schema for additional flexibility |
24
- | [Joi](https://github.com/sideway/joi) | 🚧 Planned | Support for Joi for those familiar with server-side validation |
24
+ | [Joi](https://github.com/sideway/joi) | Supported | Support for Joi for those familiar with server-side validation |
25
25
  | [Yup](https://github.com/jquense/yup) | 🚧 Planned | Adding Yup support for schema validation in front-end applications |
26
26
  | Others... | 🔄 In Consideration | Potential support for other schema tools as per user feedback |
27
27
 
package/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  EffectValidator: () => EffectValidator,
34
+ JoiValidator: () => JoiValidator,
34
35
  ZodValidator: () => ZodValidator,
35
36
  createScraper: () => createScraper
36
37
  });
@@ -105,9 +106,32 @@ var ZodValidator = class {
105
106
  return this.schema.parse(data);
106
107
  }
107
108
  };
109
+
110
+ // src/validators/joi.ts
111
+ var JoiValidator = class {
112
+ constructor(schema) {
113
+ this.schema = schema;
114
+ }
115
+ validate(data) {
116
+ const { error, value } = this.schema.validate(data, {
117
+ convert: true,
118
+ stripUnknown: true,
119
+ presence: "optional",
120
+ abortEarly: false
121
+ });
122
+ if (error) {
123
+ throw new Error(this.formatError(error));
124
+ }
125
+ return value;
126
+ }
127
+ formatError(error) {
128
+ return error.details.map((detail) => detail.message).join("\n");
129
+ }
130
+ };
108
131
  // Annotate the CommonJS export names for ESM import in node:
109
132
  0 && (module.exports = {
110
133
  EffectValidator,
134
+ JoiValidator,
111
135
  ZodValidator,
112
136
  createScraper
113
137
  });
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as cheerio from 'cheerio';
2
2
  import * as Schema from 'effect/Schema';
3
3
  import { ZodSchema } from 'zod';
4
+ import { Schema as Schema$1 } from 'joi';
4
5
 
5
6
  type ScrapeConfig<T> = {
6
7
  fields: SchemaFieldDefinitions<T>;
@@ -37,4 +38,11 @@ declare class ZodValidator<T> implements SchemaValidator<T> {
37
38
  validate(data: unknown): T;
38
39
  }
39
40
 
40
- export { EffectValidator, type FieldDefinition, type SchemaFieldDefinitions, type SchemaValidator, type ScrapeConfig, ZodValidator, createScraper };
41
+ declare class JoiValidator<T> implements SchemaValidator<T> {
42
+ private schema;
43
+ constructor(schema: Schema$1<T>);
44
+ validate(data: unknown): T;
45
+ private formatError;
46
+ }
47
+
48
+ export { EffectValidator, type FieldDefinition, JoiValidator, type SchemaFieldDefinitions, type SchemaValidator, type ScrapeConfig, ZodValidator, createScraper };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as cheerio from 'cheerio';
2
2
  import * as Schema from 'effect/Schema';
3
3
  import { ZodSchema } from 'zod';
4
+ import { Schema as Schema$1 } from 'joi';
4
5
 
5
6
  type ScrapeConfig<T> = {
6
7
  fields: SchemaFieldDefinitions<T>;
@@ -37,4 +38,11 @@ declare class ZodValidator<T> implements SchemaValidator<T> {
37
38
  validate(data: unknown): T;
38
39
  }
39
40
 
40
- export { EffectValidator, type FieldDefinition, type SchemaFieldDefinitions, type SchemaValidator, type ScrapeConfig, ZodValidator, createScraper };
41
+ declare class JoiValidator<T> implements SchemaValidator<T> {
42
+ private schema;
43
+ constructor(schema: Schema$1<T>);
44
+ validate(data: unknown): T;
45
+ private formatError;
46
+ }
47
+
48
+ export { EffectValidator, type FieldDefinition, JoiValidator, type SchemaFieldDefinitions, type SchemaValidator, type ScrapeConfig, ZodValidator, createScraper };
package/dist/index.js CHANGED
@@ -67,8 +67,31 @@ var ZodValidator = class {
67
67
  return this.schema.parse(data);
68
68
  }
69
69
  };
70
+
71
+ // src/validators/joi.ts
72
+ var JoiValidator = class {
73
+ constructor(schema) {
74
+ this.schema = schema;
75
+ }
76
+ validate(data) {
77
+ const { error, value } = this.schema.validate(data, {
78
+ convert: true,
79
+ stripUnknown: true,
80
+ presence: "optional",
81
+ abortEarly: false
82
+ });
83
+ if (error) {
84
+ throw new Error(this.formatError(error));
85
+ }
86
+ return value;
87
+ }
88
+ formatError(error) {
89
+ return error.details.map((detail) => detail.message).join("\n");
90
+ }
91
+ };
70
92
  export {
71
93
  EffectValidator,
94
+ JoiValidator,
72
95
  ZodValidator,
73
96
  createScraper
74
97
  };
package/package.json CHANGED
@@ -1,64 +1,68 @@
1
1
  {
2
- "name": "xscrape",
3
- "version": "1.2.0",
4
- "description": "A flexible and powerful library designed to extract and transform data from HTML documents using user-defined schemas",
5
- "main": "dist/index.js",
6
- "exports": {
7
- ".": {
8
- "import": "./dist/index.js",
9
- "require": "./dist/index.cjs"
10
- }
11
- },
12
- "files": [
13
- "dist"
14
- ],
15
- "type": "module",
16
- "scripts": {
17
- "build": "tsup",
18
- "ci": "npm run build && npm run check-format && npm run check-exports && npm run lint && npm run test",
19
- "lint": "tsc",
20
- "test": "vitest run",
21
- "format": "prettier --write ./src",
22
- "check-format": "prettier --check ./src",
23
- "check-exports": "attw --pack .",
24
- "local-release": "npm run ci && changeset version && changeset publish"
25
- },
26
- "keywords": [
27
- "web-scraping",
28
- "data-extraction",
29
- "automation",
30
- "html-parsing",
31
- "data-transformation",
32
- "user-defined-schemas",
33
- "crawler",
34
- "scraper",
35
- "zod",
36
- "yup",
37
- "joi",
38
- "effect-schema"
39
- ],
40
- "author": "Johnie Hjelm <johnie@hjelm.im>",
41
- "license": "MIT",
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/johnie/xscrape.git"
45
- },
46
- "bugs": {
47
- "url": "https://github.com/johnie/xscrape/issues"
48
- },
49
- "homepage": "https://github.com/johnie/xscrape#readme",
50
- "devDependencies": {
51
- "@arethetypeswrong/cli": "^0.16.4",
52
- "@changesets/cli": "^2.27.9",
53
- "prettier": "^3.3.3",
54
- "tsup": "^8.3.5",
55
- "typescript": "^5.6.3",
56
- "vite": "^5.4.10",
57
- "vitest": "^2.1.3"
58
- },
59
- "dependencies": {
60
- "cheerio": "^1.0.0",
61
- "effect": "^3.10.4",
62
- "zod": "^3.23.8"
2
+ "name": "xscrape",
3
+ "version": "1.3.1",
4
+ "description": "A flexible and powerful library designed to extract and transform data from HTML documents using user-defined schemas",
5
+ "main": "dist/index.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
63
10
  }
64
- }
11
+ },
12
+ "typings": "dist/index.d.ts",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "type": "module",
17
+ "keywords": [
18
+ "web-scraping",
19
+ "data-extraction",
20
+ "automation",
21
+ "html-parsing",
22
+ "data-transformation",
23
+ "user-defined-schemas",
24
+ "crawler",
25
+ "scraper",
26
+ "zod",
27
+ "yup",
28
+ "joi",
29
+ "effect-schema"
30
+ ],
31
+ "author": "Johnie Hjelm <johnie@hjelm.im>",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/johnie/xscrape.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/johnie/xscrape/issues"
39
+ },
40
+ "homepage": "https://github.com/johnie/xscrape#readme",
41
+ "devDependencies": {
42
+ "@arethetypeswrong/cli": "^0.16.4",
43
+ "@changesets/changelog-github": "^0.5.0",
44
+ "@changesets/cli": "^2.27.9",
45
+ "prettier": "^3.3.3",
46
+ "tsup": "^8.3.5",
47
+ "typescript": "^5.6.3",
48
+ "vite": "^5.4.10",
49
+ "vitest": "^2.1.3"
50
+ },
51
+ "dependencies": {
52
+ "cheerio": "^1.0.0",
53
+ "effect": "^3.10.4",
54
+ "joi": "^17.13.3",
55
+ "zod": "^3.23.8"
56
+ },
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "ci": "npm run build && npm run check-format && npm run check-exports && npm run lint && npm run test",
60
+ "lint": "tsc",
61
+ "test": "vitest run",
62
+ "format": "prettier --write ./src",
63
+ "check-format": "prettier --check ./src",
64
+ "check-exports": "attw --pack .",
65
+ "local-release": "npm run ci && changeset version && changeset publish",
66
+ "release": "npm run ci && changeset publish"
67
+ }
68
+ }