@live-change/dao 0.5.4 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/Path.js +58 -11
  2. package/package.json +2 -2
package/lib/Path.js CHANGED
@@ -1,10 +1,22 @@
1
- function sourceProxy(to) {
1
+ function sourceProxy(to, more, target) {
2
2
  const proxy = new Proxy({
3
3
  $toPath() {
4
4
  return to
5
5
  },
6
6
  $nonEmpty() {
7
- return sourceProxy({ nonEmpty: to })
7
+ return sourceProxy({ nonEmpty: to }, more, target)
8
+ },
9
+ $switch(options) {
10
+ return sourceProxy({ value: to, switch: options }, more, target)
11
+ },
12
+ $bind(target) {
13
+ return sourceProxy(to, more, target)
14
+ },
15
+ $target() {
16
+ return target
17
+ },
18
+ $more() {
19
+ return more
8
20
  }
9
21
  }, {
10
22
  get(target, name) {
@@ -59,15 +71,50 @@ class Path {
59
71
  for(const func of funcs) {
60
72
  const source = sourceProxy()
61
73
  const fetchObject = func(source)
62
- const path = fetchObject.what.slice(0, -1)
63
- const params = fetchObject.what[fetchObject.what.length - 1]
64
- let processedParams = processParams(params)
65
- const more = {
66
- schema: [[...path, { object: processedParams }]],
67
- more: fetchObject.more,
68
- to: fetchObject.to
74
+
75
+ if(fetchObject instanceof Path) {
76
+ const path = fetchObject.what.slice(0, -1)
77
+ const params = fetchObject.what[fetchObject.what.length - 1]
78
+ let processedParams = processParams(params)
79
+ const more = {
80
+ schema: [[...path, { object: processedParams }]],
81
+ more: fetchObject.more,
82
+ to: fetchObject.to
83
+ }
84
+ newMore.push(more)
85
+ } else if(fetchObject.$toPath) { /// sourceProxy returned
86
+ console.log("FETCH OBJECT PROXY", fetchObject)
87
+ const schema = JSON.parse(JSON.stringify(fetchObject.$toPath(), (key, value) => {
88
+ if(value instanceof Path) {
89
+ const path = value.what.slice(0, -1)
90
+ const params = value.what[value.what.length - 1]
91
+ let processedParams = processParams(params)
92
+ return [...path, { object: processedParams }]
93
+ } else return value
94
+ }))
95
+ const more = {
96
+ schema: [schema],
97
+ more: fetchObject.$more(),
98
+ to: fetchObject.$target()
99
+ }
100
+ newMore.push(more)
101
+ } else {
102
+ console.log("FETCH OBJECT", fetchObject)
103
+ const schema = JSON.parse(JSON.stringify(fetchObject, (key, value) => {
104
+ if(value instanceof Path) {
105
+ const path = value.what.slice(0, -1)
106
+ const params = value.what[value.what.length - 1]
107
+ let processedParams = processParams(params)
108
+ return [...path, { object: processedParams }]
109
+ } else return value
110
+ }))
111
+ const more = {
112
+ schema: [schema],
113
+ more: fetchObject.more,
114
+ to: fetchObject.to
115
+ }
116
+ newMore.push(more)
69
117
  }
70
- newMore.push(more)
71
118
  }
72
119
  return new Path(this.what, newMore, this.to, this.actions)
73
120
  }
@@ -100,4 +147,4 @@ class Path {
100
147
  }
101
148
  }
102
149
 
103
- module.exports = Path
150
+ module.exports = Path
package/package.json CHANGED
@@ -35,6 +35,6 @@
35
35
  "scripts": {
36
36
  "test": "NODE_ENV=test blue-tape tests/*"
37
37
  },
38
- "version": "0.5.4",
39
- "gitHead": "dfc8cd2f8de139aeb910a1bf0d3ca5818edcedd4"
38
+ "version": "0.5.6",
39
+ "gitHead": "8a0894ea0f57b6e1c5a627258617b8353e70533d"
40
40
  }