backendless 6.3.3 → 6.3.7

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": "backendless",
3
- "version": "6.3.3",
3
+ "version": "6.3.7",
4
4
  "description": "Backendless JavaScript SDK for Node.js and the browser",
5
5
  "browser": "dist/backendless.js",
6
6
  "main": "lib/index.js",
@@ -83,7 +83,7 @@
83
83
  "rimraf": "^3.0.2",
84
84
  "socket.io": "^2.3.0",
85
85
  "terser-webpack-plugin": "^2.3.8",
86
- "typescript": "^4.3.4",
86
+ "typescript": "^4.5.4",
87
87
  "watch": "^1.0.2",
88
88
  "watchify": "^4.0.0",
89
89
  "webpack": "^4.46.0",
package/src/data/index.js CHANGED
@@ -61,6 +61,12 @@ export default class Data {
61
61
  })
62
62
  }
63
63
 
64
+ async getTableNameById(tableId) {
65
+ return this.app.request.get({
66
+ url: this.app.urls.dataTableNameById(tableId),
67
+ })
68
+ }
69
+
64
70
  mapTableToClass(tableName, clientClass) {
65
71
  if (typeof tableName === 'function') {
66
72
  clientClass = tableName
@@ -29,7 +29,7 @@ export default class Files {
29
29
  query.overwrite = overwrite
30
30
  }
31
31
 
32
- filePath = FilesUtils.preventSlashInPath(filePath)
32
+ filePath = FilesUtils.trimSlashesInPath(filePath)
33
33
  fileName = FilesUtils.sanitizeFileName(fileName)
34
34
 
35
35
  return this.app.request.put({
@@ -47,7 +47,7 @@ export default class Files {
47
47
  query.overwrite = overwrite
48
48
  }
49
49
 
50
- filePath = FilesUtils.preventSlashInPath(filePath)
50
+ filePath = FilesUtils.trimSlashesInPath(filePath)
51
51
 
52
52
  const pathTokens = FilesUtils.parseFilePath(filePath)
53
53
 
@@ -66,7 +66,7 @@ export default class Files {
66
66
  }
67
67
 
68
68
  return this.app.request.post({
69
- url : `${this.app.urls.filePath(filePath)}/${fileName || ''}`,
69
+ url : `${this.app.urls.filePath(filePath)}/${fileName}`,
70
70
  query: query,
71
71
  data : {
72
72
  url: file
@@ -93,6 +93,94 @@ export default class Files {
93
93
  })
94
94
  }
95
95
 
96
+ async append(filePath, fileName, fileContent) {
97
+ if (!filePath || typeof filePath !== 'string') {
98
+ throw new Error('"filePath" must be provided and must be a string.')
99
+ }
100
+
101
+ filePath = FilesUtils.trimSlashesInPath(filePath)
102
+
103
+ if (arguments.length === 2) {
104
+ fileContent = fileName
105
+ fileName = undefined
106
+
107
+ const pathTokens = FilesUtils.parseFilePath(filePath)
108
+
109
+ if (pathTokens.fileName) {
110
+ filePath = pathTokens.filePath
111
+ fileName = pathTokens.fileName
112
+ }
113
+ }
114
+
115
+ if (!fileName) {
116
+ throw new Error('Can not resolve target file name')
117
+ }
118
+
119
+ fileName = FilesUtils.sanitizeFileName(fileName)
120
+
121
+ if (typeof fileContent === 'string') {
122
+ return this.app.request.post({
123
+ url : `${this.app.urls.fileAppendPath(filePath)}/${fileName}`,
124
+ data: {
125
+ url: fileContent
126
+ },
127
+ })
128
+ }
129
+
130
+ if (FilesUtils.isBytesArray(fileContent)) {
131
+ fileContent = await FilesUtils.toBase64(fileContent)
132
+
133
+ return this.app.request.put({
134
+ url : `${this.app.urls.fileAppendBinaryPath(filePath)}/${fileName}`,
135
+ headers: { 'Content-Type': 'text/plain' },
136
+ data : fileContent,
137
+ })
138
+ }
139
+
140
+ return this.app.request.post({
141
+ url : `${this.app.urls.fileAppendPath(filePath)}/${fileName}`,
142
+ form: {
143
+ file: fileContent
144
+ },
145
+ })
146
+ }
147
+
148
+ async appendText(filePath, fileName, textContent) {
149
+ if (!filePath || typeof filePath !== 'string') {
150
+ throw new Error('"filePath" must be provided and must be a string.')
151
+ }
152
+
153
+ filePath = FilesUtils.trimSlashesInPath(filePath)
154
+
155
+ if (arguments.length === 2) {
156
+ textContent = fileName
157
+ fileName = undefined
158
+
159
+ const pathTokens = FilesUtils.parseFilePath(filePath)
160
+
161
+ if (pathTokens.fileName) {
162
+ filePath = pathTokens.filePath
163
+ fileName = pathTokens.fileName
164
+ }
165
+ }
166
+
167
+ if (!fileName) {
168
+ throw new Error('Can not resolve target file name')
169
+ }
170
+
171
+ if (typeof textContent !== 'string') {
172
+ throw new Error('"textContent" must be a string')
173
+ }
174
+
175
+ fileName = FilesUtils.sanitizeFileName(fileName)
176
+
177
+ return this.app.request.put({
178
+ url : `${this.app.urls.fileAppendPath(filePath)}/${fileName}`,
179
+ headers: { 'Content-Type': 'text/plain' },
180
+ data : textContent,
181
+ })
182
+ }
183
+
96
184
  async listing(filePath, pattern, sub, pagesize, offset) {
97
185
  const query = {}
98
186
 
@@ -100,7 +188,7 @@ export default class Files {
100
188
  throw new Error('"filePath" must be provided and must be a string.')
101
189
  }
102
190
 
103
- filePath = FilesUtils.preventSlashInPath(filePath)
191
+ filePath = FilesUtils.trimSlashesInPath(filePath)
104
192
 
105
193
  if (pattern && typeof pattern === 'string') {
106
194
  query.pattern = pattern
@@ -181,7 +269,7 @@ export default class Files {
181
269
  throw new Error('"filePath" must be provided and must be a string.')
182
270
  }
183
271
 
184
- filePath = FilesUtils.preventSlashInPath(filePath)
272
+ filePath = FilesUtils.trimSlashesInPath(filePath)
185
273
 
186
274
  return this.app.request.get({
187
275
  url : this.app.urls.filePath(filePath),
@@ -196,7 +284,7 @@ export default class Files {
196
284
  throw new Error('Directory "path" must be provided and must be a string.')
197
285
  }
198
286
 
199
- directoryPath = FilesUtils.preventSlashInPath(directoryPath)
287
+ directoryPath = FilesUtils.trimSlashesInPath(directoryPath)
200
288
 
201
289
  return this.app.request.delete({
202
290
  url: this.app.urls.filePath(directoryPath),
@@ -212,7 +300,7 @@ export default class Files {
212
300
  throw new Error('Files Pattern must be provided and must be a string.')
213
301
  }
214
302
 
215
- filesPath = FilesUtils.preventSlashInPath(filesPath)
303
+ filesPath = FilesUtils.trimSlashesInPath(filesPath)
216
304
 
217
305
  return this.app.request.get({
218
306
  url : this.app.urls.filePath(filesPath),
@@ -1,10 +1,33 @@
1
1
  const FilesUtils = {
2
+
3
+ isBytesArray(data) {
4
+ if (typeof Buffer !== 'undefined' && data instanceof Buffer) {
5
+ return true
6
+ }
7
+
8
+ if (typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) {
9
+ return true
10
+ }
11
+
12
+ return Array.isArray(data)
13
+ },
14
+
2
15
  ensureSlashInPath(path) {
3
16
  return !path.startsWith('/') ? `/${path}` : path
4
17
  },
5
18
 
6
- preventSlashInPath(path) {
7
- return (path && path.startsWith('/')) ? path.slice(1) : path
19
+ trimSlashesInPath(path) {
20
+ if (path) {
21
+ if (path.startsWith('/')) {
22
+ path = path.slice(1)
23
+ }
24
+
25
+ if (path.endsWith('/')) {
26
+ path = path.slice(0, path.length - 1)
27
+ }
28
+ }
29
+
30
+ return path
8
31
  },
9
32
 
10
33
  parseFilePath(path) {
@@ -9,7 +9,9 @@ export default class LocalCache {
9
9
  constructor(app) {
10
10
  this.app = app
11
11
 
12
- this.storageName = `${STORAGE_KEY_NAMESPACE}_${this.app.appId}`
12
+ this.storageName = this.app.appId
13
+ ? `${STORAGE_KEY_NAMESPACE}_${this.app.appId}`
14
+ : STORAGE_KEY_NAMESPACE
13
15
 
14
16
  const Storage = Utils.isLocalStorageSupported
15
17
  ? LocalStorage
@@ -47,6 +47,10 @@ export default class Logging {
47
47
  }
48
48
 
49
49
  push(logger, logLevel, message, exception) {
50
+ if (typeof message !== 'string') {
51
+ throw new Error('"message" must be a string')
52
+ }
53
+
50
54
  this.pool.push({ logger, message, exception, 'log-level': logLevel, timestamp: Date.now() })
51
55
 
52
56
  this.checkMessagesLen()
package/src/urls.js CHANGED
@@ -157,6 +157,10 @@ export default class Urls {
157
157
  return `${this.dataTable(tableName)}/permissions/${permissionType}/${objectId}`
158
158
  }
159
159
 
160
+ dataTableNameById(tableId) {
161
+ return `${this.data()}/${tableId}/table-name`
162
+ }
163
+
160
164
  transactions() {
161
165
  return `${this.root()}/transaction/unit-of-work`
162
166
  }
@@ -257,6 +261,14 @@ export default class Urls {
257
261
  return `${this.files()}/binary/${path}`
258
262
  }
259
263
 
264
+ fileAppendPath(path) {
265
+ return `${this.files()}/append/${path}`
266
+ }
267
+
268
+ fileAppendBinaryPath(path) {
269
+ return `${this.files()}/append/binary/${path}`
270
+ }
271
+
260
272
  //users
261
273
  users() {
262
274
  return `${this.root()}/users`