@pi-r/azure 0.3.2 → 0.5.2

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Studio Trigger
1
+ Copyright 2023 Wit Studio
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @pi-r/azure
2
2
 
3
- PEP 402 - Forever Aina
3
+ PEP 402 - Forever Vivy
4
4
 
5
5
  ## LICENSE
6
6
 
package/client/index.js CHANGED
@@ -163,7 +163,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
163
163
  const closeClient = () => client?.dispose();
164
164
  for (let i = 0; i < length; ++i) {
165
165
  const item = batch[i];
166
- const { service, name, table, id, query, storedProcedureId, partitionKey, params, limit = 0, update, ignoreCache } = item;
166
+ const { service, name, table, id, query, storedProcedureId, partitionKey = null, params, limit = 0, update, ignoreCache } = item;
167
167
  if (!name || !table) {
168
168
  closeClient();
169
169
  throw (0, util_1.formatError)(item, name ? "Missing database table" : "Missing database name");
@@ -179,7 +179,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
179
179
  let rows, queryString = caching && ignoreCache !== true || ignoreCache === false || ignoreCache === 1 || renewCache ? name + '_' + table + '_' : '';
180
180
  if (storedProcedureId && params) {
181
181
  const { options } = item;
182
- if (queryString && (rows = getCache(queryString += (partitionKey || '') + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
182
+ if (queryString && (rows = getCache(queryString += Module.asString(partitionKey, true) + '_' + storedProcedureId + Module.asString(params, true) + Module.asString(options, true)))) {
183
183
  result[i] = rows;
184
184
  continue;
185
185
  }
@@ -191,7 +191,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
191
191
  else if (id) {
192
192
  const { options } = item;
193
193
  if (queryString) {
194
- queryString += (partitionKey || '') + '_' + id + Module.asString(options, true);
194
+ queryString += Module.asString(partitionKey, true) + '_' + id + Module.asString(options, true);
195
195
  if (!update && (rows = getCache(queryString))) {
196
196
  result[i] = rows;
197
197
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/azure",
3
- "version": "0.3.2",
3
+ "version": "0.5.2",
4
4
  "description": "Azure cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,11 +20,11 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.6.1",
24
- "@e-mc/module": "^0.6.1",
25
- "@e-mc/types": "^0.6.1",
26
- "@azure/cosmos": "^3.17.3",
27
- "@azure/identity": "^3.4.2",
23
+ "@e-mc/cloud": "^0.7.2",
24
+ "@e-mc/module": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "@azure/cosmos": "^4.0.0",
27
+ "@azure/identity": "^4.0.1",
28
28
  "@azure/storage-blob": "^12.17.0"
29
29
  }
30
30
  }
package/upload/index.js CHANGED
@@ -15,7 +15,7 @@ function upload(credential, service = 'azure') {
15
15
  return async (data, callback) => {
16
16
  var _a, _b;
17
17
  const { bucket, localUri } = data;
18
- const { pathname = '', fileGroup, contentType, metadata, endpoint, admin = {}, overwrite, options } = data.upload;
18
+ const { pathname = '', fileGroup, contentType, metadata, tags, endpoint, admin = {}, overwrite, options } = data.upload;
19
19
  const containerClient = blobServiceClient.getContainerClient(bucket);
20
20
  let filename = data.upload.filename || path.basename(localUri), bucketKey;
21
21
  const cleanup = () => {
@@ -28,15 +28,29 @@ function upload(credential, service = 'azure') {
28
28
  cleanup();
29
29
  callback(err);
30
30
  };
31
+ const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
32
+ const configBucket = admin.configBucket;
31
33
  if (!BUCKET_SESSION.has(bucket)) {
32
34
  const bucketAcl = admin.publicRead ? 'blob' : admin.acl;
33
- const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, admin.configBucket?.create));
35
+ const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, configBucket?.create));
34
36
  if (!await response) {
35
37
  errorResponse(null);
36
38
  return;
37
39
  }
38
40
  BUCKET_SESSION.add(bucket);
39
41
  }
42
+ let retentionPolicy = configBucket?.retentionPolicy;
43
+ if (retentionPolicy) {
44
+ if (!Array.isArray(retentionPolicy)) {
45
+ retentionPolicy = [retentionPolicy];
46
+ }
47
+ containerClient.setAccessPolicy('container', retentionPolicy)
48
+ .then(() => {
49
+ const { expiresOn, startsOn, permissions } = retentionPolicy[0].accessPolicy;
50
+ this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], expiresOn ? expiresOn.toLocaleString() + ' (expires)' : startsOn ? startsOn.toLocaleString() + ' (starts)' : permissions, { ...Cloud.LOG_CLOUD_COMMAND });
51
+ })
52
+ .catch(err => addLog(err));
53
+ }
40
54
  if (!overwrite) {
41
55
  try {
42
56
  const current = filename;
@@ -69,7 +83,6 @@ function upload(credential, service = 'azure') {
69
83
  const Key = [filename];
70
84
  const Body = [data.buffer];
71
85
  const ContentType = [contentType];
72
- const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
73
86
  if (fileGroup) {
74
87
  for (const [content, ext, localFile] of fileGroup) {
75
88
  try {
@@ -91,8 +104,13 @@ function upload(credential, service = 'azure') {
91
104
  }
92
105
  const blobName = Module.joinPath(pathname, Key[i]);
93
106
  const params = { ...options, abortSignal: this.signal };
94
- if (first && metadata) {
95
- params.metadata = metadata;
107
+ if (first) {
108
+ if ((0, types_1.isPlainObject)(metadata)) {
109
+ params.metadata = metadata;
110
+ }
111
+ if ((0, types_1.isPlainObject)(tags)) {
112
+ params.tags = tags;
113
+ }
96
114
  }
97
115
  (_b = (params.blobHTTPHeaders || (params.blobHTTPHeaders = {}))).blobContentType || (_b.blobContentType = ContentType[i]);
98
116
  containerClient.getBlockBlobClient(blobName).upload(Body[i], Body[i].byteLength, params)