industrial-model 0.3.0 → 0.5.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/README.md +217 -2
- package/dist/index.cjs +458 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -2
- package/dist/index.d.ts +81 -2
- package/dist/index.js +458 -137
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -129,10 +129,83 @@ type QueryExecutor<TModel> = {
|
|
|
129
129
|
select?: undefined;
|
|
130
130
|
}): Promise<QueryResult<QueryResultItem<TModel, undefined>>>;
|
|
131
131
|
};
|
|
132
|
+
type GroupableValue<T> = [NonNull<T>] extends [NodeId] ? true : [NonNull<T>] extends [string | number | boolean] ? true : false;
|
|
133
|
+
type GroupByKey<TModel> = {
|
|
134
|
+
[K in keyof ModelProps<TModel>]: GroupableValue<ModelProps<TModel>[K]> extends true ? K : never;
|
|
135
|
+
}[keyof ModelProps<TModel>];
|
|
136
|
+
type AggregateGroupBy<TModel> = {
|
|
137
|
+
[K in GroupByKey<TModel>]?: true;
|
|
138
|
+
};
|
|
139
|
+
type NumericKey<TModel> = {
|
|
140
|
+
[K in keyof ModelProps<TModel>]: ModelProps<TModel>[K] extends number ? K : never;
|
|
141
|
+
}[keyof ModelProps<TModel>];
|
|
142
|
+
type CountableKey<TModel> = GroupByKey<TModel> | "externalId" | "space";
|
|
143
|
+
type AggregateDefinition<TModel> = {
|
|
144
|
+
avg: NumericKey<TModel>;
|
|
145
|
+
} | {
|
|
146
|
+
min: NumericKey<TModel>;
|
|
147
|
+
} | {
|
|
148
|
+
max: NumericKey<TModel>;
|
|
149
|
+
} | {
|
|
150
|
+
sum: NumericKey<TModel>;
|
|
151
|
+
} | {
|
|
152
|
+
count: CountableKey<TModel> | Record<string, never>;
|
|
153
|
+
};
|
|
154
|
+
type SelectedGroupKeys<TGroupBy> = Extract<{
|
|
155
|
+
[K in keyof TGroupBy & string]: TGroupBy[K] extends true ? K : never;
|
|
156
|
+
}[keyof TGroupBy & string], string>;
|
|
157
|
+
type GroupValues<TModel, TGroupBy extends AggregateGroupBy<TModel> | undefined> = TGroupBy extends AggregateGroupBy<TModel> ? Simplify<Pick<ModelProps<TModel>, SelectedGroupKeys<TGroupBy> & keyof ModelProps<TModel>>> : undefined;
|
|
158
|
+
type AggregateValue<TDef> = TDef extends {
|
|
159
|
+
avg: infer P extends PropertyKey;
|
|
160
|
+
} ? {
|
|
161
|
+
property: P;
|
|
162
|
+
value: number;
|
|
163
|
+
} : TDef extends {
|
|
164
|
+
min: infer P extends PropertyKey;
|
|
165
|
+
} ? {
|
|
166
|
+
property: P;
|
|
167
|
+
value: number;
|
|
168
|
+
} : TDef extends {
|
|
169
|
+
max: infer P extends PropertyKey;
|
|
170
|
+
} ? {
|
|
171
|
+
property: P;
|
|
172
|
+
value: number;
|
|
173
|
+
} : TDef extends {
|
|
174
|
+
sum: infer P extends PropertyKey;
|
|
175
|
+
} ? {
|
|
176
|
+
property: P;
|
|
177
|
+
value: number;
|
|
178
|
+
} : TDef extends {
|
|
179
|
+
count: infer P;
|
|
180
|
+
} ? Record<string, never> extends P ? {
|
|
181
|
+
value: number;
|
|
182
|
+
} : {
|
|
183
|
+
property: P;
|
|
184
|
+
value: number;
|
|
185
|
+
} : never;
|
|
186
|
+
interface AggregateOptions<TModel> {
|
|
187
|
+
viewExternalId: string;
|
|
188
|
+
filters?: WhereInput<TModel>;
|
|
189
|
+
groupBy?: AggregateGroupBy<TModel>;
|
|
190
|
+
aggregate?: AggregateDefinition<TModel>;
|
|
191
|
+
}
|
|
192
|
+
type AggregateResultItem<TModel, TGroupBy extends AggregateGroupBy<TModel> | undefined = undefined, TAggregate extends AggregateDefinition<TModel> | undefined = undefined> = {
|
|
193
|
+
group?: GroupValues<TModel, TGroupBy>;
|
|
194
|
+
aggregate?: AggregateValue<TAggregate>;
|
|
195
|
+
};
|
|
196
|
+
interface AggregateResult<TItem = Record<string, unknown>> {
|
|
197
|
+
items: TItem[];
|
|
198
|
+
}
|
|
199
|
+
type AggregateExecutor<TModel> = <const TOptions extends AggregateOptions<TModel>>(options: TOptions) => Promise<AggregateResult<AggregateResultItem<TModel, TOptions["groupBy"], TOptions["aggregate"]>>>;
|
|
200
|
+
type SearchFilter = {
|
|
201
|
+
query: string;
|
|
202
|
+
operator?: "OR" | "AND";
|
|
203
|
+
};
|
|
132
204
|
type StringFilters = {
|
|
133
205
|
eq?: string;
|
|
134
206
|
in?: string[];
|
|
135
207
|
prefix?: string;
|
|
208
|
+
search?: SearchFilter;
|
|
136
209
|
exists?: boolean;
|
|
137
210
|
};
|
|
138
211
|
type NumberFilters = {
|
|
@@ -166,7 +239,9 @@ type ListFilters<T> = {
|
|
|
166
239
|
containsAny?: T[];
|
|
167
240
|
containsAll?: T[];
|
|
168
241
|
exists?: boolean;
|
|
169
|
-
}
|
|
242
|
+
} & (T extends string ? {
|
|
243
|
+
search?: SearchFilter;
|
|
244
|
+
} : unknown);
|
|
170
245
|
type BaseFilterFor<T> = T extends NodeId ? NodeIdFilters : T extends string ? StringFilters : T extends number ? NumberFilters : T extends boolean ? BooleanFilters : T extends Date ? DateFilters : T extends Array<infer U> ? ListFilters<U> : T extends object ? NodeIdFilters | WhereInput<T> : never;
|
|
171
246
|
type RelationFilterFor<T> = UnwrapRelationTarget<T> extends object ? WhereInput<UnwrapRelationTarget<T>> : never;
|
|
172
247
|
type QueryFilterValue<TModel, K extends PropertyKey> = K extends RelationKeys<TModel> ? K extends keyof ModelProps<TModel> ? BaseFilterFor<ModelProps<TModel>[K]> | RelationFilterFor<ModelRelations<TModel>[K]> : RelationFilterFor<ModelRelations<TModel>[K]> : K extends keyof ModelProps<TModel> ? BaseFilterFor<ModelProps<TModel>[K]> : never;
|
|
@@ -181,11 +256,15 @@ type WhereInput<TModel> = {
|
|
|
181
256
|
declare class IndustrialModelClient {
|
|
182
257
|
private readonly cognite;
|
|
183
258
|
private readonly queryMapper;
|
|
259
|
+
private readonly aggregateMapper;
|
|
260
|
+
private readonly aggregateResultMapper;
|
|
184
261
|
private readonly resultMapper;
|
|
185
262
|
private readonly resultValidator;
|
|
186
263
|
private readonly validateResults;
|
|
187
264
|
constructor(client: CogniteClient, dataModelId: DataModelId, options?: IndustrialModelClientOptions);
|
|
188
265
|
query<TModel>(): QueryExecutor<TModel>;
|
|
266
|
+
aggregate<TModel>(): AggregateExecutor<TModel>;
|
|
267
|
+
private aggregateInternal;
|
|
189
268
|
private queryInternal;
|
|
190
269
|
private queryDependenciesPages;
|
|
191
270
|
}
|
|
@@ -199,4 +278,4 @@ declare const nodeIdSchema: z.ZodObject<{
|
|
|
199
278
|
}, z.core.$strip>;
|
|
200
279
|
declare function buildViewSchema(view: ViewDefinition, options?: BuildViewSchemaOptions): z.ZodObject<Record<string, z.ZodType>>;
|
|
201
280
|
|
|
202
|
-
export { type BuildViewSchemaOptions, type DataModelId, type IndustrialModel, IndustrialModelClient, type IndustrialModelClientOptions, type ModelProps, type ModelRelations, type NodeId, type QueryOptions, type QueryResult, type QueryResultItem, type QueryResultMetadata, type QuerySelect, buildViewSchema, nodeIdSchema };
|
|
281
|
+
export { type AggregateDefinition, type AggregateGroupBy, type AggregateOptions, type AggregateResult, type AggregateResultItem, type BuildViewSchemaOptions, type DataModelId, type GroupByKey, type IndustrialModel, IndustrialModelClient, type IndustrialModelClientOptions, type ModelProps, type ModelRelations, type NodeId, type QueryOptions, type QueryResult, type QueryResultItem, type QueryResultMetadata, type QuerySelect, buildViewSchema, nodeIdSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -129,10 +129,83 @@ type QueryExecutor<TModel> = {
|
|
|
129
129
|
select?: undefined;
|
|
130
130
|
}): Promise<QueryResult<QueryResultItem<TModel, undefined>>>;
|
|
131
131
|
};
|
|
132
|
+
type GroupableValue<T> = [NonNull<T>] extends [NodeId] ? true : [NonNull<T>] extends [string | number | boolean] ? true : false;
|
|
133
|
+
type GroupByKey<TModel> = {
|
|
134
|
+
[K in keyof ModelProps<TModel>]: GroupableValue<ModelProps<TModel>[K]> extends true ? K : never;
|
|
135
|
+
}[keyof ModelProps<TModel>];
|
|
136
|
+
type AggregateGroupBy<TModel> = {
|
|
137
|
+
[K in GroupByKey<TModel>]?: true;
|
|
138
|
+
};
|
|
139
|
+
type NumericKey<TModel> = {
|
|
140
|
+
[K in keyof ModelProps<TModel>]: ModelProps<TModel>[K] extends number ? K : never;
|
|
141
|
+
}[keyof ModelProps<TModel>];
|
|
142
|
+
type CountableKey<TModel> = GroupByKey<TModel> | "externalId" | "space";
|
|
143
|
+
type AggregateDefinition<TModel> = {
|
|
144
|
+
avg: NumericKey<TModel>;
|
|
145
|
+
} | {
|
|
146
|
+
min: NumericKey<TModel>;
|
|
147
|
+
} | {
|
|
148
|
+
max: NumericKey<TModel>;
|
|
149
|
+
} | {
|
|
150
|
+
sum: NumericKey<TModel>;
|
|
151
|
+
} | {
|
|
152
|
+
count: CountableKey<TModel> | Record<string, never>;
|
|
153
|
+
};
|
|
154
|
+
type SelectedGroupKeys<TGroupBy> = Extract<{
|
|
155
|
+
[K in keyof TGroupBy & string]: TGroupBy[K] extends true ? K : never;
|
|
156
|
+
}[keyof TGroupBy & string], string>;
|
|
157
|
+
type GroupValues<TModel, TGroupBy extends AggregateGroupBy<TModel> | undefined> = TGroupBy extends AggregateGroupBy<TModel> ? Simplify<Pick<ModelProps<TModel>, SelectedGroupKeys<TGroupBy> & keyof ModelProps<TModel>>> : undefined;
|
|
158
|
+
type AggregateValue<TDef> = TDef extends {
|
|
159
|
+
avg: infer P extends PropertyKey;
|
|
160
|
+
} ? {
|
|
161
|
+
property: P;
|
|
162
|
+
value: number;
|
|
163
|
+
} : TDef extends {
|
|
164
|
+
min: infer P extends PropertyKey;
|
|
165
|
+
} ? {
|
|
166
|
+
property: P;
|
|
167
|
+
value: number;
|
|
168
|
+
} : TDef extends {
|
|
169
|
+
max: infer P extends PropertyKey;
|
|
170
|
+
} ? {
|
|
171
|
+
property: P;
|
|
172
|
+
value: number;
|
|
173
|
+
} : TDef extends {
|
|
174
|
+
sum: infer P extends PropertyKey;
|
|
175
|
+
} ? {
|
|
176
|
+
property: P;
|
|
177
|
+
value: number;
|
|
178
|
+
} : TDef extends {
|
|
179
|
+
count: infer P;
|
|
180
|
+
} ? Record<string, never> extends P ? {
|
|
181
|
+
value: number;
|
|
182
|
+
} : {
|
|
183
|
+
property: P;
|
|
184
|
+
value: number;
|
|
185
|
+
} : never;
|
|
186
|
+
interface AggregateOptions<TModel> {
|
|
187
|
+
viewExternalId: string;
|
|
188
|
+
filters?: WhereInput<TModel>;
|
|
189
|
+
groupBy?: AggregateGroupBy<TModel>;
|
|
190
|
+
aggregate?: AggregateDefinition<TModel>;
|
|
191
|
+
}
|
|
192
|
+
type AggregateResultItem<TModel, TGroupBy extends AggregateGroupBy<TModel> | undefined = undefined, TAggregate extends AggregateDefinition<TModel> | undefined = undefined> = {
|
|
193
|
+
group?: GroupValues<TModel, TGroupBy>;
|
|
194
|
+
aggregate?: AggregateValue<TAggregate>;
|
|
195
|
+
};
|
|
196
|
+
interface AggregateResult<TItem = Record<string, unknown>> {
|
|
197
|
+
items: TItem[];
|
|
198
|
+
}
|
|
199
|
+
type AggregateExecutor<TModel> = <const TOptions extends AggregateOptions<TModel>>(options: TOptions) => Promise<AggregateResult<AggregateResultItem<TModel, TOptions["groupBy"], TOptions["aggregate"]>>>;
|
|
200
|
+
type SearchFilter = {
|
|
201
|
+
query: string;
|
|
202
|
+
operator?: "OR" | "AND";
|
|
203
|
+
};
|
|
132
204
|
type StringFilters = {
|
|
133
205
|
eq?: string;
|
|
134
206
|
in?: string[];
|
|
135
207
|
prefix?: string;
|
|
208
|
+
search?: SearchFilter;
|
|
136
209
|
exists?: boolean;
|
|
137
210
|
};
|
|
138
211
|
type NumberFilters = {
|
|
@@ -166,7 +239,9 @@ type ListFilters<T> = {
|
|
|
166
239
|
containsAny?: T[];
|
|
167
240
|
containsAll?: T[];
|
|
168
241
|
exists?: boolean;
|
|
169
|
-
}
|
|
242
|
+
} & (T extends string ? {
|
|
243
|
+
search?: SearchFilter;
|
|
244
|
+
} : unknown);
|
|
170
245
|
type BaseFilterFor<T> = T extends NodeId ? NodeIdFilters : T extends string ? StringFilters : T extends number ? NumberFilters : T extends boolean ? BooleanFilters : T extends Date ? DateFilters : T extends Array<infer U> ? ListFilters<U> : T extends object ? NodeIdFilters | WhereInput<T> : never;
|
|
171
246
|
type RelationFilterFor<T> = UnwrapRelationTarget<T> extends object ? WhereInput<UnwrapRelationTarget<T>> : never;
|
|
172
247
|
type QueryFilterValue<TModel, K extends PropertyKey> = K extends RelationKeys<TModel> ? K extends keyof ModelProps<TModel> ? BaseFilterFor<ModelProps<TModel>[K]> | RelationFilterFor<ModelRelations<TModel>[K]> : RelationFilterFor<ModelRelations<TModel>[K]> : K extends keyof ModelProps<TModel> ? BaseFilterFor<ModelProps<TModel>[K]> : never;
|
|
@@ -181,11 +256,15 @@ type WhereInput<TModel> = {
|
|
|
181
256
|
declare class IndustrialModelClient {
|
|
182
257
|
private readonly cognite;
|
|
183
258
|
private readonly queryMapper;
|
|
259
|
+
private readonly aggregateMapper;
|
|
260
|
+
private readonly aggregateResultMapper;
|
|
184
261
|
private readonly resultMapper;
|
|
185
262
|
private readonly resultValidator;
|
|
186
263
|
private readonly validateResults;
|
|
187
264
|
constructor(client: CogniteClient, dataModelId: DataModelId, options?: IndustrialModelClientOptions);
|
|
188
265
|
query<TModel>(): QueryExecutor<TModel>;
|
|
266
|
+
aggregate<TModel>(): AggregateExecutor<TModel>;
|
|
267
|
+
private aggregateInternal;
|
|
189
268
|
private queryInternal;
|
|
190
269
|
private queryDependenciesPages;
|
|
191
270
|
}
|
|
@@ -199,4 +278,4 @@ declare const nodeIdSchema: z.ZodObject<{
|
|
|
199
278
|
}, z.core.$strip>;
|
|
200
279
|
declare function buildViewSchema(view: ViewDefinition, options?: BuildViewSchemaOptions): z.ZodObject<Record<string, z.ZodType>>;
|
|
201
280
|
|
|
202
|
-
export { type BuildViewSchemaOptions, type DataModelId, type IndustrialModel, IndustrialModelClient, type IndustrialModelClientOptions, type ModelProps, type ModelRelations, type NodeId, type QueryOptions, type QueryResult, type QueryResultItem, type QueryResultMetadata, type QuerySelect, buildViewSchema, nodeIdSchema };
|
|
281
|
+
export { type AggregateDefinition, type AggregateGroupBy, type AggregateOptions, type AggregateResult, type AggregateResultItem, type BuildViewSchemaOptions, type DataModelId, type GroupByKey, type IndustrialModel, IndustrialModelClient, type IndustrialModelClientOptions, type ModelProps, type ModelRelations, type NodeId, type QueryOptions, type QueryResult, type QueryResultItem, type QueryResultMetadata, type QuerySelect, buildViewSchema, nodeIdSchema };
|