@kosdev-code/kos-nx-plugin 2.0.30 → 2.0.32
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/generators.json +5 -0
- package/package.json +2 -2
- package/src/generators/kos-add-future-to-model/README.md +106 -0
- package/src/generators/kos-add-future-to-model/generator.d.ts +5 -0
- package/src/generators/kos-add-future-to-model/generator.d.ts.map +1 -0
- package/src/generators/kos-add-future-to-model/generator.js +63 -0
- package/src/generators/kos-add-future-to-model/generator.js.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/model-transformer.d.ts +17 -0
- package/src/generators/kos-add-future-to-model/lib/model-transformer.d.ts.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/model-transformer.js +277 -0
- package/src/generators/kos-add-future-to-model/lib/model-transformer.js.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/normalize-options.d.ts +4 -0
- package/src/generators/kos-add-future-to-model/lib/normalize-options.d.ts.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/normalize-options.js +54 -0
- package/src/generators/kos-add-future-to-model/lib/normalize-options.js.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/registration-transformer.d.ts +11 -0
- package/src/generators/kos-add-future-to-model/lib/registration-transformer.d.ts.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/registration-transformer.js +73 -0
- package/src/generators/kos-add-future-to-model/lib/registration-transformer.js.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/service-transformer.d.ts +13 -0
- package/src/generators/kos-add-future-to-model/lib/service-transformer.d.ts.map +1 -0
- package/src/generators/kos-add-future-to-model/lib/service-transformer.js +178 -0
- package/src/generators/kos-add-future-to-model/lib/service-transformer.js.map +1 -0
- package/src/generators/kos-add-future-to-model/schema.d.ts +24 -0
- package/src/generators/kos-add-future-to-model/schema.json +59 -0
- package/src/generators/kos-companion-model/files/types/index.d.ts.template +2 -2
- package/src/generators/kos-companion-model/schema.d.ts +1 -0
- package/src/generators/kos-model/files/model/__nameDashCase__-model.ts.template +93 -8
- package/src/generators/kos-model/files/model/__nameDashCase__-registration.ts.template +37 -3
- package/src/generators/kos-model/files/services/__nameDashCase__-services.ts.template +38 -2
- package/src/generators/kos-model/generator.d.ts.map +1 -1
- package/src/generators/kos-model/generator.js +2 -0
- package/src/generators/kos-model/generator.js.map +1 -1
- package/src/generators/kos-model/schema.d.ts +2 -0
- package/src/generators/kos-model/schema.json +41 -0
package/generators.json
CHANGED
|
@@ -65,6 +65,11 @@
|
|
|
65
65
|
"factory": "./src/generators/kos-splash-project/generator",
|
|
66
66
|
"schema": "./src/generators/kos-splash-project/schema.json",
|
|
67
67
|
"description": "Generates a new project to create a KOS splash screen"
|
|
68
|
+
},
|
|
69
|
+
"kos-add-future-to-model": {
|
|
70
|
+
"factory": "./src/generators/kos-add-future-to-model/generator",
|
|
71
|
+
"schema": "./src/generators/kos-add-future-to-model/schema.json",
|
|
72
|
+
"description": "Add Future support to an existing KOS model"
|
|
68
73
|
}
|
|
69
74
|
}
|
|
70
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kosdev-code/kos-nx-plugin",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.32",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"generators": "./generators.json",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"main": "./src/index.js",
|
|
20
20
|
"kos": {
|
|
21
21
|
"build": {
|
|
22
|
-
"gitHash": "
|
|
22
|
+
"gitHash": "ea8751ddd6a1c43f56f22bab3bf99a0e3bd3f824"
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Add Future Support to Existing KOS Model
|
|
2
|
+
|
|
3
|
+
This generator adds Future support to an existing KOS model, transforming it to support progress tracking for long-running operations.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Via CLI
|
|
8
|
+
```bash
|
|
9
|
+
# Interactive mode - automatically discovers and lists all available models
|
|
10
|
+
kos-cli add-future
|
|
11
|
+
|
|
12
|
+
# With parameters
|
|
13
|
+
kos-cli add-future --modelName=MyModel --futureType=minimal --project=my-project
|
|
14
|
+
|
|
15
|
+
# Direct Nx
|
|
16
|
+
nx generate @kosdev-code/kos-nx-plugin:kos-add-future-to-model --modelName=MyModel --modelProject=my-project --futureType=complete
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Parameters
|
|
20
|
+
|
|
21
|
+
- `modelName` (required): Name of the existing model to add Future support to
|
|
22
|
+
- `modelProject` (required): Project where the model is located
|
|
23
|
+
- `futureType`: Type of Future support (`minimal` or `complete`, defaults to `minimal`)
|
|
24
|
+
- `updateServices`: Whether to update/create services file (defaults to `true`)
|
|
25
|
+
- `dryRun`: Show what would be changed without making actual modifications
|
|
26
|
+
|
|
27
|
+
## What It Does
|
|
28
|
+
|
|
29
|
+
### Model File Changes
|
|
30
|
+
- Adds Future-related imports
|
|
31
|
+
- Adds Future properties (`futureHandler`, `future` for complete mode)
|
|
32
|
+
- Adds mixin setup call in constructor
|
|
33
|
+
- Adds `@kosFuture()` placeholder method
|
|
34
|
+
- Updates public type with `ExternalFutureInterface` intersection
|
|
35
|
+
- Adds `onFutureUpdate` method (for complete mode)
|
|
36
|
+
- Updates class implements clause (for complete mode)
|
|
37
|
+
|
|
38
|
+
### Services File Changes
|
|
39
|
+
- Adds `FutureResponse` import
|
|
40
|
+
- Creates placeholder Future operation service method
|
|
41
|
+
- Adds progress and result type definitions
|
|
42
|
+
- Creates file if it doesn't exist
|
|
43
|
+
|
|
44
|
+
### Registration File Changes
|
|
45
|
+
- Adds `as any` type cast for intersection type
|
|
46
|
+
- Updates documentation with Future capabilities
|
|
47
|
+
- Adds Future usage examples
|
|
48
|
+
|
|
49
|
+
## Example Transformation
|
|
50
|
+
|
|
51
|
+
**Before:**
|
|
52
|
+
```typescript
|
|
53
|
+
export type MyModel = PublicModelInterface<MyModelImpl>;
|
|
54
|
+
|
|
55
|
+
@kosModel(MODEL_TYPE)
|
|
56
|
+
export class MyModelImpl implements IKosDataModel, IKosIdentifiable {
|
|
57
|
+
constructor(modelId: string, options: MyOptions, context: KosCreationContext) {
|
|
58
|
+
this.id = modelId;
|
|
59
|
+
this.logger = context.logger;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**After (minimal):**
|
|
65
|
+
```typescript
|
|
66
|
+
import { kosFuture, setupMinimalFutureSupport } from "@kosdev-code/kos-ui-sdk";
|
|
67
|
+
import type { ExternalFutureInterface, FutureAwareContainer } from "@kosdev-code/kos-ui-sdk";
|
|
68
|
+
import type { MyOperationProgress } from "./services";
|
|
69
|
+
|
|
70
|
+
export type MyModel = PublicModelInterface<MyModelImpl> & ExternalFutureInterface<MyOperationProgress>;
|
|
71
|
+
|
|
72
|
+
@kosModel(MODEL_TYPE)
|
|
73
|
+
export class MyModelImpl implements IKosDataModel, IKosIdentifiable {
|
|
74
|
+
// Future support properties - guaranteed by framework
|
|
75
|
+
public futureHandler!: FutureAwareContainer<MyOperationProgress>;
|
|
76
|
+
|
|
77
|
+
constructor(modelId: string, options: MyOptions, context: KosCreationContext) {
|
|
78
|
+
this.id = modelId;
|
|
79
|
+
this.logger = context.logger;
|
|
80
|
+
|
|
81
|
+
// Initialize Future support
|
|
82
|
+
setupMinimalFutureSupport(this);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@kosFuture()
|
|
86
|
+
async performLongRunningOperation(): Promise<void> {
|
|
87
|
+
// TODO: Implement your long-running operation here
|
|
88
|
+
this.logger.debug(`Starting long-running operation for ${this.id}`);
|
|
89
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
90
|
+
this.logger.debug(`Completed long-running operation for ${this.id}`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Next Steps After Generation
|
|
96
|
+
|
|
97
|
+
1. **Implement the @kosFuture method**: Replace the placeholder with your actual long-running operation
|
|
98
|
+
2. **Update service method**: Implement the generated service method to return a proper `FutureResponse`
|
|
99
|
+
3. **Define progress types**: Customize the `OperationProgress` and `OperationResult` types for your specific use case
|
|
100
|
+
4. **Customize onFutureUpdate** (complete mode): Add custom logic for handling Future state changes
|
|
101
|
+
|
|
102
|
+
## Error Handling
|
|
103
|
+
|
|
104
|
+
- Validates that the model file exists before transformation
|
|
105
|
+
- Provides clear error messages for missing files or invalid configurations
|
|
106
|
+
- Supports dry-run mode to preview changes before applying them
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Tree } from "@nx/devkit";
|
|
2
|
+
import { KosAddFutureToModelSchema } from "./schema";
|
|
3
|
+
export declare function kosAddFutureToModelGenerator(tree: Tree, options: KosAddFutureToModelSchema): Promise<void>;
|
|
4
|
+
export default kosAddFutureToModelGenerator;
|
|
5
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAe,MAAM,YAAY,CAAC;AAM/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,yBAAyB,iBAiFnC;AAED,eAAe,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kosAddFutureToModelGenerator = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const logger_1 = require("../../utils/logger");
|
|
6
|
+
const model_transformer_1 = require("./lib/model-transformer");
|
|
7
|
+
const normalize_options_1 = require("./lib/normalize-options");
|
|
8
|
+
const registration_transformer_1 = require("./lib/registration-transformer");
|
|
9
|
+
const service_transformer_1 = require("./lib/service-transformer");
|
|
10
|
+
async function kosAddFutureToModelGenerator(tree, options) {
|
|
11
|
+
const normalized = (0, normalize_options_1.normalizeOptions)(tree, options);
|
|
12
|
+
logger_1.logger.info(`Adding ${normalized.futureType} Future support to model: ${normalized.modelName}`);
|
|
13
|
+
// Validate that model file exists
|
|
14
|
+
if (!tree.exists(normalized.modelFilePath)) {
|
|
15
|
+
throw new Error(`Model file not found: ${normalized.modelFilePath}`);
|
|
16
|
+
}
|
|
17
|
+
if (options.dryRun) {
|
|
18
|
+
logger_1.logger.info("DRY RUN - No files will be modified");
|
|
19
|
+
logger_1.logger.info(`Would modify model file: ${normalized.modelFilePath}`);
|
|
20
|
+
if (normalized.servicesFilePath) {
|
|
21
|
+
logger_1.logger.info(`Would modify/create services file: ${normalized.servicesFilePath}`);
|
|
22
|
+
}
|
|
23
|
+
if (normalized.registrationFilePath) {
|
|
24
|
+
logger_1.logger.info(`Would modify registration file: ${normalized.registrationFilePath}`);
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
// Transform model file
|
|
30
|
+
logger_1.logger.info(`Transforming model file: ${normalized.modelFilePath}`);
|
|
31
|
+
const modelTransformer = new model_transformer_1.ModelFileTransformer(tree, normalized);
|
|
32
|
+
modelTransformer.transform();
|
|
33
|
+
// Transform or create services file
|
|
34
|
+
if (normalized.updateServices) {
|
|
35
|
+
logger_1.logger.info(`Transforming services file: ${normalized.servicesFilePath || "creating new"}`);
|
|
36
|
+
const serviceTransformer = new service_transformer_1.ServiceFileTransformer(tree, normalized);
|
|
37
|
+
serviceTransformer.transform();
|
|
38
|
+
}
|
|
39
|
+
// Transform registration file
|
|
40
|
+
if (normalized.registrationFilePath) {
|
|
41
|
+
logger_1.logger.info(`Transforming registration file: ${normalized.registrationFilePath}`);
|
|
42
|
+
const registrationTransformer = new registration_transformer_1.RegistrationFileTransformer(tree, normalized);
|
|
43
|
+
registrationTransformer.transform();
|
|
44
|
+
}
|
|
45
|
+
logger_1.logger.info(`✅ Successfully added ${normalized.futureType} Future support to ${normalized.modelName}`);
|
|
46
|
+
logger_1.logger.info("");
|
|
47
|
+
logger_1.logger.info("Next steps:");
|
|
48
|
+
logger_1.logger.info("1. Review the generated @kosFuture method and implement your actual operation");
|
|
49
|
+
logger_1.logger.info("2. Update the service method to return a proper FutureResponse");
|
|
50
|
+
logger_1.logger.info("3. Define your specific progress and result types");
|
|
51
|
+
if (normalized.futureType === "complete") {
|
|
52
|
+
logger_1.logger.info("4. Customize the onFutureUpdate method for your specific needs");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger_1.logger.error(`Failed to add Future support: ${error}`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
60
|
+
}
|
|
61
|
+
exports.kosAddFutureToModelGenerator = kosAddFutureToModelGenerator;
|
|
62
|
+
exports.default = kosAddFutureToModelGenerator;
|
|
63
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/generator.ts"],"names":[],"mappings":";;;AAAA,uCAA+C;AAC/C,+CAA4C;AAC5C,+DAA+D;AAC/D,+DAA2D;AAC3D,6EAA6E;AAC7E,mEAAmE;AAG5D,KAAK,UAAU,4BAA4B,CAChD,IAAU,EACV,OAAkC;IAElC,MAAM,UAAU,GAAG,IAAA,oCAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAEnD,eAAM,CAAC,IAAI,CACT,UAAU,UAAU,CAAC,UAAU,6BAA6B,UAAU,CAAC,SAAS,EAAE,CACnF,CAAC;IAEF,kCAAkC;IACl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CAAC;YACF,MAAM,uBAAuB,GAAG,IAAI,sDAA2B,CAC7D,IAAI,EACJ,UAAU,CACX,CAAC;YACF,uBAAuB,CAAC,SAAS,EAAE,CAAC;QACtC,CAAC;QAED,eAAM,CAAC,IAAI,CACT,wBAAwB,UAAU,CAAC,UAAU,sBAAsB,UAAU,CAAC,SAAS,EAAE,CAC1F,CAAC;QACF,eAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChB,eAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC3B,eAAM,CAAC,IAAI,CACT,+EAA+E,CAChF,CAAC;QACF,eAAM,CAAC,IAAI,CACT,gEAAgE,CACjE,CAAC;QACF,eAAM,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QACjE,IAAI,UAAU,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;YACzC,eAAM,CAAC,IAAI,CACT,gEAAgE,CACjE,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,eAAM,CAAC,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;IAED,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAnFD,oEAmFC;AAED,kBAAe,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tree } from "@nx/devkit";
|
|
2
|
+
import { NormalizedKosAddFutureToModelSchema } from "../schema";
|
|
3
|
+
export declare class ModelFileTransformer {
|
|
4
|
+
private tree;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(tree: Tree, options: NormalizedKosAddFutureToModelSchema);
|
|
7
|
+
transform(): void;
|
|
8
|
+
private addImports;
|
|
9
|
+
private addServiceImport;
|
|
10
|
+
private updatePublicType;
|
|
11
|
+
private addFutureProperties;
|
|
12
|
+
private addMixinSetup;
|
|
13
|
+
private addFutureMethod;
|
|
14
|
+
private addFutureUpdateHandler;
|
|
15
|
+
private addOnFutureUpdateMethod;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=model-transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-transformer.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/lib/model-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,mCAAmC,EAAE,MAAM,WAAW,CAAC;AAEhE,qBAAa,oBAAoB;IAE7B,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;gBADP,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,mCAAmC;IAGtD,SAAS,IAAI,IAAI;IAwBjB,OAAO,CAAC,UAAU;IA2FlB,OAAO,CAAC,gBAAgB;IAmExB,OAAO,CAAC,gBAAgB;IAgBxB,OAAO,CAAC,mBAAmB;IAmC3B,OAAO,CAAC,aAAa;IA0BrB,OAAO,CAAC,eAAe;IAsCvB,OAAO,CAAC,sBAAsB;IAa9B,OAAO,CAAC,uBAAuB;CAiChC"}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModelFileTransformer = void 0;
|
|
4
|
+
class ModelFileTransformer {
|
|
5
|
+
tree;
|
|
6
|
+
options;
|
|
7
|
+
constructor(tree, options) {
|
|
8
|
+
this.tree = tree;
|
|
9
|
+
this.options = options;
|
|
10
|
+
}
|
|
11
|
+
transform() {
|
|
12
|
+
const { modelFilePath } = this.options;
|
|
13
|
+
if (!this.tree.exists(modelFilePath)) {
|
|
14
|
+
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
15
|
+
}
|
|
16
|
+
let content = this.tree.read(modelFilePath, "utf-8");
|
|
17
|
+
content = this.addImports(content);
|
|
18
|
+
content = this.addServiceImport(content);
|
|
19
|
+
content = this.updatePublicType(content);
|
|
20
|
+
content = this.addFutureProperties(content);
|
|
21
|
+
content = this.addMixinSetup(content);
|
|
22
|
+
content = this.addFutureMethod(content);
|
|
23
|
+
if (this.options.futureType === "complete") {
|
|
24
|
+
content = this.addFutureUpdateHandler(content);
|
|
25
|
+
content = this.addOnFutureUpdateMethod(content);
|
|
26
|
+
}
|
|
27
|
+
this.tree.write(modelFilePath, content);
|
|
28
|
+
}
|
|
29
|
+
addImports(content) {
|
|
30
|
+
const { internal, futureType } = this.options;
|
|
31
|
+
const isComplete = futureType === "complete";
|
|
32
|
+
// Find the kosModel import line
|
|
33
|
+
const kosModelImportRegex = internal
|
|
34
|
+
? /import\s*{\s*([^}]*kosModel[^}]*)\s*}\s*from\s*"\.\.\/\.\.\/\.\.\/core\/core\/decorators"/
|
|
35
|
+
: /import\s*{\s*([^}]*kosModel[^}]*)\s*}\s*from\s*"@kosdev-code\/kos-ui-sdk"/;
|
|
36
|
+
const kosModelMatch = content.match(kosModelImportRegex);
|
|
37
|
+
if (kosModelMatch) {
|
|
38
|
+
const existingImportsStr = kosModelMatch[1] || "";
|
|
39
|
+
const newImports = [
|
|
40
|
+
"kosFuture",
|
|
41
|
+
`setup${isComplete ? "Complete" : "Minimal"}FutureSupport`,
|
|
42
|
+
];
|
|
43
|
+
// Parse existing imports and add new ones
|
|
44
|
+
const existingImports = existingImportsStr
|
|
45
|
+
.split(",")
|
|
46
|
+
.map((s) => s.trim())
|
|
47
|
+
.filter(Boolean);
|
|
48
|
+
// Only add imports that don't already exist
|
|
49
|
+
const importsToAdd = newImports.filter((imp) => !existingImports.includes(imp));
|
|
50
|
+
const allImports = [...existingImports, ...importsToAdd];
|
|
51
|
+
const newImportLine = internal
|
|
52
|
+
? `import { ${allImports.join(", ")} } from "../../../core/core/decorators"`
|
|
53
|
+
: `import { ${allImports.join(", ")} } from "@kosdev-code/kos-ui-sdk"`;
|
|
54
|
+
content = content.replace(kosModelImportRegex, newImportLine);
|
|
55
|
+
}
|
|
56
|
+
// Add type imports
|
|
57
|
+
const typeImportsBase = internal
|
|
58
|
+
? "../../../models/types/future-interfaces"
|
|
59
|
+
: "@kosdev-code/kos-ui-sdk";
|
|
60
|
+
const futureTypeImports = [
|
|
61
|
+
"ExternalFutureInterface",
|
|
62
|
+
"FutureAwareContainer",
|
|
63
|
+
"IFutureModel",
|
|
64
|
+
];
|
|
65
|
+
if (isComplete) {
|
|
66
|
+
futureTypeImports.push("FutureUpdateHandler");
|
|
67
|
+
}
|
|
68
|
+
// Find existing type import or add new one
|
|
69
|
+
const typeImportRegex = internal
|
|
70
|
+
? /import type {([^}]*)} from "\.\.\/\.\.\/\.\.\/models\/types\/future-interfaces"/
|
|
71
|
+
: /import type {([^}]*)} from "@kosdev-code\/kos-ui-sdk"/;
|
|
72
|
+
const typeImportMatch = content.match(typeImportRegex);
|
|
73
|
+
if (typeImportMatch) {
|
|
74
|
+
// Update existing import
|
|
75
|
+
const existingTypes = typeImportMatch[1] || "";
|
|
76
|
+
const allTypes = [
|
|
77
|
+
...existingTypes
|
|
78
|
+
.split(",")
|
|
79
|
+
.map((s) => s.trim())
|
|
80
|
+
.filter(Boolean),
|
|
81
|
+
...futureTypeImports,
|
|
82
|
+
].join(", ");
|
|
83
|
+
const newTypeImport = `import type { ${allTypes} } from "${typeImportsBase}"`;
|
|
84
|
+
content = content.replace(typeImportRegex, newTypeImport);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
// Add new type import after other imports
|
|
88
|
+
const importLines = content.split("\n");
|
|
89
|
+
const lastImportIndex = importLines.findLastIndex((line) => line.trim().startsWith("import"));
|
|
90
|
+
if (lastImportIndex >= 0) {
|
|
91
|
+
const newTypeImport = `import type { ${futureTypeImports.join(", ")} } from "${typeImportsBase}";`;
|
|
92
|
+
importLines.splice(lastImportIndex + 1, 0, newTypeImport);
|
|
93
|
+
content = importLines.join("\n");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return content;
|
|
97
|
+
}
|
|
98
|
+
addServiceImport(content) {
|
|
99
|
+
const { nameProperCase, updateServices } = this.options;
|
|
100
|
+
// If updateServices is false, we don't need to import the progress type
|
|
101
|
+
if (!updateServices) {
|
|
102
|
+
return content;
|
|
103
|
+
}
|
|
104
|
+
// Check if progress type is already imported
|
|
105
|
+
if (content.includes(`${nameProperCase}OperationProgress`)) {
|
|
106
|
+
return content;
|
|
107
|
+
}
|
|
108
|
+
// Look for existing "./services" import (handle multiline)
|
|
109
|
+
const servicesImportRegex = /import\s*{([^}]*)}\s*from\s*["']\.\/services["'];?/s;
|
|
110
|
+
const servicesMatch = content.match(servicesImportRegex);
|
|
111
|
+
if (servicesMatch) {
|
|
112
|
+
// Add to existing services import
|
|
113
|
+
const existingImports = servicesMatch[1];
|
|
114
|
+
if (existingImports.includes(`${nameProperCase}OperationProgress`)) {
|
|
115
|
+
return content; // Already imported
|
|
116
|
+
}
|
|
117
|
+
// Clean up existing imports - remove trailing commas and normalize
|
|
118
|
+
const cleanedImports = existingImports
|
|
119
|
+
.split(",")
|
|
120
|
+
.map((imp) => imp.trim())
|
|
121
|
+
.filter((imp) => imp.length > 0)
|
|
122
|
+
.join(",\n ");
|
|
123
|
+
const newImports = cleanedImports
|
|
124
|
+
? `${cleanedImports},\n type ${nameProperCase}OperationProgress`
|
|
125
|
+
: `type ${nameProperCase}OperationProgress`;
|
|
126
|
+
const newImportStatement = `import {\n ${newImports}\n} from "./services";`;
|
|
127
|
+
return content.replace(servicesImportRegex, newImportStatement);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// Add new service import after all imports
|
|
131
|
+
const lines = content.split("\n");
|
|
132
|
+
let lastImportIndex = -1;
|
|
133
|
+
// Find the actual last import line (accounting for multi-line imports)
|
|
134
|
+
for (let i = 0; i < lines.length; i++) {
|
|
135
|
+
const line = lines[i].trim();
|
|
136
|
+
if (line.startsWith("import")) {
|
|
137
|
+
// Find the end of this import statement
|
|
138
|
+
let j = i;
|
|
139
|
+
while (j < lines.length && !lines[j].includes(";")) {
|
|
140
|
+
j++;
|
|
141
|
+
}
|
|
142
|
+
lastImportIndex = j;
|
|
143
|
+
i = j; // Skip to end of current import
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (lastImportIndex >= 0) {
|
|
147
|
+
const serviceImport = `import type { ${nameProperCase}OperationProgress } from "./services";`;
|
|
148
|
+
lines.splice(lastImportIndex + 1, 0, serviceImport);
|
|
149
|
+
return lines.join("\n");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return content;
|
|
153
|
+
}
|
|
154
|
+
updatePublicType(content) {
|
|
155
|
+
const { nameProperCase, updateServices } = this.options;
|
|
156
|
+
const typeRegex = new RegExp(`export type ${nameProperCase}Model = PublicModelInterface<${nameProperCase}ModelImpl>;`);
|
|
157
|
+
// Use 'any' for progress type if services are not being updated
|
|
158
|
+
const progressType = updateServices
|
|
159
|
+
? `${nameProperCase}OperationProgress`
|
|
160
|
+
: "any";
|
|
161
|
+
const newType = `export type ${nameProperCase}Model = PublicModelInterface<${nameProperCase}ModelImpl> & ExternalFutureInterface<${progressType}>;`;
|
|
162
|
+
return content.replace(typeRegex, newType);
|
|
163
|
+
}
|
|
164
|
+
addFutureProperties(content) {
|
|
165
|
+
const { nameProperCase, futureType, updateServices } = this.options;
|
|
166
|
+
const isComplete = futureType === "complete";
|
|
167
|
+
const progressType = updateServices
|
|
168
|
+
? `${nameProperCase}OperationProgress`
|
|
169
|
+
: "any";
|
|
170
|
+
// Find the class declaration and add properties after the constructor
|
|
171
|
+
const classRegex = new RegExp(`export class ${nameProperCase}ModelImpl[^{]*{`);
|
|
172
|
+
const classMatch = content.match(classRegex);
|
|
173
|
+
if (classMatch) {
|
|
174
|
+
const futureProps = [
|
|
175
|
+
"",
|
|
176
|
+
" // Future support properties - guaranteed by framework",
|
|
177
|
+
` public futureHandler!: FutureAwareContainer<${progressType}>;`,
|
|
178
|
+
];
|
|
179
|
+
if (isComplete) {
|
|
180
|
+
futureProps.push(` public future?: IFutureModel<${progressType}>; // Used internally for progress checks and custom logic`);
|
|
181
|
+
}
|
|
182
|
+
const insertAfter = classMatch[0];
|
|
183
|
+
const replacement = insertAfter + futureProps.join("\n");
|
|
184
|
+
return content.replace(classMatch[0], replacement);
|
|
185
|
+
}
|
|
186
|
+
return content;
|
|
187
|
+
}
|
|
188
|
+
addMixinSetup(content) {
|
|
189
|
+
const { futureType } = this.options;
|
|
190
|
+
const isComplete = futureType === "complete";
|
|
191
|
+
// Find constructor and add mixin setup call at the end
|
|
192
|
+
const constructorRegex = /constructor\([^)]*\)[^{]*{([^}]*)}/s;
|
|
193
|
+
const constructorMatch = content.match(constructorRegex);
|
|
194
|
+
if (constructorMatch) {
|
|
195
|
+
const constructorBody = constructorMatch[1];
|
|
196
|
+
const setupCall = `\n \n // Initialize Future support\n setup${isComplete ? "Complete" : "Minimal"}FutureSupport(this);`;
|
|
197
|
+
const newConstructorBody = constructorBody + setupCall;
|
|
198
|
+
const newConstructor = constructorMatch[0].replace(constructorBody, newConstructorBody);
|
|
199
|
+
return content.replace(constructorMatch[0], newConstructor);
|
|
200
|
+
}
|
|
201
|
+
return content;
|
|
202
|
+
}
|
|
203
|
+
addFutureMethod(content) {
|
|
204
|
+
const { nameProperCase } = this.options;
|
|
205
|
+
const futureMethod = `
|
|
206
|
+
/**
|
|
207
|
+
* Placeholder method for Future operations
|
|
208
|
+
* Replace this with your actual long-running operation
|
|
209
|
+
*/
|
|
210
|
+
@kosFuture()
|
|
211
|
+
async performLongRunningOperation(): Promise<void> {
|
|
212
|
+
// TODO: Implement your long-running operation here
|
|
213
|
+
// This method should use a service that returns a Future for progress tracking
|
|
214
|
+
|
|
215
|
+
this.logger.debug(\`Starting long-running operation for \${this.id}\`);
|
|
216
|
+
|
|
217
|
+
// Example implementation pattern using services:
|
|
218
|
+
// import { perform${nameProperCase}Operation } from './services';
|
|
219
|
+
//
|
|
220
|
+
// try {
|
|
221
|
+
// const future = await perform${nameProperCase}Operation();
|
|
222
|
+
// return this.futureHandler.setFuture(future);
|
|
223
|
+
// } catch (error) {
|
|
224
|
+
// this.logger.error(\`Failed to start operation for \${this.id}:\`, error);
|
|
225
|
+
// throw error;
|
|
226
|
+
// }
|
|
227
|
+
|
|
228
|
+
// Placeholder that doesn't actually do anything
|
|
229
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
230
|
+
|
|
231
|
+
this.logger.debug(\`Completed long-running operation for \${this.id}\`);
|
|
232
|
+
}`;
|
|
233
|
+
// Add method before the lifecycle section
|
|
234
|
+
const lifecycleRegex = /(\s+\/\/ -------------------LIFECYCLE----------------------------)/;
|
|
235
|
+
return content.replace(lifecycleRegex, futureMethod + "\n$1");
|
|
236
|
+
}
|
|
237
|
+
addFutureUpdateHandler(content) {
|
|
238
|
+
const { nameProperCase } = this.options;
|
|
239
|
+
// Update class implements clause
|
|
240
|
+
const implementsRegex = new RegExp(`export class ${nameProperCase}ModelImpl implements\\s+IKosDataModel,\\s+IKosIdentifiable`);
|
|
241
|
+
const newImplements = `export class ${nameProperCase}ModelImpl implements IKosDataModel, IKosIdentifiable, FutureUpdateHandler`;
|
|
242
|
+
return content.replace(implementsRegex, newImplements);
|
|
243
|
+
}
|
|
244
|
+
addOnFutureUpdateMethod(content) {
|
|
245
|
+
const { nameProperCase, updateServices } = this.options;
|
|
246
|
+
const progressType = updateServices
|
|
247
|
+
? `${nameProperCase}OperationProgress`
|
|
248
|
+
: "any";
|
|
249
|
+
const onFutureUpdateMethod = `
|
|
250
|
+
/**
|
|
251
|
+
* Optional: Custom Future update handling
|
|
252
|
+
* Called whenever the Future state changes (progress, status, completion, etc.)
|
|
253
|
+
*/
|
|
254
|
+
onFutureUpdate(update: IFutureModel<${progressType}>): void {
|
|
255
|
+
// Add custom Future update logic here
|
|
256
|
+
// Examples:
|
|
257
|
+
// - Log progress milestones
|
|
258
|
+
// - Update derived state based on progress
|
|
259
|
+
// - Handle specific error conditions
|
|
260
|
+
// - Trigger notifications at certain thresholds
|
|
261
|
+
|
|
262
|
+
this.logger.debug(\`Future update for \${this.id}:\`, {
|
|
263
|
+
progress: update.progress,
|
|
264
|
+
status: update.status,
|
|
265
|
+
endState: update.endState,
|
|
266
|
+
// Access typed progress data:
|
|
267
|
+
stage: update.data?.stage,
|
|
268
|
+
percentComplete: update.data?.percentComplete
|
|
269
|
+
});
|
|
270
|
+
}`;
|
|
271
|
+
// Add method before the @kosFuture method
|
|
272
|
+
const futureMethodRegex = /(\s+@kosFuture\(\))/;
|
|
273
|
+
return content.replace(futureMethodRegex, onFutureUpdateMethod + "\n$1");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.ModelFileTransformer = ModelFileTransformer;
|
|
277
|
+
//# sourceMappingURL=model-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-transformer.js","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/lib/model-transformer.ts"],"names":[],"mappings":";;;AAGA,MAAa,oBAAoB;IAErB;IACA;IAFV,YACU,IAAU,EACV,OAA4C;QAD5C,SAAI,GAAJ,IAAI,CAAM;QACV,YAAO,GAAP,OAAO,CAAqC;IACnD,CAAC;IAEJ,SAAS;QACP,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAEvC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,yBAAyB,aAAa,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,IAAI,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAE,CAAC;QAEtD,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACnC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACzC,OAAO,GAAG,IAAI,CAAC,gBAAg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AAM,CAAC,CAAC;IAC3E,CAAC;CACF;AA7VD,oDA6VC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Tree } from "@nx/devkit";
|
|
2
|
+
import { KosAddFutureToModelSchema, NormalizedKosAddFutureToModelSchema } from "../schema";
|
|
3
|
+
export declare function normalizeOptions(tree: Tree, options: KosAddFutureToModelSchema): NormalizedKosAddFutureToModelSchema;
|
|
4
|
+
//# sourceMappingURL=normalize-options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-options.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/lib/normalize-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA4B,MAAM,YAAY,CAAC;AAI5D,OAAO,EACL,yBAAyB,EACzB,mCAAmC,EACpC,MAAM,WAAW,CAAC;AAEnB,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,yBAAyB,GACjC,mCAAmC,CA0DrC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeOptions = void 0;
|
|
4
|
+
const devkit_1 = require("@nx/devkit");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const normalize_value_1 = require("../../../utils/normalize-value");
|
|
7
|
+
const project_utils_1 = require("../../../utils/project-utils");
|
|
8
|
+
function normalizeOptions(tree, options) {
|
|
9
|
+
const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, options.modelProject);
|
|
10
|
+
const kosConfig = (0, project_utils_1.getKosProjectConfiguration)(tree, options.modelProject);
|
|
11
|
+
const internal = !!kosConfig?.generator?.internal;
|
|
12
|
+
// Normalize name variations
|
|
13
|
+
const normalizedValues = (0, normalize_value_1.normalizeAllValues)({
|
|
14
|
+
modelName: options.modelName,
|
|
15
|
+
});
|
|
16
|
+
const nameDashCase = normalizedValues.modelNameDashCase;
|
|
17
|
+
const nameProperCase = normalizedValues.modelNameProperCase;
|
|
18
|
+
const nameCamelCase = normalizedValues.modelNameCamelCase;
|
|
19
|
+
const namePascalCase = normalizedValues.modelNamePascalCase;
|
|
20
|
+
const nameConstantCase = normalizedValues.modelNameConstantCase;
|
|
21
|
+
const nameLowerCase = normalizedValues.modelNameLowerCase;
|
|
22
|
+
const projectRoot = projectConfiguration.root;
|
|
23
|
+
const sourceRoot = projectConfiguration.sourceRoot || path.join(projectRoot, "src");
|
|
24
|
+
// Determine model file path
|
|
25
|
+
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
26
|
+
const modelDirectory = path.join(sourceRoot, modelLocation, nameDashCase);
|
|
27
|
+
const modelFilePath = path.join(modelDirectory, `${nameDashCase}-model.ts`);
|
|
28
|
+
// Determine services file path
|
|
29
|
+
const servicesDirectory = path.join(modelDirectory, "services");
|
|
30
|
+
const servicesFilePath = tree.exists(servicesDirectory)
|
|
31
|
+
? path.join(servicesDirectory, `${nameDashCase}-services.ts`)
|
|
32
|
+
: undefined;
|
|
33
|
+
// Determine registration file path
|
|
34
|
+
const registrationFilePath = path.join(modelDirectory, `${nameDashCase}-registration.ts`);
|
|
35
|
+
return {
|
|
36
|
+
...options,
|
|
37
|
+
nameDashCase,
|
|
38
|
+
nameProperCase,
|
|
39
|
+
nameCamelCase,
|
|
40
|
+
namePascalCase,
|
|
41
|
+
nameConstantCase,
|
|
42
|
+
nameLowerCase,
|
|
43
|
+
projectRoot,
|
|
44
|
+
sourceRoot,
|
|
45
|
+
modelFilePath,
|
|
46
|
+
servicesFilePath,
|
|
47
|
+
registrationFilePath: tree.exists(registrationFilePath)
|
|
48
|
+
? registrationFilePath
|
|
49
|
+
: undefined,
|
|
50
|
+
internal,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.normalizeOptions = normalizeOptions;
|
|
54
|
+
//# sourceMappingURL=normalize-options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-options.js","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/lib/normalize-options.ts"],"names":[],"mappings":";;;AAAA,uCAA4D;AAC5D,6BAA6B;AAC7B,oEAAoE;AACpE,gEAA0E;AAM1E,SAAgB,gBAAgB,CAC9B,IAAU,EACV,OAAkC;IAElC,MAAM,oBAAoB,GAAG,IAAA,iCAAwB,EACnD,IAAI,EACJ,OAAO,CAAC,YAAY,CACrB,CAAC;IACF,MAAM,SAAS,GAAG,IAAA,0CAA0B,EAAC,IAAI,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;IAElD,4BAA4B;IAC5B,MAAM,gBAAgB,GAAG,IAAA,oCAAkB,EAAC;QAC1C,SAAS,EAAE,OAAO,CAAC,SAAS;KAC7B,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,gBAAgB,CAAC,iBAAiB,CAAC;IACxD,MAAM,cAAc,GAAG,gBAAgB,CAAC,mBAAmB,CAAC;IAC5D,MAAM,aAAa,GAAG,gBAAgB,CAAC,kBAAkB,CAAC;IAC1D,MAAM,cAAc,GAAG,gBAAgB,CAAC,mBAAmB,CAAC;IAC5D,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,qBAAqB,CAAC;IAChE,MAAM,aAAa,GAAG,gBAAgB,CAAC,kBAAkB,CAAC;IAE1D,MAAM,WAAW,GAAG,oBAAoB,CAAC,IAAI,CAAC;IAC9C,MAAM,UAAU,GACd,oBAAoB,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAEnE,4BAA4B;IAC5B,MAAM,aAAa,GAAG,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,IAAI,EAAE,CAAC;IAC1E,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;IAC1E,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,YAAY,WAAW,CAAC,CAAC;IAE5E,+BAA+B;IAC/B,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAChE,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;QACrD,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,YAAY,cAAc,CAAC;QAC7D,CAAC,CAAC,SAAS,CAAC;IAEd,mCAAmC;IACnC,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CACpC,cAAc,EACd,GAAG,YAAY,kBAAkB,CAClC,CAAC;IAEF,OAAO;QACL,GAAG,OAAO;QACV,YAAY;QACZ,cAAc;QACd,aAAa;QACb,cAAc;QACd,gBAAgB;QAChB,aAAa;QACb,WAAW;QACX,UAAU;QACV,aAAa;QACb,gBAAgB;QAChB,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC;YACrD,CAAC,CAAC,oBAAoB;YACtB,CAAC,CAAC,SAAS;QACb,QAAQ;KACT,CAAC;AACJ,CAAC;AA7DD,4CA6DC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Tree } from "@nx/devkit";
|
|
2
|
+
import { NormalizedKosAddFutureToModelSchema } from "../schema";
|
|
3
|
+
export declare class RegistrationFileTransformer {
|
|
4
|
+
private tree;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(tree: Tree, options: NormalizedKosAddFutureToModelSchema);
|
|
7
|
+
transform(): void;
|
|
8
|
+
private addTypeCast;
|
|
9
|
+
private updateDocumentation;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=registration-transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registration-transformer.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/plugins/kos-nx-plugin/src/generators/kos-add-future-to-model/lib/registration-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,mCAAmC,EAAE,MAAM,WAAW,CAAC;AAEhE,qBAAa,2BAA2B;IAEpC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;gBADP,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,mCAAmC;IAGtD,SAAS,IAAI,IAAI;IAkBjB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,mBAAmB;CAyD5B"}
|