@ojiepermana/angular 0.1.1 → 21.0.2

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.
Files changed (133) hide show
  1. package/README.md +41 -249
  2. package/collection.json +25 -0
  3. package/fesm2022/ojiepermana-angular-chart.mjs +3714 -0
  4. package/fesm2022/ojiepermana-angular-chart.mjs.map +1 -0
  5. package/fesm2022/ojiepermana-angular-component.mjs +3463 -0
  6. package/fesm2022/ojiepermana-angular-component.mjs.map +1 -0
  7. package/fesm2022/ojiepermana-angular-generator-api.mjs +67 -0
  8. package/fesm2022/ojiepermana-angular-generator-api.mjs.map +1 -0
  9. package/fesm2022/ojiepermana-angular-layout.mjs +296 -408
  10. package/fesm2022/ojiepermana-angular-layout.mjs.map +1 -1
  11. package/fesm2022/ojiepermana-angular-navigation.mjs +2198 -404
  12. package/fesm2022/ojiepermana-angular-navigation.mjs.map +1 -1
  13. package/fesm2022/ojiepermana-angular-theme.mjs +381 -1
  14. package/fesm2022/ojiepermana-angular-theme.mjs.map +1 -1
  15. package/fesm2022/ojiepermana-angular.mjs +16 -1
  16. package/fesm2022/ojiepermana-angular.mjs.map +1 -1
  17. package/generator/api/README.md +183 -0
  18. package/generator/api/bin/schematics/init/index.js +88 -0
  19. package/generator/api/bin/schematics/sdk/index.js +58 -0
  20. package/generator/api/bin/src/config/loader.js +41 -0
  21. package/generator/api/bin/src/config/schema.js +56 -0
  22. package/generator/api/bin/src/emit/client.js +246 -0
  23. package/generator/api/bin/src/emit/metadata.js +295 -0
  24. package/generator/api/bin/src/emit/models.js +106 -0
  25. package/generator/api/bin/src/emit/navigation.js +56 -0
  26. package/generator/api/bin/src/emit/operations.js +122 -0
  27. package/generator/api/bin/src/emit/public-api.js +54 -0
  28. package/generator/api/bin/src/emit/services.js +87 -0
  29. package/generator/api/bin/src/engine.js +65 -0
  30. package/generator/api/bin/src/layout/per-domain.js +346 -0
  31. package/generator/api/bin/src/parser/bundle.js +25 -0
  32. package/generator/api/bin/src/parser/ir.js +320 -0
  33. package/generator/api/bin/src/parser/types.js +7 -0
  34. package/generator/api/bin/src/render/template.js +58 -0
  35. package/generator/api/bin/src/writer/index.js +69 -0
  36. package/generator/api/schematics/init/schema.json +19 -0
  37. package/generator/api/schematics/sdk/schema.json +19 -0
  38. package/generator/api/sdk.config.example.json +22 -0
  39. package/generator/guide/README.md +84 -0
  40. package/generator/guide/bin/schematics/build/index.js +35 -0
  41. package/generator/guide/bin/schematics/init/index.js +70 -0
  42. package/generator/guide/bin/src/config/loader.js +50 -0
  43. package/generator/guide/bin/src/config/schema.js +12 -0
  44. package/generator/guide/bin/src/engine/component.js +73 -0
  45. package/generator/guide/bin/src/engine/frontmatter.js +42 -0
  46. package/generator/guide/bin/src/engine/index.js +42 -0
  47. package/generator/guide/bin/src/engine/naming.js +39 -0
  48. package/generator/guide/bin/src/engine/render.js +18 -0
  49. package/generator/guide/bin/src/engine/routes.js +106 -0
  50. package/generator/guide/bin/src/engine/walk.js +35 -0
  51. package/generator/guide/guide.config.example.json +9 -0
  52. package/generator/guide/schematics/build/schema.json +14 -0
  53. package/generator/guide/schematics/init/schema.json +19 -0
  54. package/package.json +58 -38
  55. package/theme/styles/etos.css +38 -0
  56. package/theme/styles/index.css +32 -8
  57. package/theme/styles/themes/brand/etos/color.css +21 -0
  58. package/theme/styles/themes/brand/etos/style.css +50 -0
  59. package/theme/styles/themes/library/_components.css +63 -0
  60. package/theme/styles/themes/library/_layers.css +15 -0
  61. package/theme/styles/themes/library/_material-overrides.css +254 -0
  62. package/theme/styles/themes/library/_tokens.css +54 -0
  63. package/theme/styles/themes/library/color/amber.css +18 -0
  64. package/theme/styles/themes/library/color/blue.css +23 -0
  65. package/theme/styles/themes/library/color/green.css +18 -0
  66. package/theme/styles/themes/library/color/index.css +9 -0
  67. package/theme/styles/themes/library/color/purple.css +18 -0
  68. package/theme/styles/themes/library/color/red.css +18 -0
  69. package/theme/styles/themes/library/style/brutal.css +47 -0
  70. package/theme/styles/themes/library/style/default.css +51 -0
  71. package/theme/styles/themes/library/style/index.css +8 -0
  72. package/theme/styles/themes/library/style/sharp.css +47 -0
  73. package/theme/styles/themes/library/style/soft.css +47 -0
  74. package/theme/styles/themes/mode/dark.css +20 -0
  75. package/theme/styles/themes/mode/index.css +6 -0
  76. package/theme/styles/themes/mode/light.css +24 -0
  77. package/theme/styles/themes/taildwind.css +109 -0
  78. package/types/ojiepermana-angular-chart.d.ts +1094 -0
  79. package/types/ojiepermana-angular-component.d.ts +1174 -0
  80. package/types/ojiepermana-angular-generator-api.d.ts +85 -0
  81. package/types/ojiepermana-angular-layout.d.ts +125 -76
  82. package/types/ojiepermana-angular-navigation.d.ts +256 -116
  83. package/types/ojiepermana-angular-theme.d.ts +170 -1
  84. package/types/ojiepermana-angular.d.ts +2 -1
  85. package/fesm2022/ojiepermana-angular-internal.mjs +0 -489
  86. package/fesm2022/ojiepermana-angular-internal.mjs.map +0 -1
  87. package/fesm2022/ojiepermana-angular-navigation-horizontal.mjs +0 -721
  88. package/fesm2022/ojiepermana-angular-navigation-horizontal.mjs.map +0 -1
  89. package/fesm2022/ojiepermana-angular-navigation-vertical.mjs +0 -1647
  90. package/fesm2022/ojiepermana-angular-navigation-vertical.mjs.map +0 -1
  91. package/fesm2022/ojiepermana-angular-shell.mjs +0 -19
  92. package/fesm2022/ojiepermana-angular-shell.mjs.map +0 -1
  93. package/fesm2022/ojiepermana-angular-theme-component.mjs +0 -235
  94. package/fesm2022/ojiepermana-angular-theme-component.mjs.map +0 -1
  95. package/fesm2022/ojiepermana-angular-theme-directive.mjs +0 -29
  96. package/fesm2022/ojiepermana-angular-theme-directive.mjs.map +0 -1
  97. package/fesm2022/ojiepermana-angular-theme-service.mjs +0 -241
  98. package/fesm2022/ojiepermana-angular-theme-service.mjs.map +0 -1
  99. package/layout/README.md +0 -144
  100. package/layout/src/component/horizontal/horizontal.css +0 -130
  101. package/layout/src/component/vertical/vertical.css +0 -75
  102. package/layout/src/layout.css +0 -16
  103. package/navigation/README.md +0 -301
  104. package/navigation/horizontal/README.md +0 -49
  105. package/shell/README.md +0 -41
  106. package/styles/index.css +0 -2
  107. package/styles/resets.css +0 -22
  108. package/theme/README.md +0 -379
  109. package/theme/styles/adapters/material-ui/index.css +0 -205
  110. package/theme/styles/modes/dark.css +0 -84
  111. package/theme/styles/presets/colors/blue.css +0 -45
  112. package/theme/styles/presets/colors/brand.css +0 -52
  113. package/theme/styles/presets/colors/cyan.css +0 -45
  114. package/theme/styles/presets/colors/green.css +0 -45
  115. package/theme/styles/presets/colors/index.css +0 -7
  116. package/theme/styles/presets/colors/orange.css +0 -45
  117. package/theme/styles/presets/colors/purple.css +0 -45
  118. package/theme/styles/presets/colors/red.css +0 -45
  119. package/theme/styles/presets/styles/flat.css +0 -61
  120. package/theme/styles/presets/styles/glass.css +0 -28
  121. package/theme/styles/presets/styles/index.css +0 -2
  122. package/theme/styles/roles/index.css +0 -67
  123. package/theme/styles/tokens/foundation.css +0 -136
  124. package/theme/styles/tokens/semantic.css +0 -87
  125. package/theme/styles/utilities/index.css +0 -88
  126. package/types/ojiepermana-angular-internal.d.ts +0 -90
  127. package/types/ojiepermana-angular-navigation-horizontal.d.ts +0 -81
  128. package/types/ojiepermana-angular-navigation-vertical.d.ts +0 -262
  129. package/types/ojiepermana-angular-shell.d.ts +0 -14
  130. package/types/ojiepermana-angular-theme-component.d.ts +0 -46
  131. package/types/ojiepermana-angular-theme-directive.d.ts +0 -10
  132. package/types/ojiepermana-angular-theme-service.d.ts +0 -68
  133. /package/{navigation/vertical → chart}/README.md +0 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.init = init;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ /**
7
+ * Default config template. The published package also ships a concrete
8
+ * `sdk.config.example.json`; this fallback only exists so `init` still works if
9
+ * the file is missing in unusual local/dev states.
10
+ */
11
+ const FALLBACK_TEMPLATE = {
12
+ $schema: './node_modules/@ojiepermana/angular/generator/api/schematics/sdk/schema.json',
13
+ targets: [
14
+ {
15
+ input: './openapi.yaml',
16
+ output: './sdk',
17
+ mode: 'standalone',
18
+ clientName: 'Api',
19
+ rootUrl: 'http://127.0.0.1:8080',
20
+ splitByDomain: false,
21
+ splitDepth: 'service',
22
+ features: {
23
+ models: true,
24
+ operations: true,
25
+ services: true,
26
+ client: true,
27
+ metadata: true,
28
+ navigation: true,
29
+ },
30
+ },
31
+ ],
32
+ };
33
+ function init(options = {}) {
34
+ return (tree, context) => {
35
+ const workspaceRoot = process.cwd();
36
+ const destRelative = options.path ?? 'config/sdk.config.json';
37
+ const treePath = destRelative.startsWith('/') ? destRelative : `/${destRelative}`;
38
+ if (tree.exists(treePath) && !options.force) {
39
+ throw new Error(`${destRelative} already exists. Re-run with --force to overwrite.`);
40
+ }
41
+ const content = loadTemplate(workspaceRoot, destRelative);
42
+ const buffer = Buffer.from(content, 'utf8');
43
+ if (tree.exists(treePath)) {
44
+ tree.overwrite(treePath, buffer);
45
+ context.logger.info(`[sdk:init] overwrote ${destRelative}`);
46
+ }
47
+ else {
48
+ tree.create(treePath, buffer);
49
+ context.logger.info(`[sdk:init] created ${destRelative}`);
50
+ }
51
+ context.logger.info(`[sdk:init] edit targets[].input and targets[].output, then run \`${getNextCommand(workspaceRoot)}\`.`);
52
+ };
53
+ }
54
+ function loadTemplate(workspaceRoot, destRelative) {
55
+ const candidates = [
56
+ (0, node_path_1.resolve)(workspaceRoot, 'sdk.config.example.json'),
57
+ (0, node_path_1.resolve)(__dirname, '../../../sdk.config.example.json'),
58
+ (0, node_path_1.resolve)(workspaceRoot, 'projects/angular/generator/api/sdk.config.example.json'),
59
+ ];
60
+ for (const candidate of candidates) {
61
+ try {
62
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)(candidate, 'utf8'));
63
+ parsed.$schema = resolveSchemaPath(workspaceRoot, destRelative);
64
+ return `${JSON.stringify(parsed, null, 2)}\n`;
65
+ }
66
+ catch {
67
+ // try next
68
+ }
69
+ }
70
+ return `${JSON.stringify({ ...FALLBACK_TEMPLATE, $schema: resolveSchemaPath(workspaceRoot, destRelative) }, null, 2)}\n`;
71
+ }
72
+ function resolveSchemaPath(workspaceRoot, destRelative) {
73
+ const prefix = relativePrefix(destRelative);
74
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(workspaceRoot, 'projects/angular/generator/api/schematics/sdk/schema.json'))) {
75
+ return `${prefix}projects/angular/generator/api/schematics/sdk/schema.json`;
76
+ }
77
+ return `${prefix}node_modules/@ojiepermana/angular/generator/api/schematics/sdk/schema.json`;
78
+ }
79
+ function relativePrefix(destRelative) {
80
+ const depth = destRelative.replace(/^\/+/, '').split('/').length - 1;
81
+ return depth <= 0 ? './' : '../'.repeat(depth);
82
+ }
83
+ function getNextCommand(workspaceRoot) {
84
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(workspaceRoot, 'projects/angular/collection.json'))) {
85
+ return 'bun run gen:sdk';
86
+ }
87
+ return 'ng generate @ojiepermana/angular:sdk';
88
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdk = sdk;
4
+ const node_path_1 = require("node:path");
5
+ const loader_1 = require("../../src/config/loader");
6
+ const engine_1 = require("../../src/engine");
7
+ /**
8
+ * Schematic factory. Reads `sdk.config.json` at the workspace root, runs the
9
+ * pure generator, and writes each emitted file into the Tree so
10
+ * `--dry-run` / `--force` behave as expected.
11
+ */
12
+ function sdk(options = {}) {
13
+ return async (tree, context) => {
14
+ const workspaceRoot = process.cwd();
15
+ const configPath = options.config ?? 'config/sdk.config.json';
16
+ const targets = (0, loader_1.loadConfig)(configPath, workspaceRoot);
17
+ const selected = selectTargets(targets, options.target);
18
+ if (selected.length === 0) {
19
+ throw new Error(`No SDK targets matched "${options.target}"`);
20
+ }
21
+ for (const target of selected) {
22
+ const result = await (0, engine_1.generate)(target, workspaceRoot);
23
+ writeResult(tree, workspaceRoot, result, context);
24
+ }
25
+ };
26
+ }
27
+ function selectTargets(targets, selector) {
28
+ if (!selector)
29
+ return [...targets];
30
+ const idx = Number.parseInt(selector, 10);
31
+ if (!Number.isNaN(idx) && idx > 0 && idx <= targets.length) {
32
+ return [targets[idx - 1]];
33
+ }
34
+ const lc = selector.toLowerCase();
35
+ return targets.filter((t) => t.clientName.toLowerCase() === lc || t.output.toLowerCase().includes(lc) || t.packageName.toLowerCase() === lc);
36
+ }
37
+ function writeResult(tree, workspaceRoot, result, context) {
38
+ const relOutput = (0, node_path_1.relative)(workspaceRoot, result.outputDir) || '.';
39
+ context.logger.info(`[sdk] ${result.target.mode} → ${relOutput} ` +
40
+ `(schemas=${result.stats.schemas}, operations=${result.stats.operations}, ` +
41
+ `tags=${result.stats.tags}, files=${result.stats.files})`);
42
+ for (const file of result.files) {
43
+ const absolute = (0, node_path_1.resolve)(result.outputDir, file.path);
44
+ const treePath = normalizeTreePath(workspaceRoot, absolute);
45
+ const buffer = Buffer.from(file.content, 'utf8');
46
+ if (tree.exists(treePath)) {
47
+ tree.overwrite(treePath, buffer);
48
+ }
49
+ else {
50
+ tree.create(treePath, buffer);
51
+ }
52
+ }
53
+ }
54
+ function normalizeTreePath(workspaceRoot, absolute) {
55
+ const rel = (0, node_path_1.relative)(workspaceRoot, absolute);
56
+ const posix = rel.split(/\\+/).join('/');
57
+ return posix.startsWith('/') ? posix : `/${posix}`;
58
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadConfig = loadConfig;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const schema_1 = require("./schema");
7
+ /**
8
+ * Loads an SDK generator config from disk. Supports `.json` and `.js`/`.cjs`
9
+ * (require-based). `.ts` is intentionally not supported in the first iteration
10
+ * to avoid pulling an extra compile step — use `.json` or `.js` instead.
11
+ */
12
+ function loadConfig(configPath, workspaceRoot) {
13
+ const absolute = (0, node_path_1.isAbsolute)(configPath) ? configPath : (0, node_path_1.resolve)(workspaceRoot, configPath);
14
+ if (!(0, node_fs_1.existsSync)(absolute)) {
15
+ throw new Error(`SDK config not found at ${absolute}`);
16
+ }
17
+ const ext = (0, node_path_1.extname)(absolute).toLowerCase();
18
+ let raw;
19
+ if (ext === '.json' || ext === '') {
20
+ const text = (0, node_fs_1.readFileSync)(absolute, 'utf8');
21
+ raw = JSON.parse(stripJsonComments(text));
22
+ }
23
+ else if (ext === '.js' || ext === '.cjs') {
24
+ const mod = require(absolute);
25
+ raw = extractDefaultExport(mod);
26
+ }
27
+ else {
28
+ throw new Error(`Unsupported SDK config extension: ${ext} (use .json or .js)`);
29
+ }
30
+ return (0, schema_1.resolveConfig)(raw);
31
+ }
32
+ function extractDefaultExport(mod) {
33
+ if (mod && typeof mod === 'object' && 'default' in mod) {
34
+ return mod.default;
35
+ }
36
+ return mod;
37
+ }
38
+ function stripJsonComments(text) {
39
+ // Minimal JSONC support: strip // line comments and /* */ block comments.
40
+ return text.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:])\/\/.*$/gm, '$1');
41
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /**
3
+ * Public config shape for the SDK generator.
4
+ *
5
+ * Users place an `sdk.config.json` at the workspace root describing one or more
6
+ * generation targets. All paths are resolved relative to the workspace root
7
+ * (i.e. the directory containing the config file).
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.resolveTarget = resolveTarget;
11
+ exports.resolveConfig = resolveConfig;
12
+ const DEFAULT_BANNER = '/* eslint-disable */\n/* Auto-generated by @ojiepermana/angular/generator/api. DO NOT EDIT. */';
13
+ const DEFAULT_FEATURES = {
14
+ models: true,
15
+ operations: true,
16
+ services: true,
17
+ client: true,
18
+ metadata: true,
19
+ navigation: true,
20
+ };
21
+ function resolveTarget(raw) {
22
+ if (!raw || typeof raw !== 'object') {
23
+ throw new Error('Invalid target: expected object');
24
+ }
25
+ if (!raw.input)
26
+ throw new Error('Target is missing required "input"');
27
+ if (!raw.output)
28
+ throw new Error('Target is missing required "output"');
29
+ const mode = raw.mode ?? 'standalone';
30
+ if (!['standalone', 'library', 'secondary-entrypoint'].includes(mode)) {
31
+ throw new Error(`Invalid target mode: ${mode}`);
32
+ }
33
+ return {
34
+ input: raw.input,
35
+ output: raw.output,
36
+ mode,
37
+ clientName: raw.clientName ?? 'Api',
38
+ packageName: raw.packageName ?? '@local/sdk',
39
+ packageVersion: raw.packageVersion ?? '0.0.1',
40
+ rootUrl: raw.rootUrl,
41
+ features: { ...DEFAULT_FEATURES, ...(raw.features ?? {}) },
42
+ splitByDomain: raw.splitByDomain === true,
43
+ splitDepth: raw.splitDepth === 'tag' ? 'tag' : 'service',
44
+ banner: raw.banner ?? DEFAULT_BANNER,
45
+ };
46
+ }
47
+ function resolveConfig(raw) {
48
+ if (!raw || typeof raw !== 'object') {
49
+ throw new Error('Invalid SDK config: root must be an object');
50
+ }
51
+ const cfg = raw;
52
+ if (!Array.isArray(cfg.targets) || cfg.targets.length === 0) {
53
+ throw new Error('Invalid SDK config: "targets" must be a non-empty array');
54
+ }
55
+ return cfg.targets.map(resolveTarget);
56
+ }
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitClient = emitClient;
4
+ const template_1 = require("../render/template");
5
+ /**
6
+ * Emit the tiny runtime client primitives:
7
+ * - `api-configuration.ts` — root-url config + provider
8
+ * - `base-service.ts` — per-service rootUrl override
9
+ * - `strict-http-response.ts`— HttpResponse alias
10
+ * - `request-builder.ts` — minimal (path / query / header / body / build)
11
+ * - `api.ts` — `Api` helper with invoke() / invoke$Response()
12
+ *
13
+ * These files are **static** — identical across specs — so we embed them as
14
+ * template literals rather than parsing the IR. The only dynamic bits are the
15
+ * banner comment and the default `rootUrl`.
16
+ */
17
+ function emitClient(ir, target) {
18
+ const defaultRootUrl = target.rootUrl ?? ir.servers[0]?.url ?? '';
19
+ return [
20
+ { path: 'api-configuration.ts', content: (0, template_1.finalize)(apiConfigurationFile(target, defaultRootUrl)) },
21
+ { path: 'base-service.ts', content: (0, template_1.finalize)(baseServiceFile(target)) },
22
+ { path: 'strict-http-response.ts', content: (0, template_1.finalize)(strictResponseFile(target)) },
23
+ { path: 'request-builder.ts', content: (0, template_1.finalize)(requestBuilderFile(target)) },
24
+ { path: 'api.ts', content: (0, template_1.finalize)(apiFile(target)) },
25
+ ];
26
+ }
27
+ function apiConfigurationFile(target, rootUrl) {
28
+ return `${target.banner}
29
+
30
+ import { Injectable, makeEnvironmentProviders, type EnvironmentProviders } from '@angular/core';
31
+
32
+ @Injectable({ providedIn: 'root' })
33
+ export class ApiConfiguration {
34
+ rootUrl: string = ${JSON.stringify(rootUrl)};
35
+ }
36
+
37
+ export function provideApiConfiguration(rootUrl: string): EnvironmentProviders {
38
+ return makeEnvironmentProviders([
39
+ {
40
+ provide: ApiConfiguration,
41
+ useFactory: () => {
42
+ const c = new ApiConfiguration();
43
+ c.rootUrl = rootUrl;
44
+ return c;
45
+ },
46
+ },
47
+ ]);
48
+ }
49
+ `;
50
+ }
51
+ function baseServiceFile(target) {
52
+ return `${target.banner}
53
+
54
+ import { HttpClient } from '@angular/common/http';
55
+ import { Injectable, inject } from '@angular/core';
56
+
57
+ import { ApiConfiguration } from './api-configuration';
58
+
59
+ @Injectable()
60
+ export class BaseService {
61
+ protected readonly config = inject(ApiConfiguration);
62
+ protected readonly http = inject(HttpClient);
63
+
64
+ private _rootUrl?: string;
65
+
66
+ get rootUrl(): string {
67
+ return this._rootUrl ?? this.config.rootUrl;
68
+ }
69
+ set rootUrl(url: string) {
70
+ this._rootUrl = url;
71
+ }
72
+ }
73
+ `;
74
+ }
75
+ function strictResponseFile(target) {
76
+ return `${target.banner}
77
+
78
+ import { HttpResponse } from '@angular/common/http';
79
+
80
+ export type StrictHttpResponse<T> = HttpResponse<T> & { readonly body: T };
81
+ `;
82
+ }
83
+ /**
84
+ * Minimal request builder — intentionally drops the style/explode serializer
85
+ * from ng-openapi-gen's output. Covers the 99% case: path templating, simple
86
+ * query params (with array → repeated key), JSON body, and header params.
87
+ */
88
+ function requestBuilderFile(target) {
89
+ return `${target.banner}
90
+
91
+ import {
92
+ HttpContext,
93
+ HttpHeaders,
94
+ HttpParams,
95
+ HttpRequest,
96
+ } from '@angular/common/http';
97
+
98
+ export interface BuildOptions {
99
+ accept?: string;
100
+ responseType?: 'json' | 'text' | 'blob' | 'arraybuffer';
101
+ reportProgress?: boolean;
102
+ context?: HttpContext;
103
+ }
104
+
105
+ export class RequestBuilder {
106
+ private readonly _pathParams = new Map<string, unknown>();
107
+ private readonly _queryParams = new Map<string, unknown>();
108
+ private readonly _headerParams = new Map<string, unknown>();
109
+ private _body: unknown = undefined;
110
+ private _bodyContentType: string | undefined;
111
+
112
+ constructor(
113
+ public readonly rootUrl: string,
114
+ public readonly operationPath: string,
115
+ public readonly method: string,
116
+ ) {}
117
+
118
+ path(name: string, value: unknown): void {
119
+ this._pathParams.set(name, value);
120
+ }
121
+
122
+ query(name: string, value: unknown): void {
123
+ this._queryParams.set(name, value);
124
+ }
125
+
126
+ header(name: string, value: unknown): void {
127
+ this._headerParams.set(name, value);
128
+ }
129
+
130
+ body(value: unknown, contentType = 'application/json'): void {
131
+ if (value instanceof Blob) {
132
+ this._bodyContentType = value.type;
133
+ } else if (value instanceof FormData) {
134
+ // FormData sets its own Content-Type (with boundary) — leave it alone.
135
+ this._bodyContentType = undefined;
136
+ } else {
137
+ this._bodyContentType = contentType;
138
+ }
139
+ this._body = value;
140
+ }
141
+
142
+ build<T = unknown>(options: BuildOptions = {}): HttpRequest<T> {
143
+ let path = this.operationPath;
144
+ for (const [name, value] of this._pathParams) {
145
+ path = path.replace(
146
+ '{' + name + '}',
147
+ encodeURIComponent(value == null ? '' : String(value)),
148
+ );
149
+ }
150
+
151
+ let params = new HttpParams();
152
+ for (const [name, value] of this._queryParams) {
153
+ if (value === undefined || value === null) continue;
154
+ if (Array.isArray(value)) {
155
+ for (const v of value) {
156
+ if (v !== undefined && v !== null) params = params.append(name, String(v));
157
+ }
158
+ } else {
159
+ params = params.append(name, String(value));
160
+ }
161
+ }
162
+
163
+ let headers = new HttpHeaders();
164
+ if (options.accept) headers = headers.set('Accept', options.accept);
165
+ for (const [name, value] of this._headerParams) {
166
+ if (value === undefined || value === null) continue;
167
+ if (Array.isArray(value)) {
168
+ for (const v of value) headers = headers.append(name, String(v));
169
+ } else {
170
+ headers = headers.set(name, String(value));
171
+ }
172
+ }
173
+ if (this._bodyContentType) {
174
+ headers = headers.set('Content-Type', this._bodyContentType);
175
+ }
176
+
177
+ return new HttpRequest<T>(
178
+ this.method.toUpperCase(),
179
+ this.rootUrl + path,
180
+ this._body as T,
181
+ {
182
+ params,
183
+ headers,
184
+ responseType: options.responseType,
185
+ reportProgress: options.reportProgress,
186
+ context: options.context,
187
+ },
188
+ );
189
+ }
190
+ }
191
+ `;
192
+ }
193
+ function apiFile(target) {
194
+ return `${target.banner}
195
+
196
+ import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http';
197
+ import { Injectable, inject } from '@angular/core';
198
+ import { Observable } from 'rxjs';
199
+ import { filter, map } from 'rxjs/operators';
200
+
201
+ import { ApiConfiguration } from './api-configuration';
202
+ import { StrictHttpResponse } from './strict-http-response';
203
+
204
+ export type ApiFn<P, R> = (
205
+ http: HttpClient,
206
+ rootUrl: string,
207
+ params: P,
208
+ context?: HttpContext,
209
+ ) => Observable<StrictHttpResponse<R>>;
210
+
211
+ /**
212
+ * Helper to invoke any tree-shakeable operation function directly.
213
+ */
214
+ @Injectable({ providedIn: 'root' })
215
+ export class ${target.clientName} {
216
+ private readonly config = inject(ApiConfiguration);
217
+ private readonly http = inject(HttpClient);
218
+
219
+ private _rootUrl?: string;
220
+
221
+ get rootUrl(): string {
222
+ return this._rootUrl ?? this.config.rootUrl;
223
+ }
224
+ set rootUrl(url: string) {
225
+ this._rootUrl = url;
226
+ }
227
+
228
+ /** Invoke an operation function and stream the response body. */
229
+ invoke<P, R>(fn: ApiFn<P, R>, params: P, context?: HttpContext): Observable<R> {
230
+ return this.invoke$Response(fn, params, context).pipe(map((r) => r.body));
231
+ }
232
+
233
+ /** Invoke an operation function and stream the full HTTP response. */
234
+ invoke$Response<P, R>(
235
+ fn: ApiFn<P, R>,
236
+ params: P,
237
+ context?: HttpContext,
238
+ ): Observable<StrictHttpResponse<R>> {
239
+ return fn(this.http, this.rootUrl, params, context).pipe(
240
+ filter((r: unknown): r is HttpResponse<unknown> => r instanceof HttpResponse),
241
+ map((r) => r as StrictHttpResponse<R>),
242
+ );
243
+ }
244
+ }
245
+ `;
246
+ }