@iebh/tera-fy 2.0.21 → 2.2.0
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 +38 -0
- package/api.md +68 -66
- package/dist/lib/projectFile.d.ts +182 -0
- package/dist/lib/projectFile.js +157 -0
- package/dist/lib/projectFile.js.map +1 -0
- package/dist/lib/syncro/entities.d.ts +28 -0
- package/dist/lib/syncro/entities.js +203 -0
- package/dist/lib/syncro/entities.js.map +1 -0
- package/dist/lib/syncro/keyed.d.ts +95 -0
- package/dist/lib/syncro/keyed.js +286 -0
- package/dist/lib/syncro/keyed.js.map +1 -0
- package/dist/lib/syncro/syncro.d.ts +328 -0
- package/dist/lib/syncro/syncro.js +633 -0
- package/dist/lib/syncro/syncro.js.map +1 -0
- package/dist/lib/terafy.bootstrapper.d.ts +42 -0
- package/dist/lib/terafy.bootstrapper.js +130 -0
- package/dist/lib/terafy.bootstrapper.js.map +1 -0
- package/dist/lib/terafy.client.d.ts +532 -0
- package/dist/lib/terafy.client.js +1110 -0
- package/dist/lib/terafy.client.js.map +1 -0
- package/dist/lib/terafy.proxy.d.ts +66 -0
- package/dist/lib/terafy.proxy.js +123 -0
- package/dist/lib/terafy.proxy.js.map +1 -0
- package/dist/lib/terafy.server.d.ts +607 -0
- package/dist/lib/terafy.server.js +1774 -0
- package/dist/lib/terafy.server.js.map +1 -0
- package/dist/plugin.vue2.es2019.js +30 -13
- package/dist/plugins/base.d.ts +20 -0
- package/dist/plugins/base.js +21 -0
- package/dist/plugins/base.js.map +1 -0
- package/dist/plugins/firebase.d.ts +62 -0
- package/dist/plugins/firebase.js +111 -0
- package/dist/plugins/firebase.js.map +1 -0
- package/dist/plugins/vite.d.ts +12 -0
- package/dist/plugins/vite.js +22 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/plugins/vue2.d.ts +68 -0
- package/dist/plugins/vue2.js +96 -0
- package/dist/plugins/vue2.js.map +1 -0
- package/dist/plugins/vue3.d.ts +64 -0
- package/dist/plugins/vue3.js +96 -0
- package/dist/plugins/vue3.js.map +1 -0
- package/dist/terafy.bootstrapper.es2019.js +2 -2
- package/dist/terafy.bootstrapper.js +2 -2
- package/dist/terafy.es2019.js +2 -2
- package/dist/terafy.js +1 -1
- package/dist/utils/mixin.d.ts +11 -0
- package/dist/utils/mixin.js +15 -0
- package/dist/utils/mixin.js.map +1 -0
- package/dist/utils/pDefer.d.ts +12 -0
- package/dist/utils/pDefer.js +14 -0
- package/dist/utils/pDefer.js.map +1 -0
- package/dist/utils/pathTools.d.ts +70 -0
- package/dist/utils/pathTools.js +120 -0
- package/dist/utils/pathTools.js.map +1 -0
- package/eslint.config.js +44 -8
- package/lib/{projectFile.js → projectFile.ts} +83 -40
- package/lib/syncro/entities.ts +288 -0
- package/lib/syncro/{keyed.js → keyed.ts} +114 -57
- package/lib/syncro/{syncro.js → syncro.ts} +204 -169
- package/lib/{terafy.bootstrapper.js → terafy.bootstrapper.ts} +49 -31
- package/lib/{terafy.client.js → terafy.client.ts} +94 -86
- package/lib/{terafy.proxy.js → terafy.proxy.ts} +43 -16
- package/lib/{terafy.server.js → terafy.server.ts} +364 -223
- package/package.json +65 -26
- package/plugins/{base.js → base.ts} +3 -1
- package/plugins/{firebase.js → firebase.ts} +34 -16
- package/plugins/{vite.js → vite.ts} +3 -3
- package/plugins/{vue2.js → vue2.ts} +17 -10
- package/plugins/{vue3.js → vue3.ts} +11 -9
- package/tsconfig.json +30 -0
- package/utils/{mixin.js → mixin.ts} +1 -1
- package/utils/{pDefer.js → pDefer.ts} +10 -3
- package/utils/{pathTools.js → pathTools.ts} +11 -9
- package/lib/syncro/entities.js +0 -232
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
panic(text: any): void;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Server-side functions available to the Tera-Fy client library
|
|
8
|
+
*
|
|
9
|
+
* @class TeraFyServer
|
|
10
|
+
*/
|
|
11
|
+
export default class TeraFyServer {
|
|
12
|
+
/**
|
|
13
|
+
* Various settings to configure behaviour
|
|
14
|
+
*
|
|
15
|
+
* @type {Object}
|
|
16
|
+
* @property {Boolean} devMode Operate in devMode - i.e. force outer refresh when encountering an existing TeraFy instance
|
|
17
|
+
* @property {Number} verbosity Verbosity level, the higher the more chatty TeraFY will be. Set to zero to disable all `debug()` call output
|
|
18
|
+
* @property {Number} subscribeTimeout Acceptable timeout period for subscribers to acklowledge a project change event, failing to respond will result in the subscriber being removed from the available subscriber list
|
|
19
|
+
* @property {String} restrictOrigin URL to restrict communications to
|
|
20
|
+
* @property {String} projectId The project to use as the default reference when calling various APIs
|
|
21
|
+
* @property {Number} serverMode The current server mode matching `SERVERMODE_*`
|
|
22
|
+
* @property {String} siteUrl The main site absolute URL
|
|
23
|
+
* @property {String} sitePathLogin Either an absolute URL or the relative path (taken from `siteUrl`) when trying to log in the user
|
|
24
|
+
* @property {Boolean} embedWorkaround Try to use `getUserViaEmbedWorkaround()` to force a login via popup if the user is running in local mode (see function docs for more details). This is toggled to false after the first run
|
|
25
|
+
*/
|
|
26
|
+
settings: any;
|
|
27
|
+
static SERVERMODE_NONE: number;
|
|
28
|
+
static SERVERMODE_EMBEDDED: number;
|
|
29
|
+
static SERVERMODE_FRAME: number;
|
|
30
|
+
static SERVERMODE_POPUP: number;
|
|
31
|
+
static SERVERMODE_TERA: number;
|
|
32
|
+
/**
|
|
33
|
+
* Create a context based on a shallow copy of this instance + additional functionality for the incoming MessageEvent
|
|
34
|
+
* This is used by acceptMessage to provide a means to reply / send messages to the originator
|
|
35
|
+
*
|
|
36
|
+
* @param {MessageEvent} e Original message event to base the new context on
|
|
37
|
+
*
|
|
38
|
+
* @returns {Object} A context, which is this instance extended with additional properties
|
|
39
|
+
*/
|
|
40
|
+
createContext(e: MessageEvent): any;
|
|
41
|
+
/**
|
|
42
|
+
* Create a new client context from the server to the client even if the client hasn't requested the communication
|
|
43
|
+
* This function is used to send unsolicited communications from the server->client in contrast to createContext() which _replies_ from client->server->client
|
|
44
|
+
*
|
|
45
|
+
* @returns {Object} A context, which is this instance extended with additional properties
|
|
46
|
+
*/
|
|
47
|
+
getClientContext(): any;
|
|
48
|
+
/**
|
|
49
|
+
* MessageEvent context
|
|
50
|
+
* Only available if the context was created via `createContext()`
|
|
51
|
+
*
|
|
52
|
+
* @type {MessageEvent}
|
|
53
|
+
*/
|
|
54
|
+
messageEvent: MessageEvent | null;
|
|
55
|
+
/**
|
|
56
|
+
* Request an RPC call from the original sender of a mesasge
|
|
57
|
+
* This function only works if the context was sub-classed via `createContext()`
|
|
58
|
+
*
|
|
59
|
+
* @param {String} method The method name to call
|
|
60
|
+
* @param {...*} [args] Optional arguments to pass to the function
|
|
61
|
+
*
|
|
62
|
+
* @returns {Promise<*>} The resolved output of the server function
|
|
63
|
+
*/
|
|
64
|
+
senderRpc(method: string, ...args: any[]): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* Return basic server information as a form of validation
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<Object>} Basic promise result
|
|
69
|
+
* @property {Date} date Server date
|
|
70
|
+
*/
|
|
71
|
+
handshake(): Promise<any>;
|
|
72
|
+
/**
|
|
73
|
+
* Send a message + wait for a response object
|
|
74
|
+
* This method should likely be part of the context returned by createContext
|
|
75
|
+
* Assuming it's intended to work on the base class referencing a stored messageEvent
|
|
76
|
+
*
|
|
77
|
+
* @param {Object} message Message object to send
|
|
78
|
+
* @returns {Promise<*>} A promise which resolves when the operation has completed with the remote reply
|
|
79
|
+
*/
|
|
80
|
+
send(message: any): Promise<any>;
|
|
81
|
+
/**
|
|
82
|
+
* Send raw message content to the client
|
|
83
|
+
* Unlike send() this method does not expect any response
|
|
84
|
+
*
|
|
85
|
+
* @param {Object} message Message object to send
|
|
86
|
+
* @param {Window} sendVia Window context to dispatch the message via if its not the same as the regular window
|
|
87
|
+
*/
|
|
88
|
+
sendRaw(message: any, sendVia?: any): void;
|
|
89
|
+
/**
|
|
90
|
+
* Setter to translate between string inputs and the server modes in SERVERMODE_*
|
|
91
|
+
*
|
|
92
|
+
* @param {String} mode The server mode to set to
|
|
93
|
+
*/
|
|
94
|
+
setServerMode(mode: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Accept a message from the parent event listener
|
|
97
|
+
*
|
|
98
|
+
* @param {MessageEvent} rawMessage Raw message event to process
|
|
99
|
+
*/
|
|
100
|
+
acceptMessage(rawMessage: MessageEvent): void;
|
|
101
|
+
/**
|
|
102
|
+
* Listening postboxes, these correspond to outgoing message IDs that expect a response
|
|
103
|
+
*/
|
|
104
|
+
acceptPostboxes: Record<string, any>;
|
|
105
|
+
/**
|
|
106
|
+
* Wrapper function which runs a callback after the frontend UI has obtained focus
|
|
107
|
+
* This is to fix the issue where the front-end needs to switch between a regular webpage and a focused TERA iFrame wrapper
|
|
108
|
+
* Any use of $prompt or other UI calls should be wrapped here
|
|
109
|
+
*
|
|
110
|
+
* @param {Function} cb Async function to run in focused mode
|
|
111
|
+
*
|
|
112
|
+
* @returns {Promise<*>} A promise which resolves with the resulting inner callback payload
|
|
113
|
+
*/
|
|
114
|
+
requestFocus(cb: () => Promise<any>): Promise<any>;
|
|
115
|
+
/**
|
|
116
|
+
* Emit messages down into all connected clients
|
|
117
|
+
* Note that emitted messages have no response - they are sent to clients only with no return value
|
|
118
|
+
*
|
|
119
|
+
* @param {String} event The event name to emit
|
|
120
|
+
* @param {...*} [args] Optional event payload to send
|
|
121
|
+
* @returns {Promise} A promise which resolves when the transmission has completed
|
|
122
|
+
*/
|
|
123
|
+
emitClients(event: string, ...args: any[]): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* RPC callback to set the server verbostiy level
|
|
126
|
+
*
|
|
127
|
+
* @param {Number} verbosity The desired server verbosity level
|
|
128
|
+
*/
|
|
129
|
+
setServerVerbosity(verbosity: number): void;
|
|
130
|
+
/**
|
|
131
|
+
* User / active session within TERA
|
|
132
|
+
* @class User
|
|
133
|
+
* @property {String} id Unique identifier of the user
|
|
134
|
+
* @property {String} email The email address of the current user
|
|
135
|
+
* @property {String} name The provided full name of the user
|
|
136
|
+
* @property {Boolean} isSubscribed Whether the active user has a TERA subscription
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* Fetch the current session user
|
|
140
|
+
*
|
|
141
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
142
|
+
* @param {Boolean} [options.forceRetry=false] Forcabily try to refresh the user state
|
|
143
|
+
* @param {Boolean} [options.waitPromises=true] Wait for $auth + $subscriptions to resolve before fetching the user (mainly internal use)
|
|
144
|
+
*
|
|
145
|
+
* @returns {Promise<User>} The current logged in user or null if none
|
|
146
|
+
*/
|
|
147
|
+
getUser(options?: any): Promise<any | null>;
|
|
148
|
+
/**
|
|
149
|
+
* Require a user login to TERA
|
|
150
|
+
* If there is no user OR they are not logged in a prompt is shown to go and do so
|
|
151
|
+
* This is an pre-requisite step for requireProject()
|
|
152
|
+
*
|
|
153
|
+
* @returns {Promise<User>} A promise which will resolve if the there is a user and they are logged in
|
|
154
|
+
*/
|
|
155
|
+
requireUser(): Promise<any>;
|
|
156
|
+
/**
|
|
157
|
+
* Provide an object of credentials for 3rd party services like Firebase/Supabase
|
|
158
|
+
*
|
|
159
|
+
* @returns {Object} An object containing 3rd party service credentials
|
|
160
|
+
*/
|
|
161
|
+
getCredentials(): any;
|
|
162
|
+
/**
|
|
163
|
+
* In embed mode only - create a popup window and try to auth via that
|
|
164
|
+
*
|
|
165
|
+
* When in embed mode we can't store local state (Cookies without SameSite + LocalStorage etc.) so the only way to auth the user in the restricted envionment:
|
|
166
|
+
*
|
|
167
|
+
* 1. Try to read state from LocalStorage (if so, skip everything else)
|
|
168
|
+
* 2. Create a popup - which can escape the security container - and trigger a login
|
|
169
|
+
* 3. Listen locally for a message from the popup which it will transmit the authed user to its original window opener
|
|
170
|
+
* 3. Stash the state in LocalStorage to avoid this in future
|
|
171
|
+
*
|
|
172
|
+
* This workaround is only needed when developing with TERA in an embed window - i.e. local dev / stand alone websites
|
|
173
|
+
* Its annoying but I've tried everything else as a security method to get Non-Same-Origin sites to talk to each other
|
|
174
|
+
* - MC 2024-04-03
|
|
175
|
+
*
|
|
176
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
177
|
+
*/
|
|
178
|
+
getUserViaEmbedWorkaround(): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Project entry within TERA
|
|
181
|
+
* @class Project
|
|
182
|
+
* @property {String} id The Unique ID of the project
|
|
183
|
+
* @property {String} name The name of the project
|
|
184
|
+
* @property {String} created The creation date of the project as an ISO string
|
|
185
|
+
* @property {Boolean} isOwner Whether the current session user is the owner of the project
|
|
186
|
+
*/
|
|
187
|
+
/**
|
|
188
|
+
* Get the currently active project, if any
|
|
189
|
+
*
|
|
190
|
+
* @returns {Promise<Project|null>} The currently active project, if any
|
|
191
|
+
*/
|
|
192
|
+
getProject(): Promise<any | null>;
|
|
193
|
+
/**
|
|
194
|
+
* Get a list of projects the current session user has access to
|
|
195
|
+
*
|
|
196
|
+
* @returns {Promise<Array<Project>>} Collection of projects the user has access to
|
|
197
|
+
*/
|
|
198
|
+
getProjects(): Promise<any[]>;
|
|
199
|
+
/**
|
|
200
|
+
* Set the currently active project within TERA
|
|
201
|
+
*
|
|
202
|
+
* @param {Object|String} project The project to set as active - either the full Project object or its ID
|
|
203
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
204
|
+
*/
|
|
205
|
+
setActiveProject(project: any): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Ask the user to select a project from those available - if one isn't already active
|
|
208
|
+
* Note that this function will percist in asking the uesr even if they try to cancel
|
|
209
|
+
*
|
|
210
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
211
|
+
* @param {Boolean} [options.autoRequireUser=true] Automatically call `requireUser()` before trying to fetch a list of projects
|
|
212
|
+
* @param {Boolean} [options.autoSetActiveProject=true] After selecting a project set that project as active in TERA
|
|
213
|
+
* @param {String} [options.title="Select a project to work with"] The title of the dialog to display
|
|
214
|
+
* @param {String} [options.noSelectTitle='Select project'] Dialog title when warning the user they need to select something
|
|
215
|
+
* @param {String} [options.noSelectBody='A project needs to be selected to continue'] Dialog body when warning the user they need to select something
|
|
216
|
+
*
|
|
217
|
+
* @returns {Promise<Project>} The active project
|
|
218
|
+
*/
|
|
219
|
+
requireProject(options?: any): Promise<any>;
|
|
220
|
+
/**
|
|
221
|
+
* Prompt the user to select a project from those available
|
|
222
|
+
*
|
|
223
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
224
|
+
* @param {String} [options.title="Select a project to work with"] The title of the dialog to display
|
|
225
|
+
* @param {Boolean} [options.allowCancel=true] Allow cancelling the operation, will throw `'CANCEL'` if actioned
|
|
226
|
+
* @param {Boolean} [options.setActive=false] Also set the project as active when selected
|
|
227
|
+
*
|
|
228
|
+
* @returns {Promise<Project>} The active project
|
|
229
|
+
*/
|
|
230
|
+
selectProject(options?: any): Promise<any>;
|
|
231
|
+
/**
|
|
232
|
+
* Get a one-off snapshot of a namespace without mounting it
|
|
233
|
+
* This can be used for simpler apps which don't have their own reactive / observer equivelent
|
|
234
|
+
*
|
|
235
|
+
* @param {String} name The alias of the namespace, this should be alphanumeric + hyphens + underscores
|
|
236
|
+
*
|
|
237
|
+
* @returns {Promise<Object>} A promise which resolves to the namespace POJO state
|
|
238
|
+
*/
|
|
239
|
+
getNamespace(name: string): Promise<any>;
|
|
240
|
+
/**
|
|
241
|
+
* Set (or merge by default) a one-off snapshot over an existing namespace
|
|
242
|
+
* This can be used for simpler apps which don't have their own reactive / observer equivelent and just want to quickly set something
|
|
243
|
+
*
|
|
244
|
+
* @param {String} name The name of the namespace
|
|
245
|
+
* @param {Object} state The state to merge
|
|
246
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
247
|
+
* @param {'merge'|'set'} [options.method='merge'] How to handle the state. 'merge' (merge a partial state over the existing namespace state), 'set' (completely overwrite the existing namespace)
|
|
248
|
+
*
|
|
249
|
+
* @returns {Promise<Object>} A promise which resolves to the namespace POJO state
|
|
250
|
+
*/
|
|
251
|
+
setNamespace(name: string, state: any, options?: any): Promise<any>;
|
|
252
|
+
/**
|
|
253
|
+
* Return a list of namespaces available to the current project
|
|
254
|
+
*
|
|
255
|
+
* @returns {Promise<Array<Object>>} Collection of available namespaces for the current project
|
|
256
|
+
* @property {String} name The name of the namespace
|
|
257
|
+
*/
|
|
258
|
+
listNamespaces(): Promise<any[]>;
|
|
259
|
+
/**
|
|
260
|
+
* Return the current, full snapshot state of the active project
|
|
261
|
+
*
|
|
262
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
263
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
264
|
+
* @param {Array<String>} [options.paths] Paths to subscribe to e.g. ['/users/'],
|
|
265
|
+
*
|
|
266
|
+
* @returns {Promise<Object>} The current project state snapshot
|
|
267
|
+
*/
|
|
268
|
+
getProjectState(options?: any): Promise<any>;
|
|
269
|
+
/**
|
|
270
|
+
* Set a nested value within the project state
|
|
271
|
+
*
|
|
272
|
+
* Paths can be any valid Lodash.set() value such as:
|
|
273
|
+
* - Dotted notation - e.g. `foo.bar.1.baz`
|
|
274
|
+
* - Array path segments e.g. `['foo', 'bar', 1, 'baz']`
|
|
275
|
+
*
|
|
276
|
+
* Conflict strategies (copied from utils/pathTools @ `set()`)
|
|
277
|
+
* - 'set' / 'overwrite' - Just overwrite any existing value
|
|
278
|
+
* - 'merge' - Merge existing values using Lodash.merge()
|
|
279
|
+
* - 'defaults' - Merge existing values using Lodash.defaultsDeep()
|
|
280
|
+
*
|
|
281
|
+
* @param {String|Array<String>} path The sub-path within the project state to set
|
|
282
|
+
* @param {*} value The value to set, this is set using the conflict strategy
|
|
283
|
+
*
|
|
284
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
285
|
+
* @param {'set'} [options.strategy='set'] A PathTools.set strategy to handle existing values, if any
|
|
286
|
+
*
|
|
287
|
+
* @returns {Promise<*>} A promise which resolves to `value` when the operation has been dispatched to the server and saved
|
|
288
|
+
*/
|
|
289
|
+
setProjectState(path: string | string[], value: any, options?: any): Promise<any>;
|
|
290
|
+
/**
|
|
291
|
+
* Set a nested value within the project state - just like `setProjectState()` but applying the 'defaults' strategy by default
|
|
292
|
+
*
|
|
293
|
+
* @see setProjectState()
|
|
294
|
+
* @param {String|Array<String>} [path] The sub-path within the project state to set, if unspecifed the entire target is used as a target and a save operation is forced
|
|
295
|
+
* @param {*} value The value to set as the default structure
|
|
296
|
+
* @param {Object} [options] Additional options to mutate behaviour, see setProjectState() for the full list of supported options
|
|
297
|
+
*
|
|
298
|
+
* @returns {Promise<*>} A promise which resolves to the eventual input value after defaults have been applied
|
|
299
|
+
*/
|
|
300
|
+
setProjectStateDefaults(path: string | string[] | any, value?: any, options?: any): Promise<any>;
|
|
301
|
+
/**
|
|
302
|
+
* Force refetching the remote project state into local
|
|
303
|
+
*
|
|
304
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
305
|
+
*/
|
|
306
|
+
setProjectStateRefresh(): Promise<null>;
|
|
307
|
+
/**
|
|
308
|
+
* Data structure for a project file
|
|
309
|
+
* @class ProjectFile
|
|
310
|
+
*
|
|
311
|
+
* @property {String} id A UUID string representing the unique ID of the file
|
|
312
|
+
* @property {String} name Relative name path (can contain prefix directories) for the human readable file name
|
|
313
|
+
* @property {Object} parsedName An object representing meta file parts of a file name
|
|
314
|
+
* @property {String} parsedName.basename The filename + extention (i.e. everything without directory name)
|
|
315
|
+
* @property {String} parsedName.filename The file portion of the name (basename without the extension)
|
|
316
|
+
* @property {String} parsedName.ext The extension portion of the name (always lower case)
|
|
317
|
+
* @property {String} parsedName.dirName The directory path portion of the name
|
|
318
|
+
* @property {Date} created A date representing when the file was created
|
|
319
|
+
* @property {Date} modified A date representing when the file was created
|
|
320
|
+
* @property {Date} accessed A date representing when the file was last accessed
|
|
321
|
+
* @property {Number} size Size, in bytes, of the file
|
|
322
|
+
* @property {String} mime The associated mime type for the file
|
|
323
|
+
*/
|
|
324
|
+
/**
|
|
325
|
+
* Data structure for a file filter
|
|
326
|
+
* @class FileFilters
|
|
327
|
+
*
|
|
328
|
+
* @property {Boolean} [library=false] Restrict to library files only
|
|
329
|
+
* @property {String} [filename] CSV of @momsfriendlydevco/match expressions to filter the filename by (filenames are the basename sans extension)
|
|
330
|
+
* @property {String} [basename] CSV of @momsfriendlydevco/match expressions to filter the basename by
|
|
331
|
+
* @property {String} [ext] CSV of @momsfriendlydevco/match expressions to filter the file extension by
|
|
332
|
+
*/
|
|
333
|
+
/**
|
|
334
|
+
* Prompt the user to select a library to operate on
|
|
335
|
+
*
|
|
336
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
337
|
+
* @param {String} [options.title="Select a file"] The title of the dialog to display
|
|
338
|
+
* @param {String|Array<String>} [options.hint] Hints to identify the file to select in array order of preference
|
|
339
|
+
* @param {Boolean} [options.save=false] Set to truthy if saving a new file, UI will adjust to allowing overwrite OR new file name input
|
|
340
|
+
* @param {String} [options.saveFilename] File name to save as, if omitted the hinting system is used otherwise 'My File.unknown' is assumed
|
|
341
|
+
* @param {FileFilters} [options.filters] Optional file filters
|
|
342
|
+
* @param {Boolean} [options.allowUpload=true] Allow uploading new files
|
|
343
|
+
* @param {Boolean} [options.allowRefresh=true] Allow the user to manually refresh the file list
|
|
344
|
+
* @param {Boolean} [options.allowDownloadZip=true] Allow the user to download a Zip of all files
|
|
345
|
+
* @param {Boolean} [options.allowCancel=true] Allow cancelling the operation. Will throw `'CANCEL'` as the promise rejection if acationed
|
|
346
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
347
|
+
* @param {FileFilters} [options.filter] Optional file filters
|
|
348
|
+
*
|
|
349
|
+
* @returns {Promise<ProjectFile>} The eventually selected file, if in save mode new files are created as stubs
|
|
350
|
+
*/
|
|
351
|
+
selectProjectFile(options?: any): Promise<any>;
|
|
352
|
+
/**
|
|
353
|
+
* Fetch the files associated with a given project
|
|
354
|
+
*
|
|
355
|
+
* @param {Object} options Options which mutate behaviour
|
|
356
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
357
|
+
* @param {Boolean} [options.lazy=true] If true, use the fastest method to retrieve the file list such as the cache. If false, force a refresh each time
|
|
358
|
+
* @param {Boolean} [options.meta=true] Pull meta information for each file entity
|
|
359
|
+
*
|
|
360
|
+
* @returns {Promise<Array<ProjectFile>>} A collection of project files for the given project
|
|
361
|
+
*/
|
|
362
|
+
getProjectFiles(options?: any): Promise<any[]>;
|
|
363
|
+
/**
|
|
364
|
+
* Fetch a project file by its name
|
|
365
|
+
*
|
|
366
|
+
* @param {String} name The name + relative directory path component
|
|
367
|
+
*
|
|
368
|
+
* @param {Object|String} [options] Additional options to mutate behaviour, if a string is given `options.subkey` is assumed
|
|
369
|
+
* @param {String} [options.subkey] If specified only the extracted subkey is returned rather than the full object
|
|
370
|
+
* @param {Boolean} [options.cache=true] Use the existing file cache if possible, set to false to force a refresh of files from the server first
|
|
371
|
+
*
|
|
372
|
+
* @returns {Promise<ProjectFile>} The eventual fetched ProjectFile (or requested subkey)
|
|
373
|
+
*/
|
|
374
|
+
getProjectFile(name: string, options?: any): Promise<any>;
|
|
375
|
+
/**
|
|
376
|
+
* Fetch the raw contents of a file by its ID
|
|
377
|
+
*
|
|
378
|
+
* @param {String} [id] File ID to retrieve the contents of
|
|
379
|
+
*
|
|
380
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
381
|
+
* @param {'blob'|'json'} [options.format='blob'] The format to retrieve the file in. If `json` the raw output is run via JSON.parse() first
|
|
382
|
+
*
|
|
383
|
+
* @returns {*} The file contents in the requested format
|
|
384
|
+
*/
|
|
385
|
+
getProjectFileContents(id: string, options?: any): Promise<any>;
|
|
386
|
+
/**
|
|
387
|
+
* Create a new file
|
|
388
|
+
* This creates an empty file which can then be written to
|
|
389
|
+
* This function also forces a local file list cache update
|
|
390
|
+
*
|
|
391
|
+
* @param {String} name The name + relative directory path component
|
|
392
|
+
* @returns {Promise<ProjectFile>} The eventual ProjectFile created
|
|
393
|
+
*/
|
|
394
|
+
createProjectFile(name: string): Promise<any>;
|
|
395
|
+
/**
|
|
396
|
+
* Remove a project file by its ID
|
|
397
|
+
*
|
|
398
|
+
* @param {String} id The File ID to remove
|
|
399
|
+
*
|
|
400
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
401
|
+
*/
|
|
402
|
+
deleteProjectFile(id: string): Promise<null>;
|
|
403
|
+
/**
|
|
404
|
+
* Save (or overwrite) a file within a project
|
|
405
|
+
*
|
|
406
|
+
* @param {String|ProjectFile} [id] ProjectFile or ID of the same to overwrite, if omitted a file is prompted for
|
|
407
|
+
* @param {File|Blob|FormData|Object|Array} contents The new file contents
|
|
408
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
409
|
+
* @param {String|ProjectFile} [options.id] Alternate method to specify the file ID to save as, if omitted one will be prompted for
|
|
410
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
411
|
+
* @param {String|Array<String>} [options.hint] Hint(s) to store against the library. Generally corresponds to the current operation being performed - e.g. 'deduped'
|
|
412
|
+
* @param {String} [options.filename] Suggested filename if `id` is unspecified
|
|
413
|
+
* @param {String} [options.title='Save citation library'] Dialog title if `id` is unspecified and a prompt is necessary
|
|
414
|
+
* @param {Object} [options.meta] Optional meta data to merge into the file data
|
|
415
|
+
*
|
|
416
|
+
* @returns {Promise} A promise which will resolve when the write operation has completed
|
|
417
|
+
*/
|
|
418
|
+
setProjectFileContents(id: string | any | null, contents: any, options?: any): Promise<null>;
|
|
419
|
+
/**
|
|
420
|
+
* Prompt the user to select a library to operate on and return a array of references in a given format
|
|
421
|
+
*
|
|
422
|
+
* @param {Object} [options] Additional options to mutate behaviour - see `getProjectLibrary()` for parent list of options
|
|
423
|
+
* @param {String} [options.title="Select a citation library"] The title of the dialog to display
|
|
424
|
+
* @param {String|Array<String>} [options.hint] Hints to identify the library to select in array order of preference. Generally corresponds to the previous stage - e.g. 'deduped', 'review1', 'review2', 'dedisputed'
|
|
425
|
+
* @param {Boolean} [options.allowUpload=true] Allow uploading new files
|
|
426
|
+
* @param {Boolean} [options.allowRefresh=true] Allow the user to manually refresh the file list
|
|
427
|
+
* @param {Boolean} [options.allowDownloadZip=true] Allow the user to download a Zip of all files
|
|
428
|
+
* @param {Boolean} [options.allowCancel=true] Allow cancelling the operation. Will throw `'CANCEL'` as the promise rejection if acationed
|
|
429
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
430
|
+
* @param {FileFilters} [options.filters] Optional file filters, defaults to citation library selection only
|
|
431
|
+
*
|
|
432
|
+
* @returns {Promise<Array<Ref>>} A collection of references from the selected file
|
|
433
|
+
*/
|
|
434
|
+
selectProjectLibrary(options?: any): Promise<any[]>;
|
|
435
|
+
/**
|
|
436
|
+
* Fetch + convert a project file into a library of citations
|
|
437
|
+
*
|
|
438
|
+
* @param {String} id File ID to read
|
|
439
|
+
*
|
|
440
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
441
|
+
* @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)
|
|
442
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
443
|
+
* @param {Function} [options.filter] Optional async file filter, called each time as `(File:ProjectFile)`
|
|
444
|
+
* @param {Function} [options.find] Optional async final stage file filter to reduce all candidates down to one subject file
|
|
445
|
+
*
|
|
446
|
+
* @returns {Promise<Array<Ref>>|Promise<*>} A collection of references (default bevahiour) or a whatever format was requested
|
|
447
|
+
*/
|
|
448
|
+
getProjectLibrary(id: string, options?: any): Promise<any>;
|
|
449
|
+
/**
|
|
450
|
+
* Save back a citation library from some input
|
|
451
|
+
*
|
|
452
|
+
* @param {String} [id] File ID to save back to, if omitted a file will be prompted for
|
|
453
|
+
* @param {Array<RefLibRef>|Blob|File} [refs] Collection of references for the selected library or the raw Blob/File
|
|
454
|
+
*
|
|
455
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
456
|
+
* @param {String} [options.id] Alternate method to specify the file ID to save as, if omitted one will be prompted for
|
|
457
|
+
* @param {Array<RefLibRef>|Blob|File} [options.refs] Alternate method to specify the refs to save as an array or raw Blob/File
|
|
458
|
+
* @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)
|
|
459
|
+
* @param {Boolean} [options.autoRequire=true] Run `requireProject()` automatically before continuing
|
|
460
|
+
* @param {String|Array<String>} [options.hint] Hint(s) to store against the library. Generally corresponds to the current operation being performed - e.g. 'deduped'
|
|
461
|
+
* @param {String} [options.filename] Suggested filename if `id` is unspecified
|
|
462
|
+
* @param {String} [options.title='Save citation library'] Dialog title if `id` is unspecified and a prompt is necessary
|
|
463
|
+
* @param {Boolean} [options.overwrite=true] Allow existing file upsert
|
|
464
|
+
* @param {Object} [options.meta] Optional meta data to merge into the file data
|
|
465
|
+
*
|
|
466
|
+
* @returns {Promise} A promise which resolves when the save operation has completed
|
|
467
|
+
*/
|
|
468
|
+
setProjectLibrary(id: string | any | null, refs?: any, options?: any): Promise<null>;
|
|
469
|
+
/**
|
|
470
|
+
* Create a log entry for the currently active project
|
|
471
|
+
*
|
|
472
|
+
* The required log object can be of various forms. See https://tera-tools.com/api/logs.json for the full list
|
|
473
|
+
*
|
|
474
|
+
* @param {Object} log The log entry to create
|
|
475
|
+
* @returns {Promise} A promise which resolves when the operation has completed
|
|
476
|
+
*/
|
|
477
|
+
projectLog(log: any): Promise<void>;
|
|
478
|
+
/**
|
|
479
|
+
* Set an active tools URL or other context information so that it survives a refresh
|
|
480
|
+
* This only really makes a difference to tools within the tera-tools.com site where the tool is working as an embed
|
|
481
|
+
*
|
|
482
|
+
* @param {Object|String} options Context information about the page, if this is a string, its assumed to popupate `url`
|
|
483
|
+
* @param {String} [options.path] The URL path segment to restore on next refresh
|
|
484
|
+
* @param {String} [options.title] The page title associated with the path
|
|
485
|
+
*/
|
|
486
|
+
setPage(options: any): void;
|
|
487
|
+
/**
|
|
488
|
+
* Setup the TERA-fy client singleton
|
|
489
|
+
*
|
|
490
|
+
* @param {Object} [options] Additional options to merge into `settings`
|
|
491
|
+
*/
|
|
492
|
+
constructor(options?: any);
|
|
493
|
+
/**
|
|
494
|
+
* Initialize the browser listener
|
|
495
|
+
*/
|
|
496
|
+
init(): void;
|
|
497
|
+
/**
|
|
498
|
+
* Display simple text within TERA
|
|
499
|
+
*
|
|
500
|
+
* @param {String} [text] Text to display, if specified this populates `options.body`
|
|
501
|
+
*
|
|
502
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
503
|
+
* @param {String} [options.body="Alert!"] The body text to display
|
|
504
|
+
* @param {Boolean} [options.isHtml=false] If falsy the text is rendered as plain-text otherwise it will be assumed as HTML content
|
|
505
|
+
* @param {String} [options.title='TERA'] The title of the alert box
|
|
506
|
+
* @param {'ok'|false} [options.buttons='ok'] Button set to use or falsy to disable
|
|
507
|
+
*
|
|
508
|
+
* @returns {Promise} A promise which resolves when the alert has been dismissed
|
|
509
|
+
*/
|
|
510
|
+
uiAlert(text: string | any, options?: any): Promise<void>;
|
|
511
|
+
/**
|
|
512
|
+
* Present a simple ok/cancel dialog to the user
|
|
513
|
+
*
|
|
514
|
+
* @param {String} [text] Text to display, if specified this populates `options.body`
|
|
515
|
+
*
|
|
516
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
517
|
+
* @param {String} [options.body="Confirm?"] The body text to display
|
|
518
|
+
* @param {Boolean} [options.isHtml=false] If falsy the text is rendered as plain-text otherwise it will be assumed as HTML content
|
|
519
|
+
* @param {String} [options.title='TERA'] The title of the confirmation box
|
|
520
|
+
*
|
|
521
|
+
* @returns {Promise} A promise which resolves with `Promise.resolve('OK')` or rejects with `Promise.reject('CANCEL')`
|
|
522
|
+
*/
|
|
523
|
+
uiConfirm(text: string | any, options?: any): Promise<'OK'>;
|
|
524
|
+
/**
|
|
525
|
+
* Trigger a fatal error, killing the outer TERA site
|
|
526
|
+
*
|
|
527
|
+
* @function uiPanic
|
|
528
|
+
* @param {String} [text] Text to display
|
|
529
|
+
*/
|
|
530
|
+
uiPanic(text: any): void;
|
|
531
|
+
/**
|
|
532
|
+
* Display, update or dispose of windows for long running tasks
|
|
533
|
+
* All options are cumulative - i.e. they are merged with other options previously provided
|
|
534
|
+
*
|
|
535
|
+
* @param {Object|Boolean} [options] Additional options to mutate behaviour, if boolean false `close: true` is assumed
|
|
536
|
+
* @param {String} [options.body=''] Window body text
|
|
537
|
+
* @param {Boolean} [options.bodyHtml=false] If truthy, treat the body as HTML
|
|
538
|
+
* @param {String} [options.title='TERA'] Window title, can only be set on the initial call
|
|
539
|
+
* @param {Boolean} [options.close=false] Close the existing dialog, if true the dialog is disposed and options reset
|
|
540
|
+
* @param {Number} [options.progress] The current progress of the task being conducted, this is assumed to be a value less than `progressMax`
|
|
541
|
+
* @param {Number} [options.progressMax] The maximum value that the progress can be
|
|
542
|
+
*
|
|
543
|
+
* @returns {Promise} A promise which resolves when the dialog has been updated
|
|
544
|
+
*/
|
|
545
|
+
uiProgress(options?: any): Promise<void>;
|
|
546
|
+
_uiProgress: {
|
|
547
|
+
options: any | null;
|
|
548
|
+
promise: Promise<any> | null;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Prompt the user for an input, responding with a Promisable value
|
|
552
|
+
*
|
|
553
|
+
* @param {String} [text] Text to display, if specified this populates `options.body`
|
|
554
|
+
*
|
|
555
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
556
|
+
* @param {String} [options.body] Optional additional body text
|
|
557
|
+
* @param {Boolean} [options.isHtml=false] If truthy, treat the body as HTML
|
|
558
|
+
* @param {String} [options.value] Current or default value to display pre-filled
|
|
559
|
+
* @param {String} [options.title='Input required'] The dialog title to display
|
|
560
|
+
* @param {String} [options.placeholder] Optional placeholder text
|
|
561
|
+
* @param {Boolean} [options.required=true] Treat nullish or empty inputs as a cancel operation
|
|
562
|
+
*
|
|
563
|
+
* @returns {Promise<*>} Either the eventual user value or a throw with `Promise.reject('CANCEL')`
|
|
564
|
+
*/
|
|
565
|
+
uiPrompt(text: string | any, options?: any): Promise<any>;
|
|
566
|
+
/**
|
|
567
|
+
* Catch an error using the TERA error handler
|
|
568
|
+
*
|
|
569
|
+
* @param {Error|Object|String} error Error to handle, generally an Error object but can be a POJO or a scalar string
|
|
570
|
+
*
|
|
571
|
+
* @returns {Void} This function is fatal
|
|
572
|
+
*/
|
|
573
|
+
uiThrow(error: any): Promise<void>;
|
|
574
|
+
/**
|
|
575
|
+
* Open a popup window containing a new site
|
|
576
|
+
*
|
|
577
|
+
* @param {String} url The URL to open
|
|
578
|
+
*
|
|
579
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
580
|
+
* @param {Number} [options.width=500] The desired width of the window
|
|
581
|
+
* @param {Number} [options.height=600] The desired height of the window
|
|
582
|
+
* @param {Boolean} [options.center=true] Attempt to center the window on the screen
|
|
583
|
+
* @param {Object} [options.permissions] Additional permissions to set on opening, defaults to a suitable set of permission for popups (see code)
|
|
584
|
+
*
|
|
585
|
+
* @returns {WindowProxy} The opened window object (if `noopener` is not set in permissions)
|
|
586
|
+
*/
|
|
587
|
+
uiWindow(url: string | URL, options?: any): WindowProxy | null;
|
|
588
|
+
/**
|
|
589
|
+
* Display HTML content full-screen within TERA
|
|
590
|
+
* This function is ideally called within a requestFocus() wrapper
|
|
591
|
+
*
|
|
592
|
+
* @param {DOMElement|String|false} content Either a prepared DOM element or string to compile, set to falsy to remove existing content
|
|
593
|
+
*
|
|
594
|
+
* @param {Object} [options] Additional options to mutate behaviour
|
|
595
|
+
* @param {Boolean|String} [options.logo=false] Add a logo to the output, if boolean true the Tera-tools logo is used otherwise specify a path or URL
|
|
596
|
+
*/
|
|
597
|
+
uiSplat(content: Element | string | false, options?: any): void;
|
|
598
|
+
/**
|
|
599
|
+
* Debugging output function
|
|
600
|
+
* This function will only act if `settings.devMode` is truthy
|
|
601
|
+
*
|
|
602
|
+
* @param {'INFO'|'LOG'|'WARN'|'ERROR'} [method='LOG'] Logging method to use
|
|
603
|
+
* @param {Number} [verboseLevel=1] The verbosity level to trigger at. If `settings.verbosity` is lower than this, the message is ignored
|
|
604
|
+
* @param {...*} [msg] Output to show
|
|
605
|
+
*/
|
|
606
|
+
debug(...inputArgs: any[]): void;
|
|
607
|
+
}
|