@live-change/framework 0.7.2 → 0.7.4

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.
package/index.js CHANGED
@@ -14,6 +14,7 @@ module.exports.validation = require('./lib/utils/validation.js')
14
14
  module.exports.rangeProperties = module.exports.utils.rangeProperties
15
15
  module.exports.encodeIdentifier = module.exports.utils.encodeIdentifier
16
16
  module.exports.extractRange = module.exports.utils.extractRange
17
+ module.exports.isomorphic = module.exports.utils.isomorphic
17
18
 
18
19
 
19
20
  module.exports.ActionDefinition = require('./lib/definition/ActionDefinition.js')
package/lib/App.js CHANGED
@@ -25,7 +25,7 @@ const indexCode = require("./processors/indexCode.js")
25
25
 
26
26
  const databaseUpdater = require("./updaters/database.js")
27
27
 
28
- const accessControlFilter = require("./clientSideFilters/accessControlFilter.js")
28
+ const accessControlFilter = require("./clientSideFilters/accessFilter.js")
29
29
  const clientSideFilter = require("./clientSideFilters/clientSideFilter.js")
30
30
 
31
31
  const commandExecutor = require("./processes/commandExecutor.js")
@@ -186,10 +186,20 @@ class App {
186
186
  }
187
187
 
188
188
  async clientSideDefinition( service, client, filters ) {
189
- let definition = JSON.parse(JSON.stringify(service.definition.toJSON()))
189
+ if(!service.clientSideDefinition) {
190
+ service.clientSideDefinition = JSON.stringify(service.definition.toJSON(), (key, value) => {
191
+ if (value && typeof value == 'object' && value.function && value.isomorphic) return {
192
+ function: value.function.toString(),
193
+ isomorphic: value.isomorphic
194
+ }
195
+ return value
196
+ })
197
+ }
198
+ let definition = JSON.parse(service.clientSideDefinition)
190
199
  delete definition.use
191
200
  if(!filters) filters = this.defaultClientSideFilters
192
201
  for(let filter of filters) await filter(service, definition, this, client)
202
+ for(let filter of service.definition.clientSideFilters) await filter(service, definition, this, client)
193
203
  return definition
194
204
  }
195
205
 
@@ -87,6 +87,7 @@ class ServiceDefinition {
87
87
  this.beforeStartCallbacks = []
88
88
  this.endpoints = []
89
89
  this.validators = defaultValidators
90
+ this.clientSideFilters = []
90
91
  for(let key in definition) this[key] = definition[key]
91
92
  }
92
93
 
@@ -161,6 +162,14 @@ class ServiceDefinition {
161
162
  this.endpoints.push(endpoint)
162
163
  }
163
164
 
165
+ validator(validator) {
166
+ this.validators.push(validator)
167
+ }
168
+
169
+ clientSideFilter(filter) {
170
+ this.clientSideFilters.push(filter)
171
+ }
172
+
164
173
  toJSON() {
165
174
  let models = {}
166
175
  for(let key in this.models) models[key] = this.models[key].toJSON()
@@ -20,20 +20,21 @@ module.exports = function(service, app) {
20
20
  if(view.skipValidation) continue
21
21
  const validators = getValidators(view, service, view)
22
22
  if(Object.keys(validators).length > 0) {
23
- if (view.read && !view.fetch) {
24
- const oldRead = view.read
25
- view.read = async (...args) => {
23
+ if (view.observable) {
24
+ const oldObservable = view.observable
25
+ view.observable = async (...args) => {
26
26
  const context = args[1]
27
27
  return validate(args[0], validators, { source: view, view, service, app, ...context }).then(() =>
28
- oldRead.apply(view, args)
28
+ oldObservable.apply(view, args)
29
29
  )
30
30
  }
31
- } else {
32
- const oldFetch = view.fetch
33
- view.fetch = async (...args) => {
31
+ }
32
+ if(view.get) {
33
+ const oldGet = view.get
34
+ view.get = async (...args) => {
34
35
  const context = args[1]
35
36
  return validate(args[0], validators, { source: view, view, service, app, ...context }).then(() =>
36
- oldFetch.apply(view, args)
37
+ oldGet.apply(view, args)
37
38
  )
38
39
  }
39
40
  }
@@ -34,6 +34,9 @@ let validators = {
34
34
  minLength: ({ length }) => (value) => value.length < length ? 'tooShort' : undefined,
35
35
  maxLength: ({ length }) => (value) => value.length > length ? 'tooLong' : undefined,
36
36
 
37
+ number: () => (value) => isNaN(value) ? 'notANumber' : undefined,
38
+ integer: () => (value) => !Number.isInteger(value) ? 'notAnInteger' : undefined,
39
+
37
40
  elementsNonEmpty: (settings) => (value) => {
38
41
  if(!value) return
39
42
  for(let el of value) {
@@ -76,4 +79,4 @@ let validators = {
76
79
 
77
80
  }
78
81
 
79
- module.exports = validators
82
+ module.exports = validators
package/lib/utils.js CHANGED
@@ -267,9 +267,22 @@ function extractRange(properties) {
267
267
  }
268
268
  }
269
269
 
270
+ function isomorphic( v ) {
271
+ if(typeof v == 'function') {
272
+ return {
273
+ isomorphic: true,
274
+ function: v
275
+ }
276
+ }
277
+ return {
278
+ isomorphic: true,
279
+ value: v
280
+ }
281
+ }
282
+
270
283
  module.exports = {
271
284
  typeName, toJSON, setDifference, mapDifference, crudChanges,
272
285
  getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault,
273
286
  prefixRange, rangeProperties, fieldListToFieldsObject,
274
- encodeIdentifier, extractRange
287
+ encodeIdentifier, extractRange, isomorphic
275
288
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
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.6",
25
- "@live-change/dao-websocket": "0.5.6",
26
- "@live-change/db": "0.5.18",
27
- "@live-change/db-store-level": "0.5.18",
28
- "@live-change/db-store-lmdb": "0.5.18",
24
+ "@live-change/dao": "0.5.8",
25
+ "@live-change/dao-websocket": "0.5.8",
26
+ "@live-change/db": "0.5.19",
27
+ "@live-change/db-store-level": "0.5.19",
28
+ "@live-change/db-store-lmdb": "0.5.19",
29
29
  "@live-change/sockjs": "0.4.1",
30
- "@live-change/uid": "^0.7.2",
30
+ "@live-change/uid": "^0.7.4",
31
31
  "cookie": "^0.4.1",
32
32
  "express": "^4.18.1",
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": "946630a9b716bf48c6b77aea43c79b200bc82f9e"
38
+ "gitHead": "b4634f8267f89859042f176e5430567fd796082e"
39
39
  }