@cybertale/resolver 0.1.2 → 1.0.1
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 +28 -19
- package/src/index.ts +8 -0
- package/src/resolver/assignments/formWrapper.ts +84 -0
- package/src/resolver/assignments/resolverInterface.ts +12 -0
- package/src/resolver/assignments/rowWrapper.ts +19 -0
- package/src/resolver/assignments/tableWrapper.ts +15 -0
- package/src/resolver/assignments/wrapperAbstract.ts +67 -0
- package/src/resolver/form/value.ts +2 -38
- package/src/resolver/handlers/template.ts +59 -0
- package/src/resolver/transform/json.ts +5 -23
- package/src/resolver/transform/stat.ts +7 -32
package/package.json
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cybertale/resolver",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"type": "module",
|
|
5
|
-
"main": "
|
|
6
|
-
"module": "
|
|
7
|
-
"types": "
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "https://github.com/Joso997/cybertale-resolver.git"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/Joso997/cybertale-resolver#readme",
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/Joso997/cybertale-resolver/issues"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@cybertale/resolver",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "src/index.ts",
|
|
6
|
+
"module": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/Joso997/cybertale-resolver.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/Joso997/cybertale-resolver#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/Joso997/cybertale-resolver/issues"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./src/index.ts",
|
|
19
|
+
"require": "./src/index.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@cybertale/interface": "*"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"uuid": "^10.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -23,3 +23,11 @@ export * as FinalizeDefaults from './resolver/finalize/defaults'
|
|
|
23
23
|
export * as HandlersRemove from './resolver/handlers/remove'
|
|
24
24
|
export * as HandlersInsert from './resolver/handlers/insert'
|
|
25
25
|
export * as HandlersUpdate from './resolver/handlers/update'
|
|
26
|
+
export * as HandlersTemplate from './resolver/handlers/template'
|
|
27
|
+
|
|
28
|
+
// assignments
|
|
29
|
+
export { WrapperAbstract } from './resolver/assignments/wrapperAbstract'
|
|
30
|
+
export { FormWrapper } from './resolver/assignments/formWrapper'
|
|
31
|
+
export { RowWrapper } from './resolver/assignments/rowWrapper'
|
|
32
|
+
export { TableWrapper } from './resolver/assignments/tableWrapper'
|
|
33
|
+
export type { ResolverInterface } from './resolver/assignments/resolverInterface'
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { EventHandlerType, ObjectTemplate } from '@cybertale/interface'
|
|
2
|
+
import { WrapperAbstract } from './wrapperAbstract'
|
|
3
|
+
|
|
4
|
+
export class FormWrapper extends WrapperAbstract {
|
|
5
|
+
Button (
|
|
6
|
+
eventHandler: EventHandlerType,
|
|
7
|
+
objectTemplates: ObjectTemplate[],
|
|
8
|
+
refreshPage: () => void,
|
|
9
|
+
append: (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[],
|
|
10
|
+
id: string,
|
|
11
|
+
inEdit: boolean,
|
|
12
|
+
version: string,
|
|
13
|
+
): FormWrapper {
|
|
14
|
+
this.eventHandler = eventHandler
|
|
15
|
+
this.objectTemplates = objectTemplates
|
|
16
|
+
this.refreshPage = refreshPage
|
|
17
|
+
this.append = append
|
|
18
|
+
this.id = id
|
|
19
|
+
this.inEdit = inEdit
|
|
20
|
+
this.version = version
|
|
21
|
+
return this
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
DataList (
|
|
25
|
+
eventHandler: EventHandlerType,
|
|
26
|
+
objectTemplates: ObjectTemplate[],
|
|
27
|
+
refreshPage: () => void,
|
|
28
|
+
): FormWrapper {
|
|
29
|
+
this.eventHandler = eventHandler
|
|
30
|
+
this.objectTemplates = objectTemplates
|
|
31
|
+
this.refreshPage = refreshPage
|
|
32
|
+
return this
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ModalList (
|
|
36
|
+
eventHandler: EventHandlerType,
|
|
37
|
+
objectTemplates: ObjectTemplate[],
|
|
38
|
+
refreshPage: () => void,
|
|
39
|
+
): FormWrapper {
|
|
40
|
+
this.eventHandler = eventHandler
|
|
41
|
+
this.objectTemplates = objectTemplates
|
|
42
|
+
this.refreshPage = refreshPage
|
|
43
|
+
return this
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
SelectList (
|
|
47
|
+
eventHandler: EventHandlerType,
|
|
48
|
+
objectTemplates: ObjectTemplate[],
|
|
49
|
+
refreshPage: () => void,
|
|
50
|
+
append: (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[],
|
|
51
|
+
): FormWrapper {
|
|
52
|
+
this.eventHandler = eventHandler
|
|
53
|
+
this.objectTemplates = objectTemplates
|
|
54
|
+
this.refreshPage = refreshPage
|
|
55
|
+
this.append = append
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Field (
|
|
60
|
+
eventHandler: EventHandlerType,
|
|
61
|
+
objectTemplates: ObjectTemplate[],
|
|
62
|
+
refreshPage: () => void,
|
|
63
|
+
append: (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[],
|
|
64
|
+
): FormWrapper {
|
|
65
|
+
this.eventHandler = eventHandler
|
|
66
|
+
this.objectTemplates = objectTemplates
|
|
67
|
+
this.refreshPage = refreshPage
|
|
68
|
+
this.append = append
|
|
69
|
+
return this
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Radio (
|
|
73
|
+
eventHandler: EventHandlerType,
|
|
74
|
+
objectTemplates: ObjectTemplate[],
|
|
75
|
+
refreshPage: () => void,
|
|
76
|
+
append: (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[],
|
|
77
|
+
): FormWrapper {
|
|
78
|
+
this.eventHandler = eventHandler
|
|
79
|
+
this.objectTemplates = objectTemplates
|
|
80
|
+
this.refreshPage = refreshPage
|
|
81
|
+
this.append = append
|
|
82
|
+
return this
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ObjectTemplate } from '@cybertale/interface'
|
|
2
|
+
|
|
3
|
+
export interface ResolverInterface<T> {
|
|
4
|
+
FormSelectList (wrapper: T): Promise<ObjectTemplate[]>
|
|
5
|
+
FormModalDataList (wrapper: T): Promise<ObjectTemplate[]>
|
|
6
|
+
FormDataList (wrapper: T): Promise<ObjectTemplate[]>
|
|
7
|
+
FormButton (wrapper: T): Promise<ObjectTemplate[]>
|
|
8
|
+
FormRadio (wrapper: T): Promise<ObjectTemplate[]>
|
|
9
|
+
FormField (wrapper: T): Promise<ObjectTemplate[]>
|
|
10
|
+
RowButton (wrapper: T): Promise<ObjectTemplate[]>
|
|
11
|
+
TableButton (wrapper: T): Promise<ObjectTemplate[]>
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { EventHandlerType, ObjectTemplate } from '@cybertale/interface'
|
|
2
|
+
import { WrapperAbstract } from './wrapperAbstract'
|
|
3
|
+
|
|
4
|
+
export class RowWrapper extends WrapperAbstract {
|
|
5
|
+
public Button (
|
|
6
|
+
eventHandler: EventHandlerType,
|
|
7
|
+
objectTemplates: ObjectTemplate[],
|
|
8
|
+
refreshPage: () => void,
|
|
9
|
+
id: string,
|
|
10
|
+
version: string,
|
|
11
|
+
): RowWrapper {
|
|
12
|
+
this.eventHandler = eventHandler
|
|
13
|
+
this.objectTemplates = objectTemplates
|
|
14
|
+
this.refreshPage = refreshPage
|
|
15
|
+
this.id = id
|
|
16
|
+
this.version = version
|
|
17
|
+
return this
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { EventHandlerType, ObjectTemplate } from '@cybertale/interface'
|
|
2
|
+
import { WrapperAbstract } from './wrapperAbstract'
|
|
3
|
+
|
|
4
|
+
export class TableWrapper extends WrapperAbstract {
|
|
5
|
+
public Button (
|
|
6
|
+
eventHandler: EventHandlerType,
|
|
7
|
+
objectTemplates: ObjectTemplate[],
|
|
8
|
+
refreshPage: () => void,
|
|
9
|
+
): TableWrapper {
|
|
10
|
+
this.eventHandler = eventHandler
|
|
11
|
+
this.objectTemplates = objectTemplates
|
|
12
|
+
this.refreshPage = refreshPage
|
|
13
|
+
return this
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { EventHandlerType, ObjectTemplate } from '@cybertale/interface'
|
|
2
|
+
|
|
3
|
+
export class WrapperAbstract {
|
|
4
|
+
get inEdit (): boolean {
|
|
5
|
+
return <boolean> this._inEdit
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
set inEdit (value: boolean) {
|
|
9
|
+
this._inEdit = value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
get id (): string {
|
|
13
|
+
return <string> this._id
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
set id (value: string) {
|
|
17
|
+
this._id = value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get version (): string {
|
|
21
|
+
return <string> this._version
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
set version (value: string) {
|
|
25
|
+
this._version = value
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get append (): (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[] {
|
|
29
|
+
return <(_objectTemplates: ObjectTemplate[]) => ObjectTemplate[]> this._append
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set append (value: (_objectTemplates: ObjectTemplate[]) => ObjectTemplate[]) {
|
|
33
|
+
this._append = value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get refreshPage (): () => void {
|
|
37
|
+
return <() => void> this._refreshPage
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
set refreshPage (value: () => void) {
|
|
41
|
+
this._refreshPage = value
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get objectTemplates (): ObjectTemplate[] {
|
|
45
|
+
return <ObjectTemplate[]> this._objectTemplates
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set objectTemplates (value: ObjectTemplate[]) {
|
|
49
|
+
this._objectTemplates = value
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get eventHandler (): EventHandlerType {
|
|
53
|
+
return <EventHandlerType> this._eventHandler
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set eventHandler (value: EventHandlerType) {
|
|
57
|
+
this._eventHandler = value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private _eventHandler: EventHandlerType | undefined
|
|
61
|
+
private _objectTemplates: ObjectTemplate[] | undefined
|
|
62
|
+
private _refreshPage: (() => void) | undefined
|
|
63
|
+
private _append: ((_objectTemplates: ObjectTemplate[]) => ObjectTemplate[]) | undefined
|
|
64
|
+
private _id: string | undefined
|
|
65
|
+
private _inEdit: boolean | undefined
|
|
66
|
+
private _version: string | undefined
|
|
67
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ObjectTemplate } from '@cybertale/interface'
|
|
2
|
-
import { StatTypeEnum } from '@cybertale/interface'
|
|
3
|
-
import { getStringStat, hasStat } from '../transform/stat'
|
|
4
|
-
import { isJSONArray, parseJSON } from '../transform/json'
|
|
2
|
+
import { StatTypeEnum, GetValue } from '@cybertale/interface'
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Generic value resolution from ObjectTemplate stats.
|
|
@@ -16,39 +14,5 @@ export function getValueFromTemplate(
|
|
|
16
14
|
valueStat: StatTypeEnum,
|
|
17
15
|
indexStat: StatTypeEnum = (StatTypeEnum as any).Option,
|
|
18
16
|
): unknown {
|
|
19
|
-
|
|
20
|
-
if (!raw) return ''
|
|
21
|
-
|
|
22
|
-
if (!hasStat(object, indexStat) || !isJSONArray(raw)) {
|
|
23
|
-
return raw
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const data = parseJSON<unknown[]>(raw)
|
|
27
|
-
if (!data) return ''
|
|
28
|
-
|
|
29
|
-
const indexRaw = getStringStat(object, indexStat)
|
|
30
|
-
|
|
31
|
-
// JSON-array index case
|
|
32
|
-
if (isJSONArray(indexRaw)) {
|
|
33
|
-
const optionIndicesStat = (StatTypeEnum as any).OptionIndices as StatTypeEnum
|
|
34
|
-
const indices = parseJSON<number[]>(indexRaw) ?? []
|
|
35
|
-
|
|
36
|
-
const optionIndex = Number(getStringStat(object, optionIndicesStat))
|
|
37
|
-
const mappedIndex = indices[optionIndex]
|
|
38
|
-
|
|
39
|
-
// FIXED: redundant typeof removed, replaced with correct bounds + null check
|
|
40
|
-
if (mappedIndex != null && mappedIndex in data) {
|
|
41
|
-
return data[mappedIndex]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return ''
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Simple numeric index
|
|
48
|
-
const index = Number(indexRaw)
|
|
49
|
-
if (Number.isNaN(index) || !(index in data)) {
|
|
50
|
-
return ''
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return data[index]
|
|
17
|
+
return GetValue(object, valueStat, indexStat)
|
|
54
18
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ObjectTemplate, StatTypeEnum } from '@cybertale/interface'
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid'
|
|
3
|
+
import { insertTemplateAt } from './insert'
|
|
4
|
+
import { findTemplateIndexByStat } from './remove'
|
|
5
|
+
import { getStringStat } from '../transform/stat'
|
|
6
|
+
|
|
7
|
+
export function cloneObjectTemplate(object: ObjectTemplate): ObjectTemplate {
|
|
8
|
+
return new ObjectTemplate(
|
|
9
|
+
object.Region,
|
|
10
|
+
object.ObjectEnum,
|
|
11
|
+
object.SubObjectEnum,
|
|
12
|
+
object.ActionEnum,
|
|
13
|
+
object.Stats,
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function appendTemplates(
|
|
18
|
+
templates: ObjectTemplate[],
|
|
19
|
+
newTemplates: ObjectTemplate[],
|
|
20
|
+
): ObjectTemplate[] {
|
|
21
|
+
const appended = newTemplates.map(template => cloneObjectTemplate(template))
|
|
22
|
+
return [...templates, ...appended]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function addInputGroupTemplate(
|
|
26
|
+
templates: ObjectTemplate[],
|
|
27
|
+
payload: ObjectTemplate,
|
|
28
|
+
options?: {
|
|
29
|
+
tagStat?: StatTypeEnum
|
|
30
|
+
elementTypeStat?: StatTypeEnum
|
|
31
|
+
idFactory?: () => string
|
|
32
|
+
},
|
|
33
|
+
): ObjectTemplate[] {
|
|
34
|
+
const tagStat = options?.tagStat ?? StatTypeEnum.Tag
|
|
35
|
+
const elementTypeStat = options?.elementTypeStat ?? StatTypeEnum.ElementType
|
|
36
|
+
const idFactory = options?.idFactory ?? uuidv4
|
|
37
|
+
|
|
38
|
+
const payloadClone = cloneObjectTemplate(payload)
|
|
39
|
+
if (payloadClone.Stats?.[elementTypeStat]) {
|
|
40
|
+
payloadClone.Stats[elementTypeStat].Data = ''
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const baseTag = getStringStat(payloadClone, tagStat)
|
|
44
|
+
let insertOffset = 0
|
|
45
|
+
for (const template of templates) {
|
|
46
|
+
const tagValue = getStringStat(template, tagStat)
|
|
47
|
+
if (tagValue.includes(baseTag)) {
|
|
48
|
+
insertOffset += 1
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (payloadClone.Stats?.[tagStat]) {
|
|
53
|
+
payloadClone.Stats[tagStat].Data = baseTag + idFactory()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const baseIndex = findTemplateIndexByStat(templates, baseTag, tagStat)
|
|
57
|
+
const insertIndex = baseIndex + insertOffset
|
|
58
|
+
return insertTemplateAt(templates, insertIndex, payloadClone)
|
|
59
|
+
}
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function parseJSON<T = unknown>(value: string | null | undefined): T | null {
|
|
7
|
-
if (value == null || value === "") return null
|
|
8
|
-
try {
|
|
9
|
-
return JSON.parse(value) as T
|
|
10
|
-
} catch {
|
|
11
|
-
return null
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isJSONArray(value: string | null | undefined): boolean {
|
|
16
|
-
const parsed = parseJSON(value)
|
|
17
|
-
return Array.isArray(parsed)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function isJSONObject(value: string | null | undefined): boolean {
|
|
21
|
-
const parsed = parseJSON(value)
|
|
22
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
|
|
23
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
ParseJSON as parseJSON,
|
|
3
|
+
IsJSONArray as isJSONArray,
|
|
4
|
+
IsJSONObject as isJSONObject
|
|
5
|
+
} from '@cybertale/interface'
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function hasStat(object: ObjectTemplate, stat: StatTypeEnum): boolean {
|
|
9
|
-
return !!object.Stats && object.Stats[stat] !== undefined
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function getRawStat(object: ObjectTemplate, stat: StatTypeEnum): unknown {
|
|
13
|
-
return object.Stats?.[stat]?.Data
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getStringStat(object: ObjectTemplate, stat: StatTypeEnum): string {
|
|
17
|
-
const raw = getRawStat(object, stat)
|
|
18
|
-
if (raw == null) return ''
|
|
19
|
-
return String(raw)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getBooleanStat(object: ObjectTemplate, stat: StatTypeEnum): boolean {
|
|
23
|
-
const raw = getRawStat(object, stat)
|
|
24
|
-
// Treat empty string / null / undefined as false, anything else as true.
|
|
25
|
-
return !!raw
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function getJSONStat<T = unknown>(object: ObjectTemplate, stat: StatTypeEnum): T | null {
|
|
29
|
-
const raw = getRawStat(object, stat)
|
|
30
|
-
if (typeof raw !== 'string') return null
|
|
31
|
-
return parseJSON<T>(raw)
|
|
32
|
-
}
|
|
1
|
+
export {
|
|
2
|
+
HasStat as hasStat,
|
|
3
|
+
GetRawStat as getRawStat,
|
|
4
|
+
GetStringStat as getStringStat,
|
|
5
|
+
GetBooleanStat as getBooleanStat,
|
|
6
|
+
GetJSONStat as getJSONStat
|
|
7
|
+
} from '@cybertale/interface'
|