@neuledge/graph-router 0.2.0 → 0.3.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/matcher.js +14 -7
- package/dist/matcher.js.map +1 -1
- package/dist/router.js +35 -35
- package/dist/router.js.map +1 -1
- package/package.json +2 -2
package/dist/matcher.js
CHANGED
|
@@ -8,22 +8,29 @@ export class NeuledgeGraphMatcher {
|
|
|
8
8
|
}
|
|
9
9
|
match(args) {
|
|
10
10
|
const match = args.path.match(this.regex);
|
|
11
|
-
if (!match
|
|
11
|
+
if (!match)
|
|
12
12
|
return null;
|
|
13
13
|
return {
|
|
14
14
|
template: this.template,
|
|
15
|
-
params: Object.fromEntries(Object.entries(match.groups).map(([key, value]) => [
|
|
15
|
+
params: Object.fromEntries(Object.entries(match.groups ?? {}).map(([key, value]) => [
|
|
16
16
|
key,
|
|
17
17
|
decodePathPart(value),
|
|
18
18
|
])),
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
static generateRegex(template) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
try {
|
|
23
|
+
const escaped = template.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
|
+
const regexString = escaped.replace(/\\\{(\w+)\\\}/g, (_, name) => `(?<${name}>[^.]+?)`);
|
|
25
|
+
return new RegExp(`^${regexString}$`);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (err instanceof SyntaxError) {
|
|
29
|
+
const message = err.message.split(": ").at(-1) || "Syntax error";
|
|
30
|
+
throw new Error(`Invalid template "${template}": ${message}`);
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
//# sourceMappingURL=matcher.js.map
|
package/dist/matcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matcher.js","sourceRo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C,aAAa,CAAC,QAAgB;QAC3C,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;YAEhE,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CACjC,gBAAgB,EAChB,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,UAAU,CAClC,CAAC;YAEF,OAAO,IAAI,MAAM,CAAC,IAAI,WAAW,GAAG,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,YAAY,WAAW,EAAE,CAAC;gBAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC;gBACjE,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;YAChE,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
package/dist/router.js
CHANGED
|
@@ -8,43 +8,43 @@ export class NeuledgeGraphRouter {
|
|
|
8
8
|
async lookup(params) {
|
|
9
9
|
const path = normalizePath(params.query);
|
|
10
10
|
const match = await this.registry.match({ path });
|
|
11
|
-
if (match) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
if (!match) {
|
|
12
|
+
const suggestions = await this.registry.suggestions({
|
|
13
|
+
path,
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
status: "ambiguous",
|
|
17
|
+
reasonCode: "UNKNOWN_PATH",
|
|
18
|
+
reasonHint: "Try using one of the suggested templates",
|
|
19
|
+
suggestions: suggestions.map((r) => ({
|
|
20
|
+
template: r.template,
|
|
21
|
+
})),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const value = await this.registry.resolve(match);
|
|
26
|
+
return {
|
|
27
|
+
status: "matched",
|
|
28
|
+
match,
|
|
29
|
+
value,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!(error instanceof NeuledgeError)) {
|
|
34
|
+
throw error;
|
|
35
35
|
}
|
|
36
|
+
const suggestions = await this.registry.suggestions({
|
|
37
|
+
path: match.template,
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
status: "ambiguous",
|
|
41
|
+
reasonCode: "INVALID_IDENTIFIER",
|
|
42
|
+
reasonHint: error.message,
|
|
43
|
+
suggestions: suggestions.map((r) => ({
|
|
44
|
+
template: r.template,
|
|
45
|
+
})),
|
|
46
|
+
};
|
|
36
47
|
}
|
|
37
|
-
const suggestions = await this.registry.suggestions({
|
|
38
|
-
path,
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
status: "ambiguous",
|
|
42
|
-
reasonCode: "UNKNOWN_PATH",
|
|
43
|
-
reasonHint: "Try using one of the suggested templates",
|
|
44
|
-
suggestions: suggestions.map((r) => ({
|
|
45
|
-
template: r.template,
|
|
46
|
-
})),
|
|
47
|
-
};
|
|
48
48
|
}
|
|
49
49
|
formatError(error) {
|
|
50
50
|
return {
|
package/dist/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,GAGd,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,OAAO,mBAAmB;IACr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,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACjD,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,KAAK;gBACL,KAAK;aACN,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,aAAa,CAAC,EAAE,CAAC;gBACtC,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAClD,IAAI,EAAE,KAAK,CAAC,QAAQ;aACrB,CAAC,CAAC;YAEH,OAAO;gBACL,MAAM,EAAE,WAAW;gBACnB,UAAU,EAAE,oBAAoB;gBAChC,UAAU,EAAE,KAAK,CAAC,OAAO;gBACzB,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;oBACnC,QAAQ,EAAE,CAAC,CAAC,QAAQ;iBACrB,CAAC,CAAC;aACJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED,WAAW,CAAC,KAAc;QACxB,OAAO;YACL,KAAK,EAAE;gBACL,OAAO,EAAE,MAAM,CAAE,KAAe,EAAE,OAAO,IAAI,KAAK,CAAC;aACpD;SACF,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neuledge/graph-router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Router for pattern matching and resolution of queries against data source registries.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typescript": "^5.9.3",
|
|
49
49
|
"vite-tsconfig-paths": "^5.1.4",
|
|
50
50
|
"vitest": "^4.0.3",
|
|
51
|
-
"@neuledge/graph": "0.
|
|
51
|
+
"@neuledge/graph": "0.3.0"
|
|
52
52
|
},
|
|
53
53
|
"tsx": {
|
|
54
54
|
"require": [
|