@live-change/framework 0.9.74 → 0.9.76

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.ts ADDED
@@ -0,0 +1,39 @@
1
+ import App from './lib/App.js'
2
+
3
+ export default App
4
+
5
+ import ActionDefinition from './lib/definition/ActionDefinition.js'
6
+ import EventDefinition from './lib/definition/EventDefinition.js'
7
+ import ForeignIndexDefinition from './lib/definition/ForeignIndexDefinition.js'
8
+ import ForeignModelDefinition from './lib/definition/ForeignModelDefinition.js'
9
+ import IndexDefinition from './lib/definition/IndexDefinition.js'
10
+ import ModelDefinition from './lib/definition/ModelDefinition.js'
11
+ import PropertyDefinition from './lib/definition/PropertyDefinition.js'
12
+ import ServiceDefinition from './lib/definition/ServiceDefinition.js'
13
+ import TriggerDefinition from './lib/definition/TriggerDefinition.js'
14
+ import ViewDefinition from './lib/definition/ViewDefinition.js'
15
+
16
+ export {
17
+ ActionDefinition,
18
+ EventDefinition,
19
+ ForeignIndexDefinition,
20
+ ForeignModelDefinition,
21
+ IndexDefinition,
22
+ ModelDefinition,
23
+ PropertyDefinition,
24
+ ServiceDefinition,
25
+ TriggerDefinition,
26
+ ViewDefinition
27
+ }
28
+
29
+ // Export all types from definition files
30
+ export type { ActionDefinitionSpecification, ActionParameters } from './lib/definition/ActionDefinition.js'
31
+ export type { EventDefinitionSpecification, EventParameters } from './lib/definition/EventDefinition.js'
32
+ export type { IndexDefinitionSpecification } from './lib/definition/IndexDefinition.js'
33
+ export type { ModelDefinitionSpecification, ModelIndexDefinitionSpecification, ModelPropertyDefinitionSpecification } from './lib/definition/ModelDefinition.js'
34
+ export type { PropertyDefinitionSpecification, ValidationSpecification, ValidationSpecificationObject } from './lib/definition/PropertyDefinition.js'
35
+ export type { ViewDefinitionSpecification, ViewDefinitionSpecificationBase, ViewDefinitionSpecificationObservable, ViewDefinitionSpecificationDaoPath, ViewDefinitionSpecificationFetch } from './lib/definition/ViewDefinition.js'
36
+ export type { TriggerDefinitionSpecification } from './lib/definition/TriggerDefinition.js'
37
+ export type { ClientContext, ContextBase, ViewContext, ActionContext } from './lib/definition/types.js'
38
+ export type { ServiceDefinitionSpecification } from './lib/definition/ServiceDefinition.js'
39
+ export type { AccessSpecification, AccessFunction } from './lib/processors/accessMethod.js'
package/lib/App.js CHANGED
@@ -36,6 +36,10 @@ import Debug from 'debug'
36
36
 
37
37
  const debug = Debug('framework')
38
38
 
39
+
40
+ import * as utils from './utils.js'
41
+ import * as validation from './utils/validation.js'
42
+
39
43
  class App {
40
44
 
41
45
  constructor(config = {}) {
@@ -82,8 +86,25 @@ class App {
82
86
  this.startedServices = {}
83
87
  this.triggerRoutes = {}
84
88
  this.globalViews = {}
89
+
85
90
  }
86
91
 
92
+ static app() {
93
+ if(!globalThis.liveChangeFrameworkApp) {
94
+ globalThis.liveChangeFrameworkApp = new App()
95
+ }
96
+ return globalThis.liveChangeFrameworkApp
97
+ }
98
+
99
+ static utils = utils
100
+ static validation = validation
101
+ static rangeProperties = utils.rangeProperties
102
+ static encodeIdentifier = utils.encodeIdentifier
103
+ static extractRange = utils.extractRange
104
+ static isomorphic = utils.isomorphic
105
+ static computeDefaults = utils.computeDefaults
106
+ static computeUpdates = utils.computeUpdates
107
+
87
108
  createServiceDefinition( definition ) {
88
109
  const sourceConfig = this.config && this.config.services && this.config.services.find
89
110
  && this.config.services.find(c => c.name === definition.name)
@@ -1,18 +1,17 @@
1
+ import { AccessSpecification } from "../processors/accessMethod.js"
1
2
  import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
2
- import { ExecutionContext } from "./types.js"
3
+ import type { ActionContext } from "./types.js"
3
4
 
4
- type ActionParameters = Record<string, any>
5
-
6
- export interface ActionContext extends ExecutionContext {
7
- action: any
8
- emit: (event: any) => void
9
- }
5
+ export type ActionParameters = Record<string, any>
10
6
 
11
7
  export interface ActionDefinitionSpecification {
12
8
  name: string
13
9
  properties: Record<string, PropertyDefinitionSpecification>
14
10
  returns: PropertyDefinitionSpecification,
15
- execute: (parameters: ActionParameters, context: ActionContext, emit: (event: any) => void) => any
11
+ execute: (parameters: ActionParameters, context: ActionContext, emit: (event: any) => void) => any,
12
+ access: AccessSpecification,
13
+ skipValidation: boolean,
14
+ validation: (parameters: ActionParameters, context: ActionContext) => Promise<any>
16
15
  }
17
16
 
18
17
  class ActionDefinition<T extends ActionDefinitionSpecification> {
@@ -1,6 +1,6 @@
1
1
  import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
2
2
 
3
- type EventParameters = Record<string, any>
3
+ export type EventParameters = Record<string, any>
4
4
 
5
5
  export interface EventDefinitionSpecification {
6
6
  name: string
@@ -1,9 +1,9 @@
1
1
 
2
2
  export interface IndexDefinitionSpecification {
3
3
  name: string
4
- properties: Record<string, PropertyDefinition>
4
+ property: string | string[]
5
5
  function: (...args: any[]) => any
6
- search: boolean
6
+ parameters: Record<string, any>
7
7
  storage: any
8
8
  multi: boolean,
9
9
  }
@@ -1,12 +1,24 @@
1
1
  import PropertyDefinition from "./PropertyDefinition.js"
2
2
  import type { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
3
- import type { IndexDefinitionSpecification } from "./IndexDefinition.js"
4
3
  import { crudChanges, definitionToJSON } from "../utils.js"
5
4
 
5
+ export interface ModelIndexDefinitionSpecification {
6
+ property?: string | string[]
7
+ function?: (...args: any[]) => any
8
+ parameters?: Record<string, any>
9
+ storage?: any
10
+ multi?: boolean,
11
+ }
12
+
13
+ export interface ModelPropertyDefinitionSpecification {
14
+ type: string,
15
+ index: ModelIndexDefinitionSpecification
16
+ }
17
+
6
18
  export interface ModelDefinitionSpecification {
7
19
  name: string
8
- properties: Record<string, PropertyDefinitionSpecification>
9
- indexes: Record<string, IndexDefinitionSpecification>
20
+ properties: Record<string, ModelPropertyDefinitionSpecification>
21
+ indexes: Record<string, ModelIndexDefinitionSpecification>
10
22
  onChange: (() => void)[]
11
23
  }
12
24
 
@@ -1,10 +1,18 @@
1
1
  import { typeName, definitionToJSON } from "../utils.js"
2
2
 
3
+ export interface ValidationSpecificationObject {
4
+ name: string
5
+ [key: string]: any
6
+ }
7
+
8
+ export type ValidationSpecification = ValidationSpecificationObject | string
9
+
3
10
  export interface PropertyDefinitionSpecification {
4
11
  type: string
5
12
  of?: PropertyDefinitionSpecification
6
13
  items?: PropertyDefinitionSpecification
7
- properties?: Record<string, PropertyDefinitionSpecification>
14
+ properties?: Record<string, PropertyDefinitionSpecification>,
15
+ validation: ValidationSpecification[]
8
16
  }
9
17
 
10
18
  class PropertyDefinition<T extends PropertyDefinitionSpecification> {
@@ -72,7 +72,7 @@ function createForeignIndexProxy(definition, model) {
72
72
 
73
73
 
74
74
 
75
- interface ServiceDefinitionSpecification {
75
+ export interface ServiceDefinitionSpecification {
76
76
 
77
77
  }
78
78
 
@@ -1,14 +1,17 @@
1
1
  import PropertyDefinition, { PropertyDefinitionSpecification } from "./PropertyDefinition.js"
2
2
 
3
- import type { ExecutionContext } from "./types.js"
3
+ import type { ViewContext } from "./types.js"
4
+
5
+ import type { AccessSpecification } from "../processors/accessMethod.js"
4
6
 
5
7
  export interface ViewDefinitionSpecificationBase {
6
8
  name: string
7
9
  properties: Record<string, PropertyDefinitionSpecification>
8
10
  returns: PropertyDefinitionSpecification
9
- }
10
-
11
- export interface ViewContext extends ExecutionContext {
11
+ internal: boolean,
12
+ access: AccessSpecification,
13
+ skipValidation: boolean,
14
+ validation: (parameters: Record<string, any>, context: ViewContext) => Promise<any>
12
15
  }
13
16
 
14
17
  export interface ViewDefinitionSpecificationObservable extends ViewDefinitionSpecificationBase {
@@ -6,7 +6,16 @@ export interface ClientContext {
6
6
  roles: string[]
7
7
  }
8
8
 
9
- export interface ExecutionContext {
9
+ export interface ContextBase {
10
10
  client: ClientContext
11
- service: any
12
- }
11
+ service: any,
12
+ visibilityTest: boolean
13
+ }
14
+
15
+ export interface ViewContext extends ContextBase {
16
+ view: any,
17
+ }
18
+
19
+ export interface ActionContext extends ContextBase {
20
+ action: any
21
+ }
@@ -1,4 +1,10 @@
1
- export default function getAccessMethod(access) {
1
+ import { ActionContext, ViewContext } from "../definition/types.js"
2
+
3
+ export type AccessFunction = (params: Record<string, any>, context: ViewContext | ActionContext) => boolean
4
+
5
+ export type AccessSpecification = AccessFunction | string[] | 'internal'
6
+
7
+ export default function getAccessMethod(access: AccessSpecification) {
2
8
  if(typeof access == 'function') {
3
9
  return access
4
10
  } else if(Array.isArray(access)) {
@@ -24,6 +24,10 @@ export default function(service, app) {
24
24
  if(!action.skipValidation) {
25
25
  await validate(args[0], validators, { source: action, action, service, app, ...context })
26
26
  }
27
+ if(typeof action.validation === 'function') {
28
+ const result = await action.validation(args[0], { source: action, action, service, app, ...context })
29
+ if(result) throw result
30
+ }
27
31
  return oldExec.apply(action, args)
28
32
  }
29
33
  }
@@ -31,25 +35,35 @@ export default function(service, app) {
31
35
  }
32
36
  for(let viewName in service.views) {
33
37
  const view = service.views[viewName]
34
- if(view.skipValidation) continue
38
+ if(view.skipValidation && !view.validation) continue
35
39
  const validators = getValidators(view, service, view)
36
40
  if(Object.keys(validators).length > 0) {
37
41
  if (view.observable) {
38
42
  const oldObservable = view.observable
39
43
  view.observable = async (...args) => {
40
44
  const context = args[1]
41
- return validate(args[0], validators, { source: view, view, service, app, ...context }).then(() =>
42
- oldObservable.apply(view, args)
43
- )
45
+ if(!view.skipValidation) {
46
+ await validate(args[0], validators, { source: view, view, service, app, ...context })
47
+ }
48
+ if(typeof view.validation === 'function') {
49
+ const result = await view.validation(args[0], { source: view, view, service, app, ...context })
50
+ if(result) throw result
51
+ }
52
+ return oldObservable.apply(view, args)
44
53
  }
45
54
  }
46
55
  if(view.get) {
47
56
  const oldGet = view.get
48
57
  view.get = async (...args) => {
49
58
  const context = args[1]
50
- return validate(args[0], validators, { source: view, view, service, app, ...context }).then(() =>
51
- oldGet.apply(view, args)
52
- )
59
+ if(!view.skipValidation) {
60
+ await validate(args[0], validators, { source: view, view, service, app, ...context })
61
+ }
62
+ if(typeof view.validation === 'function') {
63
+ const result = await view.validation(args[0], { source: view, view, service, app, ...context })
64
+ if(result) throw result
65
+ }
66
+ return oldGet.apply(view, args)
53
67
  }
54
68
  }
55
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.9.74",
3
+ "version": "0.9.76",
4
4
  "description": "Live Change Framework - ultimate solution for real time mobile/web apps",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,8 +22,11 @@
22
22
  },
23
23
  "homepage": "https://github.com/live-change/live-change-stack",
24
24
  "devDependencies": {
25
- "@live-change/dao": "^0.9.74",
26
- "@live-change/uid": "^0.9.74"
25
+ "@live-change/dao": "^0.9.76",
26
+ "@live-change/uid": "^0.9.76",
27
+ "typedoc": "0.28.3",
28
+ "typedoc-plugin-markdown": "^4.6.3",
29
+ "typedoc-plugin-rename-defaults": "^0.7.3"
27
30
  },
28
- "gitHead": "cdb37d2051a08b4425fcb282dfd51a2c8f3112ba"
31
+ "gitHead": "7b28068b9dca33af82e94db52b8a778c289edfbc"
29
32
  }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ "composite": true,
4
+ "module": "nodenext",
5
+ "moduleResolution": "nodenext",
6
+ "allowSyntheticDefaultImports": true,
7
+
8
+ "target": "ES2020",
9
+ "useDefineForClassFields": true,
10
+ "lib": ["ES2020", "DOM"],
11
+
12
+ /* Linting */
13
+ "strict": false,
14
+ "noUnusedLocals": false,
15
+ "noUnusedParameters": false,
16
+ "noFallthroughCasesInSwitch": true,
17
+ "outDir": "dist",
18
+ "checkJs": false,
19
+ "esModuleInterop": true, // Enable interop for ES modules
20
+ "resolveJsonModule": true, // Allow importing JSON files
21
+ "skipLibCheck": true,
22
+ "noImplicitAny": false
23
+ },
24
+ "files": ["index.ts"],
25
+ "include": [
26
+ "lib/**/*.ts", "lib/**/*.js", "index.ts"],
27
+ "exclude": ["node_modules/@types", "node_modules/**/*.d.ts", "**/*.test.js", "**/CMakeFiles/**"]
28
+ }
29
+
package/typedoc.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "entryPoints": ["index.ts"],
3
+ "out": "docs",
4
+ "includeVersion": true,
5
+ "excludePrivate": true,
6
+ "excludeInternal": true,
7
+ "excludeProtected": true,
8
+ "tsconfig": "./tsconfig.json",
9
+ "plugin": [
10
+ "typedoc-plugin-markdown",
11
+ "typedoc-plugin-rename-defaults"
12
+ ],
13
+ "sourceLinkTemplate": "https://github.com/live-change/live-change-stack/blob/master/framework/framework/{path}#L{line}"
14
+ }
package/index.js DELETED
@@ -1,46 +0,0 @@
1
- import App from './lib/App.js'
2
-
3
- App.app = () => {
4
- if(!globalThis.liveChangeFrameworkApp) {
5
- globalThis.liveChangeFrameworkApp = new App()
6
- }
7
- return globalThis.liveChangeFrameworkApp
8
- }
9
-
10
- import * as utils from './lib/utils.js'
11
- import * as validation from './lib/utils/validation.js'
12
-
13
- App.utils = utils
14
- App.validation = validation
15
- App.rangeProperties = utils.rangeProperties
16
- App.encodeIdentifier = utils.encodeIdentifier
17
- App.extractRange = utils.extractRange
18
- App.isomorphic = utils.isomorphic
19
- App.computeDefaults = utils.computeDefaults
20
- App.computeUpdates = utils.computeUpdates
21
-
22
- export default App
23
-
24
- import ActionDefinition from './lib/definition/ActionDefinition.js'
25
- import EventDefinition from './lib/definition/EventDefinition.js'
26
- import ForeignIndexDefinition from './lib/definition/ForeignIndexDefinition.js'
27
- import ForeignModelDefinition from './lib/definition/ForeignModelDefinition.js'
28
- import IndexDefinition from './lib/definition/IndexDefinition.js'
29
- import ModelDefinition from './lib/definition/ModelDefinition.js'
30
- import PropertyDefinition from './lib/definition/PropertyDefinition.js'
31
- import ServiceDefinition from './lib/definition/ServiceDefinition.js'
32
- import TriggerDefinition from './lib/definition/TriggerDefinition.js'
33
- import ViewDefinition from './lib/definition/ViewDefinition.js'
34
-
35
- export {
36
- ActionDefinition,
37
- EventDefinition,
38
- ForeignIndexDefinition,
39
- ForeignModelDefinition,
40
- IndexDefinition,
41
- ModelDefinition,
42
- PropertyDefinition,
43
- ServiceDefinition,
44
- TriggerDefinition,
45
- ViewDefinition
46
- }