@squiz/render-runtime-lib 1.2.1-alpha.79 → 1.2.1-alpha.82

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/lib/index.js CHANGED
@@ -19873,16 +19873,16 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
19873
19873
  return prev;
19874
19874
  }, {});
19875
19875
  }
19876
- getConnection() {
19877
- return this.pool.connect();
19876
+ async getConnection() {
19877
+ return await this.pool.connect();
19878
19878
  }
19879
- async create(value) {
19879
+ async create(value, transactionClient = null) {
19880
19880
  const columns = Object.keys(value).map((a) => `"${this.modelPropertyToSqlColumn[a]}"`).join(", ");
19881
19881
  const values = Object.values(value).map((a, index) => `$${index + 1}`).join(", ");
19882
- const result = await this.executeQuery(`INSERT INTO ${this.tableName} (${columns}) VALUES (${values}) RETURNING *`, Object.values(value));
19882
+ const result = await this.executeQuery(`INSERT INTO ${this.tableName} (${columns}) VALUES (${values}) RETURNING *`, Object.values(value), transactionClient);
19883
19883
  return result[0];
19884
19884
  }
19885
- async update(where, newValue) {
19885
+ async update(where, newValue, transactionClient = null) {
19886
19886
  const whereValues = Object.values(where);
19887
19887
  const newValues = Object.values(newValue);
19888
19888
  const setString = Object.keys(newValue).map((a, index) => `"${this.modelPropertyToSqlColumn[a]}" = $${index + 1}`).join(", ");
@@ -19890,17 +19890,19 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
19890
19890
  const result = await this.executeQuery(`UPDATE ${this.tableName}
19891
19891
  SET ${setString}
19892
19892
  WHERE ${whereString}
19893
- RETURNING *`, [...Object.values(newValues), ...Object.values(whereValues)]);
19893
+ RETURNING *`, [...Object.values(newValues), ...Object.values(whereValues)], transactionClient);
19894
19894
  return result;
19895
19895
  }
19896
- async delete(where) {
19897
- const client = await this.pool.connect();
19896
+ async delete(where, transactionClient = null) {
19897
+ const client = transactionClient ?? await this.getConnection();
19898
19898
  try {
19899
19899
  const whereString = this.createWhereStringFromPartialModel(where);
19900
19900
  const result = await client.query(`DELETE FROM ${this.tableName} WHERE ${whereString}`, Object.values(where));
19901
19901
  return result.rowCount;
19902
19902
  } finally {
19903
- client.release();
19903
+ if (client && !transactionClient) {
19904
+ client.release();
19905
+ }
19904
19906
  }
19905
19907
  }
19906
19908
  createWhereStringFromPartialModel(values, initialIndex = 0) {
@@ -19914,13 +19916,13 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
19914
19916
  }, "");
19915
19917
  return sql;
19916
19918
  }
19917
- async executeQuery(query, values) {
19918
- const client = await this.pool.connect();
19919
+ async executeQuery(query, values, transactionClient = null) {
19920
+ const client = transactionClient ?? await this.getConnection();
19919
19921
  try {
19920
19922
  const result = await client.query(query, values);
19921
19923
  return result.rows.map((a) => this.createAndHydrateModel(a));
19922
19924
  } finally {
19923
- if (client) {
19925
+ if (client && !transactionClient) {
19924
19926
  client.release();
19925
19927
  }
19926
19928
  }
@@ -19945,6 +19947,11 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
19945
19947
  WHERE ${this.createWhereStringFromPartialModel(item)}`, Object.values(item));
19946
19948
  return result;
19947
19949
  }
19950
+ async findAll() {
19951
+ const result = await this.executeQuery(`SELECT *
19952
+ FROM ${this.tableName}`, []);
19953
+ return result;
19954
+ }
19948
19955
  };
19949
19956
  var ComponentRepository = class extends AbstractRepository {
19950
19957
  constructor(options) {
@@ -20111,7 +20118,54 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
20111
20118
  setTimeout(resolve, timeMs);
20112
20119
  });
20113
20120
  }
20114
- var migration_list_default = ["20220704054051_initial.sql"];
20121
+ var migration_list_default = ["20220704054051_initial.sql", "20220718172237_adding_component_sets.sql"];
20122
+ var ComponentSet = class {
20123
+ constructor() {
20124
+ this.webPath = "";
20125
+ this.displayName = "";
20126
+ this.envVars = {};
20127
+ this.description = "";
20128
+ this.headers = {};
20129
+ }
20130
+ };
20131
+ var ComponentSetRepository = class extends AbstractRepository {
20132
+ constructor(options) {
20133
+ super(options.repositories, options.pool, "component_set", {
20134
+ webPath: "web_path",
20135
+ displayName: "display_name",
20136
+ description: "description",
20137
+ envVars: "env_vars",
20138
+ headers: "headers"
20139
+ }, ComponentSet);
20140
+ }
20141
+ async getComponentSetByWebPath(webPath) {
20142
+ return this.findOne({ webPath });
20143
+ }
20144
+ async componentSetExists(webPath) {
20145
+ const comp = await this.getComponentSetByWebPath(webPath);
20146
+ return comp != null;
20147
+ }
20148
+ };
20149
+ var ComponentSetComponentVersion = class {
20150
+ constructor() {
20151
+ this.componentSetWebPath = "";
20152
+ this.componentName = "";
20153
+ this.componentVersion = "";
20154
+ }
20155
+ };
20156
+ var ComponentSetComponentVersionRepository = class extends AbstractRepository {
20157
+ constructor(options) {
20158
+ super(options.repositories, options.pool, "component_set_component_version", {
20159
+ componentSetWebPath: "component_set_web_path",
20160
+ componentName: "component_name",
20161
+ componentVersion: "component_version"
20162
+ }, ComponentSetComponentVersion);
20163
+ }
20164
+ async componentSetComponentVersionExists(componentSetWebPath, componentName, componentVersion) {
20165
+ const row = await this.findOne({ componentSetWebPath, componentName, componentVersion });
20166
+ return row != null;
20167
+ }
20168
+ };
20115
20169
  var ConnectionManager2 = class {
20116
20170
  constructor(applicationName, connection, migrationDirectory) {
20117
20171
  this.applicationName = applicationName;
@@ -20132,7 +20186,9 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
20132
20186
  });
20133
20187
  this.repositories = {
20134
20188
  component: new ComponentRepository(this),
20135
- componentVersion: new ComponentVersionRepository(this)
20189
+ componentVersion: new ComponentVersionRepository(this),
20190
+ componentSet: new ComponentSetRepository(this),
20191
+ componentSetComponentVersion: new ComponentSetComponentVersionRepository(this)
20136
20192
  };
20137
20193
  }
20138
20194
  async applyMigrations() {
@@ -20144,6 +20200,22 @@ Reference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.ht
20144
20200
  await this.pool.end();
20145
20201
  this.pool.removeAllListeners();
20146
20202
  }
20203
+ async executeInTransaction(func) {
20204
+ const client = await this.pool.connect();
20205
+ try {
20206
+ await client.query("BEGIN");
20207
+ const value = await func(client);
20208
+ await client.query("COMMIT");
20209
+ return value;
20210
+ } catch (e) {
20211
+ await client.query("ROLLBACK");
20212
+ throw e;
20213
+ } finally {
20214
+ if (client) {
20215
+ client.release();
20216
+ }
20217
+ }
20218
+ }
20147
20219
  };
20148
20220
  var import_client_secrets_manager = __toESM2(require_dist_cjs44());
20149
20221
  async function getConnectionInfo2(config) {
@@ -94777,12 +94849,11 @@ router3.get(/([^/]+)\/([^/]+)(.*)/, async (req, res, _next) => {
94777
94849
  const componentName = req.params[0];
94778
94850
  const version = req.params[1];
94779
94851
  const staticFile = req.params[2];
94780
- const config = ComponentRunner.getConfig();
94781
94852
  const manifestPath = await getManifestPath(componentName, version, isInProductionMode());
94782
94853
  const manifest = await (0, import_component_lib7.loadManifest)(manifestPath);
94783
94854
  if (manifest["static-files"]) {
94784
94855
  const componentStaticFileRoot = manifest["static-files"]["location-root"];
94785
- const staticFilePath = import_path3.default.join(config.dataMountPoint, componentName, version, componentStaticFileRoot);
94856
+ const staticFilePath = import_path3.default.join(manifestPath, "../", componentStaticFileRoot);
94786
94857
  res.sendFile(staticFile, {
94787
94858
  root: staticFilePath,
94788
94859
  dotfiles: "deny",