@milaboratories/pl-model-common 1.13.6 → 1.13.8
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/dist/drivers/pframe/spec/spec.d.ts +18 -0
- package/dist/drivers/pframe/spec/spec.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +152 -129
- package/dist/index.mjs.map +1 -1
- package/dist/json.d.ts +19 -0
- package/dist/json.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/drivers/pframe/spec/spec.ts +34 -0
- package/src/index.ts +1 -0
- package/src/json.ts +37 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-model-common",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.8",
|
|
4
4
|
"description": "Platforma SDK Model",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,15 +19,15 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"zod": "~3.23.8",
|
|
21
21
|
"canonicalize": "~2.1.0",
|
|
22
|
-
"@milaboratories/pl-error-like": "1.12.
|
|
22
|
+
"@milaboratories/pl-error-like": "1.12.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"eslint": "^9.23.0",
|
|
26
26
|
"typescript": "~5.5.4",
|
|
27
27
|
"vite": "^5.4.11",
|
|
28
28
|
"vitest": "^2.1.8",
|
|
29
|
-
"@platforma-
|
|
30
|
-
"@
|
|
29
|
+
"@milaboratories/platforma-build-configs": "1.0.3",
|
|
30
|
+
"@platforma-sdk/eslint-config": "1.0.3"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"type-check": "tsc --noEmit --composite false",
|
|
@@ -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;
|
package/src/index.ts
CHANGED
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
|
+
}
|