@dpuse/dpuse-tool-streamparser-json-parser 0.0.0-stage → 1.0.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.
@@ -0,0 +1,8 @@
1
+ {
2
+ "packages": [
3
+ "@dpuse/dpuse-shared@1.0.214",
4
+ "@streamparser/json@0.0.26",
5
+ "valibot@1.5.0"
6
+ ],
7
+ "external": []
8
+ }
@@ -0,0 +1,24 @@
1
+ import { BuildStructureIndexOptions, ListStructureEntriesOptions, ListStructureEntriesResult, ParsedRecordsChunk, ParseStreamOptions, ParseStreamSummary, ParseTextOptions, ParseTextResult, StructuredParserInterface, StructureIndex } from '@dpuse/dpuse-shared';
2
+ export declare class Tool implements StructuredParserInterface {
3
+ /**
4
+ * Build structure index. Reads the whole item once and maps its lists and objects down to 'maxDepth', with where
5
+ * each starts and ends, so any of them can be read again on its own. Memory stays small however large the item.
6
+ */
7
+ buildStructureIndex(stream: ReadableStream<Uint8Array>, options: BuildStructureIndexOptions): Promise<StructureIndex>;
8
+ /**
9
+ * List structure entries. Lists one level of a list or object for a viewer that opens one level at a time. Reading
10
+ * stops as soon as the entries asked for are known, so a page near the start of a large node is quick.
11
+ */
12
+ listStructureEntries(stream: ReadableStream<Uint8Array>, options: ListStructureEntriesOptions): Promise<ListStructureEntriesResult>;
13
+ /**
14
+ * Parse stream. Reads the list at 'structurePath', or the whole item when it is not given, as rows: a header of
15
+ * column names, then one row per item. The columns are those found in the first chunk of items. A later item with a
16
+ * field outside them keeps its other fields and counts as not uniform. The caller owns the stream and its fetch.
17
+ */
18
+ parseStream(stream: ReadableStream<Uint8Array>, options: ParseStreamOptions): AsyncGenerator<ParsedRecordsChunk, ParseStreamSummary, undefined>;
19
+ /**
20
+ * 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 a complete item is an issue. The items read before the cut are kept.
22
+ */
23
+ parseText(text: string, options: ParseTextOptions): Promise<ParseTextResult>;
24
+ }
@@ -0,0 +1,19 @@
1
+ import { ParsedRecord, StructurePath } from '@dpuse/dpuse-shared';
2
+ import { JsonValue, StructureWalkerHandlers } from './structureWalker';
3
+ export interface ItemReader {
4
+ handlers: StructureWalkerHandlers;
5
+ isTargetClosed: () => boolean;
6
+ isTargetFound: () => boolean;
7
+ }
8
+ export interface TableShape {
9
+ columnIndexes: Map<string, number>;
10
+ columnNames: string[];
11
+ }
12
+ export declare function createItemReader(targetPath: StructurePath, onItem: (item: JsonValue) => void): ItemReader;
13
+ export declare function flattenItem(item: JsonValue): Map<string, JsonValue>;
14
+ export declare function constructTableShape(itemFields: Map<string, JsonValue>[]): TableShape;
15
+ export declare function constructHeaderRecord(shape: TableShape): ParsedRecord;
16
+ export declare function constructRecord(fields: Map<string, JsonValue>, shape: TableShape): {
17
+ hasUnknownField: boolean;
18
+ record: ParsedRecord;
19
+ };
@@ -0,0 +1,51 @@
1
+ import { StructureContainerKindId, StructureKindId, StructurePath } from '@dpuse/dpuse-shared';
2
+ export interface StructureWalker {
3
+ end: () => void;
4
+ write: (input: Uint8Array) => void;
5
+ }
6
+ export interface StructureWalkerOptions {
7
+ baseOffset: number;
8
+ firstItemIndex: number;
9
+ isJsonLines: boolean;
10
+ isStartInsideList: boolean;
11
+ rootPath: StructurePath;
12
+ }
13
+ export interface StructureWalkerHandlers {
14
+ onContainerEnd?: (container: OpenContainer, endOffset: number) => void;
15
+ onContainerStart?: (container: OpenContainer) => void;
16
+ onKey?: (container: OpenContainer, key: string) => void;
17
+ onScalar?: (scalar: ScalarEntry) => void;
18
+ onTokenStart?: (offset: number) => void;
19
+ }
20
+ export interface OpenContainer {
21
+ childCount: number;
22
+ depth: number;
23
+ isVirtual: boolean;
24
+ key: EntryKey;
25
+ kindId: StructureContainerKindId;
26
+ parent: OpenContainer | undefined;
27
+ path: StructurePath;
28
+ pendingKey: string | undefined;
29
+ positionId: PositionId;
30
+ startOffset: number;
31
+ }
32
+ export type EntryKey = number | string | undefined;
33
+ type PositionId = 'afterColon' | 'afterComma' | 'afterKey' | 'afterValue' | 'start';
34
+ export interface ScalarEntry {
35
+ key: EntryKey;
36
+ kindId: Exclude<StructureKindId, StructureContainerKindId>;
37
+ parent: OpenContainer | undefined;
38
+ startOffset: number;
39
+ value: JsonScalar;
40
+ }
41
+ export interface NumberText {
42
+ readonly numberText: string;
43
+ }
44
+ export type JsonScalar = boolean | NumberText | string | null;
45
+ export type JsonValue = JsonScalar | JsonValue[] | {
46
+ [key: string]: JsonValue;
47
+ };
48
+ export declare function createStructureWalker(options: StructureWalkerOptions, handlers: StructureWalkerHandlers): StructureWalker;
49
+ export declare function isNumberText(value: unknown): value is NumberText;
50
+ export declare function stringifyJsonValue(value: JsonValue): string;
51
+ export {};
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
- "name": "@dpuse/dpuse-tool-streamparser-json-parser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@dpuse/dpuse-tool-streamparser-json-parser",
3
+ "version": "1.0.1",
4
+ "private": false,
5
+ "description": "Reads JSON and JSON Lines as a stream, and maps their structure for browsing and choosing tables.",
6
+ "license": "MIT",
7
+ "author": "Jonathan Terrell <terrell.jm@gmail.com>",
8
+ "type": "module",
9
+ "sideEffects": false,
10
+ "homepage": "https://www.dpuse.app",
11
+ "bugs": {
12
+ "url": "https://github.com/dpuse/dpuse-tool-streamparser-json-parser/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/dpuse/dpuse-tool-streamparser-json-parser.git"
17
+ },
18
+ "module": "./dist/dpuse-tool-streamparser-json-parser.es.js",
19
+ "types": "./dist/types/src/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/types/src/index.d.ts",
23
+ "import": "./dist/dpuse-tool-streamparser-json-parser.es.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "engines": {
30
+ "node": ">=24",
31
+ "npm": ">=12"
32
+ },
33
+ "devEngines": {
34
+ "runtime": {
35
+ "name": "node",
36
+ "version": ">=24",
37
+ "onFail": "error"
38
+ },
39
+ "packageManager": {
40
+ "name": "npm",
41
+ "version": ">=12",
42
+ "onFail": "error"
43
+ }
44
+ },
45
+ "prettier": "@dpuse/dpuse-development/prettierrc",
46
+ "allowScripts": {
47
+ "fsevents@2.3.3": true,
48
+ "esbuild@0.28.2": true,
49
+ "workerd@1.20261110.1": true
50
+ },
51
+ "scripts": {
52
+ "audit": "node -e \"import('@dpuse/dpuse-development').then(m => m.auditDependencies())\"",
53
+ "build": "node -e \"import('@dpuse/dpuse-development').then(m => m.buildProject())\"",
54
+ "check": "node -e \"import('@dpuse/dpuse-development').then(m => m.checkProject())\"",
55
+ "document": "node -e \"import('@dpuse/dpuse-development').then(m => m.documentProject('MIT'))\"",
56
+ "format": "node -e \"import('@dpuse/dpuse-development').then(m => m.formatCode())\"",
57
+ "lint": "node -e \"import('@dpuse/dpuse-development').then(m => m.lintCode())\"",
58
+ "release": "npm run build && npm run document && npm run sync && node -e \"import('@dpuse/dpuse-development').then(m => m.triggerGitHubRelease())\"",
59
+ "sync": "node -e \"import('@dpuse/dpuse-development').then(m => m.syncProjectWithGitHub())\"",
60
+ "test": "node -e \"import('@dpuse/dpuse-development').then(m => m.testProject())\""
61
+ },
62
+ "dependencies": {
63
+ "@dpuse/dpuse-shared": "^1.0.214",
64
+ "@streamparser/json": "^0.0.26"
65
+ },
66
+ "devDependencies": {
67
+ "@dpuse/dpuse-development": "^1.0.149",
68
+ "@dpuse/eslint-config-dpuse": "^1.0.150",
69
+ "@types/node": "^26.6.6",
70
+ "@vitest/coverage-v8": "^5.1.0",
71
+ "eslint": "^10.14.0",
72
+ "prettier": "^3.10.1",
73
+ "sonda": "^0.14.0",
74
+ "typescript": "^6.0.3",
75
+ "vite": "^8.3.8",
76
+ "vite-plugin-dts": "^5.1.2",
77
+ "vitest": "^5.1.0",
78
+ "wrangler": "^4.161.0"
79
+ }
80
+ }