@rapidhuman/graph-common 1.0.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/chunking/index.d.ts +3 -0
- package/dist/chunking/index.d.ts.map +1 -0
- package/dist/chunking/index.js +19 -0
- package/dist/chunking/index.js.map +1 -0
- package/dist/chunking/pipeline.d.ts +30 -0
- package/dist/chunking/pipeline.d.ts.map +1 -0
- package/dist/chunking/pipeline.js +194 -0
- package/dist/chunking/pipeline.js.map +1 -0
- package/dist/chunking/types.d.ts +101 -0
- package/dist/chunking/types.d.ts.map +1 -0
- package/dist/chunking/types.js +3 -0
- package/dist/chunking/types.js.map +1 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +20 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/publisher.d.ts +36 -0
- package/dist/events/publisher.d.ts.map +1 -0
- package/dist/events/publisher.js +50 -0
- package/dist/events/publisher.js.map +1 -0
- package/dist/events/topics.d.ts +7 -0
- package/dist/events/topics.d.ts.map +1 -0
- package/dist/events/topics.js +10 -0
- package/dist/events/topics.js.map +1 -0
- package/dist/events/types.d.ts +49 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +3 -0
- package/dist/events/types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/relationships/helpers.d.ts +23 -0
- package/dist/relationships/helpers.d.ts.map +1 -0
- package/dist/relationships/helpers.js +54 -0
- package/dist/relationships/helpers.js.map +1 -0
- package/dist/relationships/index.d.ts +3 -0
- package/dist/relationships/index.d.ts.map +1 -0
- package/dist/relationships/index.js +19 -0
- package/dist/relationships/index.js.map +1 -0
- package/dist/relationships/types.d.ts +53 -0
- package/dist/relationships/types.d.ts.map +1 -0
- package/dist/relationships/types.js +50 -0
- package/dist/relationships/types.js.map +1 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +18 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/types.d.ts +152 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +3 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/uri/index.d.ts +3 -0
- package/dist/uri/index.d.ts.map +1 -0
- package/dist/uri/index.js +19 -0
- package/dist/uri/index.js.map +1 -0
- package/dist/uri/types.d.ts +31 -0
- package/dist/uri/types.d.ts.map +1 -0
- package/dist/uri/types.js +6 -0
- package/dist/uri/types.js.map +1 -0
- package/dist/uri/uri.d.ts +45 -0
- package/dist/uri/uri.d.ts.map +1 -0
- package/dist/uri/uri.js +136 -0
- package/dist/uri/uri.js.map +1 -0
- package/package.json +43 -0
package/dist/uri/uri.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createUri = createUri;
|
|
4
|
+
exports.parseUri = parseUri;
|
|
5
|
+
exports.validateUri = validateUri;
|
|
6
|
+
exports.extractSolution = extractSolution;
|
|
7
|
+
exports.extractArtifactType = extractArtifactType;
|
|
8
|
+
const types_1 = require("./types");
|
|
9
|
+
/**
|
|
10
|
+
* Regex matching the URI format: {project_id}:{solution}:{artifact_type}-{id}
|
|
11
|
+
*
|
|
12
|
+
* - project_id: alphanumeric + hyphens, must start with alphanumeric
|
|
13
|
+
* - solution: one of ideation, transformation, req, arch, spec, platform
|
|
14
|
+
* - artifact_type: lowercase letters + digits + hyphens, must start with letter
|
|
15
|
+
* - id: alphanumeric characters
|
|
16
|
+
*/
|
|
17
|
+
const URI_REGEX = /^([a-zA-Z0-9][a-zA-Z0-9-]*):(intel|ideation|transformation|req|arch|spec|code|platform):([a-z][a-z0-9-]*)-([a-zA-Z0-9]+)$/;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a validated ArtifactUri from its component parts.
|
|
20
|
+
*
|
|
21
|
+
* @param projectId - Short project identifier (e.g., "acme")
|
|
22
|
+
* @param solution - Solution code (ideation, transformation, req, arch, spec, code, platform)
|
|
23
|
+
* @param artifactType - Artifact type (e.g., "persona", "user-story")
|
|
24
|
+
* @param id - Unique identifier within the solution
|
|
25
|
+
* @returns Branded ArtifactUri string
|
|
26
|
+
* @throws Error if any input is invalid
|
|
27
|
+
*/
|
|
28
|
+
function createUri(projectId, solution, artifactType, id) {
|
|
29
|
+
if (!projectId || !/^[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(projectId)) {
|
|
30
|
+
throw new Error(`Invalid projectId "${projectId}": must be alphanumeric with hyphens, starting with alphanumeric`);
|
|
31
|
+
}
|
|
32
|
+
if (!types_1.SOLUTION_CODES.includes(solution)) {
|
|
33
|
+
throw new Error(`Invalid solution "${solution}": must be one of ${types_1.SOLUTION_CODES.join(', ')}`);
|
|
34
|
+
}
|
|
35
|
+
if (!artifactType || !/^[a-z][a-z0-9-]*$/.test(artifactType)) {
|
|
36
|
+
throw new Error(`Invalid artifactType "${artifactType}": must be lowercase alphanumeric with hyphens, starting with a letter`);
|
|
37
|
+
}
|
|
38
|
+
if (!id || !/^[a-zA-Z0-9]+$/.test(id)) {
|
|
39
|
+
throw new Error(`Invalid id "${id}": must be alphanumeric`);
|
|
40
|
+
}
|
|
41
|
+
return `${projectId}:${solution}:${artifactType}-${id}`;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parses an ArtifactUri string into its component parts.
|
|
45
|
+
*
|
|
46
|
+
* @param uri - URI string to parse
|
|
47
|
+
* @returns ParsedUri with projectId, solution, artifactType, and id
|
|
48
|
+
* @throws Error if the URI does not match the expected format
|
|
49
|
+
*/
|
|
50
|
+
function parseUri(uri) {
|
|
51
|
+
const match = URI_REGEX.exec(uri);
|
|
52
|
+
if (!match) {
|
|
53
|
+
throw new Error(`Invalid URI "${uri}": expected format {project_id}:{solution}:{artifact_type}-{id}`);
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
projectId: match[1],
|
|
57
|
+
solution: match[2],
|
|
58
|
+
artifactType: match[3],
|
|
59
|
+
id: match[4],
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validates a URI string without throwing. Returns a result object
|
|
64
|
+
* indicating whether the URI is valid, with a descriptive error if not.
|
|
65
|
+
*
|
|
66
|
+
* @param uri - URI string to validate
|
|
67
|
+
* @returns ValidationResult with valid boolean and optional error message
|
|
68
|
+
*/
|
|
69
|
+
function validateUri(uri) {
|
|
70
|
+
if (!uri) {
|
|
71
|
+
return { valid: false, error: 'URI is empty' };
|
|
72
|
+
}
|
|
73
|
+
const parts = uri.split(':');
|
|
74
|
+
if (parts.length !== 3) {
|
|
75
|
+
return {
|
|
76
|
+
valid: false,
|
|
77
|
+
error: `URI must have exactly 3 colon-separated parts, found ${parts.length}`,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const [projectId, solution, typeAndId] = parts;
|
|
81
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9-]*$/.test(projectId)) {
|
|
82
|
+
return {
|
|
83
|
+
valid: false,
|
|
84
|
+
error: `Invalid project_id "${projectId}": must be alphanumeric with hyphens, starting with alphanumeric`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (!types_1.SOLUTION_CODES.includes(solution)) {
|
|
88
|
+
return {
|
|
89
|
+
valid: false,
|
|
90
|
+
error: `Invalid solution "${solution}": must be one of ${types_1.SOLUTION_CODES.join(', ')}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const dashIndex = typeAndId.lastIndexOf('-');
|
|
94
|
+
if (dashIndex === -1) {
|
|
95
|
+
return {
|
|
96
|
+
valid: false,
|
|
97
|
+
error: `Invalid type-id "${typeAndId}": must contain a hyphen separating artifact_type and id`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const artifactType = typeAndId.substring(0, dashIndex);
|
|
101
|
+
const id = typeAndId.substring(dashIndex + 1);
|
|
102
|
+
if (!/^[a-z][a-z0-9-]*$/.test(artifactType)) {
|
|
103
|
+
return {
|
|
104
|
+
valid: false,
|
|
105
|
+
error: `Invalid artifact_type "${artifactType}": must be lowercase alphanumeric with hyphens, starting with a letter`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (!id || !/^[a-zA-Z0-9]+$/.test(id)) {
|
|
109
|
+
return {
|
|
110
|
+
valid: false,
|
|
111
|
+
error: `Invalid id "${id}": must be alphanumeric and non-empty`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return { valid: true };
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Extracts the solution code from a URI string.
|
|
118
|
+
*
|
|
119
|
+
* @param uri - URI string to extract from
|
|
120
|
+
* @returns SolutionCode
|
|
121
|
+
* @throws Error if the URI is invalid
|
|
122
|
+
*/
|
|
123
|
+
function extractSolution(uri) {
|
|
124
|
+
return parseUri(uri).solution;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Extracts the artifact type from a URI string.
|
|
128
|
+
*
|
|
129
|
+
* @param uri - URI string to extract from
|
|
130
|
+
* @returns ArtifactType
|
|
131
|
+
* @throws Error if the URI is invalid
|
|
132
|
+
*/
|
|
133
|
+
function extractArtifactType(uri) {
|
|
134
|
+
return parseUri(uri).artifactType;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=uri.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uri.js","sourceRoot":"","sources":["../../src/uri/uri.ts"],"names":[],"mappings":";;AA8BA,8BA+BC;AASD,4BAeC;AASD,kCAuDC;AASD,0CAEC;AASD,kDAEC;AA3KD,mCAQiB;AAEjB;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG,2HAA2H,CAAC;AAE9I;;;;;;;;;GASG;AACH,SAAgB,SAAS,CACvB,SAAoB,EACpB,QAAsB,EACtB,YAA0B,EA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CAAC,YAAY,CAAC,EAAE,CAAC;QAC5C,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,0BAA0B,YAAY,wEAAwE;SACtH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,EAAE,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;QACtC,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,eAAe,EAAE,uCAAuC;SAChE,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACzB,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,GAAW;IACzC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC;AACpC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rapidhuman/graph-common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared types, utilities, and interfaces for the Rapidhuman Graph RAG architecture",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepare": "npm run build",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"clean": "rimraf dist"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"rapidhuman",
|
|
18
|
+
"graph-rag",
|
|
19
|
+
"spanner"
|
|
20
|
+
],
|
|
21
|
+
"author": "Rapidhuman",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public",
|
|
25
|
+
"registry": "https://registry.npmjs.org/"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/Rapidhuman-AI/rapidhuman-graph-common.git"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@google-cloud/pubsub": "^4.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@google-cloud/pubsub": "^4.0.0",
|
|
36
|
+
"@types/jest": "^29.5.0",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"jest": "^29.7.0",
|
|
39
|
+
"rimraf": "^5.0.0",
|
|
40
|
+
"ts-jest": "^29.1.0",
|
|
41
|
+
"typescript": "^5.4.0"
|
|
42
|
+
}
|
|
43
|
+
}
|