@bairock/lenz 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -4
- package/dist/cli/commands/generate.js +36 -75
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +33 -52
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/studio.js +15 -21
- package/dist/cli/commands/studio.js.map +1 -1
- package/dist/cli/index.js +13 -18
- package/dist/cli/index.js.map +1 -1
- package/dist/config/index.d.ts +1 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +29 -12
- package/dist/config/index.js.map +1 -1
- package/dist/engine/CodeGenerator.d.ts +2 -1
- package/dist/engine/CodeGenerator.d.ts.map +1 -1
- package/dist/engine/CodeGenerator.js +102 -48
- package/dist/engine/CodeGenerator.js.map +1 -1
- package/dist/engine/GraphQLParser.d.ts +2 -0
- package/dist/engine/GraphQLParser.d.ts.map +1 -1
- package/dist/engine/GraphQLParser.js +19 -16
- package/dist/engine/GraphQLParser.js.map +1 -1
- package/dist/engine/LenzEngine.d.ts +3 -3
- package/dist/engine/LenzEngine.js +32 -39
- package/dist/engine/LenzEngine.js.map +1 -1
- package/dist/engine/SchemaValidator.d.ts +1 -1
- package/dist/engine/SchemaValidator.d.ts.map +1 -1
- package/dist/engine/SchemaValidator.js +44 -32
- package/dist/engine/SchemaValidator.js.map +1 -1
- package/dist/engine/directives.d.ts.map +1 -1
- package/dist/engine/directives.js +44 -45
- package/dist/engine/directives.js.map +1 -1
- package/dist/engine/index.d.ts +3 -3
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +3 -9
- package/dist/engine/index.js.map +1 -1
- package/dist/errors/index.js +14 -31
- package/dist/errors/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -30
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -489,9 +489,6 @@ import { defineConfig } from 'lenz/config'
|
|
|
489
489
|
|
|
490
490
|
export default defineConfig({
|
|
491
491
|
schema: 'schema.graphql',
|
|
492
|
-
migrations: {
|
|
493
|
-
path: 'migrations',
|
|
494
|
-
},
|
|
495
492
|
datasource: {
|
|
496
493
|
url: process.env.MONGODB_URI,
|
|
497
494
|
database: process.env.MONGODB_DATABASE || 'myapp',
|
|
@@ -543,7 +540,7 @@ Lenz extends GraphQL with custom directives:
|
|
|
543
540
|
- `@unique` - Creates a unique index
|
|
544
541
|
- `@index` - Creates a regular index
|
|
545
542
|
- `@default(value: "...")` - Sets default value
|
|
546
|
-
- `@relation(field: "...", strategy: "populate|lookup", index: true|false)` - Defines relation with loading strategy and
|
|
543
|
+
- `@relation(field: "...", strategy: "populate|lookup", index: true|false, onDelete: "NoAction|Cascade|SetNull")` - Defines relation with loading strategy, index control, and cascade delete behavior (default: `NoAction`)
|
|
547
544
|
- `@createdAt` - Auto-sets creation timestamp
|
|
548
545
|
- `@updatedAt` - Auto-updates timestamp
|
|
549
546
|
- `@embedded` - Marks a type as embedded document
|
|
@@ -762,6 +759,36 @@ type Category @model {
|
|
|
762
759
|
}
|
|
763
760
|
```
|
|
764
761
|
|
|
762
|
+
### Cascade Delete Behavior (`onDelete`)
|
|
763
|
+
|
|
764
|
+
Lenz supports cascade delete operations on relations. By default, **no cascade is performed** (`onDelete: "NoAction"`) for performance and safety. You must explicitly opt in.
|
|
765
|
+
|
|
766
|
+
| Value | Behavior |
|
|
767
|
+
|-------|----------|
|
|
768
|
+
| `NoAction` (default) | No cascade. Deleted document's related references become orphaned. |
|
|
769
|
+
| `Cascade` | When a document is deleted, all related documents are also deleted. |
|
|
770
|
+
| `SetNull` | When a document is deleted, foreign key fields in related documents are set to `null` (only for nullable FK fields). |
|
|
771
|
+
|
|
772
|
+
**Important:** Cascade operations negatively impact write performance because each delete triggers additional queries. Use only when necessary.
|
|
773
|
+
|
|
774
|
+
Examples:
|
|
775
|
+
|
|
776
|
+
```graphql
|
|
777
|
+
type Author @model {
|
|
778
|
+
id: ID! @id
|
|
779
|
+
posts: [Post!]! @relation(field: "postIds", onDelete: "Cascade") # Deletes all posts when author is deleted
|
|
780
|
+
postIds: [ID!]!
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
type Profile @model {
|
|
784
|
+
id: ID! @id
|
|
785
|
+
user: User @relation(field: "userId", onDelete: "SetNull") # Sets userId to null when user is deleted
|
|
786
|
+
userId: ID
|
|
787
|
+
}
|
|
788
|
+
```
|
|
789
|
+
|
|
790
|
+
**Note:** `onDelete: "SetNull"` is only supported on nullable foreign key fields (optional `ID` fields, not `ID!`). Using it on required fields will cause a validation error.
|
|
791
|
+
|
|
765
792
|
### Automatic Indexing
|
|
766
793
|
|
|
767
794
|
Lenz automatically creates indexes for foreign key fields when `index: true` (default). You can disable this:
|
|
@@ -1,94 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.generateCommand = void 0;
|
|
40
|
-
const commander_1 = require("commander");
|
|
41
|
-
const LenzEngine_1 = require("../../engine/LenzEngine");
|
|
42
|
-
const fs_1 = require("fs");
|
|
43
|
-
const path_1 = require("path");
|
|
44
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
-
exports.generateCommand = new commander_1.Command('generate')
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { LenzEngine } from '../../engine/LenzEngine.js';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
import { resolve, dirname } from 'path';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
export const generateCommand = new Command('generate')
|
|
46
7
|
.description('Generate Lenz client from GraphQL schema')
|
|
47
8
|
.option('-c, --config <path>', 'Path to lenz config file', 'lenz/lenz.config.ts')
|
|
48
9
|
.option('-s, --schema <path>', 'Path to GraphQL schema file')
|
|
49
10
|
.option('-o, --output <path>', 'Output directory for generated client')
|
|
50
11
|
.option('-n, --name <name>', 'Name of the generated client', 'LenzClient')
|
|
51
12
|
.action(async (options) => {
|
|
52
|
-
console.log(
|
|
13
|
+
console.log(chalk.blue('🚀 Generating Lenz client...'));
|
|
53
14
|
try {
|
|
54
15
|
let config = {};
|
|
55
16
|
// Автоматически определяем конфиг по типу проекта, если используется значение по умолчанию
|
|
56
17
|
let configFile = options.config;
|
|
57
18
|
if (configFile === 'lenz/lenz.config.ts') {
|
|
58
|
-
const tsConfigPath =
|
|
59
|
-
const jsConfigPath =
|
|
60
|
-
if (!
|
|
19
|
+
const tsConfigPath = resolve(process.cwd(), 'lenz/lenz.config.ts');
|
|
20
|
+
const jsConfigPath = resolve(process.cwd(), 'lenz/lenz.config.js');
|
|
21
|
+
if (!existsSync(tsConfigPath) && existsSync(jsConfigPath)) {
|
|
61
22
|
configFile = 'lenz/lenz.config.js';
|
|
62
|
-
console.log(
|
|
23
|
+
console.log(chalk.gray(`📦 Using JavaScript config: ${configFile}`));
|
|
63
24
|
}
|
|
64
25
|
}
|
|
65
|
-
const configPath =
|
|
26
|
+
const configPath = resolve(process.cwd(), configFile);
|
|
66
27
|
// Загружаем конфигурацию
|
|
67
|
-
if (
|
|
28
|
+
if (existsSync(configPath)) {
|
|
68
29
|
if (configPath.endsWith('.ts')) {
|
|
69
30
|
// Для TypeScript конфига
|
|
70
|
-
const configModule = await
|
|
31
|
+
const configModule = await import(configPath);
|
|
71
32
|
config = configModule.default || configModule;
|
|
72
33
|
}
|
|
73
34
|
else if (configPath.endsWith('.js') || configPath.endsWith('.mjs')) {
|
|
74
35
|
// Для JavaScript конфига (только ESM)
|
|
75
|
-
const configModule = await
|
|
36
|
+
const configModule = await import(configPath);
|
|
76
37
|
config = configModule.default || configModule;
|
|
77
38
|
}
|
|
78
39
|
}
|
|
79
40
|
else {
|
|
80
|
-
console.log(
|
|
41
|
+
console.log(chalk.yellow('⚠️ Config file not found, using defaults'));
|
|
81
42
|
}
|
|
82
43
|
// Определяем пути
|
|
83
|
-
const schemaPath =
|
|
84
|
-
if (!
|
|
85
|
-
console.log(
|
|
86
|
-
console.log(
|
|
44
|
+
const schemaPath = resolve(dirname(configPath), options.schema || config.schema || 'schema.graphql');
|
|
45
|
+
if (!existsSync(schemaPath)) {
|
|
46
|
+
console.log(chalk.red(`❌ Schema file not found: ${schemaPath}`));
|
|
47
|
+
console.log(chalk.yellow('💡 Try running: lenz init'));
|
|
87
48
|
process.exit(1);
|
|
88
49
|
}
|
|
89
|
-
const outputPath =
|
|
50
|
+
const outputPath = resolve(dirname(configPath), options.output || config.generate?.client?.output || '../generated/lenz/client');
|
|
90
51
|
// Создаем движок и генерируем
|
|
91
|
-
const engine = new
|
|
52
|
+
const engine = new LenzEngine({
|
|
92
53
|
schemaPath,
|
|
93
54
|
outputPath,
|
|
94
55
|
clientName: options.name
|
|
@@ -97,23 +58,23 @@ exports.generateCommand = new commander_1.Command('generate')
|
|
|
97
58
|
// Отображаем информацию
|
|
98
59
|
const schemaInfo = engine.getSchemaInfo();
|
|
99
60
|
if (schemaInfo) {
|
|
100
|
-
console.log(
|
|
101
|
-
console.log(
|
|
102
|
-
console.log(
|
|
103
|
-
console.log(
|
|
104
|
-
console.log(
|
|
105
|
-
console.log(
|
|
106
|
-
console.log(
|
|
107
|
-
console.log(
|
|
108
|
-
console.log(
|
|
109
|
-
console.log(
|
|
110
|
-
console.log(
|
|
111
|
-
console.log(
|
|
61
|
+
console.log(chalk.green('✅ Generation complete!'));
|
|
62
|
+
console.log(chalk.gray('================================'));
|
|
63
|
+
console.log(chalk.cyan('📊 Generated:'));
|
|
64
|
+
console.log(chalk.white(` • ${schemaInfo.modelCount} models`));
|
|
65
|
+
console.log(chalk.white(` • ${schemaInfo.enumCount} enums`));
|
|
66
|
+
console.log(chalk.white(` • ${schemaInfo.relationCount} relations`));
|
|
67
|
+
console.log(chalk.gray('================================\n'));
|
|
68
|
+
console.log(chalk.yellow('🚀 Next steps:'));
|
|
69
|
+
console.log(chalk.white(` 1. Import client: ${chalk.cyan(`import { LenzClient } from '../generated/lenz/client'`)}`));
|
|
70
|
+
console.log(chalk.white(` 2. Create instance: ${chalk.cyan(`const lenz = new LenzClient({ url: 'mongodb://...' })`)}`));
|
|
71
|
+
console.log(chalk.white(` 3. Connect: ${chalk.cyan(`await lenz.$connect()`)}`));
|
|
72
|
+
console.log(chalk.white(` 4. Use models: ${chalk.cyan(`await lenz.user.findMany()`)}\n`));
|
|
112
73
|
}
|
|
113
74
|
}
|
|
114
75
|
catch (error) {
|
|
115
|
-
console.log(
|
|
116
|
-
console.log(
|
|
76
|
+
console.log(chalk.red('❌ Generation failed:'));
|
|
77
|
+
console.log(chalk.red(error instanceof Error ? error.message : String(error)));
|
|
117
78
|
process.exit(1);
|
|
118
79
|
}
|
|
119
80
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/cli/commands/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACxC,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;KACnD,WAAW,CAAC,0CAA0C,CAAC;KACvD,MAAM,CAAC,qBAAqB,EAAE,0BAA0B,EAAE,qBAAqB,CAAC;KAChF,MAAM,CAAC,qBAAqB,EAAE,6BAA6B,CAAC;KAC5D,MAAM,CAAC,qBAAqB,EAAE,uCAAuC,CAAC;KACtE,MAAM,CAAC,mBAAmB,EAAE,8BAA8B,EAAE,YAAY,CAAC;KACzE,MAAM,CAAC,KAAK,EAAE,OAAwB,EAAE,EAAE;IACzC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC,CAAC;IAExD,IAAI,CAAC;QACH,IAAI,MAAM,GAAQ,EAAE,CAAC;QAErB,2FAA2F;QAC3F,IAAI,UAAU,GA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 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmFpC,eAAO,MAAM,WAAW,SA4EpB,CAAC"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initCommand = void 0;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
11
5
|
const DEFAULT_SCHEMA = `# Welcome to Lenz!
|
|
12
6
|
# This is your GraphQL schema file.
|
|
13
7
|
# Define your models here using GraphQL SDL syntax.
|
|
@@ -42,68 +36,56 @@ type Post @model {
|
|
|
42
36
|
# @createdAt - Auto-sets creation timestamp
|
|
43
37
|
# @updatedAt - Auto-updates timestamp`;
|
|
44
38
|
const DEFAULT_CONFIG_TS = `import 'dotenv/config'
|
|
45
|
-
import { defineConfig } from 'lenz
|
|
39
|
+
import { defineConfig } from '@bairock/lenz'
|
|
46
40
|
|
|
47
41
|
export default defineConfig({
|
|
48
42
|
schema: 'schema.graphql',
|
|
49
43
|
datasource: {
|
|
50
|
-
url: process.env.MONGODB_URI,
|
|
51
|
-
database: process.env.MONGODB_DATABASE || 'myapp',
|
|
44
|
+
url: process.env.MONGODB_URI || 'mongodb://localhost:27017/myapp',
|
|
52
45
|
},
|
|
53
46
|
generate: {
|
|
54
47
|
client: {
|
|
55
48
|
output: '../generated/lenz/client',
|
|
56
|
-
generator: 'lenz-client-js',
|
|
57
49
|
},
|
|
58
50
|
},
|
|
59
51
|
log: ['query', 'info', 'warn', 'error'] as const,
|
|
60
52
|
autoCreateCollections: true,
|
|
61
53
|
})`;
|
|
62
54
|
const DEFAULT_CONFIG_JS = `import 'dotenv/config'
|
|
55
|
+
import { defineConfig } from '@bairock/lenz'
|
|
63
56
|
|
|
64
|
-
export default {
|
|
57
|
+
export default defineConfig({
|
|
65
58
|
schema: 'schema.graphql',
|
|
66
59
|
datasource: {
|
|
67
|
-
url: process.env.MONGODB_URI || 'mongodb://localhost:27017',
|
|
68
|
-
database: process.env.MONGODB_DATABASE || 'myapp',
|
|
60
|
+
url: process.env.MONGODB_URI || 'mongodb://localhost:27017/myapp',
|
|
69
61
|
},
|
|
70
62
|
generate: {
|
|
71
63
|
client: {
|
|
72
64
|
output: '../generated/lenz/client',
|
|
73
|
-
generator: 'lenz-client-js',
|
|
74
65
|
},
|
|
75
66
|
},
|
|
76
67
|
log: ['query', 'info', 'warn', 'error'],
|
|
77
68
|
autoCreateCollections: true,
|
|
78
|
-
};`;
|
|
79
|
-
const EXAMPLE_ENV = `# MongoDB connection string
|
|
80
|
-
MONGODB_URI=mongodb://localhost:27017
|
|
81
|
-
|
|
82
|
-
# Database name
|
|
83
|
-
MONGODB_DATABASE=myapp
|
|
69
|
+
});`;
|
|
70
|
+
const EXAMPLE_ENV = `# MongoDB connection string (include database name in URL)
|
|
71
|
+
MONGODB_URI=mongodb://localhost:27017/myapp
|
|
84
72
|
|
|
85
73
|
# Log level (debug, info, warn, error)
|
|
86
74
|
LOG_LEVEL=info
|
|
87
75
|
|
|
88
76
|
# Enable query logging
|
|
89
77
|
LOG_QUERIES=true`;
|
|
90
|
-
|
|
78
|
+
export const initCommand = new Command('init')
|
|
91
79
|
.description('Initialize a new Lenz project')
|
|
92
80
|
.option('--skip-prompts', 'Skip interactive prompts')
|
|
93
81
|
.action(async (options) => {
|
|
94
|
-
console.log(
|
|
95
|
-
const answers = options.skipPrompts ? {} : await
|
|
96
|
-
{
|
|
97
|
-
type: 'input',
|
|
98
|
-
name: 'database',
|
|
99
|
-
message: 'Database name:',
|
|
100
|
-
default: 'myapp'
|
|
101
|
-
},
|
|
82
|
+
console.log(chalk.blue('🚀 Initializing Lenz project...\n'));
|
|
83
|
+
const answers = options.skipPrompts ? {} : await inquirer.prompt([
|
|
102
84
|
{
|
|
103
85
|
type: 'input',
|
|
104
86
|
name: 'url',
|
|
105
|
-
message: 'MongoDB URL:',
|
|
106
|
-
default: 'mongodb://localhost:27017'
|
|
87
|
+
message: 'MongoDB URL (include database name):',
|
|
88
|
+
default: 'mongodb://localhost:27017/myapp'
|
|
107
89
|
},
|
|
108
90
|
{
|
|
109
91
|
type: 'confirm',
|
|
@@ -115,16 +97,16 @@ exports.initCommand = new commander_1.Command('init')
|
|
|
115
97
|
// Создаем директории
|
|
116
98
|
const dirs = ['lenz', 'generated'];
|
|
117
99
|
for (const dir of dirs) {
|
|
118
|
-
if (!
|
|
119
|
-
|
|
120
|
-
console.log(
|
|
100
|
+
if (!existsSync(dir)) {
|
|
101
|
+
mkdirSync(dir, { recursive: true });
|
|
102
|
+
console.log(chalk.green(`📁 Created directory: ./${dir}`));
|
|
121
103
|
}
|
|
122
104
|
}
|
|
123
105
|
// Определяем тип проекта (TypeScript или JavaScript)
|
|
124
|
-
const isTypeScriptProject =
|
|
106
|
+
const isTypeScriptProject = existsSync('tsconfig.json');
|
|
125
107
|
const configExtension = isTypeScriptProject ? 'ts' : 'js';
|
|
126
108
|
const configTemplate = isTypeScriptProject ? DEFAULT_CONFIG_TS : DEFAULT_CONFIG_JS;
|
|
127
|
-
console.log(
|
|
109
|
+
console.log(chalk.gray(`📦 Detected ${isTypeScriptProject ? 'TypeScript' : 'JavaScript (ESM)'} project`));
|
|
128
110
|
// Создаем файлы
|
|
129
111
|
const files = [
|
|
130
112
|
{
|
|
@@ -133,8 +115,7 @@ exports.initCommand = new commander_1.Command('init')
|
|
|
133
115
|
},
|
|
134
116
|
{
|
|
135
117
|
path: `lenz/lenz.config.${configExtension}`,
|
|
136
|
-
content: configTemplate.replace('myapp', answers.
|
|
137
|
-
.replace('mongodb://localhost:27017', answers.url || 'mongodb://localhost:27017')
|
|
118
|
+
content: configTemplate.replace('mongodb://localhost:27017/myapp', answers.url || 'mongodb://localhost:27017/myapp')
|
|
138
119
|
},
|
|
139
120
|
{
|
|
140
121
|
path: '.env.example',
|
|
@@ -150,19 +131,19 @@ generated/
|
|
|
150
131
|
}
|
|
151
132
|
];
|
|
152
133
|
for (const file of files) {
|
|
153
|
-
if (!
|
|
154
|
-
|
|
155
|
-
console.log(
|
|
134
|
+
if (!existsSync(file.path)) {
|
|
135
|
+
writeFileSync(file.path, file.content, 'utf-8');
|
|
136
|
+
console.log(chalk.green(`📄 Created file: ${file.path}`));
|
|
156
137
|
}
|
|
157
138
|
else {
|
|
158
|
-
console.log(
|
|
139
|
+
console.log(chalk.yellow(`⚠️ File already exists: ${file.path}`));
|
|
159
140
|
}
|
|
160
141
|
}
|
|
161
|
-
console.log(
|
|
162
|
-
console.log(
|
|
163
|
-
console.log(
|
|
164
|
-
console.log(
|
|
165
|
-
console.log(
|
|
166
|
-
console.log(
|
|
142
|
+
console.log(chalk.green('\n✅ Lenz project initialized!'));
|
|
143
|
+
console.log(chalk.gray('\nNext steps:'));
|
|
144
|
+
console.log(chalk.white(' 1. Edit your schema: ') + chalk.cyan('lenz/schema.graphql'));
|
|
145
|
+
console.log(chalk.white(' 2. Configure database: ') + chalk.cyan(`lenz/lenz.config.${configExtension}`));
|
|
146
|
+
console.log(chalk.white(' 3. Generate client: ') + chalk.cyan('npx lenz generate'));
|
|
147
|
+
console.log(chalk.white(' 4. Start coding! 🚀\n'));
|
|
167
148
|
});
|
|
168
149
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/cli/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sCAgCe,CAAC;AAEvC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;GAevB,CAAC;AAEJ,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;IAetB,CAAC;AAGL,MAAM,WAAW,GAAG;;;;;;;iBAOH,CAAC;AAElB,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;KAC3C,WAAW,CAAC,+BAA+B,CAAC;KAC5C,MAAM,CAAC,gBAAgB,EAAE,0BAA0B,CAAC;KACpD,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC,CAAC;IAE7D,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC;QAC/D;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,KAAK;YACX,OAAO,EAAE,sCAAsC;YAC/C,OAAO,EAAE,iCAAiC;SAC3C;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,wBAAwB;YACjC,OAAO,EAAE,IAAI;SACd;KACF,CAAC,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
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
const boxen_1 = __importDefault(require("boxen"));
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
exports.studioCommand = new commander_1.Command('studio')
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import boxen from 'boxen';
|
|
4
|
+
import { existsSync } from 'fs';
|
|
5
|
+
export const studioCommand = new Command('studio')
|
|
12
6
|
.description('Open Lenz Studio - visual database management')
|
|
13
7
|
.option('-p, --port <port>', 'Port for Lenz Studio', '5555')
|
|
14
8
|
.option('--host <host>', 'Host for Lenz Studio', 'localhost')
|
|
15
9
|
.action(async (options) => {
|
|
16
|
-
console.log(
|
|
10
|
+
console.log(chalk.blue(boxen('🚀 Lenz Studio', { padding: 1, borderStyle: 'round' })));
|
|
17
11
|
// Проверяем наличие схемы
|
|
18
12
|
const schemaPath = 'lenz/schema.graphql';
|
|
19
|
-
if (!
|
|
20
|
-
console.log(
|
|
21
|
-
console.log(
|
|
13
|
+
if (!existsSync(schemaPath)) {
|
|
14
|
+
console.log(chalk.red('❌ Schema file not found'));
|
|
15
|
+
console.log(chalk.yellow('💡 Run: lenz init'));
|
|
22
16
|
process.exit(1);
|
|
23
17
|
}
|
|
24
|
-
console.log(
|
|
25
|
-
console.log(
|
|
18
|
+
console.log(chalk.green('📡 Starting Lenz Studio...'));
|
|
19
|
+
console.log(chalk.gray(`🌐 Available at: http://${options.host}:${options.port}`));
|
|
26
20
|
// В реальности здесь будет запуск веб-сервера с интерфейсом
|
|
27
|
-
console.log(
|
|
28
|
-
console.log(
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(
|
|
21
|
+
console.log(chalk.yellow('⚠️ Studio is under development'));
|
|
22
|
+
console.log(chalk.gray('\nIn the meantime, you can use:'));
|
|
23
|
+
console.log(chalk.white(' • MongoDB Compass'));
|
|
24
|
+
console.log(chalk.white(' • Generated TypeScript client\n'));
|
|
31
25
|
});
|
|
32
26
|
//# sourceMappingURL=studio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../../../src/cli/commands/studio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../../../src/cli/commands/studio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAEhC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,+CAA+C,CAAC;KAC5D,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,CAAC;KAC3D,MAAM,CAAC,eAAe,EAAE,sBAAsB,EAAE,WAAW,CAAC;KAC5D,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAEvF,0BAA0B;IAC1B,MAAM,UAAU,GAAG,qBAAqB,CAAC;IACzC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC;IACvD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,2BAA2B,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAEnF,4DAA4D;IAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,iCAAiC,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC"}
|
package/dist/cli/index.js
CHANGED
|
@@ -1,29 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const init_1 = require("./commands/init");
|
|
10
|
-
const studio_1 = require("./commands/studio");
|
|
11
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
-
const figlet_1 = __importDefault(require("figlet"));
|
|
13
|
-
const program = new commander_1.Command();
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { generateCommand } from './commands/generate.js';
|
|
4
|
+
import { initCommand } from './commands/init.js';
|
|
5
|
+
import { studioCommand } from './commands/studio.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import figlet from 'figlet';
|
|
8
|
+
const program = new Command();
|
|
14
9
|
program
|
|
15
10
|
.name('lenz')
|
|
16
11
|
.description('Lenz CLI - GraphQL-based ORM for MongoDB')
|
|
17
12
|
.version('1.0.0')
|
|
18
13
|
.configureOutput({
|
|
19
|
-
outputError: (str, write) => write(
|
|
14
|
+
outputError: (str, write) => write(chalk.red(str))
|
|
20
15
|
});
|
|
21
|
-
program.addCommand(
|
|
22
|
-
program.addCommand(
|
|
23
|
-
program.addCommand(
|
|
16
|
+
program.addCommand(initCommand);
|
|
17
|
+
program.addCommand(generateCommand);
|
|
18
|
+
program.addCommand(studioCommand);
|
|
24
19
|
if (process.argv.length === 2) {
|
|
25
|
-
console.log(
|
|
26
|
-
console.log(
|
|
20
|
+
console.log(chalk.cyan(figlet.textSync('Lenz', { horizontalLayout: 'full' })));
|
|
21
|
+
console.log(chalk.gray('GraphQL-based ORM for MongoDB\n'));
|
|
27
22
|
program.outputHelp();
|
|
28
23
|
}
|
|
29
24
|
else {
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,MAAM,CAAC;KACZ,WAAW,CAAC,0CAA0C,CAAC;KACvD,OAAO,CAAC,OAAO,CAAC;KAChB,eAAe,CAAC;IACf,WAAW,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;CACnD,CAAC,CAAC;AAEL,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;AACpC,OAAO,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAElC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC,CAAC;IAC3D,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -6,10 +6,8 @@ export interface LenzConfig {
|
|
|
6
6
|
schema?: string;
|
|
7
7
|
/** Data source configuration */
|
|
8
8
|
datasource?: {
|
|
9
|
-
/** MongoDB connection URL */
|
|
9
|
+
/** MongoDB connection URL (include database name in URL, e.g., mongodb://localhost:27017/mydb) */
|
|
10
10
|
url?: string;
|
|
11
|
-
/** Database name */
|
|
12
|
-
database?: string;
|
|
13
11
|
};
|
|
14
12
|
/** Generation configuration */
|
|
15
13
|
generate?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,UAAU,CAAC,EAAE;QACX,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,UAAU,CAAC,EAAE;QACX,kGAAkG;QAClG,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,CAAC;IACF,+BAA+B;IAC/B,QAAQ,CAAC,EAAE;QACT,gCAAgC;QAChC,MAAM,CAAC,EAAE;YACP,4CAA4C;YAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,qBAAqB;YACrB,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;KACH,CAAC;IACF,qBAAqB;IACrB,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IAC9C,8BAA8B;IAC9B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,2BAA2B;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,qBAAqB;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CA6B3D;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UAe3B,CAAC"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,36 +1,53 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* Lenz configuration utilities
|
|
4
3
|
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultConfig = void 0;
|
|
7
|
-
exports.defineConfig = defineConfig;
|
|
8
|
-
exports.env = env;
|
|
9
4
|
/**
|
|
10
5
|
* Define a Lenz configuration
|
|
11
6
|
*/
|
|
12
|
-
function defineConfig(config) {
|
|
13
|
-
|
|
7
|
+
export function defineConfig(config) {
|
|
8
|
+
const result = {
|
|
9
|
+
...defaultConfig,
|
|
10
|
+
...config,
|
|
11
|
+
};
|
|
12
|
+
// Deep merge for datasource
|
|
13
|
+
if (config.datasource) {
|
|
14
|
+
result.datasource = {
|
|
15
|
+
...defaultConfig.datasource,
|
|
16
|
+
...config.datasource,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
// Deep merge for generate
|
|
20
|
+
if (config.generate) {
|
|
21
|
+
result.generate = {
|
|
22
|
+
...defaultConfig.generate,
|
|
23
|
+
...config.generate,
|
|
24
|
+
};
|
|
25
|
+
if (config.generate.client) {
|
|
26
|
+
result.generate.client = {
|
|
27
|
+
...defaultConfig.generate?.client,
|
|
28
|
+
...config.generate.client,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
14
33
|
}
|
|
15
34
|
/**
|
|
16
35
|
* Load environment variables
|
|
17
36
|
*/
|
|
18
|
-
function env(key, defaultValue) {
|
|
37
|
+
export function env(key, defaultValue) {
|
|
19
38
|
return process.env[key] || defaultValue || '';
|
|
20
39
|
}
|
|
21
40
|
/**
|
|
22
41
|
* Default configuration
|
|
23
42
|
*/
|
|
24
|
-
|
|
43
|
+
export const defaultConfig = {
|
|
25
44
|
schema: 'schema.graphql',
|
|
26
45
|
datasource: {
|
|
27
|
-
url: 'mongodb://localhost:27017',
|
|
28
|
-
database: 'myapp'
|
|
46
|
+
url: 'mongodb://localhost:27017/myapp',
|
|
29
47
|
},
|
|
30
48
|
generate: {
|
|
31
49
|
client: {
|
|
32
50
|
output: '../generated/lenz/client',
|
|
33
|
-
generator: 'lenz-client-js',
|
|
34
51
|
}
|
|
35
52
|
},
|
|
36
53
|
log: ['query', 'error', 'warn'],
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../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