@live-change/relations-plugin 0.9.79 → 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 +3 -3
- package/src/entity.ts +15 -10
- package/src/entityUtils.ts +39 -2
- package/src/propertyOf.js +0 -1
- package/src/types.ts +22 -2
- package/src/utils.js +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.9.
|
|
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.
|
|
25
|
+
"@live-change/framework": "^0.9.80",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
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
|
-
|
|
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 =
|
|
19
|
-
|
|
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
|
|
23
|
-
model
|
|
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)
|
package/src/entityUtils.ts
CHANGED
|
@@ -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
|
|
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
|
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
|
|
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
|
+
}
|