@iebh/tera-fy 1.0.15 → 1.0.16

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.
@@ -502,7 +502,7 @@ export default class TeraFy {
502
502
 
503
503
 
504
504
  /**
505
- * Set or merge settings - but only in dev mode
505
+ * Set or merge settings - but only in dev mode and only if the value is not undefined
506
506
  *
507
507
  * @see set()
508
508
  * @param {String|Object} key Either a single setting key to set or an object to merge
@@ -511,7 +511,7 @@ export default class TeraFy {
511
511
  * @returns {TeraFy} This chainable terafy instance
512
512
  */
513
513
  setIfDev(key, value) {
514
- if (!this.settings.devMode) return this;
514
+ if (!this.settings.devMode || value === undefined) return this;
515
515
  return this.set(key, value);
516
516
  }
517
517
 
@@ -816,7 +816,9 @@ export default class TeraFy {
816
816
  *
817
817
  * @function getProjectLibrary
818
818
  * @param {String} [path] Optional file path to use, if omitted the contents of `options` are used to guess at a suitable file
819
+ *
819
820
  * @param {Object} [options] Additional options to mutate behaviour
821
+ * @param {String} [options.format='json'] Format for the file. ENUM: 'pojo' (return a parsed JS collection), 'blob' (raw JS Blob object), 'file' (named JS File object)
820
822
  * @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
821
823
  * @param {Boolean} [options.multiple=false] Allow selection of multiple libraries
822
824
  * @param {Function} [options.filter] Optional async file filter, called each time as `(File:ProjectFile)`
@@ -2,6 +2,7 @@ import {cloneDeep, has as pathExists, set as pathSet} from 'lodash-es';
2
2
  import {diffApply, jsonPatchPathConverter as jsPatchConverter} from 'just-diff-apply';
3
3
  import {nanoid} from 'nanoid';
4
4
  import mixin from '#utils/mixin';
5
+ import Reflib from '@iebh/reflib';
5
6
 
6
7
  /**
7
8
  * Server-side functions available to the Tera-Fy client library
@@ -705,7 +706,9 @@ export default class TeraFyServer {
705
706
  * Fetch the active projects citation library
706
707
  *
707
708
  * @param {String} [path] Optional file path to use, if omitted the contents of `options` are used to guess at a suitable file
709
+ *
708
710
  * @param {Object} [options] Additional options to mutate behaviour
711
+ * @param {String} [options.format='json'] Format for the file. ENUM: 'pojo' (return a parsed JS collection), 'blob' (raw JS Blob object), 'file' (named JS File object)
709
712
  * @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
710
713
  * @param {Boolean} [options.multiple=false] Allow selection of multiple libraries
711
714
  * @param {Function} [options.filter] Optional async file filter, called each time as `(File:ProjectFile)`
@@ -717,6 +720,7 @@ export default class TeraFyServer {
717
720
  getProjectLibrary(path, options) {
718
721
  let settings = {
719
722
  path,
723
+ format: 'pojo',
720
724
  autoRequire: true,
721
725
  multiple: false,
722
726
  hint: null,
@@ -742,9 +746,28 @@ export default class TeraFyServer {
742
746
  }
743
747
  })
744
748
  .then(filePath => app.service('$supabase').fileGet(filePath, {
745
- json: true,
746
749
  toast: false,
747
750
  }))
751
+ .then(blob => {
752
+ switch (settings.format) {
753
+ case 'pojo':
754
+ return Reflib.uploadFile({
755
+ file: new File(
756
+ [blob],
757
+ app.service('$supabase')._parsePath(settings.path).basename,
758
+ ),
759
+ });
760
+ case 'blob':
761
+ return blob;
762
+ case 'file':
763
+ return new File(
764
+ [blob],
765
+ app.service('$supabase')._parsePath(settings.path).basename,
766
+ );
767
+ default:
768
+ throw new Error(`Unsupported library format "${settings.format}"`);
769
+ }
770
+ })
748
771
  }
749
772
 
750
773
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iebh/tera-fy",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "TERA website worker",
5
5
  "scripts": {
6
6
  "dev": "esbuild --platform=browser --format=esm --bundle lib/terafy.client.js --outfile=dist/terafy.js --minify --sourcemap --serve --servedir=.",