industrial-model 0.6.0 → 0.7.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.
@@ -157,6 +157,57 @@ interface AggregateResult<TItem = Record<string, unknown>> {
157
157
  items: TItem[];
158
158
  }
159
159
  type AggregateExecutor<TModel> = <const TOptions extends AggregateOptions<TModel>>(options: TOptions) => Promise<AggregateResult<AggregateResultItem<TModel, TOptions["groupBy"], TOptions["aggregate"]>>>;
160
+ type RelationReferenceValue<T> = [NonNull<T>] extends [readonly unknown[]] ? NodeId[] : NodeId;
161
+ type NodeIdLike = {
162
+ space: string;
163
+ externalId: string;
164
+ };
165
+ type ArrayReferencePropertyKeys<TModel> = {
166
+ [K in keyof ModelProps<TModel>]: [NonNull<ModelProps<TModel>[K]>] extends [readonly unknown[]] ? [ArrayItem<NonNull<ModelProps<TModel>[K]>>] extends [NodeIdLike] ? K : never : never;
167
+ }[keyof ModelProps<TModel>];
168
+ type ArrayRelationKeys<TModel> = {
169
+ [K in RelationKeys<TModel>]: [NonNull<ModelRelations<TModel>[K]>] extends [readonly unknown[]] ? K : never;
170
+ }[RelationKeys<TModel>];
171
+ type UpsertProperties<TModel> = Simplify<Partial<ModelProps<TModel>> & {
172
+ [K in RelationKeys<TModel>]?: RelationReferenceValue<ModelRelations<TModel>[K]>;
173
+ }>;
174
+ type UpsertNode<TModel> = Simplify<NodeId & Partial<Omit<UpsertProperties<TModel>, keyof NodeId>>>;
175
+ interface EdgeCreationContext {
176
+ startNode: NodeId;
177
+ endNode: NodeId;
178
+ edgeType: NodeId;
179
+ }
180
+ type EdgeCreationCallback = (context: EdgeCreationContext) => NodeId;
181
+ type EdgeCreationCallbacks<TProperty extends string = string> = Partial<Record<TProperty, EdgeCreationCallback>>;
182
+ type OnEdgeCreation<TModel> = EdgeCreationCallbacks<Extract<ArrayReferencePropertyKeys<TModel> | ArrayRelationKeys<TModel>, string>>;
183
+ type EdgeMode = "append" | "replace";
184
+ interface UpsertOptions<TModel> {
185
+ viewExternalId: string;
186
+ items: UpsertNode<TModel>[];
187
+ onEdgeCreation?: OnEdgeCreation<TModel>;
188
+ replace?: boolean;
189
+ edgeMode?: EdgeMode;
190
+ }
191
+ type UpsertResultItem = {
192
+ instanceType: "node" | "edge";
193
+ version?: number;
194
+ wasModified?: boolean;
195
+ space: string;
196
+ externalId: string;
197
+ createdTime?: number;
198
+ lastUpdatedTime?: number;
199
+ };
200
+ interface UpsertResult {
201
+ items: UpsertResultItem[];
202
+ }
203
+ type UpsertExecutor<TModel> = (options: UpsertOptions<TModel>) => Promise<UpsertResult>;
204
+ type DeleteResultItem = Omit<UpsertResultItem, "instanceType"> & {
205
+ instanceType: "node";
206
+ };
207
+ interface DeleteResult {
208
+ items: DeleteResultItem[];
209
+ }
210
+ type DeleteExecutor = <TItem extends NodeId>(items: TItem[]) => Promise<DeleteResult>;
160
211
  type SearchFilter = {
161
212
  query: string;
162
213
  operator?: "OR" | "AND";
@@ -213,4 +264,4 @@ type WhereInput<TModel> = {
213
264
  [K in keyof ModelProps<TModel> | RelationKeys<TModel>]?: QueryFilterValue<TModel, K>;
214
265
  };
215
266
 
216
- export type { AggregateExecutor as A, DataModelId as D, IndustrialModelClientOptions as I, ModelProps as M, NodeId as N, QueryExecutor as Q, AggregateResult as a, AggregateResultItem as b, IndustrialModel as c, ModelRelations as d, QueryResult as e, QueryResultItem as f, QuerySelect as g, AggregateOptions as h, QueryOptions as i };
267
+ export type { AggregateExecutor as A, DataModelId as D, EdgeCreationCallback as E, IndustrialModelClientOptions as I, ModelProps as M, NodeId as N, OnEdgeCreation as O, QueryExecutor as Q, UpsertExecutor as U, DeleteResult as a, AggregateResult as b, AggregateResultItem as c, DeleteExecutor as d, DeleteResultItem as e, EdgeCreationCallbacks as f, EdgeCreationContext as g, EdgeMode as h, IndustrialModel as i, ModelRelations as j, QueryResult as k, QueryResultItem as l, QuerySelect as m, UpsertNode as n, UpsertOptions as o, UpsertProperties as p, UpsertResult as q, UpsertResultItem as r, AggregateOptions as s, QueryOptions as t };
@@ -157,6 +157,57 @@ interface AggregateResult<TItem = Record<string, unknown>> {
157
157
  items: TItem[];
158
158
  }
159
159
  type AggregateExecutor<TModel> = <const TOptions extends AggregateOptions<TModel>>(options: TOptions) => Promise<AggregateResult<AggregateResultItem<TModel, TOptions["groupBy"], TOptions["aggregate"]>>>;
160
+ type RelationReferenceValue<T> = [NonNull<T>] extends [readonly unknown[]] ? NodeId[] : NodeId;
161
+ type NodeIdLike = {
162
+ space: string;
163
+ externalId: string;
164
+ };
165
+ type ArrayReferencePropertyKeys<TModel> = {
166
+ [K in keyof ModelProps<TModel>]: [NonNull<ModelProps<TModel>[K]>] extends [readonly unknown[]] ? [ArrayItem<NonNull<ModelProps<TModel>[K]>>] extends [NodeIdLike] ? K : never : never;
167
+ }[keyof ModelProps<TModel>];
168
+ type ArrayRelationKeys<TModel> = {
169
+ [K in RelationKeys<TModel>]: [NonNull<ModelRelations<TModel>[K]>] extends [readonly unknown[]] ? K : never;
170
+ }[RelationKeys<TModel>];
171
+ type UpsertProperties<TModel> = Simplify<Partial<ModelProps<TModel>> & {
172
+ [K in RelationKeys<TModel>]?: RelationReferenceValue<ModelRelations<TModel>[K]>;
173
+ }>;
174
+ type UpsertNode<TModel> = Simplify<NodeId & Partial<Omit<UpsertProperties<TModel>, keyof NodeId>>>;
175
+ interface EdgeCreationContext {
176
+ startNode: NodeId;
177
+ endNode: NodeId;
178
+ edgeType: NodeId;
179
+ }
180
+ type EdgeCreationCallback = (context: EdgeCreationContext) => NodeId;
181
+ type EdgeCreationCallbacks<TProperty extends string = string> = Partial<Record<TProperty, EdgeCreationCallback>>;
182
+ type OnEdgeCreation<TModel> = EdgeCreationCallbacks<Extract<ArrayReferencePropertyKeys<TModel> | ArrayRelationKeys<TModel>, string>>;
183
+ type EdgeMode = "append" | "replace";
184
+ interface UpsertOptions<TModel> {
185
+ viewExternalId: string;
186
+ items: UpsertNode<TModel>[];
187
+ onEdgeCreation?: OnEdgeCreation<TModel>;
188
+ replace?: boolean;
189
+ edgeMode?: EdgeMode;
190
+ }
191
+ type UpsertResultItem = {
192
+ instanceType: "node" | "edge";
193
+ version?: number;
194
+ wasModified?: boolean;
195
+ space: string;
196
+ externalId: string;
197
+ createdTime?: number;
198
+ lastUpdatedTime?: number;
199
+ };
200
+ interface UpsertResult {
201
+ items: UpsertResultItem[];
202
+ }
203
+ type UpsertExecutor<TModel> = (options: UpsertOptions<TModel>) => Promise<UpsertResult>;
204
+ type DeleteResultItem = Omit<UpsertResultItem, "instanceType"> & {
205
+ instanceType: "node";
206
+ };
207
+ interface DeleteResult {
208
+ items: DeleteResultItem[];
209
+ }
210
+ type DeleteExecutor = <TItem extends NodeId>(items: TItem[]) => Promise<DeleteResult>;
160
211
  type SearchFilter = {
161
212
  query: string;
162
213
  operator?: "OR" | "AND";
@@ -213,4 +264,4 @@ type WhereInput<TModel> = {
213
264
  [K in keyof ModelProps<TModel> | RelationKeys<TModel>]?: QueryFilterValue<TModel, K>;
214
265
  };
215
266
 
216
- export type { AggregateExecutor as A, DataModelId as D, IndustrialModelClientOptions as I, ModelProps as M, NodeId as N, QueryExecutor as Q, AggregateResult as a, AggregateResultItem as b, IndustrialModel as c, ModelRelations as d, QueryResult as e, QueryResultItem as f, QuerySelect as g, AggregateOptions as h, QueryOptions as i };
267
+ export type { AggregateExecutor as A, DataModelId as D, EdgeCreationCallback as E, IndustrialModelClientOptions as I, ModelProps as M, NodeId as N, OnEdgeCreation as O, QueryExecutor as Q, UpsertExecutor as U, DeleteResult as a, AggregateResult as b, AggregateResultItem as c, DeleteExecutor as d, DeleteResultItem as e, EdgeCreationCallbacks as f, EdgeCreationContext as g, EdgeMode as h, IndustrialModel as i, ModelRelations as j, QueryResult as k, QueryResultItem as l, QuerySelect as m, UpsertNode as n, UpsertOptions as o, UpsertProperties as p, UpsertResult as q, UpsertResultItem as r, AggregateOptions as s, QueryOptions as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "industrial-model",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "TypeScript SDK for querying Cognite Industrial Data Models with a type-safe, graph-aware API",
5
5
  "license": "MIT",
6
6
  "keywords": [