Merge pull request #64 from specklesystems/dim/server

Commits Update
This commit is contained in:
Dimitrie Stefanescu
2020-12-23 15:04:22 +02:00
committed by GitHub
17 changed files with 729 additions and 661 deletions
+3 -2
View File
@@ -7,7 +7,7 @@
"parserOptions": {
"ecmaVersion": 11
},
"ignorePatterns": ["modules/*/tests/*", "node_modules/*"],
"ignorePatterns": ["node_modules/*"],
"rules": {
"arrow-spacing": [
2,
@@ -26,7 +26,8 @@
],
"space-in-parens": [2, "always"],
"keyword-spacing": 2,
"semi": "off",
"semi": [1, "never"],
"quotes": [1, "single"],
"indent": ["error", 2],
"space-unary-ops": [
2,
+1 -1
View File
@@ -4,4 +4,4 @@ frontend/dist
.nyc_output
coverage/
.env
.vscode
.vscode
-1
View File
@@ -1 +0,0 @@
*.graphql
-29
View File
@@ -1,29 +0,0 @@
{
"vetur.format.defaultFormatterOptions": {
"js-beautify-html": {
"wrap_attributes": "force-expand-multiline"
},
"prettyhtml": {
"printWidth": 100,
"singleQuote": false,
"wrapAttributes": false,
"sortAttributes": false
}
},
"editor.formatOnSave": true,
"vetur.validation.template": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"cSpell.userWords": ["vetur", "vuetify"],
"vetur.format.defaultFormatter.js": "none",
"vetur.format.defaultFormatter.ts": "none",
"[vue]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"eslint.validate": ["vue"]
}
+2
View File
@@ -33,6 +33,8 @@ exports.init = async ( ) => {
SentryInit( app )
// Moves things along automatically on restart.
// Should perhaps be done manually?
await knex.migrate.latest( )
if ( process.env.NODE_ENV !== 'test' ) {
@@ -21,6 +21,10 @@ type Commit {
id: String!
referencedObject: String!
message: String
sourceApplication: String
totalChildrenCount: Int
branchName: String
parents: [String]
authorName: String
authorId: String
authorAvatar: String
@@ -31,6 +35,10 @@ type CommitCollectionUserNode {
id: String!
referencedObject: String!
message: String
sourceApplication: String
totalChildrenCount: Int
branchName: String
parents: [String]
streamId: String
streamName: String
createdAt: DateTime
@@ -140,7 +148,13 @@ input CommitCreateInput {
branchName: String!
objectId: String!
message: String
sourceApplication: String
totalChildrenCount: Int
"""
**DEPRECATED** Use the `parents` field.
"""
previousCommitIds: [String]
parents: [String]
}
input CommitUpdateInput {
+2 -4
View File
@@ -142,10 +142,8 @@ exports.up = async knex => {
table.timestamp( 'createdAt' ).defaultTo( knex.fn.now( ) )
} )
// Commit inheritance table.
// Tracks the inheritance of commits. A commit may have:
// - one ancestor (simple sequential push)
// - more ancestors (result of a merge)
// NOTE: DEPRECATED
// Table is dropped in later migration.
await knex.schema.createTable( 'parent_commits', table => {
table.string( 'parent', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( ).onDelete( 'cascade' )
table.string( 'child', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( ).onDelete( 'cascade' )
@@ -0,0 +1,12 @@
/* istanbul ignore file */
exports.up = async ( knex ) => {
await knex.schema.alterTable( 'commits', table => {
table.string( 'sourceApplication', 1024 )
} )
}
exports.down = async ( knex ) => {
await knex.schema.alterTable( 'commits', table => {
table.dropColumn( 'sourceApplication' )
} )
}
@@ -0,0 +1,12 @@
/* istanbul ignore file */
exports.up = async ( knex ) => {
await knex.schema.alterTable( 'commits', table => {
table.integer( 'totalChildrenCount' )
} )
}
exports.down = async ( knex ) => {
await knex.schema.alterTable( 'commits', table => {
table.dropColumn( 'totalChildrenCount' )
} )
}
@@ -0,0 +1,15 @@
/* istanbul ignore file */
exports.up = async ( knex ) => {
await knex.schema.dropTableIfExists( 'parent_commits' )
await knex.schema.alterTable( 'commits', table => {
table.specificType( 'parents', 'text[]' )
} )
}
exports.down = async ( knex ) => {
let hasColumn = await knex.schema.hasColumn( 'commits', 'parents' )
if ( hasColumn )
await knex.schema.alterTable( 'commits', table => {
table.dropColumn( 'parents' )
} )
}
+40 -33
View File
@@ -11,47 +11,46 @@ const BranchCommits = ( ) => knex( 'branch_commits' )
const ParentCommits = ( ) => knex( 'parent_commits' )
const { getBranchesByStreamId, getBranchByNameAndStreamId } = require( './branches' )
const { getObject } = require( './objects' )
module.exports = {
async createCommitByBranchId( { streamId, branchId, objectId, authorId, message, previousCommitIds } ) {
async createCommitByBranchId( { streamId, branchId, objectId, authorId, message, sourceApplication, totalChildrenCount, parents } ) {
// If no total children count is passed in, get it from the original object
// that this commit references.
if ( !totalChildrenCount ){
let { totalChildrenCount: tc } = await getObject( {objectId} )
totalChildrenCount = tc || 1
}
// Create main table entry
let [ id ] = await Commits( ).returning( 'id' ).insert( {
id: crs( { length: 10 } ),
referencedObject: objectId,
author: authorId,
message: message
sourceApplication,
totalChildrenCount,
parents,
message
} )
// Link it to a branch
await BranchCommits( ).insert( {
branchId: branchId,
commitId: id
} )
await BranchCommits( ).insert( {branchId: branchId, commitId: id} )
// Link it to a stream
await StreamCommits( ).insert( {
streamId: streamId,
commitId: id
} )
// Link it to its children, if any.
if ( Array.isArray( previousCommitIds ) && previousCommitIds.length > 0 ) {
let childrenMap = previousCommitIds.map( childId => { return { parent: id, child: childId } } )
await ParentCommits( ).insert( childrenMap )
}
await StreamCommits( ).insert( {streamId: streamId,commitId: id} )
return id
},
async createCommitByBranchName( { streamId, branchName, objectId, authorId, message, previousCommitIds } ) {
async createCommitByBranchName( { streamId, branchName, objectId, authorId, message, sourceApplication, totalChildrenCount, parents } ) {
branchName = branchName.toLowerCase( )
let myBranch = await getBranchByNameAndStreamId( { streamId: streamId, name: branchName } )
if ( !myBranch )
throw new Error( `Failed to find branch with name ${branchName}.` )
return await module.exports.createCommitByBranchId( { streamId, branchId: myBranch.id, objectId, authorId, message, previousCommitIds } )
return await module.exports.createCommitByBranchId( { streamId, branchId: myBranch.id, objectId, authorId, message, sourceApplication, totalChildrenCount, parents } )
},
async updateCommit( { id, message } ) {
@@ -59,9 +58,16 @@ module.exports = {
},
async getCommitById( { id } ) {
return await Commits( ).columns( [ { id: 'commits.id' }, 'message', 'referencedObject', { authorName: 'name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' }, 'commits.createdAt' ] ).select( )
let query = await Commits( )
.columns( [ { id: 'commits.id' }, 'message', 'referencedObject', 'sourceApplication', 'totalChildrenCount', 'parents', 'commits.createdAt', { branchName: 'branches.name' }, { authorName: 'users.name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' } ] )
.select( )
.join( 'users', 'commits.author', 'users.id' )
.where( { "commits.id": id } ).first( )
.join( 'branch_commits', 'commits.id', 'branch_commits.commitId' )
.join( 'branches', 'branches.id', 'branch_commits.branchId' )
// .leftJoin( 'parent_commits', 'parent_commits.parent', 'commits.id' )
.where( { 'commits.id': id } )
.first( )
return await query
},
async deleteCommit( { id } ) {
@@ -86,12 +92,14 @@ module.exports = {
async getCommitsByBranchId( { branchId, limit, cursor } ) {
limit = limit || 25
let query = BranchCommits( ).columns( [ { id: 'commitId' }, 'message', 'referencedObject', { authorName: 'name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' }, 'commits.createdAt' ] ).select( )
let query = BranchCommits( )
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', 'sourceApplication', 'totalChildrenCount', 'parents', 'commits.createdAt', { branchName: 'branches.name' },{ authorName: 'users.name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' } ] )
.select( )
.join( 'commits', 'commits.id', 'branch_commits.commitId' )
.join( 'users', 'commits.author', 'users.id' )
.join( 'branches', 'branches.id', 'branch_commits.branchId' )
.where( 'branchId', branchId )
if ( cursor )
query.andWhere( 'commits.createdAt', '<', cursor )
@@ -117,20 +125,16 @@ module.exports = {
return parseInt( res.count )
},
/**
* Gets all the commits of a stream.
* @param {[type]} options.streamId [description]
* @param {[type]} options.limit [description]
* @param {[type]} options.cursor [description]
* @return {[type]} [description]
*/
async getCommitsByStreamId( { streamId, limit, cursor } ) {
limit = limit || 25
let query = StreamCommits( )
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', { authorName: 'name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' }, 'commits.createdAt' ] ).select( )
.columns( [ { id: 'commits.id' }, 'message', 'referencedObject', 'sourceApplication', 'totalChildrenCount', 'parents', 'commits.createdAt', { branchName: 'branches.name' }, { authorName: 'users.name' }, { authorId: 'users.id' }, { authorAvatar: 'users.avatar' } ] )
.select( )
.join( 'commits', 'commits.id', 'stream_commits.commitId' )
.join( 'users', 'commits.author', 'users.id' )
.where( 'streamId', streamId )
.join( 'branch_commits', 'commits.id', 'branch_commits.commitId' )
.join( 'branches', 'branches.id', 'branch_commits.branchId' )
.where( 'stream_commits.streamId', streamId )
if ( cursor )
@@ -148,9 +152,12 @@ module.exports = {
let query =
Commits( )
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', 'commits.createdAt', { streamId: 'stream_commits.streamId' }, { streamName: 'streams.name' } ] ).select( )
.columns( [ { id: 'commits.id' }, 'message', 'referencedObject', 'sourceApplication', 'totalChildrenCount', 'parents', 'commits.createdAt', { branchName: 'branches.name' }, { streamId: 'stream_commits.streamId' }, { streamName: 'streams.name' } ] )
.select( )
.join( 'stream_commits', 'commits.id', 'stream_commits.commitId' )
.join( 'streams', 'stream_commits.streamId', 'streams.id' )
.join( 'branch_commits', 'commits.id', 'branch_commits.commitId' )
.join( 'branches', 'branches.id', 'branch_commits.branchId' )
.where( 'author', userId )
if ( publicOnly )
+1 -1
View File
@@ -129,7 +129,7 @@ module.exports = {
token_scopes
JOIN api_tokens ON "api_tokens"."id" = "token_scopes"."tokenId"
GROUP BY
token_scopes. "tokenId") ts USING (id)
token_scopes. "tokenId" ) ts USING (id)
WHERE
t.id IN(
SELECT
+1 -1
View File
@@ -22,7 +22,7 @@ const {
deleteBranchById
} = require( '../services/branches' )
describe( 'Branches', ( ) => {
describe( 'Branches @core-branches', ( ) => {
let user = {
name: 'Dimitrie Stefanescu',
+47 -8
View File
@@ -31,7 +31,7 @@ const {
getCommitsTotalCountByUserId
} = require( '../services/commits' )
describe( 'Commits', ( ) => {
describe( 'Commits @core-commits', ( ) => {
let user = {
name: 'Dimitrie Stefanescu',
@@ -76,15 +76,15 @@ describe( 'Commits', ( ) => {
let commitId1, commitId2, commitId3
it( 'Should create a commit by branch name', async ( ) => {
commitId1 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'first commit', objectId: testObject.id, authorId: user.id } )
commitId1 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'first commit', sourceApplication: 'tests', objectId: testObject.id, authorId: user.id, sourceApplication: 'tests' } )
expect( commitId1 ).to.be.a.string
} )
it( 'Should create a commit with a previous commit id', async ( ) => {
commitId2 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'second commit', objectId: testObject2.id, authorId: user.id, previousCommitIds: [ commitId1 ] } )
commitId2 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'second commit', sourceApplication: 'tests', objectId: testObject2.id, authorId: user.id, parents: [ commitId1 ] } )
expect( commitId2 ).to.be.a.string
commitId3 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'third commit', objectId: testObject3.id, authorId: user.id, previousCommitIds: [ commitId1, commitId2 ] } )
commitId3 = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'third commit', sourceApplication: 'tests', objectId: testObject3.id, authorId: user.id, parents: [ commitId1, commitId2 ] } )
expect( commitId3 ).to.be.a.string
} )
@@ -95,7 +95,7 @@ describe( 'Commits', ( ) => {
} )
it( 'Should delete a commit', async ( ) => {
let tempCommit = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'temp commit', objectId: testObject.id, authorId: user.id } )
let tempCommit = await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: 'temp commit', sourceApplication: 'tests', objectId: testObject.id, authorId: user.id } )
let res = await deleteCommit( { id: tempCommit } )
expect( res ).to.equal( 1 )
@@ -112,7 +112,7 @@ describe( 'Commits', ( ) => {
for ( let i = 0; i < 10; i++ ) {
let t = { qux: i }
t.id = await createObject( t )
await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: `commit # ${i+3}`, objectId: t.id, authorId: user.id } )
await createCommitByBranchName( { streamId: stream.id, branchName: 'main', message: `commit # ${i+3}`, sourceApplication: 'tests', objectId: t.id, authorId: user.id } )
}
let { commits, cursor } = await getCommitsByBranchName( { streamId: stream.id, branchName: 'main', limit: 2 } )
@@ -130,10 +130,12 @@ describe( 'Commits', ( ) => {
it( 'Should get the commits from a stream', async ( ) => {
await createBranch( { name: 'dim/dev', streamId: stream.id, authorId: user.id } )
let prevId
for ( let i = 0; i < 10; i++ ) {
let t = { thud: i }
t.id = await createObject( t )
await createCommitByBranchName( { streamId: stream.id, branchName: 'dim/dev', message: `pushed something # ${i+3}`, objectId: t.id, authorId: user.id } )
await createCommitByBranchName( { streamId: stream.id, branchName: 'dim/dev', message: `pushed something # ${i+3}`, sourceApplication: 'tests', objectId: t.id, authorId: user.id } )
}
let { commits, cursor } = await getCommitsByStreamId( { streamId: stream.id, limit: 10 } )
@@ -159,7 +161,7 @@ describe( 'Commits', ( ) => {
it( 'Should get the public commits of an user only', async ( ) => {
let privateStreamId = await createStream( { name: 'private', isPublic: false, ownerId: user.id } )
let commitId = await createCommitByBranchName( { streamId: privateStreamId, branchName: 'main', message: 'first commit', objectId: testObject.id, authorId: user.id } )
let commitId = await createCommitByBranchName( { streamId: privateStreamId, branchName: 'main', message: 'first commit', sourceApplication: 'tests', objectId: testObject.id, authorId: user.id } )
let { commits, cursor } = await getCommitsByUserId( { userId: user.id, limit: 1000 } )
expect( commits.length ).to.equal( 23 )
@@ -170,5 +172,42 @@ describe( 'Commits', ( ) => {
expect( c ).to.equal( 24 )
} )
it( 'Commits should have source, total count, branch name and parents fields', async() => {
let { commits: userCommits } = await getCommitsByUserId( { userId: user.id, limit: 1000 } )
let userCommit = userCommits[0]
let { commits: streamCommits } = await getCommitsByStreamId( { streamId: stream.id, limit: 10 } )
let serverCommit = streamCommits[0]
let { commits: branchCommits } = await getCommitsByBranchName( { streamId: stream.id, branchName: 'main', limit: 2 } )
let branchCommit = branchCommits[0]
let idCommit = await getCommitById( {id: commitId3 } )
for ( let commit of [ userCommit, serverCommit, branchCommit, idCommit ] ) {
expect( commit ).to.have.property( 'sourceApplication' )
expect( commit.sourceApplication ).to.be.a( 'string' )
expect( commit ).to.have.property( 'totalChildrenCount' )
expect( commit.totalChildrenCount ).to.be.a( 'number' )
expect( commit ).to.have.property( 'branchName' )
expect( commit.branchName ).to.be.a( 'string' )
expect( commit ).to.have.property( 'parents' )
}
expect( idCommit.parents ).to.be.a( 'array' )
expect( idCommit.parents.length ).to.equal( 2 )
} )
it( 'Should have an array of parents', async() => {
let commits = [ await getCommitById( {id: commitId3 } ), await await getCommitById( {id: commitId2 } ) ]
for ( let commit of commits ) {
expect( commit ).to.have.property( 'parents' )
expect( commit.parents ).to.be.a( 'array' )
expect( commit.parents.length ).to.greaterThan( 0 )
}
} )
} )
+1 -1
View File
@@ -47,7 +47,7 @@ let sampleObject = JSON.parse( `{
"speckleType": "Tests.Polyline"
}` )
describe( 'Objects', ( ) => {
describe( 'Objects @core-objects', ( ) => {
let userOne = {
name: 'Dimitrie Stefanescu',
+562 -564
View File
File diff suppressed because it is too large Load Diff
+16 -16
View File
@@ -19,10 +19,10 @@
"test:server": "cross-env PORT=3001 NODE_ENV=test nyc nyc --reporter html --reporter lcovonly mocha -s 0 --timeout 10000 --exit"
},
"dependencies": {
"@sentry/node": "^5.22.3",
"@sentry/tracing": "^5.22.3",
"apollo-server-express": "^2.17.0",
"apollo-server-testing": "^2.12.0",
"@sentry/node": "^5.29.2",
"@sentry/tracing": "^5.29.2",
"apollo-server-express": "^2.19.0",
"apollo-server-testing": "^2.19.0",
"app-root-path": "^3.0.0",
"auto-load": "^3.0.4",
"bcrypt": "^5.0.0",
@@ -31,17 +31,17 @@
"compression": "^1.7.4",
"connect-redis": "^4.0.4",
"crypto-random-string": "^3.2.0",
"debug": "^4.1.1",
"debug": "^4.3.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-session": "^1.17.1",
"graphql": "^14.6.0",
"graphql-redis-subscriptions": "^2.2.2",
"graphql-scalars": "^1.1.0",
"graphql-scalars": "^1.6.1",
"graphql-tag": "^2.11.0",
"graphql-tools": "^4.0.7",
"ioredis": "^4.17.3",
"knex": "^0.21.5",
"ioredis": "^4.19.4",
"knex": "^0.21.14",
"lodash.chunk": "^4.2.0",
"lodash.debounce": "^4.0.8",
"lodash.get": "^4.4.2",
@@ -55,13 +55,13 @@
"passport-github2": "^0.1.12",
"passport-google-oauth2": "^0.2.0",
"passport-google-oauth20": "^2.0.0",
"pg": "^8.3.3",
"pg-query-stream": "^3.2.3",
"pg": "^8.5.1",
"pg-query-stream": "^3.4.2",
"redis": "^3.0.2",
"zxcvbn": "^4.4.2"
},
"devDependencies": {
"@apollo/client": "^3.1.3",
"@apollo/client": "^3.3.6",
"apollo-cache-inmemory": "^1.6.6",
"apollo-client": "^2.6.10",
"apollo-link": "^1.2.14",
@@ -70,16 +70,16 @@
"chai": "^4.2.0",
"chai-http": "^4.3.0",
"concurrently": "^5.2.0",
"cross-env": "^7.0.2",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.1.0",
"eslint": "^7.5.0",
"http-proxy-middleware": "^1.0.4",
"eslint": "^7.16.0",
"http-proxy-middleware": "^1.0.6",
"mocha": "^7.2.0",
"node-fetch": "^2.6.1",
"nodemon": "^2.0.4",
"nodemon": "^2.0.6",
"nyc": "^15.0.1",
"supertest": "^4.0.2",
"ws": "^7.3.1"
"ws": "^7.4.1"
},
"config": {
"commitizen": {