@script-it/json-views-core 0.1.0-beta.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +174 -0
  3. package/THIRD_PARTY_NOTICES.txt +4917 -0
  4. package/dist/annotation-capabilities.d.ts +17 -0
  5. package/dist/annotation-capabilities.js +21 -0
  6. package/dist/atomic-value.d.ts +3 -0
  7. package/dist/atomic-value.js +6 -0
  8. package/dist/date-type.d.ts +48 -0
  9. package/dist/date-type.js +244 -0
  10. package/dist/diagnostics.d.ts +8 -0
  11. package/dist/diagnostics.js +252 -0
  12. package/dist/document-session.d.ts +52 -0
  13. package/dist/document-session.js +164 -0
  14. package/dist/formats/conversion.d.ts +17 -0
  15. package/dist/formats/conversion.js +75 -0
  16. package/dist/formats/csv-format.d.ts +31 -0
  17. package/dist/formats/csv-format.js +269 -0
  18. package/dist/formats/document-format.d.ts +35 -0
  19. package/dist/formats/document-format.js +1 -0
  20. package/dist/formats/json-format.d.ts +12 -0
  21. package/dist/formats/json-format.js +109 -0
  22. package/dist/html-view-bindings.d.ts +4 -0
  23. package/dist/html-view-bindings.js +32 -0
  24. package/dist/html-view-limits.d.ts +1 -0
  25. package/dist/html-view-limits.js +1 -0
  26. package/dist/index.d.ts +19 -0
  27. package/dist/index.js +19 -0
  28. package/dist/inference-fields.d.ts +5 -0
  29. package/dist/inference-fields.js +23 -0
  30. package/dist/inference.d.ts +26 -0
  31. package/dist/inference.js +304 -0
  32. package/dist/json-limits.d.ts +8 -0
  33. package/dist/json-limits.js +25 -0
  34. package/dist/json-path.d.ts +14 -0
  35. package/dist/json-path.js +84 -0
  36. package/dist/json-source-patcher.d.ts +97 -0
  37. package/dist/json-source-patcher.js +778 -0
  38. package/dist/metadata.d.ts +137 -0
  39. package/dist/metadata.js +952 -0
  40. package/dist/safe-pattern.d.ts +5 -0
  41. package/dist/safe-pattern.js +20 -0
  42. package/dist/schema-validation.d.ts +3 -0
  43. package/dist/schema-validation.js +4 -0
  44. package/dist/source-default.d.ts +2 -0
  45. package/dist/source-default.js +39 -0
  46. package/dist/table-suitability.d.ts +5 -0
  47. package/dist/table-suitability.js +55 -0
  48. package/dist/type-registry.d.ts +57 -0
  49. package/dist/type-registry.js +238 -0
  50. package/dist/value-comparison.d.ts +18 -0
  51. package/dist/value-comparison.js +133 -0
  52. package/dist/view-model.d.ts +18 -0
  53. package/dist/view-model.js +134 -0
  54. package/package.json +52 -0
  55. package/schema/jsonviews.schema.json +102 -0
@@ -0,0 +1,84 @@
1
+ export const VALUE_PATH_MISSING = Symbol('value-path-missing');
2
+ export function describeValuePath(path) {
3
+ if (path.length === 0)
4
+ return '<root>';
5
+ return path
6
+ .map((segment) => typeof segment === 'number' ? `[${segment}]` : `[${JSON.stringify(segment)}]`)
7
+ .join('');
8
+ }
9
+ /** Resolves an existing typed path or explains why it is invalid. */
10
+ export function requireValueAtPath(root, path) {
11
+ let current = root;
12
+ for (let index = 0; index < path.length; index++) {
13
+ const segment = path[index];
14
+ if (Array.isArray(current)) {
15
+ if (typeof segment !== 'number' || !Number.isInteger(segment) || segment < 0) {
16
+ throw new TypeError(`JSON array path segment at index ${index} must be a non-negative integer`);
17
+ }
18
+ if (segment >= current.length || !Object.prototype.hasOwnProperty.call(current, segment)) {
19
+ throw new RangeError(`JSON path ${describeValuePath(path)} does not exist`);
20
+ }
21
+ current = current[segment];
22
+ continue;
23
+ }
24
+ if (current !== null && typeof current === 'object') {
25
+ if (typeof segment !== 'string') {
26
+ throw new TypeError(`JSON object path segment at index ${index} must be a string`);
27
+ }
28
+ if (!Object.prototype.hasOwnProperty.call(current, segment)) {
29
+ throw new RangeError(`JSON path ${describeValuePath(path)} does not exist`);
30
+ }
31
+ current = current[segment];
32
+ continue;
33
+ }
34
+ throw new TypeError(`JSON path ${describeValuePath(path.slice(0, index))} is not a container`);
35
+ }
36
+ return current;
37
+ }
38
+ /** Resolves typed segments without conflating array indices and object keys. */
39
+ export function getValueAtPath(root, path) {
40
+ try {
41
+ return requireValueAtPath(root, path);
42
+ }
43
+ catch {
44
+ return VALUE_PATH_MISSING;
45
+ }
46
+ }
47
+ /** Stable key for view state associated with an exact JSON path. */
48
+ export function valuePathKey(path) {
49
+ return JSON.stringify(path);
50
+ }
51
+ /** Creates nested JSON data properties without following inherited objects or setters.
52
+ * Array writes may replace an existing item or append one item; sparse arrays are rejected.
53
+ */
54
+ export function setJsonValueAtPath(root, path, value) {
55
+ if (path.length === 0)
56
+ throw new TypeError('A property path is required');
57
+ let current = root;
58
+ for (let index = 0; index < path.length; index += 1) {
59
+ const segment = path[index];
60
+ if (Array.isArray(current)) {
61
+ if (typeof segment !== 'number' || !Number.isSafeInteger(segment) || segment < 0 || segment > current.length) {
62
+ throw new TypeError('Array writes require an existing index or the next consecutive index');
63
+ }
64
+ }
65
+ else if (typeof segment !== 'string') {
66
+ throw new TypeError('Object writes require a string property');
67
+ }
68
+ if (index === path.length - 1) {
69
+ Object.defineProperty(current, segment, { value, enumerable: true, writable: true, configurable: true });
70
+ return;
71
+ }
72
+ const descriptor = Object.getOwnPropertyDescriptor(current, segment);
73
+ const child = descriptor && 'value' in descriptor ? descriptor.value : undefined;
74
+ const needsArray = typeof path[index + 1] === 'number';
75
+ if (child !== null && typeof child === 'object' && Array.isArray(child) === needsArray) {
76
+ current = child;
77
+ }
78
+ else {
79
+ const next = needsArray ? [] : Object.create(null);
80
+ Object.defineProperty(current, segment, { value: next, enumerable: true, writable: true, configurable: true });
81
+ current = next;
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,97 @@
1
+ import { type AtomicValue } from './atomic-value.js';
2
+ import { type ValuePath } from './json-path.js';
3
+ export interface JsonSourceRange {
4
+ start: number;
5
+ end: number;
6
+ }
7
+ /** Locates the exact source span represented by a parsed JSON value path. */
8
+ export declare function jsonSourceRangeAtPath(source: string, path: ValuePath): JsonSourceRange;
9
+ /** Locates several value paths with one source parse, preserving path order. */
10
+ export declare function jsonSourceRangesAtPaths(source: string, paths: readonly ValuePath[]): JsonSourceRange[];
11
+ /** Serializes only JSON data: finite numbers, strings, booleans, null, dense arrays,
12
+ * and plain data objects. Accessors, toJSON methods, cycles and lossy coercions are rejected.
13
+ */
14
+ export declare function stringifyJsonValue(value: unknown, space?: number): string;
15
+ export interface JsonSourceDiagnostic {
16
+ /** The token belongs to an earlier duplicate property or one of its descendants. */
17
+ shadowed?: boolean;
18
+ code: 'duplicate-key' | 'unsafe-number';
19
+ sourcePath: ValuePath;
20
+ message: string;
21
+ token: string;
22
+ start: number;
23
+ end: number;
24
+ help?: import('./annotation-capabilities.js').JsonViewDiagnosticHelp;
25
+ }
26
+ /** Reads a source-preserving inspection value and identifies information JSON.parse cannot retain. */
27
+ export declare function inspectJsonSource(source: string): {
28
+ value: unknown;
29
+ diagnostics: JsonSourceDiagnostic[];
30
+ };
31
+ /** Replaces one existing JSON value while preserving every unrelated source byte. */
32
+ export declare function replaceJsonValueInSource(source: string, path: ValuePath, next: unknown): string;
33
+ /** Adds or replaces one property while preserving the surrounding JSON source. */
34
+ export declare function upsertJsonObjectPropertyInSource(source: string, objectPath: ValuePath, key: string, next: unknown): string;
35
+ /** Appends one item while preserving every byte outside the target array. */
36
+ export declare function appendJsonArrayItemInSource(source: string, arrayPath: ValuePath, next: unknown): string;
37
+ export interface JsonValueReplacement {
38
+ path: ValuePath;
39
+ value: unknown;
40
+ }
41
+ export interface JsonPropertyUpsert {
42
+ objectPath: ValuePath;
43
+ key: string;
44
+ value: unknown;
45
+ }
46
+ /** Adds/replaces properties against one source scan, preserving unrelated tokens. */
47
+ export declare function upsertJsonObjectPropertiesInSource(source: string, changes: readonly JsonPropertyUpsert[]): string;
48
+ /** Replaces independent existing values as one source-preserving document update. */
49
+ export declare function replaceJsonValuesInSource(source: string, replacements: readonly JsonValueReplacement[]): string;
50
+ /** Parses, validates, and replaces only the selected atomic token in the source. */
51
+ export declare function replaceJsonAtomicValueInSource(source: string, path: ValuePath, next: AtomicValue): string;
52
+ /** Removes one array item or object property while preserving unrelated JSON source bytes. */
53
+ export declare function removeJsonValueInSource(source: string, path: ValuePath): string;
54
+ /** Removes locations in the original source, independent of caller order.
55
+ * Duplicate locations are idempotent; ancestor/descendant plans are rejected.
56
+ * Adjacent siblings share a removal span so commas remain valid.
57
+ */
58
+ export declare function removeJsonValuesInSource(source: string, paths: readonly ValuePath[]): string;
59
+ export type JsonPatchOperation = {
60
+ op: 'add';
61
+ path: string;
62
+ value: unknown;
63
+ } | {
64
+ op: 'remove';
65
+ path: string;
66
+ } | {
67
+ op: 'replace';
68
+ path: string;
69
+ value: unknown;
70
+ } | {
71
+ op: 'move';
72
+ path: string;
73
+ from: string;
74
+ } | {
75
+ op: 'copy';
76
+ path: string;
77
+ from: string;
78
+ } | {
79
+ op: 'test';
80
+ path: string;
81
+ value: unknown;
82
+ };
83
+ export type JsonPatchErrorCode = 'invalid-document' | 'invalid-patch' | 'invalid-operation' | 'invalid-pointer' | 'missing-path' | 'invalid-array-index' | 'invalid-value' | 'test-failed' | 'move-into-descendant' | 'root-removal-not-supported';
84
+ export declare class JsonPatchError extends Error {
85
+ readonly code: JsonPatchErrorCode;
86
+ readonly path?: string;
87
+ readonly from?: string;
88
+ operationIndex?: number;
89
+ constructor(code: JsonPatchErrorCode, message: string, details?: {
90
+ path?: string;
91
+ from?: string;
92
+ operationIndex?: number;
93
+ cause?: unknown;
94
+ });
95
+ }
96
+ /** Applies an RFC 6902 JSON Patch atomically while preserving every unrelated source byte. */
97
+ export declare function applyJsonPatchInSource(source: string, patch: readonly unknown[]): string;