|
@@ -1,50 +1,45 @@
|
|
// A script to be executed post query-node install, that may include workarounds in Hydra node_modules
|
|
// A script to be executed post query-node install, that may include workarounds in Hydra node_modules
|
|
-import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
import path from 'path'
|
|
|
|
+import { replaceInFile } from './utils'
|
|
|
|
|
|
// FIXME: Temporarly remove broken sanitizeNullCharacter call
|
|
// FIXME: Temporarly remove broken sanitizeNullCharacter call
|
|
const subscribersJsPath = path.resolve(
|
|
const subscribersJsPath = path.resolve(
|
|
__dirname,
|
|
__dirname,
|
|
'../../../node_modules/@joystream/hydra-processor/lib/db/subscribers.js'
|
|
'../../../node_modules/@joystream/hydra-processor/lib/db/subscribers.js'
|
|
)
|
|
)
|
|
-const subscribersJsContent = fs.readFileSync(subscribersJsPath).toString()
|
|
|
|
-fs.writeFileSync(
|
|
|
|
- subscribersJsPath,
|
|
|
|
- subscribersJsContent.replace(/sanitizeNullCharacter\(entity, field\);/g, '//sanitizeNullCharacter(entity, field)')
|
|
|
|
-)
|
|
|
|
|
|
+replaceInFile({
|
|
|
|
+ filePath: subscribersJsPath,
|
|
|
|
+ regex: /sanitizeNullCharacter\(entity, field\);/g,
|
|
|
|
+ newContent: '//sanitizeNullCharacter(entity, field)',
|
|
|
|
+})
|
|
|
|
|
|
// FIXME: Temporarly replace broken relations resolution in @joystream/warthog
|
|
// FIXME: Temporarly replace broken relations resolution in @joystream/warthog
|
|
const dataLoaderJsPath = path.resolve(
|
|
const dataLoaderJsPath = path.resolve(
|
|
__dirname,
|
|
__dirname,
|
|
'../../../node_modules/@joystream/warthog/dist/middleware/DataLoaderMiddleware.js'
|
|
'../../../node_modules/@joystream/warthog/dist/middleware/DataLoaderMiddleware.js'
|
|
)
|
|
)
|
|
-const dataLoaderJsContent = fs.readFileSync(dataLoaderJsPath).toString()
|
|
|
|
-const dataLoaderJsContentLines = dataLoaderJsContent.split('\n')
|
|
|
|
-dataLoaderJsContentLines.splice(
|
|
|
|
- dataLoaderJsContentLines.findIndex((l) => l.match(/return context\.connection\.relationIdLoader/)),
|
|
|
|
- 0,
|
|
|
|
- `return Promise.all(
|
|
|
|
|
|
+replaceInFile({
|
|
|
|
+ filePath: dataLoaderJsPath,
|
|
|
|
+ regex: /return context\.connection\.relationIdLoader[\s\S]+return group\.related;\s+\}\);\s+\}\)/,
|
|
|
|
+ newContent: `return Promise.all(
|
|
entities.map(entity => context.connection.relationLoader.load(relation, entity))
|
|
entities.map(entity => context.connection.relationLoader.load(relation, entity))
|
|
).then(function (results) {
|
|
).then(function (results) {
|
|
return results.map(function (related) {
|
|
return results.map(function (related) {
|
|
return (relation.isManyToOne || relation.isOneToOne) ? related[0] : related
|
|
return (relation.isManyToOne || relation.isOneToOne) ? related[0] : related
|
|
})
|
|
})
|
|
- })
|
|
|
|
- `
|
|
|
|
-)
|
|
|
|
-fs.writeFileSync(dataLoaderJsPath, dataLoaderJsContentLines.join('\n'))
|
|
|
|
|
|
+ })`,
|
|
|
|
+})
|
|
|
|
|
|
// FIXME: Temporary fix for "table name x specified more than once"
|
|
// FIXME: Temporary fix for "table name x specified more than once"
|
|
const baseServiceJsPath = path.resolve(__dirname, '../../../node_modules/@joystream/warthog/dist/core/BaseService.js')
|
|
const baseServiceJsPath = path.resolve(__dirname, '../../../node_modules/@joystream/warthog/dist/core/BaseService.js')
|
|
-const baseServiceJsContent = fs.readFileSync(baseServiceJsPath).toString()
|
|
|
|
-const baseServiceJsContentLines = baseServiceJsContent.split('\n')
|
|
|
|
-baseServiceJsContentLines.splice(
|
|
|
|
- baseServiceJsContentLines.findIndex((l) => l.match(/function common/)) + 1,
|
|
|
|
- 4, // remove 4 lines (function body)
|
|
|
|
- `const uuid = require('uuid/v4')
|
|
|
|
- const foreignTableAlias = uuid().replace('-', '')
|
|
|
|
- var foreingIdColumn = "\\"" + foreignTableAlias + "\\".\\"" + foreignColumnMap[foreignColumnName] + "\\"";
|
|
|
|
- parameters.topLevelQb.leftJoin(foreignTableName, foreignTableAlias, localIdColumn + " = " + foreingIdColumn);
|
|
|
|
- addWhereCondition(parameters, foreignTableAlias, foreignColumnMap);`
|
|
|
|
-)
|
|
|
|
-fs.writeFileSync(baseServiceJsPath, baseServiceJsContentLines.join('\n'))
|
|
|
|
|
|
+replaceInFile({
|
|
|
|
+ filePath: baseServiceJsPath,
|
|
|
|
+ regex: /function common\(parameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName\) \{[^}]+\}/,
|
|
|
|
+ newContent: `function common(parameters, localIdColumn, foreignTableName, foreignColumnMap, foreignColumnName) {
|
|
|
|
+ const uuid = require('uuid/v4')
|
|
|
|
+ const foreignTableAlias = uuid().replace('-', '')
|
|
|
|
+ var foreingIdColumn = "\\"" + foreignTableAlias + "\\".\\"" + foreignColumnMap[foreignColumnName] + "\\"";
|
|
|
|
+ parameters.topLevelQb.leftJoin(foreignTableName, foreignTableAlias, localIdColumn + " = " + foreingIdColumn);
|
|
|
|
+ addWhereCondition(parameters, foreignTableAlias, foreignColumnMap);
|
|
|
|
+ }`,
|
|
|
|
+})
|