@rvoh/dream 0.32.1 → 0.32.3

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 (186) hide show
  1. package/dist/cjs/src/bin/helpers/sync.js +0 -1
  2. package/dist/cjs/src/bin/index.js +2 -2
  3. package/dist/cjs/src/cli/index.js +2 -13
  4. package/dist/cjs/src/db/index.js +0 -1
  5. package/dist/cjs/src/dream/Query.js +4 -3
  6. package/dist/cjs/src/dream/internal/reload.js +1 -1
  7. package/dist/cjs/src/dream-application/index.js +10 -0
  8. package/dist/cjs/src/helpers/db/dropDb.js +1 -1
  9. package/dist/cjs/src/helpers/loadRepl.js +26 -2
  10. package/dist/cjs/src/helpers/sspawn.js +2 -2
  11. package/dist/esm/src/bin/helpers/sync.js +0 -1
  12. package/dist/esm/src/bin/index.js +2 -2
  13. package/dist/esm/src/cli/index.js +2 -13
  14. package/dist/esm/src/db/index.js +0 -1
  15. package/dist/esm/src/dream/Query.js +4 -3
  16. package/dist/esm/src/dream/internal/reload.js +1 -1
  17. package/dist/esm/src/dream-application/index.js +10 -0
  18. package/dist/esm/src/helpers/db/dropDb.js +1 -1
  19. package/dist/esm/src/helpers/loadRepl.js +26 -2
  20. package/dist/esm/src/helpers/sspawn.js +2 -2
  21. package/dist/types/src/bin/helpers/sync.d.ts +0 -1
  22. package/dist/types/src/bin/index.d.ts +0 -1
  23. package/dist/types/src/cli/index.d.ts +3 -1
  24. package/dist/types/src/db/index.d.ts +0 -1
  25. package/dist/types/src/dream/Query.d.ts +1 -1
  26. package/dist/types/src/dream-application/index.d.ts +3 -0
  27. package/dist/types/src/helpers/loadRepl.d.ts +0 -1
  28. package/dist/types/src/helpers/sspawn.d.ts +4 -3
  29. package/docs/assets/search.js +1 -1
  30. package/docs/classes/Benchmark.html +2 -2
  31. package/docs/classes/CalendarDate.html +2 -2
  32. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  33. package/docs/classes/Decorators.html +19 -19
  34. package/docs/classes/Dream.html +126 -126
  35. package/docs/classes/DreamApplication.html +6 -4
  36. package/docs/classes/DreamBin.html +2 -2
  37. package/docs/classes/DreamCLI.html +4 -4
  38. package/docs/classes/DreamDbConnection.html +2 -2
  39. package/docs/classes/DreamGlam.html +2 -2
  40. package/docs/classes/DreamImporter.html +2 -2
  41. package/docs/classes/DreamMigrationHelpers.html +7 -7
  42. package/docs/classes/DreamSerializer.html +2 -2
  43. package/docs/classes/DreamTransaction.html +2 -2
  44. package/docs/classes/Encrypt.html +2 -2
  45. package/docs/classes/Env.html +2 -2
  46. package/docs/classes/GlobalNameNotSet.html +3 -3
  47. package/docs/classes/NonLoadedAssociation.html +3 -3
  48. package/docs/classes/Query.html +50 -50
  49. package/docs/classes/Range.html +2 -2
  50. package/docs/classes/RecordNotFound.html +3 -3
  51. package/docs/classes/ValidationError.html +3 -3
  52. package/docs/functions/Attribute.html +1 -1
  53. package/docs/functions/RendersMany.html +1 -1
  54. package/docs/functions/RendersOne.html +1 -1
  55. package/docs/functions/ReplicaSafe.html +1 -1
  56. package/docs/functions/STI.html +1 -1
  57. package/docs/functions/SoftDelete.html +1 -1
  58. package/docs/functions/camelize.html +1 -1
  59. package/docs/functions/capitalize.html +1 -1
  60. package/docs/functions/closeAllDbConnections.html +1 -1
  61. package/docs/functions/compact.html +1 -1
  62. package/docs/functions/db.html +1 -1
  63. package/docs/functions/debug.html +1 -1
  64. package/docs/functions/dreamDbConnections.html +1 -1
  65. package/docs/functions/dreamPath.html +1 -1
  66. package/docs/functions/generateDream.html +1 -1
  67. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  68. package/docs/functions/hyphenize.html +1 -1
  69. package/docs/functions/inferSerializerFromDreamClassOrViewModelClass.html +1 -1
  70. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  71. package/docs/functions/isEmpty.html +1 -1
  72. package/docs/functions/loadRepl.html +1 -1
  73. package/docs/functions/lookupClassByGlobalName.html +1 -1
  74. package/docs/functions/pascalize.html +1 -1
  75. package/docs/functions/pgErrorType.html +1 -1
  76. package/docs/functions/range-1.html +1 -1
  77. package/docs/functions/relativeDreamPath.html +1 -1
  78. package/docs/functions/round.html +1 -1
  79. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  80. package/docs/functions/sharedPathPrefix.html +1 -1
  81. package/docs/functions/snakeify.html +1 -1
  82. package/docs/functions/sort.html +1 -1
  83. package/docs/functions/sortBy.html +1 -1
  84. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  85. package/docs/functions/uncapitalize.html +1 -1
  86. package/docs/functions/uniq.html +1 -1
  87. package/docs/functions/validateColumn.html +1 -1
  88. package/docs/functions/validateTable.html +1 -1
  89. package/docs/interfaces/AttributeStatement.html +2 -2
  90. package/docs/interfaces/DecoratorContext.html +2 -2
  91. package/docs/interfaces/DreamApplicationInitOptions.html +2 -2
  92. package/docs/interfaces/DreamApplicationOpts.html +2 -2
  93. package/docs/interfaces/DreamSerializerAssociationStatement.html +2 -2
  94. package/docs/interfaces/EncryptOptions.html +2 -2
  95. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  96. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  97. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  98. package/docs/types/Camelized.html +1 -1
  99. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  100. package/docs/types/DateTime.html +1 -1
  101. package/docs/types/DreamAssociationMetadata.html +1 -1
  102. package/docs/types/DreamAttributes.html +1 -1
  103. package/docs/types/DreamClassColumn.html +1 -1
  104. package/docs/types/DreamColumn.html +1 -1
  105. package/docs/types/DreamColumnNames.html +1 -1
  106. package/docs/types/DreamLogLevel.html +1 -1
  107. package/docs/types/DreamLogger.html +1 -1
  108. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  109. package/docs/types/DreamParamSafeAttributes.html +1 -1
  110. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  111. package/docs/types/DreamSerializerKey.html +1 -1
  112. package/docs/types/DreamSerializers.html +1 -1
  113. package/docs/types/DreamTableSchema.html +1 -1
  114. package/docs/types/DreamVirtualColumns.html +1 -1
  115. package/docs/types/EncryptAlgorithm.html +1 -1
  116. package/docs/types/Hyphenized.html +1 -1
  117. package/docs/types/IdType.html +1 -1
  118. package/docs/types/OpenapiAllTypes.html +1 -1
  119. package/docs/types/OpenapiFormats.html +1 -1
  120. package/docs/types/OpenapiNumberFormats.html +1 -1
  121. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  122. package/docs/types/OpenapiSchemaArray.html +1 -1
  123. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  124. package/docs/types/OpenapiSchemaBase.html +1 -1
  125. package/docs/types/OpenapiSchemaBody.html +1 -1
  126. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  127. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  128. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  129. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  130. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  131. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  132. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  133. package/docs/types/OpenapiSchemaInteger.html +1 -1
  134. package/docs/types/OpenapiSchemaNull.html +1 -1
  135. package/docs/types/OpenapiSchemaNumber.html +1 -1
  136. package/docs/types/OpenapiSchemaObject.html +1 -1
  137. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  138. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  139. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  140. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  141. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  142. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  143. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  144. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  145. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  146. package/docs/types/OpenapiSchemaPartialSegment.html +1 -1
  147. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  148. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  149. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  150. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  151. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  152. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  153. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  154. package/docs/types/OpenapiSchemaString.html +1 -1
  155. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  156. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  157. package/docs/types/OpenapiTypeField.html +1 -1
  158. package/docs/types/Pascalized.html +1 -1
  159. package/docs/types/PrimaryKeyType.html +1 -1
  160. package/docs/types/RoundingPrecision.html +1 -1
  161. package/docs/types/SerializableClassOrSerializerCallback.html +1 -1
  162. package/docs/types/SerializableDreamClassOrViewModelClass.html +1 -1
  163. package/docs/types/SerializableDreamOrViewModel.html +1 -1
  164. package/docs/types/SerializableTypes.html +1 -1
  165. package/docs/types/Snakeified.html +1 -1
  166. package/docs/types/Timestamp.html +1 -1
  167. package/docs/types/UpdateableAssociationProperties.html +1 -1
  168. package/docs/types/UpdateableProperties.html +1 -1
  169. package/docs/types/ValidationType.html +1 -1
  170. package/docs/types/ViewModelSerializerKey.html +1 -1
  171. package/docs/types/WhereStatementForDream.html +1 -1
  172. package/docs/types/WhereStatementForDreamClass.html +1 -1
  173. package/docs/variables/DateTime-1.html +1 -1
  174. package/docs/variables/DreamConst.html +1 -1
  175. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  176. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  177. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  178. package/docs/variables/ops.html +1 -1
  179. package/docs/variables/primaryKeyTypes.html +1 -1
  180. package/package.json +6 -7
  181. package/dist/cjs/src/helpers/dreamOrPsychicCoreDevelopment.js +0 -10
  182. package/dist/cjs/src/helpers/loadEnv.js +0 -37
  183. package/dist/esm/src/helpers/dreamOrPsychicCoreDevelopment.js +0 -7
  184. package/dist/esm/src/helpers/loadEnv.js +0 -35
  185. package/dist/types/src/helpers/dreamOrPsychicCoreDevelopment.d.ts +0 -1
  186. package/dist/types/src/helpers/loadEnv.d.ts +0 -1
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = writeSyncFile;
4
- require("../../helpers/loadEnv.js");
5
4
  const fs = require("fs/promises");
6
5
  const path = require("path");
7
6
  const index_js_1 = require("../../cli/index.js");
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_js_1 = require("../cli/index.js");
4
4
  const ConnectionConfRetriever_js_1 = require("../db/ConnectionConfRetriever.js");
5
5
  const index_js_2 = require("../dream-application/index.js");
6
+ const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
7
  const SchemaBuilder_js_1 = require("../helpers/cli/SchemaBuilder.js");
7
8
  const generateDream_js_1 = require("../helpers/cli/generateDream.js");
8
9
  const generateMigration_js_1 = require("../helpers/cli/generateMigration.js");
@@ -10,7 +11,6 @@ const createDb_js_1 = require("../helpers/db/createDb.js");
10
11
  const dropDb_js_1 = require("../helpers/db/dropDb.js");
11
12
  const loadPgClient_js_1 = require("../helpers/db/loadPgClient.js");
12
13
  const runMigration_js_1 = require("../helpers/db/runMigration.js");
13
- require("../helpers/loadEnv.js");
14
14
  const sspawn_js_1 = require("../helpers/sspawn.js");
15
15
  const sync_js_1 = require("./helpers/sync.js");
16
16
  class DreamBin {
@@ -102,7 +102,7 @@ class DreamBin {
102
102
  const connectionRetriever = new ConnectionConfRetriever_js_1.default();
103
103
  const dbConf = connectionRetriever.getConnectionConf('primary');
104
104
  const client = await (0, loadPgClient_js_1.default)({ useSystemDb: true });
105
- if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
105
+ if (EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')) {
106
106
  const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
107
107
  index_js_1.default.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`);
108
108
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const child_process_1 = require("child_process");
4
3
  const commander_1 = require("commander");
5
4
  const index_js_1 = require("../bin/index.js");
6
5
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
+ const sspawn_js_1 = require("../helpers/sspawn.js");
7
7
  const DreamCliLogger_js_1 = require("./logger/DreamCliLogger.js");
8
8
  class DreamCLI {
9
9
  /**
@@ -145,18 +145,7 @@ class DreamCLI {
145
145
  * primary STDOUT context.
146
146
  */
147
147
  static async spawn(command, opts) {
148
- return new Promise((accept, reject) => {
149
- const spawnInstance = (0, child_process_1.spawn)(command, {
150
- stdio: 'inherit',
151
- shell: true,
152
- ...(opts || {}),
153
- });
154
- spawnInstance.on('close', code => {
155
- if (code !== 0)
156
- reject(new Error(code?.toString()));
157
- accept({});
158
- });
159
- });
148
+ return await (0, sspawn_js_1.default)(command, opts);
160
149
  }
161
150
  static get logger() {
162
151
  this._logger ||= new DreamCliLogger_js_1.default();
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = db;
4
4
  const DateTime_js_1 = require("../helpers/DateTime.js");
5
5
  const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
- require("../helpers/loadEnv.js");
7
6
  const DreamDbConnection_js_1 = require("./DreamDbConnection.js");
8
7
  if (EnvInternal_js_1.default.string('TZ', { optional: true }))
9
8
  DateTime_js_1.Settings.defaultZone = EnvInternal_js_1.default.string('TZ');
@@ -2050,6 +2050,7 @@ class Query extends ConnectedToDB_js_1.default {
2050
2050
  }
2051
2051
  applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias, joinOnStatements = {}, throughAssociations = [], joinType, }) {
2052
2052
  const { name, alias } = (0, extractAssociationMetadataFromAssociationName_js_1.default)(currentAssociationTableOrAlias);
2053
+ const joinOnStatement = joinOnStatements[currentAssociationTableOrAlias];
2053
2054
  previousAssociationTableOrAlias = (0, extractAssociationMetadataFromAssociationName_js_1.default)(previousAssociationTableOrAlias).alias;
2054
2055
  currentAssociationTableOrAlias = alias;
2055
2056
  let association = dreamClass['getAssociationMetadata'](name);
@@ -2137,7 +2138,7 @@ class Query extends ConnectedToDB_js_1.default {
2137
2138
  tableNameOrAlias: currentAssociationTableOrAlias,
2138
2139
  association,
2139
2140
  });
2140
- join = this.applyJoinOnStatements(join, joinOnStatements[currentAssociationTableOrAlias], currentAssociationTableOrAlias);
2141
+ join = this.applyJoinOnStatement(join, joinOnStatement, currentAssociationTableOrAlias);
2141
2142
  return join;
2142
2143
  });
2143
2144
  }
@@ -2178,7 +2179,7 @@ class Query extends ConnectedToDB_js_1.default {
2178
2179
  tableNameOrAlias: currentAssociationTableOrAlias,
2179
2180
  association,
2180
2181
  });
2181
- join = this.applyJoinOnStatements(join, joinOnStatements[currentAssociationTableOrAlias], currentAssociationTableOrAlias);
2182
+ join = this.applyJoinOnStatement(join, joinOnStatement, currentAssociationTableOrAlias);
2182
2183
  return join;
2183
2184
  });
2184
2185
  if (association.type === 'HasMany') {
@@ -2489,7 +2490,7 @@ class Query extends ConnectedToDB_js_1.default {
2489
2490
  throw new CannotPassUndefinedAsAValueToAWhereClause_js_1.default(this.dreamClass, a2);
2490
2491
  return { a, b, c, a2, b2, c2 };
2491
2492
  }
2492
- applyJoinOnStatements(join, joinOnStatement, rootTableOrAssociationAlias) {
2493
+ applyJoinOnStatement(join, joinOnStatement, rootTableOrAssociationAlias) {
2493
2494
  if (!joinOnStatement)
2494
2495
  return join;
2495
2496
  join = this._applyJoinOnStatements(join, joinOnStatement.on, rootTableOrAssociationAlias);
@@ -14,7 +14,7 @@ async function reload(dream, txn = null) {
14
14
  else
15
15
  query = query.connection('primary');
16
16
  query = query.removeAllDefaultScopes().where({ [dream.primaryKey]: dream.primaryKeyValue });
17
- const reloadedRecord = (await query.first());
17
+ const reloadedRecord = await query.firstOrFail();
18
18
  dream.setAttributes(reloadedRecord.getAttributes());
19
19
  dream['freezeAttributes']();
20
20
  return dream;
@@ -42,6 +42,9 @@ class DreamApplication {
42
42
  await cb(dreamApp);
43
43
  await dreamApp.inflections?.();
44
44
  await deferCb?.(dreamApp);
45
+ for (const plugin of dreamApp.plugins) {
46
+ await plugin(dreamApp);
47
+ }
45
48
  dreamApp.validateApplicationBuildIntegrity({
46
49
  bypassModelIntegrityCheck: opts.bypassModelIntegrityCheck || false,
47
50
  });
@@ -193,6 +196,10 @@ Try setting it to something valid, like:
193
196
  get inflections() {
194
197
  return this._inflections;
195
198
  }
199
+ _plugins = [];
200
+ get plugins() {
201
+ return this._plugins;
202
+ }
196
203
  loadedModels = false;
197
204
  constructor(opts) {
198
205
  if (opts?.db)
@@ -241,6 +248,9 @@ Try setting it to something valid, like:
241
248
  break;
242
249
  }
243
250
  }
251
+ plugin(cb) {
252
+ this._plugins.push(cb);
253
+ }
244
254
  set(applyOption, options) {
245
255
  switch (applyOption) {
246
256
  case 'db':
@@ -23,7 +23,7 @@ async function maybeDropDuplicateDatabases(client, dbName) {
23
23
  const parallelTests = index_js_1.default.getOrFail().parallelTests;
24
24
  if (!parallelTests)
25
25
  return;
26
- if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
26
+ if (EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')) {
27
27
  const replicaTestWorkerDatabaseName = `replica_test_${dbName}`;
28
28
  console.log(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`);
29
29
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
@@ -1,19 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = loadRepl;
4
- require("./loadEnv.js");
5
4
  const index_js_1 = require("../dream-application/index.js");
6
5
  const index_js_2 = require("../encrypt/index.js");
7
6
  const index_js_3 = require("../ops/index.js");
8
7
  const CalendarDate_js_1 = require("./CalendarDate.js");
8
+ const camelize_js_1 = require("./camelize.js");
9
+ const capitalize_js_1 = require("./capitalize.js");
10
+ const compact_js_1 = require("./compact.js");
9
11
  const DateTime_js_1 = require("./DateTime.js");
12
+ const hyphenize_js_1 = require("./hyphenize.js");
13
+ const pascalize_js_1 = require("./pascalize.js");
10
14
  const pascalizePath_js_1 = require("./pascalizePath.js");
15
+ const range_js_1 = require("./range.js");
16
+ const round_js_1 = require("./round.js");
17
+ const snakeify_js_1 = require("./snakeify.js");
18
+ const sort_js_1 = require("./sort.js");
19
+ const sortBy_js_1 = require("./sortBy.js");
20
+ const uncapitalize_js_1 = require("./uncapitalize.js");
21
+ const uniq_js_1 = require("./uniq.js");
11
22
  function loadRepl(context) {
12
23
  const dreamApp = index_js_1.default.getOrFail();
13
- context.DateTime = DateTime_js_1.DateTime;
14
24
  context.CalendarDate = CalendarDate_js_1.default;
25
+ context.DateTime = DateTime_js_1.DateTime;
15
26
  context.Encrypt = index_js_2.default;
27
+ context.camelize = camelize_js_1.default;
28
+ context.capitalize = capitalize_js_1.default;
29
+ context.compact = compact_js_1.default;
30
+ context.hyphenize = hyphenize_js_1.default;
16
31
  context.ops = index_js_3.default;
32
+ context.pascalize = pascalize_js_1.default;
33
+ context.pascalizePath = pascalizePath_js_1.default;
34
+ context.range = range_js_1.default;
35
+ context.round = round_js_1.default;
36
+ context.snakeify = snakeify_js_1.default;
37
+ context.sort = sort_js_1.default;
38
+ context.sortBy = sortBy_js_1.default;
39
+ context.uncapitalize = uncapitalize_js_1.default;
40
+ context.uniq = uniq_js_1.default;
17
41
  for (const globalName of Object.keys(dreamApp.models)) {
18
42
  context[(0, pascalizePath_js_1.default)(globalName)] = dreamApp.models[globalName];
19
43
  }
@@ -24,7 +24,7 @@ function ssspawn(command, opts = {}) {
24
24
  // NOTE: adding this stdout spy so that
25
25
  // when this cli utility runs node commands,
26
26
  // it can properly hijack the stdout from the command
27
- proc.stdout.on('data', chunk => {
27
+ proc.stdout?.on('data', chunk => {
28
28
  const txt = chunk?.toString()?.trim();
29
29
  if (typeof txt !== 'string' || !txt)
30
30
  return;
@@ -35,7 +35,7 @@ function ssspawn(command, opts = {}) {
35
35
  console.log(txt);
36
36
  }
37
37
  });
38
- proc.stdout.on('error', err => {
38
+ proc.stdout?.on('error', err => {
39
39
  console.log('sspawn error!');
40
40
  console.error(err);
41
41
  });
@@ -1,4 +1,3 @@
1
- import '../../helpers/loadEnv.js';
2
1
  import * as fs from 'fs/promises';
3
2
  import * as path from 'path';
4
3
  import DreamCLI from '../../cli/index.js';
@@ -1,6 +1,7 @@
1
1
  import DreamCLI from '../cli/index.js';
2
2
  import ConnectionConfRetriever from '../db/ConnectionConfRetriever.js';
3
3
  import DreamApplication from '../dream-application/index.js';
4
+ import EnvInternal from '../helpers/EnvInternal.js';
4
5
  import SchemaBuilder from '../helpers/cli/SchemaBuilder.js';
5
6
  import generateDream from '../helpers/cli/generateDream.js';
6
7
  import generateMigration from '../helpers/cli/generateMigration.js';
@@ -8,7 +9,6 @@ import createDb from '../helpers/db/createDb.js';
8
9
  import _dropDb from '../helpers/db/dropDb.js';
9
10
  import loadPgClient from '../helpers/db/loadPgClient.js';
10
11
  import runMigration from '../helpers/db/runMigration.js';
11
- import '../helpers/loadEnv.js';
12
12
  import sspawn from '../helpers/sspawn.js';
13
13
  import writeSyncFile from './helpers/sync.js';
14
14
  export default class DreamBin {
@@ -100,7 +100,7 @@ export default class DreamBin {
100
100
  const connectionRetriever = new ConnectionConfRetriever();
101
101
  const dbConf = connectionRetriever.getConnectionConf('primary');
102
102
  const client = await loadPgClient({ useSystemDb: true });
103
- if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
103
+ if (EnvInternal.boolean('DREAM_CORE_DEVELOPMENT')) {
104
104
  const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
105
105
  DreamCLI.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`);
106
106
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
@@ -1,7 +1,7 @@
1
- import { spawn } from 'child_process';
2
1
  import { InvalidArgumentError } from 'commander';
3
2
  import DreamBin from '../bin/index.js';
4
3
  import EnvInternal from '../helpers/EnvInternal.js';
4
+ import sspawn from '../helpers/sspawn.js';
5
5
  import DreamCliLogger from './logger/DreamCliLogger.js';
6
6
  export default class DreamCLI {
7
7
  /**
@@ -143,18 +143,7 @@ export default class DreamCLI {
143
143
  * primary STDOUT context.
144
144
  */
145
145
  static async spawn(command, opts) {
146
- return new Promise((accept, reject) => {
147
- const spawnInstance = spawn(command, {
148
- stdio: 'inherit',
149
- shell: true,
150
- ...(opts || {}),
151
- });
152
- spawnInstance.on('close', code => {
153
- if (code !== 0)
154
- reject(new Error(code?.toString()));
155
- accept({});
156
- });
157
- });
146
+ return await sspawn(command, opts);
158
147
  }
159
148
  static get logger() {
160
149
  this._logger ||= new DreamCliLogger();
@@ -1,6 +1,5 @@
1
1
  import { Settings } from '../helpers/DateTime.js';
2
2
  import EnvInternal from '../helpers/EnvInternal.js';
3
- import '../helpers/loadEnv.js';
4
3
  import DreamDbConnection from './DreamDbConnection.js';
5
4
  if (EnvInternal.string('TZ', { optional: true }))
6
5
  Settings.defaultZone = EnvInternal.string('TZ');
@@ -2048,6 +2048,7 @@ export default class Query extends ConnectedToDB {
2048
2048
  }
2049
2049
  applyOneJoin({ query, dreamClass, previousAssociationTableOrAlias, currentAssociationTableOrAlias, joinOnStatements = {}, throughAssociations = [], joinType, }) {
2050
2050
  const { name, alias } = extractAssociationMetadataFromAssociationName(currentAssociationTableOrAlias);
2051
+ const joinOnStatement = joinOnStatements[currentAssociationTableOrAlias];
2051
2052
  previousAssociationTableOrAlias = extractAssociationMetadataFromAssociationName(previousAssociationTableOrAlias).alias;
2052
2053
  currentAssociationTableOrAlias = alias;
2053
2054
  let association = dreamClass['getAssociationMetadata'](name);
@@ -2135,7 +2136,7 @@ export default class Query extends ConnectedToDB {
2135
2136
  tableNameOrAlias: currentAssociationTableOrAlias,
2136
2137
  association,
2137
2138
  });
2138
- join = this.applyJoinOnStatements(join, joinOnStatements[currentAssociationTableOrAlias], currentAssociationTableOrAlias);
2139
+ join = this.applyJoinOnStatement(join, joinOnStatement, currentAssociationTableOrAlias);
2139
2140
  return join;
2140
2141
  });
2141
2142
  }
@@ -2176,7 +2177,7 @@ export default class Query extends ConnectedToDB {
2176
2177
  tableNameOrAlias: currentAssociationTableOrAlias,
2177
2178
  association,
2178
2179
  });
2179
- join = this.applyJoinOnStatements(join, joinOnStatements[currentAssociationTableOrAlias], currentAssociationTableOrAlias);
2180
+ join = this.applyJoinOnStatement(join, joinOnStatement, currentAssociationTableOrAlias);
2180
2181
  return join;
2181
2182
  });
2182
2183
  if (association.type === 'HasMany') {
@@ -2487,7 +2488,7 @@ export default class Query extends ConnectedToDB {
2487
2488
  throw new CannotPassUndefinedAsAValueToAWhereClause(this.dreamClass, a2);
2488
2489
  return { a, b, c, a2, b2, c2 };
2489
2490
  }
2490
- applyJoinOnStatements(join, joinOnStatement, rootTableOrAssociationAlias) {
2491
+ applyJoinOnStatement(join, joinOnStatement, rootTableOrAssociationAlias) {
2491
2492
  if (!joinOnStatement)
2492
2493
  return join;
2493
2494
  join = this._applyJoinOnStatements(join, joinOnStatement.on, rootTableOrAssociationAlias);
@@ -11,7 +11,7 @@ export default async function reload(dream, txn = null) {
11
11
  else
12
12
  query = query.connection('primary');
13
13
  query = query.removeAllDefaultScopes().where({ [dream.primaryKey]: dream.primaryKeyValue });
14
- const reloadedRecord = (await query.first());
14
+ const reloadedRecord = await query.firstOrFail();
15
15
  dream.setAttributes(reloadedRecord.getAttributes());
16
16
  dream['freezeAttributes']();
17
17
  return dream;
@@ -40,6 +40,9 @@ export default class DreamApplication {
40
40
  await cb(dreamApp);
41
41
  await dreamApp.inflections?.();
42
42
  await deferCb?.(dreamApp);
43
+ for (const plugin of dreamApp.plugins) {
44
+ await plugin(dreamApp);
45
+ }
43
46
  dreamApp.validateApplicationBuildIntegrity({
44
47
  bypassModelIntegrityCheck: opts.bypassModelIntegrityCheck || false,
45
48
  });
@@ -191,6 +194,10 @@ Try setting it to something valid, like:
191
194
  get inflections() {
192
195
  return this._inflections;
193
196
  }
197
+ _plugins = [];
198
+ get plugins() {
199
+ return this._plugins;
200
+ }
194
201
  loadedModels = false;
195
202
  constructor(opts) {
196
203
  if (opts?.db)
@@ -239,6 +246,9 @@ Try setting it to something valid, like:
239
246
  break;
240
247
  }
241
248
  }
249
+ plugin(cb) {
250
+ this._plugins.push(cb);
251
+ }
242
252
  set(applyOption, options) {
243
253
  switch (applyOption) {
244
254
  case 'db':
@@ -20,7 +20,7 @@ async function maybeDropDuplicateDatabases(client, dbName) {
20
20
  const parallelTests = DreamApplication.getOrFail().parallelTests;
21
21
  if (!parallelTests)
22
22
  return;
23
- if (process.env.DREAM_CORE_DEVELOPMENT === '1') {
23
+ if (EnvInternal.boolean('DREAM_CORE_DEVELOPMENT')) {
24
24
  const replicaTestWorkerDatabaseName = `replica_test_${dbName}`;
25
25
  console.log(`dropping fake replica test database ${replicaTestWorkerDatabaseName}`);
26
26
  await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
@@ -1,16 +1,40 @@
1
- import './loadEnv.js';
2
1
  import DreamApplication from '../dream-application/index.js';
3
2
  import Encrypt from '../encrypt/index.js';
4
3
  import ops from '../ops/index.js';
5
4
  import CalendarDate from './CalendarDate.js';
5
+ import camelize from './camelize.js';
6
+ import capitalize from './capitalize.js';
7
+ import compact from './compact.js';
6
8
  import { DateTime } from './DateTime.js';
9
+ import hyphenize from './hyphenize.js';
10
+ import pascalize from './pascalize.js';
7
11
  import pascalizePath from './pascalizePath.js';
12
+ import range from './range.js';
13
+ import round from './round.js';
14
+ import snakeify from './snakeify.js';
15
+ import sort from './sort.js';
16
+ import sortBy from './sortBy.js';
17
+ import uncapitalize from './uncapitalize.js';
18
+ import uniq from './uniq.js';
8
19
  export default function loadRepl(context) {
9
20
  const dreamApp = DreamApplication.getOrFail();
10
- context.DateTime = DateTime;
11
21
  context.CalendarDate = CalendarDate;
22
+ context.DateTime = DateTime;
12
23
  context.Encrypt = Encrypt;
24
+ context.camelize = camelize;
25
+ context.capitalize = capitalize;
26
+ context.compact = compact;
27
+ context.hyphenize = hyphenize;
13
28
  context.ops = ops;
29
+ context.pascalize = pascalize;
30
+ context.pascalizePath = pascalizePath;
31
+ context.range = range;
32
+ context.round = round;
33
+ context.snakeify = snakeify;
34
+ context.sort = sort;
35
+ context.sortBy = sortBy;
36
+ context.uncapitalize = uncapitalize;
37
+ context.uniq = uniq;
14
38
  for (const globalName of Object.keys(dreamApp.models)) {
15
39
  context[pascalizePath(globalName)] = dreamApp.models[globalName];
16
40
  }
@@ -20,7 +20,7 @@ export function ssspawn(command, opts = {}) {
20
20
  // NOTE: adding this stdout spy so that
21
21
  // when this cli utility runs node commands,
22
22
  // it can properly hijack the stdout from the command
23
- proc.stdout.on('data', chunk => {
23
+ proc.stdout?.on('data', chunk => {
24
24
  const txt = chunk?.toString()?.trim();
25
25
  if (typeof txt !== 'string' || !txt)
26
26
  return;
@@ -31,7 +31,7 @@ export function ssspawn(command, opts = {}) {
31
31
  console.log(txt);
32
32
  }
33
33
  });
34
- proc.stdout.on('error', err => {
34
+ proc.stdout?.on('error', err => {
35
35
  console.log('sspawn error!');
36
36
  console.error(err);
37
37
  });
@@ -1,2 +1 @@
1
- import '../../helpers/loadEnv.js';
2
1
  export default function writeSyncFile(): Promise<void>;
@@ -1,4 +1,3 @@
1
- import '../helpers/loadEnv.js';
2
1
  export default class DreamBin {
3
2
  static sync(onSync: () => Promise<void> | void): Promise<void>;
4
3
  static buildDreamSchema(): Promise<void>;
@@ -19,7 +19,9 @@ export default class DreamCLI {
19
19
  seedDb: () => Promise<void> | void;
20
20
  onSync: () => Promise<void> | void;
21
21
  }): void;
22
- static spawn(command: string, opts?: SpawnOptions): Promise<unknown>;
22
+ static spawn(command: string, opts?: SpawnOptions & {
23
+ onStdout?: (str: string) => void;
24
+ }): Promise<unknown>;
23
25
  static get logger(): DreamCliLogger;
24
26
  private static _logger;
25
27
  }
@@ -1,5 +1,4 @@
1
1
  import { Kysely } from 'kysely';
2
2
  import Dream from '../Dream.js';
3
- import '../helpers/loadEnv.js';
4
3
  import { DbConnectionType } from '../types/db.js';
5
4
  export default function db<T extends Dream, DB extends T['DB'] = T['DB']>(connectionType?: DbConnectionType): Kysely<DB>;
@@ -1052,7 +1052,7 @@ export default class Query<DreamInstance extends Dream, QueryTypeOpts extends Re
1052
1052
  private notInArrayWithNullExpressionBuilder;
1053
1053
  private whereStatementToExpressionWrapper;
1054
1054
  private dreamWhereStatementToExpressionBuilderParts;
1055
- private applyJoinOnStatements;
1055
+ private applyJoinOnStatement;
1056
1056
  private _applyJoinOnStatements;
1057
1057
  private _applyJoinOnAnyStatements;
1058
1058
  private joinOnStatementToExpressionWrapper;
@@ -71,12 +71,15 @@ export default class DreamApplication {
71
71
  get logger(): DreamLogger;
72
72
  private _inflections?;
73
73
  get inflections(): (() => void | Promise<void>) | undefined;
74
+ private _plugins;
75
+ get plugins(): ((app: DreamApplication) => void | Promise<void>)[];
74
76
  protected loadedModels: boolean;
75
77
  constructor(opts?: Partial<DreamApplicationOpts>);
76
78
  get models(): Record<string, typeof Dream>;
77
79
  get serializers(): Record<string, typeof DreamSerializer>;
78
80
  get services(): Record<string, any>;
79
81
  load<RT extends 'models' | 'serializers' | 'services'>(resourceType: RT, resourcePath: string, importCb: (path: string) => Promise<any>): Promise<void>;
82
+ plugin(cb: (app: DreamApplication) => void | Promise<void>): void;
80
83
  set<ApplyOpt extends DreamApplicationSetOption>(applyOption: ApplyOpt, options: ApplyOpt extends 'db' ? DreamDbCredentialOptions : ApplyOpt extends 'encryption' ? DreamApplicationEncryptionOptions : ApplyOpt extends 'primaryKeyType' ? (typeof primaryKeyTypes)[number] : ApplyOpt extends 'logger' ? DreamLogger : ApplyOpt extends 'projectRoot' ? string : ApplyOpt extends 'inflections' ? () => void | Promise<void> : ApplyOpt extends 'paths' ? DreamDirectoryPaths : ApplyOpt extends 'parallelTests' ? number : never): void;
81
84
  on<T extends DreamHookEventType>(hookEventType: T, cb: T extends 'db:log' ? (event: KyselyLogEvent) => void : never): void;
82
85
  }
@@ -1,2 +1 @@
1
- import './loadEnv.js';
2
1
  export default function loadRepl(context: Record<string, unknown>): void;
@@ -1,6 +1,7 @@
1
- export default function sspawn(command: string, opts?: Record<string, unknown> & {
1
+ import { SpawnOptions } from 'child_process';
2
+ export default function sspawn(command: string, opts?: SpawnOptions & {
2
3
  onStdout?: (str: string) => void;
3
4
  }): Promise<unknown>;
4
- export declare function ssspawn(command: string, opts?: Record<string, unknown> & {
5
+ export declare function ssspawn(command: string, opts?: SpawnOptions & {
5
6
  onStdout?: (str: string) => void;
6
- }): import("child_process").ChildProcessWithoutNullStreams;
7
+ }): import("child_process").ChildProcess;