zarr-metadata 0.1.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 +113 -0
- package/dist/common.d.ts +35 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +10 -0
- package/dist/common.js.map +1 -0
- package/dist/errors.d.ts +88 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +80 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +39 -0
- package/dist/keys.d.ts.map +1 -0
- package/dist/keys.js +22 -0
- package/dist/keys.js.map +1 -0
- package/dist/schemas.d.ts +31 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +43 -0
- package/dist/schemas.js.map +1 -0
- package/dist/standard-schema.d.ts +65 -0
- package/dist/standard-schema.d.ts.map +1 -0
- package/dist/standard-schema.js +11 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/v2.d.ts +104 -0
- package/dist/v2.d.ts.map +1 -0
- package/dist/v2.js +41 -0
- package/dist/v2.js.map +1 -0
- package/dist/v3.d.ts +89 -0
- package/dist/v3.d.ts.map +1 -0
- package/dist/v3.js +44 -0
- package/dist/v3.js.map +1 -0
- package/dist/validation.d.ts +136 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +784 -0
- package/dist/validation.js.map +1 -0
- package/package.json +51 -0
- package/src/common.ts +39 -0
- package/src/errors.ts +142 -0
- package/src/index.ts +27 -0
- package/src/keys.ts +45 -0
- package/src/schemas.ts +96 -0
- package/src/standard-schema.ts +78 -0
- package/src/v2.ts +126 -0
- package/src/v3.ts +111 -0
- package/src/validation.ts +937 -0
package/src/v3.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zarr v3 metadata document types.
|
|
3
|
+
*
|
|
4
|
+
* See https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { JSONValue, ZarrV3MetadataFieldJSON } from "./common.js";
|
|
8
|
+
import { exactKeys, type OptionalKeysOf, type RequiredKeysOf } from "./keys.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The JSON value of an unknown top-level v3 metadata field.
|
|
12
|
+
*
|
|
13
|
+
* An object carrying the literal member `must_understand: false` may be
|
|
14
|
+
* ignored. Every other JSON shape implicitly requires understanding;
|
|
15
|
+
* recognition itself belongs to the reader rather than this structural type.
|
|
16
|
+
*/
|
|
17
|
+
export type ZarrV3ExtensionField = JSONValue;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Zarr v3 array metadata document (the `zarr.json` content for an array).
|
|
21
|
+
*
|
|
22
|
+
* Extra keys may contain arbitrary JSON values (extension fields).
|
|
23
|
+
*
|
|
24
|
+
* See https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html#array-metadata
|
|
25
|
+
*/
|
|
26
|
+
export type ZarrV3ArrayMetadataJSON = {
|
|
27
|
+
zarr_format: 3;
|
|
28
|
+
node_type: "array";
|
|
29
|
+
data_type: ZarrV3MetadataFieldJSON;
|
|
30
|
+
shape: number[];
|
|
31
|
+
chunk_grid: ZarrV3MetadataFieldJSON;
|
|
32
|
+
chunk_key_encoding: ZarrV3MetadataFieldJSON;
|
|
33
|
+
fill_value: JSONValue;
|
|
34
|
+
codecs: ZarrV3MetadataFieldJSON[];
|
|
35
|
+
attributes?: { [key: string]: JSONValue };
|
|
36
|
+
storage_transformers?: ZarrV3MetadataFieldJSON[];
|
|
37
|
+
dimension_names?: (string | null)[];
|
|
38
|
+
} & { [key: string]: JSONValue };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Zarr v3 group metadata document (the `zarr.json` content for a group).
|
|
42
|
+
*
|
|
43
|
+
* Extra keys may contain arbitrary JSON values (extension fields).
|
|
44
|
+
*
|
|
45
|
+
* See https://zarr-specs.readthedocs.io/en/latest/v3/core/index.html#group-metadata
|
|
46
|
+
*/
|
|
47
|
+
export type ZarrV3GroupMetadataJSON = {
|
|
48
|
+
zarr_format: 3;
|
|
49
|
+
node_type: "group";
|
|
50
|
+
attributes?: { [key: string]: JSONValue };
|
|
51
|
+
} & { [key: string]: JSONValue };
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Either v3 document form of `zarr.json`, discriminated by `node_type`.
|
|
55
|
+
*/
|
|
56
|
+
export type ZarrV3MetadataJSON = ZarrV3ArrayMetadataJSON | ZarrV3GroupMetadataJSON;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Inline consolidated metadata embedded in a v3 group.
|
|
60
|
+
*
|
|
61
|
+
* There is no Zarr v3 specification for consolidated metadata; this models
|
|
62
|
+
* the inline-on-group convention used by the reference Python implementation
|
|
63
|
+
* (and zarrs), where consolidated metadata is embedded as an extension field
|
|
64
|
+
* on a group's `zarr.json`.
|
|
65
|
+
*/
|
|
66
|
+
export type ZarrV3ConsolidatedMetadataJSON = {
|
|
67
|
+
kind: "inline";
|
|
68
|
+
must_understand: false;
|
|
69
|
+
metadata: { [key: string]: ZarrV3ArrayMetadataJSON | ZarrV3GroupMetadataJSON };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The store key both v3 node types persist their metadata document under.
|
|
74
|
+
* The document's `node_type` field distinguishes an array from a group.
|
|
75
|
+
*/
|
|
76
|
+
export const ZARR_V3_METADATA_STORE_KEY = "zarr.json";
|
|
77
|
+
|
|
78
|
+
/** The key under which consolidated metadata is embedded in a v3 group document. */
|
|
79
|
+
export const ZARR_V3_CONSOLIDATED_METADATA_KEY = "consolidated_metadata";
|
|
80
|
+
|
|
81
|
+
/** The standard top-level keys of a v3 array metadata document. */
|
|
82
|
+
export const ARRAY_METADATA_REQUIRED_KEYS_V3 = exactKeys<RequiredKeysOf<ZarrV3ArrayMetadataJSON>>()([
|
|
83
|
+
"zarr_format",
|
|
84
|
+
"node_type",
|
|
85
|
+
"data_type",
|
|
86
|
+
"shape",
|
|
87
|
+
"chunk_grid",
|
|
88
|
+
"chunk_key_encoding",
|
|
89
|
+
"fill_value",
|
|
90
|
+
"codecs",
|
|
91
|
+
]);
|
|
92
|
+
export const ARRAY_METADATA_OPTIONAL_KEYS_V3 = exactKeys<OptionalKeysOf<ZarrV3ArrayMetadataJSON>>()([
|
|
93
|
+
"attributes",
|
|
94
|
+
"storage_transformers",
|
|
95
|
+
"dimension_names",
|
|
96
|
+
]);
|
|
97
|
+
export const ARRAY_METADATA_STANDARD_KEYS_V3 = [
|
|
98
|
+
...ARRAY_METADATA_REQUIRED_KEYS_V3,
|
|
99
|
+
...ARRAY_METADATA_OPTIONAL_KEYS_V3,
|
|
100
|
+
] as const;
|
|
101
|
+
|
|
102
|
+
/** The standard top-level keys of a v3 group metadata document. */
|
|
103
|
+
export const GROUP_METADATA_REQUIRED_KEYS_V3 = exactKeys<RequiredKeysOf<ZarrV3GroupMetadataJSON>>()([
|
|
104
|
+
"zarr_format",
|
|
105
|
+
"node_type",
|
|
106
|
+
]);
|
|
107
|
+
export const GROUP_METADATA_OPTIONAL_KEYS_V3 = exactKeys<OptionalKeysOf<ZarrV3GroupMetadataJSON>>()(["attributes"]);
|
|
108
|
+
export const GROUP_METADATA_STANDARD_KEYS_V3 = [
|
|
109
|
+
...GROUP_METADATA_REQUIRED_KEYS_V3,
|
|
110
|
+
...GROUP_METADATA_OPTIONAL_KEYS_V3,
|
|
111
|
+
] as const;
|