@nicia-ai/typegraph 0.4.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/dist/backend/drizzle/index.cjs +5 -5
- package/dist/backend/drizzle/index.d.cts +1 -1
- package/dist/backend/drizzle/index.d.ts +1 -1
- package/dist/backend/drizzle/index.js +3 -3
- package/dist/backend/drizzle/postgres.cjs +3 -3
- package/dist/backend/drizzle/postgres.d.cts +1 -1
- package/dist/backend/drizzle/postgres.d.ts +1 -1
- package/dist/backend/drizzle/postgres.js +2 -2
- package/dist/backend/drizzle/sqlite.cjs +3 -3
- package/dist/backend/drizzle/sqlite.d.cts +1 -1
- package/dist/backend/drizzle/sqlite.d.ts +1 -1
- package/dist/backend/drizzle/sqlite.js +2 -2
- package/dist/backend/postgres/index.cjs +3 -3
- package/dist/backend/postgres/index.d.cts +1 -1
- package/dist/backend/postgres/index.d.ts +1 -1
- package/dist/backend/postgres/index.js +2 -2
- package/dist/backend/sqlite/index.cjs +4 -4
- package/dist/backend/sqlite/index.d.cts +1 -1
- package/dist/backend/sqlite/index.d.ts +1 -1
- package/dist/backend/sqlite/index.js +3 -3
- package/dist/{chunk-ZO2FRJ2U.js → chunk-4MTYE6CF.js} +3 -3
- package/dist/{chunk-ZO2FRJ2U.js.map → chunk-4MTYE6CF.js.map} +1 -1
- package/dist/{chunk-ZQGOBVXZ.js → chunk-6HFWKZU5.js} +20 -2
- package/dist/chunk-6HFWKZU5.js.map +1 -0
- package/dist/{chunk-LUARLSYT.cjs → chunk-ENXM4W4M.cjs} +18 -18
- package/dist/{chunk-LUARLSYT.cjs.map → chunk-ENXM4W4M.cjs.map} +1 -1
- package/dist/{chunk-Q6PXIKRQ.js → chunk-KKFJJYCP.js} +3 -3
- package/dist/{chunk-Q6PXIKRQ.js.map → chunk-KKFJJYCP.js.map} +1 -1
- package/dist/{chunk-NYDXJGA3.cjs → chunk-KPU6TLUV.cjs} +14 -14
- package/dist/{chunk-NYDXJGA3.cjs.map → chunk-KPU6TLUV.cjs.map} +1 -1
- package/dist/{chunk-7RVSDXT3.cjs → chunk-PW5BSBZV.cjs} +20 -2
- package/dist/chunk-PW5BSBZV.cjs.map +1 -0
- package/dist/index.cjs +238 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +238 -1
- package/dist/index.js.map +1 -1
- package/dist/interchange/index.d.cts +3 -3
- package/dist/interchange/index.d.ts +3 -3
- package/dist/{manager-DFKe7ql3.d.ts → manager-DXC7CqKG.d.ts} +1 -1
- package/dist/{manager-0NysX4s6.d.cts → manager-DiPf-0GG.d.cts} +1 -1
- package/dist/profiler/index.d.cts +3 -3
- package/dist/profiler/index.d.ts +3 -3
- package/dist/schema/index.d.cts +4 -4
- package/dist/schema/index.d.ts +4 -4
- package/dist/{store-SiovWEYA.d.ts → store-DODIWZxC.d.ts} +55 -3
- package/dist/{store-DhoA5uRc.d.cts → store-nDW3GOFb.d.cts} +55 -3
- package/dist/{types-6EKrWTs9.d.ts → types-DpIoePMI.d.ts} +5 -0
- package/dist/{types-BUy-pHKH.d.cts → types-WX8V9dqn.d.cts} +5 -0
- package/package.json +1 -1
- package/dist/chunk-7RVSDXT3.cjs.map +0 -1
- package/dist/chunk-ZQGOBVXZ.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -8547,6 +8547,23 @@ function createEdgeCollection(config) {
|
|
|
8547
8547
|
}
|
|
8548
8548
|
await deleteAll(backend);
|
|
8549
8549
|
},
|
|
8550
|
+
async findByEndpoints(from, to, options) {
|
|
8551
|
+
const findOptions = {};
|
|
8552
|
+
if (options?.matchOn !== void 0)
|
|
8553
|
+
findOptions.matchOn = options.matchOn;
|
|
8554
|
+
if (options?.props !== void 0)
|
|
8555
|
+
findOptions.props = options.props;
|
|
8556
|
+
const result = await config.executeFindByEndpoints(
|
|
8557
|
+
kind,
|
|
8558
|
+
from.kind,
|
|
8559
|
+
from.id,
|
|
8560
|
+
to.kind,
|
|
8561
|
+
to.id,
|
|
8562
|
+
backend,
|
|
8563
|
+
findOptions
|
|
8564
|
+
);
|
|
8565
|
+
return result === void 0 ? void 0 : narrowEdge(result);
|
|
8566
|
+
},
|
|
8550
8567
|
async getOrCreateByEndpoints(from, to, props, options) {
|
|
8551
8568
|
const getOrCreateOptions = {};
|
|
8552
8569
|
if (options?.matchOn !== void 0)
|
|
@@ -8637,7 +8654,9 @@ function createNodeCollection(config) {
|
|
|
8637
8654
|
matchesTemporalMode,
|
|
8638
8655
|
createQuery,
|
|
8639
8656
|
executeGetOrCreateByConstraint,
|
|
8640
|
-
executeBulkGetOrCreateByConstraint
|
|
8657
|
+
executeBulkGetOrCreateByConstraint,
|
|
8658
|
+
executeFindByConstraint,
|
|
8659
|
+
executeBulkFindByConstraint
|
|
8641
8660
|
} = config;
|
|
8642
8661
|
return {
|
|
8643
8662
|
async create(props, options) {
|
|
@@ -8886,6 +8905,30 @@ function createNodeCollection(config) {
|
|
|
8886
8905
|
}
|
|
8887
8906
|
await deleteAll(backend);
|
|
8888
8907
|
},
|
|
8908
|
+
async findByConstraint(constraintName, props) {
|
|
8909
|
+
const result = await executeFindByConstraint(
|
|
8910
|
+
kind,
|
|
8911
|
+
constraintName,
|
|
8912
|
+
props,
|
|
8913
|
+
backend
|
|
8914
|
+
);
|
|
8915
|
+
return result === void 0 ? void 0 : narrowNode(result);
|
|
8916
|
+
},
|
|
8917
|
+
async bulkFindByConstraint(constraintName, items) {
|
|
8918
|
+
if (items.length === 0) return [];
|
|
8919
|
+
const mappedItems = items.map((item) => ({
|
|
8920
|
+
props: item.props
|
|
8921
|
+
}));
|
|
8922
|
+
const results = await executeBulkFindByConstraint(
|
|
8923
|
+
kind,
|
|
8924
|
+
constraintName,
|
|
8925
|
+
mappedItems,
|
|
8926
|
+
backend
|
|
8927
|
+
);
|
|
8928
|
+
return results.map(
|
|
8929
|
+
(result) => result === void 0 ? void 0 : narrowNode(result)
|
|
8930
|
+
);
|
|
8931
|
+
},
|
|
8889
8932
|
async getOrCreateByConstraint(constraintName, props, options) {
|
|
8890
8933
|
const execute = async (target) => {
|
|
8891
8934
|
const result = await executeGetOrCreateByConstraint(
|
|
@@ -9746,6 +9789,28 @@ function findMatchingEdge(rows, matchOn, inputProps) {
|
|
|
9746
9789
|
}
|
|
9747
9790
|
return { liveRow, deletedRow };
|
|
9748
9791
|
}
|
|
9792
|
+
async function executeEdgeFindByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, backend, options) {
|
|
9793
|
+
const matchOn = options?.matchOn ?? [];
|
|
9794
|
+
const props = options?.props ?? {};
|
|
9795
|
+
const registration = getEdgeRegistration(ctx.graph, kind);
|
|
9796
|
+
const edgeKind = registration.type;
|
|
9797
|
+
if (matchOn.length > 0) {
|
|
9798
|
+
validateMatchOnFields(edgeKind.schema, matchOn, kind);
|
|
9799
|
+
}
|
|
9800
|
+
const candidateRows = await backend.findEdgesByKind({
|
|
9801
|
+
graphId: ctx.graphId,
|
|
9802
|
+
kind,
|
|
9803
|
+
fromKind,
|
|
9804
|
+
fromId,
|
|
9805
|
+
toKind,
|
|
9806
|
+
toId,
|
|
9807
|
+
excludeDeleted: true
|
|
9808
|
+
});
|
|
9809
|
+
if (candidateRows.length === 0) return void 0;
|
|
9810
|
+
if (matchOn.length === 0) return rowToEdge(candidateRows[0]);
|
|
9811
|
+
const { liveRow } = findMatchingEdge(candidateRows, matchOn, props);
|
|
9812
|
+
return liveRow === void 0 ? void 0 : rowToEdge(liveRow);
|
|
9813
|
+
}
|
|
9749
9814
|
async function executeEdgeGetOrCreateByEndpoints(ctx, kind, fromKind, fromId, toKind, toId, props, backend, options) {
|
|
9750
9815
|
const ifExists = options?.ifExists ?? "return";
|
|
9751
9816
|
const matchOn = options?.matchOn ?? [];
|
|
@@ -10844,6 +10909,142 @@ async function executeNodeGetOrCreateByConstraint(ctx, kind, constraintName, pro
|
|
|
10844
10909
|
}
|
|
10845
10910
|
return { node: rowToNode(existingRow), action: "found" };
|
|
10846
10911
|
}
|
|
10912
|
+
async function executeNodeFindByConstraint(ctx, kind, constraintName, props, backend) {
|
|
10913
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10914
|
+
const nodeKind = registration.type;
|
|
10915
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, props, {
|
|
10916
|
+
kind,
|
|
10917
|
+
operation: "create"
|
|
10918
|
+
});
|
|
10919
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10920
|
+
if (!checkWherePredicate(constraint, validatedProps)) return void 0;
|
|
10921
|
+
const key = computeUniqueKey(
|
|
10922
|
+
validatedProps,
|
|
10923
|
+
constraint.fields,
|
|
10924
|
+
constraint.collation
|
|
10925
|
+
);
|
|
10926
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10927
|
+
kind,
|
|
10928
|
+
constraint.scope,
|
|
10929
|
+
ctx.registry
|
|
10930
|
+
);
|
|
10931
|
+
let existingUniqueRow;
|
|
10932
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10933
|
+
const row = await backend.checkUnique({
|
|
10934
|
+
graphId: ctx.graphId,
|
|
10935
|
+
nodeKind: kindToCheck,
|
|
10936
|
+
constraintName: constraint.name,
|
|
10937
|
+
key,
|
|
10938
|
+
includeDeleted: false
|
|
10939
|
+
});
|
|
10940
|
+
if (row !== void 0) {
|
|
10941
|
+
existingUniqueRow = row;
|
|
10942
|
+
break;
|
|
10943
|
+
}
|
|
10944
|
+
}
|
|
10945
|
+
if (existingUniqueRow === void 0) return void 0;
|
|
10946
|
+
const existingRow = await backend.getNode(
|
|
10947
|
+
ctx.graphId,
|
|
10948
|
+
existingUniqueRow.concrete_kind,
|
|
10949
|
+
existingUniqueRow.node_id
|
|
10950
|
+
);
|
|
10951
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0)
|
|
10952
|
+
return void 0;
|
|
10953
|
+
return rowToNode(existingRow);
|
|
10954
|
+
}
|
|
10955
|
+
async function executeNodeBulkFindByConstraint(ctx, kind, constraintName, items, backend) {
|
|
10956
|
+
if (items.length === 0) return [];
|
|
10957
|
+
const registration = getNodeRegistration(ctx.graph, kind);
|
|
10958
|
+
const nodeKind = registration.type;
|
|
10959
|
+
const constraint = resolveConstraint(ctx.graph, kind, constraintName);
|
|
10960
|
+
const validated = [];
|
|
10961
|
+
for (const item of items) {
|
|
10962
|
+
const validatedProps = chunkLDM2AFKZ_cjs.validateNodeProps(nodeKind.schema, item.props, {
|
|
10963
|
+
kind,
|
|
10964
|
+
operation: "create"
|
|
10965
|
+
});
|
|
10966
|
+
const applies = checkWherePredicate(constraint, validatedProps);
|
|
10967
|
+
const key = applies ? computeUniqueKey(
|
|
10968
|
+
validatedProps,
|
|
10969
|
+
constraint.fields,
|
|
10970
|
+
constraint.collation
|
|
10971
|
+
) : void 0;
|
|
10972
|
+
validated.push({ validatedProps, key });
|
|
10973
|
+
}
|
|
10974
|
+
const uniqueKeys = [
|
|
10975
|
+
...new Set(
|
|
10976
|
+
validated.map((v) => v.key).filter((k) => k !== void 0)
|
|
10977
|
+
)
|
|
10978
|
+
];
|
|
10979
|
+
const kindsToCheck = getKindsForUniquenessCheck(
|
|
10980
|
+
kind,
|
|
10981
|
+
constraint.scope,
|
|
10982
|
+
ctx.registry
|
|
10983
|
+
);
|
|
10984
|
+
const existingByKey = /* @__PURE__ */ new Map();
|
|
10985
|
+
if (uniqueKeys.length > 0) {
|
|
10986
|
+
for (const kindToCheck of kindsToCheck) {
|
|
10987
|
+
if (backend.checkUniqueBatch === void 0) {
|
|
10988
|
+
for (const key of uniqueKeys) {
|
|
10989
|
+
if (existingByKey.has(key)) continue;
|
|
10990
|
+
const row = await backend.checkUnique({
|
|
10991
|
+
graphId: ctx.graphId,
|
|
10992
|
+
nodeKind: kindToCheck,
|
|
10993
|
+
constraintName: constraint.name,
|
|
10994
|
+
key,
|
|
10995
|
+
includeDeleted: false
|
|
10996
|
+
});
|
|
10997
|
+
if (row !== void 0) {
|
|
10998
|
+
existingByKey.set(row.key, row);
|
|
10999
|
+
}
|
|
11000
|
+
}
|
|
11001
|
+
} else {
|
|
11002
|
+
const rows = await backend.checkUniqueBatch({
|
|
11003
|
+
graphId: ctx.graphId,
|
|
11004
|
+
nodeKind: kindToCheck,
|
|
11005
|
+
constraintName: constraint.name,
|
|
11006
|
+
keys: uniqueKeys,
|
|
11007
|
+
includeDeleted: false
|
|
11008
|
+
});
|
|
11009
|
+
for (const row of rows) {
|
|
11010
|
+
if (!existingByKey.has(row.key)) {
|
|
11011
|
+
existingByKey.set(row.key, row);
|
|
11012
|
+
}
|
|
11013
|
+
}
|
|
11014
|
+
}
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
const results = Array.from({ length: items.length });
|
|
11018
|
+
const seenKeys = /* @__PURE__ */ new Map();
|
|
11019
|
+
for (const [index, { key }] of validated.entries()) {
|
|
11020
|
+
if (key === void 0) {
|
|
11021
|
+
results[index] = void 0;
|
|
11022
|
+
continue;
|
|
11023
|
+
}
|
|
11024
|
+
const previousIndex = seenKeys.get(key);
|
|
11025
|
+
if (previousIndex !== void 0) {
|
|
11026
|
+
results[index] = results[previousIndex];
|
|
11027
|
+
continue;
|
|
11028
|
+
}
|
|
11029
|
+
seenKeys.set(key, index);
|
|
11030
|
+
const existing = existingByKey.get(key);
|
|
11031
|
+
if (existing === void 0) {
|
|
11032
|
+
results[index] = void 0;
|
|
11033
|
+
continue;
|
|
11034
|
+
}
|
|
11035
|
+
const existingRow = await backend.getNode(
|
|
11036
|
+
ctx.graphId,
|
|
11037
|
+
existing.concrete_kind,
|
|
11038
|
+
existing.node_id
|
|
11039
|
+
);
|
|
11040
|
+
if (existingRow === void 0 || existingRow.deleted_at !== void 0) {
|
|
11041
|
+
results[index] = void 0;
|
|
11042
|
+
continue;
|
|
11043
|
+
}
|
|
11044
|
+
results[index] = rowToNode(existingRow);
|
|
11045
|
+
}
|
|
11046
|
+
return results;
|
|
11047
|
+
}
|
|
10847
11048
|
async function executeNodeBulkGetOrCreateByConstraint(ctx, kind, constraintName, items, backend, options) {
|
|
10848
11049
|
if (items.length === 0) return [];
|
|
10849
11050
|
const ifExists = options?.ifExists ?? "return";
|
|
@@ -11123,6 +11324,14 @@ var Store = class {
|
|
|
11123
11324
|
items,
|
|
11124
11325
|
backend,
|
|
11125
11326
|
options
|
|
11327
|
+
),
|
|
11328
|
+
executeFindByConstraint: (kind, constraintName, props, backend) => executeNodeFindByConstraint(ctx, kind, constraintName, props, backend),
|
|
11329
|
+
executeBulkFindByConstraint: (kind, constraintName, items, backend) => executeNodeBulkFindByConstraint(
|
|
11330
|
+
ctx,
|
|
11331
|
+
kind,
|
|
11332
|
+
constraintName,
|
|
11333
|
+
items,
|
|
11334
|
+
backend
|
|
11126
11335
|
)
|
|
11127
11336
|
};
|
|
11128
11337
|
}
|
|
@@ -11160,6 +11369,16 @@ var Store = class {
|
|
|
11160
11369
|
items,
|
|
11161
11370
|
backend,
|
|
11162
11371
|
options
|
|
11372
|
+
),
|
|
11373
|
+
executeFindByEndpoints: (kind, fromKind, fromId, toKind, toId, backend, options) => executeEdgeFindByEndpoints(
|
|
11374
|
+
ctx,
|
|
11375
|
+
kind,
|
|
11376
|
+
fromKind,
|
|
11377
|
+
fromId,
|
|
11378
|
+
toKind,
|
|
11379
|
+
toId,
|
|
11380
|
+
backend,
|
|
11381
|
+
options
|
|
11163
11382
|
)
|
|
11164
11383
|
};
|
|
11165
11384
|
}
|
|
@@ -11227,6 +11446,24 @@ var Store = class {
|
|
|
11227
11446
|
return fn({ nodes, edges });
|
|
11228
11447
|
});
|
|
11229
11448
|
}
|
|
11449
|
+
// === Graph Lifecycle ===
|
|
11450
|
+
/**
|
|
11451
|
+
* Hard-deletes all data for this graph from the database.
|
|
11452
|
+
*
|
|
11453
|
+
* Removes all nodes, edges, uniqueness entries, embeddings, and schema versions
|
|
11454
|
+
* for this graph's ID. No hooks, no per-row logic. Wrapped in a transaction
|
|
11455
|
+
* when the backend supports it.
|
|
11456
|
+
*
|
|
11457
|
+
* The store is usable after clearing — new data can be created immediately.
|
|
11458
|
+
*/
|
|
11459
|
+
async clear() {
|
|
11460
|
+
const doClear = async (target) => {
|
|
11461
|
+
await target.clearGraph(this.graphId);
|
|
11462
|
+
};
|
|
11463
|
+
await (this.#backend.capabilities.transactions ? this.#backend.transaction(async (tx) => doClear(tx)) : doClear(this.#backend));
|
|
11464
|
+
this.#nodeCollections = void 0;
|
|
11465
|
+
this.#edgeCollections = void 0;
|
|
11466
|
+
}
|
|
11230
11467
|
// === Lifecycle ===
|
|
11231
11468
|
/**
|
|
11232
11469
|
* Closes the store and releases underlying resources.
|