Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

rename to items, and remove the next/prev hack.

  • Loading branch information...
commit 1e8b2565fa121790c8faf44a4e8bcfe41c560c76 1 parent 474ab21
@robey authored
Showing with 16 additions and 13 deletions.
  1. +13 −11 src/fauna.coffee
  2. +3 −2 test/test_fauna.coffee
View
24 src/fauna.coffee
@@ -69,31 +69,28 @@ class Fauna
# ----- helpers
collapseEvents: (data) ->
- collection = []
+ items = []
for event in data.resource.events.reverse()
if not event.action? then event.action = "create"
switch event.action
when "create"
ref = data.references[event.resource]
- if ref? then collection.unshift ref
+ if ref? then items.unshift ref
when "delete"
- collection = (x for x in collection when x.ref != event.resource)
+ collection = (x for x in items when x.ref != event.resource)
else
# ignore
- if data.resource.events.length > 0
- prev = data.resource.events[0].ts
- next = data.resource.events[data.resource.events.length - 1].ts
- else
- next = 0
- prev = 0
- collection = collection.map (item) =>
+ before = data.resource.before
+ if not before? then before = 0
+ after = data.resource.after
+ items = items.map (item) =>
newrefs = {}
for k, v of item.references
v = if v instanceof Array then v.map((x) -> data.references[x]) else data.references[v]
newrefs[k] = v
item.references = newrefs
@schema.inflate(item, @)
- { before: data.resource.before, after: data.resource.after, next: next, prev: prev, items: collection }
+ { before: before, after: after, items: items }
# tell fauna to create classes & event sets for us.
# return: { class, event_sets[] }[]
@@ -211,6 +208,11 @@ class Fauna
@post("#{setName}", resource: ref).then (data) =>
@collapseEvents(data)
+ # auth: token or publisher
+ # returns: usually an empty set, because the event was a delete.
+ deleteFromEventSet: (setName, ref) ->
+ @delete("#{setName}", resource: ref).then (data) => @collapseEvents(data)
+
## ----- users
View
5 test/test_fauna.coffee
@@ -59,6 +59,7 @@ describe "Fauna", ->
response =
resource:
ref: "classes/messages"
+ after: 930000
events: [
{ ts: 930000, action: "create", resource: "classes/messages/2", set: "classes/messages" }
{ ts: 900000, action: "create", resource: "classes/messages/1", set: "classes/messages" }
@@ -68,8 +69,8 @@ describe "Fauna", ->
"classes/messages/2": message_2
f = new Fauna()
f.collapseEvents(response).should.eql {
- before: undefined,
- after: undefined,
+ before: 0,
+ after: 930000,
items: [
{ _fauna: { id: "classes/messages/2", className: "messages", ts: new Date(930), fauna: f } }
{ _fauna: { id: "classes/messages/1", className: "messages", ts: new Date(900), fauna: f } }
Please sign in to comment.
Something went wrong with that request. Please try again.