@nicia-ai/typegraph 0.1.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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/ast-BVyihVbP.d.cts +564 -0
- package/dist/ast-BVyihVbP.d.ts +564 -0
- package/dist/backend/drizzle/index.cjs +41 -0
- package/dist/backend/drizzle/index.cjs.map +1 -0
- package/dist/backend/drizzle/index.d.cts +12 -0
- package/dist/backend/drizzle/index.d.ts +12 -0
- package/dist/backend/drizzle/index.js +12 -0
- package/dist/backend/drizzle/index.js.map +1 -0
- package/dist/backend/drizzle/postgres.cjs +27 -0
- package/dist/backend/drizzle/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/postgres.d.cts +37 -0
- package/dist/backend/drizzle/postgres.d.ts +37 -0
- package/dist/backend/drizzle/postgres.js +10 -0
- package/dist/backend/drizzle/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/postgres.cjs +40 -0
- package/dist/backend/drizzle/schema/postgres.cjs.map +1 -0
- package/dist/backend/drizzle/schema/postgres.d.cts +2419 -0
- package/dist/backend/drizzle/schema/postgres.d.ts +2419 -0
- package/dist/backend/drizzle/schema/postgres.js +7 -0
- package/dist/backend/drizzle/schema/postgres.js.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.cjs +40 -0
- package/dist/backend/drizzle/schema/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/schema/sqlite.d.cts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.d.ts +2647 -0
- package/dist/backend/drizzle/schema/sqlite.js +7 -0
- package/dist/backend/drizzle/schema/sqlite.js.map +1 -0
- package/dist/backend/drizzle/sqlite.cjs +27 -0
- package/dist/backend/drizzle/sqlite.cjs.map +1 -0
- package/dist/backend/drizzle/sqlite.d.cts +36 -0
- package/dist/backend/drizzle/sqlite.d.ts +36 -0
- package/dist/backend/drizzle/sqlite.js +10 -0
- package/dist/backend/drizzle/sqlite.js.map +1 -0
- package/dist/backend/postgres/index.cjs +53 -0
- package/dist/backend/postgres/index.cjs.map +1 -0
- package/dist/backend/postgres/index.d.cts +12 -0
- package/dist/backend/postgres/index.d.ts +12 -0
- package/dist/backend/postgres/index.js +12 -0
- package/dist/backend/postgres/index.js.map +1 -0
- package/dist/backend/sqlite/index.cjs +117 -0
- package/dist/backend/sqlite/index.cjs.map +1 -0
- package/dist/backend/sqlite/index.d.cts +71 -0
- package/dist/backend/sqlite/index.d.ts +71 -0
- package/dist/backend/sqlite/index.js +78 -0
- package/dist/backend/sqlite/index.js.map +1 -0
- package/dist/chunk-2QHQ2C4P.js +146 -0
- package/dist/chunk-2QHQ2C4P.js.map +1 -0
- package/dist/chunk-3A5TKOEJ.js +306 -0
- package/dist/chunk-3A5TKOEJ.js.map +1 -0
- package/dist/chunk-4PIEL2VO.js +162 -0
- package/dist/chunk-4PIEL2VO.js.map +1 -0
- package/dist/chunk-536PH5FT.js +342 -0
- package/dist/chunk-536PH5FT.js.map +1 -0
- package/dist/chunk-DBFCKELK.cjs +156 -0
- package/dist/chunk-DBFCKELK.cjs.map +1 -0
- package/dist/chunk-DDM2FZRJ.cjs +1143 -0
- package/dist/chunk-DDM2FZRJ.cjs.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-F32HCHYA.cjs +680 -0
- package/dist/chunk-F32HCHYA.cjs.map +1 -0
- package/dist/chunk-IIAT36MI.js +353 -0
- package/dist/chunk-IIAT36MI.js.map +1 -0
- package/dist/chunk-JDAET5LO.js +236 -0
- package/dist/chunk-JDAET5LO.js.map +1 -0
- package/dist/chunk-JEQ2X3Z6.cjs +12 -0
- package/dist/chunk-JEQ2X3Z6.cjs.map +1 -0
- package/dist/chunk-JKTO7TW3.js +299 -0
- package/dist/chunk-JKTO7TW3.js.map +1 -0
- package/dist/chunk-K7SQ3SWP.js +497 -0
- package/dist/chunk-K7SQ3SWP.js.map +1 -0
- package/dist/chunk-L642L24T.js +142 -0
- package/dist/chunk-L642L24T.js.map +1 -0
- package/dist/chunk-MFVCSNIY.cjs +308 -0
- package/dist/chunk-MFVCSNIY.cjs.map +1 -0
- package/dist/chunk-MNO33ASC.cjs +240 -0
- package/dist/chunk-MNO33ASC.cjs.map +1 -0
- package/dist/chunk-N4AOJ3VF.cjs +154 -0
- package/dist/chunk-N4AOJ3VF.cjs.map +1 -0
- package/dist/chunk-P5CNM325.cjs +508 -0
- package/dist/chunk-P5CNM325.cjs.map +1 -0
- package/dist/chunk-RYT4H46I.js +646 -0
- package/dist/chunk-RYT4H46I.js.map +1 -0
- package/dist/chunk-SV5H3XM5.cjs +321 -0
- package/dist/chunk-SV5H3XM5.cjs.map +1 -0
- package/dist/chunk-TXHKFLWX.cjs +344 -0
- package/dist/chunk-TXHKFLWX.cjs.map +1 -0
- package/dist/chunk-UJAGXJDG.cjs +170 -0
- package/dist/chunk-UJAGXJDG.cjs.map +1 -0
- package/dist/chunk-VXRVGFCI.js +1128 -0
- package/dist/chunk-VXRVGFCI.js.map +1 -0
- package/dist/chunk-YM5AL65Y.cjs +357 -0
- package/dist/chunk-YM5AL65Y.cjs.map +1 -0
- package/dist/index.cjs +8334 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1365 -0
- package/dist/index.d.ts +1365 -0
- package/dist/index.js +8105 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/index.cjs +67 -0
- package/dist/indexes/index.cjs.map +1 -0
- package/dist/indexes/index.d.cts +62 -0
- package/dist/indexes/index.d.ts +62 -0
- package/dist/indexes/index.js +6 -0
- package/dist/indexes/index.js.map +1 -0
- package/dist/interchange/index.cjs +612 -0
- package/dist/interchange/index.cjs.map +1 -0
- package/dist/interchange/index.d.cts +288 -0
- package/dist/interchange/index.d.ts +288 -0
- package/dist/interchange/index.js +598 -0
- package/dist/interchange/index.js.map +1 -0
- package/dist/profiler/index.cjs +793 -0
- package/dist/profiler/index.cjs.map +1 -0
- package/dist/profiler/index.d.cts +283 -0
- package/dist/profiler/index.d.ts +283 -0
- package/dist/profiler/index.js +785 -0
- package/dist/profiler/index.js.map +1 -0
- package/dist/store-60Lcfi0w.d.ts +2263 -0
- package/dist/store-Bifii8MZ.d.cts +2263 -0
- package/dist/test-helpers-BjyRYJZX.d.ts +22 -0
- package/dist/test-helpers-NoQXhleQ.d.cts +22 -0
- package/dist/types-BRzHlhKC.d.cts +14 -0
- package/dist/types-BRzHlhKC.d.ts +14 -0
- package/dist/types-BrSfFSpW.d.cts +158 -0
- package/dist/types-CX4cLd7M.d.ts +152 -0
- package/dist/types-CjZ7g_7v.d.ts +442 -0
- package/dist/types-DDOSfrih.d.cts +442 -0
- package/dist/types-D_3mEv2y.d.ts +158 -0
- package/dist/types-a5rAxC92.d.cts +152 -0
- package/package.json +201 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkSV5H3XM5_cjs = require('./chunk-SV5H3XM5.cjs');
|
|
4
|
+
|
|
5
|
+
// src/core/types.ts
|
|
6
|
+
var NODE_TYPE_BRAND = "__nodeType";
|
|
7
|
+
var EDGE_TYPE_BRAND = "__edgeType";
|
|
8
|
+
function isNodeType(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && NODE_TYPE_BRAND in value && value[NODE_TYPE_BRAND] === true;
|
|
10
|
+
}
|
|
11
|
+
function isEdgeType(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && EDGE_TYPE_BRAND in value && value[EDGE_TYPE_BRAND] === true;
|
|
13
|
+
}
|
|
14
|
+
function isEdgeTypeWithEndpoints(value) {
|
|
15
|
+
return isEdgeType(value) && Array.isArray(value.from) && value.from.length > 0 && Array.isArray(value.to) && value.to.length > 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/core/define-graph.ts
|
|
19
|
+
var GRAPH_DEF_BRAND = "__graphDef";
|
|
20
|
+
function validateConstraintNarrowing(name, edgeType, registration) {
|
|
21
|
+
const builtInFromNames = new Set(edgeType.from.map((n) => n.name));
|
|
22
|
+
for (const fromNode of registration.from) {
|
|
23
|
+
if (!builtInFromNames.has(fromNode.name)) {
|
|
24
|
+
throw new chunkSV5H3XM5_cjs.ConfigurationError(
|
|
25
|
+
`Edge "${name}" registration has 'from' kind "${fromNode.name}" not in edge's built-in domain: [${[...builtInFromNames].join(", ")}]`,
|
|
26
|
+
{
|
|
27
|
+
edgeName: name,
|
|
28
|
+
invalidFrom: fromNode.name,
|
|
29
|
+
allowedFrom: [...builtInFromNames]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const builtInToNames = new Set(edgeType.to.map((n) => n.name));
|
|
38
|
+
for (const toNode of registration.to) {
|
|
39
|
+
if (!builtInToNames.has(toNode.name)) {
|
|
40
|
+
throw new chunkSV5H3XM5_cjs.ConfigurationError(
|
|
41
|
+
`Edge "${name}" registration has 'to' kind "${toNode.name}" not in edge's built-in range: [${[...builtInToNames].join(", ")}]`,
|
|
42
|
+
{
|
|
43
|
+
edgeName: name,
|
|
44
|
+
invalidTo: toNode.name,
|
|
45
|
+
allowedTo: [...builtInToNames]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function normalizeEdgeEntry(name, entry) {
|
|
55
|
+
if (isEdgeTypeWithEndpoints(entry)) {
|
|
56
|
+
return {
|
|
57
|
+
type: entry,
|
|
58
|
+
from: entry.from,
|
|
59
|
+
to: entry.to
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
if (isEdgeTypeWithEndpoints(entry.type)) {
|
|
63
|
+
validateConstraintNarrowing(name, entry.type, entry);
|
|
64
|
+
}
|
|
65
|
+
return entry;
|
|
66
|
+
}
|
|
67
|
+
function normalizeEdges(edges) {
|
|
68
|
+
const result = {};
|
|
69
|
+
for (const [name, entry] of Object.entries(edges)) {
|
|
70
|
+
result[name] = normalizeEdgeEntry(name, entry);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
function defineGraph(config) {
|
|
75
|
+
const defaults = {
|
|
76
|
+
onNodeDelete: config.defaults?.onNodeDelete ?? "restrict",
|
|
77
|
+
temporalMode: config.defaults?.temporalMode ?? "current"
|
|
78
|
+
};
|
|
79
|
+
const normalizedEdges = normalizeEdges(config.edges);
|
|
80
|
+
return Object.freeze({
|
|
81
|
+
[GRAPH_DEF_BRAND]: true,
|
|
82
|
+
id: config.id,
|
|
83
|
+
nodes: config.nodes,
|
|
84
|
+
edges: normalizedEdges,
|
|
85
|
+
ontology: config.ontology ?? [],
|
|
86
|
+
defaults
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function isGraphDef(value) {
|
|
90
|
+
return typeof value === "object" && value !== null && GRAPH_DEF_BRAND in value && value[GRAPH_DEF_BRAND] === true;
|
|
91
|
+
}
|
|
92
|
+
function getNodeTypeNames(graph) {
|
|
93
|
+
return Object.keys(graph.nodes);
|
|
94
|
+
}
|
|
95
|
+
function getEdgeTypeNames(graph) {
|
|
96
|
+
return Object.keys(graph.edges);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// src/utils/date.ts
|
|
100
|
+
var ISO_DATE_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/;
|
|
101
|
+
function isValidIsoDate(value) {
|
|
102
|
+
if (!ISO_DATE_PATTERN.test(value)) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
const date = new Date(value);
|
|
106
|
+
return !Number.isNaN(date.getTime());
|
|
107
|
+
}
|
|
108
|
+
function validateIsoDate(value, fieldName) {
|
|
109
|
+
if (!isValidIsoDate(value)) {
|
|
110
|
+
throw new chunkSV5H3XM5_cjs.ValidationError(
|
|
111
|
+
`Invalid ISO 8601 datetime for "${fieldName}": "${value}". Expected format: YYYY-MM-DDTHH:mm:ss.sssZ`,
|
|
112
|
+
{
|
|
113
|
+
issues: [
|
|
114
|
+
{
|
|
115
|
+
path: fieldName,
|
|
116
|
+
message: `Invalid ISO 8601 datetime format. Expected: YYYY-MM-DDTHH:mm:ss.sssZ, got: "${value}"`
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
suggestion: `Use a valid ISO 8601 UTC datetime like "2024-01-15T10:30:00.000Z"`
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function validateOptionalIsoDate(value, fieldName) {
|
|
128
|
+
if (value === void 0) return void 0;
|
|
129
|
+
return validateIsoDate(value, fieldName);
|
|
130
|
+
}
|
|
131
|
+
function encodeDate(date) {
|
|
132
|
+
return date.toISOString();
|
|
133
|
+
}
|
|
134
|
+
function decodeDate(isoString) {
|
|
135
|
+
validateIsoDate(isoString, "date");
|
|
136
|
+
return new Date(isoString);
|
|
137
|
+
}
|
|
138
|
+
function nowIso() {
|
|
139
|
+
return (/* @__PURE__ */ new Date()).toISOString();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
exports.EDGE_TYPE_BRAND = EDGE_TYPE_BRAND;
|
|
143
|
+
exports.NODE_TYPE_BRAND = NODE_TYPE_BRAND;
|
|
144
|
+
exports.decodeDate = decodeDate;
|
|
145
|
+
exports.defineGraph = defineGraph;
|
|
146
|
+
exports.encodeDate = encodeDate;
|
|
147
|
+
exports.getEdgeTypeNames = getEdgeTypeNames;
|
|
148
|
+
exports.getNodeTypeNames = getNodeTypeNames;
|
|
149
|
+
exports.isEdgeType = isEdgeType;
|
|
150
|
+
exports.isEdgeTypeWithEndpoints = isEdgeTypeWithEndpoints;
|
|
151
|
+
exports.isGraphDef = isGraphDef;
|
|
152
|
+
exports.isNodeType = isNodeType;
|
|
153
|
+
exports.nowIso = nowIso;
|
|
154
|
+
exports.validateOptionalIsoDate = validateOptionalIsoDate;
|
|
155
|
+
//# sourceMappingURL=chunk-DBFCKELK.cjs.map
|
|
156
|
+
//# sourceMappingURL=chunk-DBFCKELK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/types.ts","../src/core/define-graph.ts","../src/utils/date.ts"],"names":["ConfigurationError","ValidationError"],"mappings":";;;;;AAOO,IAAM,eAAA,GAAkB;AAGxB,IAAM,eAAA,GAAkB;AA6OxB,SAAS,WAAW,KAAA,EAAmC;AAC5D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAKO,SAAS,WAAW,KAAA,EAAsC;AAC/D,EAAA,OACE,OAAO,UAAU,QAAA,IACjB,KAAA,KAAU,QACV,eAAA,IAAmB,KAAA,IAClB,KAAA,CAAkC,eAAe,CAAA,KAAM,IAAA;AAE5D;AAMO,SAAS,wBACd,KAAA,EACgC;AAChC,EAAA,OACE,WAAW,KAAK,CAAA,IAChB,MAAM,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,IACxB,KAAA,CAAM,KAAK,MAAA,GAAS,CAAA,IACpB,MAAM,OAAA,CAAQ,KAAA,CAAM,EAAE,CAAA,IACtB,KAAA,CAAM,GAAG,MAAA,GAAS,CAAA;AAEtB;;;ACxQA,IAAM,eAAA,GAAkB,YAAA;AAoCxB,SAAS,2BAAA,CACP,IAAA,EACA,QAAA,EACA,YAAA,EACM;AACN,EAAA,MAAM,gBAAA,GAAmB,IAAI,GAAA,CAAI,QAAA,CAAS,IAAA,CAAK,IAAI,CAAC,CAAA,KAAM,CAAA,CAAE,IAAI,CAAC,CAAA;AACjE,EAAA,K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OAAO,SAAS,CAAA;AACzC;AAKO,SAAS,WAAW,IAAA,EAAoB;AAC7C,EAAA,OAAO,KAAK,WAAA,EAAY;AAC1B;AAQO,SAAS,WAAW,SAAA,EAAyB;AAClD,EAAA,eAAA,CAAgB,WAAW,MAAM,CAAA;AACjC,EAAA,OAAO,IAAI,KAAK,SAAS,CAAA;AAC3B;AAKO,SAAS,MAAA,GAAiB;AAC/B,EAAA,OAAA,iBAAO,IAAI,IAAA,EAAK,EAAE,WAAA,EAAY;AAChC","file":"chunk-DBFCKELK.cjs","sourcesContent":["import { type z } from \"zod\";\n\n// ============================================================\n// Brand Keys for Nominal Typing\n// ============================================================\n\n/** Brand key for NodeType */\nexport const NODE_TYPE_BRAND = \"__nodeType\" as const;\n\n/** Brand key for EdgeType */\nexport const EDGE_TYPE_BRAND = \"__edgeType\" as const;\n\n/** Brand symbol for NodeId */\ndeclare const __nodeId: unique symbol;\n\n// ============================================================\n// Node Type\n// ============================================================\n\n/**\n * A node type definition.\n *\n * Created via `defineNode()`. Represents a type of node in the graph\n * with an associated Zod schema for properties.\n */\nexport type NodeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [NODE_TYPE_BRAND]: true;\n name: K;\n schema: S;\n description: string | undefined;\n}>;\n\n/**\n * Branded node ID type.\n *\n * Prevents mixing IDs from different node types at compile time.\n */\nexport type NodeId<N extends NodeType> = string &\n Readonly<{\n [__nodeId]: N;\n }>;\n\n/**\n * Infer the props type from a NodeType.\n */\nexport type NodeProps<N extends NodeType> = z.infer<N[\"schema\"]>;\n\n// ============================================================\n// Edge Type\n// ============================================================\n\n/**\n * An edge type definition.\n *\n * Created via `defineEdge()`. Represents a type of edge in the graph\n * with an optional Zod schema for properties.\n *\n * Optionally includes `from` and `to` arrays that define the allowed\n * source and target node types (domain and range constraints).\n */\nexport type EdgeType<\n K extends string = string,\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n From extends readonly NodeType[] | undefined = undefined,\n To extends readonly NodeType[] | undefined = undefined,\n> = Readonly<{\n [EDGE_TYPE_BRAND]: true;\n name: K;\n schema: S;\n description: string | undefined;\n from: From;\n to: To;\n}>;\n\n/**\n * Base edge type for use in constraints - accepts any from/to configuration.\n */\nexport type AnyEdgeType = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[] | undefined,\n readonly NodeType[] | undefined\n>;\n\n/**\n * An edge type that has both from and to constraints defined.\n * Can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport type EdgeTypeWithEndpoints = EdgeType<\n string,\n z.ZodObject<z.ZodRawShape>,\n readonly NodeType[],\n readonly NodeType[]\n>;\n\n/**\n * Infer the props type from an EdgeType.\n */\nexport type EdgeProps<E extends AnyEdgeType> = z.infer<E[\"schema\"]>;\n\n// ============================================================\n// Configuration Types\n// ============================================================\n\n/**\n * Delete behaviors for nodes.\n */\nexport type DeleteBehavior = \"restrict\" | \"cascade\" | \"disconnect\";\n\n/**\n * Edge cardinality constraints.\n */\nexport type Cardinality =\n | \"many\" // No constraint (default)\n | \"one\" // At most one edge of this kind from any source node\n | \"unique\" // At most one edge of this kind between any (source, target) pair\n | \"oneActive\"; // At most one edge with valid_to IS NULL from any source\n\n/**\n * Endpoint existence modes for edge validation.\n */\nexport type EndpointExistence =\n | \"notDeleted\" // Endpoint deleted_at IS NULL (default)\n | \"currentlyValid\" // Endpoint not deleted AND temporally valid\n | \"ever\"; // Endpoint exists in any state\n\n/**\n * Temporal query modes.\n */\nexport type TemporalMode =\n | \"current\" // Valid now AND not deleted\n | \"asOf\" // Valid at specific date AND not deleted\n | \"includeEnded\" // All validity periods AND not deleted\n | \"includeTombstones\"; // Everything including soft-deleted\n\n/**\n * Uniqueness constraint scope.\n */\nexport type UniquenessScope =\n | \"kind\" // Unique within this exact kind only\n | \"kindWithSubClasses\"; // Unique across this kind and all subclasses\n\n/**\n * Collation for uniqueness constraints.\n */\nexport type Collation = \"binary\" | \"caseInsensitive\";\n\n// ============================================================\n// Uniqueness Constraint\n// ============================================================\n\n/**\n * Uniqueness constraint definition.\n */\nexport type UniqueConstraint<\n S extends z.ZodObject<z.ZodRawShape> = z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n name: string;\n fields: readonly (keyof z.infer<S> & string)[];\n where?: (\n props: UniqueConstraintPredicateBuilder<S>,\n ) => UniqueConstraintPredicate;\n scope: UniquenessScope;\n collation: Collation;\n}>;\n\n/**\n * Predicate builder for uniqueness constraint where clause.\n * Uses -? to make all fields required in the builder, even if optional in the schema.\n */\nexport type UniqueConstraintPredicateBuilder<\n S extends z.ZodObject<z.ZodRawShape>,\n> = Readonly<{\n [K in keyof z.infer<S>]-?: UniqueConstraintField;\n}>;\n\n/**\n * Field operations for uniqueness constraint predicates.\n */\ntype UniqueConstraintField = Readonly<{\n isNull: () => UniqueConstraintPredicate;\n isNotNull: () => UniqueConstraintPredicate;\n}>;\n\n/**\n * A uniqueness constraint predicate (internal representation).\n */\nexport type UniqueConstraintPredicate = Readonly<{\n __type: \"unique_predicate\";\n field: string;\n op: \"isNull\" | \"isNotNull\";\n}>;\n\n// ============================================================\n// Node Registration\n// ============================================================\n\n/**\n * Node registration in a graph definition.\n */\nexport type NodeRegistration<N extends NodeType = NodeType> = Readonly<{\n type: N;\n unique?: readonly UniqueConstraint<N[\"schema\"]>[];\n onDelete?: DeleteBehavior;\n}>;\n\n// ============================================================\n// Edge Registration\n// ============================================================\n\n/**\n * Edge registration in a graph definition.\n */\nexport type EdgeRegistration<\n E extends AnyEdgeType = AnyEdgeType,\n FromTypes extends NodeType = NodeType,\n ToTypes extends NodeType = NodeType,\n> = Readonly<{\n type: E;\n from: readonly FromTypes[];\n to: readonly ToTypes[];\n cardinality?: Cardinality;\n endpointExistence?: EndpointExistence;\n}>;\n\n// ============================================================\n// Graph Defaults\n// ============================================================\n\n/**\n * Default settings for a graph.\n */\nexport type GraphDefaults = Readonly<{\n onNodeDelete?: DeleteBehavior;\n temporalMode?: TemporalMode;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Checks if a value is a NodeType.\n */\nexport function isNodeType(value: unknown): value is NodeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n NODE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[NODE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType.\n */\nexport function isEdgeType(value: unknown): value is AnyEdgeType {\n return (\n typeof value === \"object\" &&\n value !== null &&\n EDGE_TYPE_BRAND in value &&\n (value as Record<string, unknown>)[EDGE_TYPE_BRAND] === true\n );\n}\n\n/**\n * Checks if a value is an EdgeType with both from and to constraints defined.\n * Such edges can be used directly in defineGraph without an EdgeRegistration wrapper.\n */\nexport function isEdgeTypeWithEndpoints(\n value: unknown,\n): value is EdgeTypeWithEndpoints {\n return (\n isEdgeType(value) &&\n Array.isArray(value.from) &&\n value.from.length > 0 &&\n Array.isArray(value.to) &&\n value.to.length > 0\n );\n}\n","import { ConfigurationError } from \"../errors/index\";\nimport { type OntologyRelation } from \"../ontology/types\";\nimport {\n type DeleteBehavior,\n type EdgeRegistration,\n type EdgeTypeWithEndpoints,\n type GraphDefaults,\n isEdgeTypeWithEndpoints,\n type NodeRegistration,\n type NodeType,\n type TemporalMode,\n} from \"./types\";\n\n// ============================================================\n// Graph Definition Brand Symbol\n// ============================================================\n\n/** Brand key for GraphDef */\nconst GRAPH_DEF_BRAND = \"__graphDef\" as const;\n\n// ============================================================\n// Edge Entry Types\n// ============================================================\n\n/**\n * An edge entry in the graph definition.\n * Can be:\n * - EdgeType directly (if it has from/to defined)\n * - EdgeRegistration object (always works, can override/narrow defaults)\n */\ntype EdgeEntry = EdgeRegistration | EdgeTypeWithEndpoints;\n\n/**\n * Normalized edge map type - all entries become EdgeRegistration.\n */\ntype NormalizedEdges<TEdges extends Record<string, EdgeEntry>> = {\n [K in keyof TEdges]: TEdges[K] extends EdgeRegistration ? TEdges[K]\n : TEdges[K] extends EdgeTypeWithEndpoints ?\n EdgeRegistration<\n TEdges[K],\n TEdges[K][\"from\"][number],\n TEdges[K][\"to\"][number]\n >\n : never;\n};\n\n// ============================================================\n// Edge Normalization Functions\n// ============================================================\n\n/**\n * Validates that an EdgeRegistration's constraints don't widen beyond\n * the edge type's built-in domain/range constraints.\n */\nfunction validateConstraintNarrowing(\n name: string,\n edgeType: EdgeTypeWithEndpoints,\n registration: EdgeRegistration,\n): void {\n const builtInFromNames = new Set(edgeType.from.map((n) => n.name));\n for (const fromNode of registration.from) {\n if (!builtInFromNames.has(fromNode.name)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'from' kind \"${fromNode.name}\" ` +\n `not in edge's built-in domain: [${[...builtInFromNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidFrom: fromNode.name,\n allowedFrom: [...builtInFromNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n\n const builtInToNames = new Set(edgeType.to.map((n) => n.name));\n for (const toNode of registration.to) {\n if (!builtInToNames.has(toNode.name)) {\n throw new ConfigurationError(\n `Edge \"${name}\" registration has 'to' kind \"${toNode.name}\" ` +\n `not in edge's built-in range: [${[...builtInToNames].join(\", \")}]`,\n {\n edgeName: name,\n invalidTo: toNode.name,\n allowedTo: [...builtInToNames],\n },\n {\n suggestion: `Edge registration can only narrow, not widen, the edge type's built-in constraints.`,\n },\n );\n }\n }\n}\n\n/**\n * Normalizes a single edge entry to EdgeRegistration.\n */\nfunction normalizeEdgeEntry(name: string, entry: EdgeEntry): EdgeRegistration {\n if (isEdgeTypeWithEndpoints(entry)) {\n // EdgeType with from/to - convert to EdgeRegistration\n return {\n type: entry,\n from: entry.from,\n to: entry.to,\n };\n }\n\n // Already EdgeRegistration - validate narrowing if edge has built-in constraints\n if (isEdgeTypeWithEndpoints(entry.type)) {\n validateConstraintNarrowing(name, entry.type, entry);\n }\n\n return entry;\n}\n\n/**\n * Normalizes all edge entries to EdgeRegistration.\n */\nfunction normalizeEdges(\n edges: Record<string, EdgeEntry>,\n): Record<string, EdgeRegistration> {\n const result: Record<string, EdgeRegistration> = {};\n for (const [name, entry] of Object.entries(edges)) {\n result[name] = normalizeEdgeEntry(name, entry);\n }\n return result;\n}\n\n// ============================================================\n// Graph Definition Configuration\n// ============================================================\n\n/**\n * Configuration for defineGraph.\n */\ntype GraphDefConfig<\n TNodes extends Record<string, NodeRegistration>,\n TEdges extends Record<string, EdgeEntry>,\n TOntology extends readonly OntologyRelation[],\n> = Readonly<{\n /** Unique identifier for this graph */\n id: string;\n /** Node registrations */\n nodes: TNodes;\n /** Edge registrations or EdgeTypes with built-in domain/range */\n edges: TEdges;\n /** Ontology relations */\n ontology?: TOntology;\n /** Graph-wide defaults */\n defaults?: GraphDefaults;\n}>;\n\n// ============================================================\n// Graph Definition Type\n// ============================================================\n\n/**\n * A graph definition.\n *\n * This is a compile-time artifact that describes the structure of a graph.\n * Use `createStore()` to create a runtime store from this definition.\n */\nexport type GraphDef<\n TNodes extends Record<string, NodeRegistration> = Record<\n string,\n NodeRegistration\n >,\n TEdges extends Record<string, EdgeRegistration> = Record<\n string,\n EdgeRegistration\n >,\n TOntology extends readonly OntologyRelation[] = readonly OntologyRelation[],\n> = Readonly<{\n [GRAPH_DEF_BRAND]: true;\n id: string;\n nodes: TNodes;\n edges: TEdges;\n ontology: TOntology;\n defaults: Readonly<{\n onNodeDelete: DeleteBehavior;\n temporalMode: TemporalMode;\n }>;\n}>;\n\n// ============================================================\n// Type Helpers\n// ============================================================\n\n/**\n * Extract node type names from a GraphDef.\n */\nexport type NodeTypeNames<G extends GraphDef> = keyof G[\"nodes\"] & string;\n\n/**\n * Extract edge type names from a GraphDef.\n */\nexport type EdgeTypeNames<G extends GraphDef> = keyof G[\"edges\"] & string;\n\n/**\n * Get a NodeType from a GraphDef by name.\n */\nexport type GetNodeType<\n G extends GraphDef,\n K extends NodeTypeNames<G>,\n> = G[\"nodes\"][K][\"type\"];\n\n/**\n * Get an EdgeType from a GraphDef by name.\n */\nexport type GetEdgeType<\n G extends GraphDef,\n K extends EdgeTypeNames<G>,\n> = G[\"edges\"][K][\"type\"];\n\n/**\n * Get all NodeTypes from a GraphDef.\n */\nexport type AllNodeTypes<G extends GraphDef> = {\n [K in NodeTypeNames<G>]: G[\"nodes\"][K][\"type\"];\n}[NodeTypeNames<G>];\n\n/**\n * Get all EdgeTypes from a GraphDef.\n */\nexport type AllEdgeTypes<G extends GraphDef> = {\n [K in EdgeTypeNames<G>]: G[\"edges\"][K][\"type\"];\n}[EdgeTypeNames<G>];\n\n// ============================================================\n// Define Graph Function\n// ============================================================\n\n/**\n * Creates a graph definition.\n *\n * @example\n * ```typescript\n * const graph = defineGraph({\n * id: \"my_graph\",\n * nodes: {\n * Person: { type: Person },\n * Company: { type: Company },\n * },\n * edges: {\n * // Traditional EdgeRegistration syntax\n * worksAt: {\n * type: worksAt,\n * from: [Person],\n * to: [Company],\n * cardinality: \"many\",\n * },\n * // Or use EdgeType directly if it has from/to defined\n * knows, // EdgeType with built-in domain/range\n * },\n * ontology: [\n * subClassOf(Company, Organization),\n * disjointWith(Person, Organization),\n * ],\n * defaults: {\n * onNodeDelete: \"restrict\",\n * temporalMode: \"current\",\n * },\n * });\n * ```\n */\nexport function defineGraph<\n TNodes extends Record<string, NodeRegistration<NodeType>>,\n TEdges extends Record<string, EdgeEntry>,\n TOntology extends readonly OntologyRelation[],\n>(\n config: GraphDefConfig<TNodes, TEdges, TOntology>,\n): GraphDef<TNodes, NormalizedEdges<TEdges>, TOntology> {\n const defaults = {\n onNodeDelete: config.defaults?.onNodeDelete ?? \"restrict\",\n temporalMode: config.defaults?.temporalMode ?? \"current\",\n } as const;\n\n const normalizedEdges = normalizeEdges(config.edges);\n\n return Object.freeze({\n [GRAPH_DEF_BRAND]: true as const,\n id: config.id,\n nodes: config.nodes,\n edges: normalizedEdges,\n ontology: config.ontology ?? ([] as unknown as TOntology),\n defaults,\n }) as GraphDef<TNodes, NormalizedEdges<TEdges>, TOntology>;\n}\n\n// ============================================================\n// Graph Definition Utilities\n// ============================================================\n\n/**\n * Checks if a value is a GraphDef.\n */\nexport function isGraphDef(value: unknown): value is GraphDef {\n return (\n typeof value === \"object\" &&\n value !== null &&\n GRAPH_DEF_BRAND in value &&\n (value as Record<string, unknown>)[GRAPH_DEF_BRAND] === true\n );\n}\n\n/**\n * Gets all node type names from a GraphDef.\n */\nexport function getNodeTypeNames<G extends GraphDef>(\n graph: G,\n): readonly string[] {\n return Object.keys(graph.nodes);\n}\n\n/**\n * Gets all edge type names from a GraphDef.\n */\nexport function getEdgeTypeNames<G extends GraphDef>(\n graph: G,\n): readonly string[] {\n return Object.keys(graph.edges);\n}\n","/**\n * Date encoding utilities for consistent storage.\n *\n * Contract: All dates are stored as ISO 8601 strings in UTC.\n * - Always includes milliseconds\n * - Always UTC (Z suffix)\n * - Sorts correctly as strings\n */\n\nimport { ValidationError } from \"../errors\";\n\n/**\n * ISO 8601 datetime pattern.\n * Matches formats like:\n * - 2024-01-15T10:30:00.000Z\n * - 2024-01-15T10:30:00Z\n * - 2024-01-15T10:30:00.123Z\n */\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,3})?Z$/;\n\n/**\n * Checks if a string is a valid ISO 8601 datetime.\n *\n * @param value - String to validate\n * @returns True if valid ISO 8601 datetime\n */\nexport function isValidIsoDate(value: string): boolean {\n if (!ISO_DATE_PATTERN.test(value)) {\n return false;\n }\n // Also check that Date parsing produces a valid date\n const date = new Date(value);\n return !Number.isNaN(date.getTime());\n}\n\n/**\n * Validates that a string is a valid ISO 8601 datetime.\n * Throws ValidationError if invalid.\n *\n * @param value - String to validate\n * @param fieldName - Name of field for error message\n * @returns The validated string\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function validateIsoDate(value: string, fieldName: string): string {\n if (!isValidIsoDate(value)) {\n throw new ValidationError(\n `Invalid ISO 8601 datetime for \"${fieldName}\": \"${value}\". ` +\n `Expected format: YYYY-MM-DDTHH:mm:ss.sssZ`,\n {\n issues: [\n {\n path: fieldName,\n message: `Invalid ISO 8601 datetime format. Expected: YYYY-MM-DDTHH:mm:ss.sssZ, got: \"${value}\"`,\n },\n ],\n },\n {\n suggestion: `Use a valid ISO 8601 UTC datetime like \"2024-01-15T10:30:00.000Z\"`,\n },\n );\n }\n return value;\n}\n\n/**\n * Validates an optional ISO date string.\n * Returns undefined if value is undefined, otherwise validates.\n */\nexport function validateOptionalIsoDate(\n value: string | undefined,\n fieldName: string,\n): string | undefined {\n if (value === undefined) return undefined;\n return validateIsoDate(value, fieldName);\n}\n\n/**\n * Encodes a Date to an ISO 8601 string for storage.\n */\nexport function encodeDate(date: Date): string {\n return date.toISOString();\n}\n\n/**\n * Decodes an ISO 8601 string to a Date.\n * Validates the string format first.\n *\n * @throws ValidationError if not a valid ISO datetime\n */\nexport function decodeDate(isoString: string): Date {\n validateIsoDate(isoString, \"date\");\n return new Date(isoString);\n}\n\n/**\n * Returns the current timestamp as an ISO string.\n */\nexport function nowIso(): string {\n return new Date().toISOString();\n}\n"]}
|