Skip to content

feat: Add Parse.nodeLogging to fully log Parse.Object #1594

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

Open
wants to merge 4 commits into
base: alpha
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/CoreManager.ts
Original file line number Diff line number Diff line change
@@ -355,6 +355,7 @@ const config: Config & Record<string, any> = {
IDEMPOTENCY: false,
ALLOW_CUSTOM_OBJECT_ID: false,
PARSE_ERRORS: [],
NODE_LOGGING: false,
};

function requireMethods(name: string, methods: string[], controller: any) {
11 changes: 11 additions & 0 deletions src/Parse.ts
Original file line number Diff line number Diff line change
@@ -314,6 +314,17 @@ const Parse = {
return CoreManager.get('ALLOW_CUSTOM_OBJECT_ID');
},

/**
* @property {boolean} Parse.nodeLogging
* @static
*/
set nodeLogging(value) {
CoreManager.set('NODE_LOGGING', value);
},
get nodeLogging() {
return CoreManager.get('NODE_LOGGING');
},

_request(...args) {
return CoreManager.getRESTController().request.apply(null, args);
},
7 changes: 7 additions & 0 deletions src/ParseObject.ts
Original file line number Diff line number Diff line change
@@ -186,6 +186,13 @@ class ParseObject<T extends Attributes = Attributes> {
throw new Error("Can't create an invalid Parse Object");
}
}
if (CoreManager.get('NODE_LOGGING')) {
this[Symbol.for('nodejs.util.inspect.custom')] = function () {
return `ParseObject: className: ${this.className}, id: ${
this.id
}\nAttributes: ${JSON.stringify(this.attributes, null, 2)}`;
};
}
}

/**
7 changes: 7 additions & 0 deletions src/__tests__/Parse-test.js
Original file line number Diff line number Diff line change
@@ -206,6 +206,13 @@ describe('Parse module', () => {
Parse.allowCustomObjectId = false;
});

it('can set nodeLogging', () => {
expect(Parse.nodeLogging).toBe(false);
Parse.nodeLogging = true;
expect(CoreManager.get('NODE_LOGGING')).toBe(true);
Parse.nodeLogging = false;
});

it('getServerHealth', () => {
const controller = {
request: jest.fn(),
10 changes: 10 additions & 0 deletions src/__tests__/ParseObject-test.js
Original file line number Diff line number Diff line change
@@ -4183,4 +4183,14 @@ describe('ParseObject pin', () => {
});
CoreManager.set('ALLOW_CUSTOM_OBJECT_ID', false);
});

it('can log an object', () => {
CoreManager.set('NODE_LOGGING', true);
const o = new ParseObject('Person', { foo: 'bar' });
const symbol = Symbol.for('nodejs.util.inspect.custom');
expect(o[symbol]()).toBe(
`ParseObject: className: Person, id: undefined\nAttributes: {\n \"foo\": \"bar\"\n}`
);
CoreManager.set('NODE_LOGGING', false);
});
});
5 changes: 5 additions & 0 deletions types/Parse.d.ts
Original file line number Diff line number Diff line change
@@ -322,6 +322,11 @@ declare const Parse: {
* @static
*/
allowCustomObjectId: any;
/**
* @property {boolean} Parse.nodeLogging
* @static
*/
nodeLogging: any;
_request(...args: any[]): any;
_ajax(...args: any[]): any;
_decode(_: any, value: any): any;