purplekit 1.0.0
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 +103 -0
- package/bin/dataforge +2 -0
- package/build/src/app.d.ts +2 -0
- package/build/src/app.d.ts.map +1 -0
- package/build/src/app.js +63 -0
- package/build/src/app.js.map +1 -0
- package/build/src/config/constants.d.ts +8 -0
- package/build/src/config/constants.d.ts.map +1 -0
- package/build/src/config/constants.js +16 -0
- package/build/src/config/constants.js.map +1 -0
- package/build/src/config/index.d.ts +4 -0
- package/build/src/config/index.d.ts.map +1 -0
- package/build/src/config/index.js +79 -0
- package/build/src/config/index.js.map +1 -0
- package/build/src/features/createdb.d.ts +21 -0
- package/build/src/features/createdb.d.ts.map +1 -0
- package/build/src/features/createdb.js +80 -0
- package/build/src/features/createdb.js.map +1 -0
- package/build/src/features/dropdb.d.ts +18 -0
- package/build/src/features/dropdb.d.ts.map +1 -0
- package/build/src/features/dropdb.js +70 -0
- package/build/src/features/dropdb.js.map +1 -0
- package/build/src/features/gen.d.ts +84 -0
- package/build/src/features/gen.d.ts.map +1 -0
- package/build/src/features/gen.js +241 -0
- package/build/src/features/gen.js.map +1 -0
- package/build/src/features/index.d.ts +9 -0
- package/build/src/features/index.d.ts.map +1 -0
- package/build/src/features/index.js +20 -0
- package/build/src/features/index.js.map +1 -0
- package/build/src/features/init.d.ts +7 -0
- package/build/src/features/init.d.ts.map +1 -0
- package/build/src/features/init.js +118 -0
- package/build/src/features/init.js.map +1 -0
- package/build/src/features/migrate.d.ts +83 -0
- package/build/src/features/migrate.d.ts.map +1 -0
- package/build/src/features/migrate.js +331 -0
- package/build/src/features/migrate.js.map +1 -0
- package/build/src/features/migration.d.ts +28 -0
- package/build/src/features/migration.d.ts.map +1 -0
- package/build/src/features/migration.js +128 -0
- package/build/src/features/migration.js.map +1 -0
- package/build/src/features/seed.d.ts +9 -0
- package/build/src/features/seed.d.ts.map +1 -0
- package/build/src/features/seed.js +72 -0
- package/build/src/features/seed.js.map +1 -0
- package/build/src/features/status.d.ts +55 -0
- package/build/src/features/status.d.ts.map +1 -0
- package/build/src/features/status.js +229 -0
- package/build/src/features/status.js.map +1 -0
- package/build/src/index.d.ts +4 -0
- package/build/src/index.d.ts.map +1 -0
- package/build/src/index.js +15 -0
- package/build/src/index.js.map +1 -0
- package/build/src/libs/compare-mig.d.ts +27 -0
- package/build/src/libs/compare-mig.d.ts.map +1 -0
- package/build/src/libs/compare-mig.js +215 -0
- package/build/src/libs/compare-mig.js.map +1 -0
- package/build/src/libs/create-ds.d.ts +10 -0
- package/build/src/libs/create-ds.d.ts.map +1 -0
- package/build/src/libs/create-ds.js +56 -0
- package/build/src/libs/create-ds.js.map +1 -0
- package/build/src/libs/get-commands.d.ts +45 -0
- package/build/src/libs/get-commands.d.ts.map +1 -0
- package/build/src/libs/get-commands.js +128 -0
- package/build/src/libs/get-commands.js.map +1 -0
- package/build/src/libs/paths.d.ts +22 -0
- package/build/src/libs/paths.d.ts.map +1 -0
- package/build/src/libs/paths.js +37 -0
- package/build/src/libs/paths.js.map +1 -0
- package/build/src/libs/print.d.ts +5 -0
- package/build/src/libs/print.d.ts.map +1 -0
- package/build/src/libs/print.js +18 -0
- package/build/src/libs/print.js.map +1 -0
- package/build/src/libs/sanitize.d.ts +10 -0
- package/build/src/libs/sanitize.d.ts.map +1 -0
- package/build/src/libs/sanitize.js +19 -0
- package/build/src/libs/sanitize.js.map +1 -0
- package/build/src/libs/seed-entities.d.ts +13 -0
- package/build/src/libs/seed-entities.d.ts.map +1 -0
- package/build/src/libs/seed-entities.js +40 -0
- package/build/src/libs/seed-entities.js.map +1 -0
- package/build/src/types.d.ts +49 -0
- package/build/src/types.d.ts.map +1 -0
- package/build/src/types.js +3 -0
- package/build/src/types.js.map +1 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Dataforge
|
|
2
|
+
|
|
3
|
+
TypeORM database tooling with a small, opinionated CLI.
|
|
4
|
+
|
|
5
|
+
Dataforge gives TypeORM projects a predictable workflow for creating databases,
|
|
6
|
+
generating migrations, applying migrations, checking status, and running seeders.
|
|
7
|
+
It stores project artifacts under `dataforge/` so migration and seed files stay grouped
|
|
8
|
+
away from application code.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install dataforge typeorm reflect-metadata
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Install the database driver your project needs, for example:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install pg
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npx dataforge init
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
This creates:
|
|
29
|
+
|
|
30
|
+
```text
|
|
31
|
+
dataforge/
|
|
32
|
+
migrations/
|
|
33
|
+
seeds/
|
|
34
|
+
dataforge.config.ts
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Edit `dataforge/dataforge.config.ts` with your TypeORM connection options, entities, and
|
|
38
|
+
seed classes.
|
|
39
|
+
|
|
40
|
+
## Commands
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx dataforge createdb
|
|
44
|
+
npx dataforge dropdb
|
|
45
|
+
npx dataforge status
|
|
46
|
+
npx dataforge gen --name CreateUsers
|
|
47
|
+
npx dataforge migrate
|
|
48
|
+
npx dataforge migration
|
|
49
|
+
npx dataforge seed
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Useful options:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx dataforge createdb --name app_dev
|
|
56
|
+
npx dataforge dropdb --name app_dev
|
|
57
|
+
npx dataforge status --name app_dev
|
|
58
|
+
npx dataforge gen --name CreateUsers --force
|
|
59
|
+
npx dataforge migrate --name CreateUsers1780000000000
|
|
60
|
+
npx dataforge migrate --file dataforge/migrations/CreateUsers1780000000000/migration.ts
|
|
61
|
+
npx dataforge seed --db app_dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Config
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import type { DATAFORGE_CONFIGURATIONS } from 'dataforge';
|
|
68
|
+
|
|
69
|
+
const config: DATAFORGE_CONFIGURATIONS = {
|
|
70
|
+
ENTITIES: ['src/**/*.schema.ts'],
|
|
71
|
+
SEEDS: [],
|
|
72
|
+
|
|
73
|
+
TYPE: 'postgres',
|
|
74
|
+
DATABASE_HOST: 'localhost',
|
|
75
|
+
DATABASE_PORT: 5432,
|
|
76
|
+
DATABASE_USERNAME: 'postgres',
|
|
77
|
+
DATABASE_PASSWORD: '',
|
|
78
|
+
DATABASE_NAME: 'app',
|
|
79
|
+
INITIAL_DATABASE: 'postgres',
|
|
80
|
+
|
|
81
|
+
SSL_MODE: false,
|
|
82
|
+
SSL_TYPE: 'light',
|
|
83
|
+
DATABASE_CA_CERT: './',
|
|
84
|
+
SYNCHRONIZE: false,
|
|
85
|
+
LOGGING: false,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export default config;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Public API
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
import type { DATAFORGE_CONFIGURATIONS } from 'dataforge';
|
|
95
|
+
import { seedEntities } from 'dataforge';
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`seedEntities` is provided for building reusable seed classes.
|
|
99
|
+
|
|
100
|
+
## Documentation
|
|
101
|
+
|
|
102
|
+
The README is intentionally compact. Full guides, examples, and command details
|
|
103
|
+
belong in the docs web app.
|
package/bin/dataforge
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC"}
|
package/build/src/app.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
require("reflect-metadata");
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const features_1 = require("./features");
|
|
6
|
+
// initialize the desc and info of the app
|
|
7
|
+
commander_1.program
|
|
8
|
+
.name('dataforge')
|
|
9
|
+
.description('typeorm database actions wrapper')
|
|
10
|
+
.version('1.0.0', '-v, --cli-version', 'Output the dataforge CLI version.');
|
|
11
|
+
// create core parts
|
|
12
|
+
commander_1.program
|
|
13
|
+
.command('init')
|
|
14
|
+
.description('Setup required configurations, files and folders')
|
|
15
|
+
.action(() => (0, features_1.init)());
|
|
16
|
+
// generate a new migration
|
|
17
|
+
commander_1.program
|
|
18
|
+
.command('gen')
|
|
19
|
+
.description('Generate a new migrations file')
|
|
20
|
+
.option('--name <name>', 'Title/Name of the migration')
|
|
21
|
+
.option('-f, --force', 'Force the migration generation even if no changes exist')
|
|
22
|
+
.action((args) => (0, features_1.gen)(args));
|
|
23
|
+
// create database
|
|
24
|
+
commander_1.program
|
|
25
|
+
.command('createdb')
|
|
26
|
+
.description('Create a new database')
|
|
27
|
+
.option('--name <name>', 'Database name')
|
|
28
|
+
.action((args) => (0, features_1.createdb)(args));
|
|
29
|
+
// drop database
|
|
30
|
+
commander_1.program
|
|
31
|
+
.command('dropdb')
|
|
32
|
+
.description('Drop an existing database')
|
|
33
|
+
.option('--name <name>', 'Database name')
|
|
34
|
+
.action((args) => (0, features_1.dropdb)(args));
|
|
35
|
+
// seed database
|
|
36
|
+
commander_1.program
|
|
37
|
+
.command('seed')
|
|
38
|
+
.description('Populate an existing database with seed data')
|
|
39
|
+
.option('--db <db>', 'The name of the db to be seeded')
|
|
40
|
+
.action((args) => (0, features_1.seed)(args));
|
|
41
|
+
// get the status of a database
|
|
42
|
+
commander_1.program
|
|
43
|
+
.command('status')
|
|
44
|
+
.description('Get the status of an existing database')
|
|
45
|
+
.option('--name <name>', 'Database name')
|
|
46
|
+
.action((args) => (0, features_1.status)(args));
|
|
47
|
+
// execute existing migrations
|
|
48
|
+
commander_1.program
|
|
49
|
+
.command('migrate')
|
|
50
|
+
.description('Execute already existing migration files')
|
|
51
|
+
.option('--name <name>', 'Migration basename/class name without .ts')
|
|
52
|
+
.option('--db <database>', 'Database which migration should be applied to')
|
|
53
|
+
.option('--file <file>', 'The path to the migration file to be executed eg. dataforge/migrations/Mig1234563534')
|
|
54
|
+
.action((args) => (0, features_1.migrate)(args));
|
|
55
|
+
// run the whole migration process
|
|
56
|
+
commander_1.program
|
|
57
|
+
.command('migration')
|
|
58
|
+
.description('Generate a new migration file and execute it immediately')
|
|
59
|
+
.option('-a, --all', 'Run all migration files along with the newly generated migration')
|
|
60
|
+
.action((args) => (0, features_1.migration)(args));
|
|
61
|
+
// start the app
|
|
62
|
+
commander_1.program.parseAsync();
|
|
63
|
+
//# sourceMappingURL=app.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":";;AAAA,4BAA0B;AAU1B,yCAAoC;AACpC,yCASoB;AAEpB,0CAA0C;AAC1C,mBAAO;KACJ,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,kCAAkC,CAAC;KAC/C,OAAO,CAAC,OAAO,EAAE,mBAAmB,EAAE,mCAAmC,CAAC,CAAC;AAE9E,oBAAoB;AACpB,mBAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,kDAAkD,CAAC;KAC/D,MAAM,CAAC,GAAG,EAAE,CAAC,IAAA,eAAI,GAAE,CAAC,CAAC;AAExB,2BAA2B;AAC3B,mBAAO;KACJ,OAAO,CAAC,KAAK,CAAC;KACd,WAAW,CAAC,gCAAgC,CAAC;KAC7C,MAAM,CAAC,eAAe,EAAE,6BAA6B,CAAC;KACtD,MAAM,CACL,aAAa,EACb,yDAAyD,CAC1D;KACA,MAAM,CAAC,CAAC,IAAyB,EAAE,EAAE,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A,kBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;AAE5C,kCAAkC;AAClC,mBAAO;KACJ,OAAO,CAAC,WAAW,CAAC;KACpB,WAAW,CAAC,0DAA0D,CAAC;KACvE,MAAM,CACL,WAAW,EACX,kEAAkE,CACnE;KACA,MAAM,CAAC,CAAC,IAAe,EAAE,EAAE,CAAC,IAAA,oBAAS,EAAC,IAAI,CAAC,CAAC,CAAC;AAEhD,gBAAgB;AAChB,mBAAO,CAAC,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const DATAFORGE_ROOT = "dataforge";
|
|
2
|
+
declare const DATAFORGE_CONFIG_TS = "dataforge/dataforge.config.ts";
|
|
3
|
+
declare const DATAFORGE_CONFIG_JS = "dataforge/dataforge.config.js";
|
|
4
|
+
declare const DATAFORGE_MIGRATIONS_DIR = "dataforge/migrations";
|
|
5
|
+
declare const DATAFORGE_SEEDS_DIR = "dataforge/seeds";
|
|
6
|
+
declare const DATAFORGE_MIGRATIONS_GLOB = "dataforge/migrations/**/*.{ts,js}";
|
|
7
|
+
export { DATAFORGE_CONFIG_JS, DATAFORGE_CONFIG_TS, DATAFORGE_MIGRATIONS_DIR, DATAFORGE_MIGRATIONS_GLOB, DATAFORGE_ROOT, DATAFORGE_SEEDS_DIR, };
|
|
8
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,cAAc,cAAc,CAAC;AACnC,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,mBAAmB,kCAAkC,CAAC;AAC5D,QAAA,MAAM,wBAAwB,yBAAyB,CAAC;AACxD,QAAA,MAAM,mBAAmB,oBAAoB,CAAC;AAC9C,QAAA,MAAM,yBAAyB,sCAAsC,CAAC;AAEtE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DATAFORGE_SEEDS_DIR = exports.DATAFORGE_ROOT = exports.DATAFORGE_MIGRATIONS_GLOB = exports.DATAFORGE_MIGRATIONS_DIR = exports.DATAFORGE_CONFIG_TS = exports.DATAFORGE_CONFIG_JS = void 0;
|
|
4
|
+
const DATAFORGE_ROOT = 'dataforge';
|
|
5
|
+
exports.DATAFORGE_ROOT = DATAFORGE_ROOT;
|
|
6
|
+
const DATAFORGE_CONFIG_TS = 'dataforge/dataforge.config.ts';
|
|
7
|
+
exports.DATAFORGE_CONFIG_TS = DATAFORGE_CONFIG_TS;
|
|
8
|
+
const DATAFORGE_CONFIG_JS = 'dataforge/dataforge.config.js';
|
|
9
|
+
exports.DATAFORGE_CONFIG_JS = DATAFORGE_CONFIG_JS;
|
|
10
|
+
const DATAFORGE_MIGRATIONS_DIR = 'dataforge/migrations';
|
|
11
|
+
exports.DATAFORGE_MIGRATIONS_DIR = DATAFORGE_MIGRATIONS_DIR;
|
|
12
|
+
const DATAFORGE_SEEDS_DIR = 'dataforge/seeds';
|
|
13
|
+
exports.DATAFORGE_SEEDS_DIR = DATAFORGE_SEEDS_DIR;
|
|
14
|
+
const DATAFORGE_MIGRATIONS_GLOB = 'dataforge/migrations/**/*.{ts,js}';
|
|
15
|
+
exports.DATAFORGE_MIGRATIONS_GLOB = DATAFORGE_MIGRATIONS_GLOB;
|
|
16
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/config/constants.ts"],"names":[],"mappings":";;;AAAA,MAAM,cAAc,GAAG,WAAW,CAAC;AAYjC,wCAAc;AAXhB,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAQ1D,kDAAmB;AAPrB,MAAM,mBAAmB,GAAG,+BAA+B,CAAC;AAM1D,kDAAmB;AALrB,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAOtD,4DAAwB;AAN1B,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAS5C,kDAAmB;AARrB,MAAM,yBAAyB,GAAG,mCAAmC,CAAC;AAMpE,8DAAyB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,iCAAiC,EAAE,MAAM,SAAS,CAAC;AAyDtF,QAAA,MAAM,GAAG,EAAE,iCAOV,CAAC;AAEF,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.cfg = void 0;
|
|
37
|
+
const constants_1 = require("./constants");
|
|
38
|
+
const node_module_1 = require("node:module");
|
|
39
|
+
const node_fs_1 = require("node:fs");
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
const requireConfig = (0, node_module_1.createRequire)(path.join(process.cwd(), 'dataforge.config.cjs'));
|
|
42
|
+
const defaults = {
|
|
43
|
+
ENTITIES: ['src/**/*.schema.ts'],
|
|
44
|
+
SEEDS: [],
|
|
45
|
+
TYPE: 'postgres',
|
|
46
|
+
SSL_MODE: false,
|
|
47
|
+
SSL_TYPE: 'light',
|
|
48
|
+
DATABASE_CA_CERT: './',
|
|
49
|
+
DATABASE_HOST: 'localhost',
|
|
50
|
+
DATABASE_PORT: 5432,
|
|
51
|
+
DATABASE_USERNAME: 'postgres',
|
|
52
|
+
DATABASE_PASSWORD: '',
|
|
53
|
+
DATABASE_NAME: 'app',
|
|
54
|
+
SYNCHRONIZE: false,
|
|
55
|
+
LOGGING: false,
|
|
56
|
+
INITIAL_DATABASE: 'postgres',
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Loads the user-authored Dataforge config from the opinionated project config path.
|
|
60
|
+
* Supports TypeScript and JavaScript config files and returns an empty object
|
|
61
|
+
* when no config file has been initialized yet.
|
|
62
|
+
*
|
|
63
|
+
* @returns Partial user config to merge over defaults.
|
|
64
|
+
*/
|
|
65
|
+
function loadUserConfig() {
|
|
66
|
+
var _a;
|
|
67
|
+
for (const file of [constants_1.DATAFORGE_CONFIG_TS, constants_1.DATAFORGE_CONFIG_JS]) {
|
|
68
|
+
const location = path.resolve(process.cwd(), file);
|
|
69
|
+
if (!(0, node_fs_1.existsSync)(location))
|
|
70
|
+
continue;
|
|
71
|
+
const mod = requireConfig(location);
|
|
72
|
+
return (_a = mod.default) !== null && _a !== void 0 ? _a : mod;
|
|
73
|
+
}
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
const userConfig = loadUserConfig();
|
|
77
|
+
const cfg = Object.assign(Object.assign(Object.assign({}, defaults), userConfig), { ROOT: constants_1.DATAFORGE_ROOT, MIGRATIONS_DIR: constants_1.DATAFORGE_MIGRATIONS_DIR, SEEDS_DIR: constants_1.DATAFORGE_SEEDS_DIR, MIGRATIONS: [constants_1.DATAFORGE_MIGRATIONS_GLOB] });
|
|
78
|
+
exports.cfg = cfg;
|
|
79
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,2CAOqB;AACrB,6CAA4C;AAC5C,qCAAqC;AACrC,gDAAkC;AAElC,MAAM,aAAa,GAAG,IAAA,2BAAa,EAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,sBAAsB,CAAC,CAAC,CAAC;AAEtF,MAAM,QAAQ,GAA6B;IACzC,QAAQ,EAAE,CAAC,oBAAoB,CAAC;IAChC,KAAK,EAAE,EAAE;IAET,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,KAAK;IACf,QAAQ,EAAE,OAAO;IACjB,gBAAgB,EAAE,IAAI;IACtB,aAAa,EAAE,WAAW;IAC1B,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,UAAU;IAC7B,iBAAiB,EAAE,EAAE;IACrB,aAAa,EAAE,KAAK;IACpB,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,KAAK;IACd,gBAAgB,EAAE,UAAU;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,cAAc;;IACrB,KAAK,MAAM,IAAI,IAAI,CAAC,+BAAmB,EAAE,+BAAmB,CAAC,EAAE,CAAC;QAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,IAAA,oBAAU,EAAC,QAAQ,CAAC;YAAE,SAAS;QAEpC,MAAM,GAAG,GAAG,aAAa,CAAC,QAAQ,CAEG,CAAC;QAEtC,OAAO,MAAA,GAAG,CAAC,OAAO,mCAAI,GAAG,CAAC;IAC5B,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,GAAG,cAAc,EAAE,CAAC;AAEpC,MAAM,GAAG,iDACJ,QAAQ,GACR,UAAU,KACb,IAAI,EAAE,0BAAc,EACpB,cAAc,EAAE,oCAAwB,EACxC,SAAS,EAAE,+BAAmB,EAC9B,UAAU,EAAE,CAAC,qCAAyB,CAAC,GACxC,CAAC;AAEO,kBAAG"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CREATE_DB } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a database if it does not already exist.
|
|
4
|
+
* Idempotent — safe to run multiple times with the same name.
|
|
5
|
+
*
|
|
6
|
+
* @param name - Database name to create (expected to be sanitized).
|
|
7
|
+
* @returns Outcome status and whether the database was created.
|
|
8
|
+
*/
|
|
9
|
+
declare function create(name: string): Promise<{
|
|
10
|
+
status: 'created' | 'already-exists';
|
|
11
|
+
created: boolean;
|
|
12
|
+
error?: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* CLI handler for the `createdb` command.
|
|
16
|
+
*
|
|
17
|
+
* @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
|
|
18
|
+
*/
|
|
19
|
+
declare function createdb(args: CREATE_DB): Promise<void>;
|
|
20
|
+
export { createdb, create };
|
|
21
|
+
//# sourceMappingURL=createdb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createdb.d.ts","sourceRoot":"","sources":["../../../src/features/createdb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAMpC;;;;;;GAMG;AACH,iBAAe,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3C,MAAM,EAAE,SAAS,GAAG,gBAAgB,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CA2BD;AAED;;;;GAIG;AACH,iBAAe,QAAQ,CAAC,IAAI,EAAE,SAAS,iBAatC;AAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createdb = createdb;
|
|
13
|
+
exports.create = create;
|
|
14
|
+
const get_commands_1 = require("../libs/get-commands");
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
const print_1 = require("../libs/print");
|
|
17
|
+
const sanitize_1 = require("../libs/sanitize");
|
|
18
|
+
const create_ds_1 = require("../libs/create-ds");
|
|
19
|
+
/**
|
|
20
|
+
* Creates a database if it does not already exist.
|
|
21
|
+
* Idempotent — safe to run multiple times with the same name.
|
|
22
|
+
*
|
|
23
|
+
* @param name - Database name to create (expected to be sanitized).
|
|
24
|
+
* @returns Outcome status and whether the database was created.
|
|
25
|
+
*/
|
|
26
|
+
function create(name) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const ds = (0, create_ds_1.createDataSource)();
|
|
29
|
+
let initialized = false;
|
|
30
|
+
try {
|
|
31
|
+
const createCommand = (0, get_commands_1.getCreateDbCommand)(name);
|
|
32
|
+
const checksCommand = (0, get_commands_1.getDbCheckCommand)();
|
|
33
|
+
yield ds.initialize();
|
|
34
|
+
initialized = true;
|
|
35
|
+
const rs = yield ds.query(checksCommand, [name]);
|
|
36
|
+
const exists = rs.length > 0;
|
|
37
|
+
if (!exists) {
|
|
38
|
+
yield ds.query(createCommand);
|
|
39
|
+
return { status: 'created', created: true };
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return { status: 'already-exists', created: false };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
const err = e instanceof Error ? e.message : 'Unable to serialize error';
|
|
47
|
+
throw new Error(err);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (initialized) {
|
|
51
|
+
yield ds.destroy();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* CLI handler for the `createdb` command.
|
|
58
|
+
*
|
|
59
|
+
* @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
|
|
60
|
+
*/
|
|
61
|
+
function createdb(args) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
var _a;
|
|
64
|
+
const name = (0, sanitize_1.sanitize)((_a = args.name) !== null && _a !== void 0 ? _a : config_1.cfg.DATABASE_NAME);
|
|
65
|
+
try {
|
|
66
|
+
const response = yield create(name);
|
|
67
|
+
if (response.status === 'created') {
|
|
68
|
+
(0, print_1.print)(`Database '${name}' created successfully`);
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
(0, print_1.print)(`Database '${name}' already exists`);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const err = e instanceof Error ? e.message : 'Unable to serialize error';
|
|
75
|
+
(0, print_1.printf)(`Error creating database '${name}': ${err}`);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=createdb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createdb.js","sourceRoot":"","sources":["../../../src/features/createdb.ts"],"names":[],"mappings":";;;;;;;;;;;AAmES,4BAAQ;AAAE,wBAAM;AAnEzB,sDAA4E;AAE5E,qCAA+B;AAC/B,wCAA6C;AAC7C,8CAA2C;AAC3C,gDAAoD;AAEpD;;;;;;GAMG;AACH,SAAe,MAAM,CAAC,IAAY;;QAKhC,MAAM,EAAE,GAAG,IAAA,4BAAgB,GAAE,CAAC;QAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,IAAA,iCAAkB,EAAC,IAAI,CAAC,CAAC;YAC/C,MAAM,aAAa,GAAG,IAAA,gCAAiB,GAAE,CAAC;YAE1C,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC;YACtB,WAAW,GAAG,IAAI,CAAC;YAEnB,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;YAEjD,MAAM,MAAM,GAA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A,cAAM,EAAC,4BAA4B,IAAI,MAAM,GAAG,EAAE,CAAC,CAAC;YACpD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DROP_DB } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Drops a database if it exists.
|
|
4
|
+
*
|
|
5
|
+
* @param name - Database name to drop (expected to be sanitized).
|
|
6
|
+
* @returns Whether the drop succeeded; includes `error` on failure.
|
|
7
|
+
*/
|
|
8
|
+
declare function drop(name: string): Promise<{
|
|
9
|
+
dropped: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* CLI handler for the `dropdb` command.
|
|
13
|
+
*
|
|
14
|
+
* @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
|
|
15
|
+
*/
|
|
16
|
+
declare function dropdb(args: DROP_DB): Promise<void>;
|
|
17
|
+
export { dropdb, drop };
|
|
18
|
+
//# sourceMappingURL=dropdb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdb.d.ts","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAMlC;;;;;GAKG;AACH,iBAAe,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAkB/D;AAED;;;;GAIG;AACH,iBAAe,MAAM,CAAC,IAAI,EAAE,OAAO,iBAalC;AAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.dropdb = dropdb;
|
|
13
|
+
exports.drop = drop;
|
|
14
|
+
const print_1 = require("../libs/print");
|
|
15
|
+
const config_1 = require("../config");
|
|
16
|
+
const sanitize_1 = require("../libs/sanitize");
|
|
17
|
+
const get_commands_1 = require("../libs/get-commands");
|
|
18
|
+
const create_ds_1 = require("../libs/create-ds");
|
|
19
|
+
/**
|
|
20
|
+
* Drops a database if it exists.
|
|
21
|
+
*
|
|
22
|
+
* @param name - Database name to drop (expected to be sanitized).
|
|
23
|
+
* @returns Whether the drop succeeded; includes `error` on failure.
|
|
24
|
+
*/
|
|
25
|
+
function drop(name) {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const ds = (0, create_ds_1.createDataSource)();
|
|
28
|
+
let initialized = false;
|
|
29
|
+
try {
|
|
30
|
+
const command = (0, get_commands_1.getDropDbCommand)(name);
|
|
31
|
+
yield ds.initialize();
|
|
32
|
+
initialized = true;
|
|
33
|
+
yield ds.query(command);
|
|
34
|
+
return { dropped: true };
|
|
35
|
+
}
|
|
36
|
+
catch (e) {
|
|
37
|
+
const err = e instanceof Error ? e.message : 'Unable to serialize err';
|
|
38
|
+
throw new Error(err);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
if (initialized) {
|
|
42
|
+
yield ds.destroy();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* CLI handler for the `dropdb` command.
|
|
49
|
+
*
|
|
50
|
+
* @param args - CLI options; `name` defaults to `cfg.DATABASE_NAME`.
|
|
51
|
+
*/
|
|
52
|
+
function dropdb(args) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
var _a;
|
|
55
|
+
const name = (0, sanitize_1.sanitize)((_a = args.name) !== null && _a !== void 0 ? _a : config_1.cfg.DATABASE_NAME);
|
|
56
|
+
try {
|
|
57
|
+
const response = yield drop(name);
|
|
58
|
+
const msg = response.dropped
|
|
59
|
+
? `Database '${name}' dropped successfully`
|
|
60
|
+
: `Couldn't drop Database '${name}'`;
|
|
61
|
+
(0, print_1.print)(msg);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
const err = e instanceof Error ? e.message : 'Unable to serialize err';
|
|
65
|
+
(0, print_1.printf)(`Error dropping '${name}': ${err}`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=dropdb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdb.js","sourceRoot":"","sources":["../../../src/features/dropdb.ts"],"names":[],"mappings":";;;;;;;;;;;AAqDS,wBAAM;AAAE,oBAAI;AArDrB,wCAA6C;AAE7C,qCAA+B;AAC/B,8CAA2C;AAC3C,sDAAuD;AACvD,gDAAoD;AAEpD;;;;;GAKG;AACH,SAAe,IAAI,CAAC,IAAY;;QAC9B,MAAM,EAAE,GAAG,IAAA,4BAAgB,GAAE,CAAC;QAC9B,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,IAAA,+BAAgB,EAAC,IAAI,CAAC,CAAC;YACvC,MAAM,EAAE,CAAC,UAAU,EAAE,CAAC;YACtB,WAAW,GAAG,IAAI,CAAC;YAEnB,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACxB,OAAO,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{
|
|
5
|
+
title: string;
|
|
6
|
+
saved: boolean;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
location: string;
|
|
9
|
+
};
|
|
10
|
+
type Success = {
|
|
11
|
+
generated: true;
|
|
12
|
+
more: MoreInfo & {
|
|
13
|
+
content: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type Failure = {
|
|
17
|
+
generated: false;
|
|
18
|
+
more: {
|
|
19
|
+
reason: 'duplicate-found' | 'no-changes';
|
|
20
|
+
duplicateOf?: string;
|
|
21
|
+
} & MoreInfo;
|
|
22
|
+
};
|
|
23
|
+
type GeneratReturn = Success | Failure;
|
|
24
|
+
/**
|
|
25
|
+
* Detects pending schema changes by diffing entities against the database.
|
|
26
|
+
*
|
|
27
|
+
* @param ds - Initialized TypeORM data source.
|
|
28
|
+
* @returns Whether up or down migration queries would be generated.
|
|
29
|
+
*/
|
|
30
|
+
declare const hasSchemaChanges: (ds: DataSource) => Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Generates a migration preview from an initialized data source and formats it.
|
|
33
|
+
*
|
|
34
|
+
* @param ds - Initialized TypeORM data source to diff against.
|
|
35
|
+
* @param name - Migration class/name prefix.
|
|
36
|
+
* @param timestamp - Timestamp suffix TypeORM uses in the migration class.
|
|
37
|
+
* @returns Generated source, formatted source, and whether schema changes exist.
|
|
38
|
+
*/
|
|
39
|
+
declare const genMig: (ds: DataSource, name: string, timestamp: number) => Promise<{
|
|
40
|
+
content: string;
|
|
41
|
+
formatted: string;
|
|
42
|
+
hasChanges: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Persists a generated migration file, creating its parent folder first.
|
|
46
|
+
*
|
|
47
|
+
* @param location - Destination `migration.ts` path.
|
|
48
|
+
* @param content - TypeScript migration source to write.
|
|
49
|
+
*/
|
|
50
|
+
declare const saveMig: (location: string, content: string) => Promise<undefined>;
|
|
51
|
+
/**
|
|
52
|
+
* Builds the generated migration name and location metadata.
|
|
53
|
+
*
|
|
54
|
+
* @param name - Optional migration name prefix; defaults to `Mig`.
|
|
55
|
+
* @returns Timestamped filename, TypeORM migration name, and target file path.
|
|
56
|
+
*/
|
|
57
|
+
declare const getMetadata: (name?: string) => {
|
|
58
|
+
location: string;
|
|
59
|
+
filename: string;
|
|
60
|
+
migrationName: string;
|
|
61
|
+
timestamp: number;
|
|
62
|
+
};
|
|
63
|
+
type GenerateParams = {
|
|
64
|
+
db: string;
|
|
65
|
+
force: boolean | undefined;
|
|
66
|
+
name: string | undefined;
|
|
67
|
+
save: boolean | undefined;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Generates a migration file from current entity schemas.
|
|
71
|
+
*
|
|
72
|
+
* @param params - Generation options including target database, force flag,
|
|
73
|
+
* migration name prefix, and whether to save the file.
|
|
74
|
+
* @returns Generation outcome including title and whether changes were found.
|
|
75
|
+
*/
|
|
76
|
+
declare const generate: (params?: Partial<GenerateParams>) => Promise<GeneratReturn>;
|
|
77
|
+
/**
|
|
78
|
+
* CLI handler for the `gen` command.
|
|
79
|
+
*
|
|
80
|
+
* @param args - CLI options for migration name and force flag.
|
|
81
|
+
*/
|
|
82
|
+
declare const gen: (args: GENERATE_MIGRATIONS) => Promise<never>;
|
|
83
|
+
export { gen, generate, genMig, compareMig, getMetadata, saveMig, hasSchemaChanges, };
|
|
84
|
+
//# sourceMappingURL=gen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/features/gen.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGrC,OAAO,EAAE,UAAU,EAAoB,MAAM,oBAAoB,CAAC;AAOlE,KAAK,QAAQ,GAAG;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,C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