@live-change/relations-plugin 0.9.97 → 0.9.99

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/relations-plugin",
3
- "version": "0.9.97",
3
+ "version": "0.9.99",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.97",
25
+ "@live-change/framework": "^0.9.99",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
28
  "devDependencies": {
@@ -30,5 +30,5 @@
30
30
  "typedoc-plugin-markdown": "^4.6.3",
31
31
  "typedoc-plugin-rename-defaults": "^0.7.3"
32
32
  },
33
- "gitHead": "10ec914fe91a9fe10464d68c6d145e152bb1073e"
33
+ "gitHead": "be394720644be1eea528f1f5272dd8066081bc93"
34
34
  }
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  defineProperties, defineIndex,
3
3
  extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl,
4
- includeAccessRoles, defineGlobalRangeView
4
+ includeAccessRoles, defineGlobalRangeView,
5
+ propertiesWithoutDefaults
5
6
  } from './utils.js'
6
7
  import { fireChangeTriggers } from "./changeTriggers.js"
7
8
  import App, { AccessSpecification, ModelDefinitionSpecification, PropertyDefinitionSpecification, ServiceDefinition } from '@live-change/framework'
@@ -258,7 +259,7 @@ export function defineUpdateAction(config, context) {
258
259
  const action = new ActionDefinition({
259
260
  name: actionName,
260
261
  properties: {
261
- ...(model.properties),
262
+ ...propertiesWithoutDefaults(model.properties),
262
263
  [modelPropertyName]: {
263
264
  type: modelPropertyName
264
265
  }
@@ -286,7 +287,7 @@ export function defineUpdateTrigger(config, context) {
286
287
  const trigger = new TriggerDefinition({
287
288
  name: triggerName,
288
289
  properties: {
289
- ...(model.properties),
290
+ ...propertiesWithoutDefaults(model.properties),
290
291
  [modelPropertyName]: {
291
292
  type: modelPropertyName
292
293
  }
@@ -11,7 +11,8 @@ import {
11
11
  } from './utilsAny.js'
12
12
  import {
13
13
  extractObjectData, extractIdentifiers, extractIdParts,
14
- cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl
14
+ cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl,
15
+ propertiesWithoutDefaults
15
16
  } from './utils.js'
16
17
  import { fireChangeTriggers } from "./changeTriggers.js"
17
18
 
@@ -106,7 +107,7 @@ function getCreateFunction( validators, validationContext, config, context) {
106
107
  const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
107
108
  const data = extractObjectData(writeableProperties, properties,
108
109
  App.computeDefaults(model, properties, { client, service } ))
109
- await App.validation.validate({ ...identifiers, ...data }, validators,
110
+ const result = await App.validation.validate({ ...identifiers, ...data }, validators,
110
111
  validationContext)
111
112
  await fireChangeTriggers(context, objectType, identifiers, id, null, data, trigger)
112
113
  emit({
@@ -183,9 +184,9 @@ function getUpdateFunction( validators, validationContext, config, context) {
183
184
  const entity = await modelRuntime().get(id)
184
185
  if(!entity) throw 'not_found'
185
186
  const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
186
- const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
187
- console.log("UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
188
- '=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts))
187
+ const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
188
+ /* console.log("UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
189
+ '=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts)) */
189
190
  if(JSON.stringify(entityTypeAndIdParts) !== JSON.stringify(typeAndIdParts)) {
190
191
  throw 'not_authorized'
191
192
  }
@@ -194,6 +195,16 @@ function getUpdateFunction( validators, validationContext, config, context) {
194
195
  extractObjectData(writeableProperties, properties, entity),
195
196
  App.computeUpdates(model, { ...entity, ...properties }, { client, service })
196
197
  )
198
+ if(entityTypeAndIdParts[0] == 'task_Task' && data.retries.length == 0 && entity.retries.length > 0) {
199
+ console.log("TASK UPDATE!!!!!!!!")
200
+ console.log("CURRENT STATE:", entity)
201
+ console.log("UPDATE:", properties)
202
+ console.log("IDENTIFIERS:", identifiers)
203
+ console.log("EXTRACTED ENTITY DATA:", extractObjectData(writeableProperties, properties, entity))
204
+ console.log("COMPUTED UPDATES:", App.computeUpdates(model, { ...entity, ...properties }, { client, service }))
205
+ console.log("DATA:", data)
206
+ debugger
207
+ }
197
208
  await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
198
209
  validationContext)
199
210
  await fireChangeTriggers(context, objectType, identifiers, id,
@@ -226,7 +237,7 @@ function defineUpdateAction(config, context) {
226
237
  type: model,
227
238
  validation: ['nonEmpty']
228
239
  },
229
- ...(model.properties)
240
+ ...propertiesWithoutDefaults(model.properties)
230
241
  },
231
242
  access: config.updateAccess || config.writeAccess,
232
243
  accessControl,
@@ -256,7 +267,7 @@ function defineUpdateTrigger(config, context) {
256
267
  type: model,
257
268
  validation: ['nonEmpty']
258
269
  },
259
- ...(model.properties)
270
+ ...propertiesWithoutDefaults(model.properties)
260
271
  },
261
272
  access: config.updateAccess || config.writeAccess,
262
273
  skipValidation: true,
@@ -7,7 +7,8 @@ import {
7
7
  extractIdentifiers,
8
8
  extractObjectData,
9
9
  prepareAccessControl,
10
- cloneAndPrepareAccessControl
10
+ cloneAndPrepareAccessControl,
11
+ propertiesWithoutDefaults
11
12
  } from './utils.js'
12
13
  import { fireChangeTriggers } from "./changeTriggers.js"
13
14
  import pluralize from 'pluralize'
@@ -215,7 +216,7 @@ function defineUpdateAction(config, context) {
215
216
  type: model,
216
217
  validation: ['nonEmpty']
217
218
  },
218
- ...(model.properties)
219
+ ...propertiesWithoutDefaults(model.properties)
219
220
  },
220
221
  access: config.updateAccess || config.writeAccess,
221
222
  accessControl,
@@ -244,7 +245,7 @@ function defineUpdateTrigger(config, context) {
244
245
  type: model,
245
246
  validation: ['nonEmpty']
246
247
  },
247
- ...(model.properties)
248
+ propertiesWithoutDefaults
248
249
  },
249
250
  skipValidation: true,
250
251
  //queuedBy: otherPropertyNames,
@@ -8,7 +8,8 @@ import {
8
8
  } from './utilsAny.js'
9
9
  import {
10
10
  extractObjectData,
11
- cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl
11
+ cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl,
12
+ propertiesWithoutDefaults
12
13
  } from './utils.js'
13
14
  import { allCombinations } from "./combinations.js"
14
15
  import { fireChangeTriggers } from "./changeTriggers.js"
@@ -206,7 +207,7 @@ function defineUpdateAction(config, context) {
206
207
  const action = new ActionDefinition({
207
208
  name: actionName,
208
209
  properties: {
209
- ...(model.properties)
210
+ ...propertiesWithoutDefaults(model.properties)
210
211
  },
211
212
  access: config.updateAccess || config.writeAccess,
212
213
  accessControl,
@@ -232,7 +233,7 @@ function defineUpdateTrigger(config, context) {
232
233
  const trigger = new TriggerDefinition({
233
234
  name: triggerName,
234
235
  properties: {
235
- ...(model.properties)
236
+ ...propertiesWithoutDefaults(model.properties)
236
237
  },
237
238
  skipValidation: true,
238
239
  queuedBy: otherPropertyNames,
@@ -285,7 +286,7 @@ function defineSetOrUpdateAction(config, context) {
285
286
  const action = new ActionDefinition({
286
287
  name: actionName,
287
288
  properties: {
288
- ...(model.properties)
289
+ ...propertiesWithoutDefaults(model.properties)
289
290
  },
290
291
  access: config.updateAccess || config.writeAccess,
291
292
  accessControl,
@@ -311,7 +312,7 @@ function defineSetOrUpdateTrigger(config, context) {
311
312
  const trigger = new TriggerDefinition({
312
313
  name: triggerName,
313
314
  properties: {
314
- ...(model.properties)
315
+ ...propertiesWithoutDefaults(model.properties)
315
316
  },
316
317
  skipValidation: true,
317
318
  queuedBy: otherPropertyNames,
@@ -9,7 +9,8 @@ import {
9
9
  extractIdParts,
10
10
  prepareAccessControl,
11
11
  cloneAndPrepareAccessControl,
12
- defineIndex
12
+ defineIndex,
13
+ propertiesWithoutDefaults
13
14
  } from './utils.js'
14
15
  import { fireChangeTriggers } from "./changeTriggers.js"
15
16
  import { extractTypeAndIdParts } from './utilsAny.js'
@@ -61,7 +62,8 @@ export function defineObjectView(config, context, external = true) {
61
62
  const path = config.fields ? modelRuntime().limitedPath(idProp, config.fields) : modelRuntime().path(idProp)
62
63
  return path
63
64
  }
64
- const id = idProp ? idProp : idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
65
+ const idParts = extractIdParts(otherPropertyNames, properties)
66
+ const id = idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
65
67
  const path = config.fields ? modelRuntime().limitedPath(id, config.fields) : modelRuntime().path(id)
66
68
  return path
67
69
  }
@@ -254,7 +256,7 @@ export function defineUpdateAction(config, context) {
254
256
  const action = new ActionDefinition({
255
257
  name: actionName,
256
258
  properties: {
257
- ...(model.properties)
259
+ ...propertiesWithoutDefaults(model.properties)
258
260
  },
259
261
  access: config.updateAccess || config.writeAccess,
260
262
  accessControl,
@@ -280,7 +282,7 @@ export function defineUpdateTrigger(config, context) {
280
282
  const trigger = new TriggerDefinition({
281
283
  name: triggerName,
282
284
  properties: {
283
- ...(model.properties)
285
+ ...propertiesWithoutDefaults(model.properties)
284
286
  },
285
287
  skipValidation: true,
286
288
  queuedBy: otherPropertyNames,
@@ -332,7 +334,7 @@ export function defineSetOrUpdateAction(config, context) {
332
334
  const action = new ActionDefinition({
333
335
  name: actionName,
334
336
  properties: {
335
- ...(model.properties)
337
+ ...propertiesWithoutDefaults(model.properties)
336
338
  },
337
339
  access: config.updateAccess || config.writeAccess,
338
340
  accessControl,
@@ -358,7 +360,7 @@ export function defineSetOrUpdateTrigger(config, context) {
358
360
  const trigger = new TriggerDefinition({
359
361
  name: triggerName,
360
362
  properties: {
361
- ...(model.properties)
363
+ ...propertiesWithoutDefaults(model.properties)
362
364
  },
363
365
  skipValidation: true,
364
366
  queuedBy: otherPropertyNames,
package/src/utils.ts CHANGED
@@ -18,6 +18,32 @@ import pluralize from 'pluralize'
18
18
  import { ModelDefinitionSpecificationWithEntity } from "./entityUtils.js"
19
19
  import { AccessControlSettings, ModelDefinitionSpecificationWithAccessControl, PreparedAccessControlSettings } from "./types.js"
20
20
 
21
+ export function definitionWithoutDefaults(definition: PropertyDefinitionSpecification) {
22
+ const newDefinition = { ...definition }
23
+ if(newDefinition.default) {
24
+ delete newDefinition.default
25
+ }
26
+ if(newDefinition.of) {
27
+ newDefinition.of = definitionWithoutDefaults(newDefinition.of)
28
+ }
29
+ if(newDefinition.items) {
30
+ newDefinition.items = definitionWithoutDefaults(newDefinition.items)
31
+ }
32
+ if(newDefinition.properties) {
33
+ newDefinition.properties = propertiesWithoutDefaults(newDefinition.properties)
34
+ }
35
+ return newDefinition
36
+ }
37
+
38
+ export function propertiesWithoutDefaults(properties: Record<string, any>) {
39
+ const newProperties = {}
40
+ for(const key in properties) {
41
+ const property = properties[key]
42
+ newProperties[key] = definitionWithoutDefaults(property)
43
+ }
44
+ return newProperties
45
+ }
46
+
21
47
  export function extractIdParts(otherPropertyNames: string[], properties: Record<string, any>) {
22
48
  const idParts = []
23
49
  for (const propertyName of otherPropertyNames) {
package/src/utilsAny.ts CHANGED
@@ -302,12 +302,12 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
302
302
  await output.delete({ id: type })
303
303
  }
304
304
  } catch(e) {
305
- output.debug('typeJson', typeJson, 'id', id)
306
- console.error("Error parsing typeJson", typeJson, e)
305
+ console.debug("Error parsing typeJson", typeJson, e, 'in id', id, "from table", tableName)
306
+ console.error("Error parsing typeJson", typeJson, e, 'in id', id, "from table", tableName)
307
307
  }
308
308
  })
309
309
  },
310
- parameters: { tableName: tableName }
310
+ parameters: { tableName: tableName, }
311
311
  }
312
312
  return
313
313
  }
@@ -324,17 +324,17 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
324
324
  await index.onChange(async (obj, oldObj) => {
325
325
  const id = obj?.id ?? oldObj?.id
326
326
  const typeJson = id.slice(0, id.indexOf(':'))
327
- try {
327
+ try {
328
328
  const type = JSON.parse(typeJson)
329
- const count = await index.count({ gte: type+':', lte: typeJson+'_\xFF\xFF\xFF\xFF', limit: 1 })
329
+ const count = await index.count({ gte: typeJson+':', lte: typeJson+'_\xFF\xFF\xFF\xFF', limit: 1 })
330
330
  if(count > 0) {
331
331
  await output.put({ id: type })
332
332
  } else {
333
333
  await output.delete({ id: type })
334
334
  }
335
335
  } catch(e) {
336
- output.debug('typeJson', typeJson, 'id', id)
337
- console.error("Error parsing typeJson", typeJson, e)
336
+ output.debug("Error parsing typeJson", typeJson, e, 'in id', id, "from index", indexName)
337
+ console.error("Error parsing typeJson", typeJson, e, 'in id', id, "from index", indexName)
338
338
  }
339
339
  })
340
340
  },
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "sourceMap": true,
3
4
  "composite": true,
4
5
  "module": "nodenext",
5
6
  "moduleResolution": "nodenext",