Skip to content

Commit

Permalink
Hook up to faunadb!
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Feb 12, 2021
1 parent bf08d65 commit 3694328
Show file tree
Hide file tree
Showing 3 changed files with 3,763 additions and 3,491 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"classnames": "^2.2.6",
"faunadb": "^4.0.3",
"lodash": ">=4.17.11",
"next": "10.0.5",
"react": "17.0.1",
Expand Down
135 changes: 19 additions & 116 deletions pages/api/replicache-client-view.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,20 @@
export default (req, res) => {
res.status(200).json({
// We'll come back to this when we implement mutations
"lastMutationID": 0,
"clientView": {
// o1 is the unique ID
"/object/1": {
"width": 163,
"height": 84,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(0, 123, 255, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 17,
"y": 15
},
"/object/2": {
"width": 70,
"height": 146,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(255, 255, 255, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 19,
"y": 109
},
"/object/3": {
"width": 81,
"height": 69,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(241, 97, 99, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 100,
"y": 110
},
"/object/4": {
"width": 231,
"height": 70,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(0, 123, 255, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 100,
"y": 187
},
"/object/5": {
"width": 183,
"height": 60,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(255, 241, 0, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 19,
"y": 265
},
"/object/6": {
"width": 118,
"height": 119,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(241, 97, 99, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 211,
"y": 266
},
"/object/7": {
"width": 82,
"height": 51,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(255, 255, 255, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 120,
"y": 333
},
"/object/8": {
"width": 89,
"height": 50,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(241, 97, 99, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 21,
"y": 334
},
"/object/9": {
"width": 143,
"height": 160,
"rotate": 0,
"strokeWidth": 0,
"fill": "rgba(255, 241, 0, 1)",
"radius": "0",
"blendMode": "normal",
"type": "rectangle",
"x": 190,
"y": 16
}
}
});
import faunadb from 'faunadb';

const q = faunadb.query;

export default async (req, res) => {
// TODO: Um, keep this secret with Next environment variables. Yolo.
const client = new faunadb.Client({secret: 'fnAEB0r_VeACDfFpFovYautQ-N_AvbOM1sLm3Fb3'});
const result = await client.query(q.Map(q.Paginate(
q.Documents(q.Collection('objects')), {size: 100000}),
q.Lambda('r', q.Get(q.Var('r')))));
const {data} = result;

const response = {
lastMutationID: 0,
clientView: Object.fromEntries(
data.map(entry => [`/object/${entry.ref.id}`, entry.data]))
};
console.debug({response});
res.status(200).json(response);
};
Loading

0 comments on commit 3694328

Please sign in to comment.