@streamline-pulse/formkrafter-core 0.28.1 → 0.30.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/dist/brick/brick.d.ts +2 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +364 -4
- package/dist/index.js.map +13 -9
- package/dist/services/document_reader_service.d.ts +57 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/utils/documents.d.ts +14 -0
- package/dist/utils/registries.d.ts +21 -0
- package/dist/utils/units.d.ts +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { FileLike } from "./file_upload_service.js";
|
|
2
|
+
/**
|
|
3
|
+
* What a document reader returns for a scanned or uploaded document: the
|
|
4
|
+
* text it could read, the fields it was asked for, and some metadata. The
|
|
5
|
+
* reader itself (OCR, layout analysis, a language model…) lives on the host:
|
|
6
|
+
* FormKrafter only sends the file and keeps the answer.
|
|
7
|
+
*/
|
|
8
|
+
export interface DocumentReading {
|
|
9
|
+
/** Plain text (or Markdown) read from the document. */
|
|
10
|
+
text?: string;
|
|
11
|
+
/** The fields that were requested, by key; `null` when not found. */
|
|
12
|
+
fields?: Record<string, unknown>;
|
|
13
|
+
pages?: number;
|
|
14
|
+
/** Free label of the engine that produced the reading. */
|
|
15
|
+
engine?: string;
|
|
16
|
+
/** Reading confidence in [0, 1] when the engine provides one. */
|
|
17
|
+
confidence?: number;
|
|
18
|
+
warnings?: string[];
|
|
19
|
+
}
|
|
20
|
+
export interface DocumentReadOptions {
|
|
21
|
+
url?: string;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/** Field keys the reader should extract (see `parseDocumentFields`). */
|
|
24
|
+
fields?: {
|
|
25
|
+
key: string;
|
|
26
|
+
label?: string;
|
|
27
|
+
}[];
|
|
28
|
+
/** Language hint for OCR, e.g. `fr`. */
|
|
29
|
+
language?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The form context (`_`-prefixed keys such as `_processVersionId`). The
|
|
32
|
+
* default reader does not send it; a host reader may use it to scope the
|
|
33
|
+
* reading (organisation, process…).
|
|
34
|
+
*/
|
|
35
|
+
context?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export interface DocumentReaderService {
|
|
38
|
+
read(file: FileLike, options?: DocumentReadOptions): Promise<DocumentReading>;
|
|
39
|
+
}
|
|
40
|
+
export interface FetchDocumentReaderDefaults {
|
|
41
|
+
url?: string;
|
|
42
|
+
headers?: Record<string, string>;
|
|
43
|
+
credentials?: RequestCredentials;
|
|
44
|
+
fieldName?: string;
|
|
45
|
+
fetch?: typeof fetch;
|
|
46
|
+
}
|
|
47
|
+
/** Normalises whatever a reader answered into a `DocumentReading`. */
|
|
48
|
+
export declare function readDocumentReading(payload: unknown): DocumentReading;
|
|
49
|
+
/**
|
|
50
|
+
* Default reader: POSTs the file as multipart (`file`, plus `fields` as a
|
|
51
|
+
* comma-separated list and `language`) to the URL and reads the JSON answer.
|
|
52
|
+
*/
|
|
53
|
+
export declare class FetchDocumentReaderService implements DocumentReaderService {
|
|
54
|
+
private readonly defaults;
|
|
55
|
+
constructor(defaults?: FetchDocumentReaderDefaults);
|
|
56
|
+
read(file: FileLike, options?: DocumentReadOptions): Promise<DocumentReading>;
|
|
57
|
+
}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { type DataSourceService } from "./data_source_service.js";
|
|
|
3
3
|
import { type FileUploadService } from "./file_upload_service.js";
|
|
4
4
|
import { type SpecSourceService } from "./spec_source_service.js";
|
|
5
5
|
import { type OptionSourceService } from "./option_source_service.js";
|
|
6
|
+
import { type DocumentReaderService } from "./document_reader_service.js";
|
|
6
7
|
export interface Services {
|
|
7
8
|
jsRunnerService: JsRunnerService;
|
|
8
9
|
dataSourceService: DataSourceService;
|
|
9
10
|
fileUploadService: FileUploadService;
|
|
10
11
|
specSourceService: SpecSourceService;
|
|
11
12
|
optionSourceService: OptionSourceService;
|
|
13
|
+
documentReaderService: DocumentReaderService;
|
|
12
14
|
}
|
|
13
15
|
declare const services: Services;
|
|
14
16
|
export { services };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document bricks: the fields a reader should look for and the form keys they
|
|
3
|
+
* fill, both written one per line in the brick configuration.
|
|
4
|
+
*/
|
|
5
|
+
export interface DocumentField {
|
|
6
|
+
key: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
9
|
+
/** `key|Label` per line (or `key` alone); blank lines and `#` comments ignored. */
|
|
10
|
+
export declare function parseDocumentFields(source: unknown): DocumentField[];
|
|
11
|
+
/** `field=formKey` per line: which form key each read field fills. */
|
|
12
|
+
export declare function parseDocumentFills(source: unknown): Record<string, string>;
|
|
13
|
+
/** The form patch a reading produces: only the mapped fields with a value. */
|
|
14
|
+
export declare function documentFillPatch(fields: Record<string, unknown> | undefined, fills: Record<string, string>): Record<string, unknown>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public registries: vehicle plates and company registration numbers, each
|
|
3
|
+
* checked against a named format (per country, or a generic one).
|
|
4
|
+
*/
|
|
5
|
+
interface Format {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** Tested against the compacted, upper-cased value. */
|
|
9
|
+
test: (value: string) => boolean;
|
|
10
|
+
/** Display form of a valid value (compacted input). */
|
|
11
|
+
format?: (value: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare const PLATE_FORMATS: Format[];
|
|
14
|
+
export declare const REGISTRY_FORMATS: Format[];
|
|
15
|
+
/** Compact form kept in the data for plates (letters and digits only, upper case). */
|
|
16
|
+
export declare const compactPlate: (value: string) => string;
|
|
17
|
+
export declare function checkPlate(format: string, value: string): boolean;
|
|
18
|
+
export declare function formatPlate(format: string, value: string): string;
|
|
19
|
+
export declare function checkCompanyRegistry(format: string, value: string): boolean;
|
|
20
|
+
export declare function formatCompanyRegistry(format: string, value: string): string;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Measures: a number with a unit, kept with its value in the family's base
|
|
3
|
+
* unit so sums and averages stay meaningful whatever unit each answer used.
|
|
4
|
+
*/
|
|
5
|
+
export type MeasureFamily = "length" | "area" | "mass" | "volume" | "duration";
|
|
6
|
+
export interface MeasureUnit {
|
|
7
|
+
id: string;
|
|
8
|
+
/** Symbol shown to the user. */
|
|
9
|
+
symbol: string;
|
|
10
|
+
/** Multiply a value in this unit by `factor` to get the family's base unit. */
|
|
11
|
+
factor: number;
|
|
12
|
+
}
|
|
13
|
+
export interface MeasureValue {
|
|
14
|
+
value: number;
|
|
15
|
+
unit: string;
|
|
16
|
+
/** `value` converted to the family's base unit. */
|
|
17
|
+
base: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const MEASURE_FAMILIES: Record<MeasureFamily, {
|
|
20
|
+
base: string;
|
|
21
|
+
units: MeasureUnit[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const measureFamilyOf: (value: unknown) => MeasureFamily;
|
|
24
|
+
/** The units of a family, restricted to `allowed` (comma-separated ids) when given. */
|
|
25
|
+
export declare function measureUnits(family: MeasureFamily, allowed?: unknown): MeasureUnit[];
|
|
26
|
+
export declare function unitOf(family: MeasureFamily, id: string): MeasureUnit | undefined;
|
|
27
|
+
/** Converts between two units of the same family; `undefined` when a unit is unknown. */
|
|
28
|
+
export declare function convertMeasure(family: MeasureFamily, value: number, from: string, to: string): number | undefined;
|
|
29
|
+
/** Builds the stored value: the number, its unit and the base-unit equivalent. */
|
|
30
|
+
export declare function measureValue(family: MeasureFamily, value: number, unit: string): MeasureValue | undefined;
|
|
31
|
+
/** Human form, e.g. `2,5 ha`. */
|
|
32
|
+
export declare function formatMeasure(family: MeasureFamily, value: MeasureValue | undefined, locale?: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamline-pulse/formkrafter-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Framework-agnostic core for FormKrafter: form specs, RFC 6902 ops with undo/redo, Ajv validation, sandboxed rules engine and injectable services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|