Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(datastore): tweak cli to fix end-to-end test
- Loading branch information
1 parent
c8b6c8a
commit 4355cd1
Showing
18 changed files
with
215 additions
and
207 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
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
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
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
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,38 @@ | ||
import CreditsStore from '@ulixee/datastore/lib/CreditsStore'; | ||
import DatastoreApiClient from '@ulixee/datastore/lib/DatastoreApiClient'; | ||
import { execAndLog } from '../utils'; | ||
|
||
export default async function main( | ||
datastore: { | ||
credits: { id: string; secret: string; remainingCredits: number }; | ||
minerHost: string; | ||
datastoreHash: string; | ||
}, | ||
rootDir: string, | ||
): Promise<void> { | ||
const { datastoreHash, credits, minerHost } = datastore; | ||
|
||
execAndLog( | ||
`npx @ulixee/datastore credits install ${minerHost}/${datastoreHash}/credits/${credits.id} ${credits.secret}`, | ||
{ | ||
cwd: rootDir, | ||
stdio: 'inherit', | ||
}, | ||
); | ||
|
||
const datastoreClient = new DatastoreApiClient(minerHost); | ||
const pricing = await datastoreClient.getFunctionPricing(datastoreHash, 'default'); | ||
const payment = await CreditsStore.getPayment(datastoreHash, pricing.minimumPrice); | ||
|
||
const result = await datastoreClient.query(datastoreHash, 'SELECT * FROM default(test => $1)', { | ||
boundValues: [1], | ||
payment, | ||
}); | ||
|
||
console.log('Result of datastore query is:', result); | ||
|
||
execAndLog(`npx @ulixee/datastore credits get ${minerHost}/${datastoreHash} ${credits.id}`, { | ||
cwd: rootDir, | ||
stdio: 'inherit', | ||
}); | ||
} |
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,12 @@ | ||
import Datastore, { Function } from '@ulixee/datastore'; | ||
|
||
export default new Datastore({ | ||
functions: { | ||
default: new Function({ | ||
pricePerQuery: 50e4, // ~50 cents | ||
run(ctx) { | ||
ctx.Output.emit({ success: true, input: ctx.input }); | ||
}, | ||
}), | ||
}, | ||
}); |
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,75 @@ | ||
import { spawn } from 'child_process'; | ||
import * as Path from 'path'; | ||
import * as assert from 'assert'; | ||
import { execAndLog, getMinerHost } from '../utils'; | ||
|
||
export default async function main( | ||
needsClosing: (() => Promise<any> | any)[], | ||
rootDir: string, | ||
): Promise<{ | ||
credits: { id: string; secret: string; remainingCredits: number }; | ||
minerHost: string; | ||
datastoreHash: string; | ||
}> { | ||
// CREATE IDENTITIES | ||
const identityPath = Path.resolve(`${__dirname}/identities/DatastoreDev.json`); | ||
execAndLog(`npx @ulixee/crypto identity --filename="${identityPath}"`, { | ||
stdio: 'inherit', | ||
}); | ||
|
||
const identityBech32 = execAndLog( | ||
`npx @ulixee/crypto read-identity --filename="${identityPath}"`, | ||
); | ||
assert(identityBech32, 'Must be a valid identity'); | ||
|
||
// BOOT UP A MINER WITH GIFT CARD RESTRICTIONS | ||
const miner = spawn(`npx @ulixee/miner start`, { | ||
stdio: 'pipe', | ||
cwd: rootDir, | ||
shell: true, | ||
env: { | ||
...process.env, | ||
ULX_SERVER_ADMIN_IDENTITIES: identityBech32, | ||
ULX_IDENTITY_PATH: identityPath, | ||
ULX_DISABLE_CHROMEALIVE: 'true', | ||
}, | ||
}); | ||
const minerHost = await getMinerHost(miner); | ||
needsClosing.push(() => miner.kill()); | ||
|
||
// For some reason, nodejs is taking CWD, but then going to closest package.json, so have to prefix with ./credits | ||
const datastoreResult = execAndLog( | ||
`npx @ulixee/datastore deploy ./credits/datastore/index.js -h ${minerHost}`, | ||
{ | ||
cwd: __dirname, | ||
env: { | ||
...process.env, | ||
ULX_IDENTITY_PATH: identityPath, | ||
}, | ||
}, | ||
); | ||
|
||
console.log(datastoreResult); | ||
const datastoreMatch = datastoreResult.match(/'dbx1(?:[0-9a-z]+)'/g); | ||
const datastoreHash = datastoreMatch[0].trim().replace(/'/g, ''); | ||
console.log('Datastore VersionHash', datastoreHash); | ||
|
||
const creditResult = execAndLog( | ||
`npx @ulixee/datastore credits create ${minerHost}/${datastoreHash} -m 500c`, | ||
{ | ||
cwd: __dirname, | ||
env: { | ||
...process.env, | ||
ULX_IDENTITY_PATH: identityPath, | ||
}, | ||
}, | ||
); | ||
const credits = JSON.parse(creditResult); | ||
console.log('Store Credits:', credits); | ||
|
||
return { | ||
credits: credits.credit, | ||
datastoreHash, | ||
minerHost, | ||
}; | ||
} |
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,28 @@ | ||
import '@ulixee/commons/lib/SourceMapSupport'; | ||
import * as Path from 'path'; | ||
import datastoreDev from './datastoreDev'; | ||
import dataUser from './dataUser'; | ||
|
||
async function main(): Promise<void> { | ||
const needsClosing: (() => Promise<any> | any)[] = []; | ||
let root = __dirname; | ||
while (!root.endsWith('/ulixee')) { | ||
root = Path.dirname(root); | ||
if (root === '/') throw new Error('Root project not found'); | ||
} | ||
|
||
const buildDir = Path.join(root, 'build'); | ||
try { | ||
const result = await datastoreDev(needsClosing, buildDir); | ||
await dataUser(result, buildDir); | ||
console.log('Completed!') | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
for (const closer of needsClosing) { | ||
await closer(); | ||
} | ||
process.exit(); | ||
} | ||
|
||
main().catch(console.error); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.