@opencraw/core 0.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 +67 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +5302 -0
- package/dist/src/access/access-broker.use-case.d.ts +43 -0
- package/dist/src/access/access-config.error.d.ts +5 -0
- package/dist/src/access/access-config.repository.d.ts +11 -0
- package/dist/src/access/access-json-schema.mapper.d.ts +8 -0
- package/dist/src/access/access-plugin.contract.d.ts +48 -0
- package/dist/src/access/access-preset.store.d.ts +19 -0
- package/dist/src/access/access-profile.contract.d.ts +91 -0
- package/dist/src/access/index.d.ts +11 -0
- package/dist/src/access/render-access.mapper.d.ts +41 -0
- package/dist/src/access/session-id.algorithm.d.ts +8 -0
- package/dist/src/api-steps/extract-from-document.use-case.d.ts +27 -0
- package/dist/src/api-steps/index.d.ts +4 -0
- package/dist/src/api-steps/run-api-step.use-case.d.ts +20 -0
- package/dist/src/api-steps/send-request.use-case.d.ts +22 -0
- package/dist/src/browser-session/browser-session.config.d.ts +21 -0
- package/dist/src/browser-session/browser.client.d.ts +67 -0
- package/dist/src/browser-session/index.d.ts +5 -0
- package/dist/src/crawl-events/crawl-event.contract.d.ts +120 -0
- package/dist/src/crawl-events/event-bus.store.d.ts +10 -0
- package/dist/src/crawl-events/index.d.ts +4 -0
- package/dist/src/crawl-events/trace-line.mapper.d.ts +14 -0
- package/dist/src/crawl-execution/bootstrap-session.use-case.d.ts +55 -0
- package/dist/src/crawl-execution/crawl-options.config.d.ts +37 -0
- package/dist/src/crawl-execution/crawl-report.model.d.ts +25 -0
- package/dist/src/crawl-execution/create-crawler.use-case.d.ts +19 -0
- package/dist/src/crawl-execution/index.d.ts +8 -0
- package/dist/src/crawl-execution/rotating-runner.use-case.d.ts +57 -0
- package/dist/src/crawl-execution/run-crawl.use-case.d.ts +13 -0
- package/dist/src/crawl-execution/run-input-recipe.use-case.d.ts +40 -0
- package/dist/src/extraction-scope/extraction-scope.model.d.ts +73 -0
- package/dist/src/extraction-scope/index.d.ts +5 -0
- package/dist/src/extraction-scope/live-element.model.d.ts +28 -0
- package/dist/src/hooks/hook-registry.store.d.ts +16 -0
- package/dist/src/hooks/hook.contract.d.ts +17 -0
- package/dist/src/hooks/hook.error.d.ts +7 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/http-session/http-response.contract.d.ts +44 -0
- package/dist/src/http-session/http.client.d.ts +42 -0
- package/dist/src/http-session/index.d.ts +5 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/output-mapping/coerce-field.mapper.d.ts +19 -0
- package/dist/src/output-mapping/generated-field.mapper.d.ts +16 -0
- package/dist/src/output-mapping/index.d.ts +9 -0
- package/dist/src/output-mapping/map-record.use-case.d.ts +27 -0
- package/dist/src/output-mapping/mapping.error.d.ts +17 -0
- package/dist/src/output-mapping/missing-value.policy.d.ts +14 -0
- package/dist/src/output-mapping/output-field.validator.d.ts +10 -0
- package/dist/src/output-mapping/output-record.model.d.ts +20 -0
- package/dist/src/recipe-loading/index.d.ts +9 -0
- package/dist/src/recipe-loading/load-recipe-set.use-case.d.ts +45 -0
- package/dist/src/recipe-loading/read-recipe-source.use-case.d.ts +14 -0
- package/dist/src/recipe-loading/recipe-binding.error.d.ts +14 -0
- package/dist/src/recipe-loading/recipe-binding.validator.d.ts +32 -0
- package/dist/src/recipe-loading/recipe-file.repository.d.ts +11 -0
- package/dist/src/recipe-loading/recipe-set.model.d.ts +12 -0
- package/dist/src/recipe-loading/recipe-source.contract.d.ts +28 -0
- package/dist/src/recipe-loading/recipe-text.mapper.d.ts +14 -0
- package/dist/src/recipe-schema/index.d.ts +15 -0
- package/dist/src/recipe-schema/input-recipe.contract.d.ts +103 -0
- package/dist/src/recipe-schema/json-schema.mapper.d.ts +15 -0
- package/dist/src/recipe-schema/output-recipe.contract.d.ts +47 -0
- package/dist/src/recipe-schema/recipe-kind.enum.d.ts +31 -0
- package/dist/src/recipe-schema/recipe-validation.error.d.ts +17 -0
- package/dist/src/recipe-schema/recipe.validator.d.ts +28 -0
- package/dist/src/recipe-schema/step.contract.d.ts +152 -0
- package/dist/src/recipe-schema/transform-rule.contract.d.ts +120 -0
- package/dist/src/record-sink/dedupe.policy.d.ts +17 -0
- package/dist/src/record-sink/index.d.ts +8 -0
- package/dist/src/record-sink/json-lines-sink.repository.d.ts +19 -0
- package/dist/src/record-sink/memory-sink.repository.d.ts +9 -0
- package/dist/src/record-sink/record-sink.contract.d.ts +17 -0
- package/dist/src/selection/html-selector.algorithm.d.ts +18 -0
- package/dist/src/selection/index.d.ts +8 -0
- package/dist/src/selection/json-path.algorithm.d.ts +9 -0
- package/dist/src/selection/json-text.algorithm.d.ts +31 -0
- package/dist/src/selection/regex.algorithm.d.ts +12 -0
- package/dist/src/selection/take-value.mapper.d.ts +27 -0
- package/dist/src/step-flow/block-rule.policy.d.ts +21 -0
- package/dist/src/step-flow/blocked.error.d.ts +9 -0
- package/dist/src/step-flow/for-each.use-case.d.ts +18 -0
- package/dist/src/step-flow/index.d.ts +10 -0
- package/dist/src/step-flow/paginate.use-case.d.ts +17 -0
- package/dist/src/step-flow/retry.policy.d.ts +21 -0
- package/dist/src/step-flow/run-gate.policy.d.ts +39 -0
- package/dist/src/step-flow/run-steps.use-case.d.ts +39 -0
- package/dist/src/step-flow/step-failure.error.d.ts +14 -0
- package/dist/src/step-flow/step-runner.contract.d.ts +39 -0
- package/dist/src/template/expression.algorithm.d.ts +53 -0
- package/dist/src/template/index.d.ts +7 -0
- package/dist/src/template/template.algorithm.d.ts +53 -0
- package/dist/src/template/value-path.algorithm.d.ts +29 -0
- package/dist/src/template/value-text.algorithm.d.ts +18 -0
- package/dist/src/transformation/apply-transform-chain.use-case.d.ts +17 -0
- package/dist/src/transformation/collection.algorithm.d.ts +15 -0
- package/dist/src/transformation/currency.algorithm.d.ts +15 -0
- package/dist/src/transformation/date.algorithm.d.ts +13 -0
- package/dist/src/transformation/index.d.ts +10 -0
- package/dist/src/transformation/lookup.algorithm.d.ts +24 -0
- package/dist/src/transformation/number.algorithm.d.ts +30 -0
- package/dist/src/transformation/string.algorithm.d.ts +18 -0
- package/dist/src/transformation/transform-registry.store.d.ts +36 -0
- package/dist/src/transformation/transform.error.d.ts +8 -0
- package/dist/src/transformation/url.algorithm.d.ts +20 -0
- package/dist/src/web-steps/evaluate-script.use-case.d.ts +10 -0
- package/dist/src/web-steps/extract-from-page.use-case.d.ts +10 -0
- package/dist/src/web-steps/index.d.ts +2 -0
- package/dist/src/web-steps/interact.use-case.d.ts +36 -0
- package/dist/src/web-steps/navigate.use-case.d.ts +14 -0
- package/dist/src/web-steps/run-web-step.use-case.d.ts +22 -0
- package/dist/src/web-steps/snapshot-elements.use-case.d.ts +13 -0
- package/package.json +75 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @opencraw/core
|
|
2
|
+
|
|
3
|
+
The recipe-driven crawler engine. See the [repository README](../../README.md) for the concept, the
|
|
4
|
+
[recipe guide](../../docs/recipes/authoring.md) for authoring recipes and [`docs/requirements.md`](../../docs/requirements.md)
|
|
5
|
+
for the specification.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @opencraw/core
|
|
9
|
+
npx playwright install chromium # web recipes and browser bootstraps only
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
| Export | Purpose |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `loadRecipes(source)` | Reads, validates and binds recipes from one source holding all of them, the output recipe found by its `kind`. The source is any of the forms below. Throws `RecipeValidationError` / `RecipeBindingError` with every problem and its JSON path. |
|
|
17
|
+
| `loadRecipeSet({ output, inputs })` | The same, with the output recipe given apart; each part is any of the forms below. |
|
|
18
|
+
| `readRecipeSource(source)` | Decodes recipes without validating them, each with where it came from, for tooling. |
|
|
19
|
+
| `createCrawler(options)` | Builds an engine: `hooks`, `sink` (`memorySink()` default, `jsonLinesSink(path, { append? })`), `onEvent`, `browser` settings, `dedupe` (`run` / `recipe` / `off`), `onRecipeError` (`continue` / `stop`), `resume` (skip keys the sink already has), `access` + `accessPlugins` (proxy profiles, see [access.md](../../docs/recipes/access.md)). |
|
|
20
|
+
| `loadAccessConfig(path)`, `AccessBroker`, `ACCESS_PRESETS` | Access configs: load and validate one, lease a profile outside a crawl (the cli's `probe` does), list the provider presets. |
|
|
21
|
+
| `crawler.run(set)` | Runs every input recipe in sequence; returns a `CrawlReport`. |
|
|
22
|
+
| `crawler.close()` | Closes the browser, if one was launched. |
|
|
23
|
+
| `HttpClient`, `BrowserClient` | The same clients the engine's runners use, for tooling built on top of `@opencraw/core` (`@opencraw/cli`'s `probe` command uses both). |
|
|
24
|
+
| `parseInputRecipe`, `parseOutputRecipe`, `inputRecipeJsonSchema`, `outputRecipeJsonSchema`, `accessConfigJsonSchema` | The contracts, for tooling. |
|
|
25
|
+
|
|
26
|
+
A recipe source is any of:
|
|
27
|
+
|
|
28
|
+
| Form | Example |
|
|
29
|
+
|---|---|
|
|
30
|
+
| A path: a `.json` or `.jsonl` file, or a directory of them | `'recipes/'`, `'recipes/bundle.jsonl'` |
|
|
31
|
+
| JSON or JSON Lines text: a string starting with `{` or `[` | `'{"kind":"output",...}\n{"kind":"input",...}'` |
|
|
32
|
+
| Bytes of either: `Buffer` or any typed array, `ArrayBuffer`, `Blob`, `File`, a stream (Node `Readable`, web `ReadableStream`) | `formData.get('recipes')` |
|
|
33
|
+
| Decoded recipe objects | `[outputRecipe, ...inputRecipes]` |
|
|
34
|
+
| An array mixing the above | `['recipes/product.output.json', uploadedBlob]` |
|
|
35
|
+
|
|
36
|
+
A JSON file or text holds one recipe or an array of them; JSON Lines holds one recipe per line. Errors name
|
|
37
|
+
where each recipe came from: the path, `path:line` in a JSON Lines file, a `File`'s name, or `recipes[2]` /
|
|
38
|
+
`recipes:3` for recipes from memory.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
// On a server, with the recipes in memory rather than on disk:
|
|
42
|
+
const recipes = await loadRecipes(file) // a File from a multipart upload: JSON Lines, output recipe anywhere in it
|
|
43
|
+
const report = await createCrawler({ sink: memorySink() }).run(recipes)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Hooks are plain functions `(input, args, context) => value`, referenced from recipes by name in a `hook`
|
|
47
|
+
step or a `hook` transform.
|
|
48
|
+
|
|
49
|
+
## Layout
|
|
50
|
+
|
|
51
|
+
`src/` is a set of flat, role-suffixed slices (see the [ADR](../../docs/architecture/vertical-feature-slices.md)):
|
|
52
|
+
|
|
53
|
+
```text
|
|
54
|
+
recipe-schema zod contracts, validation, JSON Schema template {{ }} rendering, dotted paths
|
|
55
|
+
extraction-scope values by id, nested per page/iteration selection jsonpath-plus, cheerio
|
|
56
|
+
hooks the named-handler registry crawl-events the event bus
|
|
57
|
+
http-session Playwright request context browser-session Playwright browser
|
|
58
|
+
step-flow forEach / paginate / emit / policies api-steps request + extract runner
|
|
59
|
+
web-steps goto / click / extract runner transformation the built-in ops
|
|
60
|
+
output-mapping ids -> validated records record-sink memory, JSON Lines, dedupe
|
|
61
|
+
recipe-loading files -> a bound RecipeSet crawl-execution sessions, runs, reports
|
|
62
|
+
access proxy profiles, presets, leases, plugins
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`e2e/` holds the fixture shop and the browser suite (`nx run core:e2e`); `tools/` emits `schemas/`.
|
|
66
|
+
Set `OPENCRAW_CHROMIUM=/path/to/chrome` to run the e2e suite with a browser other than the one
|
|
67
|
+
`playwright install` fetched.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index.js";
|