ballerina-core 1.0.12 → 1.0.14

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
@@ -2,7 +2,7 @@
2
2
  "name": "ballerina-core",
3
3
  "author": "Dr. Giuseppe Maggiore",
4
4
  "private": false,
5
- "version": "1.0.12",
5
+ "version": "1.0.14",
6
6
  "main": "main.ts",
7
7
  "dependencies": {
8
8
  "immutable": "^5.0.0-beta.5",
@@ -15,6 +15,7 @@ export const LoadValidateAndParseFormsConfig = () => {
15
15
  return Sum.Default.right(validationResult.value)
16
16
  return parseForms(
17
17
  builtIns,
18
+ current.fieldTypeConverters,
18
19
  current.containerFormView,
19
20
  current.nestedContainerFormView,
20
21
  current.fieldViews,
@@ -118,8 +118,9 @@ export const defaultValue = (types:Map<TypeName, TypeDefinition>, builtIns:Built
118
118
  }
119
119
 
120
120
  export const fromAPIRawValue = (t:Type, types:Map<TypeName, TypeDefinition>, builtIns:BuiltIns, converters:ApiConverters) => (raw:any) : any => {
121
+ // alert(JSON.stringify(t))
121
122
  if (raw == undefined) {
122
- console.error(`instantiating default value for type ${JSON.stringify(t)}: something is missing from the API response`)
123
+ console.warn(`instantiating default value for type ${JSON.stringify(t)}: the value was undefined so something is missing from the API response`)
123
124
  return defaultValue(types, builtIns)(t.kind == "primitive" ? t.value : t.kind == "lookup" ? t.name : t.value)
124
125
  }
125
126
 
@@ -132,58 +133,71 @@ export const fromAPIRawValue = (t:Type, types:Map<TypeName, TypeDefinition>, bui
132
133
  fromAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))(result)
133
134
  return result
134
135
  }
135
- if (t.value == "MultiSelection" && t.args.length == 1) {
136
- let result = converters[t.value].fromAPIRawValue(raw)
136
+ if ((t.value == "Multiselection" || t.value == "MultiSelection") && t.args.length == 1) {
137
+ let result = converters["MultiSelection"].fromAPIRawValue(raw)
137
138
  result = result.map(fromAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))
138
139
  return result
139
140
  }
140
141
  if (t.value == "List" && t.args.length == 1) {
141
142
  let result = converters[t.value].fromAPIRawValue(raw)
142
- result = result.map(fromAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))
143
+ result = result.map(fromAPIRawValue(
144
+ PrimitiveTypes.some(_ => _ == t.args[0]) ?
145
+ { kind:"primitive", value:t.args[0] as PrimitiveType }
146
+ : { kind:"lookup", name:t.args[0] }
147
+ , types, builtIns, converters))
143
148
  return result
144
149
  }
145
150
  } else { // t.kind == lookup: we are dealing with a record/object
146
- let result:any = {}
151
+ let result:any = {...raw}
147
152
  const tDef = types.get(t.name)!
148
153
  tDef.fields.forEach((fieldType, fieldName) => {
149
- result[fieldName] = fromAPIRawValue(fieldType, types, builtIns, converters)(raw[fieldName])
154
+ const fieldValue = raw[fieldName]
155
+ result[fieldName] = fromAPIRawValue(fieldType, types, builtIns, converters)(fieldValue)
150
156
  })
151
157
  return result
152
158
  }
153
- console.error(`instantiating default value for type ${JSON.stringify(t)}: something is missing from the API response`)
154
- return defaultValue(types, builtIns)(t.value)
159
+ console.error(`unsupported type ${JSON.stringify(t)}, returning the raw value right away`)
160
+ return raw
155
161
  }
156
162
 
157
163
 
158
164
  export const toAPIRawValue = (t:Type, types:Map<TypeName, TypeDefinition>, builtIns:BuiltIns, converters:ApiConverters) => (raw:any) : any => {
159
165
  if (t.kind == "primitive") {
160
- // t.value == ""
161
166
  return converters[t.value].toAPIRawValue(raw as never)
162
167
  } else if (t.kind == "application") { // application here means "generic type application"
163
168
  if (t.value == "SingleSelection" && t.args.length == 1) {
164
169
  let result = converters[t.value].toAPIRawValue(raw)
165
- result = CollectionSelection().Updaters.left(
166
- toAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))(result)
170
+ if (result != undefined)
171
+ result = toAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters)(result)
167
172
  return result
168
173
  }
169
- if (t.value == "MultiSelection" && t.args.length == 1) {
170
- let result = converters[t.value].toAPIRawValue(raw)
174
+ if ((t.value == "Multiselection" || t.value == "MultiSelection") && t.args.length == 1) {
175
+ // alert(`MultiSelect ${JSON.stringify(t)} ${JSON.stringify(raw)}`)
176
+ let result = converters["MultiSelection"].toAPIRawValue(raw)
177
+ // alert(`MultiSelect result1 = ${JSON.stringify(result)}`)
178
+ // alert(`${JSON.stringify(t.args[0])}`)
171
179
  result = result.map(toAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))
180
+ // alert(`MultiSelect result2 = ${JSON.stringify(result)}`)
172
181
  return result
173
182
  }
174
183
  if (t.value == "List" && t.args.length == 1) {
175
184
  let result = converters[t.value].toAPIRawValue(raw)
176
- result = result.map(toAPIRawValue({ kind:"lookup", name:t.args[0] }, types, builtIns, converters))
185
+ result = result.map(toAPIRawValue(
186
+ PrimitiveTypes.some(_ => _ == t.args[0]) ?
187
+ { kind:"primitive", value:t.args[0] as PrimitiveType }
188
+ : { kind:"lookup", name:t.args[0] },
189
+ // { kind:"lookup", name:t.args[0] },
190
+ types, builtIns, converters))
177
191
  return result
178
192
  }
179
193
  } else { // t.kind == lookup: we are dealing with a record/object
180
- let result:any = {}
194
+ let result:any = {...raw}
181
195
  const tDef = types.get(t.name)!
182
196
  tDef.fields.forEach((fieldType, fieldName) => {
183
- result[fieldName] = toAPIRawValue(fieldType, types, builtIns, converters)(raw[fieldName])
197
+ const fieldValue = raw[fieldName]
198
+ result[fieldName] = toAPIRawValue(fieldType, types, builtIns, converters)(fieldValue)
184
199
  })
185
200
  return result
186
201
  }
187
- console.error(`instantiating default value for type ${JSON.stringify(t)}: something is missing from the API response`)
188
202
  return defaultValue(types, builtIns)(t.value)
189
203
  }
@@ -1,5 +1,5 @@
1
1
  import { Collection, Map, OrderedMap, OrderedSet, Set } from "immutable";
2
- import { BoolExpr, Unit, PromiseRepo, Guid, LeafPredicatesEvaluators, Predicate, FormsConfig, BuiltIns, FormDef, Sum, BasicFun, Template, unit, EditFormState, EditFormTemplate, ApiErrors, CreateFormTemplate, EntityFormTemplate, SharedFormState, CreateFormState, Entity, EditFormContext, CreateFormContext, MappedEntityFormTemplate, Mapping, FormValidationResult, Synchronized, simpleUpdater, PrimitiveType, GenericType, ApiConverter, TypeName, ListFieldState, ListForm, TypeDefinition, ApiConverters, defaultValue, fromAPIRawValue } from "../../../../main";
2
+ import { BoolExpr, Unit, PromiseRepo, Guid, LeafPredicatesEvaluators, Predicate, FormsConfig, BuiltIns, FormDef, Sum, BasicFun, Template, unit, EditFormState, EditFormTemplate, ApiErrors, CreateFormTemplate, EntityFormTemplate, SharedFormState, CreateFormState, Entity, EditFormContext, CreateFormContext, MappedEntityFormTemplate, Mapping, FormValidationResult, Synchronized, simpleUpdater, PrimitiveType, GenericType, ApiConverter, TypeName, ListFieldState, ListForm, TypeDefinition, ApiConverters, defaultValue, fromAPIRawValue, toAPIRawValue } from "../../../../main";
3
3
  import { Value } from "../../../value/state";
4
4
  import { CollectionReference } from "../collection/domains/reference/state";
5
5
  import { CollectionSelection } from "../collection/domains/selection/state";
@@ -91,10 +91,13 @@ export const FieldFormState = //<Context, FieldViews extends DefaultFieldViews,
91
91
  export type ParsedForm = {
92
92
  initialFormState: any,
93
93
  formConfig: any,
94
+ formName: string,
95
+ formDef: FormDef,
94
96
  visibleFields: any,
95
97
  disabledFields: any,
96
98
  }
97
99
  export const ParseForm = (
100
+ formName: string,
98
101
  formDef: FormDef,
99
102
  containerFormView: any,
100
103
  nestedContainerFormView: any,
@@ -201,6 +204,8 @@ export const ParseForm = (
201
204
 
202
205
  return ({
203
206
  initialFormState,
207
+ formName,
208
+ formDef,
204
209
  formConfig,
205
210
  visibleFields,
206
211
  disabledFields,
@@ -273,6 +278,7 @@ export type EnumOptionsSources = BasicFun<EnumName, Promise<Array<[CollectionRef
273
278
  export const parseForms =
274
279
  <LeafPredicates,>(
275
280
  builtIns: BuiltIns,
281
+ apiConverters: ApiConverters,
276
282
  containerFormView: any,
277
283
  nestedContainerFormView: any,
278
284
  fieldViews: any,
@@ -321,6 +327,7 @@ export const parseForms =
321
327
 
322
328
  try {
323
329
  const parsedForm = ParseForm(
330
+ formName,
324
331
  formConfig,
325
332
  containerFormView,
326
333
  nestedContainerFormView,
@@ -359,8 +366,13 @@ export const parseForms =
359
366
  const form = parsedForm.form
360
367
  const initialState = parsedForm.initialFormState
361
368
  const api = {
362
- get: entityApis.get(launcher.api),
363
- update: entityApis.update(launcher.api)
369
+ get: (id:string) => entityApis.get(launcher.api)(id).then((raw: any) => {
370
+ // alert(JSON.stringify(raw))
371
+ // alert(JSON.stringify(parsedForm.formDef.type))
372
+ const parsed = fromAPIRawValue({ kind: "lookup", name: parsedForm.formDef.type }, formsConfig.types, builtIns, apiConverters)(raw)
373
+ return parsed
374
+ }),
375
+ update: (value:any) => entityApis.update(launcher.api)(toAPIRawValue({ kind: "lookup", name: parsedForm.formDef.type }, formsConfig.types, builtIns, apiConverters)(value))
364
376
  }
365
377
  parsedLaunchers.edit = parsedLaunchers.edit.set(
366
378
  launcherName,
@@ -381,13 +393,18 @@ export const parseForms =
381
393
  const form = parsedForm.form
382
394
  const initialState = parsedForm.initialFormState
383
395
  const api = {
384
- create: entityApis.create(launcher.api),
385
- default: (_:Unit) => entityApis.default(launcher.api)(unit)
386
- // .then((raw:undefined) => {
387
- // alert(JSON.stringify(parsedForm.formConfig))
388
- // const parsed = fromAPIRawValue({ kind:"lookup", name:"" }, null!, null!, null!)(raw)
389
- // return parsed
390
- // })
396
+ create: (value:any) => {
397
+ // alert(`type = ${JSON.stringify(parsedForm.formDef.type)}`)
398
+ // alert(`value = ${JSON.stringify(value)}`)
399
+ const raw = toAPIRawValue({ kind: "lookup", name: parsedForm.formDef.type }, formsConfig.types, builtIns, apiConverters)(value)
400
+ alert(`raw = ${JSON.stringify(raw.interests)}`)
401
+ return entityApis.create(launcher.api)(raw)
402
+ },
403
+ default: (_: Unit) => entityApis.default(launcher.api)(unit)
404
+ .then((raw: any) => {
405
+ const parsed = fromAPIRawValue({ kind: "lookup", name: parsedForm.formDef.type }, formsConfig.types, builtIns, apiConverters)(raw)
406
+ return parsed
407
+ })
391
408
  }
392
409
  parsedLaunchers.create = parsedLaunchers.create.set(
393
410
  launcherName,