@iebh/tera-fy 1.6.0 → 1.6.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/CHANGELOG.md +2 -0
- package/api.md +441 -421
- package/dist/terafy.es2019.js +2 -2
- package/dist/terafy.js +1 -1
- package/lib/projectFile.js +25 -4
- package/lib/terafy.client.js +9 -9
- package/lib/terafy.server.js +31 -38
- package/package.json +1 -1
package/lib/terafy.server.js
CHANGED
|
@@ -990,11 +990,11 @@ export default class TeraFyServer {
|
|
|
990
990
|
|
|
991
991
|
/**
|
|
992
992
|
* Fetch a project file
|
|
993
|
-
* @param {String}
|
|
993
|
+
* @param {String} id File ID to read
|
|
994
994
|
* @returns {Promise<Blob>} The eventual fetched file as a blob
|
|
995
995
|
*/
|
|
996
|
-
getProjectFile(
|
|
997
|
-
return app.service('$supabase').fileGet(
|
|
996
|
+
getProjectFile(id) {
|
|
997
|
+
return app.service('$supabase').fileGet(app.service('$projects').decodeFilePath(id), {
|
|
998
998
|
toast: false,
|
|
999
999
|
});
|
|
1000
1000
|
}
|
|
@@ -1003,12 +1003,12 @@ export default class TeraFyServer {
|
|
|
1003
1003
|
/**
|
|
1004
1004
|
* Replace a project files contents
|
|
1005
1005
|
*
|
|
1006
|
-
* @param {String}
|
|
1006
|
+
* @param {String} id File to overwrite
|
|
1007
1007
|
* @param {File|Blob|FormData|Object|Array} contents The new file contents
|
|
1008
1008
|
* @returns {Promise} A promise which will resolve when the write operation has completed
|
|
1009
1009
|
*/
|
|
1010
|
-
setProjectFile(
|
|
1011
|
-
return app.service('$supabase').fileSet(
|
|
1010
|
+
setProjectFile(id, contents) {
|
|
1011
|
+
return app.service('$supabase').fileSet(app.service('$projects').decodeFilePath(id), contents, {
|
|
1012
1012
|
overwrite: true,
|
|
1013
1013
|
toast: false,
|
|
1014
1014
|
});
|
|
@@ -1058,7 +1058,7 @@ export default class TeraFyServer {
|
|
|
1058
1058
|
/**
|
|
1059
1059
|
* Fetch + convert a project file into a library of citations
|
|
1060
1060
|
*
|
|
1061
|
-
* @param {String}
|
|
1061
|
+
* @param {String} id File ID to read
|
|
1062
1062
|
*
|
|
1063
1063
|
* @param {Object} [options] Additional options to mutate behaviour
|
|
1064
1064
|
* @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)
|
|
@@ -1068,7 +1068,7 @@ export default class TeraFyServer {
|
|
|
1068
1068
|
*
|
|
1069
1069
|
* @returns {Promise<Array<Ref>>|Promise<*>} A collection of references (default bevahiour) or a whatever format was requested
|
|
1070
1070
|
*/
|
|
1071
|
-
getProjectLibrary(
|
|
1071
|
+
getProjectLibrary(id, options) {
|
|
1072
1072
|
let settings = {
|
|
1073
1073
|
format: 'pojo',
|
|
1074
1074
|
autoRequire: true,
|
|
@@ -1077,9 +1077,11 @@ export default class TeraFyServer {
|
|
|
1077
1077
|
...options,
|
|
1078
1078
|
};
|
|
1079
1079
|
|
|
1080
|
+
let filePath = app.service('$projects').decodeFilePath(id);
|
|
1081
|
+
|
|
1080
1082
|
return Promise.resolve()
|
|
1081
1083
|
.then(()=> settings.autoRequire && this.requireProject())
|
|
1082
|
-
.then(()=> app.service('$supabase').fileGet(
|
|
1084
|
+
.then(()=> app.service('$supabase').fileGet(filePath, {
|
|
1083
1085
|
toast: false,
|
|
1084
1086
|
}))
|
|
1085
1087
|
.then(blob => {
|
|
@@ -1089,7 +1091,7 @@ export default class TeraFyServer {
|
|
|
1089
1091
|
return Reflib.uploadFile({
|
|
1090
1092
|
file: new File(
|
|
1091
1093
|
[blob],
|
|
1092
|
-
app.service('$supabase')._parsePath(
|
|
1094
|
+
app.service('$supabase')._parsePath(filePath).basename,
|
|
1093
1095
|
),
|
|
1094
1096
|
});
|
|
1095
1097
|
case 'blob':
|
|
@@ -1097,7 +1099,7 @@ export default class TeraFyServer {
|
|
|
1097
1099
|
case 'file':
|
|
1098
1100
|
return new File(
|
|
1099
1101
|
[blob],
|
|
1100
|
-
app.service('$supabase')._parsePath(
|
|
1102
|
+
app.service('$supabase')._parsePath(filePath).basename,
|
|
1101
1103
|
);
|
|
1102
1104
|
default:
|
|
1103
1105
|
throw new Error(`Unsupported library format "${settings.format}"`);
|
|
@@ -1109,23 +1111,23 @@ export default class TeraFyServer {
|
|
|
1109
1111
|
/**
|
|
1110
1112
|
* Save back a citation library from some input
|
|
1111
1113
|
*
|
|
1112
|
-
* @param {String} [
|
|
1114
|
+
* @param {String} [id] File ID to save back to, if omitted a file will be prompted for
|
|
1113
1115
|
* @param {Array<RefLibRef>|Blob|File} [refs] Collection of references for the selected library or the raw Blob/File
|
|
1114
1116
|
*
|
|
1115
1117
|
* @param {Object} [options] Additional options to mutate behaviour
|
|
1116
|
-
* @param {String} [options.
|
|
1118
|
+
* @param {String} [options.id] Alternate method to specify the file ID to save as, if omitted one will be prompted for
|
|
1117
1119
|
* @param {Array<RefLibRef>|Blob|File} [options.refs] Alternate method to specify the refs to save as an array or raw Blob/File
|
|
1118
1120
|
* @param {String} [options.format='auto'] Input format used. ENUM: 'auto' (try to figure it out from context), 'pojo' (JS array of RefLib references), 'blob' (raw JS Blob object), 'file' (named JS File object)
|
|
1119
1121
|
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
1120
1122
|
* @param {String|Array<String>} [options.hint] Hint(s) to store against the library. Generally corresponds to the current operation being performed - e.g. 'deduped'
|
|
1121
|
-
* @param {String} [options.filename] Suggested filename if
|
|
1122
|
-
* @param {String} [options.title='Save citation library'] Dialog title if
|
|
1123
|
+
* @param {String} [options.filename] Suggested filename if `id` is unspecified
|
|
1124
|
+
* @param {String} [options.title='Save citation library'] Dialog title if `id` is unspecified and a prompt is necessary
|
|
1123
1125
|
* @param {Boolean} [options.overwrite=true] Allow existing file upsert
|
|
1124
1126
|
* @param {Object} [options.meta] Optional meta data to merge into the file data
|
|
1125
1127
|
*
|
|
1126
1128
|
* @returns {Promise} A promise which resolves when the save operation has completed
|
|
1127
1129
|
*/
|
|
1128
|
-
setProjectLibrary(
|
|
1130
|
+
setProjectLibrary(id, refs, options) {
|
|
1129
1131
|
let settings = {
|
|
1130
1132
|
format: 'auto',
|
|
1131
1133
|
autoRequire: true,
|
|
@@ -1135,17 +1137,18 @@ export default class TeraFyServer {
|
|
|
1135
1137
|
overwrite: true,
|
|
1136
1138
|
meta: null,
|
|
1137
1139
|
...(
|
|
1138
|
-
typeof
|
|
1139
|
-
: Array.isArray(
|
|
1140
|
-
:
|
|
1140
|
+
typeof id == 'string' && Array.isArray(refs) ? {id, refs, ...options} // Called as (id, refs, options?)
|
|
1141
|
+
: Array.isArray(id) || refs instanceof Blob || refs instanceof File ? {refs: id, ...refs} // Called as (refs, options?)
|
|
1142
|
+
: id // Called as (options?)
|
|
1141
1143
|
)
|
|
1142
1144
|
};
|
|
1143
1145
|
if (!settings.refs) throw new Error('No refs to save');
|
|
1144
1146
|
|
|
1147
|
+
let filePath; // Eventual Supabase path to use
|
|
1145
1148
|
return Promise.resolve()
|
|
1146
1149
|
.then(()=> settings.autoRequire && this.requireProject())
|
|
1147
1150
|
.then(()=> {
|
|
1148
|
-
if (settings.
|
|
1151
|
+
if (settings.id) return; // We already have a file ID specified - skip
|
|
1149
1152
|
|
|
1150
1153
|
// Prompt for a save filename
|
|
1151
1154
|
return this.selectProjectFile({
|
|
@@ -1158,14 +1161,11 @@ export default class TeraFyServer {
|
|
|
1158
1161
|
},
|
|
1159
1162
|
autoRequire: false, // Handled above anyway
|
|
1160
1163
|
})
|
|
1161
|
-
.then(
|
|
1164
|
+
.then(file => settings.id = file.id)
|
|
1162
1165
|
})
|
|
1163
|
-
.then(()=> { //
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
this.debug('INFO', 2, 'Save citation library as', path);
|
|
1166
|
+
.then(()=> { // Compute filePath
|
|
1167
|
+
filePath = app.service('$projects').decodeFilePath(settings.id);
|
|
1168
|
+
debugger; // FIXME: Untested
|
|
1169
1169
|
})
|
|
1170
1170
|
.then(()=> {
|
|
1171
1171
|
// Mutate settings.ref -> Blob or File format needed by Supabase
|
|
@@ -1184,12 +1184,12 @@ export default class TeraFyServer {
|
|
|
1184
1184
|
|
|
1185
1185
|
// Get Reflib to encode the POJO into a Blob/File
|
|
1186
1186
|
return Reflib.downloadFile(settings.refs, {
|
|
1187
|
-
filename:
|
|
1187
|
+
filename: app.service('$supabase')._parsePath(filePath).filename,
|
|
1188
1188
|
promptDownload: false, // Just return the fileBlob we hand to Supabase
|
|
1189
1189
|
})
|
|
1190
1190
|
case 'blob':
|
|
1191
1191
|
if (!(settings.refs instanceof Blob)) throw new Error("setProjectLibrary({format: 'blob'} but non-Blob provided as `refs`");
|
|
1192
|
-
return new File([settings.refs], app.service('$supabase')._parsePath(
|
|
1192
|
+
return new File([settings.refs], app.service('$supabase')._parsePath(filePath).basename);
|
|
1193
1193
|
case 'file':
|
|
1194
1194
|
if (!(settings.ref instanceof File)) throw new Error("setProjectLibrary({format: 'file'} but non-File provided as `refs`");
|
|
1195
1195
|
return settings.refs;
|
|
@@ -1197,13 +1197,7 @@ export default class TeraFyServer {
|
|
|
1197
1197
|
throw new Error(`Unsupported library format "${settings.format}"`);
|
|
1198
1198
|
}
|
|
1199
1199
|
})
|
|
1200
|
-
.then(fileBlob => app.service('$supabase').fileUpload(
|
|
1201
|
-
file: fileBlob,
|
|
1202
|
-
mode: 'encoded',
|
|
1203
|
-
overwrite: true,
|
|
1204
|
-
meta: settings.meta,
|
|
1205
|
-
transcoders: false, // We can skip transcoders as we are supplying the meta information above anyway
|
|
1206
|
-
}))
|
|
1200
|
+
.then(fileBlob => app.service('$supabase').fileUpload(filePath))
|
|
1207
1201
|
}
|
|
1208
1202
|
|
|
1209
1203
|
// }}}
|
|
@@ -1222,7 +1216,7 @@ export default class TeraFyServer {
|
|
|
1222
1216
|
}
|
|
1223
1217
|
// }}}
|
|
1224
1218
|
|
|
1225
|
-
// Webpages - setPageUrl() {{{
|
|
1219
|
+
// Webpages - setPageUrl(), setPageTitle {{{
|
|
1226
1220
|
|
|
1227
1221
|
/**
|
|
1228
1222
|
* Set an active tools URL (or path) so that it survives a refresh
|
|
@@ -1430,6 +1424,5 @@ export default class TeraFyServer {
|
|
|
1430
1424
|
...msg,
|
|
1431
1425
|
);
|
|
1432
1426
|
}
|
|
1433
|
-
|
|
1434
1427
|
// }}}
|
|
1435
1428
|
}
|
package/package.json
CHANGED