1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
|
17 | if (k2 === undefined) k2 = k;
|
18 | var desc = Object.getOwnPropertyDescriptor(m, k);
|
19 | if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
20 | desc = {
|
21 | enumerable: true,
|
22 | get: function () {
|
23 | return m[k];
|
24 | }
|
25 | };
|
26 | }
|
27 | Object.defineProperty(o, k2, desc);
|
28 | } : function (o, m, k, k2) {
|
29 | if (k2 === undefined) k2 = k;
|
30 | o[k2] = m[k];
|
31 | });
|
32 | var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
|
33 | Object.defineProperty(o, "default", {
|
34 | enumerable: true,
|
35 | value: v
|
36 | });
|
37 | } : function (o, v) {
|
38 | o["default"] = v;
|
39 | });
|
40 | var __importStar = this && this.__importStar || function (mod) {
|
41 | if (mod && mod.__esModule) return mod;
|
42 | var result = {};
|
43 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
44 | __setModuleDefault(result, mod);
|
45 | return result;
|
46 | };
|
47 | Object.defineProperty(exports, "__esModule", {
|
48 | value: true
|
49 | });
|
50 | exports.PassThroughShim = void 0;
|
51 | exports.normalize = normalize;
|
52 | exports.objectEntries = objectEntries;
|
53 | exports.fixedEncodeURIComponent = fixedEncodeURIComponent;
|
54 | exports.encodeURI = encodeURI;
|
55 | exports.qsStringify = qsStringify;
|
56 | exports.objectKeyToLowercase = objectKeyToLowercase;
|
57 | exports.unicodeJSONStringify = unicodeJSONStringify;
|
58 | exports.convertObjKeysToSnakeCase = convertObjKeysToSnakeCase;
|
59 | exports.formatAsUTCISO = formatAsUTCISO;
|
60 | exports.getRuntimeTrackingString = getRuntimeTrackingString;
|
61 | exports.getUserAgentString = getUserAgentString;
|
62 | exports.getDirName = getDirName;
|
63 | exports.getModuleFormat = getModuleFormat;
|
64 | const path = __importStar(require("path"));
|
65 | const querystring = __importStar(require("querystring"));
|
66 | const stream_1 = require("stream");
|
67 | const url = __importStar(require("url"));
|
68 |
|
69 |
|
70 | const package_json_helper_cjs_1 = require("./package-json-helper.cjs");
|
71 |
|
72 | const fileURLToPath = url.fileURLToPath;
|
73 | const isEsm = false;
|
74 | function normalize(optionsOrCallback, cb) {
|
75 | const options = typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
|
76 | const callback = typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
|
77 | return {
|
78 | options,
|
79 | callback
|
80 | };
|
81 | }
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function objectEntries(obj) {
|
88 | return Object.keys(obj).map(key => [key, obj[key]]);
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | function fixedEncodeURIComponent(str) {
|
100 | return encodeURIComponent(str).replace(/[!'()*]/g, c => '%' + c.charCodeAt(0).toString(16).toUpperCase());
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | function encodeURI(uri, encodeSlash) {
|
112 |
|
113 |
|
114 | return uri.split('/').map(fixedEncodeURIComponent).join(encodeSlash ? '%2F' : '/');
|
115 | }
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | function qsStringify(qs) {
|
122 | return querystring.stringify(qs, '&', '=', {
|
123 | encodeURIComponent: component => encodeURI(component, true)
|
124 | });
|
125 | }
|
126 | function objectKeyToLowercase(object) {
|
127 | const newObj = {};
|
128 | for (let key of Object.keys(object)) {
|
129 | const value = object[key];
|
130 | key = key.toLowerCase();
|
131 | newObj[key] = value;
|
132 | }
|
133 | return newObj;
|
134 | }
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | function unicodeJSONStringify(obj) {
|
141 | return JSON.stringify(obj).replace(/[\u0080-\uFFFF]/g, char => '\\u' + ('0000' + char.charCodeAt(0).toString(16)).slice(-4));
|
142 | }
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | function convertObjKeysToSnakeCase(obj) {
|
149 | if (obj instanceof Date || obj instanceof RegExp) {
|
150 | return obj;
|
151 | }
|
152 | if (Array.isArray(obj)) {
|
153 | return obj.map(convertObjKeysToSnakeCase);
|
154 | }
|
155 | if (obj instanceof Object) {
|
156 | return Object.keys(obj).reduce((acc, cur) => {
|
157 | const s = cur[0].toLocaleLowerCase() + cur.slice(1).replace(/([A-Z]+)/g, (match, p1) => {
|
158 | return `_${p1.toLowerCase()}`;
|
159 | });
|
160 | acc[s] = convertObjKeysToSnakeCase(obj[cur]);
|
161 | return acc;
|
162 | }, Object());
|
163 | }
|
164 | return obj;
|
165 | }
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | function formatAsUTCISO(dateTimeToFormat, includeTime = false, dateDelimiter = '', timeDelimiter = '') {
|
175 | const year = dateTimeToFormat.getUTCFullYear();
|
176 | const month = dateTimeToFormat.getUTCMonth() + 1;
|
177 | const day = dateTimeToFormat.getUTCDate();
|
178 | const hour = dateTimeToFormat.getUTCHours();
|
179 | const minute = dateTimeToFormat.getUTCMinutes();
|
180 | const second = dateTimeToFormat.getUTCSeconds();
|
181 | let resultString = `${year.toString().padStart(4, '0')}${dateDelimiter}${month.toString().padStart(2, '0')}${dateDelimiter}${day.toString().padStart(2, '0')}`;
|
182 | if (includeTime) {
|
183 | resultString = `${resultString}T${hour.toString().padStart(2, '0')}${timeDelimiter}${minute.toString().padStart(2, '0')}${timeDelimiter}${second.toString().padStart(2, '0')}Z`;
|
184 | }
|
185 | return resultString;
|
186 | }
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | function getRuntimeTrackingString() {
|
192 | if (
|
193 |
|
194 |
|
195 | globalThis.Deno &&
|
196 |
|
197 |
|
198 | globalThis.Deno.version &&
|
199 |
|
200 |
|
201 | globalThis.Deno.version.deno) {
|
202 |
|
203 |
|
204 | return `gl-deno/${globalThis.Deno.version.deno}`;
|
205 | } else {
|
206 | return `gl-node/${process.versions.node}`;
|
207 | }
|
208 | }
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | function getUserAgentString() {
|
214 | const pkg = (0, package_json_helper_cjs_1.getPackageJSON)();
|
215 | const hyphenatedPackageName = pkg.name.replace('@google-cloud', 'gcloud-node')
|
216 | .replace('/', '-');
|
217 | return hyphenatedPackageName + '/' + pkg.version;
|
218 | }
|
219 | function getDirName() {
|
220 | let dirToUse = '';
|
221 | try {
|
222 | dirToUse = __dirname;
|
223 | } catch (e) {
|
224 |
|
225 |
|
226 | dirToUse = __dirname;
|
227 | }
|
228 | return dirToUse;
|
229 | }
|
230 | function getModuleFormat() {
|
231 | return isEsm ? 'ESM' : 'CJS';
|
232 | }
|
233 | class PassThroughShim extends stream_1.PassThrough {
|
234 | constructor() {
|
235 | super(...arguments);
|
236 | this.shouldEmitReading = true;
|
237 | this.shouldEmitWriting = true;
|
238 | }
|
239 | _read(size) {
|
240 | if (this.shouldEmitReading) {
|
241 | this.emit('reading');
|
242 | this.shouldEmitReading = false;
|
243 | }
|
244 | super._read(size);
|
245 | }
|
246 | _write(chunk, encoding, callback) {
|
247 | if (this.shouldEmitWriting) {
|
248 | this.emit('writing');
|
249 | this.shouldEmitWriting = false;
|
250 | }
|
251 |
|
252 | process.nextTick(() => {
|
253 | super._write(chunk, encoding, callback);
|
254 | });
|
255 | }
|
256 | _final(callback) {
|
257 |
|
258 |
|
259 | if (this.shouldEmitReading) {
|
260 | this.emit('reading');
|
261 | this.shouldEmitReading = false;
|
262 | }
|
263 | if (this.shouldEmitWriting) {
|
264 | this.emit('writing');
|
265 | this.shouldEmitWriting = false;
|
266 | }
|
267 | callback(null);
|
268 | }
|
269 | }
|
270 | exports.PassThroughShim = PassThroughShim;
|