@ir-kit/codegen-core 0.1.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/README.md +1 -1
- package/dist/fs.d.ts +12 -0
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js +18 -2
- package/dist/fs.js.map +1 -1
- package/dist/identifiers.d.ts +6 -0
- package/dist/identifiers.d.ts.map +1 -1
- package/dist/identifiers.js +13 -0
- package/dist/identifiers.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/namespace.d.ts +34 -0
- package/dist/namespace.d.ts.map +1 -0
- package/dist/namespace.js +40 -0
- package/dist/namespace.js.map +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -51,4 +51,4 @@ defaultProjectName("./out/petstore-sdk"); // "petstore-sdk"
|
|
|
51
51
|
|
|
52
52
|
## Repo
|
|
53
53
|
|
|
54
|
-
Source at [
|
|
54
|
+
Source at [ahmedrowaihi/ir-kit](https://github.com/ahmedrowaihi/ir-kit/tree/main/packages/shared/codegen-core).
|
package/dist/fs.d.ts
CHANGED
|
@@ -15,4 +15,16 @@ export declare function assertSafeOutputDir(out: string): void;
|
|
|
15
15
|
* have a valid name slot.
|
|
16
16
|
*/
|
|
17
17
|
export declare function defaultProjectName(outputDir: string): string;
|
|
18
|
+
export interface OutputFile {
|
|
19
|
+
/** Path relative to the output directory. */
|
|
20
|
+
path: string;
|
|
21
|
+
/** File contents. */
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Write `files` under `out`, first wiping `out` unless `clean` is `false`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function writeOutput(out: string, files: ReadonlyArray<OutputFile>, { clean }?: {
|
|
28
|
+
clean?: boolean;
|
|
29
|
+
}): Promise<void>;
|
|
18
30
|
//# sourceMappingURL=fs.d.ts.map
|
package/dist/fs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAOrD;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,qBAAqB;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAChC,EAAE,KAAY,EAAE,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,OAAO,CAAC,IAAI,CAAC,CAUf"}
|
package/dist/fs.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdir, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { basename, dirname, join, parse as parsePath, resolve, } from "node:path";
|
|
2
3
|
/**
|
|
3
4
|
* Refuse to wipe the current working directory or a filesystem root.
|
|
4
5
|
* `clean: true` runs `rm -rf` on the resolved output directory at the
|
|
@@ -7,7 +8,8 @@ import { basename, parse as parsePath } from "node:path";
|
|
|
7
8
|
* positives — generators always want output under a dedicated subdir.
|
|
8
9
|
*/
|
|
9
10
|
export function assertSafeOutputDir(out) {
|
|
10
|
-
|
|
11
|
+
const dir = resolve(out);
|
|
12
|
+
if (dir === process.cwd() || dir === parsePath(dir).root) {
|
|
11
13
|
throw new Error(`Refusing to clean output directory: ${out} (would wipe cwd or filesystem root). Use a dedicated subdirectory.`);
|
|
12
14
|
}
|
|
13
15
|
}
|
|
@@ -23,4 +25,18 @@ export function defaultProjectName(outputDir) {
|
|
|
23
25
|
const base = basename(outputDir).replace(/[^A-Za-z0-9-]+/g, "-");
|
|
24
26
|
return base || "generated-sdk";
|
|
25
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Write `files` under `out`, first wiping `out` unless `clean` is `false`.
|
|
30
|
+
*/
|
|
31
|
+
export async function writeOutput(out, files, { clean = true } = {}) {
|
|
32
|
+
if (clean) {
|
|
33
|
+
assertSafeOutputDir(out);
|
|
34
|
+
await rm(out, { recursive: true, force: true });
|
|
35
|
+
}
|
|
36
|
+
for (const file of files) {
|
|
37
|
+
const full = join(out, file.path);
|
|
38
|
+
await mkdir(dirname(full), { recursive: true });
|
|
39
|
+
await writeFile(full, file.content);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
26
42
|
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EACL,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,KAAK,IAAI,SAAS,EAClB,OAAO,GACR,MAAM,WAAW,CAAC;AAEnB;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,GAAG,KAAK,OAAO,CAAC,GAAG,EAAE,IAAI,GAAG,KAAK,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CACb,uCAAuC,GAAG,qEAAqE,CAChH,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,MAAM,IAAI,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACjE,OAAO,IAAI,IAAI,eAAe,CAAC;AACjC,CAAC;AASD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,GAAW,EACX,KAAgC,EAChC,EAAE,KAAK,GAAG,IAAI,KAA0B,EAAE;IAE1C,IAAI,KAAK,EAAE,CAAC;QACV,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACzB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;AACH,CAAC"}
|
package/dist/identifiers.d.ts
CHANGED
|
@@ -48,4 +48,10 @@ export declare function escapeIfReserved(name: string, reserved: ReadonlySet<str
|
|
|
48
48
|
* pascal regex over the joined string.
|
|
49
49
|
*/
|
|
50
50
|
export declare function synthName(owner: string, path: ReadonlyArray<string>): string;
|
|
51
|
+
/**
|
|
52
|
+
* PascalCase that keeps `_` as a word separator (`Owner_Path` stays
|
|
53
|
+
* intact) while collapsing every other non-alphanumeric run. Leading
|
|
54
|
+
* digits get a `_` prefix. Empty results become `"Empty"`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function typeIdent(s: string): string;
|
|
51
57
|
//# sourceMappingURL=identifiers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAMxC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGvC;AAED;uEACuE;AACvE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;mEACmE;AACnE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;2BAE2B;AAC3B,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;+BAG+B;AAC/B,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAC/B,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAE5E"}
|
|
1
|
+
{"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAMxC;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAGvC;AAED;uEACuE;AACvE,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;mEACmE;AACnE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED;;2BAE2B;AAC3B,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;+BAG+B;AAC/B,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,EAC7B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAC/B,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAE5E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAO3C"}
|
package/dist/identifiers.js
CHANGED
|
@@ -69,4 +69,17 @@ export function escapeIfReserved(name, reserved, escape) {
|
|
|
69
69
|
export function synthName(owner, path) {
|
|
70
70
|
return [owner, ...path.map(pascal)].join("_");
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* PascalCase that keeps `_` as a word separator (`Owner_Path` stays
|
|
74
|
+
* intact) while collapsing every other non-alphanumeric run. Leading
|
|
75
|
+
* digits get a `_` prefix. Empty results become `"Empty"`.
|
|
76
|
+
*/
|
|
77
|
+
export function typeIdent(s) {
|
|
78
|
+
const p = s
|
|
79
|
+
.replace(/^[^a-zA-Z0-9_]+/, "")
|
|
80
|
+
.replace(/[^a-zA-Z0-9_]+$/, "")
|
|
81
|
+
.replace(/[^a-zA-Z0-9_]+(.)/g, (_, c) => c.toUpperCase())
|
|
82
|
+
.replace(/^./, (c) => c.toUpperCase());
|
|
83
|
+
return avoidLeadingDigit(p) || "Empty";
|
|
84
|
+
}
|
|
72
85
|
//# sourceMappingURL=identifiers.js.map
|
package/dist/identifiers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifiers.js","sourceRoot":"","sources":["../src/identifiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAC,CAAS;IAC9B,OAAO,CAAC;SACL,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SAC/D,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,CAAS;IAC7B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED;uEACuE;AACvE,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;mEACmE;AACnE,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,OAAO,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACrC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAC3E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O,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,OAAO,CAAC,iBAAiB,EAAE,EAAE,CAAC;SAC9B,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;SAChE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACzC,OAAO,iBAAiB,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { assertSafeOutputDir, defaultProjectName } from "./fs.js";
|
|
2
|
-
export { avoidLeadingDigit, camel, escapeIfReserved, pascal, safeCaseName, safeIdent, softCamel, synthName, } from "./identifiers.js";
|
|
1
|
+
export { assertSafeOutputDir, defaultProjectName, type OutputFile, writeOutput, } from "./fs.js";
|
|
2
|
+
export { avoidLeadingDigit, camel, escapeIfReserved, pascal, safeCaseName, safeIdent, softCamel, synthName, typeIdent, } from "./identifiers.js";
|
|
3
|
+
export { Namespace, type NamingPolicy } from "./namespace.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,UAAU,EACf,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,iBAAiB,EACjB,KAAK,EACL,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { assertSafeOutputDir, defaultProjectName } from "./fs.js";
|
|
2
|
-
export { avoidLeadingDigit, camel, escapeIfReserved, pascal, safeCaseName, safeIdent, softCamel, synthName, } from "./identifiers.js";
|
|
1
|
+
export { assertSafeOutputDir, defaultProjectName, writeOutput, } from "./fs.js";
|
|
2
|
+
export { avoidLeadingDigit, camel, escapeIfReserved, pascal, safeCaseName, safeIdent, softCamel, synthName, typeIdent, } from "./identifiers.js";
|
|
3
|
+
export { Namespace } from "./namespace.js";
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAElB,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,iBAAiB,EACjB,KAAK,EACL,gBAAgB,EAChB,MAAM,EACN,YAAY,EACZ,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAqB,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Target-specific rules for turning a source string into an identifier
|
|
3
|
+
* and resolving clashes. A {@link Namespace} applies one policy to every
|
|
4
|
+
* name it hands out, so declaration and reference sites can never
|
|
5
|
+
* disagree on spelling.
|
|
6
|
+
*/
|
|
7
|
+
export interface NamingPolicy {
|
|
8
|
+
/** Source string → candidate identifier. Must be deterministic. */
|
|
9
|
+
normalize(raw: string): string;
|
|
10
|
+
/** n-th alternative (n ≥ 2) when `base` is already owned by another
|
|
11
|
+
* key. Default: `${base}${n}`. */
|
|
12
|
+
disambiguate?(base: string, n: number): string;
|
|
13
|
+
/** Identifiers that are never handed out (keywords, runtime decls). */
|
|
14
|
+
reserved?: ReadonlySet<string>;
|
|
15
|
+
/** Treat names differing only by case as clashing. */
|
|
16
|
+
foldCase?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Owns a set of identifiers. Each name is claimed by a semantic key
|
|
20
|
+
* (`schema:Pet`, `synth:Pet/status`, a raw enum value, …). Claiming is
|
|
21
|
+
* idempotent per key, and two keys never receive the same name — clashes
|
|
22
|
+
* are resolved deterministically via the policy instead of throwing.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Namespace {
|
|
25
|
+
#private;
|
|
26
|
+
readonly policy: NamingPolicy;
|
|
27
|
+
constructor(policy: NamingPolicy);
|
|
28
|
+
/** Resolve `key` to its identifier, claiming `raw` (normalized) on
|
|
29
|
+
* first sight. Later calls with the same key return the same name
|
|
30
|
+
* whatever `raw` they pass. */
|
|
31
|
+
claim(key: string, raw?: string): string;
|
|
32
|
+
get(key: string): string | undefined;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,mEAAmE;IACnE,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B;uCACmC;IACnC,YAAY,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/C,uEAAuE;IACvE,QAAQ,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC/B,sDAAsD;IACtD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,SAAS;;IAIR,QAAQ,CAAC,MAAM,EAAE,YAAY;gBAApB,MAAM,EAAE,YAAY;IAIzC;;oCAEgC;IAChC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,MAAY,GAAG,MAAM;IAe7C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAOrC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Owns a set of identifiers. Each name is claimed by a semantic key
|
|
3
|
+
* (`schema:Pet`, `synth:Pet/status`, a raw enum value, …). Claiming is
|
|
4
|
+
* idempotent per key, and two keys never receive the same name — clashes
|
|
5
|
+
* are resolved deterministically via the policy instead of throwing.
|
|
6
|
+
*/
|
|
7
|
+
export class Namespace {
|
|
8
|
+
policy;
|
|
9
|
+
#byKey = new Map();
|
|
10
|
+
#taken = new Set();
|
|
11
|
+
constructor(policy) {
|
|
12
|
+
this.policy = policy;
|
|
13
|
+
for (const r of policy.reserved ?? [])
|
|
14
|
+
this.#taken.add(this.#fold(r));
|
|
15
|
+
}
|
|
16
|
+
/** Resolve `key` to its identifier, claiming `raw` (normalized) on
|
|
17
|
+
* first sight. Later calls with the same key return the same name
|
|
18
|
+
* whatever `raw` they pass. */
|
|
19
|
+
claim(key, raw = key) {
|
|
20
|
+
const existing = this.#byKey.get(key);
|
|
21
|
+
if (existing !== undefined)
|
|
22
|
+
return existing;
|
|
23
|
+
const base = this.policy.normalize(raw);
|
|
24
|
+
const disambiguate = this.policy.disambiguate ?? ((b, n) => `${b}${n}`);
|
|
25
|
+
let name = base;
|
|
26
|
+
for (let n = 2; this.#taken.has(this.#fold(name)); n++) {
|
|
27
|
+
name = disambiguate(base, n);
|
|
28
|
+
}
|
|
29
|
+
this.#taken.add(this.#fold(name));
|
|
30
|
+
this.#byKey.set(key, name);
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
get(key) {
|
|
34
|
+
return this.#byKey.get(key);
|
|
35
|
+
}
|
|
36
|
+
#fold(name) {
|
|
37
|
+
return this.policy.foldCase ? name.toLowerCase() : name;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=namespace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.js","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAkBA;;;;;GAKG;AACH,MAAM,OAAO,SAAS;IAIC;IAHZ,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IAEpC,YAAqB,MAAoB;QAApB,WAAM,GAAN,MAAM,CAAc;QACvC,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,IAAI,EAAE;YAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;oCAEgC;IAChC,KAAK,CAAC,GAAW,EAAE,MAAc,GAAG;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACtC,IAAI,QAAQ,KAAK,SAAS;YAAE,OAAO,QAAQ,CAAC;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACxC,MAAM,YAAY,GAChB,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACrE,IAAI,IAAI,GAAG,IAAI,CAAC;QAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YACvD,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1D,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ir-kit/codegen-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Spec-agnostic codegen primitives shared by OpenAPI and AsyncAPI generator families — identifier transforms (pascal/camel/safeIdent), filesystem safety, project-name derivation. Pure functions, no spec dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"shared",
|
|
11
11
|
"identifiers"
|
|
12
12
|
],
|
|
13
|
-
"homepage": "https://github.com/
|
|
13
|
+
"homepage": "https://github.com/ahmedrowaihi/ir-kit/tree/main/packages/shared/codegen-core",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/ahmedrowaihi/ir-kit/issues"
|
|
16
16
|
},
|
|
17
17
|
"license": "MIT",
|
|
18
18
|
"author": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/
|
|
24
|
+
"url": "git+https://github.com/ahmedrowaihi/ir-kit.git",
|
|
25
25
|
"directory": "packages/shared/codegen-core"
|
|
26
26
|
},
|
|
27
27
|
"type": "module",
|