fix(prettier): Properly handle lint-stage files (#6970)
Now handles top level files and recursive files in folders. Set max line length to be 100
This commit is contained in:
@@ -93,11 +93,7 @@ class ParseLiveQueryServer {
|
||||
} else if (channel === Parse.applicationId + 'afterDelete') {
|
||||
this._onAfterDelete(message);
|
||||
} else {
|
||||
logger.error(
|
||||
'Get message %s from unknown channel %j',
|
||||
message,
|
||||
channel
|
||||
);
|
||||
logger.error('Get message %s from unknown channel %j', message, channel);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -131,11 +127,7 @@ class ParseLiveQueryServer {
|
||||
let deletedParseObject = message.currentParseObject.toJSON();
|
||||
const classLevelPermissions = message.classLevelPermissions;
|
||||
const className = deletedParseObject.className;
|
||||
logger.verbose(
|
||||
'ClassName: %j | ObjectId: %s',
|
||||
className,
|
||||
deletedParseObject.id
|
||||
);
|
||||
logger.verbose('ClassName: %j | ObjectId: %s', className, deletedParseObject.id);
|
||||
logger.verbose('Current client number : %d', this.clients.size);
|
||||
|
||||
const classSubscriptions = this.subscriptions.get(className);
|
||||
@@ -144,16 +136,11 @@ class ParseLiveQueryServer {
|
||||
return;
|
||||
}
|
||||
for (const subscription of classSubscriptions.values()) {
|
||||
const isSubscriptionMatched = this._matchesSubscription(
|
||||
deletedParseObject,
|
||||
subscription
|
||||
);
|
||||
const isSubscriptionMatched = this._matchesSubscription(deletedParseObject, subscription);
|
||||
if (!isSubscriptionMatched) {
|
||||
continue;
|
||||
}
|
||||
for (const [clientId, requestIds] of _.entries(
|
||||
subscription.clientRequestIds
|
||||
)) {
|
||||
for (const [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
|
||||
const client = this.clients.get(clientId);
|
||||
if (typeof client === 'undefined') {
|
||||
continue;
|
||||
@@ -163,13 +150,7 @@ class ParseLiveQueryServer {
|
||||
// Check CLP
|
||||
const op = this._getCLPOperation(subscription.query);
|
||||
let res = {};
|
||||
this._matchesCLP(
|
||||
classLevelPermissions,
|
||||
message.currentParseObject,
|
||||
client,
|
||||
requestId,
|
||||
op
|
||||
)
|
||||
this._matchesCLP(classLevelPermissions, message.currentParseObject, client, requestId, op)
|
||||
.then(() => {
|
||||
// Check ACL
|
||||
return this._matchesACL(acl, client, requestId);
|
||||
@@ -230,11 +211,7 @@ class ParseLiveQueryServer {
|
||||
const classLevelPermissions = message.classLevelPermissions;
|
||||
let currentParseObject = message.currentParseObject.toJSON();
|
||||
const className = currentParseObject.className;
|
||||
logger.verbose(
|
||||
'ClassName: %s | ObjectId: %s',
|
||||
className,
|
||||
currentParseObject.id
|
||||
);
|
||||
logger.verbose('ClassName: %s | ObjectId: %s', className, currentParseObject.id);
|
||||
logger.verbose('Current client number : %d', this.clients.size);
|
||||
|
||||
const classSubscriptions = this.subscriptions.get(className);
|
||||
@@ -251,9 +228,7 @@ class ParseLiveQueryServer {
|
||||
currentParseObject,
|
||||
subscription
|
||||
);
|
||||
for (const [clientId, requestIds] of _.entries(
|
||||
subscription.clientRequestIds
|
||||
)) {
|
||||
for (const [clientId, requestIds] of _.entries(subscription.clientRequestIds)) {
|
||||
const client = this.clients.get(clientId);
|
||||
if (typeof client === 'undefined') {
|
||||
continue;
|
||||
@@ -269,11 +244,7 @@ class ParseLiveQueryServer {
|
||||
if (message.originalParseObject) {
|
||||
originalACL = message.originalParseObject.getACL();
|
||||
}
|
||||
originalACLCheckingPromise = this._matchesACL(
|
||||
originalACL,
|
||||
client,
|
||||
requestId
|
||||
);
|
||||
originalACLCheckingPromise = this._matchesACL(originalACL, client, requestId);
|
||||
}
|
||||
// Set current ParseObject ACL checking promise, if the object does not match
|
||||
// subscription, we do not need to check ACL
|
||||
@@ -283,25 +254,12 @@ class ParseLiveQueryServer {
|
||||
currentACLCheckingPromise = Promise.resolve(false);
|
||||
} else {
|
||||
const currentACL = message.currentParseObject.getACL();
|
||||
currentACLCheckingPromise = this._matchesACL(
|
||||
currentACL,
|
||||
client,
|
||||
requestId
|
||||
);
|
||||
currentACLCheckingPromise = this._matchesACL(currentACL, client, requestId);
|
||||
}
|
||||
const op = this._getCLPOperation(subscription.query);
|
||||
this._matchesCLP(
|
||||
classLevelPermissions,
|
||||
message.currentParseObject,
|
||||
client,
|
||||
requestId,
|
||||
op
|
||||
)
|
||||
this._matchesCLP(classLevelPermissions, message.currentParseObject, client, requestId, op)
|
||||
.then(() => {
|
||||
return Promise.all([
|
||||
originalACLCheckingPromise,
|
||||
currentACLCheckingPromise,
|
||||
]);
|
||||
return Promise.all([originalACLCheckingPromise, currentACLCheckingPromise]);
|
||||
})
|
||||
.then(([isOriginalMatched, isCurrentMatched]) => {
|
||||
logger.verbose(
|
||||
@@ -350,22 +308,16 @@ class ParseLiveQueryServer {
|
||||
}
|
||||
if (res.object && typeof res.object.toJSON === 'function') {
|
||||
currentParseObject = res.object.toJSON();
|
||||
currentParseObject.className =
|
||||
res.object.className || className;
|
||||
currentParseObject.className = res.object.className || className;
|
||||
}
|
||||
|
||||
if (res.original && typeof res.original.toJSON === 'function') {
|
||||
originalParseObject = res.original.toJSON();
|
||||
originalParseObject.className =
|
||||
res.original.className || className;
|
||||
originalParseObject.className = res.original.className || className;
|
||||
}
|
||||
const functionName = 'push' + message.event;
|
||||
if (client[functionName]) {
|
||||
client[functionName](
|
||||
requestId,
|
||||
currentParseObject,
|
||||
originalParseObject
|
||||
);
|
||||
client[functionName](requestId, currentParseObject, originalParseObject);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
@@ -447,16 +399,12 @@ class ParseLiveQueryServer {
|
||||
this.clients.delete(clientId);
|
||||
|
||||
// Delete client from subscriptions
|
||||
for (const [requestId, subscriptionInfo] of _.entries(
|
||||
client.subscriptionInfos
|
||||
)) {
|
||||
for (const [requestId, subscriptionInfo] of _.entries(client.subscriptionInfos)) {
|
||||
const subscription = subscriptionInfo.subscription;
|
||||
subscription.deleteClientSubscription(clientId, requestId);
|
||||
|
||||
// If there is no client which is subscribing this subscription, remove it from subscriptions
|
||||
const classSubscriptions = this.subscriptions.get(
|
||||
subscription.className
|
||||
);
|
||||
const classSubscriptions = this.subscriptions.get(subscription.className);
|
||||
if (!subscription.hasSubscribingClient()) {
|
||||
classSubscriptions.delete(subscription.hash);
|
||||
}
|
||||
@@ -492,9 +440,7 @@ class ParseLiveQueryServer {
|
||||
return matchesQuery(parseObject, subscription.query);
|
||||
}
|
||||
|
||||
getAuthForSessionToken(
|
||||
sessionToken: ?string
|
||||
): Promise<{ auth: ?Auth, userId: ?string }> {
|
||||
getAuthForSessionToken(sessionToken: ?string): Promise<{ auth: ?Auth, userId: ?string }> {
|
||||
if (!sessionToken) {
|
||||
return Promise.resolve({});
|
||||
}
|
||||
@@ -514,11 +460,7 @@ class ParseLiveQueryServer {
|
||||
const result = {};
|
||||
if (error && error.code === Parse.Error.INVALID_SESSION_TOKEN) {
|
||||
result.error = error;
|
||||
this.authCache.set(
|
||||
sessionToken,
|
||||
Promise.resolve(result),
|
||||
this.config.cacheTimeout
|
||||
);
|
||||
this.authCache.set(sessionToken, Promise.resolve(result), this.config.cacheTimeout);
|
||||
} else {
|
||||
this.authCache.del(sessionToken);
|
||||
}
|
||||
@@ -540,9 +482,7 @@ class ParseLiveQueryServer {
|
||||
const aclGroup = ['*'];
|
||||
let userId;
|
||||
if (typeof subscriptionInfo !== 'undefined') {
|
||||
const { userId } = await this.getAuthForSessionToken(
|
||||
subscriptionInfo.sessionToken
|
||||
);
|
||||
const { userId } = await this.getAuthForSessionToken(subscriptionInfo.sessionToken);
|
||||
if (userId) {
|
||||
aclGroup.push(userId);
|
||||
}
|
||||
@@ -602,9 +542,7 @@ class ParseLiveQueryServer {
|
||||
return Promise.resolve()
|
||||
.then(async () => {
|
||||
// Resolve false right away if the acl doesn't have any roles
|
||||
const acl_has_roles = Object.keys(acl.permissionsById).some(key =>
|
||||
key.startsWith('role:')
|
||||
);
|
||||
const acl_has_roles = Object.keys(acl.permissionsById).some(key => key.startsWith('role:'));
|
||||
if (!acl_has_roles) {
|
||||
return false;
|
||||
}
|
||||
@@ -624,11 +562,7 @@ class ParseLiveQueryServer {
|
||||
});
|
||||
}
|
||||
|
||||
async _matchesACL(
|
||||
acl: any,
|
||||
client: any,
|
||||
requestId: number
|
||||
): Promise<boolean> {
|
||||
async _matchesACL(acl: any, client: any, requestId: number): Promise<boolean> {
|
||||
// Return true directly if ACL isn't present, ACL is public read, or client has master key
|
||||
if (!acl || acl.getPublicReadAccess() || client.hasMasterKey) {
|
||||
return true;
|
||||
@@ -685,12 +619,7 @@ class ParseLiveQueryServer {
|
||||
client.pushConnect();
|
||||
runLiveQueryEventHandlers(req);
|
||||
} catch (error) {
|
||||
Client.pushError(
|
||||
parseWebsocket,
|
||||
error.code || 141,
|
||||
error.message || error,
|
||||
false
|
||||
);
|
||||
Client.pushError(parseWebsocket, error.code || 141, error.message || error, false);
|
||||
logger.error(
|
||||
`Failed running beforeConnect for session ${request.sessionToken} with:\n Error: ` +
|
||||
JSON.stringify(error)
|
||||
@@ -699,17 +628,10 @@ class ParseLiveQueryServer {
|
||||
}
|
||||
|
||||
_hasMasterKey(request: any, validKeyPairs: any): boolean {
|
||||
if (
|
||||
!validKeyPairs ||
|
||||
validKeyPairs.size == 0 ||
|
||||
!validKeyPairs.has('masterKey')
|
||||
) {
|
||||
if (!validKeyPairs || validKeyPairs.size == 0 || !validKeyPairs.has('masterKey')) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
!request ||
|
||||
!Object.prototype.hasOwnProperty.call(request, 'masterKey')
|
||||
) {
|
||||
if (!request || !Object.prototype.hasOwnProperty.call(request, 'masterKey')) {
|
||||
return false;
|
||||
}
|
||||
return request.masterKey === validKeyPairs.get('masterKey');
|
||||
@@ -738,9 +660,7 @@ class ParseLiveQueryServer {
|
||||
2,
|
||||
'Can not find this client, make sure you connect to server before subscribing'
|
||||
);
|
||||
logger.error(
|
||||
'Can not find this client, make sure you connect to server before subscribing'
|
||||
);
|
||||
logger.error('Can not find this client, make sure you connect to server before subscribing');
|
||||
return;
|
||||
}
|
||||
const client = this.clients.get(parseWebsocket.clientId);
|
||||
@@ -760,11 +680,7 @@ class ParseLiveQueryServer {
|
||||
if (classSubscriptions.has(subscriptionHash)) {
|
||||
subscription = classSubscriptions.get(subscriptionHash);
|
||||
} else {
|
||||
subscription = new Subscription(
|
||||
className,
|
||||
request.query.where,
|
||||
subscriptionHash
|
||||
);
|
||||
subscription = new Subscription(className, request.query.where, subscriptionHash);
|
||||
classSubscriptions.set(subscriptionHash, subscription);
|
||||
}
|
||||
|
||||
@@ -782,10 +698,7 @@ class ParseLiveQueryServer {
|
||||
client.addSubscriptionInfo(request.requestId, subscriptionInfo);
|
||||
|
||||
// Add clientId to subscription
|
||||
subscription.addClientSubscription(
|
||||
parseWebsocket.clientId,
|
||||
request.requestId
|
||||
);
|
||||
subscription.addClientSubscription(parseWebsocket.clientId, request.requestId);
|
||||
|
||||
client.pushSubscribe(request.requestId);
|
||||
|
||||
@@ -803,13 +716,7 @@ class ParseLiveQueryServer {
|
||||
installationId: client.installationId,
|
||||
});
|
||||
} catch (e) {
|
||||
Client.pushError(
|
||||
parseWebsocket,
|
||||
e.code || 141,
|
||||
e.message || e,
|
||||
false,
|
||||
request.requestId
|
||||
);
|
||||
Client.pushError(parseWebsocket, e.code || 141, e.message || e, false, request.requestId);
|
||||
logger.error(
|
||||
`Failed running beforeSubscribe on ${className} for session ${request.sessionToken} with:\n Error: ` +
|
||||
JSON.stringify(e)
|
||||
@@ -822,11 +729,7 @@ class ParseLiveQueryServer {
|
||||
this._handleSubscribe(parseWebsocket, request);
|
||||
}
|
||||
|
||||
_handleUnsubscribe(
|
||||
parseWebsocket: any,
|
||||
request: any,
|
||||
notifyClient: boolean = true
|
||||
): any {
|
||||
_handleUnsubscribe(parseWebsocket: any, request: any, notifyClient: boolean = true): any {
|
||||
// If we can not find this client, return error to client
|
||||
if (!Object.prototype.hasOwnProperty.call(parseWebsocket, 'clientId')) {
|
||||
Client.pushError(
|
||||
|
||||
Reference in New Issue
Block a user