yaml-admin-api 0.0.42 → 0.0.52

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": "yaml-admin-api",
3
- "version": "0.0.42",
3
+ "version": "0.0.52",
4
4
  "license": "MIT",
5
5
  "description": "YAML Admin API package",
6
6
  "type": "commonjs",
@@ -243,7 +243,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
243
243
  console.log('list', entity_name, 'found', count)
244
244
 
245
245
  await addInfo(db, list)
246
- options?.listener?.entityListed?.(db, entity_name, list)
246
+ if(options?.listener?.entityListed)
247
+ await options.listener.entityListed(db, entity_name, list)
247
248
 
248
249
  res.header('X-Total-Count', count);
249
250
  res.json(list);
@@ -316,7 +317,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
316
317
 
317
318
  var r = await db.collection(entity_name).insertOne(entity);
318
319
  //Custom Create Tail Start
319
- options?.listener?.entityCreated?.(db, entity_name, entity)
320
+ if(options?.listener?.entityCreated)
321
+ await options.listener.entityCreated(db, entity_name, entity)
320
322
  //Custom Create Tail End
321
323
 
322
324
  const generatedId = entityId || r.insertedId
@@ -357,7 +359,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
357
359
  await db.collection(entity_name).updateOne(f, { $set: entity });
358
360
 
359
361
  //Custom Create Tail Start
360
- options?.listener?.entityUpdated?.(db, entity_name, entity)
362
+ if(options?.listener?.entityUpdated)
363
+ await options.listener.entityUpdated(db, entity_name, entity)
361
364
  //Custom Create Tail End
362
365
 
363
366
  // Ensure React-Admin receives an `id` in the response
@@ -406,7 +409,8 @@ const generateCrud = async ({ app, db, entity_name, yml_entity, yml, options })
406
409
  else
407
410
  await db.collection(entity_name).deleteOne(f);
408
411
 
409
- options?.listener?.entityDeleted?.(db, entity_name, entity)
412
+ if(options?.listener?.entityDeleted)
413
+ await options.listener.entityDeleted(db, entity_name, entity)
410
414
 
411
415
  res.json(entity);
412
416
  }));
@@ -18,9 +18,12 @@ const changeEnv = (yamlString, env = {}) => {
18
18
  }
19
19
 
20
20
  async function registerRoutes(app, options = {}) {
21
- const { yamlPath, yamlString, env } = options;
21
+ const { yamlPath, yamlString, env, yamlJson } = options;
22
22
  let yml;
23
- if(yamlPath) {
23
+
24
+ if(yamlJson) {
25
+ yml = yamlJson;
26
+ } else if(yamlPath) {
24
27
  yml = await readYml(yamlPath, env);
25
28
  } else if(yamlString) {
26
29
  const replaced = changeEnv(yamlString, env);