@ama-openapi/core 0.0.0-placeholder
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 +105 -0
- package/renovate/default.json +7 -0
- package/schemas/manifest.schema.json +106 -0
- package/src/constants.d.mts +15 -0
- package/src/constants.d.mts.map +1 -0
- package/src/constants.mjs +22 -0
- package/src/constants.mjs.map +1 -0
- package/src/core/file-system/cleaner.d.mts +6 -0
- package/src/core/file-system/cleaner.d.mts.map +1 -0
- package/src/core/file-system/cleaner.mjs +11 -0
- package/src/core/file-system/cleaner.mjs.map +1 -0
- package/src/core/file-system/parse-file.d.mts +11 -0
- package/src/core/file-system/parse-file.d.mts.map +1 -0
- package/src/core/file-system/parse-file.mjs +20 -0
- package/src/core/file-system/parse-file.mjs.map +1 -0
- package/src/core/file-system/write-model.d.mts +7 -0
- package/src/core/file-system/write-model.d.mts.map +1 -0
- package/src/core/file-system/write-model.mjs +17 -0
- package/src/core/file-system/write-model.mjs.map +1 -0
- package/src/core/manifest/extract-dependency-models.d.mts +35 -0
- package/src/core/manifest/extract-dependency-models.d.mts.map +1 -0
- package/src/core/manifest/extract-dependency-models.mjs +112 -0
- package/src/core/manifest/extract-dependency-models.mjs.map +1 -0
- package/src/core/manifest/manifest.d.mts +46 -0
- package/src/core/manifest/manifest.d.mts.map +1 -0
- package/src/core/manifest/manifest.mjs +55 -0
- package/src/core/manifest/manifest.mjs.map +1 -0
- package/src/core/serialization.d.mts +14 -0
- package/src/core/serialization.d.mts.map +1 -0
- package/src/core/serialization.mjs +24 -0
- package/src/core/serialization.mjs.map +1 -0
- package/src/core/transforms/add-annotation.d.mts +18 -0
- package/src/core/transforms/add-annotation.d.mts.map +1 -0
- package/src/core/transforms/add-annotation.mjs +19 -0
- package/src/core/transforms/add-annotation.mjs.map +1 -0
- package/src/core/transforms/apply-mask.d.mts +10 -0
- package/src/core/transforms/apply-mask.d.mts.map +1 -0
- package/src/core/transforms/apply-mask.mjs +57 -0
- package/src/core/transforms/apply-mask.mjs.map +1 -0
- package/src/core/transforms/rename.d.mts +10 -0
- package/src/core/transforms/rename.d.mts.map +1 -0
- package/src/core/transforms/rename.mjs +18 -0
- package/src/core/transforms/rename.mjs.map +1 -0
- package/src/core/transforms/to-reference.d.mts +16 -0
- package/src/core/transforms/to-reference.d.mts.map +1 -0
- package/src/core/transforms/to-reference.mjs +19 -0
- package/src/core/transforms/to-reference.mjs.map +1 -0
- package/src/core/transforms/transform.d.mts +7 -0
- package/src/core/transforms/transform.d.mts.map +1 -0
- package/src/core/transforms/transform.mjs +2 -0
- package/src/core/transforms/transform.mjs.map +1 -0
- package/src/core/transforms/update-references.d.mts +15 -0
- package/src/core/transforms/update-references.d.mts.map +1 -0
- package/src/core/transforms/update-references.mjs +39 -0
- package/src/core/transforms/update-references.mjs.map +1 -0
- package/src/logger.d.mts +36 -0
- package/src/logger.d.mts.map +1 -0
- package/src/logger.mjs +2 -0
- package/src/logger.mjs.map +1 -0
- package/src/main.d.mts +13 -0
- package/src/main.d.mts.map +1 -0
- package/src/main.mjs +51 -0
- package/src/main.mjs.map +1 -0
- package/src/public_api.d.mts +4 -0
- package/src/public_api.d.mts.map +1 -0
- package/src/public_api.mjs +4 -0
- package/src/public_api.mjs.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ama-openapi/core",
|
|
3
|
+
"version": "0.0.0-placeholder",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"typings": "./src/public_api.d.mts",
|
|
9
|
+
"main": "./src/public_api.mjs",
|
|
10
|
+
"description": "Package exposing core function to manage OpenAPI dependencies",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"otter",
|
|
13
|
+
"otter-module",
|
|
14
|
+
"openapi"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"nx": "nx",
|
|
18
|
+
"ng": "yarn nx",
|
|
19
|
+
"copy:schemas": "yarn cpy 'schemas/*.json' dist/schemas",
|
|
20
|
+
"copy:renovate": "yarn cpy 'renovate/*.json' dist/renovate",
|
|
21
|
+
"build:source": "tsc -b tsconfig.build.json && yarn cpy package.json dist/",
|
|
22
|
+
"build": "yarn nx build ama-openapi-core",
|
|
23
|
+
"postbuild": "patch-package-json-main"
|
|
24
|
+
},
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": {
|
|
27
|
+
"default": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
"./schemas/*.json": {
|
|
30
|
+
"default": "./schemas/*.json"
|
|
31
|
+
},
|
|
32
|
+
"./renovate/*.json": {
|
|
33
|
+
"default": "./renovate/*.json"
|
|
34
|
+
},
|
|
35
|
+
".": {
|
|
36
|
+
"module": "./src/public_api.mjs",
|
|
37
|
+
"typings": "./src/public_api.d.mts",
|
|
38
|
+
"default": "./src/public_api.mjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"ajv": "~8.17.1",
|
|
43
|
+
"js-yaml": "^4.1.0",
|
|
44
|
+
"semver": "^7.5.2",
|
|
45
|
+
"tslib": "^2.6.2"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"type-fest": "^4.30.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependenciesMeta": {
|
|
51
|
+
"type-fest": {
|
|
52
|
+
"optional": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@babel/core": "~7.28.0",
|
|
57
|
+
"@babel/preset-env": "~7.28.0",
|
|
58
|
+
"@babel/preset-typescript": "~7.28.0",
|
|
59
|
+
"@compodoc/compodoc": "^1.1.19",
|
|
60
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.4.0",
|
|
61
|
+
"@nx/eslint": "~21.6.0",
|
|
62
|
+
"@nx/eslint-plugin": "~21.6.0",
|
|
63
|
+
"@nx/jest": "~21.6.0",
|
|
64
|
+
"@nx/js": "~21.6.0",
|
|
65
|
+
"@o3r/build-helpers": "workspace:~",
|
|
66
|
+
"@o3r/eslint-plugin": "workspace:~",
|
|
67
|
+
"@o3r/telemetry": "workspace:~",
|
|
68
|
+
"@o3r/test-helpers": "workspace:~",
|
|
69
|
+
"@stylistic/eslint-plugin": "~5.5.0",
|
|
70
|
+
"@types/jest": "~29.5.2",
|
|
71
|
+
"@types/js-yaml": "^4.0.5",
|
|
72
|
+
"@types/minimist": "^1.2.2",
|
|
73
|
+
"@types/node": "~22.18.0",
|
|
74
|
+
"@types/semver": "^7.3.13",
|
|
75
|
+
"@typescript-eslint/parser": "~8.46.0",
|
|
76
|
+
"angular-eslint": "~20.4.0",
|
|
77
|
+
"babel-jest": "^29.7.0",
|
|
78
|
+
"cpy-cli": "^6.0.0",
|
|
79
|
+
"eslint": "~9.38.0",
|
|
80
|
+
"eslint-import-resolver-node": "~0.3.9",
|
|
81
|
+
"eslint-import-resolver-typescript": "~4.4.0",
|
|
82
|
+
"eslint-plugin-import": "~2.32.0",
|
|
83
|
+
"eslint-plugin-import-newlines": "~1.4.0",
|
|
84
|
+
"eslint-plugin-jest": "~29.0.0",
|
|
85
|
+
"eslint-plugin-jsdoc": "~54.7.0",
|
|
86
|
+
"eslint-plugin-prefer-arrow": "~1.2.3",
|
|
87
|
+
"eslint-plugin-unicorn": "~60.0.0",
|
|
88
|
+
"eslint-plugin-unused-imports": "~4.3.0",
|
|
89
|
+
"globals": "^16.0.0",
|
|
90
|
+
"jest": "~29.7.0",
|
|
91
|
+
"jest-junit": "~16.0.0",
|
|
92
|
+
"jest-resolve": "~29.7.0",
|
|
93
|
+
"jest-util": "~29.7.0",
|
|
94
|
+
"jsonc-eslint-parser": "~2.4.0",
|
|
95
|
+
"nx": "~21.6.0",
|
|
96
|
+
"pid-from-port": "^1.1.3",
|
|
97
|
+
"ts-jest": "~29.4.0",
|
|
98
|
+
"type-fest": "^4.30.1",
|
|
99
|
+
"typescript": "~5.9.2",
|
|
100
|
+
"typescript-eslint": "~8.46.0"
|
|
101
|
+
},
|
|
102
|
+
"engines": {
|
|
103
|
+
"node": "^20.19.0 || ^22.17.0 || ^24.0.0"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "OpenApi specification package manifest",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"models": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"description": "Dependency package containing the specification to include",
|
|
9
|
+
"additionalProperties": {
|
|
10
|
+
"oneOf": [
|
|
11
|
+
{ "$ref": "#/definitions/model" },
|
|
12
|
+
{ "type": "array", "items": { "$ref": "#/definitions/model" } }
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"additionalProperties": true,
|
|
18
|
+
"definitions": {
|
|
19
|
+
"transform": {
|
|
20
|
+
"oneOf": [
|
|
21
|
+
{
|
|
22
|
+
"type": "object",
|
|
23
|
+
"examples": [
|
|
24
|
+
{
|
|
25
|
+
"mask": { "data": true },
|
|
26
|
+
"fileRename": "MyPrefix_$1"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"properties": {
|
|
30
|
+
"mask": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"description": "Mask to apply"
|
|
33
|
+
},
|
|
34
|
+
"titleRename": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "Rename the model title. The keyword `$1` can be used to refer to original name (ex: a prefix would be `myPrefix_$1`)"
|
|
37
|
+
},
|
|
38
|
+
"fileRename": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description": "Rename the outputted file (to be specified without extension)."
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"additionalProperties": false,
|
|
44
|
+
"required": [
|
|
45
|
+
"fileRename"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"type": "string",
|
|
50
|
+
"description": "A reference to a predefined transform"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"model": {
|
|
55
|
+
"examples": [
|
|
56
|
+
true,
|
|
57
|
+
"models/ExampleModel.v1.yaml",
|
|
58
|
+
{
|
|
59
|
+
"path": "models/ExampleModel.v1.yaml",
|
|
60
|
+
"transform": {
|
|
61
|
+
"mask": { "data": true },
|
|
62
|
+
"fileRename": "MyPrefix_$1"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"oneOf": [
|
|
67
|
+
{
|
|
68
|
+
"type": "boolean",
|
|
69
|
+
"default": true,
|
|
70
|
+
"description": "Include the default model from the artifact"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "Path to the model to include as is"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "object",
|
|
78
|
+
"description": "Model definition within a dependency",
|
|
79
|
+
"properties": {
|
|
80
|
+
"path": {
|
|
81
|
+
"type": "string",
|
|
82
|
+
"description": "Path to the model in the artifact"
|
|
83
|
+
},
|
|
84
|
+
"transform": {
|
|
85
|
+
"oneOf": [
|
|
86
|
+
{
|
|
87
|
+
"$ref": "#/definitions/transform"
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"type": "array",
|
|
91
|
+
"items": {
|
|
92
|
+
"$ref": "#/definitions/transform"
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"required": [
|
|
99
|
+
"path"
|
|
100
|
+
],
|
|
101
|
+
"additionalProperties": false
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Directory containing the extracted module */
|
|
2
|
+
export declare const OUTPUT_DIRECTORY = "models_external";
|
|
3
|
+
/** Default manifest filenames to look for */
|
|
4
|
+
export declare const DEFAULT_MANIFEST_FILENAMES: readonly ["package.json", "ama-openapi.manifest.json", "ama-openapi.manifest.yaml", "openapi.manifest.json", "openapi.manifest.yaml"];
|
|
5
|
+
/** Key to mark masked properties */
|
|
6
|
+
export declare const MASKED_PROPERTY_KEY = "x-internal-masked";
|
|
7
|
+
/** Key to mark touched properties */
|
|
8
|
+
export declare const TOUCHED_PROPERTY_KEY = "x-internal-touched";
|
|
9
|
+
/** Key to indicate the source of the model */
|
|
10
|
+
export declare const SOURCE_PROPERTY_KEY = "x-internal-source";
|
|
11
|
+
/** Key to indicate the version of the model */
|
|
12
|
+
export declare const VERSION_PROPERTY_KEY = "x-internal-version";
|
|
13
|
+
/** Key to indicate reference rewrites */
|
|
14
|
+
export declare const REF_REWRITE_PROPERTY_KEY = "x-internal-reference-rewrite";
|
|
15
|
+
//# sourceMappingURL=constants.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD,6CAA6C;AAC7C,eAAO,MAAM,0BAA0B,uIAM7B,CAAC;AAIX,oCAAoC;AACpC,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,qCAAqC;AACrC,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,8CAA8C;AAC9C,eAAO,MAAM,mBAAmB,sBAAsB,CAAC;AACvD,+CAA+C;AAC/C,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AACzD,yCAAyC;AACzC,eAAO,MAAM,wBAAwB,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Directory containing the extracted module */
|
|
2
|
+
export const OUTPUT_DIRECTORY = 'models_external';
|
|
3
|
+
/** Default manifest filenames to look for */
|
|
4
|
+
export const DEFAULT_MANIFEST_FILENAMES = [
|
|
5
|
+
'package.json',
|
|
6
|
+
'ama-openapi.manifest.json',
|
|
7
|
+
'ama-openapi.manifest.yaml',
|
|
8
|
+
'openapi.manifest.json',
|
|
9
|
+
'openapi.manifest.yaml'
|
|
10
|
+
];
|
|
11
|
+
// Internal property keys :
|
|
12
|
+
/** Key to mark masked properties */
|
|
13
|
+
export const MASKED_PROPERTY_KEY = 'x-internal-masked';
|
|
14
|
+
/** Key to mark touched properties */
|
|
15
|
+
export const TOUCHED_PROPERTY_KEY = 'x-internal-touched';
|
|
16
|
+
/** Key to indicate the source of the model */
|
|
17
|
+
export const SOURCE_PROPERTY_KEY = 'x-internal-source';
|
|
18
|
+
/** Key to indicate the version of the model */
|
|
19
|
+
export const VERSION_PROPERTY_KEY = 'x-internal-version';
|
|
20
|
+
/** Key to indicate reference rewrites */
|
|
21
|
+
export const REF_REWRITE_PROPERTY_KEY = 'x-internal-reference-rewrite';
|
|
22
|
+
//# sourceMappingURL=constants.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/constants.mts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,cAAc;IACd,2BAA2B;IAC3B,2BAA2B;IAC3B,uBAAuB;IACvB,uBAAuB;CACf,CAAC;AAEX,2BAA2B;AAE3B,oCAAoC;AACpC,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,qCAAqC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AACzD,yCAAyC;AACzC,MAAM,CAAC,MAAM,wBAAwB,GAAG,8BAA8B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleaner.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/cleaner.mts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,kBAE/C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { promises as fs, } from 'node:fs';
|
|
2
|
+
import { resolve, } from 'node:path';
|
|
3
|
+
import { OUTPUT_DIRECTORY, } from '../../constants.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Clean the dependency output directory
|
|
6
|
+
* @param cwd
|
|
7
|
+
*/
|
|
8
|
+
export const cleanOutputDirectory = (cwd) => {
|
|
9
|
+
return fs.rm(resolve(cwd, OUTPUT_DIRECTORY), { force: true, recursive: true });
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=cleaner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cleaner.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/cleaner.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAE7B;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,EAAE;IAClD,OAAO,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AACjF,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if the file is a JSON file
|
|
3
|
+
* @param filePath
|
|
4
|
+
*/
|
|
5
|
+
export declare const isJsonFile: (filePath: string) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
*n Parse a file content based on its extension
|
|
8
|
+
* @param filePath
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseFile: <S>(filePath: string) => Promise<S>;
|
|
11
|
+
//# sourceMappingURL=parse-file.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-file.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/parse-file.mts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,KAAG,OAE7C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAU,CAAC,EAAG,UAAU,MAAM,KAAG,OAAO,CAAC,CAAC,CAK/D,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { promises as fs, } from 'node:fs';
|
|
2
|
+
import { load, } from 'js-yaml';
|
|
3
|
+
/**
|
|
4
|
+
* Check if the file is a JSON file
|
|
5
|
+
* @param filePath
|
|
6
|
+
*/
|
|
7
|
+
export const isJsonFile = (filePath) => {
|
|
8
|
+
return filePath.toLowerCase().endsWith('.json');
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
*n Parse a file content based on its extension
|
|
12
|
+
* @param filePath
|
|
13
|
+
*/
|
|
14
|
+
export const parseFile = async (filePath) => {
|
|
15
|
+
const content = await fs.readFile(filePath, { encoding: 'utf8' });
|
|
16
|
+
return (isJsonFile(filePath)
|
|
17
|
+
? JSON.parse(content)
|
|
18
|
+
: load(content));
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=parse-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-file.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/parse-file.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,IAAI,GACL,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAgB,EAAW,EAAE;IACtD,OAAO,QAAQ,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAClD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAM,QAAgB,EAAc,EAAE;IAClE,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;IAClE,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC1B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QACrB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAM,CAAC;AAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Write the model file in the dependencies folder.
|
|
4
|
+
* @param retrievedModel
|
|
5
|
+
*/
|
|
6
|
+
export declare const writeModelFile: (retrievedModel: RetrievedDependencyModel) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=write-model.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-model.d.mts","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,gBAAgB,wBAAwB,kBAS5E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { promises as fs, } from 'node:fs';
|
|
2
|
+
import { dirname, } from 'node:path';
|
|
3
|
+
/**
|
|
4
|
+
* Write the model file in the dependencies folder.
|
|
5
|
+
* @param retrievedModel
|
|
6
|
+
*/
|
|
7
|
+
export const writeModelFile = async (retrievedModel) => {
|
|
8
|
+
const { outputFilePath, content } = retrievedModel;
|
|
9
|
+
try {
|
|
10
|
+
await fs.mkdir(dirname(outputFilePath), { recursive: true });
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
// ignore folder creation failure because it can be due to existing one. If not the next command will fail.
|
|
14
|
+
}
|
|
15
|
+
await fs.writeFile(outputFilePath, content, { encoding: 'utf8' });
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=write-model.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-model.mjs","sourceRoot":"","sources":["../../../../src/core/file-system/write-model.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,OAAO,GACR,MAAM,WAAW,CAAC;AAKnB;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EAAE,cAAwC,EAAE,EAAE;IAC/E,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,2GAA2G;IAC7G,CAAC;IAED,MAAM,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Logger } from '../../logger.mjs';
|
|
2
|
+
import type { Manifest, Model, Transform } from './manifest.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Extracted dependency model information
|
|
5
|
+
*/
|
|
6
|
+
export interface RetrievedDependencyModel {
|
|
7
|
+
/** Name of the artifact */
|
|
8
|
+
artifactName: string;
|
|
9
|
+
/** Version of the artifact */
|
|
10
|
+
version: string;
|
|
11
|
+
/** Absolute path to the model file */
|
|
12
|
+
modelPath: string;
|
|
13
|
+
/** Content of the model file */
|
|
14
|
+
content: string;
|
|
15
|
+
/** Model definition from the manifest */
|
|
16
|
+
model: Model & {
|
|
17
|
+
path: string;
|
|
18
|
+
};
|
|
19
|
+
/** Indicates if the model file is a JSON file */
|
|
20
|
+
isJson: boolean;
|
|
21
|
+
/** Absolute path to the artifact root folder */
|
|
22
|
+
artifactBasePath: string;
|
|
23
|
+
/** Absolute path to the output for the generated file */
|
|
24
|
+
outputFilePath: string;
|
|
25
|
+
/** Mask to apply */
|
|
26
|
+
transform?: Transform;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Extract dependency models from the manifest
|
|
30
|
+
* @param cwd
|
|
31
|
+
* @param manifest
|
|
32
|
+
* @param _logger
|
|
33
|
+
*/
|
|
34
|
+
export declare const extractDependencyModels: (cwd: string, manifest: Manifest, _logger?: Logger) => Promise<RetrievedDependencyModel>[];
|
|
35
|
+
//# sourceMappingURL=extract-dependency-models.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-dependency-models.d.mts","sourceRoot":"","sources":["../../../../src/core/manifest/extract-dependency-models.mts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAI1B,OAAO,KAAK,EACV,QAAQ,EACR,KAAK,EACL,SAAS,EACV,MAAM,gBAAgB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,2BAA2B;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,KAAK,EAAE,KAAK,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAChC,iDAAiD;IACjD,MAAM,EAAE,OAAO,CAAC;IAChB,gDAAgD;IAChD,gBAAgB,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB;IACpB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAiGD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,MAAM,EAAE,UAAU,QAAQ,EAAE,UAAU,MAAM,wCAUxF,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { promises as fs, } from 'node:fs';
|
|
2
|
+
import { createRequire, } from 'node:module';
|
|
3
|
+
import { basename, dirname, extname, join, resolve, } from 'node:path';
|
|
4
|
+
import { load, } from 'js-yaml';
|
|
5
|
+
import { OUTPUT_DIRECTORY, } from '../../constants.mjs';
|
|
6
|
+
import { isJsonFile, } from '../file-system/parse-file.mjs';
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
/**
|
|
9
|
+
* Sanitize the package path to be used in file system
|
|
10
|
+
* @param artifactName
|
|
11
|
+
*/
|
|
12
|
+
const sanitizePackagePath = (artifactName) => {
|
|
13
|
+
return artifactName
|
|
14
|
+
.replace('/', '-')
|
|
15
|
+
.replace(/^@/, '');
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve the transform object from the manifest
|
|
19
|
+
* @param cwd
|
|
20
|
+
* @param transform
|
|
21
|
+
*/
|
|
22
|
+
const retrieveTransform = async (cwd, transform) => {
|
|
23
|
+
if (typeof transform === 'string') {
|
|
24
|
+
const transformPath = resolve(cwd, transform);
|
|
25
|
+
const fileContent = await fs.readFile(transformPath, { encoding: 'utf8' });
|
|
26
|
+
return extname(transformPath).toLowerCase() === '.json'
|
|
27
|
+
? JSON.parse(fileContent)
|
|
28
|
+
: load(fileContent);
|
|
29
|
+
}
|
|
30
|
+
return transform;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Extract dependency model given simple model definition (as string or boolean)
|
|
34
|
+
* @param cwd
|
|
35
|
+
* @param artifactName
|
|
36
|
+
* @param modelName
|
|
37
|
+
*/
|
|
38
|
+
const extractDependencyModelsSimple = async (cwd, artifactName, modelName) => {
|
|
39
|
+
const artifactPackageJson = require.resolve(`${artifactName}/package.json`);
|
|
40
|
+
const artifactBasePath = dirname(artifactPackageJson);
|
|
41
|
+
const modelPath = typeof modelName === 'string' ? join(artifactBasePath, modelName) : require.resolve(artifactName);
|
|
42
|
+
const version = await fs.readFile(artifactPackageJson, { encoding: 'utf8' }).then((data) => JSON.parse(data).version || 'latest');
|
|
43
|
+
const content = await fs.readFile(modelPath, { encoding: 'utf8' });
|
|
44
|
+
const path = typeof modelName === 'string' ? modelName : artifactName;
|
|
45
|
+
const model = { path };
|
|
46
|
+
const outputFilePath = resolve(cwd, OUTPUT_DIRECTORY, sanitizePackagePath(artifactName), model.path);
|
|
47
|
+
return {
|
|
48
|
+
outputFilePath,
|
|
49
|
+
artifactBasePath,
|
|
50
|
+
artifactName,
|
|
51
|
+
modelPath,
|
|
52
|
+
version,
|
|
53
|
+
content,
|
|
54
|
+
model: {
|
|
55
|
+
path
|
|
56
|
+
},
|
|
57
|
+
isJson: isJsonFile(modelPath)
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Extract dependency model given full model definition
|
|
62
|
+
* @param cwd
|
|
63
|
+
* @param artifactName
|
|
64
|
+
* @param model
|
|
65
|
+
* @param transformPromise
|
|
66
|
+
*/
|
|
67
|
+
const extractDependencyModelsObject = async (cwd, artifactName, model, transformPromise) => {
|
|
68
|
+
const transform = await transformPromise;
|
|
69
|
+
const artifactPackageJson = require.resolve(`${artifactName}/package.json`);
|
|
70
|
+
const artifactBasePath = dirname(artifactPackageJson);
|
|
71
|
+
const modelPath = model.path ? join(artifactBasePath, model.path) : require.resolve(artifactName);
|
|
72
|
+
const version = await fs.readFile(artifactPackageJson, { encoding: 'utf8' }).then((data) => JSON.parse(data).version || 'latest');
|
|
73
|
+
const content = await fs.readFile(modelPath, { encoding: 'utf8' });
|
|
74
|
+
const defaultSpec = require.resolve(artifactName).split(artifactName)[1];
|
|
75
|
+
const path = model.path || defaultSpec;
|
|
76
|
+
const fileExtension = extname(path);
|
|
77
|
+
const replaceName = transform?.fileRename && path.replace(new RegExp(`(${basename(path, fileExtension)})${fileExtension}$`), transform.fileRename + fileExtension);
|
|
78
|
+
const fileNameOutput = replaceName || path;
|
|
79
|
+
const outputFilePath = resolve(cwd, OUTPUT_DIRECTORY, sanitizePackagePath(artifactName), fileNameOutput);
|
|
80
|
+
return {
|
|
81
|
+
transform,
|
|
82
|
+
outputFilePath,
|
|
83
|
+
artifactBasePath,
|
|
84
|
+
artifactName,
|
|
85
|
+
modelPath,
|
|
86
|
+
version,
|
|
87
|
+
content,
|
|
88
|
+
model: {
|
|
89
|
+
...model,
|
|
90
|
+
path
|
|
91
|
+
},
|
|
92
|
+
isJson: isJsonFile(modelPath)
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Extract dependency models from the manifest
|
|
97
|
+
* @param cwd
|
|
98
|
+
* @param manifest
|
|
99
|
+
* @param _logger
|
|
100
|
+
*/
|
|
101
|
+
export const extractDependencyModels = (cwd, manifest, _logger) => {
|
|
102
|
+
return Object.entries(manifest.models).flatMap(([dependencyName, modelDefinition]) => {
|
|
103
|
+
const models = Array.isArray(modelDefinition) ? modelDefinition : [modelDefinition];
|
|
104
|
+
return models
|
|
105
|
+
.flatMap((model) => typeof model === 'string' || typeof model === 'boolean'
|
|
106
|
+
? [extractDependencyModelsSimple(cwd, dependencyName, model)]
|
|
107
|
+
: (Array.isArray(model.transform)
|
|
108
|
+
? (model.transform.length > 0 ? model.transform : [undefined]).map((transform) => extractDependencyModelsObject(cwd, dependencyName, model, retrieveTransform(cwd, transform)))
|
|
109
|
+
: [extractDependencyModelsObject(cwd, dependencyName, model, retrieveTransform(cwd, model.transform))]));
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=extract-dependency-models.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-dependency-models.mjs","sourceRoot":"","sources":["../../../../src/core/manifest/extract-dependency-models.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,QAAQ,EACR,OAAO,EACP,OAAO,EACP,IAAI,EACJ,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,IAAI,GACL,MAAM,SAAS,CAAC;AAIjB,OAAO,EACL,gBAAgB,GACjB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACL,UAAU,GACX,MAAM,+BAA+B,CAAC;AA+BvC,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;GAGG;AACH,MAAM,mBAAmB,GAAG,CAAC,YAAoB,EAAE,EAAE;IACnD,OAAO,YAAY;SAChB,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;SACjB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,KAAK,EAAE,GAAW,EAAE,SAA8B,EAAkC,EAAE;IAC9G,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QAC9C,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3E,OAAO,OAAO,CAAC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,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,6BAA6B,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC;gBAC/K,CAAC,CAAC,CAAC,6BAA6B,CAAC,GAAG,EAAE,cAAc,EAAE,KAAK,EAAE,iBAAiB,CAAC,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACjH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PackageJson } from 'type-fest';
|
|
2
|
+
import type { Logger } from '../../logger.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Mask object for filtering properties
|
|
5
|
+
*/
|
|
6
|
+
export interface Mask {
|
|
7
|
+
properties?: Record<string, any>;
|
|
8
|
+
[x: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface Transform {
|
|
11
|
+
/** Mask to apply */
|
|
12
|
+
mask?: Mask;
|
|
13
|
+
/** Rename the model */
|
|
14
|
+
titleRename?: string;
|
|
15
|
+
/** Rename the outputted file (without extension) */
|
|
16
|
+
fileRename: string;
|
|
17
|
+
}
|
|
18
|
+
type TransformOrReference = Transform | string;
|
|
19
|
+
/**
|
|
20
|
+
* Model definition within a dependency
|
|
21
|
+
*/
|
|
22
|
+
export interface Model {
|
|
23
|
+
/** Path to the model in the artifact */
|
|
24
|
+
path?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Transforms to apply to the model
|
|
27
|
+
* Note that for each transform object, a new definition will be generated
|
|
28
|
+
*/
|
|
29
|
+
transform?: TransformOrReference | TransformOrReference[];
|
|
30
|
+
}
|
|
31
|
+
/** List of supported types for an Model */
|
|
32
|
+
export type SupportedModelTypes = string | Model | boolean;
|
|
33
|
+
/** Models dependencies */
|
|
34
|
+
export type Models = Record<string, SupportedModelTypes | SupportedModelTypes[]>;
|
|
35
|
+
/** Manifest file structure */
|
|
36
|
+
export type Manifest = PackageJson & {
|
|
37
|
+
models: Models;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve Manifest file
|
|
41
|
+
* @param workspaceDirectory
|
|
42
|
+
* @param logger
|
|
43
|
+
*/
|
|
44
|
+
export declare const retrieveManifest: (workspaceDirectory: string, logger?: Logger) => Promise<Manifest | undefined>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=manifest.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.mts","sourceRoot":"","sources":["../../../../src/core/manifest/manifest.mts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,WAAW,CAAC;AAInB,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,oBAAoB;IACpB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,uBAAuB;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,oBAAoB,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,SAAS,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,EAAE,CAAC;CAC3D;AAED,2CAA2C;AAC3C,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAE3D,0BAA0B;AAC1B,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,mBAAmB,EAAE,CAAC,CAAC;AAEjF,8BAA8B;AAC9B,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AA2BxD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAU,oBAAoB,MAAM,EAAE,SAAQ,MAAgB,KAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAoBzH,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, promises as fs, } from 'node:fs';
|
|
2
|
+
import { extname, resolve, } from 'node:path';
|
|
3
|
+
import { fileURLToPath, } from 'node:url';
|
|
4
|
+
import { Ajv, } from 'ajv';
|
|
5
|
+
import { load, } from 'js-yaml';
|
|
6
|
+
import { DEFAULT_MANIFEST_FILENAMES, } from '../../constants.mjs';
|
|
7
|
+
/**
|
|
8
|
+
* Validate the manifest file
|
|
9
|
+
* @param manifest
|
|
10
|
+
* @param manifestPath
|
|
11
|
+
* @param logger
|
|
12
|
+
*/
|
|
13
|
+
const isValidManifest = async (manifest, manifestPath, logger) => {
|
|
14
|
+
if (!manifest || (typeof manifest === 'object' && !('models' in manifest))) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const ajv = new Ajv();
|
|
18
|
+
const schemaPath = resolve(fileURLToPath(new URL('.', import.meta.url)), '..', '..', 'schemas', 'manifest.schema.json');
|
|
19
|
+
const schema = JSON.parse(await fs.readFile(schemaPath, { encoding: 'utf8' }));
|
|
20
|
+
const validate = ajv.compile(schema);
|
|
21
|
+
const isValid = validate(manifest);
|
|
22
|
+
if (!isValid) {
|
|
23
|
+
logger.error(`${manifestPath} is invalid. Errors:`);
|
|
24
|
+
logger.error(validate.errors);
|
|
25
|
+
throw new Error('Invalid models definitions');
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve Manifest file
|
|
31
|
+
* @param workspaceDirectory
|
|
32
|
+
* @param logger
|
|
33
|
+
*/
|
|
34
|
+
export const retrieveManifest = async (workspaceDirectory, logger = console) => {
|
|
35
|
+
for (const manifestFileName of DEFAULT_MANIFEST_FILENAMES) {
|
|
36
|
+
const manifestPath = resolve(workspaceDirectory, manifestFileName);
|
|
37
|
+
if (!existsSync(manifestPath)) {
|
|
38
|
+
logger.debug?.(`Manifest file not found at ${manifestPath}`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const content = await fs.readFile(manifestPath, { encoding: 'utf8' });
|
|
42
|
+
const manifest = (extname(manifestPath).toLowerCase() === '.json'
|
|
43
|
+
? JSON.parse(content)
|
|
44
|
+
: load(content));
|
|
45
|
+
if (await isValidManifest(manifest, manifestPath, logger)) {
|
|
46
|
+
logger.info?.(`Manifest file found at ${manifestPath}`);
|
|
47
|
+
return manifest;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
logger.debug?.(`Manifest file at ${manifestPath} is not conform to the expected schema`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=manifest.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.mjs","sourceRoot":"","sources":["../../../../src/core/manifest/manifest.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,QAAQ,IAAI,EAAE,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,OAAO,EACP,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,GACd,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,GAAG,GACJ,MAAM,KAAK,CAAC;AACb,OAAO,EACL,IAAI,GACL,MAAM,SAAS,CAAC;AAIjB,OAAO,EACL,0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,GAAG,OAAO,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;QACnE,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;YAC9B,MAAM,CAAC,KAAK,EAAE,CAAC,8BAA8B,YAAY,EAAE,CAAC,CAAC;YAC7D,SAAS;QACX,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,KAAK,OAAO;YAC/D,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YACrB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAa,CAAC;QAC/B,IAAI,MAAM,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,CAAC;YAC1D,MAAM,CAAC,IAAI,EAAE,CAAC,0BAA0B,YAAY,EAAE,CAAC,CAAC;YACxD,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,EAAE,CAAC,oBAAoB,YAAY,wCAAwC,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RetrievedDependencyModel } from './manifest/extract-dependency-models.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Deserialize the content of a model file
|
|
4
|
+
* @param specification
|
|
5
|
+
* @param model
|
|
6
|
+
*/
|
|
7
|
+
export declare const deserialize: (specification: string, model: RetrievedDependencyModel) => any;
|
|
8
|
+
/**
|
|
9
|
+
* Serialize an object into a model file content
|
|
10
|
+
* @param specification
|
|
11
|
+
* @param model
|
|
12
|
+
*/
|
|
13
|
+
export declare const serialize: (specification: any, model: RetrievedDependencyModel) => string;
|
|
14
|
+
//# sourceMappingURL=serialization.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.mts","sourceRoot":"","sources":["../../../src/core/serialization.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,0CAA0C,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,eAAe,MAAM,EAAE,OAAO,wBAAwB,KAAG,GAKpF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,eAAe,GAAG,EAAE,OAAO,wBAAwB,KAAG,MAK/E,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { dump, load, } from 'js-yaml';
|
|
2
|
+
/**
|
|
3
|
+
* Deserialize the content of a model file
|
|
4
|
+
* @param specification
|
|
5
|
+
* @param model
|
|
6
|
+
*/
|
|
7
|
+
export const deserialize = (specification, model) => {
|
|
8
|
+
if (model.isJson) {
|
|
9
|
+
return JSON.parse(specification);
|
|
10
|
+
}
|
|
11
|
+
return load(specification);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Serialize an object into a model file content
|
|
15
|
+
* @param specification
|
|
16
|
+
* @param model
|
|
17
|
+
*/
|
|
18
|
+
export const serialize = (specification, model) => {
|
|
19
|
+
if (model.isJson) {
|
|
20
|
+
return JSON.stringify(specification, null, 2);
|
|
21
|
+
}
|
|
22
|
+
return dump(specification);
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=serialization.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.mjs","sourceRoot":"","sources":["../../../src/core/serialization.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,IAAI,GACL,MAAM,SAAS,CAAC;AAKjB;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,aAAqB,EAAE,KAA+B,EAAO,EAAE;IACzF,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;AAC7B,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,aAAkB,EAAE,KAA+B,EAAU,EAAE;IACvF,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MASKED_PROPERTY_KEY, SOURCE_PROPERTY_KEY, TOUCHED_PROPERTY_KEY, VERSION_PROPERTY_KEY } from '../../constants.mjs';
|
|
2
|
+
import type { Logger } from '../../logger.mjs';
|
|
3
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
4
|
+
type AdditionalAnnotation = {
|
|
5
|
+
[MASKED_PROPERTY_KEY]: boolean;
|
|
6
|
+
[TOUCHED_PROPERTY_KEY]: boolean;
|
|
7
|
+
[SOURCE_PROPERTY_KEY]: string;
|
|
8
|
+
[VERSION_PROPERTY_KEY]: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Add annotation to the specification indicating its source, version, and if it was masked
|
|
12
|
+
* @param specification
|
|
13
|
+
* @param retrievedModel
|
|
14
|
+
* @param _logger
|
|
15
|
+
*/
|
|
16
|
+
export declare const addAnnotation: <S extends object>(specification: S, retrievedModel: RetrievedDependencyModel, _logger?: Logger) => S & AdditionalAnnotation;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=add-annotation.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-annotation.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/add-annotation.mts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD,KAAK,oBAAoB,GAAG;IAC1B,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC/B,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAChC,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC9B,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,EAAE,eAAe,CAAC,EAAE,gBAAgB,wBAAwB,EAAE,UAAU,MAAM,KAAG,CAAC,GAAG,oBASlI,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { posix, } from 'node:path';
|
|
2
|
+
import { MASKED_PROPERTY_KEY, SOURCE_PROPERTY_KEY, TOUCHED_PROPERTY_KEY, VERSION_PROPERTY_KEY, } from '../../constants.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Add annotation to the specification indicating its source, version, and if it was masked
|
|
5
|
+
* @param specification
|
|
6
|
+
* @param retrievedModel
|
|
7
|
+
* @param _logger
|
|
8
|
+
*/
|
|
9
|
+
export const addAnnotation = (specification, retrievedModel, _logger) => {
|
|
10
|
+
const { artifactName, version, transform } = retrievedModel;
|
|
11
|
+
return {
|
|
12
|
+
...specification,
|
|
13
|
+
[SOURCE_PROPERTY_KEY]: posix.join(artifactName, retrievedModel.model.path),
|
|
14
|
+
[VERSION_PROPERTY_KEY]: version,
|
|
15
|
+
[MASKED_PROPERTY_KEY]: !!transform?.mask,
|
|
16
|
+
[TOUCHED_PROPERTY_KEY]: !!transform
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=add-annotation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-annotation.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/add-annotation.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,GACN,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAe7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAmB,aAAgB,EAAE,cAAwC,EAAE,OAAgB,EAA4B,EAAE;IACxJ,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC;IAC5D,OAAO;QACL,GAAG,aAAa;QAChB,CAAC,mBAAmB,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC;QAC1E,CAAC,oBAAoB,CAAC,EAAE,OAAO;QAC/B,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,IAAI;QACxC,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,SAAS;KACpC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Logger } from '../../logger.mjs';
|
|
2
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Apply the mask to the model
|
|
5
|
+
* @param specification
|
|
6
|
+
* @param retrievedModel
|
|
7
|
+
* @param _logger
|
|
8
|
+
*/
|
|
9
|
+
export declare const applyMask: <S extends object>(specification: S, retrievedModel: RetrievedDependencyModel, _logger?: Logger) => S;
|
|
10
|
+
//# sourceMappingURL=apply-mask.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-mask.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/apply-mask.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAqDnD;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EAAE,eAAe,CAAC,EAAE,gBAAgB,wBAAwB,EAAE,UAAU,MAAM,KAAG,CAK1H,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-argument -- due to unknown object structure */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access -- due to unknown object structure */
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment -- due to unknown object structure */
|
|
4
|
+
/**
|
|
5
|
+
* Recursively apply the mask to model properties
|
|
6
|
+
* @param modelProperties
|
|
7
|
+
* @param maskProperties
|
|
8
|
+
*/
|
|
9
|
+
const maskModelProperties = (modelProperties, maskProperties) => {
|
|
10
|
+
return Object.fromEntries(Object.entries(modelProperties)
|
|
11
|
+
.filter(([key]) => !!maskProperties && key in maskProperties && maskProperties[key] !== false)
|
|
12
|
+
.map(([key, value]) => typeof maskProperties[key] === 'object' ? [key, maskModelProperties(value, maskProperties[key])] : [key, value]));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Recursively apply the sub-mask to the specification
|
|
16
|
+
* @param specification
|
|
17
|
+
* @param mask
|
|
18
|
+
*/
|
|
19
|
+
const applySubMask = (specification, mask) => {
|
|
20
|
+
const result = { ...specification };
|
|
21
|
+
if (!mask || typeof mask !== 'object') {
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
if ('properties' in mask && 'properties' in result) {
|
|
25
|
+
result.properties = maskModelProperties(result.properties, mask.properties);
|
|
26
|
+
}
|
|
27
|
+
const maskAdditionalProperties = Object.entries(mask)
|
|
28
|
+
.filter(([key]) => key !== 'properties');
|
|
29
|
+
if (maskAdditionalProperties.length > 0) {
|
|
30
|
+
delete result.type;
|
|
31
|
+
delete result.properties;
|
|
32
|
+
for (const [key, value] of maskAdditionalProperties) {
|
|
33
|
+
if (typeof value === 'object') {
|
|
34
|
+
result[key] = Array.isArray(value)
|
|
35
|
+
? value.map((subMask) => applyMask(result[key], subMask))
|
|
36
|
+
: value && Object.fromEntries(Object.entries(value).map(([maskKey, subMask]) => ([maskKey, applyMask(result[key][maskKey], subMask)])));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
result[key] = value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Apply the mask to the model
|
|
47
|
+
* @param specification
|
|
48
|
+
* @param retrievedModel
|
|
49
|
+
* @param _logger
|
|
50
|
+
*/
|
|
51
|
+
export const applyMask = (specification, retrievedModel, _logger) => {
|
|
52
|
+
if (!retrievedModel.transform) {
|
|
53
|
+
return specification;
|
|
54
|
+
}
|
|
55
|
+
return applySubMask(specification, retrievedModel.transform.mask);
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=apply-mask.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-mask.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/apply-mask.mts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,kGAAkG;AAClG,+FAA+F;AAS/F;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,CAAC,eAAoB,EAAE,cAAmB,EAAO,EAAE;IAC7E,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC;SAC5B,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc,IAAI,GAAG,IAAI,cAAc,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,KAAK,CAAC;SAC7F,GAAG,C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C,OAAO,EAAO,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC;oBAC9D,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5I,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAmB,aAAgB,EAAE,cAAwC,EAAE,OAAgB,EAAK,EAAE;IAC7H,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;QAC9B,OAAO,aAAa,CAAC;IACvB,CAAC;IACD,OAAO,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,SAAS,CAAC,IAAI,CAAM,CAAC;AACzE,CAAC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Logger } from '../../logger.mjs';
|
|
2
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Rename the title of the specification
|
|
5
|
+
* @param specification
|
|
6
|
+
* @param retrievedModel
|
|
7
|
+
* @param _logger
|
|
8
|
+
*/
|
|
9
|
+
export declare const renameTitle: <S extends object>(specification: S, retrievedModel: RetrievedDependencyModel, _logger?: Logger) => S;
|
|
10
|
+
//# sourceMappingURL=rename.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/rename.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,eAAe,CAAC,EAAE,gBAAgB,wBAAwB,EAAE,UAAU,MAAM,KAAG,CAU5H,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rename the title of the specification
|
|
3
|
+
* @param specification
|
|
4
|
+
* @param retrievedModel
|
|
5
|
+
* @param _logger
|
|
6
|
+
*/
|
|
7
|
+
export const renameTitle = (specification, retrievedModel, _logger) => {
|
|
8
|
+
if (retrievedModel.transform?.titleRename) {
|
|
9
|
+
let title = 'title' in specification ? specification.title : undefined;
|
|
10
|
+
title = title && title.replace(new RegExp(`^(${title})$`), retrievedModel.transform.titleRename);
|
|
11
|
+
specification = {
|
|
12
|
+
...specification,
|
|
13
|
+
title
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return specification;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=rename.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/rename.mts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,aAAgB,EAAE,cAAwC,EAAE,OAAgB,EAAK,EAAE;IAC/H,IAAI,cAAc,CAAC,SAAS,EAAE,WAAW,EAAE,CAAC;QAC1C,IAAI,KAAK,GAAuB,OAAO,IAAI,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,KAAe,CAAC,CAAC,CAAC,SAAS,CAAC;QACrG,KAAK,GAAG,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACjG,aAAa,GAAG;YACd,GAAG,aAAa;YAChB,KAAK;SACN,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger } from '../../logger.mjs';
|
|
2
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
3
|
+
type ReferenceSpecification = {
|
|
4
|
+
$ref: string;
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Transform the specification to a single reference if no transformation required
|
|
9
|
+
* The process will keep the x-vendor properties from the retrieved model
|
|
10
|
+
* @param specification
|
|
11
|
+
* @param retrievedModel
|
|
12
|
+
* @param logger
|
|
13
|
+
*/
|
|
14
|
+
export declare const toReference: <S extends object>(specification: S, retrievedModel: RetrievedDependencyModel, logger?: Logger) => S | ReferenceSpecification;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=to-reference.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-reference.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/to-reference.mts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD,KAAK,sBAAsB,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,MAAM,EAAE,eAAe,CAAC,EAAE,gBAAgB,wBAAwB,EAAE,SAAS,MAAM,KAAG,CAAC,GAAG,sBAU/H,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { relative, } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Transform the specification to a single reference if no transformation required
|
|
4
|
+
* The process will keep the x-vendor properties from the retrieved model
|
|
5
|
+
* @param specification
|
|
6
|
+
* @param retrievedModel
|
|
7
|
+
* @param logger
|
|
8
|
+
*/
|
|
9
|
+
export const toReference = (specification, retrievedModel, logger) => {
|
|
10
|
+
if (retrievedModel.transform) {
|
|
11
|
+
logger?.debug?.(`The specification ${retrievedModel.modelPath} has transform, the conversion to reference will be ignored`);
|
|
12
|
+
return specification;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
$ref: relative(retrievedModel.outputFilePath, retrievedModel.modelPath),
|
|
16
|
+
...Object.fromEntries(Object.entries(retrievedModel).filter(([key]) => key.startsWith('x-')))
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=to-reference.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-reference.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/to-reference.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,GACT,MAAM,WAAW,CAAC;AAanB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAmB,aAAgB,EAAE,cAAwC,EAAE,MAAe,EAA8B,EAAE;IACvJ,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;QAC7B,MAAM,EAAE,KAAK,EAAE,CAAC,qBAAqB,cAAc,CAAC,SAAS,6DAA6D,CAAC,CAAC;QAC5H,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ,CAAC,cAAc,CAAC,cAAc,EAAE,cAAc,CAAC,SAAS,CAAC;QACvE,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;KAC9F,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Logger } from '../../logger.mjs';
|
|
2
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Transform a specification with specified transformation function
|
|
5
|
+
*/
|
|
6
|
+
export type Transform<S extends object = object, T = any> = (specification: S, retrievedModel: RetrievedDependencyModel, logger?: Logger) => T | Promise<T>;
|
|
7
|
+
//# sourceMappingURL=transform.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/transform.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/transform.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { REF_REWRITE_PROPERTY_KEY } from '../../constants.mjs';
|
|
2
|
+
import type { Logger } from '../../logger.mjs';
|
|
3
|
+
import type { RetrievedDependencyModel } from '../manifest/extract-dependency-models.mjs';
|
|
4
|
+
type AdditionalAnnotation = {
|
|
5
|
+
[REF_REWRITE_PROPERTY_KEY]: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Update the $ref references in the specification to be relative to the model path
|
|
9
|
+
* @param specification
|
|
10
|
+
* @param receivedModel
|
|
11
|
+
* @param _logger
|
|
12
|
+
*/
|
|
13
|
+
export declare const updateReferences: <S extends object>(specification: S, receivedModel: RetrievedDependencyModel, _logger?: Logger) => S & AdditionalAnnotation;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=update-references.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-references.d.mts","sourceRoot":"","sources":["../../../../src/core/transforms/update-references.mts"],"names":[],"mappings":"AAQA,OAAO,EACL,wBAAwB,EACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,MAAM,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACzB,MAAM,2CAA2C,CAAC;AAMnD,KAAK,oBAAoB,GAAG;IAC1B,CAAC,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,EAAE,eAAe,CAAC,EAAE,eAAe,wBAAwB,EAAE,UAAU,MAAM,KAAG,CAAC,GAAG,oBA4BpI,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isAbsolute, resolve, } from 'node:path';
|
|
2
|
+
import { dirname, relative, } from 'node:path/posix';
|
|
3
|
+
import { REF_REWRITE_PROPERTY_KEY, } from '../../constants.mjs';
|
|
4
|
+
const isRelativePath = (path) => {
|
|
5
|
+
return !URL.canParse(path) && !isAbsolute(path);
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Update the $ref references in the specification to be relative to the model path
|
|
9
|
+
* @param specification
|
|
10
|
+
* @param receivedModel
|
|
11
|
+
* @param _logger
|
|
12
|
+
*/
|
|
13
|
+
export const updateReferences = (specification, receivedModel, _logger) => {
|
|
14
|
+
let hasTouchedReference = false;
|
|
15
|
+
const walkSpecification = (specItem) => {
|
|
16
|
+
if (typeof specItem === 'object') {
|
|
17
|
+
if (specItem === null) {
|
|
18
|
+
return specItem;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray(specItem)) {
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return -- due to unknown object structure
|
|
22
|
+
return specItem.map((item) => walkSpecification(item));
|
|
23
|
+
}
|
|
24
|
+
return Object.fromEntries(Object.entries(specItem).map(([key, value]) => {
|
|
25
|
+
if (key === '$ref' && typeof value === 'string' && isRelativePath(value)) {
|
|
26
|
+
value = relative(dirname(receivedModel.outputFilePath), resolve(dirname(receivedModel.modelPath), value));
|
|
27
|
+
hasTouchedReference = true;
|
|
28
|
+
}
|
|
29
|
+
return [key, walkSpecification(value)];
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
return specItem;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
...walkSpecification(specification),
|
|
36
|
+
[REF_REWRITE_PROPERTY_KEY]: hasTouchedReference
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=update-references.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-references.mjs","sourceRoot":"","sources":["../../../../src/core/transforms/update-references.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,OAAO,GACR,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,OAAO,EACP,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAQ7B,MAAM,cAAc,GAAG,CAAC,IAAY,EAAW,EAAE;IAC/C,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC,CAAC;AAMF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAmB,aAAgB,EAAE,aAAuC,EAAE,OAAgB,EAA4B,EAAE;IA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|
+
*/
|
|
4
|
+
export interface Logger {
|
|
5
|
+
/**
|
|
6
|
+
* Log an error.
|
|
7
|
+
* @param message Message to log
|
|
8
|
+
* @param optionalParams Optional parameters to log
|
|
9
|
+
*/
|
|
10
|
+
error(message?: any, ...optionalParams: any[]): void;
|
|
11
|
+
/**
|
|
12
|
+
* Log a warning.
|
|
13
|
+
* @param message Message to log
|
|
14
|
+
* @param optionalParams Optional parameters to log
|
|
15
|
+
*/
|
|
16
|
+
warn(message?: any, ...optionalParams: any[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* Log a message.
|
|
19
|
+
* @param message Message to log
|
|
20
|
+
* @param optionalParams Optional parameters to log
|
|
21
|
+
*/
|
|
22
|
+
info(message?: any, ...optionalParams: any[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Log a message.
|
|
25
|
+
* @param message Message to log
|
|
26
|
+
* @param optionalParams Optional parameters to log
|
|
27
|
+
*/
|
|
28
|
+
log(message?: any, ...optionalParams: any[]): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log a debug message.
|
|
31
|
+
* @param message Message to log
|
|
32
|
+
* @param optionalParams Optional parameters to log
|
|
33
|
+
*/
|
|
34
|
+
debug?(message?: any, ...optionalParams: any[]): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=logger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.mts","sourceRoot":"","sources":["../../src/logger.mts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAErD;;;;OAIG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEpD;;;;OAIG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEpD;;;;OAIG;IACH,GAAG,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEnD;;;;OAIG;IACH,KAAK,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACvD"}
|
package/src/logger.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","sourceRoot":"","sources":["../../src/logger.mts"],"names":[],"mappings":""}
|
package/src/main.d.mts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Logger } from './logger.mjs';
|
|
2
|
+
/** Options for Install Dependencies */
|
|
3
|
+
export interface InstallDependenciesOptions {
|
|
4
|
+
/** Logger instance */
|
|
5
|
+
logger?: Logger;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Run the process to download and write dependency models
|
|
9
|
+
* @param workingDirectory
|
|
10
|
+
* @param options
|
|
11
|
+
*/
|
|
12
|
+
export declare const installDependencies: (workingDirectory?: string, options?: InstallDependenciesOptions) => Promise<void>;
|
|
13
|
+
//# sourceMappingURL=main.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.mts","sourceRoot":"","sources":["../../src/main.mts"],"names":[],"mappings":"AAkCA,OAAO,KAAK,EACV,MAAM,EACP,MAAM,cAAc,CAAC;AAEtB,uCAAuC;AACvC,MAAM,WAAW,0BAA0B;IACzC,sBAAsB;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,yBAAwB,EAAE,UAAU,0BAA0B,KAAG,OAAO,CAAC,IAAI,CA2CtH,CAAC"}
|
package/src/main.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { cwd, } from 'node:process';
|
|
2
|
+
import { cleanOutputDirectory, } from './core/file-system/cleaner.mjs';
|
|
3
|
+
import { writeModelFile, } from './core/file-system/write-model.mjs';
|
|
4
|
+
import { extractDependencyModels, } from './core/manifest/extract-dependency-models.mjs';
|
|
5
|
+
import { retrieveManifest, } from './core/manifest/manifest.mjs';
|
|
6
|
+
import { deserialize, serialize, } from './core/serialization.mjs';
|
|
7
|
+
import { addAnnotation, } from './core/transforms/add-annotation.mjs';
|
|
8
|
+
import { applyMask, } from './core/transforms/apply-mask.mjs';
|
|
9
|
+
import { renameTitle, } from './core/transforms/rename.mjs';
|
|
10
|
+
import { toReference, } from './core/transforms/to-reference.mjs';
|
|
11
|
+
import { updateReferences, } from './core/transforms/update-references.mjs';
|
|
12
|
+
/**
|
|
13
|
+
* Run the process to download and write dependency models
|
|
14
|
+
* @param workingDirectory
|
|
15
|
+
* @param options
|
|
16
|
+
*/
|
|
17
|
+
export const installDependencies = async (workingDirectory = cwd(), options) => {
|
|
18
|
+
const { logger = console } = options || {};
|
|
19
|
+
const manifest = await retrieveManifest(workingDirectory, logger);
|
|
20
|
+
if (!manifest) {
|
|
21
|
+
logger?.info('No Manifest file discovered');
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
await cleanOutputDirectory(workingDirectory);
|
|
25
|
+
const models = extractDependencyModels(workingDirectory, manifest, logger);
|
|
26
|
+
await cleanOutputDirectory(workingDirectory);
|
|
27
|
+
const results = await Promise.allSettled(models
|
|
28
|
+
.map(async (retrievedModelPromise) => {
|
|
29
|
+
const retrievedModel = await retrievedModelPromise;
|
|
30
|
+
logger?.debug?.(`Retrieving model from ${retrievedModel.artifactName} at ${retrievedModel.modelPath}`);
|
|
31
|
+
const modelObj = deserialize(retrievedModel.content, retrievedModel);
|
|
32
|
+
const transforms = [toReference, addAnnotation, applyMask, updateReferences, renameTitle];
|
|
33
|
+
transforms.reduce((acc, transform) => transform(acc, retrievedModel, logger), deserialize(retrievedModel.content, retrievedModel));
|
|
34
|
+
return {
|
|
35
|
+
...retrievedModel,
|
|
36
|
+
content: serialize(modelObj, retrievedModel)
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
.map(async (processedModel) => {
|
|
40
|
+
await writeModelFile(await processedModel);
|
|
41
|
+
}));
|
|
42
|
+
const rejected = results
|
|
43
|
+
.filter((result) => result.status === 'rejected');
|
|
44
|
+
if (rejected.length > 0) {
|
|
45
|
+
logger?.error(`Failed to retrieve some models:`);
|
|
46
|
+
rejected.forEach((result) => logger?.error(result.reason));
|
|
47
|
+
throw new Error('Failed to retrieve some models');
|
|
48
|
+
}
|
|
49
|
+
logger?.info(`Successfully retrieved all models`);
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=main.mjs.map
|
package/src/main.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.mjs","sourceRoot":"","sources":["../../src/main.mts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,GACJ,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,GACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,cAAc,GACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,uBAAuB,GACxB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EACL,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,WAAW,EACX,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,aAAa,GACd,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,SAAS,GACV,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,WAAW,GACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,WAAW,GACZ,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,gBAAgB,GACjB,MAAM,yCAAyC,CAAC;AAWjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,EAAE,gBAAgB,G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,GAAG,CAAC,KAAK,EAAE,cAAc,EAAE,EAAE;QAC5B,MAAM,cAAc,CAAC,MAAM,cAAc,CAAC,CAAC;IAC7C,CAAC,CAAC,CACL,CAAC;IAEF,MAAM,QAAQ,GAAG,OAAO;SACrB,MAAM,CAAC,CAAC,MAAM,EAAmC,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC;IAErF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACjD,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAC3D,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,EAAE,IAAI,CAAC,mCAAmC,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.d.mts","sourceRoot":"","sources":["../../src/public_api.mts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public_api.mjs","sourceRoot":"","sources":["../../src/public_api.mts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|