@rvoh/dream 0.44.7 → 0.44.8

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 (191) hide show
  1. package/dist/cjs/src/bin/index.js +7 -87
  2. package/dist/cjs/src/dream/LeftJoinLoadBuilder.js +1 -1
  3. package/dist/cjs/src/dream/LoadBuilder.js +1 -1
  4. package/dist/cjs/src/dream/Query.js +46 -1417
  5. package/dist/cjs/src/dream/QueryDriver/Base.js +311 -0
  6. package/dist/cjs/src/dream/QueryDriver/Kysely.js +1771 -0
  7. package/dist/cjs/src/dream/QueryDriver/Postgres.js +6 -0
  8. package/dist/cjs/src/dream/internal/saveDream.js +4 -17
  9. package/dist/esm/src/bin/index.js +7 -87
  10. package/dist/esm/src/dream/LeftJoinLoadBuilder.js +1 -1
  11. package/dist/esm/src/dream/LoadBuilder.js +1 -1
  12. package/dist/esm/src/dream/Query.js +46 -1417
  13. package/dist/esm/src/dream/QueryDriver/Base.js +308 -0
  14. package/dist/esm/src/dream/QueryDriver/Kysely.js +1768 -0
  15. package/dist/esm/src/dream/QueryDriver/Postgres.js +3 -0
  16. package/dist/esm/src/dream/internal/saveDream.js +4 -17
  17. package/dist/types/src/bin/index.d.ts +0 -2
  18. package/dist/types/src/dream/Query.d.ts +27 -155
  19. package/dist/types/src/dream/QueryDriver/Base.d.ts +242 -0
  20. package/dist/types/src/dream/QueryDriver/Kysely.d.ts +354 -0
  21. package/dist/types/src/dream/QueryDriver/Postgres.d.ts +4 -0
  22. package/dist/types/src/dream/internal/executeDatabaseQuery.d.ts +2 -1
  23. package/docs/assets/search.js +1 -1
  24. package/docs/classes/Benchmark.html +2 -2
  25. package/docs/classes/CalendarDate.html +2 -2
  26. package/docs/classes/CreateOrFindByFailedToCreateAndFind.html +3 -3
  27. package/docs/classes/Decorators.html +19 -19
  28. package/docs/classes/Dream.html +131 -131
  29. package/docs/classes/DreamApp.html +4 -4
  30. package/docs/classes/DreamBin.html +3 -4
  31. package/docs/classes/DreamCLI.html +4 -4
  32. package/docs/classes/DreamImporter.html +2 -2
  33. package/docs/classes/DreamLogos.html +2 -2
  34. package/docs/classes/DreamMigrationHelpers.html +7 -7
  35. package/docs/classes/DreamSerializerBuilder.html +2 -2
  36. package/docs/classes/DreamTransaction.html +2 -2
  37. package/docs/classes/Encrypt.html +2 -2
  38. package/docs/classes/Env.html +2 -2
  39. package/docs/classes/GlobalNameNotSet.html +3 -3
  40. package/docs/classes/NonLoadedAssociation.html +3 -3
  41. package/docs/classes/ObjectSerializerBuilder.html +2 -2
  42. package/docs/classes/Query.html +86 -57
  43. package/docs/classes/Range.html +2 -2
  44. package/docs/classes/RecordNotFound.html +3 -3
  45. package/docs/classes/ValidationError.html +3 -3
  46. package/docs/functions/DreamSerializer.html +1 -1
  47. package/docs/functions/ObjectSerializer.html +1 -1
  48. package/docs/functions/ReplicaSafe.html +1 -1
  49. package/docs/functions/STI.html +1 -1
  50. package/docs/functions/SoftDelete.html +1 -1
  51. package/docs/functions/camelize.html +1 -1
  52. package/docs/functions/capitalize.html +1 -1
  53. package/docs/functions/cloneDeepSafe.html +1 -1
  54. package/docs/functions/closeAllDbConnections.html +1 -1
  55. package/docs/functions/compact.html +1 -1
  56. package/docs/functions/dreamDbConnections.html +1 -1
  57. package/docs/functions/dreamPath.html +1 -1
  58. package/docs/functions/expandStiClasses.html +1 -1
  59. package/docs/functions/generateDream.html +1 -1
  60. package/docs/functions/globalClassNameFromFullyQualifiedModelName.html +1 -1
  61. package/docs/functions/groupBy.html +1 -1
  62. package/docs/functions/hyphenize.html +1 -1
  63. package/docs/functions/inferSerializerFromDreamOrViewModel.html +1 -1
  64. package/docs/functions/inferSerializersFromDreamClassOrViewModelClass.html +1 -1
  65. package/docs/functions/intersection.html +1 -1
  66. package/docs/functions/isDreamSerializer.html +1 -1
  67. package/docs/functions/isEmpty.html +1 -1
  68. package/docs/functions/loadRepl.html +1 -1
  69. package/docs/functions/lookupClassByGlobalName.html +1 -1
  70. package/docs/functions/normalizeUnicode.html +1 -1
  71. package/docs/functions/pascalize.html +1 -1
  72. package/docs/functions/pgErrorType.html +1 -1
  73. package/docs/functions/range-1.html +1 -1
  74. package/docs/functions/relativeDreamPath.html +1 -1
  75. package/docs/functions/round.html +1 -1
  76. package/docs/functions/serializerNameFromFullyQualifiedModelName.html +1 -1
  77. package/docs/functions/sharedPathPrefix.html +1 -1
  78. package/docs/functions/snakeify.html +1 -1
  79. package/docs/functions/sort.html +1 -1
  80. package/docs/functions/sortBy.html +1 -1
  81. package/docs/functions/sortObjectByKey.html +1 -1
  82. package/docs/functions/sortObjectByValue.html +1 -1
  83. package/docs/functions/standardizeFullyQualifiedModelName.html +1 -1
  84. package/docs/functions/uncapitalize.html +1 -1
  85. package/docs/functions/uniq.html +1 -1
  86. package/docs/functions/untypedDb.html +1 -1
  87. package/docs/functions/validateColumn.html +1 -1
  88. package/docs/functions/validateTable.html +1 -1
  89. package/docs/interfaces/BelongsToStatement.html +2 -2
  90. package/docs/interfaces/DecoratorContext.html +2 -2
  91. package/docs/interfaces/DreamAppInitOptions.html +2 -2
  92. package/docs/interfaces/DreamAppOpts.html +2 -2
  93. package/docs/interfaces/EncryptOptions.html +2 -2
  94. package/docs/interfaces/InternalAnyTypedSerializerRendersMany.html +2 -2
  95. package/docs/interfaces/InternalAnyTypedSerializerRendersOne.html +2 -2
  96. package/docs/interfaces/OpenapiDescription.html +2 -2
  97. package/docs/interfaces/OpenapiSchemaProperties.html +1 -1
  98. package/docs/interfaces/OpenapiSchemaPropertiesShorthand.html +1 -1
  99. package/docs/interfaces/OpenapiTypeFieldObject.html +1 -1
  100. package/docs/interfaces/SerializerRendererOpts.html +2 -2
  101. package/docs/types/Camelized.html +1 -1
  102. package/docs/types/CommonOpenapiSchemaObjectFields.html +1 -1
  103. package/docs/types/DateTime.html +1 -1
  104. package/docs/types/DbConnectionType.html +1 -1
  105. package/docs/types/DbTypes.html +1 -1
  106. package/docs/types/DreamAssociationMetadata.html +1 -1
  107. package/docs/types/DreamAttributes.html +1 -1
  108. package/docs/types/DreamClassColumn.html +1 -1
  109. package/docs/types/DreamColumn.html +1 -1
  110. package/docs/types/DreamColumnNames.html +1 -1
  111. package/docs/types/DreamLogLevel.html +1 -1
  112. package/docs/types/DreamLogger.html +1 -1
  113. package/docs/types/DreamModelSerializerType.html +1 -1
  114. package/docs/types/DreamOrViewModelClassSerializerKey.html +1 -1
  115. package/docs/types/DreamOrViewModelSerializerKey.html +1 -1
  116. package/docs/types/DreamParamSafeAttributes.html +1 -1
  117. package/docs/types/DreamParamSafeColumnNames.html +1 -1
  118. package/docs/types/DreamSerializable.html +1 -1
  119. package/docs/types/DreamSerializableArray.html +1 -1
  120. package/docs/types/DreamSerializerKey.html +1 -1
  121. package/docs/types/DreamSerializers.html +1 -1
  122. package/docs/types/DreamTableSchema.html +1 -1
  123. package/docs/types/DreamVirtualColumns.html +1 -1
  124. package/docs/types/EncryptAlgorithm.html +1 -1
  125. package/docs/types/HasManyStatement.html +1 -1
  126. package/docs/types/HasOneStatement.html +1 -1
  127. package/docs/types/Hyphenized.html +1 -1
  128. package/docs/types/IdType.html +1 -1
  129. package/docs/types/OpenapiAllTypes.html +1 -1
  130. package/docs/types/OpenapiFormats.html +1 -1
  131. package/docs/types/OpenapiNumberFormats.html +1 -1
  132. package/docs/types/OpenapiPrimitiveBaseTypes.html +1 -1
  133. package/docs/types/OpenapiPrimitiveTypes.html +1 -1
  134. package/docs/types/OpenapiSchemaArray.html +1 -1
  135. package/docs/types/OpenapiSchemaArrayShorthand.html +1 -1
  136. package/docs/types/OpenapiSchemaBase.html +1 -1
  137. package/docs/types/OpenapiSchemaBody.html +1 -1
  138. package/docs/types/OpenapiSchemaBodyShorthand.html +1 -1
  139. package/docs/types/OpenapiSchemaCommonFields.html +1 -1
  140. package/docs/types/OpenapiSchemaExpressionAllOf.html +1 -1
  141. package/docs/types/OpenapiSchemaExpressionAnyOf.html +1 -1
  142. package/docs/types/OpenapiSchemaExpressionOneOf.html +1 -1
  143. package/docs/types/OpenapiSchemaExpressionRef.html +1 -1
  144. package/docs/types/OpenapiSchemaExpressionRefSchemaShorthand.html +1 -1
  145. package/docs/types/OpenapiSchemaInteger.html +1 -1
  146. package/docs/types/OpenapiSchemaNull.html +1 -1
  147. package/docs/types/OpenapiSchemaNumber.html +1 -1
  148. package/docs/types/OpenapiSchemaObject.html +1 -1
  149. package/docs/types/OpenapiSchemaObjectAllOf.html +1 -1
  150. package/docs/types/OpenapiSchemaObjectAllOfShorthand.html +1 -1
  151. package/docs/types/OpenapiSchemaObjectAnyOf.html +1 -1
  152. package/docs/types/OpenapiSchemaObjectAnyOfShorthand.html +1 -1
  153. package/docs/types/OpenapiSchemaObjectBase.html +1 -1
  154. package/docs/types/OpenapiSchemaObjectBaseShorthand.html +1 -1
  155. package/docs/types/OpenapiSchemaObjectOneOf.html +1 -1
  156. package/docs/types/OpenapiSchemaObjectOneOfShorthand.html +1 -1
  157. package/docs/types/OpenapiSchemaObjectShorthand.html +1 -1
  158. package/docs/types/OpenapiSchemaPrimitiveGeneric.html +1 -1
  159. package/docs/types/OpenapiSchemaShorthandExpressionAllOf.html +1 -1
  160. package/docs/types/OpenapiSchemaShorthandExpressionAnyOf.html +1 -1
  161. package/docs/types/OpenapiSchemaShorthandExpressionOneOf.html +1 -1
  162. package/docs/types/OpenapiSchemaShorthandExpressionSerializableRef.html +1 -1
  163. package/docs/types/OpenapiSchemaShorthandExpressionSerializerRef.html +1 -1
  164. package/docs/types/OpenapiSchemaShorthandPrimitiveGeneric.html +1 -1
  165. package/docs/types/OpenapiSchemaString.html +1 -1
  166. package/docs/types/OpenapiShorthandAllTypes.html +1 -1
  167. package/docs/types/OpenapiShorthandPrimitiveBaseTypes.html +1 -1
  168. package/docs/types/OpenapiShorthandPrimitiveTypes.html +1 -1
  169. package/docs/types/OpenapiTypeField.html +1 -1
  170. package/docs/types/Pascalized.html +1 -1
  171. package/docs/types/PrimaryKeyType.html +1 -1
  172. package/docs/types/RoundingPrecision.html +1 -1
  173. package/docs/types/SerializerCasing.html +1 -1
  174. package/docs/types/SimpleObjectSerializerType.html +1 -1
  175. package/docs/types/Snakeified.html +1 -1
  176. package/docs/types/Timestamp.html +1 -1
  177. package/docs/types/UpdateableAssociationProperties.html +1 -1
  178. package/docs/types/UpdateableProperties.html +1 -1
  179. package/docs/types/ValidationType.html +1 -1
  180. package/docs/types/ViewModel.html +1 -1
  181. package/docs/types/ViewModelClass.html +1 -1
  182. package/docs/types/WhereStatementForDream.html +1 -1
  183. package/docs/types/WhereStatementForDreamClass.html +1 -1
  184. package/docs/variables/DateTime-1.html +1 -1
  185. package/docs/variables/DreamConst.html +1 -1
  186. package/docs/variables/TRIGRAM_OPERATORS.html +1 -1
  187. package/docs/variables/openapiPrimitiveTypes-1.html +1 -1
  188. package/docs/variables/openapiShorthandPrimitiveTypes-1.html +1 -1
  189. package/docs/variables/ops.html +1 -1
  190. package/docs/variables/primaryKeyTypes.html +1 -1
  191. package/package.json +2 -2
@@ -1,81 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const index_js_1 = require("../cli/index.js");
4
- const index_js_2 = require("../dream-app/index.js");
5
- const EnvInternal_js_1 = require("../helpers/EnvInternal.js");
6
- const SchemaBuilder_js_1 = require("../helpers/cli/SchemaBuilder.js");
4
+ const Query_js_1 = require("../dream/Query.js");
7
5
  const generateDream_js_1 = require("../helpers/cli/generateDream.js");
8
- const generateMigration_js_1 = require("../helpers/cli/generateMigration.js");
9
- const createDb_js_1 = require("../helpers/db/createDb.js");
10
- const dropDb_js_1 = require("../helpers/db/dropDb.js");
11
- const loadPgClient_js_1 = require("../helpers/db/loadPgClient.js");
12
- const runMigration_js_1 = require("../helpers/db/runMigration.js");
13
6
  const sspawn_js_1 = require("../helpers/sspawn.js");
14
- const sync_js_1 = require("./helpers/sync.js");
15
7
  class DreamBin {
16
8
  static async sync(onSync) {
17
- index_js_1.default.logger.logStartProgress('writing db schema...');
18
- await (0, sync_js_1.default)();
19
- index_js_1.default.logger.logEndProgress();
20
- index_js_1.default.logger.logStartProgress('building dream schema...');
21
- await this.buildDreamSchema();
22
- index_js_1.default.logger.logEndProgress();
23
- // intentionally leaving logs off here, since it allows other
24
- // onSync handlers to determine their own independent logging approach
25
- await onSync();
26
- }
27
- static async buildDreamSchema() {
28
- await new SchemaBuilder_js_1.default().build();
9
+ await Query_js_1.default.dbDriverClass().sync(onSync);
29
10
  }
30
11
  static async dbCreate() {
31
- const dreamApp = index_js_2.default.getOrFail();
32
- const primaryDbConf = dreamApp.dbConnectionConfig('primary');
33
- index_js_1.default.logger.logStartProgress(`creating ${primaryDbConf.name}...`);
34
- await (0, createDb_js_1.default)('primary');
35
- index_js_1.default.logger.logEndProgress();
36
- // TODO: add support for creating replicas. Began doing it below, but it is very tricky,
37
- // and we don't need it at the moment, so kicking off for future development when we have more time
38
- // to flesh this out.
39
- // if (connectionRetriever.hasReplicaConfig()) {
40
- // const replicaDbConf = connectionRetriever.getConnectionConf('replica')
41
- // console.log(`creating ${process.env[replicaDbConf.name]}`)
42
- // await createDb('replica')
43
- // }
12
+ await Query_js_1.default.dbDriverClass().dbCreate();
44
13
  }
45
14
  static async dbDrop() {
46
- const dreamApp = index_js_2.default.getOrFail();
47
- const primaryDbConf = dreamApp.dbConnectionConfig('primary');
48
- index_js_1.default.logger.logStartProgress(`dropping ${primaryDbConf.name}...`);
49
- await (0, dropDb_js_1.default)('primary');
50
- index_js_1.default.logger.logEndProgress();
51
- // TODO: add support for dropping replicas. Began doing it below, but it is very tricky,
52
- // and we don't need it at the moment, so kicking off for future development when we have more time
53
- // to flesh this out.
54
- // if (connectionRetriever.hasReplicaConfig()) {
55
- // const replicaDbConf = connectionRetriever.getConnectionConf('replica')
56
- // console.log(`dropping ${process.env[replicaDbConf.name]}`)
57
- // await _dropDb('replica')
58
- // }
15
+ await Query_js_1.default.dbDriverClass().dbDrop();
59
16
  }
60
17
  static async dbMigrate() {
61
- const dreamApp = index_js_2.default.getOrFail();
62
- const primaryDbConf = dreamApp.dbConnectionConfig('primary');
63
- index_js_1.default.logger.logStartProgress(`migrating ${primaryDbConf.name}...`);
64
- await (0, runMigration_js_1.default)({ mode: 'migrate' });
65
- index_js_1.default.logger.logEndProgress();
66
- await this.duplicateDatabase();
18
+ await Query_js_1.default.dbDriverClass().migrate();
67
19
  }
68
20
  static async dbRollback(opts) {
69
- const dreamApp = index_js_2.default.getOrFail();
70
- const primaryDbConf = dreamApp.dbConnectionConfig('primary');
71
- index_js_1.default.logger.logStartProgress(`rolling back ${primaryDbConf.name}...`);
72
- let step = opts.steps;
73
- while (step > 0) {
74
- await (0, runMigration_js_1.default)({ mode: 'rollback' });
75
- step -= 1;
76
- }
77
- index_js_1.default.logger.logEndProgress();
78
- await this.duplicateDatabase();
21
+ await Query_js_1.default.dbDriverClass().rollback(opts);
79
22
  }
80
23
  static async generateDream(fullyQualifiedModelName, columnsWithTypes, options) {
81
24
  await (0, generateDream_js_1.default)({ fullyQualifiedModelName, columnsWithTypes, options });
@@ -89,7 +32,7 @@ class DreamBin {
89
32
  });
90
33
  }
91
34
  static async generateMigration(migrationName, columnsWithTypes) {
92
- await (0, generateMigration_js_1.default)({ migrationName, columnsWithTypes });
35
+ await Query_js_1.default.dbDriverClass().generateMigration(migrationName, columnsWithTypes);
93
36
  }
94
37
  // though this is a private method, it is still used internally.
95
38
  // It is only made private so that people don't mistakenly try
@@ -99,28 +42,5 @@ class DreamBin {
99
42
  await (0, sspawn_js_1.default)('yarn typedoc src/index.ts --tsconfig ./tsconfig.esm.build.json --out docs');
100
43
  index_js_1.default.logger.logEndProgress();
101
44
  }
102
- static async duplicateDatabase() {
103
- const dreamApp = index_js_2.default.getOrFail();
104
- const parallelTests = dreamApp.parallelTests;
105
- if (!parallelTests)
106
- return;
107
- index_js_1.default.logger.logStartProgress(`duplicating db for parallel tests...`);
108
- const dbConf = dreamApp.dbConnectionConfig('primary');
109
- const client = await (0, loadPgClient_js_1.default)({ useSystemDb: true });
110
- if (EnvInternal_js_1.default.boolean('DREAM_CORE_DEVELOPMENT')) {
111
- const replicaTestWorkerDatabaseName = `replica_test_${dbConf.name}`;
112
- index_js_1.default.logger.logContinueProgress(`creating fake replica test database ${replicaTestWorkerDatabaseName}...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
113
- await client.query(`DROP DATABASE IF EXISTS ${replicaTestWorkerDatabaseName};`);
114
- await client.query(`CREATE DATABASE ${replicaTestWorkerDatabaseName} TEMPLATE ${dbConf.name};`);
115
- }
116
- for (let i = 2; i <= parallelTests; i++) {
117
- const workerDatabaseName = `${dbConf.name}_${i}`;
118
- index_js_1.default.logger.logContinueProgress(`creating duplicate test database ${workerDatabaseName} for concurrent tests...`, { logPrefix: ' ├ [db]', logPrefixColor: 'cyan' });
119
- await client.query(`DROP DATABASE IF EXISTS ${workerDatabaseName};`);
120
- await client.query(`CREATE DATABASE ${workerDatabaseName} TEMPLATE ${dbConf.name};`);
121
- }
122
- await client.end();
123
- index_js_1.default.logger.logEndProgress();
124
- }
125
45
  }
126
46
  exports.default = DreamBin;
@@ -67,7 +67,7 @@ class LeftJoinLoadBuilder {
67
67
  const associationMetadata = this.dream['getAssociationMetadata'](associationName);
68
68
  if (associationMetadata === undefined)
69
69
  throw new UnexpectedUndefined_js_1.default();
70
- this.query['hydrateAssociation']([this.dream], associationMetadata, this.associationToPreloadedDreamsAndWhatTheyPointTo({
70
+ this.query.dbDriverInstance()['hydrateAssociation']([this.dream], associationMetadata, this.associationToPreloadedDreamsAndWhatTheyPointTo({
71
71
  pointsToPrimaryKey: this.dream.primaryKeyValue,
72
72
  associatedModels: dreamWithLoadedAssociations[associationName],
73
73
  }));
@@ -61,7 +61,7 @@ class LoadBuilder {
61
61
  if (this.dreamTransaction) {
62
62
  this.query = this.query.txn(this.dreamTransaction);
63
63
  }
64
- await this.query['hydratePreload'](this.dream);
64
+ await this.query.dbDriverInstance()['hydratePreload'](this.dream);
65
65
  return this.dream;
66
66
  }
67
67
  }