@ojiepermana/angular-sdk 22.0.44 → 22.0.46

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ojiepermana/angular-sdk",
3
- "version": "22.0.44",
3
+ "version": "22.0.46",
4
4
  "description": "OpenAPI 3.x → Angular SDK generator (schematics + config surface) for @ojiepermana/angular.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,7 +15,14 @@
15
15
  "@angular/core": ">=22.0.0"
16
16
  },
17
17
  "dependencies": {
18
- "tslib": "^2.8.1"
18
+ "@angular-devkit/schematics": ">=18.0.0",
19
+ "semver": "^7.6.0",
20
+ "tslib": "^2.8.1",
21
+ "yaml": "^2.9.0"
22
+ },
23
+ "schematics": "./schematics/collection.json",
24
+ "ng-add": {
25
+ "save": "dependencies"
19
26
  },
20
27
  "publishConfig": {
21
28
  "access": "public",
@@ -32,6 +39,5 @@
32
39
  "types": "./types/ojiepermana-angular-sdk.d.ts",
33
40
  "default": "./fesm2022/ojiepermana-angular-sdk.mjs"
34
41
  }
35
- },
36
- "type": "module"
37
- }
42
+ }
43
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json",
3
+ "schematics": {
4
+ "ng-add": {
5
+ "factory": "./ng-add/index#ngAdd",
6
+ "schema": "./ng-add/schema.json",
7
+ "description": "Install @ojiepermana/angular-sdk and align its peer dependencies."
8
+ },
9
+ "init": {
10
+ "factory": "./init/index#init",
11
+ "schema": "./init/schema.json",
12
+ "description": "Create an sdk.config.json at the workspace root."
13
+ },
14
+ "sdk": {
15
+ "factory": "./sdk/index#sdk",
16
+ "schema": "./sdk/schema.json",
17
+ "description": "Generate an Angular SDK from an OpenAPI spec using sdk.config.json."
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,90 @@
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: 'library',
18
+ clientName: 'Api',
19
+ packageName: '@my-scope/sdk',
20
+ packageVersion: '0.0.1',
21
+ rootUrl: '',
22
+ splitByDomain: true,
23
+ splitDepth: 'service',
24
+ features: {
25
+ models: true,
26
+ operations: true,
27
+ services: true,
28
+ client: true,
29
+ metadata: true,
30
+ navigation: true,
31
+ },
32
+ },
33
+ ],
34
+ };
35
+ function init(options = {}) {
36
+ return (tree, context) => {
37
+ const workspaceRoot = process.cwd();
38
+ const destRelative = options.path ?? 'config/sdk.config.json';
39
+ const treePath = destRelative.startsWith('/') ? destRelative : `/${destRelative}`;
40
+ if (tree.exists(treePath) && !options.force) {
41
+ throw new Error(`${destRelative} already exists. Re-run with --force to overwrite.`);
42
+ }
43
+ const content = loadTemplate(workspaceRoot, destRelative);
44
+ const buffer = Buffer.from(content, 'utf8');
45
+ if (tree.exists(treePath)) {
46
+ tree.overwrite(treePath, buffer);
47
+ context.logger.info(`[sdk:init] overwrote ${destRelative}`);
48
+ }
49
+ else {
50
+ tree.create(treePath, buffer);
51
+ context.logger.info(`[sdk:init] created ${destRelative}`);
52
+ }
53
+ context.logger.info(`[sdk:init] edit targets[].input and targets[].output, then run \`${getNextCommand(workspaceRoot)}\`.`);
54
+ };
55
+ }
56
+ function loadTemplate(workspaceRoot, destRelative) {
57
+ const candidates = [
58
+ (0, node_path_1.resolve)(workspaceRoot, 'sdk.config.example.json'),
59
+ (0, node_path_1.resolve)(__dirname, '../../../sdk.config.example.json'),
60
+ (0, node_path_1.resolve)(workspaceRoot, 'projects/angular/generator/api/sdk.config.example.json'),
61
+ ];
62
+ for (const candidate of candidates) {
63
+ try {
64
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)(candidate, 'utf8'));
65
+ parsed.$schema = resolveSchemaPath(workspaceRoot, destRelative);
66
+ return `${JSON.stringify(parsed, null, 2)}\n`;
67
+ }
68
+ catch {
69
+ // try next
70
+ }
71
+ }
72
+ return `${JSON.stringify({ ...FALLBACK_TEMPLATE, $schema: resolveSchemaPath(workspaceRoot, destRelative) }, null, 2)}\n`;
73
+ }
74
+ function resolveSchemaPath(workspaceRoot, destRelative) {
75
+ const prefix = relativePrefix(destRelative);
76
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(workspaceRoot, 'projects/angular/generator/api/schematics/sdk/schema.json'))) {
77
+ return `${prefix}projects/angular/generator/api/schematics/sdk/schema.json`;
78
+ }
79
+ return `${prefix}node_modules/@ojiepermana/angular/generator/api/schematics/sdk/schema.json`;
80
+ }
81
+ function relativePrefix(destRelative) {
82
+ const depth = destRelative.replace(/^\/+/, '').split('/').length - 1;
83
+ return depth <= 0 ? './' : '../'.repeat(depth);
84
+ }
85
+ function getNextCommand(workspaceRoot) {
86
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(workspaceRoot, 'projects/angular/collection.json'))) {
87
+ return 'bun run gen:sdk';
88
+ }
89
+ return 'ng generate @ojiepermana/angular:sdk';
90
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "SdkInitSchema",
4
+ "title": "Initialize SDK generator config",
5
+ "type": "object",
6
+ "properties": {
7
+ "path": {
8
+ "type": "string",
9
+ "description": "Path (relative to workspace root) where the config file will be created.",
10
+ "default": "config/sdk.config.json"
11
+ },
12
+ "force": {
13
+ "type": "boolean",
14
+ "description": "Overwrite the file if it already exists.",
15
+ "default": false
16
+ }
17
+ },
18
+ "required": []
19
+ }
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ngAdd = ngAdd;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const tasks_1 = require("@angular-devkit/schematics/tasks");
7
+ const semver_1 = require("semver");
8
+ function ngAdd(options = {}) {
9
+ return (tree, context) => {
10
+ const manifest = loadLibraryManifest();
11
+ const requiredDependencies = collectRequiredDependencies(manifest);
12
+ if (requiredDependencies.length === 0) {
13
+ context.logger.warn('[ng-add] No peer dependencies were declared by @ojiepermana/angular.');
14
+ return;
15
+ }
16
+ const workspacePackageJson = readWorkspacePackageJson(tree);
17
+ workspacePackageJson.dependencies ??= {};
18
+ let changed = false;
19
+ for (const dependency of requiredDependencies) {
20
+ const existingDependency = findExistingDependency(workspacePackageJson, dependency.name);
21
+ if (existingDependency) {
22
+ if (shouldUpdateDependency(existingDependency.version, dependency.version)) {
23
+ const section = workspacePackageJson[existingDependency.section] ?? {};
24
+ section[dependency.name] = dependency.version;
25
+ workspacePackageJson[existingDependency.section] = section;
26
+ changed = true;
27
+ context.logger.info(`[ng-add] updated ${dependency.name} from ${existingDependency.version} to ${dependency.version} in ${existingDependency.section}.`);
28
+ }
29
+ else {
30
+ context.logger.info(`[ng-add] keeping existing ${dependency.name}@${existingDependency.version} from ${existingDependency.section}.`);
31
+ }
32
+ continue;
33
+ }
34
+ workspacePackageJson.dependencies[dependency.name] = dependency.version;
35
+ changed = true;
36
+ context.logger.info(`[ng-add] added ${dependency.name}@${dependency.version}.`);
37
+ }
38
+ if (!changed) {
39
+ context.logger.info('[ng-add] Required dependencies are already present.');
40
+ return;
41
+ }
42
+ workspacePackageJson.dependencies = sortSection(workspacePackageJson.dependencies);
43
+ writeWorkspacePackageJson(tree, workspacePackageJson);
44
+ if (!options.skipInstall) {
45
+ context.addTask(new tasks_1.NodePackageInstallTask());
46
+ }
47
+ };
48
+ }
49
+ /**
50
+ * Use the package manifest as the source of truth so ng-add stays aligned with
51
+ * the published peerDependencies and ng-update packageGroup metadata.
52
+ */
53
+ function loadLibraryManifest() {
54
+ const candidates = [
55
+ // This package's own manifest (…/node_modules/@ojiepermana/angular-sdk/package.json)
56
+ // so a standalone install always resolves a manifest to read peers from.
57
+ (0, node_path_1.resolve)(__dirname, '../../package.json'),
58
+ (0, node_path_1.resolve)(__dirname, '../../../../../package.json'),
59
+ (0, node_path_1.resolve)(process.cwd(), 'node_modules/@ojiepermana/angular/package.json'),
60
+ (0, node_path_1.resolve)(process.cwd(), 'projects/angular/package.json'),
61
+ ];
62
+ for (const candidate of candidates) {
63
+ if (!(0, node_fs_1.existsSync)(candidate))
64
+ continue;
65
+ return JSON.parse((0, node_fs_1.readFileSync)(candidate, 'utf8'));
66
+ }
67
+ throw new Error('Could not locate the @ojiepermana/angular package manifest for ng-add.');
68
+ }
69
+ function collectRequiredDependencies(manifest) {
70
+ const peerDependencies = manifest.peerDependencies ?? {};
71
+ const packageGroup = normalizePackageGroup(manifest['ng-update']?.packageGroup);
72
+ return Object.keys(peerDependencies)
73
+ .sort((left, right) => left.localeCompare(right))
74
+ .map((name) => ({
75
+ name,
76
+ version: packageGroup[name] ?? peerDependencies[name],
77
+ }));
78
+ }
79
+ function normalizePackageGroup(packageGroup) {
80
+ if (!packageGroup) {
81
+ return {};
82
+ }
83
+ if (Array.isArray(packageGroup)) {
84
+ return {};
85
+ }
86
+ return packageGroup;
87
+ }
88
+ function readWorkspacePackageJson(tree) {
89
+ const buffer = tree.read('/package.json');
90
+ if (!buffer) {
91
+ throw new Error('No package.json found at the workspace root.');
92
+ }
93
+ return JSON.parse(buffer.toString('utf8'));
94
+ }
95
+ function writeWorkspacePackageJson(tree, packageJson) {
96
+ const content = `${JSON.stringify(packageJson, null, 2)}\n`;
97
+ if (tree.exists('/package.json')) {
98
+ tree.overwrite('/package.json', content);
99
+ }
100
+ else {
101
+ tree.create('/package.json', content);
102
+ }
103
+ }
104
+ function findExistingDependency(packageJson, dependencyName) {
105
+ const sections = [
106
+ 'dependencies',
107
+ 'devDependencies',
108
+ 'peerDependencies',
109
+ 'optionalDependencies',
110
+ ];
111
+ for (const section of sections) {
112
+ const version = packageJson[section]?.[dependencyName];
113
+ if (version) {
114
+ return { section, version };
115
+ }
116
+ }
117
+ return null;
118
+ }
119
+ function shouldUpdateDependency(existingVersion, requiredVersion) {
120
+ const existing = (0, semver_1.validRange)(existingVersion);
121
+ const required = (0, semver_1.validRange)(requiredVersion);
122
+ if (!existing || !required) {
123
+ return false;
124
+ }
125
+ const existingMinimum = (0, semver_1.minVersion)(existing);
126
+ const requiredMinimum = (0, semver_1.minVersion)(required);
127
+ if (!existingMinimum || !requiredMinimum) {
128
+ return false;
129
+ }
130
+ return existingMinimum.compare(requiredMinimum) < 0;
131
+ }
132
+ function sortSection(section) {
133
+ return Object.fromEntries(Object.entries(section).sort(([left], [right]) => left.localeCompare(right)));
134
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "NgAddSchema",
4
+ "title": "@ojiepermana/angular ng-add options",
5
+ "type": "object",
6
+ "properties": {
7
+ "skipInstall": {
8
+ "type": "boolean",
9
+ "default": false,
10
+ "description": "Skip installing dependencies after updating package.json."
11
+ }
12
+ },
13
+ "additionalProperties": false
14
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdk = sdk;
4
+ exports.writeResult = writeResult;
5
+ const node_path_1 = require("node:path");
6
+ const loader_1 = require("../../src/config/loader");
7
+ const engine_1 = require("../../src/engine");
8
+ /**
9
+ * Schematic factory. Reads `sdk.config.json` at the workspace root, runs the
10
+ * pure generator, and writes each emitted file into the Tree so
11
+ * `--dry-run` / `--force` behave as expected.
12
+ */
13
+ function sdk(options = {}) {
14
+ return async (tree, context) => {
15
+ const workspaceRoot = process.cwd();
16
+ const configPath = options.config ?? 'config/sdk.config.json';
17
+ const targets = (0, loader_1.loadConfig)(configPath, workspaceRoot);
18
+ const selected = selectTargets(targets, options.target);
19
+ if (selected.length === 0) {
20
+ throw new Error(`No SDK targets matched "${options.target}"`);
21
+ }
22
+ for (const target of selected) {
23
+ const result = await (0, engine_1.generate)(target, workspaceRoot);
24
+ writeResult(tree, workspaceRoot, result, context);
25
+ }
26
+ };
27
+ }
28
+ function selectTargets(targets, selector) {
29
+ if (!selector)
30
+ return [...targets];
31
+ const idx = Number.parseInt(selector, 10);
32
+ if (!Number.isNaN(idx) && idx > 0 && idx <= targets.length) {
33
+ return [targets[idx - 1]];
34
+ }
35
+ const lc = selector.toLowerCase();
36
+ return targets.filter((t) => t.clientName.toLowerCase() === lc || t.output.toLowerCase().includes(lc) || t.packageName.toLowerCase() === lc);
37
+ }
38
+ function writeResult(tree, workspaceRoot, result, context) {
39
+ const relOutput = (0, node_path_1.relative)(workspaceRoot, result.outputDir) || '.';
40
+ context.logger.info(`[sdk] ${result.target.mode} → ${relOutput} ` +
41
+ `(schemas=${result.stats.schemas}, operations=${result.stats.operations}, ` +
42
+ `tags=${result.stats.tags}, files=${result.stats.files})`);
43
+ removeStaleFiles(tree, workspaceRoot, result);
44
+ for (const file of result.files) {
45
+ const absolute = (0, node_path_1.resolve)(result.outputDir, file.path);
46
+ const treePath = normalizeTreePath(workspaceRoot, absolute);
47
+ const buffer = Buffer.from(file.content, 'utf8');
48
+ if (tree.exists(treePath)) {
49
+ tree.overwrite(treePath, buffer);
50
+ }
51
+ else {
52
+ tree.create(treePath, buffer);
53
+ }
54
+ }
55
+ }
56
+ function removeStaleFiles(tree, workspaceRoot, result) {
57
+ const outputRoot = normalizeTreePath(workspaceRoot, result.outputDir);
58
+ if (outputRoot === '/') {
59
+ return;
60
+ }
61
+ const nextFiles = new Set(result.files.map((file) => normalizeTreePath(workspaceRoot, (0, node_path_1.resolve)(result.outputDir, file.path))));
62
+ const staleFiles = [];
63
+ tree.getDir(outputRoot).visit((path) => {
64
+ if (!nextFiles.has(path)) {
65
+ staleFiles.push(path);
66
+ }
67
+ });
68
+ for (const staleFile of staleFiles) {
69
+ tree.delete(staleFile);
70
+ }
71
+ }
72
+ function normalizeTreePath(workspaceRoot, absolute) {
73
+ const rel = (0, node_path_1.relative)(workspaceRoot, absolute);
74
+ const posix = rel.split(/\\+/).join('/');
75
+ return posix.startsWith('/') ? posix : `/${posix}`;
76
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "$id": "SdkGeneratorSchema",
4
+ "title": "Generate an Angular SDK from an OpenAPI spec",
5
+ "type": "object",
6
+ "properties": {
7
+ "config": {
8
+ "type": "string",
9
+ "description": "Path to sdk.config.json (defaults to ./config/sdk.config.json at workspace root).",
10
+ "default": "config/sdk.config.json"
11
+ },
12
+ "target": {
13
+ "type": "string",
14
+ "description": "Optional name/index of a specific target in the config to generate."
15
+ }
16
+ },
17
+ "required": [],
18
+ "additionalProperties": false
19
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "./node_modules/@ojiepermana/angular/generator/api/schematics/sdk/schema.json",
3
+ "targets": [
4
+ {
5
+ "input": "./openapi.yaml",
6
+ "output": "./sdk",
7
+ "mode": "library",
8
+ "clientName": "Api",
9
+ "packageName": "@my-scope/sdk",
10
+ "packageVersion": "0.0.1",
11
+ "rootUrl": "",
12
+ "splitByDomain": true,
13
+ "splitDepth": "service",
14
+ "features": {
15
+ "models": true,
16
+ "operations": true,
17
+ "services": true,
18
+ "client": true,
19
+ "metadata": true,
20
+ "navigation": true
21
+ }
22
+ }
23
+ ]
24
+ }
@@ -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,58 @@
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
+ resources: false,
21
+ };
22
+ function resolveTarget(raw) {
23
+ if (!raw || typeof raw !== 'object') {
24
+ throw new Error('Invalid target: expected object');
25
+ }
26
+ if (!raw.input)
27
+ throw new Error('Target is missing required "input"');
28
+ if (!raw.output)
29
+ throw new Error('Target is missing required "output"');
30
+ const mode = raw.mode ?? 'standalone';
31
+ if (!['standalone', 'library', 'secondary-entrypoint'].includes(mode)) {
32
+ throw new Error(`Invalid target mode: ${mode}`);
33
+ }
34
+ const splitByDomain = raw.splitByDomain ?? mode === 'library';
35
+ return {
36
+ input: raw.input,
37
+ output: raw.output,
38
+ mode,
39
+ clientName: raw.clientName ?? 'Api',
40
+ packageName: raw.packageName ?? '@local/sdk',
41
+ packageVersion: raw.packageVersion ?? '0.0.1',
42
+ rootUrl: raw.rootUrl,
43
+ features: { ...DEFAULT_FEATURES, ...(raw.features ?? {}) },
44
+ splitByDomain,
45
+ splitDepth: raw.splitDepth === 'tag' ? 'tag' : 'service',
46
+ banner: raw.banner ?? DEFAULT_BANNER,
47
+ };
48
+ }
49
+ function resolveConfig(raw) {
50
+ if (!raw || typeof raw !== 'object') {
51
+ throw new Error('Invalid SDK config: root must be an object');
52
+ }
53
+ const cfg = raw;
54
+ if (!Array.isArray(cfg.targets) || cfg.targets.length === 0) {
55
+ throw new Error('Invalid SDK config: "targets" must be a non-empty array');
56
+ }
57
+ return cfg.targets.map(resolveTarget);
58
+ }