-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bin/repl: run NodeJS REPL with initialised container (#1191)
Example use: ./lib/bin/repl Available vars: Actees, Actors, Analytics, Assignments, Audits, Auth, Blobs, ClientAudits, Comments, Configs, Datasets, Entities, FieldKeys, FormAttachments, Forms, Keys, Projects, PublicLinks, Roles, Sentry, Sessions, SubmissionAttachments, Submissions, Users, all, db, enketo, env, mail, maybeOne, maybeOneFirst, one, oneFirst, run, s3, sql, stream, with, xlsform > await db.any(sql`SELECT * FROM blobs`) []
- Loading branch information
Showing
4 changed files
with
85 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ node_modules/ | |
.idea/ | ||
/.eslintcache | ||
/.pgbadger/ | ||
/.repl-history | ||
.vscode | ||
/junit-reports/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 ODK Central Developers | ||
// See the NOTICE file at the top-level directory of this distribution and at | ||
// https://github.com/getodk/central-backend/blob/master/NOTICE. | ||
// This file is part of ODK Central. It is subject to the license terms in | ||
// the LICENSE file found in the top-level directory of this distribution and at | ||
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
// including this file, may be copied, modified, propagated, or distributed | ||
// except according to the terms contained in the LICENSE file. | ||
|
||
const should = require('should'); // eslint-disable-line import/no-extraneous-dependencies | ||
require('../../test/assertions'); | ||
|
||
const _ = require('lodash'); // eslint-disable-line import/no-extraneous-dependencies | ||
const { sql } = require('slonik'); | ||
|
||
const container = require('../util/default-container'); | ||
|
||
(async () => { | ||
const context = { ..._.omit(container, 'with'), container, should, sql }; | ||
const contextKeys = Object.keys(context).sort(); | ||
console.log('Available vars:', contextKeys.join(', ')); | ||
|
||
const repl = require('repl').start({ | ||
useGlobal: true, // enable should.js prototype pollution | ||
}); | ||
|
||
await new Promise((resolve, reject) => { | ||
repl.setupHistory('.repl-history', err => { | ||
if (err) reject(err); | ||
else resolve(); | ||
}); | ||
}); | ||
|
||
Object.entries(context).forEach(([k, value]) => { | ||
Object.defineProperty(repl.context, k, { | ||
configurable: false, | ||
enumerable: true, | ||
value, | ||
}); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 ODK Central Developers | ||
// See the NOTICE file at the top-level directory of this distribution and at | ||
// https://github.com/getodk/central-backend/blob/master/NOTICE. | ||
// This file is part of ODK Central. It is subject to the license terms in | ||
// the LICENSE file found in the top-level directory of this distribution and at | ||
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
// including this file, may be copied, modified, propagated, or distributed | ||
// except according to the terms contained in the LICENSE file. | ||
|
||
const { mergeRight } = require('ramda'); | ||
const config = require('config'); | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// CONTAINER SETUP | ||
|
||
// initialize our slonik connection pool. | ||
const { slonikPool } = require('../external/slonik'); | ||
const db = slonikPool(config.get('default.database')); | ||
|
||
// set up our mailer. | ||
const env = config.get('default.env'); | ||
const { mailer } = require('../external/mail'); | ||
const mail = mailer(mergeRight(config.get('default.email'), { env })); | ||
|
||
// get a sentry and configure errors. | ||
const Sentry = require('../external/sentry').init(config.get('default.external.sentry')); | ||
Error.stackTrackLimit = 20; | ||
|
||
// get an xlsform client and a password module. | ||
const xlsform = require('../external/xlsform').init(config.get('default.xlsform')); | ||
|
||
// get an Enketo client | ||
const enketo = require('../external/enketo').init(config.get('default.enketo')); | ||
|
||
// get an S3 client. | ||
const s3 = require('../external/s3').init(config.get('default.external.s3blobStore')); | ||
|
||
const container = require('../model/container') | ||
.withDefaults({ db, mail, env, Sentry, xlsform, enketo, s3 }); | ||
|
||
module.exports = container; |