@dpuse/dpuse-tool-streamparser-json-parser 1.0.3 → 1.0.4
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 +16 -16
- package/dist/dpuse-tool-streamparser-json-parser.es.js +596 -293
- package/dist/dpuse-tool-streamparser-json-parser.es.js.map +1 -1
- package/dist/shipped-packages.json +1 -1
- package/dist/types/src/index.d.ts +12 -8
- package/dist/types/src/itemRecords.d.ts +1 -1
- package/dist/types/src/structureWalker.d.ts +10 -2
- package/dist/types/src/textPosition.d.ts +11 -0
- package/package.json +2 -2
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { BuildStructureIndexOptions, ListStructureEntriesOptions, ListStructureEntriesResult, ParsedRecordsChunk, ParseStreamOptions, ParseStreamSummary, ParseTextOptions, ParseTextResult, StructuredParserInterface, StructureIndex } from '@dpuse/dpuse-shared';
|
|
2
2
|
export declare class Tool implements StructuredParserInterface {
|
|
3
3
|
/**
|
|
4
|
-
* Build structure index.
|
|
5
|
-
* each
|
|
4
|
+
* Build structure index. Maps the lists and objects of the item, or of its start for a preview, with a locator for
|
|
5
|
+
* each, so any of them can be read again on its own. Suggests the list to read as the table when there is only one.
|
|
6
|
+
* A syntax error ends the map early and is reported in it. Memory stays small however large the item.
|
|
6
7
|
*/
|
|
7
8
|
buildStructureIndex(stream: ReadableStream<Uint8Array>, options: BuildStructureIndexOptions): Promise<StructureIndex>;
|
|
8
9
|
/**
|
|
9
|
-
* List structure entries. Lists one
|
|
10
|
-
* stops as soon as the
|
|
10
|
+
* List structure entries. Lists one page of a list or object for a viewer that opens one level at a time, and says
|
|
11
|
+
* where the next page starts. Reading stops as soon as the page is known, so a page near the start of a large node is
|
|
12
|
+
* quick.
|
|
11
13
|
*/
|
|
12
14
|
listStructureEntries(stream: ReadableStream<Uint8Array>, options: ListStructureEntriesOptions): Promise<ListStructureEntriesResult>;
|
|
13
15
|
/**
|
|
14
|
-
* Parse stream. Reads the list at 'structurePath', or the
|
|
15
|
-
* column names, then one row per item. The columns are those found in the first chunk of items. A later item with
|
|
16
|
-
* field outside them keeps its other fields and counts as not uniform.
|
|
16
|
+
* Parse stream. Reads the list at 'structurePath', or at the top of the item when it is not given, as rows: a header
|
|
17
|
+
* of column names, then one row per item. The columns are those found in the first chunk of items. A later item with
|
|
18
|
+
* a field outside them keeps its other fields and counts as not uniform. Stops between items at 'byteLimit' or when
|
|
19
|
+
* 'stopSignal' fires. Fails on a syntax error, naming its line and column. The caller owns the stream and its fetch.
|
|
17
20
|
*/
|
|
18
21
|
parseStream(stream: ReadableStream<Uint8Array>, options: ParseStreamOptions): AsyncGenerator<ParsedRecordsChunk, ParseStreamSummary, undefined>;
|
|
19
22
|
/**
|
|
20
23
|
* Parse text. Reads a preview the same way as 'parseStream'. A preview cut short ends in the middle of the JSON, so
|
|
21
|
-
* only an error in
|
|
24
|
+
* only an error in what was read is an issue, and the items read before the cut are kept. In JSON Lines each line is
|
|
25
|
+
* read on its own, so a line that cannot be read is an issue and the lines after it are still read.
|
|
22
26
|
*/
|
|
23
27
|
parseText(text: string, options: ParseTextOptions): Promise<ParseTextResult>;
|
|
24
28
|
}
|
|
@@ -9,7 +9,7 @@ export interface TableShape {
|
|
|
9
9
|
columnIndexes: Map<string, number>;
|
|
10
10
|
columnNames: string[];
|
|
11
11
|
}
|
|
12
|
-
export declare function createItemReader(targetPath: StructurePath, onItem: (item: JsonValue) => void): ItemReader;
|
|
12
|
+
export declare function createItemReader(targetPath: StructurePath, onItem: (item: JsonValue, endOffset: number) => void): ItemReader;
|
|
13
13
|
export declare function flattenItem(item: JsonValue): Map<string, JsonValue>;
|
|
14
14
|
export declare function constructTableShape(itemFields: Map<string, JsonValue>[]): TableShape;
|
|
15
15
|
export declare function constructHeaderRecord(shape: TableShape): ParsedRecord;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { StructureContainerKindId, StructureKindId, StructurePath } from '@dpuse/dpuse-shared';
|
|
2
2
|
export interface StructureWalker {
|
|
3
|
+
byteCount: () => number;
|
|
3
4
|
end: () => void;
|
|
4
5
|
write: (input: Uint8Array) => void;
|
|
5
6
|
}
|
|
6
7
|
export interface StructureWalkerOptions {
|
|
7
8
|
baseOffset: number;
|
|
8
|
-
firstItemIndex: number;
|
|
9
9
|
isJsonLines: boolean;
|
|
10
|
-
isStartInsideList: boolean;
|
|
11
10
|
rootPath: StructurePath;
|
|
11
|
+
startInside: StartInside | undefined;
|
|
12
|
+
}
|
|
13
|
+
export interface StartInside {
|
|
14
|
+
firstIndex: number;
|
|
15
|
+
kindId: StructureContainerKindId;
|
|
12
16
|
}
|
|
13
17
|
export interface StructureWalkerHandlers {
|
|
14
18
|
onContainerEnd?: (container: OpenContainer, endOffset: number) => void;
|
|
@@ -45,7 +49,11 @@ export type JsonScalar = boolean | NumberText | string | null;
|
|
|
45
49
|
export type JsonValue = JsonScalar | JsonValue[] | {
|
|
46
50
|
[key: string]: JsonValue;
|
|
47
51
|
};
|
|
52
|
+
export interface StructureError extends Error {
|
|
53
|
+
offset: number;
|
|
54
|
+
}
|
|
48
55
|
export declare function createStructureWalker(options: StructureWalkerOptions, handlers: StructureWalkerHandlers): StructureWalker;
|
|
49
56
|
export declare function isNumberText(value: unknown): value is NumberText;
|
|
57
|
+
export declare function isStructureError(error: unknown): error is StructureError;
|
|
50
58
|
export declare function stringifyJsonValue(value: JsonValue): string;
|
|
51
59
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PositionTracker {
|
|
2
|
+
locate: (offset: number) => TextPosition;
|
|
3
|
+
take: (bytes: Uint8Array, startOffset: number) => void;
|
|
4
|
+
}
|
|
5
|
+
export interface TextPosition {
|
|
6
|
+
columnNumber: number | undefined;
|
|
7
|
+
excerpt: string;
|
|
8
|
+
lineNumber: number | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function createPositionTracker(isFromTop: boolean): PositionTracker;
|
|
11
|
+
export declare function countLineFeeds(bytes: Uint8Array): number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dpuse/dpuse-tool-streamparser-json-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Reads JSON and JSON Lines as a stream, and maps their structure for browsing and choosing tables.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"test": "node -e \"import('@dpuse/dpuse-development').then(m => m.testProject())\""
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@dpuse/dpuse-shared": "^1.0.
|
|
63
|
+
"@dpuse/dpuse-shared": "^1.0.216",
|
|
64
64
|
"@streamparser/json": "^0.0.26"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|