flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

Nuxt | Generate timestamp errors warning for each entry made in flamelink schema. #80

Closed JamesDevGit closed 4 years ago

JamesDevGit commented 5 years ago

I am testing a Nuxt flamelink setup, using cloud firestore and not rtdb. I am having a few issues getting results on page correctly.

flamelink@next

current pkg

"dependencies": { "@nuxtjs/axios": "^5.3.6", "@nuxtjs/dotenv": "^1.3.0", "@nuxtjs/pwa": "^2.6.0", "cross-env": "^5.2.0", "firebase": "^6.0.4", "firebase-admin": "^8.0.0", "flamelink": "^1.0.0-alpha.19", "lodash.get": "^4.4.2", "nuxt": "^2.3.4" },

build command: yarn generate

results:

Generated / 11:04:04 All of your blogPage: { parentId: 0, 11:04:05 status: 'published', content: 'blah blah ', date: '2019-05-27T13:54:17+02:00', id: 'LdbHtNjScTubHFGK2sdu', _flmeta: { schemaType: 'single', schemaRef: { fields: [Array], sortable: true, type: 'single', group: 'Blog Page', id: 'blogPage', icon: '', _flmeta: [Object], title: 'Blog Page', enabled: true, description: 'blogroll' }, schema: 'blogPage', createdBy: 'zGOE6udkHkRRPsAlCLmpUo5eJrS2', locale: 'en-US', createdDate: Timestamp { _seconds: 1558958088, _nanoseconds: 880000000 }, fl_id: 'LdbHtNjScTubHFGK2sdu', docId: 'LdbHtNjScTubHFGK2sdu', env: 'production' }, summary: 'waffle waffle', title: 'Blog Test', order: 0, author: 'me' }

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:05

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:05

√ Generated /blog 11:04:05 All of your products: { '2JdT9worB7eq5p5gvssq': 11:04:06 { order: 0, parentId: 0, image: [ [Object] ], name: 'Product One', id: '2JdT9worB7eq5p5gvssq', _flmeta: { fl_id: '2JdT9worB7eq5p5gvssq', env: 'production', docId: '2JdT9worB7eq5p5gvssq', schemaType: 'collection', schemaRef: [Object], schema: 'products', createdBy: 'zGOE6udkHkRRPsAlCLmpUo5eJrS2', lastModifiedDate: [Object], lastModifiedBy: 'zGOE6udkHkRRPsAlCLmpUo5eJrS2', locale: 'en-US', createdDate: [Object] }, price: 152 }, zHfioqfq8njB5TNwYlkt: { order: 0, parentId: 0, image: [ [Object] ], name: 'Product two', id: 'zHfioqfq8njB5TNwYlkt', _flmeta: { schemaRef: [Object], schema: 'products', createdBy: 'zGOE6udkHkRRPsAlCLmpUo5eJrS2', lastModifiedDate: [Object], lastModifiedBy: 'zGOE6udkHkRRPsAlCLmpUo5eJrS2', locale: 'en-US', createdDate: [Object], fl_id: 'zHfioqfq8njB5TNwYlkt', env: 'production', docId: 'zHfioqfq8njB5TNwYlkt', schemaType: 'collection' }, price: 258 } }

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06

√ Generated /products 11:04:06

╭──────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ ⚠ Nuxt Warning │ │ │ │ The command 'nuxt generate' finished but did not exit after 5s │ │ This is most likely not caused by a bug in Nuxt.js │ │ Make sure to cleanup all timers and listeners you or your plugins/modules start. │ │ Nuxt.js will now force exit │ │ │ │ DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error │ │

suggestions on how to resolve this before Nuxt three turns up would be greatly appreciated. My full flamelink js

jperasmus commented 5 years ago

The warning for WARN Cannot stringify arbitrary non-POJOs Timestamp 11:04:06 happens when you try and console.log() or JSON.stringify() a value that includes a Firestore reference field. Nuxt tries to JSON.stringify the whole store object before sending it to your browser. The Firestore document reference object has a circular structure so it cannot be stringified correctly. This is how the Firestore reference type works and not something with the Flamelink SDK. But it is not all bad news, if you pluck out only the fields that you need or populate these references into non-circular objects, the problem should be resolved.

gitdubz commented 4 years ago

Closing this issue due to inactivity

Note on circular objects

You can use this nifty package for circular structures https://github.com/WebReflection/flatted


import { parse, stringify } from 'flatted';

const JSONPojo = stringify(someCircularPojo)

// use parse to change it back to a JS POJO