@live-change/framework 0.7.33 → 0.7.35

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.
@@ -1,5 +1,6 @@
1
1
  const utils = require("../utils.js")
2
2
  const debug = require('debug')('framework:updaters:db')
3
+
3
4
  async function update(changes, service, app, force) {
4
5
 
5
6
  const dao = app.dao
@@ -116,7 +117,8 @@ async function update(changes, service, app, force) {
116
117
 
117
118
  debug("DATABASE UPDATER")
118
119
 
119
- for(let change of changes) {
120
+ for(let i = 0; i < changes.length; i++) {
121
+ const change = changes[i]
120
122
  debug("PROCESSING CHANGE", change)
121
123
  switch(change.operation) {
122
124
  case "createModel": {
@@ -124,9 +126,18 @@ async function update(changes, service, app, force) {
124
126
  const tableName = generateTableName(model.name)
125
127
  await dao.request(['database', 'createTable'], database, tableName, model.storage ?? {})
126
128
  debug("TABLE CREATED!", tableName)
127
- for(let indexName in model.indexes) {
128
- const index = model.indexes[indexName]
129
+ for(const [indexName, index] of Object.entries(model.indexes || {})) {
130
+ if(index.created) continue
131
+ if(index.dependsOn) {
132
+ const dependsOn = Array.isArray(index.dependsOn) ? index.dependsOn : [index.dependsOn]
133
+ for(const indexName of dependsOn) {
134
+ const index = model.indexes[indexName]
135
+ await createIndex(tableName, indexName, index)
136
+ index.created = true
137
+ }
138
+ }
129
139
  await createIndex(tableName, indexName, index)
140
+ index.created = true
130
141
  }
131
142
  } break
132
143
  case "renameModel": {
@@ -74,9 +74,106 @@ let validators = {
74
74
  return false
75
75
  }
76
76
  }
77
- return
78
- }
77
+ return validator
78
+ },
79
79
 
80
+ switchBy: ({ prop, cases }, { getValidator }) => {
81
+ let validators = {}
82
+ for(let [value, then] of Object.entries(cases)) {
83
+ validators[value] = then.map(getValidator)
84
+ }
85
+ const validator = (value, context) => {
86
+ let selectorValue = getField(context, prop)
87
+ for(let v of (validators[selectorValue] || [])) {
88
+ const err = v(value, context)
89
+ if(err) return err
90
+ }
91
+ }
92
+ validator.isRequired = (context) => {
93
+ let value = getField(context, prop)
94
+ for(let v of validators[value]) {
95
+ if(v.isRequired && v.isRequired(context)) return true
96
+ }
97
+ return false
98
+ }
99
+ return validator
100
+ },
101
+
102
+ ifNotOneOf: ({ prop, what, then }, { getValidator }) => {
103
+ let validators = then.map(getValidator)
104
+ const validator = (value, context) => {
105
+ console.error("VIF NOT ONE OF", getField(context, prop), what, what.includes(getField(context, prop)))
106
+ if(!what.includes(getField(context, prop))) {
107
+ console.log("V", validators)
108
+ for(let v of validators) {
109
+ const err = v(value, context)
110
+ if(err) return err
111
+ }
112
+ }
113
+ }
114
+ validator.isRequired = (context) => {
115
+ if(!what.includes(getField(context, prop))) {
116
+ for(let v of validators) {
117
+ if(v.isRequired && v.isRequired(context)) return true
118
+ }
119
+ return false
120
+ }
121
+ }
122
+ return validator
123
+ },
124
+
125
+ ifEmpty: ({ prop, then }, { getValidator }) => {
126
+ let validators = then.map(getValidator)
127
+ const validator = (value, context) => {
128
+ console.log("IFEMPTY CTX", context, "FIELD", prop, "VALUE", getField(context, prop))
129
+ if(!getField(context, prop)) {
130
+ console.log("V", validators)
131
+ for(let v of validators) {
132
+ const err = v(value, context)
133
+ if(err) return err
134
+ }
135
+ }
136
+ }
137
+ validator.isRequired = (context) => {
138
+ if(!getField(context, prop)) {
139
+ for(let v of validators) {
140
+ if(v.isRequired && v.isRequired(context)) return true
141
+ }
142
+ return false
143
+ }
144
+ }
145
+ return validator
146
+ },
147
+
148
+
149
+ ifIncludes: ({ prop, that, then }, { getValidator }) => {
150
+ let validators = then.map(getValidator)
151
+ const validator = (value, context) => {
152
+ if(getField(context, prop).includes(that)) {
153
+ for(let v of validators) {
154
+ const err = v(value, context)
155
+ if(err) return err
156
+ }
157
+ }
158
+ }
159
+ validator.isRequired = (context) => {
160
+ if(getField(context, prop).includes(that)) {
161
+ for(let v of validators) {
162
+ if(v.isRequired && v.isRequired(context)) return true
163
+ }
164
+ return false
165
+ }
166
+ }
167
+ return validator
168
+ },
169
+
170
+ httpUrl: (settings) => (value) => {
171
+ if(!value) return false // ignore empty
172
+ const match = value.match(
173
+ /^(?:http(s)?:\/\/)[\w.-]+(?:\.[\w\.-]+)+[\w\-\._%~:/?#[\]@!\$&'\(\)\*\+,;=.]+$/
174
+ )
175
+ if(!match) return 'wrongUrl'
176
+ }
80
177
  }
81
178
 
82
179
  module.exports = validators
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.7.33",
3
+ "version": "0.7.35",
4
4
  "description": "Live Change Framework - ultimate solution for real time mobile/web apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,13 +21,13 @@
21
21
  },
22
22
  "homepage": "https://github.com/live-change/live-change-framework",
23
23
  "devDependencies": {
24
- "@live-change/dao": "0.5.21",
25
- "@live-change/dao-websocket": "0.5.21",
26
- "@live-change/db": "0.6.22",
27
- "@live-change/db-store-level": "0.6.22",
28
- "@live-change/db-store-lmdb": "0.6.22",
24
+ "@live-change/dao": "0.5.22",
25
+ "@live-change/dao-websocket": "0.5.22",
26
+ "@live-change/db": "0.6.23",
27
+ "@live-change/db-store-level": "0.6.23",
28
+ "@live-change/db-store-lmdb": "0.6.23",
29
29
  "@live-change/sockjs": "0.4.1",
30
- "@live-change/uid": "^0.7.33",
30
+ "@live-change/uid": "^0.7.35",
31
31
  "cookie": "^0.4.1",
32
32
  "express": "^4.18.2",
33
33
  "os-service": "^2.2.0",
@@ -35,5 +35,5 @@
35
35
  "tape": "^5.3.2",
36
36
  "websocket": "^1.0.34"
37
37
  },
38
- "gitHead": "244a5a0eccac3b8fe8f9efc0d8cca08f4e383b60"
38
+ "gitHead": "11313d136ef6bc6770050671a61721c2fa7586f9"
39
39
  }