@rvoh/dream 0.31.1 → 0.31.2
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 +17 -17
- package/dist/cjs/src/Dream.js +15 -15
- package/dist/cjs/src/bin/helpers/sync.js +9 -2
- package/dist/cjs/src/bin/index.js +18 -19
- package/dist/cjs/src/cli/logger/DreamCliLogger.js +12 -46
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggable.js +1 -3
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableText.js +2 -2
- package/dist/cjs/src/decorators/Decorators.js +28 -28
- package/dist/cjs/src/decorators/field/association/BelongsTo.js +2 -2
- package/dist/cjs/src/decorators/field/association/HasMany.js +2 -2
- package/dist/cjs/src/decorators/field/association/HasOne.js +2 -2
- package/dist/cjs/src/decorators/field/lifecycle/AfterCreateCommit.js +1 -1
- package/dist/cjs/src/decorators/field/lifecycle/AfterDestroyCommit.js +1 -1
- package/dist/cjs/src/decorators/field/lifecycle/AfterSaveCommit.js +1 -1
- package/dist/cjs/src/decorators/field/lifecycle/AfterUpdateCommit.js +1 -1
- package/dist/cjs/src/decorators/field/validation/Validates.js +1 -1
- package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +2 -2
- package/dist/cjs/src/dream/Query.js +2 -2
- package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -2
- package/dist/cjs/src/helpers/db/runMigration.js +5 -5
- package/dist/cjs/src/helpers/sspawn.js +29 -3
- package/dist/cjs/src/serializer/decorators/associations/RendersMany.js +2 -2
- package/dist/cjs/src/serializer/decorators/associations/RendersOne.js +2 -2
- package/dist/esm/src/Dream.js +15 -15
- package/dist/esm/src/bin/helpers/sync.js +9 -2
- package/dist/esm/src/bin/index.js +18 -19
- package/dist/esm/src/cli/logger/DreamCliLogger.js +12 -46
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggable.js +1 -3
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggableText.js +2 -2
- package/dist/esm/src/decorators/Decorators.js +28 -28
- package/dist/esm/src/decorators/field/association/BelongsTo.js +2 -2
- package/dist/esm/src/decorators/field/association/HasMany.js +2 -2
- package/dist/esm/src/decorators/field/association/HasOne.js +2 -2
- package/dist/esm/src/decorators/field/lifecycle/AfterCreateCommit.js +1 -1
- package/dist/esm/src/decorators/field/lifecycle/AfterDestroyCommit.js +1 -1
- package/dist/esm/src/decorators/field/lifecycle/AfterSaveCommit.js +1 -1
- package/dist/esm/src/decorators/field/lifecycle/AfterUpdateCommit.js +1 -1
- package/dist/esm/src/decorators/field/validation/Validates.js +1 -1
- package/dist/esm/src/dream/DreamClassTransactionBuilder.js +2 -2
- package/dist/esm/src/dream/Query.js +2 -2
- package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -2
- package/dist/esm/src/helpers/db/runMigration.js +5 -5
- package/dist/esm/src/helpers/sspawn.js +29 -3
- package/dist/esm/src/serializer/decorators/associations/RendersMany.js +2 -2
- package/dist/esm/src/serializer/decorators/associations/RendersOne.js +2 -2
- package/dist/types/src/Dream.d.ts +15 -15
- package/dist/types/src/cli/logger/DreamCliLogger.d.ts +4 -8
- package/dist/types/src/cli/logger/loggable/DreamCliLoggable.d.ts +1 -3
- package/dist/types/src/cli/logger/loggable/DreamCliLoggableText.d.ts +1 -2
- package/dist/types/src/decorators/Decorators.d.ts +22 -22
- package/dist/types/src/decorators/field/lifecycle/AfterCreateCommit.d.ts +1 -1
- package/dist/types/src/decorators/field/lifecycle/AfterDestroyCommit.d.ts +1 -1
- package/dist/types/src/decorators/field/lifecycle/AfterSaveCommit.d.ts +1 -1
- package/dist/types/src/decorators/field/lifecycle/AfterUpdateCommit.d.ts +1 -1
- package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +2 -2
- package/dist/types/src/dream/Query.d.ts +2 -2
- package/dist/types/src/helpers/sspawn.d.ts +6 -2
- package/dist/types/src/serializer/decorators/associations/RendersMany.d.ts +2 -2
- package/dist/types/src/serializer/decorators/associations/RendersOne.d.ts +2 -2
- package/dist/types/src/types/logger.d.ts +1 -5
- package/docs/classes/Benchmark.html +2 -2
- package/docs/classes/CalendarDate.html +2 -2
- package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
- package/docs/classes/Decorators.html +38 -38
- package/docs/classes/Dream.html +138 -138
- package/docs/classes/DreamApplication.html +4 -4
- package/docs/classes/DreamBin.html +2 -2
- package/docs/classes/DreamCLI.html +4 -4
- package/docs/classes/DreamDbConnection.html +2 -2
- package/docs/classes/DreamGlam.html +2 -2
- package/docs/classes/DreamImporter.html +2 -2
- package/docs/classes/DreamMigrationHelpers.html +7 -7
- package/docs/classes/DreamSerializer.html +2 -2
- package/docs/classes/DreamTransaction.html +2 -2
- package/docs/classes/Encrypt.html +2 -2
- package/docs/classes/Env.html +2 -2
- package/docs/classes/GlobalNameNotSet.html +3 -3
- package/docs/classes/NonLoadedAssociation.html +3 -3
- package/docs/classes/Query.html +51 -51
- package/docs/classes/Range.html +2 -2
- package/docs/classes/RecordNotFound.html +3 -3
- package/docs/classes/ValidationError.html +3 -3
- package/docs/functions/Attribute.html +1 -1
- package/docs/functions/RendersMany.html +2 -2
- package/docs/functions/RendersOne.html +2 -2
- package/docs/functions/ReplicaSafe.html +1 -1
- package/docs/functions/STI.html +1 -1
- package/docs/functions/SoftDelete.html +1 -1
- package/docs/functions/camelize.html +1 -1
- package/docs/functions/capitalize.html +1 -1
- package/docs/functions/closeAllDbConnections.html +1 -1
- package/docs/functions/compact.html +1 -1
- package/docs/functions/db.html +1 -1
- package/docs/functions/debug.html +1 -1
- package/docs/functions/dreamDbConnections.html +1 -1
- package/docs/functions/dreamPath.html +1 -1
- package/docs/functions/generateDream.html +1 -1
- package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/hyphenize.html +1 -1
- package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
- package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
- package/docs/functions/isEmpty.html +1 -1
- package/docs/functions/loadRepl.html +1 -1
- package/docs/functions/lookupClassByGlobalName.html +1 -1
- package/docs/functions/pascalize.html +1 -1
- package/docs/functions/pgErrorType.html +1 -1
- package/docs/functions/range-1.html +1 -1
- package/docs/functions/relativeDreamPath.html +1 -1
- package/docs/functions/round.html +1 -1
- package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
- package/docs/functions/sharedPathPrefix.html +1 -1
- package/docs/functions/snakeify.html +1 -1
- package/docs/functions/sort.html +1 -1
- package/docs/functions/sortBy.html +1 -1
- package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
- package/docs/functions/uncapitalize.html +1 -1
- package/docs/functions/uniq.html +1 -1
- package/docs/functions/validateColumn.html +1 -1
- package/docs/functions/validateTable.html +1 -1
- package/docs/index.html +5 -5
- package/docs/interfaces/AttributeStatement.html +2 -2
- package/docs/interfaces/DecoratorContext.html +2 -2
- package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
- package/docs/interfaces/DreamApplicationOpts.html +2 -2
- package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
- package/docs/interfaces/EncryptOptions.html +2 -2
- package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
- package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
- package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
- package/docs/types/Camelized.html +1 -1
- package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
- package/docs/types/DateTime.html +1 -1
- package/docs/types/DreamAssociationMetadata.html +1 -1
- package/docs/types/DreamAttributes.html +1 -1
- package/docs/types/DreamClassColumn.html +1 -1
- package/docs/types/DreamColumn.html +1 -1
- package/docs/types/DreamColumnNames.html +1 -1
- package/docs/types/DreamLogLevel.html +1 -1
- package/docs/types/DreamLogger.html +1 -1
- package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
- package/docs/types/DreamParamSafeAttributes.html +1 -1
- package/docs/types/DreamParamSafeColumnNames.html +1 -1
- package/docs/types/DreamSerializerKey.html +1 -1
- package/docs/types/DreamSerializers.html +1 -1
- package/docs/types/DreamTableSchema.html +1 -1
- package/docs/types/DreamVirtualColumns.html +1 -1
- package/docs/types/EncryptAlgorithm.html +1 -1
- package/docs/types/Hyphenized.html +1 -1
- package/docs/types/IdType.html +1 -1
- package/docs/types/OpenapiAllTypes.html +1 -1
- package/docs/types/OpenapiFormats.html +1 -1
- package/docs/types/OpenapiNumberFormats.html +1 -1
- package/docs/types/OpenapiPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiSchemaArray.html +1 -1
- package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
- package/docs/types/OpenapiSchemaBase.html +1 -1
- package/docs/types/OpenapiSchemaBody.html +1 -1
- package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
- package/docs/types/OpenapiSchemaCommonFields.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
- package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
- package/docs/types/OpenapiSchemaInteger.html +1 -1
- package/docs/types/OpenapiSchemaNull.html +1 -1
- package/docs/types/OpenapiSchemaNumber.html +1 -1
- package/docs/types/OpenapiSchemaObject.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectBase.html +1 -1
- package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
- package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
- package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
- package/docs/types/OpenapiSchemaPartialSegment.html +1 -1
- package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
- package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
- package/docs/types/OpenapiSchemaString.html +1 -1
- package/docs/types/OpenapiShorthandAllTypes.html +1 -1
- package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
- package/docs/types/OpenapiTypeField.html +1 -1
- package/docs/types/Pascalized.html +1 -1
- package/docs/types/PrimaryKeyType.html +1 -1
- package/docs/types/RoundingPrecision.html +1 -1
- package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
- package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
- package/docs/types/SerializableDreamOrViewModel.html +1 -1
- package/docs/types/SerializableTypes.html +1 -1
- package/docs/types/Snakeified.html +1 -1
- package/docs/types/Timestamp.html +1 -1
- package/docs/types/UpdateableAssociationProperties.html +1 -1
- package/docs/types/UpdateableProperties.html +1 -1
- package/docs/types/ValidationType.html +1 -1
- package/docs/types/ViewModelSerializerKey.html +1 -1
- package/docs/types/WhereStatementForDream.html +1 -1
- package/docs/types/WhereStatementForDreamClass.html +1 -1
- package/docs/variables/DateTime-1.html +1 -1
- package/docs/variables/DreamConst.html +1 -1
- package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
- package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
- package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
- package/docs/variables/ops.html +1 -1
- package/docs/variables/primaryKeyTypes.html +1 -1
- package/package.json +1 -2
- package/dist/cjs/src/cli/logger/helpers/createSpinner.js +0 -14
- package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableSpinner.js +0 -31
- package/dist/cjs/src/cli/logger/loggable/spinners.js +0 -1185
- package/dist/esm/src/cli/logger/helpers/createSpinner.js +0 -11
- package/dist/esm/src/cli/logger/loggable/DreamCliLoggableSpinner.js +0 -28
- package/dist/esm/src/cli/logger/loggable/spinners.js +0 -1183
- package/dist/types/src/cli/logger/helpers/createSpinner.d.ts +0 -2
- package/dist/types/src/cli/logger/loggable/DreamCliLoggableSpinner.d.ts +0 -21
- package/dist/types/src/cli/logger/loggable/spinners.d.ts +0 -355
|
@@ -13,20 +13,25 @@ import sspawn from '../helpers/sspawn.js';
|
|
|
13
13
|
import writeSyncFile from './helpers/sync.js';
|
|
14
14
|
export default class DreamBin {
|
|
15
15
|
static async sync(onSync) {
|
|
16
|
+
DreamCLI.logger.logStartProgress('writing db schema...');
|
|
16
17
|
await writeSyncFile();
|
|
18
|
+
DreamCLI.logger.logEndProgress();
|
|
19
|
+
DreamCLI.logger.logStartProgress('building dream schema...');
|
|
17
20
|
await this.buildDreamSchema();
|
|
21
|
+
DreamCLI.logger.logEndProgress();
|
|
22
|
+
DreamCLI.logger.logStartProgress('running sync hooks...');
|
|
18
23
|
await onSync();
|
|
24
|
+
DreamCLI.logger.logEndProgress();
|
|
19
25
|
}
|
|
20
26
|
static async buildDreamSchema() {
|
|
21
|
-
const spinner = DreamCLI.logger.log('writing dream schema...', { spinner: true });
|
|
22
27
|
await new SchemaBuilder().build();
|
|
23
|
-
spinner.stop();
|
|
24
28
|
}
|
|
25
29
|
static async dbCreate() {
|
|
26
30
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
27
31
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
28
|
-
|
|
32
|
+
DreamCLI.logger.logStartProgress(`creating ${primaryDbConf.name}...`);
|
|
29
33
|
await createDb('primary');
|
|
34
|
+
DreamCLI.logger.logEndProgress();
|
|
30
35
|
// TODO: add support for creating replicas. Began doing it below, but it is very tricky,
|
|
31
36
|
// and we don't need it at the moment, so kicking off for future development when we have more time
|
|
32
37
|
// to flesh this out.
|
|
@@ -35,13 +40,13 @@ export default class DreamBin {
|
|
|
35
40
|
// console.log(`creating ${process.env[replicaDbConf.name]}`)
|
|
36
41
|
// await createDb('replica')
|
|
37
42
|
// }
|
|
38
|
-
spinner.stop();
|
|
39
43
|
}
|
|
40
44
|
static async dbDrop() {
|
|
41
45
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
42
46
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
43
|
-
|
|
47
|
+
DreamCLI.logger.logStartProgress(`dropping ${primaryDbConf.name}...`);
|
|
44
48
|
await _dropDb('primary');
|
|
49
|
+
DreamCLI.logger.logEndProgress();
|
|
45
50
|
// TODO: add support for dropping replicas. Began doing it below, but it is very tricky,
|
|
46
51
|
// and we don't need it at the moment, so kicking off for future development when we have more time
|
|
47
52
|
// to flesh this out.
|
|
@@ -50,27 +55,26 @@ export default class DreamBin {
|
|
|
50
55
|
// console.log(`dropping ${process.env[replicaDbConf.name]}`)
|
|
51
56
|
// await _dropDb('replica')
|
|
52
57
|
// }
|
|
53
|
-
spinner.stop();
|
|
54
58
|
}
|
|
55
59
|
static async dbMigrate() {
|
|
56
60
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
57
61
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
58
|
-
|
|
62
|
+
DreamCLI.logger.logStartProgress(`migrating ${primaryDbConf.name}...`);
|
|
59
63
|
await runMigration({ mode: 'migrate' });
|
|
60
64
|
await this.duplicateDatabase();
|
|
61
|
-
|
|
65
|
+
DreamCLI.logger.logEndProgress();
|
|
62
66
|
}
|
|
63
67
|
static async dbRollback(opts) {
|
|
64
68
|
const connectionRetriever = new ConnectionConfRetriever();
|
|
65
69
|
const primaryDbConf = connectionRetriever.getConnectionConf('primary');
|
|
66
|
-
|
|
70
|
+
DreamCLI.logger.logStartProgress(`rolling back ${primaryDbConf.name}...`);
|
|
67
71
|
let step = opts.steps;
|
|
68
72
|
while (step > 0) {
|
|
69
73
|
await runMigration({ mode: 'rollback' });
|
|
70
74
|
step -= 1;
|
|
71
75
|
}
|
|
72
76
|
await this.duplicateDatabase();
|
|
73
|
-
|
|
77
|
+
DreamCLI.logger.logEndProgress();
|
|
74
78
|
}
|
|
75
79
|
static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
|
|
76
80
|
await generateDream({ fullyQualifiedModelName, columnsWithTypes, options });
|
|
@@ -85,8 +89,9 @@ export default class DreamBin {
|
|
|
85
89
|
// It is only made private so that people don't mistakenly try
|
|
86
90
|
// to use it to generate docs for their apps.
|
|
87
91
|
static async buildDocs() {
|
|
88
|
-
DreamCLI.logger.
|
|
92
|
+
DreamCLI.logger.logStartProgress('generating docs...');
|
|
89
93
|
await sspawn('yarn typedoc src/index.ts --tsconfig ./tsconfig.esm.build.json --out docs');
|
|
94
|
+
DreamCLI.logger.logEndProgress();
|
|
90
95
|
}
|
|
91
96
|
static async duplicateDatabase() {
|
|
92
97
|
const parallelTests = DreamApplication.getOrFail().parallelTests;
|
|
@@ -97,22 +102,16 @@ export default class DreamBin {
|
|
|
97
102
|
const client = await loadPgClient({ useSystemDb: true });
|
|
98
103
|
if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
|
|
99
104
|
const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
|
|
100
|
-
|
|
101
|
-
spinner: true,
|
|
102
|
-
});
|
|
105
|
+
DreamCLI.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`);
|
|
103
106
|
await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
|
|
104
107
|
await client.query(`CREATE DATABASE ${replicaTestWorkerDatabaseName} TEMPLATE ${dbConf.name};`);
|
|
105
|
-
spinner.stop();
|
|
106
108
|
}
|
|
107
109
|
for (let i = 2; i <= parallelTests; i++) {
|
|
108
110
|
const workerDatabaseName = `${dbConf.name}_${i}`;
|
|
109
111
|
console.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests`);
|
|
110
|
-
|
|
111
|
-
spinner: true,
|
|
112
|
-
});
|
|
112
|
+
DreamCLI.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`);
|
|
113
113
|
await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
|
|
114
114
|
await client.query(`CREATE DATABASE ${workerDatabaseName} TEMPLATE ${dbConf.name};`);
|
|
115
|
-
spinner.stop();
|
|
116
115
|
}
|
|
117
116
|
await client.end();
|
|
118
117
|
}
|
|
@@ -1,54 +1,20 @@
|
|
|
1
|
-
import DreamCliLoggableSpinner from './loggable/DreamCliLoggableSpinner.js';
|
|
2
1
|
import DreamCliLoggableText from './loggable/DreamCliLoggableText.js';
|
|
3
2
|
export default class DreamCliLogger {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
permanent: false,
|
|
10
|
-
spinner: 'noise',
|
|
11
|
-
color: spinnerPrefixColor,
|
|
12
|
-
bgColor: spinnerPrefixBgColor,
|
|
13
|
-
})
|
|
14
|
-
: new DreamCliLoggableText(text, {
|
|
15
|
-
permanent,
|
|
16
|
-
logPrefix,
|
|
17
|
-
logPrefixColor: logPrefixColor || (permanent ? 'green' : 'yellow'),
|
|
18
|
-
logPrefixBgColor,
|
|
19
|
-
});
|
|
20
|
-
this.logs.push(loggable);
|
|
21
|
-
// re-render everything
|
|
22
|
-
this.render();
|
|
23
|
-
return loggable;
|
|
24
|
-
}
|
|
25
|
-
render() {
|
|
26
|
-
this.clear();
|
|
27
|
-
let skipNext = false;
|
|
28
|
-
this.logs.forEach(loggable => {
|
|
29
|
-
if (skipNext) {
|
|
30
|
-
skipNext = false;
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
loggable.render();
|
|
3
|
+
log(text, { logPrefix, logPrefixColor, logPrefixBgColor } = {}) {
|
|
4
|
+
const loggable = new DreamCliLoggableText(text, {
|
|
5
|
+
logPrefix,
|
|
6
|
+
logPrefixColor: logPrefixColor || 'green',
|
|
7
|
+
logPrefixBgColor,
|
|
34
8
|
});
|
|
9
|
+
loggable.render();
|
|
35
10
|
}
|
|
36
|
-
|
|
37
|
-
|
|
11
|
+
logStartProgress(text, { logPrefix = '✺ ┌', logPrefixColor, logPrefixBgColor } = {}) {
|
|
12
|
+
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
38
13
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
* then clear STDOUT and re-render with only
|
|
42
|
-
* the permanent logs remaining.
|
|
43
|
-
*/
|
|
44
|
-
purge() {
|
|
45
|
-
this.logs = this.logs.filter(log => log.permanent);
|
|
46
|
-
this.render();
|
|
14
|
+
logContinueProgress(text, { logPrefix = '✺ ├', logPrefixColor, logPrefixBgColor } = {}) {
|
|
15
|
+
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
47
16
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// @ts-expect-error this works fine with no args provided
|
|
51
|
-
process.stdout.clearLine?.();
|
|
52
|
-
process.stdout.cursorTo?.(0);
|
|
17
|
+
logEndProgress(text = 'complete', { logPrefix = '✺ └', logPrefixColor, logPrefixBgColor } = {}) {
|
|
18
|
+
this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
|
|
53
19
|
}
|
|
54
20
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import colorize from './colorize.js';
|
|
2
2
|
export default class DreamCliLoggable {
|
|
3
|
-
permanent;
|
|
4
3
|
logPrefix;
|
|
5
4
|
logPrefixColor;
|
|
6
5
|
logPrefixBgColor;
|
|
7
|
-
constructor({
|
|
8
|
-
this.permanent = permanent;
|
|
6
|
+
constructor({ logPrefix = '✺', logPrefixColor, logPrefixBgColor, }) {
|
|
9
7
|
this.logPrefix = logPrefix;
|
|
10
8
|
this.logPrefixColor = logPrefixColor;
|
|
11
9
|
this.logPrefixBgColor = logPrefixBgColor;
|
|
@@ -4,8 +4,8 @@ export default class DreamCliLoggableText extends DreamCliLoggable {
|
|
|
4
4
|
text;
|
|
5
5
|
color;
|
|
6
6
|
bgColor;
|
|
7
|
-
constructor(text, {
|
|
8
|
-
super({
|
|
7
|
+
constructor(text, { logPrefix, color, bgColor, logPrefixColor, logPrefixBgColor, }) {
|
|
8
|
+
super({ logPrefix });
|
|
9
9
|
this.text = text;
|
|
10
10
|
this.color = color;
|
|
11
11
|
this.bgColor = bgColor;
|
|
@@ -27,13 +27,13 @@ export default class Decorators {
|
|
|
27
27
|
*
|
|
28
28
|
* ```ts
|
|
29
29
|
* class UserSettings extends ApplicationModel {
|
|
30
|
-
* @
|
|
30
|
+
* @deco.BelongsTo('User')
|
|
31
31
|
* public user: User
|
|
32
32
|
* public userId: DreamColumn<UserSettings, 'userId'>
|
|
33
33
|
* }
|
|
34
34
|
*
|
|
35
35
|
* class User extends ApplicationModel {
|
|
36
|
-
* @
|
|
36
|
+
* @deco.HasOne('UserSettings')
|
|
37
37
|
* public userSettings: UserSettings
|
|
38
38
|
* }
|
|
39
39
|
* ```
|
|
@@ -55,12 +55,12 @@ export default class Decorators {
|
|
|
55
55
|
*
|
|
56
56
|
* ```ts
|
|
57
57
|
* class User extends ApplicationModel {
|
|
58
|
-
* @
|
|
58
|
+
* @deco.HasMany('Post')
|
|
59
59
|
* public posts: Post[]
|
|
60
60
|
* }
|
|
61
61
|
*
|
|
62
62
|
* class Post extends ApplicationModel {
|
|
63
|
-
* @
|
|
63
|
+
* @deco.BelongsTo('User')
|
|
64
64
|
* public user: User
|
|
65
65
|
* public userId: DreamColumn<Post, 'userId'>
|
|
66
66
|
* }
|
|
@@ -80,12 +80,12 @@ export default class Decorators {
|
|
|
80
80
|
*
|
|
81
81
|
* ```ts
|
|
82
82
|
* class User extends ApplicationModel {
|
|
83
|
-
* @
|
|
83
|
+
* @deco.HasOne('UserSettings')
|
|
84
84
|
* public userSettings: UserSettings
|
|
85
85
|
* }
|
|
86
86
|
*
|
|
87
87
|
* class UserSettings extends ApplicationModel {
|
|
88
|
-
* @
|
|
88
|
+
* @deco.BelongsTo('User')
|
|
89
89
|
* public user: User
|
|
90
90
|
* public userId: DreamColumn<UserSettings, 'userId'>
|
|
91
91
|
* }
|
|
@@ -108,14 +108,14 @@ export default class Decorators {
|
|
|
108
108
|
*
|
|
109
109
|
* ```ts
|
|
110
110
|
* class User {
|
|
111
|
-
* @
|
|
111
|
+
* @deco.Encrypted()
|
|
112
112
|
* // automatically sets `encryptedSsn` to the encrypted value that
|
|
113
113
|
* // `ssn` is set to in new/create/update, e.g., `await user.update({ ssn })`
|
|
114
114
|
* public ssn: string
|
|
115
115
|
*
|
|
116
116
|
* // automatically sets `myEncryptedPhone` to the encrypted value that
|
|
117
117
|
* // `phone` is set to new/create/update, e.g., `await user.update({ phone })`
|
|
118
|
-
* @
|
|
118
|
+
* @deco.Encrypted('myEncryptedPhone)
|
|
119
119
|
* public phone: string
|
|
120
120
|
* }
|
|
121
121
|
* ```
|
|
@@ -132,7 +132,7 @@ export default class Decorators {
|
|
|
132
132
|
*
|
|
133
133
|
* ```ts
|
|
134
134
|
* class Collar {
|
|
135
|
-
* @
|
|
135
|
+
* @deco.Scope({ default: true })
|
|
136
136
|
* public static hideHiddenCollars(query: Query<Collar>) {
|
|
137
137
|
* return query.where({ hidden: false })
|
|
138
138
|
* }
|
|
@@ -154,7 +154,7 @@ export default class Decorators {
|
|
|
154
154
|
*
|
|
155
155
|
* ```ts
|
|
156
156
|
* class Balloon {
|
|
157
|
-
* @
|
|
157
|
+
* @deco.Sortable({ scope: 'user' })
|
|
158
158
|
* public position: DreamColumn<Balloon, 'position'>
|
|
159
159
|
* }
|
|
160
160
|
* ```
|
|
@@ -172,7 +172,7 @@ export default class Decorators {
|
|
|
172
172
|
*
|
|
173
173
|
* ```ts
|
|
174
174
|
* class Sandbag {
|
|
175
|
-
* @
|
|
175
|
+
* @deco.Validate()
|
|
176
176
|
* public validateWeight(this: Sandbag) {
|
|
177
177
|
* if (!this.weight) return
|
|
178
178
|
*
|
|
@@ -197,7 +197,7 @@ export default class Decorators {
|
|
|
197
197
|
*
|
|
198
198
|
* ```ts
|
|
199
199
|
* class Balloon {
|
|
200
|
-
* @
|
|
200
|
+
* @deco.Validates('numericality', { min: 0, max: 100 })
|
|
201
201
|
* public volume: DreamColumn<Balloon, 'volume'>
|
|
202
202
|
* }
|
|
203
203
|
* ```
|
|
@@ -231,7 +231,7 @@ export default class Decorators {
|
|
|
231
231
|
*
|
|
232
232
|
* ```ts
|
|
233
233
|
* class BodyMeasurement {
|
|
234
|
-
* @
|
|
234
|
+
* @deco.Virtual()
|
|
235
235
|
* public get lbs() {
|
|
236
236
|
* const self: User = this
|
|
237
237
|
* return gramsToLbs(self.getAttribute('grams') ?? 0)
|
|
@@ -242,7 +242,7 @@ export default class Decorators {
|
|
|
242
242
|
* self.setAttribute('grams', lbsToGrams(lbs))
|
|
243
243
|
* }
|
|
244
244
|
*
|
|
245
|
-
* @
|
|
245
|
+
* @deco.Virtual()
|
|
246
246
|
* public get kilograms() {
|
|
247
247
|
* const self: User = this
|
|
248
248
|
* return gramsToKilograms(self.getAttribute('grams') ?? 0)
|
|
@@ -258,10 +258,10 @@ export default class Decorators {
|
|
|
258
258
|
*
|
|
259
259
|
* ```ts
|
|
260
260
|
* class User {
|
|
261
|
-
* @
|
|
261
|
+
* @deco.Virtual()
|
|
262
262
|
* public password: string
|
|
263
263
|
*
|
|
264
|
-
* @
|
|
264
|
+
* @deco.BeforeSave()
|
|
265
265
|
* public hasPassword() {
|
|
266
266
|
* this.setAttribute('hashedPassword', preferredHashingAlgorithm(this.password))
|
|
267
267
|
* }
|
|
@@ -278,7 +278,7 @@ export default class Decorators {
|
|
|
278
278
|
*
|
|
279
279
|
* ```ts
|
|
280
280
|
* class User {
|
|
281
|
-
* @
|
|
281
|
+
* @deco.BeforeCreate()
|
|
282
282
|
* public doSomething() {
|
|
283
283
|
* console.log('hi!')
|
|
284
284
|
* }
|
|
@@ -296,7 +296,7 @@ export default class Decorators {
|
|
|
296
296
|
*
|
|
297
297
|
* ```ts
|
|
298
298
|
* class User {
|
|
299
|
-
* @
|
|
299
|
+
* @deco.BeforeSave()
|
|
300
300
|
* public doSomething() {
|
|
301
301
|
* console.log('hi!')
|
|
302
302
|
* }
|
|
@@ -314,7 +314,7 @@ export default class Decorators {
|
|
|
314
314
|
*
|
|
315
315
|
* ```ts
|
|
316
316
|
* class User {
|
|
317
|
-
* @
|
|
317
|
+
* @deco.BeforeUpdate()
|
|
318
318
|
* public doSomething() {
|
|
319
319
|
* console.log('hi!')
|
|
320
320
|
* }
|
|
@@ -332,7 +332,7 @@ export default class Decorators {
|
|
|
332
332
|
*
|
|
333
333
|
* ```ts
|
|
334
334
|
* class User {
|
|
335
|
-
* @
|
|
335
|
+
* @deco.BeforeDestroy()
|
|
336
336
|
* public doSomething() {
|
|
337
337
|
* console.log('hi!')
|
|
338
338
|
* }
|
|
@@ -349,7 +349,7 @@ export default class Decorators {
|
|
|
349
349
|
*
|
|
350
350
|
* ```ts
|
|
351
351
|
* class User {
|
|
352
|
-
* @
|
|
352
|
+
* @deco.AfterCreate()
|
|
353
353
|
* public doSomething() {
|
|
354
354
|
* console.log('hi!')
|
|
355
355
|
* }
|
|
@@ -367,7 +367,7 @@ export default class Decorators {
|
|
|
367
367
|
*
|
|
368
368
|
* ```ts
|
|
369
369
|
* class User {
|
|
370
|
-
* @
|
|
370
|
+
* @deco.AfterCreateCommit()
|
|
371
371
|
* public doSomething() {
|
|
372
372
|
* console.log('hi!')
|
|
373
373
|
* }
|
|
@@ -384,7 +384,7 @@ export default class Decorators {
|
|
|
384
384
|
*
|
|
385
385
|
* ```ts
|
|
386
386
|
* class User {
|
|
387
|
-
* @
|
|
387
|
+
* @deco.AfterSave()
|
|
388
388
|
* public doSomething() {
|
|
389
389
|
* console.log('hi!')
|
|
390
390
|
* }
|
|
@@ -402,7 +402,7 @@ export default class Decorators {
|
|
|
402
402
|
*
|
|
403
403
|
* ```ts
|
|
404
404
|
* class User {
|
|
405
|
-
* @
|
|
405
|
+
* @deco.AfterSaveCommit()
|
|
406
406
|
* public doSomething() {
|
|
407
407
|
* console.log('hi!')
|
|
408
408
|
* }
|
|
@@ -420,7 +420,7 @@ export default class Decorators {
|
|
|
420
420
|
*
|
|
421
421
|
* ```ts
|
|
422
422
|
* class User {
|
|
423
|
-
* @
|
|
423
|
+
* @deco.AfterUpdate()
|
|
424
424
|
* public doSomething() {
|
|
425
425
|
* console.log('hi!')
|
|
426
426
|
* }
|
|
@@ -438,7 +438,7 @@ export default class Decorators {
|
|
|
438
438
|
*
|
|
439
439
|
* ```ts
|
|
440
440
|
* class User {
|
|
441
|
-
* @
|
|
441
|
+
* @deco.AfterUpdateCommit()
|
|
442
442
|
* public doSomething() {
|
|
443
443
|
* console.log('hi!')
|
|
444
444
|
* }
|
|
@@ -456,7 +456,7 @@ export default class Decorators {
|
|
|
456
456
|
*
|
|
457
457
|
* ```ts
|
|
458
458
|
* class User {
|
|
459
|
-
* @
|
|
459
|
+
* @deco.AfterDestroy()
|
|
460
460
|
* public doSomething() {
|
|
461
461
|
* console.log('hi!')
|
|
462
462
|
* }
|
|
@@ -474,7 +474,7 @@ export default class Decorators {
|
|
|
474
474
|
*
|
|
475
475
|
* ```ts
|
|
476
476
|
* class User {
|
|
477
|
-
* @
|
|
477
|
+
* @deco.AfterDestroyCommit()
|
|
478
478
|
* public doSomething() {
|
|
479
479
|
* console.log('hi!')
|
|
480
480
|
* }
|
|
@@ -8,13 +8,13 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
10
|
* class UserSettings extends ApplicationModel {
|
|
11
|
-
* @
|
|
11
|
+
* @deco.BelongsTo('User')
|
|
12
12
|
* public user: User
|
|
13
13
|
* public userId: DreamColumn<UserSettings, 'userId'>
|
|
14
14
|
* }
|
|
15
15
|
*
|
|
16
16
|
* class User extends ApplicationModel {
|
|
17
|
-
* @
|
|
17
|
+
* @deco.HasOne('UserSettings')
|
|
18
18
|
* public userSettings: UserSettings
|
|
19
19
|
* }
|
|
20
20
|
* ```
|
|
@@ -7,12 +7,12 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* class User extends ApplicationModel {
|
|
10
|
-
* @
|
|
10
|
+
* @deco.HasMany('Post')
|
|
11
11
|
* public posts: Post[]
|
|
12
12
|
* }
|
|
13
13
|
*
|
|
14
14
|
* class Post extends ApplicationModel {
|
|
15
|
-
* @
|
|
15
|
+
* @deco.BelongsTo('User')
|
|
16
16
|
* public user: User
|
|
17
17
|
* public userId: DreamColumn<Post, 'userId'>
|
|
18
18
|
* }
|
|
@@ -7,12 +7,12 @@ import { applyGetterAndSetter, associationPrimaryKeyAccessors, blankAssociations
|
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
9
|
* class User extends ApplicationModel {
|
|
10
|
-
* @
|
|
10
|
+
* @deco.HasOne('UserSettings')
|
|
11
11
|
* public userSettings: UserSettings
|
|
12
12
|
* }
|
|
13
13
|
*
|
|
14
14
|
* class UserSettings extends ApplicationModel {
|
|
15
|
-
* @
|
|
15
|
+
* @deco.BelongsTo('User')
|
|
16
16
|
* public user: User
|
|
17
17
|
* public userId: DreamColumn<UserSettings, 'userId'>
|
|
18
18
|
* }
|
|
@@ -51,7 +51,7 @@ function extractValidationOptionsFromArgs(type, args) {
|
|
|
51
51
|
When validating using "length", the second argument must be a number representing
|
|
52
52
|
the min length, or else an object expressing both min and max length, like so:
|
|
53
53
|
|
|
54
|
-
@
|
|
54
|
+
@deco.Validates('length', { min: 4, max: 32 })
|
|
55
55
|
`);
|
|
56
56
|
}
|
|
57
57
|
case 'requiredBelongsTo':
|
|
@@ -513,10 +513,10 @@ export default class DreamClassTransactionBuilder {
|
|
|
513
513
|
*
|
|
514
514
|
* ```ts
|
|
515
515
|
* class Post {
|
|
516
|
-
* @
|
|
516
|
+
* @deco.HasMany('LocalizedText')
|
|
517
517
|
* public localizedTexts: LocalizedText[]
|
|
518
518
|
*
|
|
519
|
-
* @
|
|
519
|
+
* @deco.HasOne('LocalizedText', {
|
|
520
520
|
* where: { locale: DreamConst.passthrough },
|
|
521
521
|
* })
|
|
522
522
|
* public currentLocalizedText: LocalizedText
|
|
@@ -761,10 +761,10 @@ export default class Query extends ConnectedToDB {
|
|
|
761
761
|
*
|
|
762
762
|
* ```ts
|
|
763
763
|
* class Post {
|
|
764
|
-
* @
|
|
764
|
+
* @deco.HasMany('LocalizedText')
|
|
765
765
|
* public localizedTexts: LocalizedText[]
|
|
766
766
|
*
|
|
767
|
-
* @
|
|
767
|
+
* @deco.HasOne('LocalizedText', {
|
|
768
768
|
* on: { locale: DreamConst.passthrough },
|
|
769
769
|
* })
|
|
770
770
|
* public currentLocalizedText: LocalizedText
|
|
@@ -35,7 +35,7 @@ export default function generateDreamContent({ fullyQualifiedModelName, columnsW
|
|
|
35
35
|
case 'belongs_to':
|
|
36
36
|
modelImportStatements.push(associationImportStatement);
|
|
37
37
|
return `
|
|
38
|
-
@
|
|
38
|
+
@deco.BelongsTo('${fullyQualifiedAssociatedModelName}'${descriptors.includes('optional') ? ', { optional: true }' : ''})
|
|
39
39
|
public ${associationName}: ${associationModelName}${descriptors.includes('optional') ? ' | null' : ''}
|
|
40
40
|
public ${associationName}Id: DreamColumn<${modelClassName}, '${associationName}Id'>
|
|
41
41
|
`;
|
|
@@ -73,7 +73,7 @@ public ${camelize(attributeName)}: ${getAttributeType(attribute, modelClassName)
|
|
|
73
73
|
return `\
|
|
74
74
|
import { ${uniq(dreamImports).join(', ')} } from '@rvoh/dream'${uniq(modelImportStatements).join('')}
|
|
75
75
|
|
|
76
|
-
const
|
|
76
|
+
const deco = new Decorators<InstanceType<typeof ${modelClassName}>>()
|
|
77
77
|
|
|
78
78
|
${isSTI ? `\n@STI(${parentModelClassName})` : ''}
|
|
79
79
|
export default class ${modelClassName} extends ${isSTI ? parentModelClassName : 'ApplicationModel'} {
|
|
@@ -86,14 +86,14 @@ function migratedActionPastTense(mode) {
|
|
|
86
86
|
function logResults(results, mode) {
|
|
87
87
|
results?.forEach(it => {
|
|
88
88
|
if (it.status === 'Success') {
|
|
89
|
-
DreamCLI.logger.
|
|
90
|
-
` migration "${it.migrationName}" was ${migratedActionPastTense(mode)} successfully`, {
|
|
89
|
+
DreamCLI.logger.logContinueProgress(colorize(`[db]`, { color: 'cyan' }) +
|
|
90
|
+
` migration "${it.migrationName}" was ${migratedActionPastTense(mode)} successfully`, { logPrefixColor: 'cyan' });
|
|
91
91
|
}
|
|
92
92
|
else if (it.status === 'Error') {
|
|
93
|
-
DreamCLI.logger.
|
|
94
|
-
DreamCLI.logger.
|
|
93
|
+
DreamCLI.logger.logContinueProgress(JSON.stringify(it, null, 2));
|
|
94
|
+
DreamCLI.logger.logContinueProgress(colorize(`failed to ${migratedActionCurrentTense(mode)} migration "${it.migrationName}"`, {
|
|
95
95
|
color: 'redBright',
|
|
96
|
-
})
|
|
96
|
+
}));
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
}
|
|
@@ -3,15 +3,41 @@ export default function sspawn(command, opts = {}) {
|
|
|
3
3
|
return new Promise((accept, reject) => {
|
|
4
4
|
ssspawn(command, opts).on('close', code => {
|
|
5
5
|
if (code !== 0)
|
|
6
|
-
reject(
|
|
6
|
+
reject(code);
|
|
7
7
|
accept({});
|
|
8
8
|
});
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
export function ssspawn(command, opts = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const proc = spawn(command, {
|
|
13
|
+
// even though github security scans want to remove this,
|
|
14
|
+
// it is necessary to allow the cli util to run as the current
|
|
15
|
+
// user. This is only done to provision a new psychic application,
|
|
16
|
+
// so it is safe from unknown execution contexts.
|
|
14
17
|
shell: true,
|
|
15
18
|
...opts,
|
|
16
19
|
});
|
|
20
|
+
// NOTE: adding this stdout spy so that
|
|
21
|
+
// when this cli utility runs node commands,
|
|
22
|
+
// it can properly hijack the stdout from the command
|
|
23
|
+
proc.stdout.on('data', chunk => {
|
|
24
|
+
const txt = chunk?.toString()?.trim();
|
|
25
|
+
if (typeof txt !== 'string' || !txt)
|
|
26
|
+
return;
|
|
27
|
+
if (opts?.onStdout) {
|
|
28
|
+
opts?.onStdout?.(txt);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
console.log(txt);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
proc.stdout.on('error', err => {
|
|
35
|
+
console.log('sspawn error!');
|
|
36
|
+
console.error(err);
|
|
37
|
+
});
|
|
38
|
+
proc.on('error', err => {
|
|
39
|
+
console.log('sspawn error!');
|
|
40
|
+
console.error(err);
|
|
41
|
+
});
|
|
42
|
+
return proc;
|
|
17
43
|
}
|
|
@@ -13,12 +13,12 @@ import { isSerializable } from './shared.js';
|
|
|
13
13
|
*
|
|
14
14
|
* ```ts
|
|
15
15
|
* class User extends ApplicationModel {
|
|
16
|
-
* @
|
|
16
|
+
* @deco.HasOne('Settings')
|
|
17
17
|
* public settings: Settings
|
|
18
18
|
* }
|
|
19
19
|
*
|
|
20
20
|
* class Post extends ApplicationModel {
|
|
21
|
-
* @
|
|
21
|
+
* @deco.BelongsTo('User')
|
|
22
22
|
* public user: User
|
|
23
23
|
* }
|
|
24
24
|
*
|