@live-change/relations-plugin 0.9.78 → 0.9.80

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.78",
3
+ "version": "0.9.80",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -22,8 +22,8 @@
22
22
  },
23
23
  "type": "module",
24
24
  "dependencies": {
25
- "@live-change/framework": "^0.9.78",
25
+ "@live-change/framework": "^0.9.80",
26
26
  "pluralize": "^8.0.0"
27
27
  },
28
- "gitHead": "747a9cb02377d924583925508f082c8dd5031d43"
28
+ "gitHead": "8c4e9d0d1415c8805f0a56dbef07d7b8333632a4"
29
29
  }
package/src/entity.ts CHANGED
@@ -4,23 +4,28 @@ import {
4
4
 
5
5
  import {
6
6
  defineView, defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineCreateAction,
7
- defineUpdateAction, defineDeleteAction, defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger
7
+ defineUpdateAction, defineDeleteAction, defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
8
+ ModelDefinitionSpecificationWithEntity,
9
+ EntityConfig,
10
+ EntityContext
8
11
  } from './entityUtils.js'
12
+ import { AccessControlSettings, ModelDefinitionSpecificationExtended } from './types.js'
13
+ import { AccessSpecification, ModelDefinitionSpecification } from '@live-change/framework'
9
14
 
10
- const annotation = 'entity'
11
-
15
+ export type { EntityConfig, ModelDefinitionSpecificationWithEntity } from './entityUtils.js'
12
16
 
13
17
  export default function(service, app) {
14
18
  if (!service) throw new Error("no service")
15
19
  if (!app) throw new Error("no app")
16
20
 
17
21
  for(let modelName in service.models) {
18
- const model = service.models[modelName]
19
- const config = model[annotation]
22
+ const model: ModelDefinitionSpecificationWithEntity =
23
+ service.models[modelName] as ModelDefinitionSpecificationWithEntity
24
+ const config:EntityConfig = model.entity
20
25
  if(!config) continue
21
26
 
22
- if (model[annotation + 'Processed']) throw new Error("duplicated processing of " + annotation + " processor")
23
- model[annotation + 'Processed'] = true
27
+ if (model.entityProcessed) throw new Error("duplicated processing of entity processor")
28
+ model.entityProcessed = true
24
29
 
25
30
  const originalModelProperties = { ...model.properties }
26
31
  const modelProperties = Object.keys(model.properties)
@@ -45,13 +50,13 @@ export default function(service, app) {
45
50
  //console.log("PPP", others)
46
51
  const objectType = service.name + '_' + modelName
47
52
 
48
- const context = {
53
+ const context: EntityContext = {
49
54
  service, app, model, originalModelProperties, modelProperties, modelPropertyName, modelRuntime,
50
- modelName, writeableProperties, annotation, objectType
55
+ modelName, writeableProperties, annotation: 'entity', objectType
51
56
  }
52
57
 
53
58
  defineView(config, context, config.readAccess || config.readAccessControl || config.writeAccessControl)
54
- defineGlobalRangeView(config, context, config.readAllAccess)
59
+ defineGlobalRangeView(config, context, !!config.readAllAccess)
55
60
  /// TODO: multiple views with limited fields
56
61
 
57
62
  defineCreatedEvent(config, context)
@@ -4,16 +4,53 @@ import {
4
4
  includeAccessRoles, defineGlobalRangeView
5
5
  } from './utils.js'
6
6
  import { fireChangeTriggers } from "./changeTriggers.js"
7
- import App, { ServiceDefinition } from '@live-change/framework'
7
+ import App, { AccessSpecification, ModelDefinitionSpecification, PropertyDefinitionSpecification, ServiceDefinition } from '@live-change/framework'
8
8
  import {
9
9
  PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition, TriggerDefinition
10
10
  } from "@live-change/framework"
11
11
  import pluralize from 'pluralize'
12
12
 
13
13
  import { ServiceDefinitionSpecification } from "@live-change/framework"
14
- import { ActionDefinitionSpecificationAC, ViewDefinitionSpecificationAC, TriggerDefinitionSpecificationAC } from "./types.js"
14
+ import { ActionDefinitionSpecificationAC, ViewDefinitionSpecificationAC, TriggerDefinitionSpecificationAC,
15
+ ModelDefinitionSpecificationExtended, AccessControlSettings } from "./types.js"
15
16
  import { EventDefinitionSpecification } from "@live-change/framework"
16
17
 
18
+ export interface EntityConfig {
19
+ readAccessControl?: AccessControlSettings
20
+ writeAccessControl?: AccessControlSettings
21
+ createAccessControl?: AccessControlSettings
22
+ updateAccessControl?: AccessControlSettings
23
+ deleteAccessControl?: AccessControlSettings
24
+
25
+ readAllAccess?: AccessSpecification
26
+ readAccess?: AccessSpecification
27
+ writeAccess?: AccessSpecification
28
+ createAccess?: AccessSpecification
29
+ updateAccess?: AccessSpecification
30
+ deleteAccess?: AccessSpecification
31
+
32
+ writeableProperties?: string[]
33
+ }
34
+
35
+ export interface ModelDefinitionSpecificationWithEntity extends ModelDefinitionSpecificationExtended {
36
+ entity: EntityConfig
37
+ entityProcessed: boolean
38
+ }
39
+
40
+ export interface EntityContext {
41
+ service: ServiceDefinitionSpecification
42
+ modelName: string
43
+ modelPropertyName: string
44
+ model: ModelDefinitionSpecificationWithEntity
45
+ originalModelProperties: Record<string, PropertyDefinitionSpecification>
46
+ modelProperties: string[]
47
+ writeableProperties: string[]
48
+ objectType: string
49
+ app: App,
50
+ modelRuntime: any,
51
+ annotation: 'entity'
52
+ }
53
+
17
54
 
18
55
  export function entityAccessControl({service, modelName, modelPropertyName}, accessControl) {
19
56
  if(!accessControl) return undefined
@@ -159,7 +196,7 @@ export function defineCreateAction(config, context) {
159
196
  waitForEvents: true,
160
197
  execute: () => { throw new Error("not generated yet") }
161
198
  })
162
- const validators = App.validation.getValidators(action, service, action)
199
+ const validators = App.validation.getValidators(action, service)
163
200
  const validationContext = { source: action, action }
164
201
  action.execute = getCreateFunction( validators, validationContext, config, context)
165
202
  service.actions[actionName] = action
@@ -179,7 +216,7 @@ export function defineCreateTrigger(config, context) {
179
216
  waitForEvents: true,
180
217
  execute: () => { throw new Error("not generated yet") }
181
218
  })
182
- const validators = App.validation.getValidators(trigger, service, trigger)
219
+ const validators = App.validation.getValidators(trigger, service)
183
220
  const validationContext = { source: trigger, trigger }
184
221
  trigger.execute = getCreateFunction( validators, validationContext, config, context)
185
222
  }
@@ -233,7 +270,7 @@ export function defineUpdateAction(config, context) {
233
270
  waitForEvents: true,
234
271
  execute: () => { throw new Error("not generated yet") }
235
272
  })
236
- const validators = App.validation.getValidators(action, service, action)
273
+ const validators = App.validation.getValidators(action, service)
237
274
  const validationContext = { source: action, action }
238
275
  action.execute = getUpdateFunction( validators, validationContext, config, context)
239
276
  service.actions[actionName] = action
@@ -258,7 +295,7 @@ export function defineUpdateTrigger(config, context) {
258
295
  waitForEvents: true,
259
296
  execute: () => { throw new Error("not generated yet") }
260
297
  })
261
- const validators = App.validation.getValidators(trigger, service, trigger)
298
+ const validators = App.validation.getValidators(trigger, service)
262
299
  const validationContext = { source: trigger, trigger }
263
300
  trigger.execute = getUpdateFunction( validators, validationContext, config, context)
264
301
  service.triggers[triggerName] = [trigger]
package/src/propertyOf.js CHANGED
@@ -55,7 +55,6 @@ export default function(service, app) {
55
55
 
56
56
  defineGlobalRangeView(config, context, config.readAllAccess)
57
57
 
58
-
59
58
  defineSetEvent(config, context, generateId)
60
59
  defineUpdatedEvent(config, context, generateId)
61
60
  defineTransferredEvent(config, context, generateId)
package/src/types.ts CHANGED
@@ -2,7 +2,8 @@ import {
2
2
  ViewContext, ViewDefinitionSpecificationObservable, ViewDefinitionSpecificationDaoPath,
3
3
  ViewDefinitionSpecificationFetch,
4
4
  ActionDefinitionSpecification,
5
- TriggerDefinitionSpecification
5
+ TriggerDefinitionSpecification,
6
+ ModelDefinitionSpecification
6
7
  } from "@live-change/framework"
7
8
 
8
9
  export type AccessControlSettings = string | string[] | {
@@ -33,4 +34,23 @@ export interface ActionDefinitionSpecificationAC extends ActionDefinitionSpecifi
33
34
 
34
35
  export interface TriggerDefinitionSpecificationAC extends TriggerDefinitionSpecification {
35
36
  accessControl?: AccessControlSettings
36
- }
37
+ }
38
+
39
+ export interface CrudSettings {
40
+ read?: string
41
+ create?: string
42
+ update?: string
43
+ delete?: string
44
+ }
45
+
46
+ export interface Identifier {
47
+ name: string
48
+ field: string
49
+ }
50
+
51
+ export interface ModelDefinitionSpecificationExtended extends ModelDefinitionSpecification {
52
+ crud: CrudSettings,
53
+ identifiers: Identifier[]
54
+ }
55
+
56
+
package/src/utils.js CHANGED
@@ -250,7 +250,12 @@ export function includeAccessRoles(model, access) {
250
250
 
251
251
  export function defineGlobalRangeView(config, context, external = true) {
252
252
  const { service, modelRuntime, modelPropertyName, modelName, model } = context
253
- const viewName = (config.prefix || '' ) + pluralize(config.prefix ? modelName : modelPropertyName) + (config.suffix || '')
253
+ const alreadyPlural = pluralize.isPlural(modelPropertyName)
254
+ const prefix = (config.prefix || '') + (alreadyPlural ? 'all' : '')
255
+ const viewName =
256
+ prefix
257
+ + pluralize(prefix ? modelName : modelPropertyName)
258
+ + (config.suffix || '')
254
259
  if(external) model.crud.range = viewName
255
260
  service.views[viewName] = new ViewDefinition({
256
261
  name: viewName,
@@ -272,4 +277,4 @@ export function defineGlobalRangeView(config, context, external = true) {
272
277
  return path
273
278
  }
274
279
  })
275
- }
280
+ }