@graphty/graph-format 0.0.0 → 0.2.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/LICENSE +21 -0
- package/README.md +216 -43
- package/dist/graph-format.d.ts +1 -0
- package/dist/graph-format.d.ts.map +1 -0
- package/dist/graph-format.js +15798 -0
- package/dist/graph-format.js.map +1 -0
- package/dist/src/builder/arena.d.ts +85 -0
- package/dist/src/builder/arena.d.ts.map +1 -0
- package/dist/src/builder/arena.js +154 -0
- package/dist/src/builder/arena.js.map +1 -0
- package/dist/src/builder/compact.d.ts +515 -0
- package/dist/src/builder/compact.d.ts.map +1 -0
- package/dist/src/builder/compact.js +1553 -0
- package/dist/src/builder/compact.js.map +1 -0
- package/dist/src/builder/counting-sort.d.ts +96 -0
- package/dist/src/builder/counting-sort.d.ts.map +1 -0
- package/dist/src/builder/counting-sort.js +430 -0
- package/dist/src/builder/counting-sort.js.map +1 -0
- package/dist/src/builder/freeze.d.ts +72 -0
- package/dist/src/builder/freeze.d.ts.map +1 -0
- package/dist/src/builder/freeze.js +548 -0
- package/dist/src/builder/freeze.js.map +1 -0
- package/dist/src/builder/graph-builder.d.ts +602 -0
- package/dist/src/builder/graph-builder.d.ts.map +1 -0
- package/dist/src/builder/graph-builder.js +1940 -0
- package/dist/src/builder/graph-builder.js.map +1 -0
- package/dist/src/builder/options.d.ts +16 -0
- package/dist/src/builder/options.d.ts.map +1 -0
- package/dist/src/builder/options.js +21 -0
- package/dist/src/builder/options.js.map +1 -0
- package/dist/src/columns/bitmap.d.ts +96 -0
- package/dist/src/columns/bitmap.d.ts.map +1 -0
- package/dist/src/columns/bitmap.js +184 -0
- package/dist/src/columns/bitmap.js.map +1 -0
- package/dist/src/columns/column.d.ts +220 -0
- package/dist/src/columns/column.d.ts.map +1 -0
- package/dist/src/columns/column.js +2109 -0
- package/dist/src/columns/column.js.map +1 -0
- package/dist/src/columns/dictionary.d.ts +60 -0
- package/dist/src/columns/dictionary.d.ts.map +1 -0
- package/dist/src/columns/dictionary.js +102 -0
- package/dist/src/columns/dictionary.js.map +1 -0
- package/dist/src/columns/growable.d.ts +198 -0
- package/dist/src/columns/growable.d.ts.map +1 -0
- package/dist/src/columns/growable.js +296 -0
- package/dist/src/columns/growable.js.map +1 -0
- package/dist/src/columns/infer.d.ts +121 -0
- package/dist/src/columns/infer.d.ts.map +1 -0
- package/dist/src/columns/infer.js +268 -0
- package/dist/src/columns/infer.js.map +1 -0
- package/dist/src/columns/remap.d.ts +143 -0
- package/dist/src/columns/remap.d.ts.map +1 -0
- package/dist/src/columns/remap.js +588 -0
- package/dist/src/columns/remap.js.map +1 -0
- package/dist/src/columns/table.d.ts +184 -0
- package/dist/src/columns/table.d.ts.map +1 -0
- package/dist/src/columns/table.js +485 -0
- package/dist/src/columns/table.js.map +1 -0
- package/dist/src/constants.d.ts +34 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +79 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +76 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +32 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/ids/edge-id-index.d.ts +77 -0
- package/dist/src/ids/edge-id-index.d.ts.map +1 -0
- package/dist/src/ids/edge-id-index.js +155 -0
- package/dist/src/ids/edge-id-index.js.map +1 -0
- package/dist/src/ids/node-id-map.d.ts +280 -0
- package/dist/src/ids/node-id-map.d.ts.map +1 -0
- package/dist/src/ids/node-id-map.js +1139 -0
- package/dist/src/ids/node-id-map.js.map +1 -0
- package/dist/src/ids/string-store.d.ts +219 -0
- package/dist/src/ids/string-store.d.ts.map +1 -0
- package/dist/src/ids/string-store.js +526 -0
- package/dist/src/ids/string-store.js.map +1 -0
- package/dist/src/index.d.ts +30 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +29 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/populate/from-csr.d.ts +61 -0
- package/dist/src/populate/from-csr.d.ts.map +1 -0
- package/dist/src/populate/from-csr.js +706 -0
- package/dist/src/populate/from-csr.js.map +1 -0
- package/dist/src/populate/from-edge-arrays.d.ts +51 -0
- package/dist/src/populate/from-edge-arrays.d.ts.map +1 -0
- package/dist/src/populate/from-edge-arrays.js +217 -0
- package/dist/src/populate/from-edge-arrays.js.map +1 -0
- package/dist/src/populate/from-records.d.ts +51 -0
- package/dist/src/populate/from-records.d.ts.map +1 -0
- package/dist/src/populate/from-records.js +447 -0
- package/dist/src/populate/from-records.js.map +1 -0
- package/dist/src/snapshot/derived.d.ts +211 -0
- package/dist/src/snapshot/derived.d.ts.map +1 -0
- package/dist/src/snapshot/derived.js +1254 -0
- package/dist/src/snapshot/derived.js.map +1 -0
- package/dist/src/snapshot/graph-meta.d.ts +23 -0
- package/dist/src/snapshot/graph-meta.d.ts.map +1 -0
- package/dist/src/snapshot/graph-meta.js +159 -0
- package/dist/src/snapshot/graph-meta.js.map +1 -0
- package/dist/src/snapshot/graph-snapshot.d.ts +509 -0
- package/dist/src/snapshot/graph-snapshot.d.ts.map +1 -0
- package/dist/src/snapshot/graph-snapshot.js +1247 -0
- package/dist/src/snapshot/graph-snapshot.js.map +1 -0
- package/dist/src/snapshot/hash.d.ts +90 -0
- package/dist/src/snapshot/hash.d.ts.map +1 -0
- package/dist/src/snapshot/hash.js +228 -0
- package/dist/src/snapshot/hash.js.map +1 -0
- package/dist/src/snapshot/queries.d.ts +74 -0
- package/dist/src/snapshot/queries.d.ts.map +1 -0
- package/dist/src/snapshot/queries.js +131 -0
- package/dist/src/snapshot/queries.js.map +1 -0
- package/dist/src/snapshot/validate.d.ts +192 -0
- package/dist/src/snapshot/validate.d.ts.map +1 -0
- package/dist/src/snapshot/validate.js +990 -0
- package/dist/src/snapshot/validate.js.map +1 -0
- package/dist/src/snapshot/views.d.ts +274 -0
- package/dist/src/snapshot/views.d.ts.map +1 -0
- package/dist/src/snapshot/views.js +856 -0
- package/dist/src/snapshot/views.js.map +1 -0
- package/dist/src/types/builder.d.ts +456 -0
- package/dist/src/types/builder.d.ts.map +1 -0
- package/dist/src/types/builder.js +11 -0
- package/dist/src/types/builder.js.map +1 -0
- package/dist/src/types/columns.d.ts +615 -0
- package/dist/src/types/columns.d.ts.map +1 -0
- package/dist/src/types/columns.js +14 -0
- package/dist/src/types/columns.js.map +1 -0
- package/dist/src/types/index.d.ts +14 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +11 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/internal.d.ts +172 -0
- package/dist/src/types/internal.d.ts.map +1 -0
- package/dist/src/types/internal.js +13 -0
- package/dist/src/types/internal.js.map +1 -0
- package/dist/src/types/snapshot.d.ts +801 -0
- package/dist/src/types/snapshot.d.ts.map +1 -0
- package/dist/src/types/snapshot.js +14 -0
- package/dist/src/types/snapshot.js.map +1 -0
- package/dist/src/types/wire.d.ts +196 -0
- package/dist/src/types/wire.d.ts.map +1 -0
- package/dist/src/types/wire.js +8 -0
- package/dist/src/types/wire.js.map +1 -0
- package/dist/src/util/mask.d.ts +55 -0
- package/dist/src/util/mask.d.ts.map +1 -0
- package/dist/src/util/mask.js +71 -0
- package/dist/src/util/mask.js.map +1 -0
- package/dist/src/util/options.d.ts +22 -0
- package/dist/src/util/options.d.ts.map +1 -0
- package/dist/src/util/options.js +49 -0
- package/dist/src/util/options.js.map +1 -0
- package/dist/src/util/shared-buffers.d.ts +42 -0
- package/dist/src/util/shared-buffers.d.ts.map +1 -0
- package/dist/src/util/shared-buffers.js +52 -0
- package/dist/src/util/shared-buffers.js.map +1 -0
- package/dist/src/util/typed-array.d.ts +205 -0
- package/dist/src/util/typed-array.d.ts.map +1 -0
- package/dist/src/util/typed-array.js +289 -0
- package/dist/src/util/typed-array.js.map +1 -0
- package/dist/src/wire/bytes.d.ts +69 -0
- package/dist/src/wire/bytes.d.ts.map +1 -0
- package/dist/src/wire/bytes.js +361 -0
- package/dist/src/wire/bytes.js.map +1 -0
- package/dist/src/wire/carried-views.d.ts +111 -0
- package/dist/src/wire/carried-views.d.ts.map +1 -0
- package/dist/src/wire/carried-views.js +286 -0
- package/dist/src/wire/carried-views.js.map +1 -0
- package/dist/src/wire/from-wire.d.ts +144 -0
- package/dist/src/wire/from-wire.d.ts.map +1 -0
- package/dist/src/wire/from-wire.js +1425 -0
- package/dist/src/wire/from-wire.js.map +1 -0
- package/dist/src/wire/to-wire.d.ts +171 -0
- package/dist/src/wire/to-wire.d.ts.map +1 -0
- package/dist/src/wire/to-wire.js +652 -0
- package/dist/src/wire/to-wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +72 -7
- package/src/builder/arena.ts +192 -0
- package/src/builder/compact.ts +1811 -0
- package/src/builder/counting-sort.ts +506 -0
- package/src/builder/freeze.ts +689 -0
- package/src/builder/graph-builder.ts +2264 -0
- package/src/builder/options.ts +29 -0
- package/src/columns/bitmap.ts +196 -0
- package/src/columns/column.ts +2574 -0
- package/src/columns/dictionary.ts +114 -0
- package/src/columns/growable.ts +350 -0
- package/src/columns/infer.ts +285 -0
- package/src/columns/remap.ts +663 -0
- package/src/columns/table.ts +568 -0
- package/src/constants.ts +89 -0
- package/src/errors.ts +115 -0
- package/src/ids/edge-id-index.ts +179 -0
- package/src/ids/node-id-map.ts +1340 -0
- package/src/ids/string-store.ts +589 -0
- package/src/index.ts +139 -0
- package/src/lib-resizable-array-buffer.d.ts +34 -0
- package/src/populate/from-csr.ts +802 -0
- package/src/populate/from-edge-arrays.ts +257 -0
- package/src/populate/from-records.ts +536 -0
- package/src/snapshot/derived.ts +1486 -0
- package/src/snapshot/graph-meta.ts +167 -0
- package/src/snapshot/graph-snapshot.ts +1503 -0
- package/src/snapshot/hash.ts +241 -0
- package/src/snapshot/queries.ts +136 -0
- package/src/snapshot/validate.ts +1108 -0
- package/src/snapshot/views.ts +943 -0
- package/src/types/builder.ts +480 -0
- package/src/types/columns.ts +727 -0
- package/src/types/index.ts +14 -0
- package/src/types/internal.ts +195 -0
- package/src/types/snapshot.ts +886 -0
- package/src/types/wire.ts +207 -0
- package/src/util/mask.ts +89 -0
- package/src/util/options.ts +57 -0
- package/src/util/shared-buffers.ts +56 -0
- package/src/util/typed-array.ts +371 -0
- package/src/wire/bytes.ts +440 -0
- package/src/wire/carried-views.ts +327 -0
- package/src/wire/from-wire.ts +1690 -0
- package/src/wire/to-wire.ts +755 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one resolver of graph-level metadata patches (design section 5.9), shared by the builder's
|
|
3
|
+
* `setMeta` and by `fromCsr`: a GraphMetaPatch merged over the current metadata with the type rules
|
|
4
|
+
* of every field -- strings, enums, a string list for keywords, a boolean or null for
|
|
5
|
+
* declaredMultigraph, a ColumnOrigin for weightOrigin and a JSON object for extra. A field that is
|
|
6
|
+
* `undefined` in the patch keeps the current value; `null` clears it. Every violation is
|
|
7
|
+
* E_COLUMN_TYPE with `details.field`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { resolveColumnMeta } from "../columns/column.js";
|
|
11
|
+
import { GraphFormatError } from "../errors.js";
|
|
12
|
+
import { type ColumnOrigin, type GraphMeta, type GraphMetaPatch } from "../types/index.js";
|
|
13
|
+
|
|
14
|
+
const ID_TYPES: ReadonlySet<"string" | "integer" | "mixed"> = new Set(["string", "integer", "mixed"] as const);
|
|
15
|
+
const TIME_FORMATS: ReadonlySet<"integer" | "double" | "date" | "dateTime"> = new Set([
|
|
16
|
+
"integer",
|
|
17
|
+
"double",
|
|
18
|
+
"date",
|
|
19
|
+
"dateTime",
|
|
20
|
+
] as const);
|
|
21
|
+
const TIME_REPRESENTATIONS: ReadonlySet<"interval" | "timestamp"> = new Set(["interval", "timestamp"] as const);
|
|
22
|
+
const MODES: ReadonlySet<"static" | "dynamic" | "slice"> = new Set(["static", "dynamic", "slice"] as const);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A GraphMeta with every field null / empty (design section 5.9), for producers that have no
|
|
26
|
+
* metadata and for tests.
|
|
27
|
+
*/
|
|
28
|
+
export const EMPTY_GRAPH_META: GraphMeta = Object.freeze({
|
|
29
|
+
name: null,
|
|
30
|
+
description: null,
|
|
31
|
+
creator: null,
|
|
32
|
+
created: null,
|
|
33
|
+
modified: null,
|
|
34
|
+
keywords: Object.freeze([]),
|
|
35
|
+
sourceFormat: null,
|
|
36
|
+
sourceVersion: null,
|
|
37
|
+
idType: null,
|
|
38
|
+
timeFormat: null,
|
|
39
|
+
timeRepresentation: null,
|
|
40
|
+
mode: null,
|
|
41
|
+
declaredMultigraph: null,
|
|
42
|
+
weightOrigin: null,
|
|
43
|
+
extra: Object.freeze({}),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The E_COLUMN_TYPE error for a metadata field of the wrong type.
|
|
48
|
+
* @param field - the field
|
|
49
|
+
* @param found - the value
|
|
50
|
+
* @returns the error
|
|
51
|
+
*/
|
|
52
|
+
function metaError(field: string, found: unknown): GraphFormatError {
|
|
53
|
+
return new GraphFormatError("E_COLUMN_TYPE", `meta.${field} has an unsupported value`, {
|
|
54
|
+
field,
|
|
55
|
+
found: typeof found,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An optional-string metadata field (the value is never undefined here).
|
|
61
|
+
* @param field - the field name
|
|
62
|
+
* @param value - the value
|
|
63
|
+
* @returns the string or null
|
|
64
|
+
*/
|
|
65
|
+
function metaString(field: string, value: unknown): string | null {
|
|
66
|
+
if (value === null || typeof value === "string") {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
throw metaError(field, value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* An enum-valued metadata field.
|
|
74
|
+
* @param field - the field name
|
|
75
|
+
* @param value - the value
|
|
76
|
+
* @param allowed - the legal strings
|
|
77
|
+
* @returns the value or null
|
|
78
|
+
*/
|
|
79
|
+
function metaEnum<T extends string>(field: string, value: unknown, allowed: ReadonlySet<T>): T | null {
|
|
80
|
+
if (value === null) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === "string" && allowed.has(value as T)) {
|
|
84
|
+
return value as T;
|
|
85
|
+
}
|
|
86
|
+
throw metaError(field, value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The weightOrigin field as a complete ColumnOrigin.
|
|
91
|
+
* @param value - the value
|
|
92
|
+
* @returns the origin or null
|
|
93
|
+
*/
|
|
94
|
+
function metaOrigin(value: unknown): ColumnOrigin | null {
|
|
95
|
+
if (value === null) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (typeof value !== "object") {
|
|
99
|
+
throw metaError("weightOrigin", value);
|
|
100
|
+
}
|
|
101
|
+
const input = value as Record<string, unknown>;
|
|
102
|
+
const field = (name: string): string | null => {
|
|
103
|
+
const v = input[name];
|
|
104
|
+
if (v === undefined || v === null) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
if (typeof v !== "string") {
|
|
108
|
+
throw metaError(`weightOrigin.${name}`, v);
|
|
109
|
+
}
|
|
110
|
+
return v;
|
|
111
|
+
};
|
|
112
|
+
return Object.freeze({
|
|
113
|
+
format: field("format"),
|
|
114
|
+
id: field("id"),
|
|
115
|
+
title: field("title"),
|
|
116
|
+
type: field("type"),
|
|
117
|
+
namespace: field("namespace"),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Merge a metadata patch over the current metadata (design section 5.9): undefined fields keep the
|
|
123
|
+
* current value, every other field is type-checked (E_COLUMN_TYPE with details.field).
|
|
124
|
+
* @param current - the metadata before the patch
|
|
125
|
+
* @param patch - the fields to set
|
|
126
|
+
* @returns the merged metadata, frozen
|
|
127
|
+
*/
|
|
128
|
+
export function resolveGraphMeta(current: GraphMeta, patch: GraphMetaPatch): GraphMeta {
|
|
129
|
+
const pick = <K extends keyof GraphMeta>(key: K, convert: (value: unknown) => GraphMeta[K]): GraphMeta[K] => {
|
|
130
|
+
const value = patch[key];
|
|
131
|
+
return value === undefined ? current[key] : convert(value);
|
|
132
|
+
};
|
|
133
|
+
return Object.freeze({
|
|
134
|
+
name: pick("name", (v) => metaString("name", v)),
|
|
135
|
+
description: pick("description", (v) => metaString("description", v)),
|
|
136
|
+
creator: pick("creator", (v) => metaString("creator", v)),
|
|
137
|
+
created: pick("created", (v) => metaString("created", v)),
|
|
138
|
+
modified: pick("modified", (v) => metaString("modified", v)),
|
|
139
|
+
keywords: pick("keywords", (v) => {
|
|
140
|
+
if (!Array.isArray(v) || v.some((k) => typeof k !== "string")) {
|
|
141
|
+
throw metaError("keywords", v);
|
|
142
|
+
}
|
|
143
|
+
return Object.freeze([...(v as string[])]);
|
|
144
|
+
}),
|
|
145
|
+
sourceFormat: pick("sourceFormat", (v) => metaString("sourceFormat", v)),
|
|
146
|
+
sourceVersion: pick("sourceVersion", (v) => metaString("sourceVersion", v)),
|
|
147
|
+
idType: pick("idType", (v) => metaEnum("idType", v, ID_TYPES)),
|
|
148
|
+
timeFormat: pick("timeFormat", (v) => metaEnum("timeFormat", v, TIME_FORMATS)),
|
|
149
|
+
timeRepresentation: pick("timeRepresentation", (v) => metaEnum("timeRepresentation", v, TIME_REPRESENTATIONS)),
|
|
150
|
+
mode: pick("mode", (v) => metaEnum("mode", v, MODES)),
|
|
151
|
+
declaredMultigraph: pick("declaredMultigraph", (v) => {
|
|
152
|
+
if (v === null || typeof v === "boolean") {
|
|
153
|
+
return v;
|
|
154
|
+
}
|
|
155
|
+
throw metaError("declaredMultigraph", v);
|
|
156
|
+
}),
|
|
157
|
+
weightOrigin: pick("weightOrigin", (v) => metaOrigin(v)),
|
|
158
|
+
extra: pick("extra", (v) => {
|
|
159
|
+
// the column resolver applies the JSON rules of design section 5.9 to `extra`
|
|
160
|
+
const resolved = resolveColumnMeta("meta", "graph", {
|
|
161
|
+
dtype: "json",
|
|
162
|
+
extra: v as Readonly<Record<string, unknown>>,
|
|
163
|
+
});
|
|
164
|
+
return resolved.extra;
|
|
165
|
+
}),
|
|
166
|
+
});
|
|
167
|
+
}
|