@nicia-ai/typegraph 0.10.0 → 0.11.1
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/index.cjs +152 -123
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +152 -123
- package/dist/index.js.map +1 -1
- package/dist/interchange/index.d.cts +1 -1
- package/dist/interchange/index.d.ts +1 -1
- package/dist/profiler/index.d.cts +1 -1
- package/dist/profiler/index.d.ts +1 -1
- package/dist/{store-NE18RGqV.d.cts → store-C01_WsOg.d.cts} +27 -0
- package/dist/{store-BcFe9jJe.d.ts → store-Cy6gSNqg.d.ts} +27 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -579,6 +579,10 @@ function baseFieldBuilder(field2) {
|
|
|
579
579
|
function stringField(field2) {
|
|
580
580
|
return {
|
|
581
581
|
...baseFieldBuilder(field2),
|
|
582
|
+
gt: (value) => comparison("gt", field2, value),
|
|
583
|
+
gte: (value) => comparison("gte", field2, value),
|
|
584
|
+
lt: (value) => comparison("lt", field2, value),
|
|
585
|
+
lte: (value) => comparison("lte", field2, value),
|
|
582
586
|
contains: (pattern) => stringOp("contains", field2, pattern),
|
|
583
587
|
startsWith: (pattern) => stringOp("startsWith", field2, pattern),
|
|
584
588
|
endsWith: (pattern) => stringOp("endsWith", field2, pattern),
|
|
@@ -4936,6 +4940,10 @@ var FieldAccessTracker = class {
|
|
|
4936
4940
|
#fields = /* @__PURE__ */ new Map();
|
|
4937
4941
|
record(alias, field2, isSystemField) {
|
|
4938
4942
|
const key = `${alias}\0${field2}`;
|
|
4943
|
+
const existing = this.#fields.get(key);
|
|
4944
|
+
if (existing !== void 0 && existing.isSystemField && !isSystemField) {
|
|
4945
|
+
return;
|
|
4946
|
+
}
|
|
4939
4947
|
this.#fields.set(key, { alias, field: field2, isSystemField });
|
|
4940
4948
|
}
|
|
4941
4949
|
getAccessedFields() {
|
|
@@ -6617,6 +6625,10 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6617
6625
|
#recordOrderByFieldsForPagination(tracker) {
|
|
6618
6626
|
for (const spec of this.#state.orderBy) {
|
|
6619
6627
|
const field2 = spec.field;
|
|
6628
|
+
if (field2.path.length === 1 && field2.path[0] !== "props" && field2.jsonPointer === void 0) {
|
|
6629
|
+
tracker.record(field2.alias, field2.path[0], true);
|
|
6630
|
+
continue;
|
|
6631
|
+
}
|
|
6620
6632
|
if (field2.path.length !== 1 || field2.path[0] !== "props") {
|
|
6621
6633
|
return false;
|
|
6622
6634
|
}
|
|
@@ -6657,7 +6669,19 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6657
6669
|
const alias = spec.field.alias;
|
|
6658
6670
|
const jsonPointer2 = spec.field.jsonPointer;
|
|
6659
6671
|
if (jsonPointer2 === void 0) {
|
|
6660
|
-
|
|
6672
|
+
if (spec.field.path.length !== 1) {
|
|
6673
|
+
throw new MissingSelectiveFieldError(alias, "orderBy");
|
|
6674
|
+
}
|
|
6675
|
+
const fieldName = spec.field.path[0];
|
|
6676
|
+
const outputName2 = outputNameByAliasField.get(
|
|
6677
|
+
`${alias}\0${fieldName}`
|
|
6678
|
+
);
|
|
6679
|
+
if (outputName2 === void 0) {
|
|
6680
|
+
throw new MissingSelectiveFieldError(alias, fieldName);
|
|
6681
|
+
}
|
|
6682
|
+
const aliasObject2 = this.#getOrCreateAliasObject(cursorContext, alias);
|
|
6683
|
+
aliasObject2[fieldName] = nullToUndefined2(row[outputName2]);
|
|
6684
|
+
continue;
|
|
6661
6685
|
}
|
|
6662
6686
|
const segments = chunkP5CNM325_cjs.parseJsonPointer(jsonPointer2);
|
|
6663
6687
|
if (segments.length === 0) {
|
|
@@ -6680,14 +6704,7 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6680
6704
|
continue;
|
|
6681
6705
|
}
|
|
6682
6706
|
}
|
|
6683
|
-
|
|
6684
|
-
const existing = cursorContext[alias];
|
|
6685
|
-
if (typeof existing === "object" && existing !== null) {
|
|
6686
|
-
aliasObject = existing;
|
|
6687
|
-
} else {
|
|
6688
|
-
aliasObject = {};
|
|
6689
|
-
cursorContext[alias] = aliasObject;
|
|
6690
|
-
}
|
|
6707
|
+
const aliasObject = this.#getOrCreateAliasObject(cursorContext, alias);
|
|
6691
6708
|
const kindNames = this.#getNodeKindNamesForAlias(alias);
|
|
6692
6709
|
const typeInfo = kindNames ? this.#config.schemaIntrospector.getSharedFieldTypeInfo(
|
|
6693
6710
|
kindNames,
|
|
@@ -6714,6 +6731,15 @@ var ExecutableQuery = class _ExecutableQuery {
|
|
|
6714
6731
|
}
|
|
6715
6732
|
return cursorContext;
|
|
6716
6733
|
}
|
|
6734
|
+
#getOrCreateAliasObject(cursorContext, alias) {
|
|
6735
|
+
const existing = cursorContext[alias];
|
|
6736
|
+
if (typeof existing === "object" && existing !== null) {
|
|
6737
|
+
return existing;
|
|
6738
|
+
}
|
|
6739
|
+
const created = {};
|
|
6740
|
+
cursorContext[alias] = created;
|
|
6741
|
+
return created;
|
|
6742
|
+
}
|
|
6717
6743
|
#getNodeKindNamesForAlias(alias) {
|
|
6718
6744
|
if (alias === this.#state.startAlias) {
|
|
6719
6745
|
return this.#state.startKinds;
|
|
@@ -7541,9 +7567,12 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
7541
7567
|
* Orders results.
|
|
7542
7568
|
*/
|
|
7543
7569
|
orderBy(alias, field2, direction = "asc") {
|
|
7544
|
-
const
|
|
7545
|
-
const typeInfo =
|
|
7546
|
-
const orderSpec = {
|
|
7570
|
+
const isSystem = field2 === "id" || field2 === "kind";
|
|
7571
|
+
const typeInfo = isSystem ? void 0 : this.#getOrderByTypeInfo(alias, field2);
|
|
7572
|
+
const orderSpec = isSystem ? {
|
|
7573
|
+
field: fieldRef(alias, [field2], { valueType: "string" }),
|
|
7574
|
+
direction
|
|
7575
|
+
} : {
|
|
7547
7576
|
field: fieldRef(alias, ["props"], {
|
|
7548
7577
|
jsonPointer: chunkP5CNM325_cjs.jsonPointer([field2]),
|
|
7549
7578
|
valueType: typeInfo?.valueType,
|
|
@@ -7557,6 +7586,10 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
7557
7586
|
};
|
|
7558
7587
|
return new _QueryBuilder(this.#config, newState);
|
|
7559
7588
|
}
|
|
7589
|
+
#getOrderByTypeInfo(alias, field2) {
|
|
7590
|
+
const kindNames = this.#getKindNamesForAlias(alias);
|
|
7591
|
+
return kindNames ? this.#config.schemaIntrospector.getSharedFieldTypeInfo(kindNames, field2) : void 0;
|
|
7592
|
+
}
|
|
7560
7593
|
/**
|
|
7561
7594
|
* Limits the number of results.
|
|
7562
7595
|
*/
|
|
@@ -8267,21 +8300,29 @@ function narrowEdge(edge) {
|
|
|
8267
8300
|
function narrowEdges(edges) {
|
|
8268
8301
|
return edges;
|
|
8269
8302
|
}
|
|
8303
|
+
function buildCreateEdgeInput(kind, from, to, props, options) {
|
|
8304
|
+
const input = {
|
|
8305
|
+
kind,
|
|
8306
|
+
fromKind: from.kind,
|
|
8307
|
+
fromId: from.id,
|
|
8308
|
+
toKind: to.kind,
|
|
8309
|
+
toId: to.id,
|
|
8310
|
+
props
|
|
8311
|
+
};
|
|
8312
|
+
if (options?.id !== void 0) input.id = options.id;
|
|
8313
|
+
if (options?.validFrom !== void 0) input.validFrom = options.validFrom;
|
|
8314
|
+
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8315
|
+
return input;
|
|
8316
|
+
}
|
|
8317
|
+
function buildUpdateEdgeInput(id, props, options) {
|
|
8318
|
+
const input = { id, props };
|
|
8319
|
+
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8320
|
+
return input;
|
|
8321
|
+
}
|
|
8270
8322
|
function mapBulkEdgeInputs(kind, items) {
|
|
8271
|
-
return items.map(
|
|
8272
|
-
|
|
8273
|
-
|
|
8274
|
-
fromKind: item.from.kind,
|
|
8275
|
-
fromId: item.from.id,
|
|
8276
|
-
toKind: item.to.kind,
|
|
8277
|
-
toId: item.to.id,
|
|
8278
|
-
props: item.props ?? {}
|
|
8279
|
-
};
|
|
8280
|
-
if (item.id !== void 0) input.id = item.id;
|
|
8281
|
-
if (item.validFrom !== void 0) input.validFrom = item.validFrom;
|
|
8282
|
-
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8283
|
-
return input;
|
|
8284
|
-
});
|
|
8323
|
+
return items.map(
|
|
8324
|
+
(item) => buildCreateEdgeInput(kind, item.from, item.to, item.props ?? {}, item)
|
|
8325
|
+
);
|
|
8285
8326
|
}
|
|
8286
8327
|
function createEdgeCollection(config) {
|
|
8287
8328
|
const {
|
|
@@ -8301,18 +8342,16 @@ function createEdgeCollection(config) {
|
|
|
8301
8342
|
} = config;
|
|
8302
8343
|
return {
|
|
8303
8344
|
async create(from, to, props, options) {
|
|
8304
|
-
const
|
|
8305
|
-
|
|
8306
|
-
|
|
8307
|
-
|
|
8308
|
-
|
|
8309
|
-
|
|
8310
|
-
|
|
8311
|
-
|
|
8312
|
-
|
|
8313
|
-
|
|
8314
|
-
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8315
|
-
const result = await executeEdgeCreate2(input, backend);
|
|
8345
|
+
const result = await executeEdgeCreate2(
|
|
8346
|
+
buildCreateEdgeInput(
|
|
8347
|
+
kind,
|
|
8348
|
+
from,
|
|
8349
|
+
to,
|
|
8350
|
+
props ?? {},
|
|
8351
|
+
options
|
|
8352
|
+
),
|
|
8353
|
+
backend
|
|
8354
|
+
);
|
|
8316
8355
|
return narrowEdge(result);
|
|
8317
8356
|
},
|
|
8318
8357
|
async getById(id, options) {
|
|
@@ -8349,12 +8388,10 @@ function createEdgeCollection(config) {
|
|
|
8349
8388
|
);
|
|
8350
8389
|
},
|
|
8351
8390
|
async update(id, props, options) {
|
|
8352
|
-
const
|
|
8353
|
-
id,
|
|
8354
|
-
|
|
8355
|
-
|
|
8356
|
-
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8357
|
-
const result = await executeEdgeUpdate2(input, backend);
|
|
8391
|
+
const result = await executeEdgeUpdate2(
|
|
8392
|
+
buildUpdateEdgeInput(id, props, options),
|
|
8393
|
+
backend
|
|
8394
|
+
);
|
|
8358
8395
|
return narrowEdge(result);
|
|
8359
8396
|
},
|
|
8360
8397
|
async findFrom(from) {
|
|
@@ -8467,29 +8504,26 @@ function createEdgeCollection(config) {
|
|
|
8467
8504
|
for (const item of items) {
|
|
8468
8505
|
const existing = existingMap.get(item.id);
|
|
8469
8506
|
if (existing) {
|
|
8470
|
-
const input = {
|
|
8471
|
-
id: item.id,
|
|
8472
|
-
props: item.props
|
|
8473
|
-
};
|
|
8474
|
-
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8475
8507
|
toUpdate.push({
|
|
8476
8508
|
index: itemIndex,
|
|
8477
|
-
input
|
|
8509
|
+
input: buildUpdateEdgeInput(
|
|
8510
|
+
item.id,
|
|
8511
|
+
item.props ?? {},
|
|
8512
|
+
item
|
|
8513
|
+
),
|
|
8478
8514
|
clearDeleted: existing.deleted_at !== void 0
|
|
8479
8515
|
});
|
|
8480
8516
|
} else {
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
|
|
8487
|
-
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8492
|
-
toCreate.push({ index: itemIndex, input });
|
|
8517
|
+
toCreate.push({
|
|
8518
|
+
index: itemIndex,
|
|
8519
|
+
input: buildCreateEdgeInput(
|
|
8520
|
+
kind,
|
|
8521
|
+
item.from,
|
|
8522
|
+
item.to,
|
|
8523
|
+
item.props ?? {},
|
|
8524
|
+
item
|
|
8525
|
+
)
|
|
8526
|
+
});
|
|
8493
8527
|
}
|
|
8494
8528
|
itemIndex++;
|
|
8495
8529
|
}
|
|
@@ -8618,17 +8652,20 @@ function narrowNode(node) {
|
|
|
8618
8652
|
function narrowNodes(nodes) {
|
|
8619
8653
|
return nodes;
|
|
8620
8654
|
}
|
|
8655
|
+
function buildCreateInput(kind, props, options) {
|
|
8656
|
+
const input = { kind, props };
|
|
8657
|
+
if (options?.id !== void 0) input.id = options.id;
|
|
8658
|
+
if (options?.validFrom !== void 0) input.validFrom = options.validFrom;
|
|
8659
|
+
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8660
|
+
return input;
|
|
8661
|
+
}
|
|
8662
|
+
function buildUpdateInput(kind, id, props, options) {
|
|
8663
|
+
const input = { kind, id, props };
|
|
8664
|
+
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8665
|
+
return input;
|
|
8666
|
+
}
|
|
8621
8667
|
function mapBulkNodeInputs(kind, items) {
|
|
8622
|
-
return items.map((item) =>
|
|
8623
|
-
const input = {
|
|
8624
|
-
kind,
|
|
8625
|
-
props: item.props
|
|
8626
|
-
};
|
|
8627
|
-
if (item.id !== void 0) input.id = item.id;
|
|
8628
|
-
if (item.validFrom !== void 0) input.validFrom = item.validFrom;
|
|
8629
|
-
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8630
|
-
return input;
|
|
8631
|
-
});
|
|
8668
|
+
return items.map((item) => buildCreateInput(kind, item.props, item));
|
|
8632
8669
|
}
|
|
8633
8670
|
function createNodeCollection(config) {
|
|
8634
8671
|
const {
|
|
@@ -8653,14 +8690,13 @@ function createNodeCollection(config) {
|
|
|
8653
8690
|
} = config;
|
|
8654
8691
|
return {
|
|
8655
8692
|
async create(props, options) {
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
const result = await executeNodeCreate2(input, backend);
|
|
8693
|
+
return this.createFromRecord(props, options);
|
|
8694
|
+
},
|
|
8695
|
+
async createFromRecord(data, options) {
|
|
8696
|
+
const result = await executeNodeCreate2(
|
|
8697
|
+
buildCreateInput(kind, data, options),
|
|
8698
|
+
backend
|
|
8699
|
+
);
|
|
8664
8700
|
return narrowNode(result);
|
|
8665
8701
|
},
|
|
8666
8702
|
async getById(id, options) {
|
|
@@ -8698,13 +8734,10 @@ function createNodeCollection(config) {
|
|
|
8698
8734
|
);
|
|
8699
8735
|
},
|
|
8700
8736
|
async update(id, props, options) {
|
|
8701
|
-
const
|
|
8702
|
-
kind,
|
|
8703
|
-
|
|
8704
|
-
|
|
8705
|
-
};
|
|
8706
|
-
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8707
|
-
const result = await executeNodeUpdate2(input, backend);
|
|
8737
|
+
const result = await executeNodeUpdate2(
|
|
8738
|
+
buildUpdateInput(kind, id, props, options),
|
|
8739
|
+
backend
|
|
8740
|
+
);
|
|
8708
8741
|
return narrowNode(result);
|
|
8709
8742
|
},
|
|
8710
8743
|
async delete(id) {
|
|
@@ -8760,31 +8793,28 @@ function createNodeCollection(config) {
|
|
|
8760
8793
|
return backend.countNodesByKind(params);
|
|
8761
8794
|
},
|
|
8762
8795
|
async upsertById(id, props, options) {
|
|
8796
|
+
return this.upsertByIdFromRecord(
|
|
8797
|
+
id,
|
|
8798
|
+
props,
|
|
8799
|
+
options
|
|
8800
|
+
);
|
|
8801
|
+
},
|
|
8802
|
+
async upsertByIdFromRecord(id, data, options) {
|
|
8763
8803
|
const existing = await backend.getNode(graphId, kind, id);
|
|
8764
8804
|
if (existing) {
|
|
8765
|
-
const input = {
|
|
8766
|
-
kind,
|
|
8767
|
-
id,
|
|
8768
|
-
props
|
|
8769
|
-
};
|
|
8770
|
-
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8771
8805
|
const clearDeleted = existing.deleted_at !== void 0;
|
|
8772
|
-
const
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
kind,
|
|
8779
|
-
id,
|
|
8780
|
-
props
|
|
8781
|
-
};
|
|
8782
|
-
if (options?.validFrom !== void 0)
|
|
8783
|
-
input.validFrom = options.validFrom;
|
|
8784
|
-
if (options?.validTo !== void 0) input.validTo = options.validTo;
|
|
8785
|
-
const result = await executeNodeCreate2(input, backend);
|
|
8786
|
-
return narrowNode(result);
|
|
8806
|
+
const result2 = await executeNodeUpdate2(
|
|
8807
|
+
buildUpdateInput(kind, id, data, options),
|
|
8808
|
+
backend,
|
|
8809
|
+
{ clearDeleted }
|
|
8810
|
+
);
|
|
8811
|
+
return narrowNode(result2);
|
|
8787
8812
|
}
|
|
8813
|
+
const result = await executeNodeCreate2(
|
|
8814
|
+
buildCreateInput(kind, data, { ...options, id }),
|
|
8815
|
+
backend
|
|
8816
|
+
);
|
|
8817
|
+
return narrowNode(result);
|
|
8788
8818
|
},
|
|
8789
8819
|
async bulkCreate(items) {
|
|
8790
8820
|
const batchInputs = mapBulkNodeInputs(
|
|
@@ -8828,26 +8858,25 @@ function createNodeCollection(config) {
|
|
|
8828
8858
|
for (const item of items) {
|
|
8829
8859
|
const existing = existingMap.get(item.id);
|
|
8830
8860
|
if (existing) {
|
|
8831
|
-
const input = {
|
|
8832
|
-
kind,
|
|
8833
|
-
id: item.id,
|
|
8834
|
-
props: item.props
|
|
8835
|
-
};
|
|
8836
|
-
if (item.validTo !== void 0) input.validTo = item.validTo;
|
|
8837
8861
|
toUpdate.push({
|
|
8838
8862
|
index: itemIndex,
|
|
8839
|
-
input
|
|
8863
|
+
input: buildUpdateInput(
|
|
8864
|
+
kind,
|
|
8865
|
+
item.id,
|
|
8866
|
+
item.props,
|
|
8867
|
+
item
|
|
8868
|
+
),
|
|
8840
8869
|
clearDeleted: existing.deleted_at !== void 0
|
|
8841
8870
|
});
|
|
8842
8871
|
} else {
|
|
8843
|
-
|
|
8844
|
-
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8872
|
+
toCreate.push({
|
|
8873
|
+
index: itemIndex,
|
|
8874
|
+
input: buildCreateInput(
|
|
8875
|
+
kind,
|
|
8876
|
+
item.props,
|
|
8877
|
+
item
|
|
8878
|
+
)
|
|
8879
|
+
});
|
|
8851
8880
|
}
|
|
8852
8881
|
itemIndex++;
|
|
8853
8882
|
}
|