Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter config for schemas #415

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
13 changes: 11 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
data
dist
*
!.
!lib
!schemas
!test
!*.js
!*.action
!*.category
!*.domains
!*.form
!*.application
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
{
"files": [".babelrc", ".prettierrc", ".metadocrc"],
"options": { "parser": "json" }
},
{
"files": [
"*.action",
"*.category",
"*.domains",
"*.form",
"*.application"
],
"options": { "parser": "babel" }
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
],
"scripts": {
"test": "npm run lint && metatests test/",
"lint": "eslint . --ignore-path .gitignore && prettier -c \"**/*.js\" \"**/*.json\" \"**/*.md\" \".*rc\" \"**/*.yml\"",
"fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \".*rc\" \"**/*.yml\"",
"lint": "eslint . && prettier -c \"**/*\"",
"fmt": "eslint --fix . && prettier --write \"**/*\"",
"doc": "metadoc",
"build": "babel gs.js -d dist && babel lib -d dist/lib",
"prepublish": "npm run -s build"
Expand Down
28 changes: 28 additions & 0 deletions schemas-eslint-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

module.exports = {
globals: {
api: false,
Action: false,
Many: false,
Master: false,
Validate: false,
Unique: false,
Index: false,
System: false,
Global: false,
Registry: false,
Local: false,
Dictionary: false,
Log: false,
Enum: false,
Flags: false,
Catalog: false,
Subsystem: false,
Form: false,
},
rules: {
strict: 'off',
'new-cap': 'off',
},
};
3 changes: 3 additions & 0 deletions schemas/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extends: '../schemas-eslint-config.js'
globals:
gs: false
2 changes: 1 addition & 1 deletion schemas/system/Action.category
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ System({
CheckPublic: Validate(record => !record.Category !== !record.Public),

NaturalKey: Unique('Category', 'Name'),
})
});
2 changes: 1 addition & 1 deletion schemas/system/Application.category
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System({
Name: { domain: 'Nomen', lookup: true, required: true, unique: true },
Categories: Many('Category'),
})
});
2 changes: 1 addition & 1 deletion schemas/system/Catalog.category
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ System({
Caption: { domain: 'Nomen', lookup: true, required: true, index: true },
Category: { category: 'Category', required: true },
Parent: { category: 'Catalog' },
})
});
4 changes: 2 additions & 2 deletions schemas/system/Category.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ System({
Realm: { domain: 'CategoryRealm', required: true },
Family: { domain: 'CategoryFamily', required: true },
Version: { domain: 'Version', default: 0, required: true },
Master: { category: 'Category' }
})
Master: { category: 'Category' },
});
4 changes: 2 additions & 2 deletions schemas/system/Config.category
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System({
Name: { domain: 'Nomen', lookup: true, required: true, unique: true },
Config: { domain: 'JSON', required: true }
})
Config: { domain: 'JSON', required: true },
});
4 changes: 2 additions & 2 deletions schemas/system/Cursor.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Local({
Created: { domain: 'DateTime', required: true },
Query: { domain: 'JSON', required: true },
Version: { domain: 'Version', default: 0, required: true },
Subscribers: Many('Session')
})
Subscribers: Many('Session'),
});
6 changes: 3 additions & 3 deletions schemas/system/File.category
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Registry({
CompressedSize: { domain: 'DataSize', required: true },
CompressRatio: {
domain: 'Ratio',
expression: record => record.CompressedSize / record.OriginalSize
}
})
expression: record => record.CompressedSize / record.OriginalSize,
},
});
4 changes: 2 additions & 2 deletions schemas/system/Identifier.category
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ Registry({
} else {
return !record.Category;
}
})
})
}),
});
4 changes: 2 additions & 2 deletions schemas/system/Language.category
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Dictionary({
Name: { domain: 'Nomen', lookup: true, required: true, unique: true },
Locale: { domain: 'Nomen', required: true, unique: true }
})
Locale: { domain: 'Nomen', required: true, unique: true },
});
4 changes: 2 additions & 2 deletions schemas/system/Localization.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ System({
Language: { category: 'Language', required: true, index: true },
Text: { domain: 'Text' },

NaturalKey: Unique('ResourceKey', 'Language')
})
NaturalKey: Unique('ResourceKey', 'Language'),
});
33 changes: 18 additions & 15 deletions schemas/system/Locking.category
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
Local({
Identifier: { category: 'Identifier', required: true, index: true },
Session: { category: 'Session', required: true, index: true },
Expand All @@ -7,32 +8,34 @@ Local({
Expire: { domain: 'DateTime', index: true },
Updates: { domain: 'Version', required: true, default: 0 },

Lock: Action(({ Identifier }, callback) => {
Lock: Action(({ Identifier } /*, callback*/) => {
const now = new Date();
gs.create({
Identifier,
Session: client.sessionId,
SystemUser: client.systemUserId,
Request: now
}, (err, data) => {
// to be implemented
});
gs.create(
{
Identifier,
Session: client.sessionId,
SystemUser: client.systemUserId,
Request: now,
},
(/*err, data*/) => {
// to be implemented
}
);
}),

Unlock: Action(({ Identifier }, callback) => {
Unlock: Action(({ Identifier } /*, callback*/) => {
gs.select({
Identifier,
Session: client.sessionId,
SystemUser: client.systemUserId,
Start: gs.notNull,
Expire: gs.Null
}).fetch((err, data) => {
Expire: gs.Null,
}).fetch((/*err, data*/) => {
// to be implemented
});
}),

CheckLock: Action(({ Identifier }, callback) => {
CheckLock: Action((/*{ Identifier }, callback*/) => {
// to be implemented
}),

})
});
2 changes: 1 addition & 1 deletion schemas/system/Log.category
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Log({
Query: { domain: 'JSON' },
Patch: { domain: 'JSON' },
Response: { domain: 'JSON' },
})
});
4 changes: 2 additions & 2 deletions schemas/system/Permission.category
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ System({

NaturalKey: Index('Role', 'Category'),

CheckBound: Validate(record => true)
})
CheckBound: Validate((/*record*/) => true),
});
4 changes: 2 additions & 2 deletions schemas/system/Replication.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ System({
Destination: { category: 'Subsystem', required: true },
Category: { category: 'Category', required: true },

NaturalKey: Unique('Source', 'Destination', 'Category')
})
NaturalKey: Unique('Source', 'Destination', 'Category'),
});
2 changes: 1 addition & 1 deletion schemas/system/Role.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ System({
Blocked: { domain: 'Logical', required: true, default: false },
Subsystem: Subsystem(),
Applications: Many('Application'),
})
});
4 changes: 2 additions & 2 deletions schemas/system/Schema.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ System({
Version: { domain: 'Version', required: true, index: true },
Schema: { domain: 'Source', required: true },

NaturalKey: Unique('Category', 'Version')
})
NaturalKey: Unique('Category', 'Version'),
});
4 changes: 2 additions & 2 deletions schemas/system/Server.category
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ System({
Name: { domain: 'Nomen', display: true, required: true, unique: true },
Suffix: { domain: 'Id', required: true, unique: true },
IP: { domain: 'IP', required: true, unique: true },
ServerType: { domain: 'ServerType', required: true, default: 'Server' }
})
ServerType: { domain: 'ServerType', required: true, default: 'Server' },
});
4 changes: 2 additions & 2 deletions schemas/system/ServerNode.category
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ Local({

UniqueSequence: Unique('Server', 'Instance'),
UniqueProcess: Unique('Server', 'Process'),
UniquePort: Unique('Server', 'Port')
})
UniquePort: Unique('Server', 'Port'),
});
4 changes: 2 additions & 2 deletions schemas/system/Session.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ System({
SystemUser: { category: 'SystemUser', required: true, index: true },
Start: { domain: 'DateTime', required: true },
LastActivity: { domain: 'DateTime', required: true },
LastIP: { domain: 'IP', required: true }
})
LastIP: { domain: 'IP', required: true },
});
2 changes: 1 addition & 1 deletion schemas/system/Subsystem.category
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ System({
Code: { domain: 'Id', required: true, unique: true },
SystemType: { domain: 'SystemType', required: true, default: 'Autonomous' },
Parent: { category: 'Subsystem' },
})
});
4 changes: 2 additions & 2 deletions schemas/system/SystemUser.SignIn.form
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Form({
Login: { domain: 'Login', required: true },
Password: { domain: 'Password', required: true }
})
Password: { domain: 'Password', required: true },
});
6 changes: 3 additions & 3 deletions schemas/system/SystemUser.SignUp.form
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Form({

Check: Validate(record => {
return (
login.length > 5 &&
record.Login.length > 5 &&
record.Password.length > 7 &&
record.Password === record.PasswordConfirm
);
})
})
}),
});
16 changes: 8 additions & 8 deletions schemas/system/SystemUser.category
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
System({
Login: {
domain: 'Login',
Expand All @@ -9,7 +10,7 @@ System({
validate: login => {
// TODO: implement OWASP recomendations
return login.length > 5;
}
},
},
Password: {
domain: 'PasswordHash',
Expand All @@ -19,13 +20,13 @@ System({
// TODO: implement OWASP recomendations
// See https://www.owasp.org/index.php/Authentication_Cheat_Sheet
return Auth.passwordStrength(password);
}
},
},
Subsystem: Subsystem(),
Roles: Many('Role'),
Blocked: { domain: 'Logical', default: false },

SignIn: Action(({ Login, Password }, callback) => {
SignIn: Action((/*{ Login, Password }, callback*/) => {
// Hint: you can use destructing arguments for `data`
// Hint: If we have `FormName.schema` with same name as `ActionName`
// TODO: implement session creation
Expand All @@ -37,12 +38,11 @@ System({
// Hint: Also common and other APIs can be injected here as `api.*`
}),

SignOut: Action((data, callback) => {
SignOut: Action((/*data, callback*/) => {
// TODO: implement remove session
}),

SignUp: Action((data, callback) => {
SignUp: Action((/*data, callback*/) => {
// TODO: implement user registration
})

})
}),
});
29 changes: 22 additions & 7 deletions schemas/system/gs.domains
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
({
Id: {
type: 'object',
class: 'Uint64',
Expand All @@ -9,7 +9,7 @@
);
}
return new api.common.Uint64(x);
}
},
},
Lambda: { type: 'function' },
Logical: { type: 'boolean', control: 'CheckBox' },
Expand Down Expand Up @@ -67,12 +67,27 @@
CountryNumeric: { type: 'string', length: 3, comment: 'ISO 3166-1 numeric' },
Year: { type: 'number', length: 4 },
Month: Enum(
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December'
),
Day: Enum(
'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
'Saturday', 'Sunday'
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
),
Seconds: { type: 'number', unit: 'Second' },
Minutes: { type: 'number', unit: 'Minute', base: 'Second', mul: 60 },
Expand Down Expand Up @@ -115,4 +130,4 @@
Volume: { type: 'number', unit: 'Litre', symbol: 'l' },
Speed: { type: 'number', unit: 'Metres per second', symbol: 'm/s' },
Ratio: { type: 'number' },
}
});
Loading