@live-change/user-service 0.8.21 → 0.8.23

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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019-2024 Michał Łaszczewski
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/authenticator.js CHANGED
@@ -18,7 +18,7 @@ definition.authenticator({
18
18
  await authenticatedTable.object(session).onChange(async (authData, oldAuthData) => {
19
19
  output.debug("NEW USER AUTH", authData, "FROM", oldAuthData)
20
20
  const newUser = authData ? authData.user : null
21
- if(newUser == user) return
21
+ if(newUser === user) return
22
22
  output.debug("USER CHANGE", user, '=>', newUser)
23
23
  if(user) {
24
24
  if(userObject) {
@@ -41,7 +41,7 @@ definition.authenticator({
41
41
  output.change(newCredentials, oldCredentials)
42
42
  oldCredentials = newCredentials
43
43
  }).then(observer => {
44
- if(user == newUser) {
44
+ if(user === newUser) {
45
45
  userObserver = observer
46
46
  } else { // if user changed before observer loaded data
47
47
  currentUserObject.unobserve(observer)
@@ -15,7 +15,6 @@ definition.processor(function(service, app) {
15
15
 
16
16
  const originalModelProperties = { ...model.properties }
17
17
  const modelProperties = Object.keys(model.properties)
18
- const defaults = App.utils.generateDefault(model.properties)
19
18
  const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
20
19
 
21
20
  function modelRuntime() {
@@ -20,7 +20,6 @@ definition.processor(function(service, app) {
20
20
 
21
21
  const originalModelProperties = { ...model.properties }
22
22
  const modelProperties = Object.keys(model.properties)
23
- const defaults = App.utils.generateDefault(model.properties)
24
23
 
25
24
  function modelRuntime() {
26
25
  return service._runtime.models[modelName]
@@ -232,7 +231,8 @@ definition.processor(function(service, app) {
232
231
  newObject[propertyName] = properties[propertyName]
233
232
  }
234
233
  }
235
- const data = App.utils.mergeDeep({}, defaults, newObject)
234
+ const data = App.utils.mergeDeep({},
235
+ App.computeDefaults(model, properties, { client, service } ), newObject)
236
236
  await App.validation.validate(data, validators, { source: action, action, service, app, client })
237
237
  const identifiers = {
238
238
  ownerType: 'user_User',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/user-service",
3
- "version": "0.8.21",
3
+ "version": "0.8.23",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,9 +22,9 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "0.8.21",
26
- "@live-change/relations-plugin": "0.8.21",
25
+ "@live-change/framework": "^0.8.23",
26
+ "@live-change/relations-plugin": "^0.8.23",
27
27
  "pluralize": "^8.0.0"
28
28
  },
29
- "gitHead": "4453aa639a9fe1a857d93d73ebd28a82c97fdd87"
29
+ "gitHead": "581260523149a1e596f08e878b5f4fabeaba26ea"
30
30
  }
@@ -15,7 +15,6 @@ definition.processor(function(service, app) {
15
15
  if (model.properties.sessionOrUser) throw new Error('user property already exists!!!')
16
16
  const originalModelProperties = { ...model.properties }
17
17
  const modelProperties = Object.keys(model.properties)
18
- const defaults = App.utils.generateDefault(model.properties)
19
18
  const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
20
19
 
21
20
  function modelRuntime() {
@@ -20,14 +20,13 @@ definition.processor(function(service, app) {
20
20
 
21
21
  const originalModelProperties = { ...model.properties }
22
22
  const modelProperties = Object.keys(model.properties)
23
- const defaults = App.utils.generateDefault(model.properties)
24
23
 
25
24
  function modelRuntime() {
26
25
  return service._runtime.models[modelName]
27
26
  }
28
27
 
29
28
  const config = model.sessionOrUserProperty
30
- const writeableProperties = modelProperties || config.writableProperties
29
+ const writeableProperties = modelProperties || config.writeableProperties
31
30
 
32
31
  if(model.propertyOf) throw new Error("model " + modelName + " already have owner")
33
32
  if(model.propertyOfAny) throw new Error("model " + modelName + " already have owner")
@@ -40,6 +39,8 @@ definition.processor(function(service, app) {
40
39
  to: ['sessionOrUser', ...extendedWith]
41
40
  }
42
41
 
42
+ modelProperties.push(...extendedWith.map(p => [p, p+'Type']).flat())
43
+
43
44
  const transferEventName = ['sessionOrUser', ...(extendedWith.map(e => e[0].toUpperCase() + e.slice(1)))]
44
45
  .join('And') + 'Owned' + modelName + 'Transferred'
45
46
 
@@ -167,7 +168,7 @@ definition.processor(function(service, app) {
167
168
  access(params, context) {
168
169
  return config.ownerReadAccess ? config.ownerReadAccess(params, context) : true
169
170
  },
170
- daoPath(params, { client, context }) {
171
+ async daoPath(params, { client, context }) {
171
172
  const owner = client.user ? ['user_User', client.user] : ['session_Session', client.session]
172
173
  for(const key of extendedWith) {
173
174
  owner.push(params[key+'Type'], params[key])
@@ -253,7 +254,8 @@ definition.processor(function(service, app) {
253
254
  newObject[propertyName] = properties[propertyName]
254
255
  }
255
256
  }
256
- const data = App.utils.mergeDeep({}, defaults, newObject)
257
+ const data = App.utils.mergeDeep({},
258
+ App.computeDefaults(model, properties, { client, service } ), newObject)
257
259
  await App.validation.validate(data, validators, { source: action, action, service, app, client })
258
260
  const identifiers = client.user ? {
259
261
  sessionOrUserType: 'user_User',
@@ -363,7 +365,8 @@ definition.processor(function(service, app) {
363
365
  identifiers[key]=properties[key]
364
366
  }
365
367
  if(!entity) {
366
- const data = App.utils.mergeDeep({}, defaults, updateObject)
368
+ const data = App.utils.mergeDeep({},
369
+ App.computeDefaults(model, properties, { client, service } ), updateObject)
367
370
  //console.log('V', { ...identifiers, ...data}, validators)
368
371
  await App.validation.validate({ ...identifiers, ...data}, validators,
369
372
  { source: action, action, service, app, client })
package/userItem.js CHANGED
@@ -14,7 +14,6 @@ definition.processor(function(service, app) {
14
14
  if (model.properties.user) throw new Error('user property already exists!!!')
15
15
  const originalModelProperties = {...model.properties}
16
16
  const modelProperties = Object.keys(model.properties)
17
- const defaults = App.utils.generateDefault(model.properties)
18
17
  const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
19
18
 
20
19
  function modelRuntime() {
package/userProperty.js CHANGED
@@ -16,7 +16,6 @@ definition.processor(function(service, app) {
16
16
 
17
17
  const originalModelProperties = { ...model.properties }
18
18
  const modelProperties = Object.keys(model.properties)
19
- const defaults = App.utils.generateDefault(model.properties)
20
19
 
21
20
  function modelRuntime() {
22
21
  return service._runtime.models[modelName]
@@ -84,7 +83,8 @@ definition.processor(function(service, app) {
84
83
  newObject[propertyName] = properties[propertyName]
85
84
  }
86
85
  }
87
- const data = App.utils.mergeDeep({}, defaults, newObject)
86
+ const data = App.utils.mergeDeep({},
87
+ App.computeDefaults(model, properties, { client, service }), newObject)
88
88
  await App.validation.validate(data, validators, { source: action, action, service, app, client })
89
89
  emit({
90
90
  type: eventName,