@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.
Files changed (221) hide show
  1. package/README.md +17 -17
  2. package/dist/cjs/src/Dream.js +15 -15
  3. package/dist/cjs/src/bin/helpers/sync.js +9 -2
  4. package/dist/cjs/src/bin/index.js +18 -19
  5. package/dist/cjs/src/cli/logger/DreamCliLogger.js +12 -46
  6. package/dist/cjs/src/cli/logger/loggable/DreamCliLoggable.js +1 -3
  7. package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableText.js +2 -2
  8. package/dist/cjs/src/decorators/Decorators.js +28 -28
  9. package/dist/cjs/src/decorators/field/association/BelongsTo.js +2 -2
  10. package/dist/cjs/src/decorators/field/association/HasMany.js +2 -2
  11. package/dist/cjs/src/decorators/field/association/HasOne.js +2 -2
  12. package/dist/cjs/src/decorators/field/lifecycle/AfterCreateCommit.js +1 -1
  13. package/dist/cjs/src/decorators/field/lifecycle/AfterDestroyCommit.js +1 -1
  14. package/dist/cjs/src/decorators/field/lifecycle/AfterSaveCommit.js +1 -1
  15. package/dist/cjs/src/decorators/field/lifecycle/AfterUpdateCommit.js +1 -1
  16. package/dist/cjs/src/decorators/field/validation/Validates.js +1 -1
  17. package/dist/cjs/src/dream/DreamClassTransactionBuilder.js +2 -2
  18. package/dist/cjs/src/dream/Query.js +2 -2
  19. package/dist/cjs/src/helpers/cli/generateDreamContent.js +2 -2
  20. package/dist/cjs/src/helpers/db/runMigration.js +5 -5
  21. package/dist/cjs/src/helpers/sspawn.js +29 -3
  22. package/dist/cjs/src/serializer/decorators/associations/RendersMany.js +2 -2
  23. package/dist/cjs/src/serializer/decorators/associations/RendersOne.js +2 -2
  24. package/dist/esm/src/Dream.js +15 -15
  25. package/dist/esm/src/bin/helpers/sync.js +9 -2
  26. package/dist/esm/src/bin/index.js +18 -19
  27. package/dist/esm/src/cli/logger/DreamCliLogger.js +12 -46
  28. package/dist/esm/src/cli/logger/loggable/DreamCliLoggable.js +1 -3
  29. package/dist/esm/src/cli/logger/loggable/DreamCliLoggableText.js +2 -2
  30. package/dist/esm/src/decorators/Decorators.js +28 -28
  31. package/dist/esm/src/decorators/field/association/BelongsTo.js +2 -2
  32. package/dist/esm/src/decorators/field/association/HasMany.js +2 -2
  33. package/dist/esm/src/decorators/field/association/HasOne.js +2 -2
  34. package/dist/esm/src/decorators/field/lifecycle/AfterCreateCommit.js +1 -1
  35. package/dist/esm/src/decorators/field/lifecycle/AfterDestroyCommit.js +1 -1
  36. package/dist/esm/src/decorators/field/lifecycle/AfterSaveCommit.js +1 -1
  37. package/dist/esm/src/decorators/field/lifecycle/AfterUpdateCommit.js +1 -1
  38. package/dist/esm/src/decorators/field/validation/Validates.js +1 -1
  39. package/dist/esm/src/dream/DreamClassTransactionBuilder.js +2 -2
  40. package/dist/esm/src/dream/Query.js +2 -2
  41. package/dist/esm/src/helpers/cli/generateDreamContent.js +2 -2
  42. package/dist/esm/src/helpers/db/runMigration.js +5 -5
  43. package/dist/esm/src/helpers/sspawn.js +29 -3
  44. package/dist/esm/src/serializer/decorators/associations/RendersMany.js +2 -2
  45. package/dist/esm/src/serializer/decorators/associations/RendersOne.js +2 -2
  46. package/dist/types/src/Dream.d.ts +15 -15
  47. package/dist/types/src/cli/logger/DreamCliLogger.d.ts +4 -8
  48. package/dist/types/src/cli/logger/loggable/DreamCliLoggable.d.ts +1 -3
  49. package/dist/types/src/cli/logger/loggable/DreamCliLoggableText.d.ts +1 -2
  50. package/dist/types/src/decorators/Decorators.d.ts +22 -22
  51. package/dist/types/src/decorators/field/lifecycle/AfterCreateCommit.d.ts +1 -1
  52. package/dist/types/src/decorators/field/lifecycle/AfterDestroyCommit.d.ts +1 -1
  53. package/dist/types/src/decorators/field/lifecycle/AfterSaveCommit.d.ts +1 -1
  54. package/dist/types/src/decorators/field/lifecycle/AfterUpdateCommit.d.ts +1 -1
  55. package/dist/types/src/dream/DreamClassTransactionBuilder.d.ts +2 -2
  56. package/dist/types/src/dream/Query.d.ts +2 -2
  57. package/dist/types/src/helpers/sspawn.d.ts +6 -2
  58. package/dist/types/src/serializer/decorators/associations/RendersMany.d.ts +2 -2
  59. package/dist/types/src/serializer/decorators/associations/RendersOne.d.ts +2 -2
  60. package/dist/types/src/types/logger.d.ts +1 -5
  61. package/docs/classes/Benchmark.html +2 -2
  62. package/docs/classes/CalendarDate.html +2 -2
  63. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  64. package/docs/classes/Decorators.html +38 -38
  65. package/docs/classes/Dream.html +138 -138
  66. package/docs/classes/DreamApplication.html +4 -4
  67. package/docs/classes/DreamBin.html +2 -2
  68. package/docs/classes/DreamCLI.html +4 -4
  69. package/docs/classes/DreamDbConnection.html +2 -2
  70. package/docs/classes/DreamGlam.html +2 -2
  71. package/docs/classes/DreamImporter.html +2 -2
  72. package/docs/classes/DreamMigrationHelpers.html +7 -7
  73. package/docs/classes/DreamSerializer.html +2 -2
  74. package/docs/classes/DreamTransaction.html +2 -2
  75. package/docs/classes/Encrypt.html +2 -2
  76. package/docs/classes/Env.html +2 -2
  77. package/docs/classes/GlobalNameNotSet.html +3 -3
  78. package/docs/classes/NonLoadedAssociation.html +3 -3
  79. package/docs/classes/Query.html +51 -51
  80. package/docs/classes/Range.html +2 -2
  81. package/docs/classes/RecordNotFound.html +3 -3
  82. package/docs/classes/ValidationError.html +3 -3
  83. package/docs/functions/Attribute.html +1 -1
  84. package/docs/functions/RendersMany.html +2 -2
  85. package/docs/functions/RendersOne.html +2 -2
  86. package/docs/functions/ReplicaSafe.html +1 -1
  87. package/docs/functions/STI.html +1 -1
  88. package/docs/functions/SoftDelete.html +1 -1
  89. package/docs/functions/camelize.html +1 -1
  90. package/docs/functions/capitalize.html +1 -1
  91. package/docs/functions/closeAllDbConnections.html +1 -1
  92. package/docs/functions/compact.html +1 -1
  93. package/docs/functions/db.html +1 -1
  94. package/docs/functions/debug.html +1 -1
  95. package/docs/functions/dreamDbConnections.html +1 -1
  96. package/docs/functions/dreamPath.html +1 -1
  97. package/docs/functions/generateDream.html +1 -1
  98. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  99. package/docs/functions/hyphenize.html +1 -1
  100. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
  101. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  102. package/docs/functions/isEmpty.html +1 -1
  103. package/docs/functions/loadRepl.html +1 -1
  104. package/docs/functions/lookupClassByGlobalName.html +1 -1
  105. package/docs/functions/pascalize.html +1 -1
  106. package/docs/functions/pgErrorType.html +1 -1
  107. package/docs/functions/range-1.html +1 -1
  108. package/docs/functions/relativeDreamPath.html +1 -1
  109. package/docs/functions/round.html +1 -1
  110. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  111. package/docs/functions/sharedPathPrefix.html +1 -1
  112. package/docs/functions/snakeify.html +1 -1
  113. package/docs/functions/sort.html +1 -1
  114. package/docs/functions/sortBy.html +1 -1
  115. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  116. package/docs/functions/uncapitalize.html +1 -1
  117. package/docs/functions/uniq.html +1 -1
  118. package/docs/functions/validateColumn.html +1 -1
  119. package/docs/functions/validateTable.html +1 -1
  120. package/docs/index.html +5 -5
  121. package/docs/interfaces/AttributeStatement.html +2 -2
  122. package/docs/interfaces/DecoratorContext.html +2 -2
  123. package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
  124. package/docs/interfaces/DreamApplicationOpts.html +2 -2
  125. package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
  126. package/docs/interfaces/EncryptOptions.html +2 -2
  127. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  128. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  129. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  130. package/docs/types/Camelized.html +1 -1
  131. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  132. package/docs/types/DateTime.html +1 -1
  133. package/docs/types/DreamAssociationMetadata.html +1 -1
  134. package/docs/types/DreamAttributes.html +1 -1
  135. package/docs/types/DreamClassColumn.html +1 -1
  136. package/docs/types/DreamColumn.html +1 -1
  137. package/docs/types/DreamColumnNames.html +1 -1
  138. package/docs/types/DreamLogLevel.html +1 -1
  139. package/docs/types/DreamLogger.html +1 -1
  140. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  141. package/docs/types/DreamParamSafeAttributes.html +1 -1
  142. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  143. package/docs/types/DreamSerializerKey.html +1 -1
  144. package/docs/types/DreamSerializers.html +1 -1
  145. package/docs/types/DreamTableSchema.html +1 -1
  146. package/docs/types/DreamVirtualColumns.html +1 -1
  147. package/docs/types/EncryptAlgorithm.html +1 -1
  148. package/docs/types/Hyphenized.html +1 -1
  149. package/docs/types/IdType.html +1 -1
  150. package/docs/types/OpenapiAllTypes.html +1 -1
  151. package/docs/types/OpenapiFormats.html +1 -1
  152. package/docs/types/OpenapiNumberFormats.html +1 -1
  153. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  154. package/docs/types/OpenapiSchemaArray.html +1 -1
  155. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  156. package/docs/types/OpenapiSchemaBase.html +1 -1
  157. package/docs/types/OpenapiSchemaBody.html +1 -1
  158. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  159. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  160. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  161. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  162. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  163. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  164. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  165. package/docs/types/OpenapiSchemaInteger.html +1 -1
  166. package/docs/types/OpenapiSchemaNull.html +1 -1
  167. package/docs/types/OpenapiSchemaNumber.html +1 -1
  168. package/docs/types/OpenapiSchemaObject.html +1 -1
  169. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  170. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  171. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  172. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  173. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  174. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  175. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  176. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  177. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  178. package/docs/types/OpenapiSchemaPartialSegment.html +1 -1
  179. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  180. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  181. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  182. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  183. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  184. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  185. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  186. package/docs/types/OpenapiSchemaString.html +1 -1
  187. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  188. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  189. package/docs/types/OpenapiTypeField.html +1 -1
  190. package/docs/types/Pascalized.html +1 -1
  191. package/docs/types/PrimaryKeyType.html +1 -1
  192. package/docs/types/RoundingPrecision.html +1 -1
  193. package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
  194. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
  195. package/docs/types/SerializableDreamOrViewModel.html +1 -1
  196. package/docs/types/SerializableTypes.html +1 -1
  197. package/docs/types/Snakeified.html +1 -1
  198. package/docs/types/Timestamp.html +1 -1
  199. package/docs/types/UpdateableAssociationProperties.html +1 -1
  200. package/docs/types/UpdateableProperties.html +1 -1
  201. package/docs/types/ValidationType.html +1 -1
  202. package/docs/types/ViewModelSerializerKey.html +1 -1
  203. package/docs/types/WhereStatementForDream.html +1 -1
  204. package/docs/types/WhereStatementForDreamClass.html +1 -1
  205. package/docs/variables/DateTime-1.html +1 -1
  206. package/docs/variables/DreamConst.html +1 -1
  207. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  208. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  209. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  210. package/docs/variables/ops.html +1 -1
  211. package/docs/variables/primaryKeyTypes.html +1 -1
  212. package/package.json +1 -2
  213. package/dist/cjs/src/cli/logger/helpers/createSpinner.js +0 -14
  214. package/dist/cjs/src/cli/logger/loggable/DreamCliLoggableSpinner.js +0 -31
  215. package/dist/cjs/src/cli/logger/loggable/spinners.js +0 -1185
  216. package/dist/esm/src/cli/logger/helpers/createSpinner.js +0 -11
  217. package/dist/esm/src/cli/logger/loggable/DreamCliLoggableSpinner.js +0 -28
  218. package/dist/esm/src/cli/logger/loggable/spinners.js +0 -1183
  219. package/dist/types/src/cli/logger/helpers/createSpinner.d.ts +0 -2
  220. package/dist/types/src/cli/logger/loggable/DreamCliLoggableSpinner.d.ts +0 -21
  221. 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
- const spinner = DreamCLI.logger.log(`creating ${primaryDbConf.name}...`, { spinner: true });
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
- const spinner = DreamCLI.logger.log(`dropping ${primaryDbConf.name}...`, { spinner: true });
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
- const spinner = DreamCLI.logger.log(`migrating ${primaryDbConf.name}...`, { spinner: true });
62
+ DreamCLI.logger.logStartProgress(`migrating ${primaryDbConf.name}...`);
59
63
  await runMigration({ mode: 'migrate' });
60
64
  await this.duplicateDatabase();
61
- spinner.stop();
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
- const spinner = DreamCLI.logger.log(`rolling back ${primaryDbConf.name}...`, { spinner: true });
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
- spinner.stop();
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.log('generating docs...');
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
- const spinner = DreamCLI.logger.log(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`, {
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
- const spinner = DreamCLI.logger.log(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`, {
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
- logs = [];
5
- log(text, { permanent = false, spinner = false, logPrefix, logPrefixColor, logPrefixBgColor, spinnerPrefixColor = 'greenBright', spinnerPrefixBgColor, } = {}) {
6
- const loggable = spinner
7
- ? new DreamCliLoggableSpinner({
8
- text,
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
- get spinners() {
37
- return this.logs.filter(log => log instanceof DreamCliLoggableSpinner);
11
+ logStartProgress(text, { logPrefix = '✺ ┌', logPrefixColor, logPrefixBgColor } = {}) {
12
+ this.log(text, { logPrefix, logPrefixColor, logPrefixBgColor });
38
13
  }
39
- /*
40
- * remove all logs that are not marked permanent,
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
- clear() {
49
- console.clear();
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({ permanent, logPrefix = '✺', logPrefixColor, logPrefixBgColor, }) {
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, { permanent, logPrefix, color, bgColor, logPrefixColor, logPrefixBgColor, }) {
8
- super({ permanent, logPrefix });
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
- * @Deco.BelongsTo('User')
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
- * @Deco.HasOne('UserSettings')
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
- * @Deco.HasMany('Post')
58
+ * @deco.HasMany('Post')
59
59
  * public posts: Post[]
60
60
  * }
61
61
  *
62
62
  * class Post extends ApplicationModel {
63
- * @Deco.BelongsTo('User')
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
- * @Deco.HasOne('UserSettings')
83
+ * @deco.HasOne('UserSettings')
84
84
  * public userSettings: UserSettings
85
85
  * }
86
86
  *
87
87
  * class UserSettings extends ApplicationModel {
88
- * @Deco.BelongsTo('User')
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
- * @Deco.Encrypted()
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
- * @Deco.Encrypted('myEncryptedPhone)
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
- * @Deco.Scope({ default: true })
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
- * @Deco.Sortable({ scope: 'user' })
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
- * @Deco.Validate()
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
- * @Deco.Validates('numericality', { min: 0, max: 100 })
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
- * @Deco.Virtual()
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
- * @Deco.Virtual()
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
- * @Deco.Virtual()
261
+ * @deco.Virtual()
262
262
  * public password: string
263
263
  *
264
- * @Deco.BeforeSave()
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
- * @Deco.BeforeCreate()
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
- * @Deco.BeforeSave()
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
- * @Deco.BeforeUpdate()
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
- * @Deco.BeforeDestroy()
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
- * @Deco.AfterCreate()
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
- * @Deco.AfterCreateCommit()
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
- * @Deco.AfterSave()
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
- * @Deco.AfterSaveCommit()
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
- * @Deco.AfterUpdate()
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
- * @Deco.AfterUpdateCommit()
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
- * @Deco.AfterDestroy()
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
- * @Deco.AfterDestroyCommit()
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
- * @Deco.BelongsTo('User')
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
- * @Deco.HasOne('UserSettings')
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
- * @Deco.HasMany('Post')
10
+ * @deco.HasMany('Post')
11
11
  * public posts: Post[]
12
12
  * }
13
13
  *
14
14
  * class Post extends ApplicationModel {
15
- * @Deco.BelongsTo('User')
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
- * @Deco.HasOne('UserSettings')
10
+ * @deco.HasOne('UserSettings')
11
11
  * public userSettings: UserSettings
12
12
  * }
13
13
  *
14
14
  * class UserSettings extends ApplicationModel {
15
- * @Deco.BelongsTo('User')
15
+ * @deco.BelongsTo('User')
16
16
  * public user: User
17
17
  * public userId: DreamColumn<UserSettings, 'userId'>
18
18
  * }
@@ -8,7 +8,7 @@ import { blankHooksFactory } from './shared.js';
8
8
  * is complete.
9
9
  *
10
10
  * class User extends ApplicationModel {
11
- * @Deco.AfterCreateCommit()
11
+ * @deco.AfterCreateCommit()
12
12
  * public doSomething() {
13
13
  * ...
14
14
  * }
@@ -8,7 +8,7 @@ import { blankHooksFactory } from './shared.js';
8
8
  * is complete.
9
9
  *
10
10
  * class User extends ApplicationModel {
11
- * @Deco.AfterDestroyCommit()
11
+ * @deco.AfterDestroyCommit()
12
12
  * public doSomething() {
13
13
  * ...
14
14
  * }
@@ -8,7 +8,7 @@ import { blankHooksFactory } from './shared.js';
8
8
  * is complete.
9
9
  *
10
10
  * class User extends ApplicationModel {
11
- * @Deco.AfterSaveCommit()
11
+ * @deco.AfterSaveCommit()
12
12
  * public doSomething() {
13
13
  * ...
14
14
  * }
@@ -8,7 +8,7 @@ import { blankHooksFactory } from './shared.js';
8
8
  * is complete.
9
9
  *
10
10
  * class User extends ApplicationModel {
11
- * @Deco.AfterUpdateCommit()
11
+ * @deco.AfterUpdateCommit()
12
12
  * public doSomething() {
13
13
  * ...
14
14
  * }
@@ -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
- @Deco.Validates('length', { min: 4, max: 32 })
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
- * @Deco.HasMany('LocalizedText')
516
+ * @deco.HasMany('LocalizedText')
517
517
  * public localizedTexts: LocalizedText[]
518
518
  *
519
- * @Deco.HasOne('LocalizedText', {
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
- * @Deco.HasMany('LocalizedText')
764
+ * @deco.HasMany('LocalizedText')
765
765
  * public localizedTexts: LocalizedText[]
766
766
  *
767
- * @Deco.HasOne('LocalizedText', {
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
- @Deco.BelongsTo('${fullyQualifiedAssociatedModelName}'${descriptors.includes('optional') ? ', { optional: true }' : ''})
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 Deco = new Decorators<InstanceType<typeof ${modelClassName}>>()
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.log(colorize(`[db]`, { color: 'cyan' }) +
90
- ` migration "${it.migrationName}" was ${migratedActionPastTense(mode)} successfully`, { permanent: true, logPrefix: '├', logPrefixColor: 'cyan' });
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.log(JSON.stringify(it, null, 2), { permanent: true });
94
- DreamCLI.logger.log(colorize(`failed to ${migratedActionCurrentTense(mode)} migration "${it.migrationName}"`, {
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
- }), { permanent: true });
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(new Error(code?.toString()));
6
+ reject(code);
7
7
  accept({});
8
8
  });
9
9
  });
10
10
  }
11
11
  export function ssspawn(command, opts = {}) {
12
- return spawn(command, {
13
- stdio: 'inherit',
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
- * @Deco.HasOne('Settings')
16
+ * @deco.HasOne('Settings')
17
17
  * public settings: Settings
18
18
  * }
19
19
  *
20
20
  * class Post extends ApplicationModel {
21
- * @Deco.BelongsTo('User')
21
+ * @deco.BelongsTo('User')
22
22
  * public user: User
23
23
  * }
24
24
  *