@rwdocs/backstage-plugin-rw-common 0.1.4
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/config.d.ts +56 -0
- package/dist/config.cjs.js +30 -0
- package/dist/config.cjs.js.map +1 -0
- package/dist/config.esm.js +28 -0
- package/dist/config.esm.js.map +1 -0
- package/dist/entityPath.cjs.js +22 -0
- package/dist/entityPath.cjs.js.map +1 -0
- package/dist/entityPath.esm.js +19 -0
- package/dist/entityPath.esm.js.map +1 -0
- package/dist/index.cjs.js +13 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.esm.js +4 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/parseAnnotation.cjs.js +34 -0
- package/dist/parseAnnotation.cjs.js.map +1 -0
- package/dist/parseAnnotation.esm.js +32 -0
- package/dist/parseAnnotation.esm.js.map +1 -0
- package/package.json +75 -0
package/config.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface Config {
|
|
2
|
+
/** @visibility backend */
|
|
3
|
+
rw?: {
|
|
4
|
+
/**
|
|
5
|
+
* Local directory containing documentation source files.
|
|
6
|
+
* Mutually exclusive with `s3`.
|
|
7
|
+
*/
|
|
8
|
+
projectDir?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Entity ref that the local projectDir serves as (required when projectDir is set).
|
|
11
|
+
* Standard Backstage entity ref format: "kind:namespace/name" (e.g. "component:default/my-docs")
|
|
12
|
+
*/
|
|
13
|
+
entity?: string;
|
|
14
|
+
/** Maximum number of cached RwSite instances. Default: 20. */
|
|
15
|
+
cacheSize?: number;
|
|
16
|
+
/**
|
|
17
|
+
* How often to check cached sites for upstream changes and reload if needed.
|
|
18
|
+
* If not set, no periodic reloading is performed.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```yaml
|
|
22
|
+
* rw:
|
|
23
|
+
* reloadInterval: { minutes: 5 }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
reloadInterval?: import("@backstage/types").HumanDuration;
|
|
27
|
+
/**
|
|
28
|
+
* S3 storage configuration. Shared across all entity sites.
|
|
29
|
+
* Mutually exclusive with `projectDir`.
|
|
30
|
+
*/
|
|
31
|
+
s3?: {
|
|
32
|
+
/** S3 bucket name. */
|
|
33
|
+
bucket: string;
|
|
34
|
+
/** AWS region. */
|
|
35
|
+
region?: string;
|
|
36
|
+
/** Custom S3 endpoint URL. */
|
|
37
|
+
endpoint?: string;
|
|
38
|
+
/** Root path within the bucket. */
|
|
39
|
+
bucketRootPath?: string;
|
|
40
|
+
/** AWS access key ID. */
|
|
41
|
+
accessKeyId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* AWS secret access key.
|
|
44
|
+
* @visibility secret
|
|
45
|
+
*/
|
|
46
|
+
secretAccessKey?: string;
|
|
47
|
+
};
|
|
48
|
+
/** Diagram rendering configuration. Shared across all sites. */
|
|
49
|
+
diagrams?: {
|
|
50
|
+
/** Kroki server URL for rendering diagrams. */
|
|
51
|
+
krokiUrl?: string;
|
|
52
|
+
/** Diagram rendering DPI. */
|
|
53
|
+
dpi?: number;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function readRwSiteConfig(config) {
|
|
4
|
+
const projectDir = config.getOptionalString("rw.projectDir");
|
|
5
|
+
const entity = config.getOptionalString("rw.entity");
|
|
6
|
+
const s3Config = config.getOptionalConfig("rw.s3");
|
|
7
|
+
const s3 = s3Config ? {
|
|
8
|
+
bucket: s3Config.getString("bucket"),
|
|
9
|
+
region: s3Config.getOptionalString("region"),
|
|
10
|
+
endpoint: s3Config.getOptionalString("endpoint"),
|
|
11
|
+
bucketRootPath: s3Config.getOptionalString("bucketRootPath"),
|
|
12
|
+
accessKeyId: s3Config.getOptionalString("accessKeyId"),
|
|
13
|
+
secretAccessKey: s3Config.getOptionalString("secretAccessKey")
|
|
14
|
+
} : void 0;
|
|
15
|
+
const diagramsConfig = config.getOptionalConfig("rw.diagrams");
|
|
16
|
+
const diagrams = diagramsConfig ? {
|
|
17
|
+
krokiUrl: diagramsConfig.getOptionalString("krokiUrl"),
|
|
18
|
+
dpi: diagramsConfig.getOptionalNumber("dpi")
|
|
19
|
+
} : void 0;
|
|
20
|
+
if (!projectDir && !s3) {
|
|
21
|
+
throw new Error("Either rw.projectDir or rw.s3 must be configured");
|
|
22
|
+
}
|
|
23
|
+
if (projectDir && !entity) {
|
|
24
|
+
throw new Error("rw.entity is required when rw.projectDir is set");
|
|
25
|
+
}
|
|
26
|
+
return { projectDir, entity, s3, diagrams };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.readRwSiteConfig = readRwSiteConfig;
|
|
30
|
+
//# sourceMappingURL=config.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.cjs.js","sources":["../src/config.ts"],"sourcesContent":["import type { Config } from \"@backstage/config\";\n\nexport interface S3Config {\n bucket: string;\n region?: string;\n endpoint?: string;\n bucketRootPath?: string;\n accessKeyId?: string;\n secretAccessKey?: string;\n}\n\nexport interface RwDiagramsConfig {\n krokiUrl?: string;\n dpi?: number;\n}\n\nexport interface RwSiteConfig {\n projectDir?: string;\n entity?: string;\n s3?: S3Config;\n diagrams?: RwDiagramsConfig;\n}\n\n/**\n * Reads the shared `rw` site configuration from Backstage config.\n *\n * Validates that either `rw.projectDir` or `rw.s3` is set, and that\n * `rw.entity` is present when `rw.projectDir` is used.\n */\nexport function readRwSiteConfig(config: Config): RwSiteConfig {\n const projectDir = config.getOptionalString(\"rw.projectDir\");\n const entity = config.getOptionalString(\"rw.entity\");\n\n const s3Config = config.getOptionalConfig(\"rw.s3\");\n const s3 = s3Config\n ? {\n bucket: s3Config.getString(\"bucket\"),\n region: s3Config.getOptionalString(\"region\"),\n endpoint: s3Config.getOptionalString(\"endpoint\"),\n bucketRootPath: s3Config.getOptionalString(\"bucketRootPath\"),\n accessKeyId: s3Config.getOptionalString(\"accessKeyId\"),\n secretAccessKey: s3Config.getOptionalString(\"secretAccessKey\"),\n }\n : undefined;\n\n const diagramsConfig = config.getOptionalConfig(\"rw.diagrams\");\n const diagrams = diagramsConfig\n ? {\n krokiUrl: diagramsConfig.getOptionalString(\"krokiUrl\"),\n dpi: diagramsConfig.getOptionalNumber(\"dpi\"),\n }\n : undefined;\n\n if (!projectDir && !s3) {\n throw new Error(\"Either rw.projectDir or rw.s3 must be configured\");\n }\n\n if (projectDir && !entity) {\n throw new Error(\"rw.entity is required when rw.projectDir is set\");\n }\n\n return { projectDir, entity, s3, diagrams };\n}\n"],"names":[],"mappings":";;AA6BO,SAAS,iBAAiB,MAAA,EAA8B;AAC7D,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,iBAAA,CAAkB,eAAe,CAAA;AAC3D,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,WAAW,CAAA;AAEnD,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AACjD,EAAA,MAAM,KAAK,QAAA,GACP;AAAA,IACE,MAAA,EAAQ,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA;AAAA,IACnC,MAAA,EAAQ,QAAA,CAAS,iBAAA,CAAkB,QAAQ,CAAA;AAAA,IAC3C,QAAA,EAAU,QAAA,CAAS,iBAAA,CAAkB,UAAU,CAAA;AAAA,IAC/C,cAAA,EAAgB,QAAA,CAAS,iBAAA,CAAkB,gBAAgB,CAAA;AAAA,IAC3D,WAAA,EAAa,QAAA,CAAS,iBAAA,CAAkB,aAAa,CAAA;AAAA,IACrD,eAAA,EAAiB,QAAA,CAAS,iBAAA,CAAkB,iBAAiB;AAAA,GAC/D,GACA,MAAA;AAEJ,EAAA,MAAM,cAAA,GAAiB,MAAA,CAAO,iBAAA,CAAkB,aAAa,CAAA;AAC7D,EAAA,MAAM,WAAW,cAAA,GACb;AAAA,IACE,QAAA,EAAU,cAAA,CAAe,iBAAA,CAAkB,UAAU,CAAA;AAAA,IACrD,GAAA,EAAK,cAAA,CAAe,iBAAA,CAAkB,KAAK;AAAA,GAC7C,GACA,MAAA;AAEJ,EAAA,IAAI,CAAC,UAAA,IAAc,CAAC,EAAA,EAAI;AACtB,IAAA,MAAM,IAAI,MAAM,kDAAkD,CAAA;AAAA,EACpE;AAEA,EAAA,IAAI,UAAA,IAAc,CAAC,MAAA,EAAQ;AACzB,IAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;AAAA,EACnE;AAEA,EAAA,OAAO,EAAE,UAAA,EAAY,MAAA,EAAQ,EAAA,EAAI,QAAA,EAAS;AAC5C;;;;"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function readRwSiteConfig(config) {
|
|
2
|
+
const projectDir = config.getOptionalString("rw.projectDir");
|
|
3
|
+
const entity = config.getOptionalString("rw.entity");
|
|
4
|
+
const s3Config = config.getOptionalConfig("rw.s3");
|
|
5
|
+
const s3 = s3Config ? {
|
|
6
|
+
bucket: s3Config.getString("bucket"),
|
|
7
|
+
region: s3Config.getOptionalString("region"),
|
|
8
|
+
endpoint: s3Config.getOptionalString("endpoint"),
|
|
9
|
+
bucketRootPath: s3Config.getOptionalString("bucketRootPath"),
|
|
10
|
+
accessKeyId: s3Config.getOptionalString("accessKeyId"),
|
|
11
|
+
secretAccessKey: s3Config.getOptionalString("secretAccessKey")
|
|
12
|
+
} : void 0;
|
|
13
|
+
const diagramsConfig = config.getOptionalConfig("rw.diagrams");
|
|
14
|
+
const diagrams = diagramsConfig ? {
|
|
15
|
+
krokiUrl: diagramsConfig.getOptionalString("krokiUrl"),
|
|
16
|
+
dpi: diagramsConfig.getOptionalNumber("dpi")
|
|
17
|
+
} : void 0;
|
|
18
|
+
if (!projectDir && !s3) {
|
|
19
|
+
throw new Error("Either rw.projectDir or rw.s3 must be configured");
|
|
20
|
+
}
|
|
21
|
+
if (projectDir && !entity) {
|
|
22
|
+
throw new Error("rw.entity is required when rw.projectDir is set");
|
|
23
|
+
}
|
|
24
|
+
return { projectDir, entity, s3, diagrams };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { readRwSiteConfig };
|
|
28
|
+
//# sourceMappingURL=config.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.esm.js","sources":["../src/config.ts"],"sourcesContent":["import type { Config } from \"@backstage/config\";\n\nexport interface S3Config {\n bucket: string;\n region?: string;\n endpoint?: string;\n bucketRootPath?: string;\n accessKeyId?: string;\n secretAccessKey?: string;\n}\n\nexport interface RwDiagramsConfig {\n krokiUrl?: string;\n dpi?: number;\n}\n\nexport interface RwSiteConfig {\n projectDir?: string;\n entity?: string;\n s3?: S3Config;\n diagrams?: RwDiagramsConfig;\n}\n\n/**\n * Reads the shared `rw` site configuration from Backstage config.\n *\n * Validates that either `rw.projectDir` or `rw.s3` is set, and that\n * `rw.entity` is present when `rw.projectDir` is used.\n */\nexport function readRwSiteConfig(config: Config): RwSiteConfig {\n const projectDir = config.getOptionalString(\"rw.projectDir\");\n const entity = config.getOptionalString(\"rw.entity\");\n\n const s3Config = config.getOptionalConfig(\"rw.s3\");\n const s3 = s3Config\n ? {\n bucket: s3Config.getString(\"bucket\"),\n region: s3Config.getOptionalString(\"region\"),\n endpoint: s3Config.getOptionalString(\"endpoint\"),\n bucketRootPath: s3Config.getOptionalString(\"bucketRootPath\"),\n accessKeyId: s3Config.getOptionalString(\"accessKeyId\"),\n secretAccessKey: s3Config.getOptionalString(\"secretAccessKey\"),\n }\n : undefined;\n\n const diagramsConfig = config.getOptionalConfig(\"rw.diagrams\");\n const diagrams = diagramsConfig\n ? {\n krokiUrl: diagramsConfig.getOptionalString(\"krokiUrl\"),\n dpi: diagramsConfig.getOptionalNumber(\"dpi\"),\n }\n : undefined;\n\n if (!projectDir && !s3) {\n throw new Error(\"Either rw.projectDir or rw.s3 must be configured\");\n }\n\n if (projectDir && !entity) {\n throw new Error(\"rw.entity is required when rw.projectDir is set\");\n }\n\n return { projectDir, entity, s3, diagrams };\n}\n"],"names":[],"mappings":"AA6BO,SAAS,iBAAiB,MAAA,EAA8B;AAC7D,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,iBAAA,CAAkB,eAAe,CAAA;AAC3D,EAAA,MAAM,MAAA,GAAS,MAAA,CAAO,iBAAA,CAAkB,WAAW,CAAA;AAEnD,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,iBAAA,CAAkB,OAAO,CAAA;AACjD,EAAA,MAAM,KAAK,QAAA,GACP;AAAA,IACE,MAAA,EAAQ,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA;AAAA,IACnC,MAAA,EAAQ,QAAA,CAAS,iBAAA,CAAkB,QAAQ,CAAA;AAAA,IAC3C,QAAA,EAAU,QAAA,CAAS,iBAAA,CAAkB,UAAU,CAAA;AAAA,IAC/C,cAAA,EAAgB,QAAA,CAAS,iBAAA,CAAkB,gBAAgB,CAAA;AAAA,IAC3D,WAAA,EAAa,QAAA,CAAS,iBAAA,CAAkB,aAAa,CAAA;AAAA,IACrD,eAAA,EAAiB,QAAA,CAAS,iBAAA,CAAkB,iBAAiB;AAAA,GAC/D,GACA,MAAA;AAEJ,EAAA,MAAM,cAAA,GAAiB,MAAA,CAAO,iBAAA,CAAkB,aAAa,CAAA;AAC7D,EAAA,MAAM,WAAW,cAAA,GACb;AAAA,IACE,QAAA,EAAU,cAAA,CAAe,iBAAA,CAAkB,UAAU,CAAA;AAAA,IACrD,GAAA,EAAK,cAAA,CAAe,iBAAA,CAAkB,KAAK;AAAA,GAC7C,GACA,MAAA;AAEJ,EAAA,IAAI,CAAC,UAAA,IAAc,CAAC,EAAA,EAAI;AACtB,IAAA,MAAM,IAAI,MAAM,kDAAkD,CAAA;AAAA,EACpE;AAEA,EAAA,IAAI,UAAA,IAAc,CAAC,MAAA,EAAQ;AACzB,IAAA,MAAM,IAAI,MAAM,iDAAiD,CAAA;AAAA,EACnE;AAEA,EAAA,OAAO,EAAE,UAAA,EAAY,MAAA,EAAQ,EAAA,EAAI,QAAA,EAAS;AAC5C;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
4
|
+
var errors = require('@backstage/errors');
|
|
5
|
+
|
|
6
|
+
function toEntityPath(ref) {
|
|
7
|
+
const parsed = typeof ref === "string" ? catalogModel.parseEntityRef(ref) : ref;
|
|
8
|
+
const ns = parsed.namespace ?? "default";
|
|
9
|
+
return `${ns}/${parsed.kind}/${parsed.name}`.toLocaleLowerCase("en-US");
|
|
10
|
+
}
|
|
11
|
+
function fromEntityPath(path) {
|
|
12
|
+
const parts = path.split("/");
|
|
13
|
+
if (parts.length !== 3 || parts.some((p) => !p)) {
|
|
14
|
+
throw new errors.InputError(`Invalid entity path: "${path}" (expected "namespace/kind/name")`);
|
|
15
|
+
}
|
|
16
|
+
const [namespace, kind, name] = parts;
|
|
17
|
+
return catalogModel.stringifyEntityRef({ kind, namespace, name });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.fromEntityPath = fromEntityPath;
|
|
21
|
+
exports.toEntityPath = toEntityPath;
|
|
22
|
+
//# sourceMappingURL=entityPath.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityPath.cjs.js","sources":["../src/entityPath.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from \"@backstage/catalog-model\";\nimport { InputError } from \"@backstage/errors\";\n\n/**\n * Converts an entity ref (e.g. \"component:default/arch\") or a compound ref\n * object to the slash-delimited, lowercased path used in API URLs\n * (e.g. \"default/component/arch\").\n *\n * Uses namespace/kind/name ordering to match Backstage catalog URL convention.\n */\nexport function toEntityPath(\n ref: string | { kind: string; namespace?: string; name: string },\n): string {\n const parsed = typeof ref === \"string\" ? parseEntityRef(ref) : ref;\n const ns = parsed.namespace ?? \"default\";\n return `${ns}/${parsed.kind}/${parsed.name}`.toLocaleLowerCase(\"en-US\");\n}\n\n/**\n * Converts a slash-delimited entity path (e.g. \"default/component/arch\")\n * back to the standard Backstage entity ref format (e.g. \"component:default/arch\").\n *\n * This is the inverse of `toEntityPath`. Note that the round-trip always\n * produces lowercased refs since `toEntityPath` lowercases its output.\n */\nexport function fromEntityPath(path: string): string {\n const parts = path.split(\"/\");\n if (parts.length !== 3 || parts.some((p) => !p)) {\n throw new InputError(`Invalid entity path: \"${path}\" (expected \"namespace/kind/name\")`);\n }\n const [namespace, kind, name] = parts;\n return stringifyEntityRef({ kind, namespace, name });\n}\n"],"names":["parseEntityRef","InputError","stringifyEntityRef"],"mappings":";;;;;AAUO,SAAS,aACd,GAAA,EACQ;AACR,EAAA,MAAM,SAAS,OAAO,GAAA,KAAQ,QAAA,GAAWA,2BAAA,CAAe,GAAG,CAAA,GAAI,GAAA;AAC/D,EAAA,MAAM,EAAA,GAAK,OAAO,SAAA,IAAa,SAAA;AAC/B,EAAA,OAAO,CAAA,EAAG,EAAE,CAAA,CAAA,EAAI,MAAA,CAAO,IAAI,IAAI,MAAA,CAAO,IAAI,CAAA,CAAA,CAAG,iBAAA,CAAkB,OAAO,CAAA;AACxE;AASO,SAAS,eAAe,IAAA,EAAsB;AACnD,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC5B,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,IAAK,KAAA,CAAM,KAAK,CAAC,CAAA,KAAM,CAAC,CAAC,CAAA,EAAG;AAC/C,IAAA,MAAM,IAAIC,iBAAA,CAAW,CAAA,sBAAA,EAAyB,IAAI,CAAA,kCAAA,CAAoC,CAAA;AAAA,EACxF;AACA,EAAA,MAAM,CAAC,SAAA,EAAW,IAAA,EAAM,IAAI,CAAA,GAAI,KAAA;AAChC,EAAA,OAAOC,+BAAA,CAAmB,EAAE,IAAA,EAAM,SAAA,EAAW,MAAM,CAAA;AACrD;;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseEntityRef, stringifyEntityRef } from '@backstage/catalog-model';
|
|
2
|
+
import { InputError } from '@backstage/errors';
|
|
3
|
+
|
|
4
|
+
function toEntityPath(ref) {
|
|
5
|
+
const parsed = typeof ref === "string" ? parseEntityRef(ref) : ref;
|
|
6
|
+
const ns = parsed.namespace ?? "default";
|
|
7
|
+
return `${ns}/${parsed.kind}/${parsed.name}`.toLocaleLowerCase("en-US");
|
|
8
|
+
}
|
|
9
|
+
function fromEntityPath(path) {
|
|
10
|
+
const parts = path.split("/");
|
|
11
|
+
if (parts.length !== 3 || parts.some((p) => !p)) {
|
|
12
|
+
throw new InputError(`Invalid entity path: "${path}" (expected "namespace/kind/name")`);
|
|
13
|
+
}
|
|
14
|
+
const [namespace, kind, name] = parts;
|
|
15
|
+
return stringifyEntityRef({ kind, namespace, name });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { fromEntityPath, toEntityPath };
|
|
19
|
+
//# sourceMappingURL=entityPath.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entityPath.esm.js","sources":["../src/entityPath.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from \"@backstage/catalog-model\";\nimport { InputError } from \"@backstage/errors\";\n\n/**\n * Converts an entity ref (e.g. \"component:default/arch\") or a compound ref\n * object to the slash-delimited, lowercased path used in API URLs\n * (e.g. \"default/component/arch\").\n *\n * Uses namespace/kind/name ordering to match Backstage catalog URL convention.\n */\nexport function toEntityPath(\n ref: string | { kind: string; namespace?: string; name: string },\n): string {\n const parsed = typeof ref === \"string\" ? parseEntityRef(ref) : ref;\n const ns = parsed.namespace ?? \"default\";\n return `${ns}/${parsed.kind}/${parsed.name}`.toLocaleLowerCase(\"en-US\");\n}\n\n/**\n * Converts a slash-delimited entity path (e.g. \"default/component/arch\")\n * back to the standard Backstage entity ref format (e.g. \"component:default/arch\").\n *\n * This is the inverse of `toEntityPath`. Note that the round-trip always\n * produces lowercased refs since `toEntityPath` lowercases its output.\n */\nexport function fromEntityPath(path: string): string {\n const parts = path.split(\"/\");\n if (parts.length !== 3 || parts.some((p) => !p)) {\n throw new InputError(`Invalid entity path: \"${path}\" (expected \"namespace/kind/name\")`);\n }\n const [namespace, kind, name] = parts;\n return stringifyEntityRef({ kind, namespace, name });\n}\n"],"names":[],"mappings":";;;AAUO,SAAS,aACd,GAAA,EACQ;AACR,EAAA,MAAM,SAAS,OAAO,GAAA,KAAQ,QAAA,GAAW,cAAA,CAAe,GAAG,CAAA,GAAI,GAAA;AAC/D,EAAA,MAAM,EAAA,GAAK,OAAO,SAAA,IAAa,SAAA;AAC/B,EAAA,OAAO,CAAA,EAAG,EAAE,CAAA,CAAA,EAAI,MAAA,CAAO,IAAI,IAAI,MAAA,CAAO,IAAI,CAAA,CAAA,CAAG,iBAAA,CAAkB,OAAO,CAAA;AACxE;AASO,SAAS,eAAe,IAAA,EAAsB;AACnD,EAAA,MAAM,KAAA,GAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC5B,EAAA,IAAI,KAAA,CAAM,WAAW,CAAA,IAAK,KAAA,CAAM,KAAK,CAAC,CAAA,KAAM,CAAC,CAAC,CAAA,EAAG;AAC/C,IAAA,MAAM,IAAI,UAAA,CAAW,CAAA,sBAAA,EAAyB,IAAI,CAAA,kCAAA,CAAoC,CAAA;AAAA,EACxF;AACA,EAAA,MAAM,CAAC,SAAA,EAAW,IAAA,EAAM,IAAI,CAAA,GAAI,KAAA;AAChC,EAAA,OAAO,kBAAA,CAAmB,EAAE,IAAA,EAAM,SAAA,EAAW,MAAM,CAAA;AACrD;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var entityPath = require('./entityPath.cjs.js');
|
|
4
|
+
var parseAnnotation = require('./parseAnnotation.cjs.js');
|
|
5
|
+
var config = require('./config.cjs.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.fromEntityPath = entityPath.fromEntityPath;
|
|
10
|
+
exports.toEntityPath = entityPath.toEntityPath;
|
|
11
|
+
exports.parseAnnotation = parseAnnotation.parseAnnotation;
|
|
12
|
+
exports.readRwSiteConfig = config.readRwSiteConfig;
|
|
13
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Config } from '@backstage/config';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts an entity ref (e.g. "component:default/arch") or a compound ref
|
|
5
|
+
* object to the slash-delimited, lowercased path used in API URLs
|
|
6
|
+
* (e.g. "default/component/arch").
|
|
7
|
+
*
|
|
8
|
+
* Uses namespace/kind/name ordering to match Backstage catalog URL convention.
|
|
9
|
+
*/
|
|
10
|
+
declare function toEntityPath(ref: string | {
|
|
11
|
+
kind: string;
|
|
12
|
+
namespace?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
}): string;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a slash-delimited entity path (e.g. "default/component/arch")
|
|
17
|
+
* back to the standard Backstage entity ref format (e.g. "component:default/arch").
|
|
18
|
+
*
|
|
19
|
+
* This is the inverse of `toEntityPath`. Note that the round-trip always
|
|
20
|
+
* produces lowercased refs since `toEntityPath` lowercases its output.
|
|
21
|
+
*/
|
|
22
|
+
declare function fromEntityPath(path: string): string;
|
|
23
|
+
|
|
24
|
+
interface ParsedAnnotation {
|
|
25
|
+
/** Slash-delimited path for API URLs (e.g. "default/component/arch"). */
|
|
26
|
+
entityPath: string;
|
|
27
|
+
/** Standard Backstage entity ref (e.g. "component:default/arch"). */
|
|
28
|
+
entityRef: string;
|
|
29
|
+
sectionRef: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses an `rwdocs.org/ref` annotation value into its component parts.
|
|
33
|
+
*
|
|
34
|
+
* The annotation format is `<entityRef>[#<sectionRef>]`, where `entityRef` is
|
|
35
|
+
* a standard Backstage entity ref and `sectionRef` is an optional path within
|
|
36
|
+
* the documentation site.
|
|
37
|
+
*
|
|
38
|
+
* A special value of `"."` refers to the entity itself; this requires the
|
|
39
|
+
* `selfEntityPath` parameter to resolve.
|
|
40
|
+
*
|
|
41
|
+
* @param value - The raw annotation value
|
|
42
|
+
* @param selfEntityPath - The entity path of the entity bearing the annotation,
|
|
43
|
+
* required to resolve `"."` self-references
|
|
44
|
+
*/
|
|
45
|
+
declare function parseAnnotation(value: string | undefined, selfEntityPath?: string): ParsedAnnotation | undefined;
|
|
46
|
+
|
|
47
|
+
interface S3Config {
|
|
48
|
+
bucket: string;
|
|
49
|
+
region?: string;
|
|
50
|
+
endpoint?: string;
|
|
51
|
+
bucketRootPath?: string;
|
|
52
|
+
accessKeyId?: string;
|
|
53
|
+
secretAccessKey?: string;
|
|
54
|
+
}
|
|
55
|
+
interface RwDiagramsConfig {
|
|
56
|
+
krokiUrl?: string;
|
|
57
|
+
dpi?: number;
|
|
58
|
+
}
|
|
59
|
+
interface RwSiteConfig {
|
|
60
|
+
projectDir?: string;
|
|
61
|
+
entity?: string;
|
|
62
|
+
s3?: S3Config;
|
|
63
|
+
diagrams?: RwDiagramsConfig;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reads the shared `rw` site configuration from Backstage config.
|
|
67
|
+
*
|
|
68
|
+
* Validates that either `rw.projectDir` or `rw.s3` is set, and that
|
|
69
|
+
* `rw.entity` is present when `rw.projectDir` is used.
|
|
70
|
+
*/
|
|
71
|
+
declare function readRwSiteConfig(config: Config): RwSiteConfig;
|
|
72
|
+
|
|
73
|
+
export { fromEntityPath, parseAnnotation, readRwSiteConfig, toEntityPath };
|
|
74
|
+
export type { ParsedAnnotation, RwDiagramsConfig, RwSiteConfig, S3Config };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var catalogModel = require('@backstage/catalog-model');
|
|
4
|
+
var entityPath = require('./entityPath.cjs.js');
|
|
5
|
+
|
|
6
|
+
function parseAnnotation(value, selfEntityPath) {
|
|
7
|
+
if (!value) return void 0;
|
|
8
|
+
const hashIndex = value.indexOf("#");
|
|
9
|
+
let entity;
|
|
10
|
+
let sectionRef;
|
|
11
|
+
if (hashIndex === -1) {
|
|
12
|
+
entity = value;
|
|
13
|
+
sectionRef = void 0;
|
|
14
|
+
} else {
|
|
15
|
+
entity = value.slice(0, hashIndex);
|
|
16
|
+
sectionRef = value.slice(hashIndex + 1) || void 0;
|
|
17
|
+
}
|
|
18
|
+
if (entity === ".") {
|
|
19
|
+
if (!selfEntityPath) return void 0;
|
|
20
|
+
return { entityPath: selfEntityPath, entityRef: entityPath.fromEntityPath(selfEntityPath), sectionRef };
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
return {
|
|
24
|
+
entityPath: entityPath.toEntityPath(entity),
|
|
25
|
+
entityRef: catalogModel.stringifyEntityRef(catalogModel.parseEntityRef(entity)),
|
|
26
|
+
sectionRef
|
|
27
|
+
};
|
|
28
|
+
} catch {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.parseAnnotation = parseAnnotation;
|
|
34
|
+
//# sourceMappingURL=parseAnnotation.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseAnnotation.cjs.js","sources":["../src/parseAnnotation.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from \"@backstage/catalog-model\";\nimport { toEntityPath, fromEntityPath } from \"./entityPath\";\n\nexport interface ParsedAnnotation {\n /** Slash-delimited path for API URLs (e.g. \"default/component/arch\"). */\n entityPath: string;\n /** Standard Backstage entity ref (e.g. \"component:default/arch\"). */\n entityRef: string;\n sectionRef: string | undefined;\n}\n\n/**\n * Parses an `rwdocs.org/ref` annotation value into its component parts.\n *\n * The annotation format is `<entityRef>[#<sectionRef>]`, where `entityRef` is\n * a standard Backstage entity ref and `sectionRef` is an optional path within\n * the documentation site.\n *\n * A special value of `\".\"` refers to the entity itself; this requires the\n * `selfEntityPath` parameter to resolve.\n *\n * @param value - The raw annotation value\n * @param selfEntityPath - The entity path of the entity bearing the annotation,\n * required to resolve `\".\"` self-references\n */\nexport function parseAnnotation(\n value: string | undefined,\n selfEntityPath?: string,\n): ParsedAnnotation | undefined {\n if (!value) return undefined;\n\n const hashIndex = value.indexOf(\"#\");\n let entity: string;\n let sectionRef: string | undefined;\n\n if (hashIndex === -1) {\n entity = value;\n sectionRef = undefined;\n } else {\n entity = value.slice(0, hashIndex);\n sectionRef = value.slice(hashIndex + 1) || undefined;\n }\n\n if (entity === \".\") {\n if (!selfEntityPath) return undefined;\n return { entityPath: selfEntityPath, entityRef: fromEntityPath(selfEntityPath), sectionRef };\n }\n\n try {\n return {\n entityPath: toEntityPath(entity),\n entityRef: stringifyEntityRef(parseEntityRef(entity)),\n sectionRef,\n };\n } catch {\n return undefined;\n }\n}\n"],"names":["fromEntityPath","toEntityPath","stringifyEntityRef","parseEntityRef"],"mappings":";;;;;AAyBO,SAAS,eAAA,CACd,OACA,cAAA,EAC8B;AAC9B,EAAA,IAAI,CAAC,OAAO,OAAO,MAAA;AAEnB,EAAA,MAAM,SAAA,GAAY,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AACnC,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,UAAA;AAEJ,EAAA,IAAI,cAAc,EAAA,EAAI;AACpB,IAAA,MAAA,GAAS,KAAA;AACT,IAAA,UAAA,GAAa,MAAA;AAAA,EACf,CAAA,MAAO;AACL,IAAA,MAAA,GAAS,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA;AACjC,IAAA,UAAA,GAAa,KAAA,CAAM,KAAA,CAAM,SAAA,GAAY,CAAC,CAAA,IAAK,MAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,WAAW,GAAA,EAAK;AAClB,IAAA,IAAI,CAAC,gBAAgB,OAAO,MAAA;AAC5B,IAAA,OAAO,EAAE,UAAA,EAAY,cAAA,EAAgB,WAAWA,yBAAA,CAAe,cAAc,GAAG,UAAA,EAAW;AAAA,EAC7F;AAEA,EAAA,IAAI;AACF,IAAA,OAAO;AAAA,MACL,UAAA,EAAYC,wBAAa,MAAM,CAAA;AAAA,MAC/B,SAAA,EAAWC,+BAAA,CAAmBC,2BAAA,CAAe,MAAM,CAAC,CAAA;AAAA,MACpD;AAAA,KACF;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { stringifyEntityRef, parseEntityRef } from '@backstage/catalog-model';
|
|
2
|
+
import { fromEntityPath, toEntityPath } from './entityPath.esm.js';
|
|
3
|
+
|
|
4
|
+
function parseAnnotation(value, selfEntityPath) {
|
|
5
|
+
if (!value) return void 0;
|
|
6
|
+
const hashIndex = value.indexOf("#");
|
|
7
|
+
let entity;
|
|
8
|
+
let sectionRef;
|
|
9
|
+
if (hashIndex === -1) {
|
|
10
|
+
entity = value;
|
|
11
|
+
sectionRef = void 0;
|
|
12
|
+
} else {
|
|
13
|
+
entity = value.slice(0, hashIndex);
|
|
14
|
+
sectionRef = value.slice(hashIndex + 1) || void 0;
|
|
15
|
+
}
|
|
16
|
+
if (entity === ".") {
|
|
17
|
+
if (!selfEntityPath) return void 0;
|
|
18
|
+
return { entityPath: selfEntityPath, entityRef: fromEntityPath(selfEntityPath), sectionRef };
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
return {
|
|
22
|
+
entityPath: toEntityPath(entity),
|
|
23
|
+
entityRef: stringifyEntityRef(parseEntityRef(entity)),
|
|
24
|
+
sectionRef
|
|
25
|
+
};
|
|
26
|
+
} catch {
|
|
27
|
+
return void 0;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { parseAnnotation };
|
|
32
|
+
//# sourceMappingURL=parseAnnotation.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseAnnotation.esm.js","sources":["../src/parseAnnotation.ts"],"sourcesContent":["import { parseEntityRef, stringifyEntityRef } from \"@backstage/catalog-model\";\nimport { toEntityPath, fromEntityPath } from \"./entityPath\";\n\nexport interface ParsedAnnotation {\n /** Slash-delimited path for API URLs (e.g. \"default/component/arch\"). */\n entityPath: string;\n /** Standard Backstage entity ref (e.g. \"component:default/arch\"). */\n entityRef: string;\n sectionRef: string | undefined;\n}\n\n/**\n * Parses an `rwdocs.org/ref` annotation value into its component parts.\n *\n * The annotation format is `<entityRef>[#<sectionRef>]`, where `entityRef` is\n * a standard Backstage entity ref and `sectionRef` is an optional path within\n * the documentation site.\n *\n * A special value of `\".\"` refers to the entity itself; this requires the\n * `selfEntityPath` parameter to resolve.\n *\n * @param value - The raw annotation value\n * @param selfEntityPath - The entity path of the entity bearing the annotation,\n * required to resolve `\".\"` self-references\n */\nexport function parseAnnotation(\n value: string | undefined,\n selfEntityPath?: string,\n): ParsedAnnotation | undefined {\n if (!value) return undefined;\n\n const hashIndex = value.indexOf(\"#\");\n let entity: string;\n let sectionRef: string | undefined;\n\n if (hashIndex === -1) {\n entity = value;\n sectionRef = undefined;\n } else {\n entity = value.slice(0, hashIndex);\n sectionRef = value.slice(hashIndex + 1) || undefined;\n }\n\n if (entity === \".\") {\n if (!selfEntityPath) return undefined;\n return { entityPath: selfEntityPath, entityRef: fromEntityPath(selfEntityPath), sectionRef };\n }\n\n try {\n return {\n entityPath: toEntityPath(entity),\n entityRef: stringifyEntityRef(parseEntityRef(entity)),\n sectionRef,\n };\n } catch {\n return undefined;\n }\n}\n"],"names":[],"mappings":";;;AAyBO,SAAS,eAAA,CACd,OACA,cAAA,EAC8B;AAC9B,EAAA,IAAI,CAAC,OAAO,OAAO,MAAA;AAEnB,EAAA,MAAM,SAAA,GAAY,KAAA,CAAM,OAAA,CAAQ,GAAG,CAAA;AACnC,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI,UAAA;AAEJ,EAAA,IAAI,cAAc,EAAA,EAAI;AACpB,IAAA,MAAA,GAAS,KAAA;AACT,IAAA,UAAA,GAAa,MAAA;AAAA,EACf,CAAA,MAAO;AACL,IAAA,MAAA,GAAS,KAAA,CAAM,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA;AACjC,IAAA,UAAA,GAAa,KAAA,CAAM,KAAA,CAAM,SAAA,GAAY,CAAC,CAAA,IAAK,MAAA;AAAA,EAC7C;AAEA,EAAA,IAAI,WAAW,GAAA,EAAK;AAClB,IAAA,IAAI,CAAC,gBAAgB,OAAO,MAAA;AAC5B,IAAA,OAAO,EAAE,UAAA,EAAY,cAAA,EAAgB,WAAW,cAAA,CAAe,cAAc,GAAG,UAAA,EAAW;AAAA,EAC7F;AAEA,EAAA,IAAI;AACF,IAAA,OAAO;AAAA,MACL,UAAA,EAAY,aAAa,MAAM,CAAA;AAAA,MAC/B,SAAA,EAAW,kBAAA,CAAmB,cAAA,CAAe,MAAM,CAAC,CAAA;AAAA,MACpD;AAAA,KACF;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,MAAA;AAAA,EACT;AACF;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rwdocs/backstage-plugin-rw-common",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"license": "MIT OR Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/rwdocs/backstage-plugins.git",
|
|
8
|
+
"directory": "plugins/rw-common"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.esm.js",
|
|
15
|
+
"require": "./dist/index.cjs.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.cjs.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"main": "dist/index.cjs.js",
|
|
24
|
+
"module": "dist/index.esm.js",
|
|
25
|
+
"types": "dist/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"backstage": {
|
|
28
|
+
"role": "common-library",
|
|
29
|
+
"pluginId": "rw",
|
|
30
|
+
"pluginPackages": [
|
|
31
|
+
"@rwdocs/backstage-plugin-rw",
|
|
32
|
+
"@rwdocs/backstage-plugin-rw-backend",
|
|
33
|
+
"@rwdocs/backstage-plugin-rw-common"
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
"configSchema": "config.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist",
|
|
39
|
+
"config.d.ts",
|
|
40
|
+
"LICENSE-MIT",
|
|
41
|
+
"LICENSE-APACHE"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"start": "backstage-cli package start",
|
|
45
|
+
"build": "backstage-cli package build",
|
|
46
|
+
"lint": "backstage-cli package lint",
|
|
47
|
+
"test": "backstage-cli package test",
|
|
48
|
+
"clean": "backstage-cli package clean",
|
|
49
|
+
"format": "prettier --write src/",
|
|
50
|
+
"format:check": "prettier --check src/",
|
|
51
|
+
"prepack": "backstage-cli package prepack",
|
|
52
|
+
"postpack": "backstage-cli package postpack"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@backstage/catalog-model": "^1.7.6",
|
|
56
|
+
"@backstage/config": "^1.3.6",
|
|
57
|
+
"@backstage/errors": "^1.2.7",
|
|
58
|
+
"@backstage/types": "^1.2.2"
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@backstage/cli": "^0.36.0",
|
|
62
|
+
"@types/jest": "^30.0.0",
|
|
63
|
+
"jest": "^30.2.0",
|
|
64
|
+
"prettier": "^3.4.2",
|
|
65
|
+
"typescript": "^5.7.0"
|
|
66
|
+
},
|
|
67
|
+
"typesVersions": {
|
|
68
|
+
"*": {
|
|
69
|
+
"package.json": [
|
|
70
|
+
"package.json"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"module": "dist/index.esm.js"
|
|
75
|
+
}
|