@event-driven-io/emmett-postgresql 0.41.0-alpha.1 → 0.41.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2126,23 +2126,39 @@ var handleProjections = async (options) => {
2126
2126
  }
2127
2127
  };
2128
2128
  var postgreSQLProjection = (definition) => projection(definition);
2129
- var postgreSQLRawBatchSQLProjection = (handle, ...canHandle) => postgreSQLProjection({
2130
- canHandle,
2129
+ var postgreSQLRawBatchSQLProjection = (options) => postgreSQLProjection({
2130
+ canHandle: options.canHandle,
2131
2131
  handle: async (events, context) => {
2132
- const sqls = await handle(events, context);
2132
+ const sqls = await options.evolve(events, context);
2133
2133
  await context.execute.batchCommand(sqls);
2134
+ },
2135
+ init: async (context) => {
2136
+ if (options.init) {
2137
+ await options.init(context);
2138
+ }
2139
+ if (options.initSQL) {
2140
+ await context.execute.command(options.initSQL);
2141
+ }
2134
2142
  }
2135
2143
  });
2136
- var postgreSQLRawSQLProjection = (handle, ...canHandle) => postgreSQLRawBatchSQLProjection(
2137
- async (events, context) => {
2138
- const sqls = [];
2139
- for (const event of events) {
2140
- sqls.push(await handle(event, context));
2144
+ var postgreSQLRawSQLProjection = (options) => {
2145
+ const { evolve, ...rest } = options;
2146
+ return postgreSQLRawBatchSQLProjection({
2147
+ ...rest,
2148
+ evolve: async (events, context) => {
2149
+ const sqls = [];
2150
+ for (const event of events) {
2151
+ const pendingSqls = await evolve(event, context);
2152
+ if (Array.isArray(pendingSqls)) {
2153
+ sqls.push(...pendingSqls);
2154
+ } else {
2155
+ sqls.push(pendingSqls);
2156
+ }
2157
+ }
2158
+ return sqls;
2141
2159
  }
2142
- return sqls;
2143
- },
2144
- ...canHandle
2145
- );
2160
+ });
2161
+ };
2146
2162
 
2147
2163
  // src/eventStore/postgreSQLEventStore.ts
2148
2164
  var defaultPostgreSQLOptions = {