sanity-plugin-transifex 1.1.2 → 2.0.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/dist/index.d.ts +10 -15
- package/dist/sanity-plugin-transifex.cjs.development.js +492 -1063
- package/dist/sanity-plugin-transifex.cjs.development.js.map +1 -1
- package/dist/sanity-plugin-transifex.cjs.production.min.js +1 -1
- package/dist/sanity-plugin-transifex.cjs.production.min.js.map +1 -1
- package/dist/sanity-plugin-transifex.esm.js +466 -1053
- package/dist/sanity-plugin-transifex.esm.js.map +1 -1
- package/dist/transifexAdapter/createTask.d.ts +6 -0
- package/dist/transifexAdapter/getLocales.d.ts +2 -0
- package/dist/transifexAdapter/getTranslation.d.ts +2 -0
- package/dist/transifexAdapter/getTranslationTask.d.ts +6 -0
- package/dist/transifexAdapter/helpers.d.ts +7 -0
- package/dist/{transifexAdapter.d.ts → transifexAdapter/index.d.ts} +0 -0
- package/package.json +2 -2
- package/src/index.ts +25 -30
- package/src/transifexAdapter/createTask.ts +87 -0
- package/src/transifexAdapter/getLocales.ts +21 -0
- package/src/transifexAdapter/getTranslation.ts +102 -0
- package/src/transifexAdapter/getTranslationTask.ts +58 -0
- package/src/transifexAdapter/helpers.ts +11 -0
- package/src/transifexAdapter/index.ts +13 -0
- package/dist/helpers.d.ts +0 -5
- package/src/helpers.ts +0 -114
- package/src/transifexAdapter.ts +0 -230
|
@@ -1,814 +1,422 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, customSerializers, defaultStopTypes } from 'sanity-naive-html-serializer';
|
|
4
|
-
import sanityClient from 'part:@sanity/base/client';
|
|
1
|
+
import { baseFieldLevelConfig, baseDocumentLevelConfig } from 'sanity-translations-tab';
|
|
2
|
+
export { BaseDocumentDeserializer, BaseDocumentMerger, BaseDocumentSerializer, TranslationsTab, customSerializers, defaultStopTypes, documentLevelPatch, fieldLevelPatch, findLatestDraft } from 'sanity-translations-tab';
|
|
5
3
|
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
var info = gen[key](arg);
|
|
9
|
-
var value = info.value;
|
|
10
|
-
} catch (error) {
|
|
11
|
-
reject(error);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (info.done) {
|
|
16
|
-
resolve(value);
|
|
17
|
-
} else {
|
|
18
|
-
Promise.resolve(value).then(_next, _throw);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function _asyncToGenerator(fn) {
|
|
23
|
-
return function () {
|
|
24
|
-
var self = this,
|
|
25
|
-
args = arguments;
|
|
26
|
-
return new Promise(function (resolve, reject) {
|
|
27
|
-
var gen = fn.apply(self, args);
|
|
28
|
-
|
|
29
|
-
function _next(value) {
|
|
30
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function _throw(err) {
|
|
34
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
35
|
-
}
|
|
4
|
+
function _regeneratorRuntime() {
|
|
5
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
36
6
|
|
|
37
|
-
|
|
38
|
-
|
|
7
|
+
_regeneratorRuntime = function () {
|
|
8
|
+
return exports;
|
|
39
9
|
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function createCommonjsModule(fn, module) {
|
|
43
|
-
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var runtime_1 = createCommonjsModule(function (module) {
|
|
47
|
-
/**
|
|
48
|
-
* Copyright (c) 2014-present, Facebook, Inc.
|
|
49
|
-
*
|
|
50
|
-
* This source code is licensed under the MIT license found in the
|
|
51
|
-
* LICENSE file in the root directory of this source tree.
|
|
52
|
-
*/
|
|
53
10
|
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
|
62
|
-
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
11
|
+
var exports = {},
|
|
12
|
+
Op = Object.prototype,
|
|
13
|
+
hasOwn = Op.hasOwnProperty,
|
|
14
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
16
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
17
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
63
18
|
|
|
64
19
|
function define(obj, key, value) {
|
|
65
|
-
Object.defineProperty(obj, key, {
|
|
20
|
+
return Object.defineProperty(obj, key, {
|
|
66
21
|
value: value,
|
|
67
|
-
enumerable:
|
|
68
|
-
configurable:
|
|
69
|
-
writable:
|
|
70
|
-
});
|
|
71
|
-
return obj[key];
|
|
22
|
+
enumerable: !0,
|
|
23
|
+
configurable: !0,
|
|
24
|
+
writable: !0
|
|
25
|
+
}), obj[key];
|
|
72
26
|
}
|
|
27
|
+
|
|
73
28
|
try {
|
|
74
|
-
// IE 8 has a broken Object.defineProperty that only works on DOM objects.
|
|
75
29
|
define({}, "");
|
|
76
30
|
} catch (err) {
|
|
77
|
-
define = function(obj, key, value) {
|
|
31
|
+
define = function (obj, key, value) {
|
|
78
32
|
return obj[key] = value;
|
|
79
33
|
};
|
|
80
34
|
}
|
|
81
35
|
|
|
82
36
|
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
37
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
38
|
+
generator = Object.create(protoGenerator.prototype),
|
|
39
|
+
context = new Context(tryLocsList || []);
|
|
40
|
+
return generator._invoke = function (innerFn, self, context) {
|
|
41
|
+
var state = "suspendedStart";
|
|
42
|
+
return function (method, arg) {
|
|
43
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
44
|
+
|
|
45
|
+
if ("completed" === state) {
|
|
46
|
+
if ("throw" === method) throw arg;
|
|
47
|
+
return doneResult();
|
|
48
|
+
}
|
|
87
49
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
generator._invoke = makeInvokeMethod(innerFn, self, context);
|
|
50
|
+
for (context.method = method, context.arg = arg;;) {
|
|
51
|
+
var delegate = context.delegate;
|
|
91
52
|
|
|
92
|
-
|
|
53
|
+
if (delegate) {
|
|
54
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
55
|
+
|
|
56
|
+
if (delegateResult) {
|
|
57
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
58
|
+
return delegateResult;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
63
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
64
|
+
context.dispatchException(context.arg);
|
|
65
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
66
|
+
state = "executing";
|
|
67
|
+
var record = tryCatch(innerFn, self, context);
|
|
68
|
+
|
|
69
|
+
if ("normal" === record.type) {
|
|
70
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
71
|
+
return {
|
|
72
|
+
value: record.arg,
|
|
73
|
+
done: context.done
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}(innerFn, self, context), generator;
|
|
93
81
|
}
|
|
94
|
-
exports.wrap = wrap;
|
|
95
82
|
|
|
96
|
-
// Try/catch helper to minimize deoptimizations. Returns a completion
|
|
97
|
-
// record like context.tryEntries[i].completion. This interface could
|
|
98
|
-
// have been (and was previously) designed to take a closure to be
|
|
99
|
-
// invoked without arguments, but in all the cases we care about we
|
|
100
|
-
// already have an existing method we want to call, so there's no need
|
|
101
|
-
// to create a new function object. We can even get away with assuming
|
|
102
|
-
// the method takes exactly one argument, since that happens to be true
|
|
103
|
-
// in every case, so we don't have to touch the arguments object. The
|
|
104
|
-
// only additional allocation required is the completion record, which
|
|
105
|
-
// has a stable shape and so hopefully should be cheap to allocate.
|
|
106
83
|
function tryCatch(fn, obj, arg) {
|
|
107
84
|
try {
|
|
108
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
type: "normal",
|
|
87
|
+
arg: fn.call(obj, arg)
|
|
88
|
+
};
|
|
109
89
|
} catch (err) {
|
|
110
|
-
return {
|
|
90
|
+
return {
|
|
91
|
+
type: "throw",
|
|
92
|
+
arg: err
|
|
93
|
+
};
|
|
111
94
|
}
|
|
112
95
|
}
|
|
113
96
|
|
|
114
|
-
|
|
115
|
-
var GenStateSuspendedYield = "suspendedYield";
|
|
116
|
-
var GenStateExecuting = "executing";
|
|
117
|
-
var GenStateCompleted = "completed";
|
|
118
|
-
|
|
119
|
-
// Returning this object from the innerFn has the same effect as
|
|
120
|
-
// breaking out of the dispatch switch statement.
|
|
97
|
+
exports.wrap = wrap;
|
|
121
98
|
var ContinueSentinel = {};
|
|
122
99
|
|
|
123
|
-
// Dummy constructor functions that we use as the .constructor and
|
|
124
|
-
// .constructor.prototype properties for functions that return Generator
|
|
125
|
-
// objects. For full spec compliance, you may wish to configure your
|
|
126
|
-
// minifier not to mangle the names of these two functions.
|
|
127
100
|
function Generator() {}
|
|
101
|
+
|
|
128
102
|
function GeneratorFunction() {}
|
|
103
|
+
|
|
129
104
|
function GeneratorFunctionPrototype() {}
|
|
130
105
|
|
|
131
|
-
// This is a polyfill for %IteratorPrototype% for environments that
|
|
132
|
-
// don't natively support it.
|
|
133
106
|
var IteratorPrototype = {};
|
|
134
|
-
IteratorPrototype
|
|
107
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
135
108
|
return this;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
NativeIteratorPrototype !== Op &&
|
|
142
|
-
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
|
143
|
-
// This environment has a native %IteratorPrototype%; use it instead
|
|
144
|
-
// of the polyfill.
|
|
145
|
-
IteratorPrototype = NativeIteratorPrototype;
|
|
146
|
-
}
|
|
109
|
+
});
|
|
110
|
+
var getProto = Object.getPrototypeOf,
|
|
111
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
112
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
113
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
147
114
|
|
|
148
|
-
var Gp = GeneratorFunctionPrototype.prototype =
|
|
149
|
-
Generator.prototype = Object.create(IteratorPrototype);
|
|
150
|
-
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
|
151
|
-
GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
|
152
|
-
GeneratorFunction.displayName = define(
|
|
153
|
-
GeneratorFunctionPrototype,
|
|
154
|
-
toStringTagSymbol,
|
|
155
|
-
"GeneratorFunction"
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
// Helper for defining the .next, .throw, and .return methods of the
|
|
159
|
-
// Iterator interface in terms of a single ._invoke method.
|
|
160
115
|
function defineIteratorMethods(prototype) {
|
|
161
|
-
["next", "throw", "return"].forEach(function(method) {
|
|
162
|
-
define(prototype, method, function(arg) {
|
|
116
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
117
|
+
define(prototype, method, function (arg) {
|
|
163
118
|
return this._invoke(method, arg);
|
|
164
119
|
});
|
|
165
120
|
});
|
|
166
121
|
}
|
|
167
122
|
|
|
168
|
-
exports.isGeneratorFunction = function(genFun) {
|
|
169
|
-
var ctor = typeof genFun === "function" && genFun.constructor;
|
|
170
|
-
return ctor
|
|
171
|
-
? ctor === GeneratorFunction ||
|
|
172
|
-
// For the native GeneratorFunction constructor, the best we can
|
|
173
|
-
// do is to check its .name property.
|
|
174
|
-
(ctor.displayName || ctor.name) === "GeneratorFunction"
|
|
175
|
-
: false;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
exports.mark = function(genFun) {
|
|
179
|
-
if (Object.setPrototypeOf) {
|
|
180
|
-
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
|
181
|
-
} else {
|
|
182
|
-
genFun.__proto__ = GeneratorFunctionPrototype;
|
|
183
|
-
define(genFun, toStringTagSymbol, "GeneratorFunction");
|
|
184
|
-
}
|
|
185
|
-
genFun.prototype = Object.create(Gp);
|
|
186
|
-
return genFun;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
// Within the body of any async function, `await x` is transformed to
|
|
190
|
-
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
|
|
191
|
-
// `hasOwn.call(value, "__await")` to determine if the yielded value is
|
|
192
|
-
// meant to be awaited.
|
|
193
|
-
exports.awrap = function(arg) {
|
|
194
|
-
return { __await: arg };
|
|
195
|
-
};
|
|
196
|
-
|
|
197
123
|
function AsyncIterator(generator, PromiseImpl) {
|
|
198
124
|
function invoke(method, arg, resolve, reject) {
|
|
199
125
|
var record = tryCatch(generator[method], generator, arg);
|
|
200
|
-
if (record.type === "throw") {
|
|
201
|
-
reject(record.arg);
|
|
202
|
-
} else {
|
|
203
|
-
var result = record.arg;
|
|
204
|
-
var value = result.value;
|
|
205
|
-
if (value &&
|
|
206
|
-
typeof value === "object" &&
|
|
207
|
-
hasOwn.call(value, "__await")) {
|
|
208
|
-
return PromiseImpl.resolve(value.__await).then(function(value) {
|
|
209
|
-
invoke("next", value, resolve, reject);
|
|
210
|
-
}, function(err) {
|
|
211
|
-
invoke("throw", err, resolve, reject);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
126
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
127
|
+
if ("throw" !== record.type) {
|
|
128
|
+
var result = record.arg,
|
|
129
|
+
value = result.value;
|
|
130
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
131
|
+
invoke("next", value, resolve, reject);
|
|
132
|
+
}, function (err) {
|
|
133
|
+
invoke("throw", err, resolve, reject);
|
|
134
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
135
|
+
result.value = unwrapped, resolve(result);
|
|
136
|
+
}, function (error) {
|
|
224
137
|
return invoke("throw", error, resolve, reject);
|
|
225
138
|
});
|
|
226
139
|
}
|
|
140
|
+
|
|
141
|
+
reject(record.arg);
|
|
227
142
|
}
|
|
228
143
|
|
|
229
144
|
var previousPromise;
|
|
230
145
|
|
|
231
|
-
function
|
|
146
|
+
this._invoke = function (method, arg) {
|
|
232
147
|
function callInvokeWithMethodAndArg() {
|
|
233
|
-
return new PromiseImpl(function(resolve, reject) {
|
|
148
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
234
149
|
invoke(method, arg, resolve, reject);
|
|
235
150
|
});
|
|
236
151
|
}
|
|
237
152
|
|
|
238
|
-
return previousPromise =
|
|
239
|
-
// If enqueue has been called before, then we want to wait until
|
|
240
|
-
// all previous Promises have been resolved before calling invoke,
|
|
241
|
-
// so that results are always delivered in the correct order. If
|
|
242
|
-
// enqueue has not been called before, then it is important to
|
|
243
|
-
// call invoke immediately, without waiting on a callback to fire,
|
|
244
|
-
// so that the async generator function has the opportunity to do
|
|
245
|
-
// any necessary setup in a predictable way. This predictability
|
|
246
|
-
// is why the Promise constructor synchronously invokes its
|
|
247
|
-
// executor callback, and why async functions synchronously
|
|
248
|
-
// execute code before the first await. Since we implement simple
|
|
249
|
-
// async functions in terms of async generators, it is especially
|
|
250
|
-
// important to get this right, even though it requires care.
|
|
251
|
-
previousPromise ? previousPromise.then(
|
|
252
|
-
callInvokeWithMethodAndArg,
|
|
253
|
-
// Avoid propagating failures to Promises returned by later
|
|
254
|
-
// invocations of the iterator.
|
|
255
|
-
callInvokeWithMethodAndArg
|
|
256
|
-
) : callInvokeWithMethodAndArg();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Define the unified helper method that is used to implement .next,
|
|
260
|
-
// .throw, and .return (see defineIteratorMethods).
|
|
261
|
-
this._invoke = enqueue;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
defineIteratorMethods(AsyncIterator.prototype);
|
|
265
|
-
AsyncIterator.prototype[asyncIteratorSymbol] = function () {
|
|
266
|
-
return this;
|
|
267
|
-
};
|
|
268
|
-
exports.AsyncIterator = AsyncIterator;
|
|
269
|
-
|
|
270
|
-
// Note that simple async functions are implemented on top of
|
|
271
|
-
// AsyncIterator objects; they just return a Promise for the value of
|
|
272
|
-
// the final result produced by the iterator.
|
|
273
|
-
exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
274
|
-
if (PromiseImpl === void 0) PromiseImpl = Promise;
|
|
275
|
-
|
|
276
|
-
var iter = new AsyncIterator(
|
|
277
|
-
wrap(innerFn, outerFn, self, tryLocsList),
|
|
278
|
-
PromiseImpl
|
|
279
|
-
);
|
|
280
|
-
|
|
281
|
-
return exports.isGeneratorFunction(outerFn)
|
|
282
|
-
? iter // If outerFn is a generator, return the full iterator.
|
|
283
|
-
: iter.next().then(function(result) {
|
|
284
|
-
return result.done ? result.value : iter.next();
|
|
285
|
-
});
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
289
|
-
var state = GenStateSuspendedStart;
|
|
290
|
-
|
|
291
|
-
return function invoke(method, arg) {
|
|
292
|
-
if (state === GenStateExecuting) {
|
|
293
|
-
throw new Error("Generator is already running");
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (state === GenStateCompleted) {
|
|
297
|
-
if (method === "throw") {
|
|
298
|
-
throw arg;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
// Be forgiving, per 25.3.3.3.3 of the spec:
|
|
302
|
-
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
|
|
303
|
-
return doneResult();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
context.method = method;
|
|
307
|
-
context.arg = arg;
|
|
308
|
-
|
|
309
|
-
while (true) {
|
|
310
|
-
var delegate = context.delegate;
|
|
311
|
-
if (delegate) {
|
|
312
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
313
|
-
if (delegateResult) {
|
|
314
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
315
|
-
return delegateResult;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (context.method === "next") {
|
|
320
|
-
// Setting context._sent for legacy support of Babel's
|
|
321
|
-
// function.sent implementation.
|
|
322
|
-
context.sent = context._sent = context.arg;
|
|
323
|
-
|
|
324
|
-
} else if (context.method === "throw") {
|
|
325
|
-
if (state === GenStateSuspendedStart) {
|
|
326
|
-
state = GenStateCompleted;
|
|
327
|
-
throw context.arg;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
context.dispatchException(context.arg);
|
|
331
|
-
|
|
332
|
-
} else if (context.method === "return") {
|
|
333
|
-
context.abrupt("return", context.arg);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
state = GenStateExecuting;
|
|
337
|
-
|
|
338
|
-
var record = tryCatch(innerFn, self, context);
|
|
339
|
-
if (record.type === "normal") {
|
|
340
|
-
// If an exception is thrown from innerFn, we leave state ===
|
|
341
|
-
// GenStateExecuting and loop back for another invocation.
|
|
342
|
-
state = context.done
|
|
343
|
-
? GenStateCompleted
|
|
344
|
-
: GenStateSuspendedYield;
|
|
345
|
-
|
|
346
|
-
if (record.arg === ContinueSentinel) {
|
|
347
|
-
continue;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
return {
|
|
351
|
-
value: record.arg,
|
|
352
|
-
done: context.done
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
} else if (record.type === "throw") {
|
|
356
|
-
state = GenStateCompleted;
|
|
357
|
-
// Dispatch the exception by looping back around to the
|
|
358
|
-
// context.dispatchException(context.arg) call above.
|
|
359
|
-
context.method = "throw";
|
|
360
|
-
context.arg = record.arg;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
153
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
363
154
|
};
|
|
364
155
|
}
|
|
365
156
|
|
|
366
|
-
// Call delegate.iterator[context.method](context.arg) and handle the
|
|
367
|
-
// result, either by returning a { value, done } result from the
|
|
368
|
-
// delegate iterator, or by modifying context.method and context.arg,
|
|
369
|
-
// setting context.delegate to null, and returning the ContinueSentinel.
|
|
370
157
|
function maybeInvokeDelegate(delegate, context) {
|
|
371
158
|
var method = delegate.iterator[context.method];
|
|
372
|
-
if (method === undefined$1) {
|
|
373
|
-
// A .throw or .return when the delegate iterator has no .throw
|
|
374
|
-
// method always terminates the yield* loop.
|
|
375
|
-
context.delegate = null;
|
|
376
|
-
|
|
377
|
-
if (context.method === "throw") {
|
|
378
|
-
// Note: ["return"] must be used for ES3 parsing compatibility.
|
|
379
|
-
if (delegate.iterator["return"]) {
|
|
380
|
-
// If the delegate iterator has a return method, give it a
|
|
381
|
-
// chance to clean up.
|
|
382
|
-
context.method = "return";
|
|
383
|
-
context.arg = undefined$1;
|
|
384
|
-
maybeInvokeDelegate(delegate, context);
|
|
385
|
-
|
|
386
|
-
if (context.method === "throw") {
|
|
387
|
-
// If maybeInvokeDelegate(context) changed context.method from
|
|
388
|
-
// "return" to "throw", let that override the TypeError below.
|
|
389
|
-
return ContinueSentinel;
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
159
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
160
|
+
if (undefined === method) {
|
|
161
|
+
if (context.delegate = null, "throw" === context.method) {
|
|
162
|
+
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
|
|
163
|
+
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
|
|
396
164
|
}
|
|
397
165
|
|
|
398
166
|
return ContinueSentinel;
|
|
399
167
|
}
|
|
400
168
|
|
|
401
169
|
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
402
|
-
|
|
403
|
-
if (record.type === "throw") {
|
|
404
|
-
context.method = "throw";
|
|
405
|
-
context.arg = record.arg;
|
|
406
|
-
context.delegate = null;
|
|
407
|
-
return ContinueSentinel;
|
|
408
|
-
}
|
|
409
|
-
|
|
170
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
410
171
|
var info = record.arg;
|
|
411
|
-
|
|
412
|
-
if (! info) {
|
|
413
|
-
context.method = "throw";
|
|
414
|
-
context.arg = new TypeError("iterator result is not an object");
|
|
415
|
-
context.delegate = null;
|
|
416
|
-
return ContinueSentinel;
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (info.done) {
|
|
420
|
-
// Assign the result of the finished delegate to the temporary
|
|
421
|
-
// variable specified by delegate.resultName (see delegateYield).
|
|
422
|
-
context[delegate.resultName] = info.value;
|
|
423
|
-
|
|
424
|
-
// Resume execution at the desired location (see delegateYield).
|
|
425
|
-
context.next = delegate.nextLoc;
|
|
426
|
-
|
|
427
|
-
// If context.method was "throw" but the delegate handled the
|
|
428
|
-
// exception, let the outer generator proceed normally. If
|
|
429
|
-
// context.method was "next", forget context.arg since it has been
|
|
430
|
-
// "consumed" by the delegate iterator. If context.method was
|
|
431
|
-
// "return", allow the original .return call to continue in the
|
|
432
|
-
// outer generator.
|
|
433
|
-
if (context.method !== "return") {
|
|
434
|
-
context.method = "next";
|
|
435
|
-
context.arg = undefined$1;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
} else {
|
|
439
|
-
// Re-yield the result returned by the delegate method.
|
|
440
|
-
return info;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// The delegate iterator is finished, so forget it and continue with
|
|
444
|
-
// the outer generator.
|
|
445
|
-
context.delegate = null;
|
|
446
|
-
return ContinueSentinel;
|
|
172
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
447
173
|
}
|
|
448
174
|
|
|
449
|
-
// Define Generator.prototype.{next,throw,return} in terms of the
|
|
450
|
-
// unified ._invoke helper method.
|
|
451
|
-
defineIteratorMethods(Gp);
|
|
452
|
-
|
|
453
|
-
define(Gp, toStringTagSymbol, "Generator");
|
|
454
|
-
|
|
455
|
-
// A Generator should always return itself as the iterator object when the
|
|
456
|
-
// @@iterator function is called on it. Some browsers' implementations of the
|
|
457
|
-
// iterator prototype chain incorrectly implement this, causing the Generator
|
|
458
|
-
// object to not be returned from this call. This ensures that doesn't happen.
|
|
459
|
-
// See https://github.com/facebook/regenerator/issues/274 for more details.
|
|
460
|
-
Gp[iteratorSymbol] = function() {
|
|
461
|
-
return this;
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
Gp.toString = function() {
|
|
465
|
-
return "[object Generator]";
|
|
466
|
-
};
|
|
467
|
-
|
|
468
175
|
function pushTryEntry(locs) {
|
|
469
|
-
var entry = {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (2 in locs) {
|
|
476
|
-
entry.finallyLoc = locs[2];
|
|
477
|
-
entry.afterLoc = locs[3];
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
this.tryEntries.push(entry);
|
|
176
|
+
var entry = {
|
|
177
|
+
tryLoc: locs[0]
|
|
178
|
+
};
|
|
179
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
481
180
|
}
|
|
482
181
|
|
|
483
182
|
function resetTryEntry(entry) {
|
|
484
183
|
var record = entry.completion || {};
|
|
485
|
-
record.type = "normal";
|
|
486
|
-
delete record.arg;
|
|
487
|
-
entry.completion = record;
|
|
184
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
488
185
|
}
|
|
489
186
|
|
|
490
187
|
function Context(tryLocsList) {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
this.tryEntries = [{ tryLoc: "root" }];
|
|
495
|
-
tryLocsList.forEach(pushTryEntry, this);
|
|
496
|
-
this.reset(true);
|
|
188
|
+
this.tryEntries = [{
|
|
189
|
+
tryLoc: "root"
|
|
190
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
497
191
|
}
|
|
498
192
|
|
|
499
|
-
exports.keys = function(object) {
|
|
500
|
-
var keys = [];
|
|
501
|
-
for (var key in object) {
|
|
502
|
-
keys.push(key);
|
|
503
|
-
}
|
|
504
|
-
keys.reverse();
|
|
505
|
-
|
|
506
|
-
// Rather than returning an object with a next method, we keep
|
|
507
|
-
// things simple and return the next function itself.
|
|
508
|
-
return function next() {
|
|
509
|
-
while (keys.length) {
|
|
510
|
-
var key = keys.pop();
|
|
511
|
-
if (key in object) {
|
|
512
|
-
next.value = key;
|
|
513
|
-
next.done = false;
|
|
514
|
-
return next;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// To avoid creating an additional object, we just hang the .value
|
|
519
|
-
// and .done properties off the next function object itself. This
|
|
520
|
-
// also ensures that the minifier will not anonymize the function.
|
|
521
|
-
next.done = true;
|
|
522
|
-
return next;
|
|
523
|
-
};
|
|
524
|
-
};
|
|
525
|
-
|
|
526
193
|
function values(iterable) {
|
|
527
194
|
if (iterable) {
|
|
528
195
|
var iteratorMethod = iterable[iteratorSymbol];
|
|
529
|
-
if (iteratorMethod)
|
|
530
|
-
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
if (typeof iterable.next === "function") {
|
|
534
|
-
return iterable;
|
|
535
|
-
}
|
|
196
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
197
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
536
198
|
|
|
537
199
|
if (!isNaN(iterable.length)) {
|
|
538
|
-
var i = -1,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
next.value = iterable[i];
|
|
542
|
-
next.done = false;
|
|
543
|
-
return next;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
200
|
+
var i = -1,
|
|
201
|
+
next = function next() {
|
|
202
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
546
203
|
|
|
547
|
-
next.value = undefined
|
|
548
|
-
next.done = true;
|
|
549
|
-
|
|
550
|
-
return next;
|
|
204
|
+
return next.value = undefined, next.done = !0, next;
|
|
551
205
|
};
|
|
552
206
|
|
|
553
207
|
return next.next = next;
|
|
554
208
|
}
|
|
555
209
|
}
|
|
556
210
|
|
|
557
|
-
|
|
558
|
-
|
|
211
|
+
return {
|
|
212
|
+
next: doneResult
|
|
213
|
+
};
|
|
559
214
|
}
|
|
560
|
-
exports.values = values;
|
|
561
215
|
|
|
562
216
|
function doneResult() {
|
|
563
|
-
return {
|
|
217
|
+
return {
|
|
218
|
+
value: undefined,
|
|
219
|
+
done: !0
|
|
220
|
+
};
|
|
564
221
|
}
|
|
565
222
|
|
|
566
|
-
|
|
567
|
-
constructor
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
this[name] = undefined$1;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
},
|
|
223
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
224
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
225
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
226
|
+
}, exports.mark = function (genFun) {
|
|
227
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
228
|
+
}, exports.awrap = function (arg) {
|
|
229
|
+
return {
|
|
230
|
+
__await: arg
|
|
231
|
+
};
|
|
232
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
233
|
+
return this;
|
|
234
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
235
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
236
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
237
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
238
|
+
return result.done ? result.value : iter.next();
|
|
239
|
+
});
|
|
240
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
241
|
+
return this;
|
|
242
|
+
}), define(Gp, "toString", function () {
|
|
243
|
+
return "[object Generator]";
|
|
244
|
+
}), exports.keys = function (object) {
|
|
245
|
+
var keys = [];
|
|
594
246
|
|
|
595
|
-
|
|
596
|
-
this.done = true;
|
|
247
|
+
for (var key in object) keys.push(key);
|
|
597
248
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
249
|
+
return keys.reverse(), function next() {
|
|
250
|
+
for (; keys.length;) {
|
|
251
|
+
var key = keys.pop();
|
|
252
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
602
253
|
}
|
|
603
254
|
|
|
255
|
+
return next.done = !0, next;
|
|
256
|
+
};
|
|
257
|
+
}, exports.values = values, Context.prototype = {
|
|
258
|
+
constructor: Context,
|
|
259
|
+
reset: function (skipTempReset) {
|
|
260
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
261
|
+
},
|
|
262
|
+
stop: function () {
|
|
263
|
+
this.done = !0;
|
|
264
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
265
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
604
266
|
return this.rval;
|
|
605
267
|
},
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (this.done) {
|
|
609
|
-
throw exception;
|
|
610
|
-
}
|
|
611
|
-
|
|
268
|
+
dispatchException: function (exception) {
|
|
269
|
+
if (this.done) throw exception;
|
|
612
270
|
var context = this;
|
|
613
|
-
function handle(loc, caught) {
|
|
614
|
-
record.type = "throw";
|
|
615
|
-
record.arg = exception;
|
|
616
|
-
context.next = loc;
|
|
617
|
-
|
|
618
|
-
if (caught) {
|
|
619
|
-
// If the dispatched exception was caught by a catch block,
|
|
620
|
-
// then let that catch block handle the exception normally.
|
|
621
|
-
context.method = "next";
|
|
622
|
-
context.arg = undefined$1;
|
|
623
|
-
}
|
|
624
271
|
|
|
625
|
-
|
|
272
|
+
function handle(loc, caught) {
|
|
273
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
626
274
|
}
|
|
627
275
|
|
|
628
276
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
629
|
-
var entry = this.tryEntries[i]
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
if (entry.tryLoc === "root") {
|
|
633
|
-
// Exception thrown outside of any try block that could handle
|
|
634
|
-
// it, so set the completion value of the entire function to
|
|
635
|
-
// throw the exception.
|
|
636
|
-
return handle("end");
|
|
637
|
-
}
|
|
277
|
+
var entry = this.tryEntries[i],
|
|
278
|
+
record = entry.completion;
|
|
279
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
638
280
|
|
|
639
281
|
if (entry.tryLoc <= this.prev) {
|
|
640
|
-
var hasCatch = hasOwn.call(entry, "catchLoc")
|
|
641
|
-
|
|
282
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
283
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
642
284
|
|
|
643
285
|
if (hasCatch && hasFinally) {
|
|
644
|
-
if (this.prev < entry.catchLoc)
|
|
645
|
-
|
|
646
|
-
} else if (this.prev < entry.finallyLoc) {
|
|
647
|
-
return handle(entry.finallyLoc);
|
|
648
|
-
}
|
|
649
|
-
|
|
286
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
287
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
650
288
|
} else if (hasCatch) {
|
|
651
|
-
if (this.prev < entry.catchLoc)
|
|
652
|
-
return handle(entry.catchLoc, true);
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
} else if (hasFinally) {
|
|
656
|
-
if (this.prev < entry.finallyLoc) {
|
|
657
|
-
return handle(entry.finallyLoc);
|
|
658
|
-
}
|
|
659
|
-
|
|
289
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
660
290
|
} else {
|
|
661
|
-
throw new Error("try statement without catch or finally");
|
|
291
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
292
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
662
293
|
}
|
|
663
294
|
}
|
|
664
295
|
}
|
|
665
296
|
},
|
|
666
|
-
|
|
667
|
-
abrupt: function(type, arg) {
|
|
297
|
+
abrupt: function (type, arg) {
|
|
668
298
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
669
299
|
var entry = this.tryEntries[i];
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
this.prev < entry.finallyLoc) {
|
|
300
|
+
|
|
301
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
673
302
|
var finallyEntry = entry;
|
|
674
303
|
break;
|
|
675
304
|
}
|
|
676
305
|
}
|
|
677
306
|
|
|
678
|
-
|
|
679
|
-
(type === "break" ||
|
|
680
|
-
type === "continue") &&
|
|
681
|
-
finallyEntry.tryLoc <= arg &&
|
|
682
|
-
arg <= finallyEntry.finallyLoc) {
|
|
683
|
-
// Ignore the finally entry if control is not jumping to a
|
|
684
|
-
// location outside the try/catch block.
|
|
685
|
-
finallyEntry = null;
|
|
686
|
-
}
|
|
687
|
-
|
|
307
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
688
308
|
var record = finallyEntry ? finallyEntry.completion : {};
|
|
689
|
-
record.type = type;
|
|
690
|
-
record.arg = arg;
|
|
691
|
-
|
|
692
|
-
if (finallyEntry) {
|
|
693
|
-
this.method = "next";
|
|
694
|
-
this.next = finallyEntry.finallyLoc;
|
|
695
|
-
return ContinueSentinel;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
return this.complete(record);
|
|
309
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
699
310
|
},
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
throw record.arg;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
if (record.type === "break" ||
|
|
707
|
-
record.type === "continue") {
|
|
708
|
-
this.next = record.arg;
|
|
709
|
-
} else if (record.type === "return") {
|
|
710
|
-
this.rval = this.arg = record.arg;
|
|
711
|
-
this.method = "return";
|
|
712
|
-
this.next = "end";
|
|
713
|
-
} else if (record.type === "normal" && afterLoc) {
|
|
714
|
-
this.next = afterLoc;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
return ContinueSentinel;
|
|
311
|
+
complete: function (record, afterLoc) {
|
|
312
|
+
if ("throw" === record.type) throw record.arg;
|
|
313
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
718
314
|
},
|
|
719
|
-
|
|
720
|
-
finish: function(finallyLoc) {
|
|
315
|
+
finish: function (finallyLoc) {
|
|
721
316
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
722
317
|
var entry = this.tryEntries[i];
|
|
723
|
-
if (entry.finallyLoc === finallyLoc)
|
|
724
|
-
this.complete(entry.completion, entry.afterLoc);
|
|
725
|
-
resetTryEntry(entry);
|
|
726
|
-
return ContinueSentinel;
|
|
727
|
-
}
|
|
318
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
728
319
|
}
|
|
729
320
|
},
|
|
730
|
-
|
|
731
|
-
"catch": function(tryLoc) {
|
|
321
|
+
catch: function (tryLoc) {
|
|
732
322
|
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
733
323
|
var entry = this.tryEntries[i];
|
|
324
|
+
|
|
734
325
|
if (entry.tryLoc === tryLoc) {
|
|
735
326
|
var record = entry.completion;
|
|
736
|
-
|
|
327
|
+
|
|
328
|
+
if ("throw" === record.type) {
|
|
737
329
|
var thrown = record.arg;
|
|
738
330
|
resetTryEntry(entry);
|
|
739
331
|
}
|
|
332
|
+
|
|
740
333
|
return thrown;
|
|
741
334
|
}
|
|
742
335
|
}
|
|
743
336
|
|
|
744
|
-
// The context.catch method must only be called with a location
|
|
745
|
-
// argument that corresponds to a known catch block.
|
|
746
337
|
throw new Error("illegal catch attempt");
|
|
747
338
|
},
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
this.delegate = {
|
|
339
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
|
340
|
+
return this.delegate = {
|
|
751
341
|
iterator: values(iterable),
|
|
752
342
|
resultName: resultName,
|
|
753
343
|
nextLoc: nextLoc
|
|
754
|
-
};
|
|
344
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
345
|
+
}
|
|
346
|
+
}, exports;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
350
|
+
try {
|
|
351
|
+
var info = gen[key](arg);
|
|
352
|
+
var value = info.value;
|
|
353
|
+
} catch (error) {
|
|
354
|
+
reject(error);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (info.done) {
|
|
359
|
+
resolve(value);
|
|
360
|
+
} else {
|
|
361
|
+
Promise.resolve(value).then(_next, _throw);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function _asyncToGenerator(fn) {
|
|
366
|
+
return function () {
|
|
367
|
+
var self = this,
|
|
368
|
+
args = arguments;
|
|
369
|
+
return new Promise(function (resolve, reject) {
|
|
370
|
+
var gen = fn.apply(self, args);
|
|
755
371
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
// accidentally pass it on to the delegate.
|
|
759
|
-
this.arg = undefined$1;
|
|
372
|
+
function _next(value) {
|
|
373
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
760
374
|
}
|
|
761
375
|
|
|
762
|
-
|
|
763
|
-
|
|
376
|
+
function _throw(err) {
|
|
377
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
_next(undefined);
|
|
381
|
+
});
|
|
764
382
|
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function _extends() {
|
|
386
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
387
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
388
|
+
var source = arguments[i];
|
|
389
|
+
|
|
390
|
+
for (var key in source) {
|
|
391
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
392
|
+
target[key] = source[key];
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
765
396
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
// injected easily by `bin/regenerator --include-runtime script.js`.
|
|
770
|
-
return exports;
|
|
771
|
-
|
|
772
|
-
}(
|
|
773
|
-
// If this script is executing as a CommonJS module, use module.exports
|
|
774
|
-
// as the regeneratorRuntime namespace. Otherwise create a new empty
|
|
775
|
-
// object. Either way, the resulting object will be used to initialize
|
|
776
|
-
// the regeneratorRuntime variable at the top of this file.
|
|
777
|
-
module.exports
|
|
778
|
-
));
|
|
779
|
-
|
|
780
|
-
try {
|
|
781
|
-
regeneratorRuntime = runtime;
|
|
782
|
-
} catch (accidentalStrictMode) {
|
|
783
|
-
// This module should not be running in strict mode, so the above
|
|
784
|
-
// assignment should always work unless something is misconfigured. Just
|
|
785
|
-
// in case runtime.js accidentally runs in strict mode, we can escape
|
|
786
|
-
// strict mode using a global Function call. This could conceivably fail
|
|
787
|
-
// if a Content Security Policy forbids using Function, but in that case
|
|
788
|
-
// the proper solution is to fix the accidental strict mode problem. If
|
|
789
|
-
// you've misconfigured your bundler to force strict mode and applied a
|
|
790
|
-
// CSP to forbid Function, and you're not willing to fix either of those
|
|
791
|
-
// problems, please detail your unique predicament in a GitHub issue.
|
|
792
|
-
Function("r", "regeneratorRuntime = r")(runtime);
|
|
397
|
+
return target;
|
|
398
|
+
};
|
|
399
|
+
return _extends.apply(this, arguments);
|
|
793
400
|
}
|
|
794
|
-
});
|
|
795
401
|
|
|
796
402
|
var baseTransifexUrl = 'https://rest.api.transifex.com';
|
|
797
|
-
|
|
798
403
|
var getHeaders = function getHeaders(secrets) {
|
|
799
404
|
return {
|
|
800
405
|
Authorization: "Bearer " + (secrets == null ? void 0 : secrets.token),
|
|
801
406
|
'Content-Type': 'application/vnd.api+json'
|
|
802
407
|
};
|
|
803
408
|
};
|
|
804
|
-
|
|
805
409
|
var projOrgSlug = function projOrgSlug(secrets) {
|
|
806
410
|
return "o:" + (secrets == null ? void 0 : secrets.organization) + ":p:" + (secrets == null ? void 0 : secrets.project);
|
|
807
411
|
};
|
|
808
412
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
413
|
+
function getLocales(_x) {
|
|
414
|
+
return _getLocales.apply(this, arguments);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function _getLocales() {
|
|
418
|
+
_getLocales = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(secrets) {
|
|
419
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
812
420
|
while (1) {
|
|
813
421
|
switch (_context.prev = _context.next) {
|
|
814
422
|
case 0:
|
|
@@ -841,25 +449,26 @@ var getLocales = /*#__PURE__*/function () {
|
|
|
841
449
|
}
|
|
842
450
|
}, _callee);
|
|
843
451
|
}));
|
|
452
|
+
return _getLocales.apply(this, arguments);
|
|
453
|
+
}
|
|
844
454
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
}();
|
|
455
|
+
function getTranslationTask(_x, _x2) {
|
|
456
|
+
return _getTranslationTask.apply(this, arguments);
|
|
457
|
+
}
|
|
849
458
|
|
|
850
|
-
|
|
851
|
-
|
|
459
|
+
function _getTranslationTask() {
|
|
460
|
+
_getTranslationTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(documentId, secrets) {
|
|
852
461
|
var projectFilter, resourceFilter, task, locales, localeIds, validLocales;
|
|
853
|
-
return
|
|
462
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
854
463
|
while (1) {
|
|
855
|
-
switch (
|
|
464
|
+
switch (_context.prev = _context.next) {
|
|
856
465
|
case 0:
|
|
857
466
|
if (!(!documentId || !secrets)) {
|
|
858
|
-
|
|
467
|
+
_context.next = 2;
|
|
859
468
|
break;
|
|
860
469
|
}
|
|
861
470
|
|
|
862
|
-
return
|
|
471
|
+
return _context.abrupt("return", {
|
|
863
472
|
taskId: documentId,
|
|
864
473
|
documentId: documentId,
|
|
865
474
|
locales: []
|
|
@@ -868,21 +477,20 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
868
477
|
case 2:
|
|
869
478
|
projectFilter = "filter[project]=" + projOrgSlug(secrets);
|
|
870
479
|
resourceFilter = "filter[resource]=" + projOrgSlug(secrets) + ":r:" + documentId;
|
|
871
|
-
|
|
480
|
+
_context.next = 6;
|
|
872
481
|
return fetch(baseTransifexUrl + "/resource_language_stats?" + projectFilter + "&" + resourceFilter, {
|
|
873
482
|
headers: getHeaders(secrets)
|
|
874
483
|
}).then(function (res) {
|
|
875
484
|
if (res.ok) {
|
|
876
485
|
return res.json();
|
|
877
486
|
} //normal -- just means that this task doesn't exist yet.
|
|
878
|
-
else
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
}
|
|
487
|
+
else if (res.status === 404) {
|
|
488
|
+
return {
|
|
489
|
+
data: []
|
|
490
|
+
};
|
|
491
|
+
} else {
|
|
492
|
+
throw Error("Failed to retrieve tasks from Transifex. Status: " + res.status);
|
|
493
|
+
}
|
|
886
494
|
}).then(function (res) {
|
|
887
495
|
return {
|
|
888
496
|
taskId: projOrgSlug(secrets) + ":r:" + documentId,
|
|
@@ -897,12 +505,12 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
897
505
|
});
|
|
898
506
|
|
|
899
507
|
case 6:
|
|
900
|
-
task =
|
|
901
|
-
|
|
508
|
+
task = _context.sent;
|
|
509
|
+
_context.next = 9;
|
|
902
510
|
return getLocales(secrets);
|
|
903
511
|
|
|
904
512
|
case 9:
|
|
905
|
-
locales =
|
|
513
|
+
locales = _context.sent;
|
|
906
514
|
localeIds = locales.map(function (l) {
|
|
907
515
|
return l.localeId;
|
|
908
516
|
});
|
|
@@ -912,9 +520,170 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
912
520
|
});
|
|
913
521
|
});
|
|
914
522
|
task.locales = validLocales;
|
|
915
|
-
return
|
|
523
|
+
return _context.abrupt("return", task);
|
|
916
524
|
|
|
917
525
|
case 14:
|
|
526
|
+
case "end":
|
|
527
|
+
return _context.stop();
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}, _callee);
|
|
531
|
+
}));
|
|
532
|
+
return _getTranslationTask.apply(this, arguments);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function getTranslation(_x, _x2, _x3) {
|
|
536
|
+
return _getTranslation.apply(this, arguments);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function _getTranslation() {
|
|
540
|
+
_getTranslation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(taskId, localeId, secrets) {
|
|
541
|
+
var resourceDownloadBody, resourceDownloadUrl, translationDownloadId, headers, location;
|
|
542
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
543
|
+
while (1) {
|
|
544
|
+
switch (_context3.prev = _context3.next) {
|
|
545
|
+
case 0:
|
|
546
|
+
resourceDownloadBody = {
|
|
547
|
+
data: {
|
|
548
|
+
attributes: {
|
|
549
|
+
content_encoding: 'text'
|
|
550
|
+
},
|
|
551
|
+
relationships: {
|
|
552
|
+
language: {
|
|
553
|
+
data: {
|
|
554
|
+
id: "l:" + localeId,
|
|
555
|
+
type: 'languages'
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
resource: {
|
|
559
|
+
data: {
|
|
560
|
+
id: taskId,
|
|
561
|
+
type: 'resources'
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
},
|
|
565
|
+
type: 'resource_translations_async_downloads'
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
resourceDownloadUrl = baseTransifexUrl + "/resource_translations_async_downloads";
|
|
569
|
+
_context3.next = 4;
|
|
570
|
+
return fetch(resourceDownloadUrl, {
|
|
571
|
+
headers: getHeaders(secrets),
|
|
572
|
+
method: 'POST',
|
|
573
|
+
body: JSON.stringify(resourceDownloadBody)
|
|
574
|
+
}).then(function (res) {
|
|
575
|
+
return res.json();
|
|
576
|
+
}).then(function (res) {
|
|
577
|
+
return res.data.id;
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
case 4:
|
|
581
|
+
translationDownloadId = _context3.sent;
|
|
582
|
+
headers = getHeaders(secrets);
|
|
583
|
+
_context3.next = 8;
|
|
584
|
+
return pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers);
|
|
585
|
+
|
|
586
|
+
case 8:
|
|
587
|
+
location = _context3.sent;
|
|
588
|
+
return _context3.abrupt("return", handleFileDownload(location));
|
|
589
|
+
|
|
590
|
+
case 10:
|
|
591
|
+
case "end":
|
|
592
|
+
return _context3.stop();
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}, _callee3);
|
|
596
|
+
}));
|
|
597
|
+
return _getTranslation.apply(this, arguments);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
var pollForFileDownloadLocation = /*#__PURE__*/function () {
|
|
601
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(resourceDownloadUrl, translationDownloadId, headers) {
|
|
602
|
+
var response;
|
|
603
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
604
|
+
while (1) {
|
|
605
|
+
switch (_context.prev = _context.next) {
|
|
606
|
+
case 0:
|
|
607
|
+
_context.next = 2;
|
|
608
|
+
return fetch(resourceDownloadUrl + "/" + translationDownloadId, {
|
|
609
|
+
headers: headers
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
case 2:
|
|
613
|
+
response = _context.sent;
|
|
614
|
+
|
|
615
|
+
if (!(response.status === 500)) {
|
|
616
|
+
_context.next = 10;
|
|
617
|
+
break;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
console.info("Transifex plugin message: Received 500 for translation download ID " + translationDownloadId + ". Trying to reconnect...");
|
|
621
|
+
_context.next = 7;
|
|
622
|
+
return new Promise(function (resolve) {
|
|
623
|
+
return setTimeout(resolve, 3000);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
case 7:
|
|
627
|
+
return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
|
|
628
|
+
|
|
629
|
+
case 10:
|
|
630
|
+
if (!response.redirected) {
|
|
631
|
+
_context.next = 15;
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
console.info("Transifex plugin message: Received redirect for translation download ID " + translationDownloadId + ". Following redirect now for file download.");
|
|
636
|
+
return _context.abrupt("return", response.url);
|
|
637
|
+
|
|
638
|
+
case 15:
|
|
639
|
+
if (!(response.status === 200)) {
|
|
640
|
+
_context.next = 22;
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
console.info("Transifex plugin message: Requested download location for translation download ID " + translationDownloadId + ". Location is still pending, trying again.");
|
|
645
|
+
_context.next = 19;
|
|
646
|
+
return new Promise(function (resolve) {
|
|
647
|
+
return setTimeout(resolve, 3000);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
case 19:
|
|
651
|
+
return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
|
|
652
|
+
|
|
653
|
+
case 22:
|
|
654
|
+
console.info("Transifex plugin message: Requested download location for translation download ID " + translationDownloadId + " but received error code " + response.status + ". Waiting and trying again.");
|
|
655
|
+
_context.next = 25;
|
|
656
|
+
return new Promise(function (resolve) {
|
|
657
|
+
return setTimeout(resolve, 3000);
|
|
658
|
+
});
|
|
659
|
+
|
|
660
|
+
case 25:
|
|
661
|
+
return _context.abrupt("return", pollForFileDownloadLocation(resourceDownloadUrl, translationDownloadId, headers));
|
|
662
|
+
|
|
663
|
+
case 26:
|
|
664
|
+
case "end":
|
|
665
|
+
return _context.stop();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}, _callee);
|
|
669
|
+
}));
|
|
670
|
+
|
|
671
|
+
return function pollForFileDownloadLocation(_x4, _x5, _x6) {
|
|
672
|
+
return _ref.apply(this, arguments);
|
|
673
|
+
};
|
|
674
|
+
}();
|
|
675
|
+
|
|
676
|
+
var handleFileDownload = /*#__PURE__*/function () {
|
|
677
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url) {
|
|
678
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
679
|
+
while (1) {
|
|
680
|
+
switch (_context2.prev = _context2.next) {
|
|
681
|
+
case 0:
|
|
682
|
+
return _context2.abrupt("return", fetch(url).then(function (res) {
|
|
683
|
+
return res.text();
|
|
684
|
+
}));
|
|
685
|
+
|
|
686
|
+
case 1:
|
|
918
687
|
case "end":
|
|
919
688
|
return _context2.stop();
|
|
920
689
|
}
|
|
@@ -922,17 +691,17 @@ var getTranslationTask = /*#__PURE__*/function () {
|
|
|
922
691
|
}, _callee2);
|
|
923
692
|
}));
|
|
924
693
|
|
|
925
|
-
return function
|
|
694
|
+
return function handleFileDownload(_x7) {
|
|
926
695
|
return _ref2.apply(this, arguments);
|
|
927
696
|
};
|
|
928
697
|
}();
|
|
929
698
|
|
|
930
699
|
var createResource = /*#__PURE__*/function () {
|
|
931
|
-
var
|
|
700
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(doc, documentId, secrets) {
|
|
932
701
|
var resourceCreateBody;
|
|
933
|
-
return
|
|
702
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
934
703
|
while (1) {
|
|
935
|
-
switch (
|
|
704
|
+
switch (_context.prev = _context.next) {
|
|
936
705
|
case 0:
|
|
937
706
|
resourceCreateBody = {
|
|
938
707
|
data: {
|
|
@@ -958,7 +727,7 @@ var createResource = /*#__PURE__*/function () {
|
|
|
958
727
|
type: 'resources'
|
|
959
728
|
}
|
|
960
729
|
};
|
|
961
|
-
return
|
|
730
|
+
return _context.abrupt("return", fetch(baseTransifexUrl + "/resources", {
|
|
962
731
|
headers: getHeaders(secrets),
|
|
963
732
|
method: 'POST',
|
|
964
733
|
body: JSON.stringify(resourceCreateBody)
|
|
@@ -970,27 +739,31 @@ var createResource = /*#__PURE__*/function () {
|
|
|
970
739
|
|
|
971
740
|
case 2:
|
|
972
741
|
case "end":
|
|
973
|
-
return
|
|
742
|
+
return _context.stop();
|
|
974
743
|
}
|
|
975
744
|
}
|
|
976
|
-
},
|
|
745
|
+
}, _callee);
|
|
977
746
|
}));
|
|
978
747
|
|
|
979
|
-
return function createResource(
|
|
980
|
-
return
|
|
748
|
+
return function createResource(_x, _x2, _x3) {
|
|
749
|
+
return _ref.apply(this, arguments);
|
|
981
750
|
};
|
|
982
751
|
}();
|
|
983
752
|
|
|
984
|
-
|
|
985
|
-
|
|
753
|
+
function createTask(_x4, _x5, _x6, _x7) {
|
|
754
|
+
return _createTask.apply(this, arguments);
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function _createTask() {
|
|
758
|
+
_createTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(documentId, document, //unfortunately Transifex doesn't let you specify locales on creating a task
|
|
986
759
|
//@ts-ignore
|
|
987
760
|
localeIds, secrets) {
|
|
988
761
|
var resourceId, resourceUploadUrl, resourceUploadBody;
|
|
989
|
-
return
|
|
762
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
990
763
|
while (1) {
|
|
991
|
-
switch (
|
|
764
|
+
switch (_context2.prev = _context2.next) {
|
|
992
765
|
case 0:
|
|
993
|
-
|
|
766
|
+
_context2.next = 2;
|
|
994
767
|
return fetch(baseTransifexUrl + "/resources/" + projOrgSlug(secrets) + ":r:" + documentId, {
|
|
995
768
|
headers: getHeaders(secrets)
|
|
996
769
|
}).then(function (res) {
|
|
@@ -1000,18 +773,18 @@ var createTask = /*#__PURE__*/function () {
|
|
|
1000
773
|
});
|
|
1001
774
|
|
|
1002
775
|
case 2:
|
|
1003
|
-
resourceId =
|
|
776
|
+
resourceId = _context2.sent;
|
|
1004
777
|
|
|
1005
778
|
if (resourceId) {
|
|
1006
|
-
|
|
779
|
+
_context2.next = 7;
|
|
1007
780
|
break;
|
|
1008
781
|
}
|
|
1009
782
|
|
|
1010
|
-
|
|
783
|
+
_context2.next = 6;
|
|
1011
784
|
return createResource(document, documentId, secrets);
|
|
1012
785
|
|
|
1013
786
|
case 6:
|
|
1014
|
-
resourceId =
|
|
787
|
+
resourceId = _context2.sent;
|
|
1015
788
|
|
|
1016
789
|
case 7:
|
|
1017
790
|
resourceUploadUrl = baseTransifexUrl + "/resource_strings_async_uploads";
|
|
@@ -1032,7 +805,7 @@ var createTask = /*#__PURE__*/function () {
|
|
|
1032
805
|
type: 'resource_strings_async_uploads'
|
|
1033
806
|
}
|
|
1034
807
|
};
|
|
1035
|
-
return
|
|
808
|
+
return _context2.abrupt("return", fetch(resourceUploadUrl, {
|
|
1036
809
|
method: 'POST',
|
|
1037
810
|
body: JSON.stringify(resourceUploadBody),
|
|
1038
811
|
headers: getHeaders(secrets)
|
|
@@ -1042,109 +815,13 @@ var createTask = /*#__PURE__*/function () {
|
|
|
1042
815
|
|
|
1043
816
|
case 10:
|
|
1044
817
|
case "end":
|
|
1045
|
-
return
|
|
1046
|
-
}
|
|
1047
|
-
}
|
|
1048
|
-
}, _callee4);
|
|
1049
|
-
}));
|
|
1050
|
-
|
|
1051
|
-
return function createTask(_x7, _x8, _x9, _x10) {
|
|
1052
|
-
return _ref4.apply(this, arguments);
|
|
1053
|
-
};
|
|
1054
|
-
}();
|
|
1055
|
-
|
|
1056
|
-
var getTranslation = /*#__PURE__*/function () {
|
|
1057
|
-
var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(taskId, localeId, secrets) {
|
|
1058
|
-
var resourceDownloadBody, resourceDownloadUrl, translationDownloadId;
|
|
1059
|
-
return runtime_1.wrap(function _callee5$(_context5) {
|
|
1060
|
-
while (1) {
|
|
1061
|
-
switch (_context5.prev = _context5.next) {
|
|
1062
|
-
case 0:
|
|
1063
|
-
resourceDownloadBody = {
|
|
1064
|
-
data: {
|
|
1065
|
-
attributes: {
|
|
1066
|
-
content_encoding: 'text'
|
|
1067
|
-
},
|
|
1068
|
-
relationships: {
|
|
1069
|
-
language: {
|
|
1070
|
-
data: {
|
|
1071
|
-
id: "l:" + localeId,
|
|
1072
|
-
type: 'languages'
|
|
1073
|
-
}
|
|
1074
|
-
},
|
|
1075
|
-
resource: {
|
|
1076
|
-
data: {
|
|
1077
|
-
id: taskId,
|
|
1078
|
-
type: 'resources'
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
},
|
|
1082
|
-
type: 'resource_translations_async_downloads'
|
|
1083
|
-
}
|
|
1084
|
-
};
|
|
1085
|
-
resourceDownloadUrl = baseTransifexUrl + "/resource_translations_async_downloads";
|
|
1086
|
-
_context5.next = 4;
|
|
1087
|
-
return fetch(resourceDownloadUrl, {
|
|
1088
|
-
headers: getHeaders(secrets),
|
|
1089
|
-
method: 'POST',
|
|
1090
|
-
body: JSON.stringify(resourceDownloadBody)
|
|
1091
|
-
}).then(function (res) {
|
|
1092
|
-
return res.json();
|
|
1093
|
-
}).then(function (res) {
|
|
1094
|
-
return res.data.id;
|
|
1095
|
-
});
|
|
1096
|
-
|
|
1097
|
-
case 4:
|
|
1098
|
-
translationDownloadId = _context5.sent;
|
|
1099
|
-
return _context5.abrupt("return", new Promise(function (resolve) {
|
|
1100
|
-
setTimeout(function () {
|
|
1101
|
-
fetch(resourceDownloadUrl + "/" + translationDownloadId, {
|
|
1102
|
-
headers: getHeaders(secrets)
|
|
1103
|
-
}).then(function (res) {
|
|
1104
|
-
if (res.redirected) {
|
|
1105
|
-
return resolve(handleFileDownload(res.url));
|
|
1106
|
-
} else {
|
|
1107
|
-
return res.json();
|
|
1108
|
-
}
|
|
1109
|
-
});
|
|
1110
|
-
}, 3000);
|
|
1111
|
-
}));
|
|
1112
|
-
|
|
1113
|
-
case 6:
|
|
1114
|
-
case "end":
|
|
1115
|
-
return _context5.stop();
|
|
1116
|
-
}
|
|
1117
|
-
}
|
|
1118
|
-
}, _callee5);
|
|
1119
|
-
}));
|
|
1120
|
-
|
|
1121
|
-
return function getTranslation(_x11, _x12, _x13) {
|
|
1122
|
-
return _ref5.apply(this, arguments);
|
|
1123
|
-
};
|
|
1124
|
-
}();
|
|
1125
|
-
|
|
1126
|
-
var handleFileDownload = /*#__PURE__*/function () {
|
|
1127
|
-
var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(url) {
|
|
1128
|
-
return runtime_1.wrap(function _callee6$(_context6) {
|
|
1129
|
-
while (1) {
|
|
1130
|
-
switch (_context6.prev = _context6.next) {
|
|
1131
|
-
case 0:
|
|
1132
|
-
return _context6.abrupt("return", fetch(url).then(function (res) {
|
|
1133
|
-
return res.text();
|
|
1134
|
-
}));
|
|
1135
|
-
|
|
1136
|
-
case 1:
|
|
1137
|
-
case "end":
|
|
1138
|
-
return _context6.stop();
|
|
818
|
+
return _context2.stop();
|
|
1139
819
|
}
|
|
1140
820
|
}
|
|
1141
|
-
},
|
|
821
|
+
}, _callee2);
|
|
1142
822
|
}));
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
return _ref6.apply(this, arguments);
|
|
1146
|
-
};
|
|
1147
|
-
}();
|
|
823
|
+
return _createTask.apply(this, arguments);
|
|
824
|
+
}
|
|
1148
825
|
|
|
1149
826
|
var TransifexAdapter = {
|
|
1150
827
|
getLocales: getLocales,
|
|
@@ -1153,279 +830,15 @@ var TransifexAdapter = {
|
|
|
1153
830
|
getTranslation: getTranslation
|
|
1154
831
|
};
|
|
1155
832
|
|
|
1156
|
-
var
|
|
1157
|
-
apiVersion: '2021-03-25'
|
|
1158
|
-
}); //document fetch
|
|
1159
|
-
|
|
1160
|
-
var findLatestDraft = function findLatestDraft(documentId) {
|
|
1161
|
-
//eliminates i18n versions
|
|
1162
|
-
var query = "*[_id == $id || _id == $draftId]";
|
|
1163
|
-
var params = {
|
|
1164
|
-
id: "" + documentId,
|
|
1165
|
-
draftId: "drafts." + documentId
|
|
1166
|
-
};
|
|
1167
|
-
return client.fetch(query, params).then(function (docs) {
|
|
1168
|
-
var _docs$find;
|
|
1169
|
-
|
|
1170
|
-
return (_docs$find = docs.find(function (doc) {
|
|
1171
|
-
return doc._id.includes('draft');
|
|
1172
|
-
})) != null ? _docs$find : docs[0];
|
|
1173
|
-
});
|
|
1174
|
-
}; //revision fetch
|
|
1175
|
-
|
|
1176
|
-
var findDocumentAtRevision = /*#__PURE__*/function () {
|
|
1177
|
-
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(documentId, rev) {
|
|
1178
|
-
var dataset, baseUrl, url, revisionDoc;
|
|
1179
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1180
|
-
while (1) {
|
|
1181
|
-
switch (_context.prev = _context.next) {
|
|
1182
|
-
case 0:
|
|
1183
|
-
dataset = client.config().dataset;
|
|
1184
|
-
baseUrl = "/data/history/" + dataset + "/documents/" + documentId + "?revision=" + rev;
|
|
1185
|
-
url = client.getUrl(baseUrl);
|
|
1186
|
-
_context.next = 5;
|
|
1187
|
-
return fetch(url, {
|
|
1188
|
-
credentials: 'include'
|
|
1189
|
-
}).then(function (req) {
|
|
1190
|
-
return req.json();
|
|
1191
|
-
}).then(function (req) {
|
|
1192
|
-
return req.documents[0];
|
|
1193
|
-
});
|
|
1194
|
-
|
|
1195
|
-
case 5:
|
|
1196
|
-
revisionDoc = _context.sent;
|
|
1197
|
-
|
|
1198
|
-
if (!(!revisionDoc || revisionDoc._rev !== rev)) {
|
|
1199
|
-
_context.next = 12;
|
|
1200
|
-
break;
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
baseUrl = "/data/history/" + dataset + "/documents/drafts." + documentId + "?revision=" + rev;
|
|
1204
|
-
url = client.getUrl(baseUrl);
|
|
1205
|
-
_context.next = 11;
|
|
1206
|
-
return fetch(url, {
|
|
1207
|
-
credentials: 'include'
|
|
1208
|
-
}).then(function (req) {
|
|
1209
|
-
return req.json();
|
|
1210
|
-
}).then(function (req) {
|
|
1211
|
-
return req.documents[0];
|
|
1212
|
-
});
|
|
1213
|
-
|
|
1214
|
-
case 11:
|
|
1215
|
-
revisionDoc = _context.sent;
|
|
1216
|
-
|
|
1217
|
-
case 12:
|
|
1218
|
-
return _context.abrupt("return", revisionDoc);
|
|
1219
|
-
|
|
1220
|
-
case 13:
|
|
1221
|
-
case "end":
|
|
1222
|
-
return _context.stop();
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
}, _callee);
|
|
1226
|
-
}));
|
|
1227
|
-
|
|
1228
|
-
return function findDocumentAtRevision(_x, _x2) {
|
|
1229
|
-
return _ref.apply(this, arguments);
|
|
1230
|
-
};
|
|
1231
|
-
}(); //document-level patch
|
|
1232
|
-
|
|
1233
|
-
var documentLevelPatch = /*#__PURE__*/function () {
|
|
1234
|
-
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(documentId, translatedFields, localeId) {
|
|
1235
|
-
var baseDoc, merged, targetId, i18nDoc, cleanedMerge;
|
|
1236
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1237
|
-
while (1) {
|
|
1238
|
-
switch (_context2.prev = _context2.next) {
|
|
1239
|
-
case 0:
|
|
1240
|
-
if (!translatedFields._rev) {
|
|
1241
|
-
_context2.next = 6;
|
|
1242
|
-
break;
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
_context2.next = 3;
|
|
1246
|
-
return findDocumentAtRevision(documentId, translatedFields._rev);
|
|
1247
|
-
|
|
1248
|
-
case 3:
|
|
1249
|
-
baseDoc = _context2.sent;
|
|
1250
|
-
_context2.next = 9;
|
|
1251
|
-
break;
|
|
1252
|
-
|
|
1253
|
-
case 6:
|
|
1254
|
-
_context2.next = 8;
|
|
1255
|
-
return findLatestDraft(documentId);
|
|
1256
|
-
|
|
1257
|
-
case 8:
|
|
1258
|
-
baseDoc = _context2.sent;
|
|
1259
|
-
|
|
1260
|
-
case 9:
|
|
1261
|
-
merged = BaseDocumentMerger.documentLevelMerge(translatedFields, baseDoc);
|
|
1262
|
-
targetId = "i18n." + documentId + "." + localeId;
|
|
1263
|
-
_context2.next = 13;
|
|
1264
|
-
return findLatestDraft(targetId);
|
|
1265
|
-
|
|
1266
|
-
case 13:
|
|
1267
|
-
i18nDoc = _context2.sent;
|
|
1268
|
-
|
|
1269
|
-
if (i18nDoc) {
|
|
1270
|
-
cleanedMerge = {}; //don't overwrite any existing values on the i18n doc
|
|
1271
|
-
|
|
1272
|
-
Object.entries(merged).forEach(function (_ref3) {
|
|
1273
|
-
var key = _ref3[0],
|
|
1274
|
-
value = _ref3[1];
|
|
1275
|
-
|
|
1276
|
-
if (Object.keys(translatedFields).includes(key) && !['_id', '_rev', '_updatedAt'].includes(key)) {
|
|
1277
|
-
cleanedMerge[key] = value;
|
|
1278
|
-
}
|
|
1279
|
-
});
|
|
1280
|
-
client.transaction() //@ts-ignore
|
|
1281
|
-
.patch(i18nDoc._id, function (p) {
|
|
1282
|
-
return p.set(cleanedMerge);
|
|
1283
|
-
}).commit();
|
|
1284
|
-
} else {
|
|
1285
|
-
merged._id = "drafts." + targetId; //account for legacy implementations of i18n plugin lang
|
|
1286
|
-
|
|
1287
|
-
if (baseDoc._lang) {
|
|
1288
|
-
merged._lang = localeId;
|
|
1289
|
-
} else if (baseDoc.__i18n_lang) {
|
|
1290
|
-
merged.__i18n_lang = localeId;
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
client.create(merged);
|
|
1294
|
-
}
|
|
1295
|
-
|
|
1296
|
-
case 15:
|
|
1297
|
-
case "end":
|
|
1298
|
-
return _context2.stop();
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
}, _callee2);
|
|
1302
|
-
}));
|
|
1303
|
-
|
|
1304
|
-
return function documentLevelPatch(_x3, _x4, _x5) {
|
|
1305
|
-
return _ref2.apply(this, arguments);
|
|
1306
|
-
};
|
|
1307
|
-
}(); //field level patch
|
|
1308
|
-
|
|
1309
|
-
var fieldLevelPatch = /*#__PURE__*/function () {
|
|
1310
|
-
var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(documentId, translatedFields, localeId) {
|
|
1311
|
-
var baseDoc, merged;
|
|
1312
|
-
return runtime_1.wrap(function _callee3$(_context3) {
|
|
1313
|
-
while (1) {
|
|
1314
|
-
switch (_context3.prev = _context3.next) {
|
|
1315
|
-
case 0:
|
|
1316
|
-
if (!translatedFields._rev) {
|
|
1317
|
-
_context3.next = 6;
|
|
1318
|
-
break;
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
_context3.next = 3;
|
|
1322
|
-
return findDocumentAtRevision(documentId, translatedFields._rev);
|
|
1323
|
-
|
|
1324
|
-
case 3:
|
|
1325
|
-
baseDoc = _context3.sent;
|
|
1326
|
-
_context3.next = 9;
|
|
1327
|
-
break;
|
|
1328
|
-
|
|
1329
|
-
case 6:
|
|
1330
|
-
_context3.next = 8;
|
|
1331
|
-
return findLatestDraft(documentId);
|
|
1332
|
-
|
|
1333
|
-
case 8:
|
|
1334
|
-
baseDoc = _context3.sent;
|
|
1335
|
-
|
|
1336
|
-
case 9:
|
|
1337
|
-
merged = BaseDocumentMerger.fieldLevelMerge(translatedFields, baseDoc, localeId, 'en');
|
|
1338
|
-
client.patch(baseDoc._id).set(merged).commit();
|
|
1339
|
-
|
|
1340
|
-
case 11:
|
|
1341
|
-
case "end":
|
|
1342
|
-
return _context3.stop();
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}, _callee3);
|
|
1346
|
-
}));
|
|
1347
|
-
|
|
1348
|
-
return function fieldLevelPatch(_x6, _x7, _x8) {
|
|
1349
|
-
return _ref4.apply(this, arguments);
|
|
1350
|
-
};
|
|
1351
|
-
}();
|
|
1352
|
-
|
|
1353
|
-
var defaultDocumentLevelConfig = {
|
|
1354
|
-
exportForTranslation: /*#__PURE__*/function () {
|
|
1355
|
-
var _exportForTranslation = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(id) {
|
|
1356
|
-
var doc, serialized;
|
|
1357
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
1358
|
-
while (1) {
|
|
1359
|
-
switch (_context.prev = _context.next) {
|
|
1360
|
-
case 0:
|
|
1361
|
-
_context.next = 2;
|
|
1362
|
-
return findLatestDraft(id);
|
|
1363
|
-
|
|
1364
|
-
case 2:
|
|
1365
|
-
doc = _context.sent;
|
|
1366
|
-
serialized = BaseDocumentSerializer.serializeDocument(doc, 'document');
|
|
1367
|
-
serialized.name = id;
|
|
1368
|
-
return _context.abrupt("return", serialized);
|
|
1369
|
-
|
|
1370
|
-
case 6:
|
|
1371
|
-
case "end":
|
|
1372
|
-
return _context.stop();
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}, _callee);
|
|
1376
|
-
}));
|
|
1377
|
-
|
|
1378
|
-
function exportForTranslation(_x) {
|
|
1379
|
-
return _exportForTranslation.apply(this, arguments);
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
return exportForTranslation;
|
|
1383
|
-
}(),
|
|
1384
|
-
importTranslation: function importTranslation(id, localeId, document) {
|
|
1385
|
-
var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
|
|
1386
|
-
documentLevelPatch(id, deserialized, localeId);
|
|
1387
|
-
},
|
|
833
|
+
var defaultDocumentLevelConfig = /*#__PURE__*/_extends({}, baseDocumentLevelConfig, {
|
|
1388
834
|
adapter: TransifexAdapter,
|
|
1389
835
|
secretsNamespace: 'transifex'
|
|
1390
|
-
};
|
|
1391
|
-
var defaultFieldLevelConfig = {
|
|
1392
|
-
exportForTranslation: /*#__PURE__*/function () {
|
|
1393
|
-
var _exportForTranslation2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(id) {
|
|
1394
|
-
var doc, serialized;
|
|
1395
|
-
return runtime_1.wrap(function _callee2$(_context2) {
|
|
1396
|
-
while (1) {
|
|
1397
|
-
switch (_context2.prev = _context2.next) {
|
|
1398
|
-
case 0:
|
|
1399
|
-
_context2.next = 2;
|
|
1400
|
-
return findLatestDraft(id);
|
|
1401
|
-
|
|
1402
|
-
case 2:
|
|
1403
|
-
doc = _context2.sent;
|
|
1404
|
-
serialized = BaseDocumentSerializer.serializeDocument(doc, 'field');
|
|
1405
|
-
serialized.name = id;
|
|
1406
|
-
return _context2.abrupt("return", serialized);
|
|
1407
|
-
|
|
1408
|
-
case 6:
|
|
1409
|
-
case "end":
|
|
1410
|
-
return _context2.stop();
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
}, _callee2);
|
|
1414
|
-
}));
|
|
1415
|
-
|
|
1416
|
-
function exportForTranslation(_x2) {
|
|
1417
|
-
return _exportForTranslation2.apply(this, arguments);
|
|
1418
|
-
}
|
|
836
|
+
});
|
|
1419
837
|
|
|
1420
|
-
|
|
1421
|
-
}(),
|
|
1422
|
-
importTranslation: function importTranslation(id, localeId, document) {
|
|
1423
|
-
var deserialized = BaseDocumentDeserializer.deserializeDocument(document);
|
|
1424
|
-
fieldLevelPatch(id, deserialized, localeId);
|
|
1425
|
-
},
|
|
838
|
+
var defaultFieldLevelConfig = /*#__PURE__*/_extends({}, baseFieldLevelConfig, {
|
|
1426
839
|
adapter: TransifexAdapter,
|
|
1427
840
|
secretsNamespace: 'transifex'
|
|
1428
|
-
};
|
|
841
|
+
});
|
|
1429
842
|
|
|
1430
843
|
export { TransifexAdapter, defaultDocumentLevelConfig, defaultFieldLevelConfig };
|
|
1431
844
|
//# sourceMappingURL=sanity-plugin-transifex.esm.js.map
|