From e3284a71dd6399cab78105f64ac8c68ddda4b021 Mon Sep 17 00:00:00 2001 From: dblythy Date: Thu, 3 Nov 2022 15:13:23 +1100 Subject: [PATCH 1/2] feat: Add `Parse.nodeLogging` to fully log Parse.Object --- src/CoreManager.js | 1 + src/Parse.js | 11 +++++++++++ src/ParseObject.js | 7 +++++++ src/__tests__/Parse-test.js | 7 +++++++ src/__tests__/ParseObject-test.js | 10 ++++++++++ 5 files changed, 36 insertions(+) diff --git a/src/CoreManager.js b/src/CoreManager.js index 188970e5c..41e783bbd 100644 --- a/src/CoreManager.js +++ b/src/CoreManager.js @@ -201,6 +201,7 @@ const config: Config & { [key: string]: mixed } = { ENCRYPTED_USER: false, IDEMPOTENCY: false, ALLOW_CUSTOM_OBJECT_ID: false, + NODE_LOGGING: false, }; function requireMethods(name: string, methods: Array, controller: any) { diff --git a/src/Parse.js b/src/Parse.js index 548fbfd6e..4c2261fe0 100644 --- a/src/Parse.js +++ b/src/Parse.js @@ -209,6 +209,17 @@ const Parse = { get allowCustomObjectId() { return CoreManager.get('ALLOW_CUSTOM_OBJECT_ID'); }, + + /** + * @member {boolean} Parse.nodeLogging + * @static + */ + set nodeLogging(value) { + CoreManager.set('NODE_LOGGING', value); + }, + get nodeLogging() { + return CoreManager.get('NODE_LOGGING'); + }, }; Parse.ACL = require('./ParseACL').default; diff --git a/src/ParseObject.js b/src/ParseObject.js index 6e838b72a..06dd29522 100644 --- a/src/ParseObject.js +++ b/src/ParseObject.js @@ -143,6 +143,13 @@ class ParseObject { if (toSet && !this.set(toSet, options)) { 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)}`; + }; + } } /** diff --git a/src/__tests__/Parse-test.js b/src/__tests__/Parse-test.js index c33502842..71d786ac2 100644 --- a/src/__tests__/Parse-test.js +++ b/src/__tests__/Parse-test.js @@ -195,6 +195,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(), diff --git a/src/__tests__/ParseObject-test.js b/src/__tests__/ParseObject-test.js index 0e35f56be..94e9d3689 100644 --- a/src/__tests__/ParseObject-test.js +++ b/src/__tests__/ParseObject-test.js @@ -3836,4 +3836,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); + }); }); From cd7cf2efff490dc3c198a81095237a09a9233ebb Mon Sep 17 00:00:00 2001 From: Diamond Lewis Date: Thu, 17 Apr 2025 11:35:39 -0500 Subject: [PATCH 2/2] build types --- src/CoreManager.ts | 1 + src/Parse.ts | 11 +++++++++++ types/Parse.d.ts | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/src/CoreManager.ts b/src/CoreManager.ts index 03e2b6002..cdf1f1527 100644 --- a/src/CoreManager.ts +++ b/src/CoreManager.ts @@ -355,6 +355,7 @@ const config: Config & Record = { IDEMPOTENCY: false, ALLOW_CUSTOM_OBJECT_ID: false, PARSE_ERRORS: [], + NODE_LOGGING: false, }; function requireMethods(name: string, methods: string[], controller: any) { diff --git a/src/Parse.ts b/src/Parse.ts index 67e55b063..bd94d01b4 100644 --- a/src/Parse.ts +++ b/src/Parse.ts @@ -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); }, diff --git a/types/Parse.d.ts b/types/Parse.d.ts index 8eb283059..75af2561b 100644 --- a/types/Parse.d.ts +++ b/types/Parse.d.ts @@ -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;