@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.
Files changed (114) hide show
  1. package/README.md +67 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.esm.js +5302 -0
  4. package/dist/src/access/access-broker.use-case.d.ts +43 -0
  5. package/dist/src/access/access-config.error.d.ts +5 -0
  6. package/dist/src/access/access-config.repository.d.ts +11 -0
  7. package/dist/src/access/access-json-schema.mapper.d.ts +8 -0
  8. package/dist/src/access/access-plugin.contract.d.ts +48 -0
  9. package/dist/src/access/access-preset.store.d.ts +19 -0
  10. package/dist/src/access/access-profile.contract.d.ts +91 -0
  11. package/dist/src/access/index.d.ts +11 -0
  12. package/dist/src/access/render-access.mapper.d.ts +41 -0
  13. package/dist/src/access/session-id.algorithm.d.ts +8 -0
  14. package/dist/src/api-steps/extract-from-document.use-case.d.ts +27 -0
  15. package/dist/src/api-steps/index.d.ts +4 -0
  16. package/dist/src/api-steps/run-api-step.use-case.d.ts +20 -0
  17. package/dist/src/api-steps/send-request.use-case.d.ts +22 -0
  18. package/dist/src/browser-session/browser-session.config.d.ts +21 -0
  19. package/dist/src/browser-session/browser.client.d.ts +67 -0
  20. package/dist/src/browser-session/index.d.ts +5 -0
  21. package/dist/src/crawl-events/crawl-event.contract.d.ts +120 -0
  22. package/dist/src/crawl-events/event-bus.store.d.ts +10 -0
  23. package/dist/src/crawl-events/index.d.ts +4 -0
  24. package/dist/src/crawl-events/trace-line.mapper.d.ts +14 -0
  25. package/dist/src/crawl-execution/bootstrap-session.use-case.d.ts +55 -0
  26. package/dist/src/crawl-execution/crawl-options.config.d.ts +37 -0
  27. package/dist/src/crawl-execution/crawl-report.model.d.ts +25 -0
  28. package/dist/src/crawl-execution/create-crawler.use-case.d.ts +19 -0
  29. package/dist/src/crawl-execution/index.d.ts +8 -0
  30. package/dist/src/crawl-execution/rotating-runner.use-case.d.ts +57 -0
  31. package/dist/src/crawl-execution/run-crawl.use-case.d.ts +13 -0
  32. package/dist/src/crawl-execution/run-input-recipe.use-case.d.ts +40 -0
  33. package/dist/src/extraction-scope/extraction-scope.model.d.ts +73 -0
  34. package/dist/src/extraction-scope/index.d.ts +5 -0
  35. package/dist/src/extraction-scope/live-element.model.d.ts +28 -0
  36. package/dist/src/hooks/hook-registry.store.d.ts +16 -0
  37. package/dist/src/hooks/hook.contract.d.ts +17 -0
  38. package/dist/src/hooks/hook.error.d.ts +7 -0
  39. package/dist/src/hooks/index.d.ts +4 -0
  40. package/dist/src/http-session/http-response.contract.d.ts +44 -0
  41. package/dist/src/http-session/http.client.d.ts +42 -0
  42. package/dist/src/http-session/index.d.ts +5 -0
  43. package/dist/src/index.d.ts +24 -0
  44. package/dist/src/output-mapping/coerce-field.mapper.d.ts +19 -0
  45. package/dist/src/output-mapping/generated-field.mapper.d.ts +16 -0
  46. package/dist/src/output-mapping/index.d.ts +9 -0
  47. package/dist/src/output-mapping/map-record.use-case.d.ts +27 -0
  48. package/dist/src/output-mapping/mapping.error.d.ts +17 -0
  49. package/dist/src/output-mapping/missing-value.policy.d.ts +14 -0
  50. package/dist/src/output-mapping/output-field.validator.d.ts +10 -0
  51. package/dist/src/output-mapping/output-record.model.d.ts +20 -0
  52. package/dist/src/recipe-loading/index.d.ts +9 -0
  53. package/dist/src/recipe-loading/load-recipe-set.use-case.d.ts +45 -0
  54. package/dist/src/recipe-loading/read-recipe-source.use-case.d.ts +14 -0
  55. package/dist/src/recipe-loading/recipe-binding.error.d.ts +14 -0
  56. package/dist/src/recipe-loading/recipe-binding.validator.d.ts +32 -0
  57. package/dist/src/recipe-loading/recipe-file.repository.d.ts +11 -0
  58. package/dist/src/recipe-loading/recipe-set.model.d.ts +12 -0
  59. package/dist/src/recipe-loading/recipe-source.contract.d.ts +28 -0
  60. package/dist/src/recipe-loading/recipe-text.mapper.d.ts +14 -0
  61. package/dist/src/recipe-schema/index.d.ts +15 -0
  62. package/dist/src/recipe-schema/input-recipe.contract.d.ts +103 -0
  63. package/dist/src/recipe-schema/json-schema.mapper.d.ts +15 -0
  64. package/dist/src/recipe-schema/output-recipe.contract.d.ts +47 -0
  65. package/dist/src/recipe-schema/recipe-kind.enum.d.ts +31 -0
  66. package/dist/src/recipe-schema/recipe-validation.error.d.ts +17 -0
  67. package/dist/src/recipe-schema/recipe.validator.d.ts +28 -0
  68. package/dist/src/recipe-schema/step.contract.d.ts +152 -0
  69. package/dist/src/recipe-schema/transform-rule.contract.d.ts +120 -0
  70. package/dist/src/record-sink/dedupe.policy.d.ts +17 -0
  71. package/dist/src/record-sink/index.d.ts +8 -0
  72. package/dist/src/record-sink/json-lines-sink.repository.d.ts +19 -0
  73. package/dist/src/record-sink/memory-sink.repository.d.ts +9 -0
  74. package/dist/src/record-sink/record-sink.contract.d.ts +17 -0
  75. package/dist/src/selection/html-selector.algorithm.d.ts +18 -0
  76. package/dist/src/selection/index.d.ts +8 -0
  77. package/dist/src/selection/json-path.algorithm.d.ts +9 -0
  78. package/dist/src/selection/json-text.algorithm.d.ts +31 -0
  79. package/dist/src/selection/regex.algorithm.d.ts +12 -0
  80. package/dist/src/selection/take-value.mapper.d.ts +27 -0
  81. package/dist/src/step-flow/block-rule.policy.d.ts +21 -0
  82. package/dist/src/step-flow/blocked.error.d.ts +9 -0
  83. package/dist/src/step-flow/for-each.use-case.d.ts +18 -0
  84. package/dist/src/step-flow/index.d.ts +10 -0
  85. package/dist/src/step-flow/paginate.use-case.d.ts +17 -0
  86. package/dist/src/step-flow/retry.policy.d.ts +21 -0
  87. package/dist/src/step-flow/run-gate.policy.d.ts +39 -0
  88. package/dist/src/step-flow/run-steps.use-case.d.ts +39 -0
  89. package/dist/src/step-flow/step-failure.error.d.ts +14 -0
  90. package/dist/src/step-flow/step-runner.contract.d.ts +39 -0
  91. package/dist/src/template/expression.algorithm.d.ts +53 -0
  92. package/dist/src/template/index.d.ts +7 -0
  93. package/dist/src/template/template.algorithm.d.ts +53 -0
  94. package/dist/src/template/value-path.algorithm.d.ts +29 -0
  95. package/dist/src/template/value-text.algorithm.d.ts +18 -0
  96. package/dist/src/transformation/apply-transform-chain.use-case.d.ts +17 -0
  97. package/dist/src/transformation/collection.algorithm.d.ts +15 -0
  98. package/dist/src/transformation/currency.algorithm.d.ts +15 -0
  99. package/dist/src/transformation/date.algorithm.d.ts +13 -0
  100. package/dist/src/transformation/index.d.ts +10 -0
  101. package/dist/src/transformation/lookup.algorithm.d.ts +24 -0
  102. package/dist/src/transformation/number.algorithm.d.ts +30 -0
  103. package/dist/src/transformation/string.algorithm.d.ts +18 -0
  104. package/dist/src/transformation/transform-registry.store.d.ts +36 -0
  105. package/dist/src/transformation/transform.error.d.ts +8 -0
  106. package/dist/src/transformation/url.algorithm.d.ts +20 -0
  107. package/dist/src/web-steps/evaluate-script.use-case.d.ts +10 -0
  108. package/dist/src/web-steps/extract-from-page.use-case.d.ts +10 -0
  109. package/dist/src/web-steps/index.d.ts +2 -0
  110. package/dist/src/web-steps/interact.use-case.d.ts +36 -0
  111. package/dist/src/web-steps/navigate.use-case.d.ts +14 -0
  112. package/dist/src/web-steps/run-web-step.use-case.d.ts +22 -0
  113. package/dist/src/web-steps/snapshot-elements.use-case.d.ts +13 -0
  114. 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.
@@ -0,0 +1 @@
1
+ export * from "./src/index.js";