►
From YouTube: hyper63 hacking 2-9
Description
Part 2 of adding the bulk api endpoint for the data port
https://github.com/hyper63/hyper63
A
Okay,
we're
going
to
go
ahead
and
get
started.
No
one's
joined
the
stream
yet,
but
there's
no
reason
we
can't
go
ahead
and
get
started
and
as
people
come
in,
they
can
catch
up.
Well,
we
got
travis
coming
in.
A
Thanks
for
joining
as
we
left
off
yesterday
we
were
working
on
this
bulk
endpoint
and
we
got
the
documentation,
kind
of
stood
up,
the
app
express
module
set
up
and
tested,
and
then
we
implemented
a
feature
in
the
data
port
and
what
I'm
going
to
do
today
is
use
a
git
pod
which
allows
you
to
you
know
kind
of
pull
down
code
from
github
on
a
hosted
server
that
runs
in
your
tab
and
I'm
going
to
give
that
a
shot
and
see
how
that
works
with
not
having
to
switch
screens
may
drive
me
crazy,
may
not,
but
we'll
see.
A
So,
basically
what
I've
done
is
gone
into
github
and
I've
got
a
little
extension
added
where
I
can
click
a
button
and
that'll.
Take
me
to
my
get
pod
and
essentially
you
can
think
of
get
pod
as
a.
A
Git
pod
as
visual
studio
code
in
the
in
the
browser-
and
it
works
pretty
nice,
so
we've
got
our
visual
studio
code
and
we've
got
like
a
little
terminal
and
we've
got
our
project
we're
going
to
be
working
on
core.
So
we
we
pulled
down
main.
The
first
thing
we'll
do
is
create
a
branch
so.
A
Add
data
bulk
to
core
okay
and
now
we'll
work
in
the
core
and
it's
under
packages
and
core
and
I'll
pull
up
we'll
just
start
with
main
and
work
through
kind
of
the
code
base.
That
way,
so
main
is
the
starting
point
for
core,
and
what
core
does
is
it's
got
a
lib
folder
and
it
has
each
one
of
the
services
in
that
lib
folder,
so
we'll
probably
be
working
with
data,
but
I'll
just
quickly
run
through
kind
of
what
the
main
file
does.
A
So
the
main
file
will
load
all
the
ports
and
then
grab
the
core
and
then
basically,
it's
going
to
take
this
configuration
file.
That's
specified
and
it's
going
to
take
that
configuration
file
hyper63.config
and
it
will
essentially
read
from
that
configuration
file
and
then
associate
or
combine
all
the
pieces
of
that
file
into
a
hyper
63
instance.
A
B
A
A
And
it's
nine
so
we're
we're
good
cool.
So
we've
got
that.
Let's
just
run
our
test
to
see
what
happens
so
all
of
our
tests
pass
and
now
let's
go
into
ports
and
basically
with
ports.
It's
just
pulling
in
port
data
and
mapping
it
to
an
object.
So
that's
good
and
then
let's
go
into
our
lib
index.js
file,
it's
pulling
in
data
core
and
it's
just
mapping
that
as
services.
A
Core
data-
okay,
so
here
it
looks
like
it's
calling
some
of
our
methods,
so
this
is
where
we
want
to
do
our
work,
so
we've
got
create
database,
destroy,
create
document,
update,
remove
list
documents
cool
now
we
want
to
you
know,
add
our.
A
A
And
it'll
take
a
db
name
and
it's
going
to
take
some
docs
right
and
then
we
would
call
db
alt
documents
and
give
it
a
name.
A
A
A
Index
so
these
are
coming
from
each
one
of
these
guys
and
since
it's
kind
of
a
database
top
thing,
we
can
choose
to
call
it.
What
we
want
so
we'll
keep
this
and
do
run
with
then
we'll
pass
in
our
service
data
and
events,
so
we're
gonna.
This
is
pretty
much
like
dependency
injection,
we're
injecting
our
service,
which
is
our
adapter,
that's
wrapped
around
our
port.
So
we
have
data
and
then
we're
also
of
passing
events
as
well.
So
we
can
keep
things
observable.
A
So
what
we
need
to
do
is
just
implement
this
function
in
the
db.js
file.
So
if
we
look
up
at
the
top
here,
we
got
the
dbjs
file
and
we
need
to
implement
that
function
there.
So
we
go
to
dbjs
file
and
we're
gonna
just
come
down
here
and
create.
A
Almost
I
already
forgot
what
I
called
it
so.
A
And
then
we're
going
to
start
a
chain
or
a
pipeline,
and
it's
it's
in
a
sync
reader
in
crocs
and
and
basically
what
this
does
is
allows
for
dependency
injection
and
we
can
just
reuse
a
lot
of
code.
So
here
we're
gonna,
take
the
db
and
the
docks
and
kind
of
stick
them
in
our
box,
our
sync
box
and
then
we're
going
to
chain
over
that,
and
then
that
chain
is
going
to
use
a
util
function
called
apply,
and
this
apply
basically
takes
the
name
of
the
function.
A
A
Then
we
can
trigger
an
event
so
chain
trigger
event
and
we'll
just
call
this
data
bulk
and
then
what
that'll
do
is
just
anything
that
hooks
into
our
event
system
will
get
these
events
for
them.
So
that
is
our
implementation
of
bulk.
And
if
you
want
to
see
what
the
of
apply
and
trigger
event
does
you
can
go
to
the
utils
file.
A
And
check
those
out,
but
basically
it
uses
a
lot
of
procs
and
it
just
kind
of
a
lot
of
that
boilerplate,
that's
the
same
code
over
and
over
again
so
apply
it's
pulling
the
services
from
that
dependency
injection
and
then
it's
running
in
a
synchronous
method
on
those
services
and
since
each
service
method
is
a
promise,
it's
actually
converting
the
promise
of
that
service,
and
then
it
manages
the
errors
and
then
the
trigger
event
does
a
similar
thing.
A
So
that's
pretty
much
what
that
does,
and
now
we
can
go
into
our
db
test
and
write
a
test
for
this.
So
we'll
just
go
to
test
and
say
test
bulk
documents.
A
A
Id
two
okay,
so
that's
our
database
name
and
our
docs
array
and
then
we'll
inject
in
here,
a
service
so
we'll
say,
run
with
and
service
mock
db
and
our
events.
So
we'll
inject
all
those.
A
And
then
up
here
in
our
mock
db,
we'll
add
that
handler.
So
if
I
run
yarn
test
now,
I
should
get
a
failure.
Oh
probably
didn't
save
this
right.
Okay,
so
if
I
run
the
iron
test
now,
hopefully
it'll
fail.
Yeah.
We
get
one
failure
good.
A
B
A
A
A
A
A
A
A
A
Well,
okay,
so
we
can
just
call
this
handle
phil.
A
If
we
run
that
test,
we
should
be
good,
so
we
kind
of
got.
You
know
a
happy
test
and
a
sad
test
again
we
could
get
more
detailed,
but
really
we're
just
trying
to
test
the
code
that
we
wrote
and
make
sure
that
it's
doing
the
right
thing.
A
So
we'll
check
that
off
and
to
update
core.
We
need
to
do
a
couple
of
things.
So
we've
got
our
code,
we're
in
a
feature
branch
and
what
we
want
to
do
make
sure
everything's
saved.
A
A
A
A
That's
the
one
thing
about
get
pod
is
the
control
or
command
w
doesn't
close
the
tab
that
doesn't
close
the
tab?
It
close,
it
closes
the
chrome
tab
which
is
not
fun
so.
A
A
B
B
A
So
that
takes
care
of
the
core,
so
we've
got
the
port,
we've
got
the
core
and
the
cores
updated
with
the
new
port,
and
then
we
have
app
express
so
so
really
what's
remaining
is
to.
B
A
And
in
an
adapter
there's
kind
of
two
files:
there's
the
index
file
and
the
index
file
kind
of
handles
the
initialization
phase
of
when
an
adapter
has
been
attached.
A
B
A
A
There's
some
cutting
and
pastings
going
on,
so
this
function
should
be
pouchdb,
and
so,
when
you
call
this
function
in
the
config,
you
pass
in
the
config
information
and
then
it
returns.
This
object
that
has
an
id
a
port
and
a
load
function
and
a
link
function
and
the
link
function
is
where
the
adapter
is,
and
it's
got
a
manual
curry.
So
it'll
inject
the
config
which
has
a
directory
and
then
it'll
call
another
function
which
is
a
pipeline
function,
so
you
can
pipe
multiple
adapter
implementations
together
in
one
adapter.
A
The
best
way
to
show
this
is
to
go
to
dev
in
the
config
file.
So
these
plugins,
you
can
add
multiple
adapter
functions
in
that
array
and
then
what
will
happen
is
from.
I
think
it's
from
left
to
right.
A
Each
one
of
those
will
get
called
and
it'll
pass
the
result
in
the
other
one
so
that,
if
you
wanted
to,
you
could
essentially
implement
a
wrapper
function
that
did
a
start
date
and
a
stop
date
for
every
single
function
on
your
adapter
or
you
could
inspect
stuff
with
with
those
particular
plugins
or
you
could
just
partially
implement
an
adapter
say
you
know,
pouch
db
database
calls
pouch
db,
crud
calls
it's
etc,
and
you
could
actually
break
your
adapter
pattern
there.
A
It
doesn't
really
matter
it's
just
at
the
end
of
the
day
when
all
these
functions
kind
of
run
and
it
returns,
it's
got
to
match
the
api
of
the
port.
So
I'm
happy
to
talk
about
that
a
little
bit
more
if
it
gets
confusing,
but
that's
kind
of
how
it's
set
up
right
now
and
then
so.
You've
got
id
port
load
and
link,
and
then
we've
got
the
adapter
and
the
adapter
is
your
interface.
So
it
takes
and
should
provide
all
the
methods
given
to
it
by
the
port.
A
So
here
we're
returning
all
of
those
methods
and
matching
those
function.
Signatures
so
there's
create
database,
remove
database,
create
document
etc,
and
these
have
all
the
functionality
in
them
and
with
pouchdb,
it's
actually
using
promises
and
each
one
of
these
functions
returns
a
promise
so
we'll
implement
the
bulk
documents.
The
same
way
same
pattern.
A
A
Start
here
get
confused,
I
think
it
supports
them,
but
doesn't
seem
to
be
supporting
all
of
them.
So
I
think
it
doesn't
support
the
hold
the
key
down
and
I
think
that's
driving
me
crazy.
A
little
bit
so
we'll
say,
function
bulk
documents
and
we're
going
to
take
an
object
with
a
db
and
a
dox.
A
And
we'll
make
this
an
object
and
we'll
call
it
bulk
input
and
then
it'll
have
a
property.
A
B
A
So
we've
got
the
db
and
then
we're
going
to
call
databases.get
to
get
the
pouchdb
instance
and
then
do
our
stuff.
So
there
is
a
bulk
function
on
pouchdb,
so
this
will
be
pretty
straightforward.
We're
going
to
pouch
people
databases.get
db
and
now
we've
got
kind
of
our
pouch
instance.
A
A
All
right,
well
I'll,
have
to
look
at
the
options
in
a
little
bit,
but
I
think
everything's
good,
we'll
just
call
bulk
docs
pass
in
our
docs
and
then
get
the
response
back,
which
will
be
a
result
and
the
result
will
be
an
array
where
we
have
okay
and
id
in
the
rep
and
we're
just
going
to
want
to
strip
the
rev
out.
Because
our
result,
body
is
okay,
true
or
false,
and
then
results
and
then
the
array.
So
we
just
need
to
match
that
signature.
B
A
Okay,
so
what
we're
gonna
do
is
call
pouch,
dot,
bulk,
docs
and
we'll
pass
it.
Our
docs
and.
A
In
we
want
to
map
over
these
results
and
essentially
omit
the
the
rev
so
we're
gonna
do
map.
A
A
A
A
You
want
to
check
that,
but
right
now
we're
just
handling
the
bulk
docks
and
then
we're
returning
it
in
a
shape
that
matches
our
port.
B
A
Okay,
so
this
is
kind
of
just
working
through
some
crud,
it's
doing
a
fine.
Let's
do
bulk
docs
and,
let's
add
it
at
the
top
here.
A
Okay
and
then
we're
ready
to
call
our
bulk
so
we'll
do
result
equals.
A
Now,
there's
one
thing
that
I
know
that's
a
challenge
because
pouchdb
stores
documents
with
the
underscore
id
and
an
underscore
id
so
we're
going
to
have
to
before
we
do
our
bulk
docs
we're
going
to
have
to
map
over
all
the
ids
and
change
them
to
underscore
ids,
and
then
we're
also
going
to
have
to
deal
with
any
revisions.
A
So
we
may
have
to
check
in
case
a
document
exists
or
not,
but
we'll
do
the
first
case
of
just
the
happy
path
of
adding
and
then
we'll
deal
with
the
second,
and
we
need
to
await
that
and
then
console.log
result
t
dot.
Okay,
true
she
got
in.
B
A
Okay,
so
both
of
them
added
with
a
custom
id-
it
wasn't
one
or
two,
but
he
noticed
it
kind
of
generated
its
own
id.
So
we
need
to
fix
that.
A
Or
we
can
just
use
lenses.
A
Lens
id
or
something
and
then
it's
going
to
return
us
the
id.
But
then
we're
going
to
want
to
write
to
the
underscore
id
so.
A
A
A
A
And
let's
run
this
nc,
okay,
all
right!
So
that
way
we
got
okay,
one
and
okay,
two,
which
is
pretty
cool,
so
we're
just
going
to
deal
with
that.
We
need
to
handle
the
edit.
A
A
And
in
that
case,
what
we
will
have
to
do
is
we're
going
to
have
to
essentially
do
two
two
loops
through
the
documents.
First,
we'll
be
find
all
documents.
A
Then
update
those
with
a
rev
and
ignore
docks
that
don't
exist,
so
that'll
be
a
fun
problem
to
solve.
I
don't
think
we'll
have
time
to
solve
that
today,
but
we
did
get
the
initial
piece
in
to
support
bulk
documents
and
we've
got
our
test
now.
What
we
can
do
is
do
a
get
status
and
we
need
to
update
this
version
of
the
adapter.
So
we'll
do
npm
version
patch.
A
These
changes,
updated
pouchdb,
adapter
to
support
bulk,
add
and
oh
okay,
so
we'll
need
to
support
bulk
update
and
both
delete.
A
So
we've
got
that
and
now
we'll
we'll
push
this
up.
A
Make
sure
that
passes
then
we'll
generate
a
pull
request,
but
no
I've
been
kind
of
just
running
any
questions
that
you.
B
A
And
once
those
are
reviewed,
they'll
be
merged
in
and
we'll
have
a
working
adapter
with
the
new
bulk
method
and
tomorrow
we'll
work
on
getting
the
update
and
delete
working
for
pouchdb
and
then
we'll
go
into.
A
Couchdb
and
since
they're
both
pretty
similar
apis,
we
can
deal
with
that.