@milaboratories/pl-model-common 1.13.5 → 1.13.7

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.
@@ -104,6 +104,40 @@ export interface PDataColumnSpec extends PUniversalColumnSpec {
104
104
  // @todo: change this to PUniversalColumnSpec
105
105
  export type PColumnSpec = PDataColumnSpec;
106
106
 
107
+ /** Unique PColumnSpec identifier */
108
+ export type PColumnSpecId = {
109
+ /** Defines specific type of BObject, the most generic type of unit of
110
+ * information in Platforma Project. */
111
+ readonly kind: 'PColumn';
112
+
113
+ /** Type of column values */
114
+ readonly valueType: ValueType;
115
+
116
+ /** Column name */
117
+ readonly name: string;
118
+
119
+ /** Adds auxiliary information to the axis name, type and parents to form a
120
+ * unique identifier */
121
+ readonly domain?: Record<string, string>;
122
+
123
+ /** A list of zero-based indices of parent axes from the {@link axesSpec} array. */
124
+ readonly parentAxes?: number[];
125
+
126
+ /** Axes id */
127
+ readonly axesId: AxesId;
128
+ };
129
+
130
+ export function getPColumnSpecId(spec: PColumnSpec): PColumnSpecId {
131
+ return {
132
+ kind: spec.kind,
133
+ valueType: spec.valueType,
134
+ name: spec.name,
135
+ domain: spec.domain,
136
+ parentAxes: spec.parentAxes,
137
+ axesId: getAxesId(spec.axesSpec),
138
+ };
139
+ }
140
+
107
141
  export interface PColumn<Data> extends PObject<Data> {
108
142
  /** PColumn spec, allowing it to be found among other PObjects */
109
143
  readonly spec: PColumnSpec;
@@ -119,6 +153,14 @@ export interface PColumnIdAndSpec {
119
153
  readonly spec: PColumnSpec;
120
154
  }
121
155
 
156
+ /** Get column id and spec from a column */
157
+ export function getColumnIdAndSpec<Data>(column: PColumn<Data>): PColumnIdAndSpec {
158
+ return {
159
+ columnId: column.id,
160
+ spec: column.spec,
161
+ };
162
+ }
163
+
122
164
  /** Information returned by {@link PFrame.listColumns} method */
123
165
  export interface PColumnInfo extends PColumnIdAndSpec {
124
166
  /** True if data was associated with this PColumn */
package/src/index.ts CHANGED
@@ -9,3 +9,4 @@ export * from './common_types';
9
9
  export * from './pool';
10
10
  export * from './value_or_error';
11
11
  export * from './plid';
12
+ export * from './json';
package/src/json.ts ADDED
@@ -0,0 +1,37 @@
1
+ import canonicalize from 'canonicalize';
2
+
3
+ type JsonPrimitive = string | number | boolean | null | undefined;
4
+
5
+ type JsonValue = JsonPrimitive | JsonValue[] | {
6
+ [key: string]: JsonValue;
7
+ };
8
+
9
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
10
+ type NotAssignableToJson = bigint | symbol | Function;
11
+
12
+ type JsonCompatible<T> = unknown extends T ? never : {
13
+ [P in keyof T]:
14
+ T[P] extends JsonValue ? T[P] :
15
+ T[P] extends NotAssignableToJson ? never :
16
+ JsonCompatible<T[P]>;
17
+ };
18
+
19
+ export type StringifiedJson<T> = JsonCompatible<T> extends never ? never : string & {
20
+ __json_stringified: T;
21
+ };
22
+
23
+ export function stringifyJson<T>(value: JsonCompatible<T>): StringifiedJson<T> {
24
+ return JSON.stringify(value)! as StringifiedJson<T>;
25
+ }
26
+
27
+ export type CanonicalizedJson<T> = JsonCompatible<T> extends never ? never : string & {
28
+ __json_canonicalized: T;
29
+ };
30
+
31
+ export function canonicalizeJson<T>(value: JsonCompatible<T>): CanonicalizedJson<T> {
32
+ return canonicalize(value)! as CanonicalizedJson<T>;
33
+ }
34
+
35
+ export function parseJson<T>(value: StringifiedJson<T> | CanonicalizedJson<T>): T {
36
+ return JSON.parse(value) as T;
37
+ }