@coveo/push-api-client 3.0.117 → 3.0.122
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/APICore.js +47 -47
- package/dist/APICore.js.map +1 -1
- package/dist/definitions/APICore.d.ts +18 -18
- package/dist/definitions/document.d.ts +124 -124
- package/dist/definitions/documentBuilder.d.ts +168 -168
- package/dist/definitions/documentBuilder.spec.d.ts +1 -1
- package/dist/definitions/environment.d.ts +16 -16
- package/dist/definitions/errors/baseError.d.ts +4 -4
- package/dist/definitions/errors/fieldErrors.d.ts +18 -18
- package/dist/definitions/errors/index.d.ts +3 -3
- package/dist/definitions/errors/privilegeError.d.ts +6 -6
- package/dist/definitions/errors/validatorErrors.d.ts +20 -20
- package/dist/definitions/fieldAnalyser/fieldAnalyser.d.ts +36 -36
- package/dist/definitions/fieldAnalyser/fieldAnalyser.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/fieldStore.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/fieldUtils.d.ts +6 -6
- package/dist/definitions/fieldAnalyser/fieldsUtils.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/inconsistencies.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/inconsistencies.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/typeUtils.d.ts +3 -3
- package/dist/definitions/fieldAnalyser/typeUtils.spec.d.ts +1 -1
- package/dist/definitions/help/file.d.ts +3 -3
- package/dist/definitions/help/file.spec.d.ts +1 -1
- package/dist/definitions/help/fileConsumer.d.ts +31 -31
- package/dist/definitions/help/fileConsumer.spec.d.ts +1 -1
- package/dist/definitions/help/fileContainer.d.ts +8 -8
- package/dist/definitions/help/fileContainer.spec.d.ts +1 -1
- package/dist/definitions/help/function.d.ts +1 -1
- package/dist/definitions/help/generator.d.ts +11 -11
- package/dist/definitions/help/generator.spec.d.ts +1 -1
- package/dist/definitions/help/urlUtils.d.ts +27 -27
- package/dist/definitions/help/urlUtils.spec.d.ts +1 -1
- package/dist/definitions/index.d.ts +14 -14
- package/dist/definitions/interfaces.d.ts +70 -70
- package/dist/definitions/localtest.d.ts +1 -1
- package/dist/definitions/permissionSetBuilder.d.ts +34 -34
- package/dist/definitions/permissionSetBuilder.spec.d.ts +1 -1
- package/dist/definitions/securityIdentityBuilder.d.ts +105 -105
- package/dist/definitions/securityIdentityBuilder.spec.d.ts +1 -1
- package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -11
- package/dist/definitions/source/batchUploadDocumentsFromFile.spec.d.ts +1 -1
- package/dist/definitions/source/catalog.d.ts +70 -70
- package/dist/definitions/source/catalog.spec.d.ts +1 -1
- package/dist/definitions/source/documentUploader.d.ts +11 -11
- package/dist/definitions/source/documentUploader.spec.d.ts +1 -1
- package/dist/definitions/source/push.d.ts +87 -87
- package/dist/definitions/source/push.spec.d.ts +1 -1
- package/dist/definitions/source/securityIdenty.d.ts +43 -43
- package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/fileContainerStrategy.spec.d.ts +1 -1
- package/dist/definitions/uploadStrategy/index.d.ts +3 -3
- package/dist/definitions/uploadStrategy/strategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +28 -28
- package/dist/definitions/uploadStrategy/streamChunkStrategy.spec.d.ts +1 -1
- package/dist/definitions/validation/caseInsensitiveDocument.d.ts +13 -13
- package/dist/definitions/validation/knownKey.d.ts +10 -10
- package/dist/definitions/validation/parseFile.d.ts +4 -4
- package/dist/definitions/validation/parseFile.spec.d.ts +1 -1
- package/dist/definitions/validation/parsePermissions.d.ts +5 -5
- package/dist/definitions/validation/parsePermissions.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -3
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -7
- package/dist/definitions/validation/requiredKeyValidator.d.ts +17 -17
- package/dist/definitions/validation/transformers/transformer.d.ts +31 -31
- package/dist/definitions/validation/transformers/transformer.spec.d.ts +1 -1
- package/dist/document.js +2 -2
- package/dist/documentBuilder.js +292 -292
- package/dist/documentBuilder.spec.js +191 -191
- package/dist/environment.js +41 -41
- package/dist/errors/baseError.js +10 -10
- package/dist/errors/fieldErrors.js +42 -42
- package/dist/errors/index.js +19 -19
- package/dist/errors/privilegeError.js +12 -12
- package/dist/errors/validatorErrors.js +40 -40
- package/dist/fieldAnalyser/fieldAnalyser.js +95 -95
- package/dist/fieldAnalyser/fieldAnalyser.spec.js +230 -230
- package/dist/fieldAnalyser/fieldStore.js +21 -21
- package/dist/fieldAnalyser/fieldUtils.js +41 -41
- package/dist/fieldAnalyser/fieldsUtils.spec.js +116 -116
- package/dist/fieldAnalyser/inconsistencies.js +14 -14
- package/dist/fieldAnalyser/inconsistencies.spec.js +40 -40
- package/dist/fieldAnalyser/typeUtils.js +61 -61
- package/dist/fieldAnalyser/typeUtils.spec.js +142 -142
- package/dist/help/file.js +37 -37
- package/dist/help/file.spec.js +67 -67
- package/dist/help/fileConsumer.js +150 -150
- package/dist/help/fileConsumer.spec.js +153 -153
- package/dist/help/fileContainer.js +48 -48
- package/dist/help/fileContainer.spec.js +65 -65
- package/dist/help/function.js +5 -5
- package/dist/help/generator.js +32 -32
- package/dist/help/generator.spec.js +82 -82
- package/dist/help/urlUtils.js +42 -42
- package/dist/help/urlUtils.spec.js +41 -41
- package/dist/index.js +38 -38
- package/dist/interfaces.js +2 -2
- package/dist/localtest.js +55 -55
- package/dist/permissionSetBuilder.js +58 -58
- package/dist/permissionSetBuilder.spec.js +68 -68
- package/dist/securityIdentityBuilder.js +128 -128
- package/dist/securityIdentityBuilder.spec.js +50 -50
- package/dist/source/batchUploadDocumentsFromFile.js +46 -46
- package/dist/source/batchUploadDocumentsFromFile.spec.js +145 -145
- package/dist/source/catalog.js +111 -111
- package/dist/source/catalog.spec.js +64 -64
- package/dist/source/documentUploader.js +45 -45
- package/dist/source/documentUploader.spec.js +118 -118
- package/dist/source/push.js +140 -140
- package/dist/source/push.spec.js +152 -152
- package/dist/source/securityIdenty.js +57 -57
- package/dist/uploadStrategy/fileContainerStrategy.js +32 -32
- package/dist/uploadStrategy/fileContainerStrategy.spec.js +86 -86
- package/dist/uploadStrategy/index.js +19 -19
- package/dist/uploadStrategy/strategy.js +2 -2
- package/dist/uploadStrategy/streamChunkStrategy.js +52 -52
- package/dist/uploadStrategy/streamChunkStrategy.spec.js +77 -77
- package/dist/validation/caseInsensitiveDocument.js +31 -31
- package/dist/validation/knownKey.js +37 -37
- package/dist/validation/parseFile.js +120 -120
- package/dist/validation/parseFile.spec.js +96 -96
- package/dist/validation/parsePermissions.js +118 -118
- package/dist/validation/parsePermissions.spec.js +86 -86
- package/dist/validation/preconditions/apiKeyPrivilege.js +20 -20
- package/dist/validation/preconditions/apiKeyPrivilege.spec.js +66 -66
- package/dist/validation/preconditions/platformPrivilege.js +32 -32
- package/dist/validation/requiredKeyValidator.js +61 -61
- package/dist/validation/transformers/transformer.js +51 -51
- package/dist/validation/transformers/transformer.spec.js +21 -21
- package/package.json +11 -11
@@ -1,49 +1,49 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uploadContentToFileContainer = void 0;
|
4
|
-
const node_url_1 = require("node:url");
|
5
|
-
const uploadContentToFileContainer = async (fileContainer, batch) => {
|
6
|
-
const uploadURL = new node_url_1.URL(fileContainer.uploadUri);
|
7
|
-
let response;
|
8
|
-
const errors = [];
|
9
|
-
try {
|
10
|
-
response = await fetch(uploadURL.toString(), {
|
11
|
-
method: 'PUT',
|
12
|
-
body: JSON.stringify({
|
13
|
-
addOrUpdate: batch.addOrUpdate.map((docBuilder) => docBuilder.marshal()),
|
14
|
-
delete: batch.delete,
|
15
|
-
}),
|
16
|
-
headers: fileContainer.requiredHeaders,
|
17
|
-
});
|
18
|
-
}
|
19
|
-
catch (error) {
|
20
|
-
errors.push(error);
|
21
|
-
}
|
22
|
-
finally {
|
23
|
-
if ((response === null || response === void 0 ? void 0 : response.ok) === false) {
|
24
|
-
if (isMaxBodyLengthExceededError(response)) {
|
25
|
-
addMaxBodyLengthError(errors, response);
|
26
|
-
}
|
27
|
-
else {
|
28
|
-
addGenericFetchError(errors, response);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
32
|
-
if (errors.length > 0) {
|
33
|
-
throw new AggregateError(errors);
|
34
|
-
}
|
35
|
-
else {
|
36
|
-
return response;
|
37
|
-
}
|
38
|
-
};
|
39
|
-
exports.uploadContentToFileContainer = uploadContentToFileContainer;
|
40
|
-
function addGenericFetchError(errors, response) {
|
41
|
-
errors.push(new Error('Request failed', { cause: response }));
|
42
|
-
}
|
43
|
-
function addMaxBodyLengthError(errors, response) {
|
44
|
-
errors.push(new Error('File container size limit exceeded.\nSee <https://docs.coveo.com/en/63/index-content/push-api-limits#request-size-limits>.', { cause: response }));
|
45
|
-
}
|
46
|
-
function isMaxBodyLengthExceededError(response) {
|
47
|
-
return (response === null || response === void 0 ? void 0 : response.status) === 413;
|
48
|
-
}
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uploadContentToFileContainer = void 0;
|
4
|
+
const node_url_1 = require("node:url");
|
5
|
+
const uploadContentToFileContainer = async (fileContainer, batch) => {
|
6
|
+
const uploadURL = new node_url_1.URL(fileContainer.uploadUri);
|
7
|
+
let response;
|
8
|
+
const errors = [];
|
9
|
+
try {
|
10
|
+
response = await fetch(uploadURL.toString(), {
|
11
|
+
method: 'PUT',
|
12
|
+
body: JSON.stringify({
|
13
|
+
addOrUpdate: batch.addOrUpdate.map((docBuilder) => docBuilder.marshal()),
|
14
|
+
delete: batch.delete,
|
15
|
+
}),
|
16
|
+
headers: fileContainer.requiredHeaders,
|
17
|
+
});
|
18
|
+
}
|
19
|
+
catch (error) {
|
20
|
+
errors.push(error);
|
21
|
+
}
|
22
|
+
finally {
|
23
|
+
if ((response === null || response === void 0 ? void 0 : response.ok) === false) {
|
24
|
+
if (isMaxBodyLengthExceededError(response)) {
|
25
|
+
addMaxBodyLengthError(errors, response);
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
addGenericFetchError(errors, response);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
if (errors.length > 0) {
|
33
|
+
throw new AggregateError(errors);
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
return response;
|
37
|
+
}
|
38
|
+
};
|
39
|
+
exports.uploadContentToFileContainer = uploadContentToFileContainer;
|
40
|
+
function addGenericFetchError(errors, response) {
|
41
|
+
errors.push(new Error('Request failed', { cause: response }));
|
42
|
+
}
|
43
|
+
function addMaxBodyLengthError(errors, response) {
|
44
|
+
errors.push(new Error('File container size limit exceeded.\nSee <https://docs.coveo.com/en/63/index-content/push-api-limits#request-size-limits>.', { cause: response }));
|
45
|
+
}
|
46
|
+
function isMaxBodyLengthExceededError(response) {
|
47
|
+
return (response === null || response === void 0 ? void 0 : response.status) === 413;
|
48
|
+
}
|
49
49
|
//# sourceMappingURL=fileContainer.js.map
|
@@ -1,71 +1,71 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
require("fetch-undici-polyfill");
|
4
|
-
jest.mock('fetch-undici-polyfill', () => {
|
5
|
-
Object.assign(global, { fetch: jest.fn() });
|
6
|
-
});
|
7
|
-
const __1 = require("..");
|
8
|
-
const fileContainer_1 = require("./fileContainer");
|
9
|
-
describe('#uploadContentToFileContainer', () => {
|
10
|
-
const fetchMocked = fetch;
|
11
|
-
const fileContainerResponse = {
|
12
|
-
uploadUri: 'https://fake.upload.url',
|
13
|
-
fileId: 'file_id',
|
14
|
-
requiredHeaders: { foo: 'bar' },
|
15
|
-
};
|
16
|
-
const batch = {
|
17
|
-
addOrUpdate: [new __1.DocumentBuilder('http://some.url', 'Some document')],
|
18
|
-
delete: [],
|
19
|
-
};
|
20
|
-
const doMockFetch = () => {
|
21
|
-
fetchMocked.mockImplementation(() => Promise.resolve());
|
22
|
-
};
|
23
|
-
beforeEach(() => {
|
24
|
-
doMockFetch();
|
25
|
-
});
|
26
|
-
it('should perform an PUT request with the right params', async () => {
|
27
|
-
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
28
|
-
expect(fetchMocked).toBeCalled();
|
29
|
-
expect(fetchMocked.mock.lastCall).toMatchSnapshot();
|
30
|
-
});
|
31
|
-
describe('when the server respond with 413', () => {
|
32
|
-
beforeEach(() => {
|
33
|
-
fetchMocked.mockImplementationOnce(() => Promise.resolve({
|
34
|
-
ok: false,
|
35
|
-
status: 413,
|
36
|
-
}));
|
37
|
-
});
|
38
|
-
it('should give some info on how to fix it', async () => {
|
39
|
-
try {
|
40
|
-
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
41
|
-
}
|
42
|
-
catch (error) {
|
43
|
-
expect(error).toBeInstanceOf(AggregateError);
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
require("fetch-undici-polyfill");
|
4
|
+
jest.mock('fetch-undici-polyfill', () => {
|
5
|
+
Object.assign(global, { fetch: jest.fn() });
|
6
|
+
});
|
7
|
+
const __1 = require("..");
|
8
|
+
const fileContainer_1 = require("./fileContainer");
|
9
|
+
describe('#uploadContentToFileContainer', () => {
|
10
|
+
const fetchMocked = fetch;
|
11
|
+
const fileContainerResponse = {
|
12
|
+
uploadUri: 'https://fake.upload.url',
|
13
|
+
fileId: 'file_id',
|
14
|
+
requiredHeaders: { foo: 'bar' },
|
15
|
+
};
|
16
|
+
const batch = {
|
17
|
+
addOrUpdate: [new __1.DocumentBuilder('http://some.url', 'Some document')],
|
18
|
+
delete: [],
|
19
|
+
};
|
20
|
+
const doMockFetch = () => {
|
21
|
+
fetchMocked.mockImplementation(() => Promise.resolve());
|
22
|
+
};
|
23
|
+
beforeEach(() => {
|
24
|
+
doMockFetch();
|
25
|
+
});
|
26
|
+
it('should perform an PUT request with the right params', async () => {
|
27
|
+
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
28
|
+
expect(fetchMocked).toBeCalled();
|
29
|
+
expect(fetchMocked.mock.lastCall).toMatchSnapshot();
|
30
|
+
});
|
31
|
+
describe('when the server respond with 413', () => {
|
32
|
+
beforeEach(() => {
|
33
|
+
fetchMocked.mockImplementationOnce(() => Promise.resolve({
|
34
|
+
ok: false,
|
35
|
+
status: 413,
|
36
|
+
}));
|
37
|
+
});
|
38
|
+
it('should give some info on how to fix it', async () => {
|
39
|
+
try {
|
40
|
+
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
41
|
+
}
|
42
|
+
catch (error) {
|
43
|
+
expect(error).toBeInstanceOf(AggregateError);
|
44
44
|
expect(error.errors).toMatchSnapshot(`
|
45
45
|
[
|
46
46
|
[Error: File container size limit exceeded.
|
47
47
|
See <https://docs.coveo.com/en/63/index-content/push-api-limits#request-size-limits>.],
|
48
48
|
]
|
49
|
-
`);
|
50
|
-
}
|
51
|
-
expect.assertions(2);
|
52
|
-
});
|
53
|
-
});
|
54
|
-
describe('when anything else than MaxBodyLengthExceededError is thrown', () => {
|
55
|
-
const thrownError = new Error();
|
56
|
-
beforeEach(() => {
|
57
|
-
fetchMocked.mockImplementationOnce(() => Promise.reject(thrownError));
|
58
|
-
});
|
59
|
-
it('should bubble up the error', async () => {
|
60
|
-
try {
|
61
|
-
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
62
|
-
}
|
63
|
-
catch (error) {
|
64
|
-
expect(error).toBeInstanceOf(AggregateError);
|
65
|
-
expect(error.errors).toContain(thrownError);
|
66
|
-
}
|
67
|
-
expect.assertions(2);
|
68
|
-
});
|
69
|
-
});
|
70
|
-
});
|
49
|
+
`);
|
50
|
+
}
|
51
|
+
expect.assertions(2);
|
52
|
+
});
|
53
|
+
});
|
54
|
+
describe('when anything else than MaxBodyLengthExceededError is thrown', () => {
|
55
|
+
const thrownError = new Error();
|
56
|
+
beforeEach(() => {
|
57
|
+
fetchMocked.mockImplementationOnce(() => Promise.reject(thrownError));
|
58
|
+
});
|
59
|
+
it('should bubble up the error', async () => {
|
60
|
+
try {
|
61
|
+
await (0, fileContainer_1.uploadContentToFileContainer)(fileContainerResponse, batch);
|
62
|
+
}
|
63
|
+
catch (error) {
|
64
|
+
expect(error).toBeInstanceOf(AggregateError);
|
65
|
+
expect(error.errors).toContain(thrownError);
|
66
|
+
}
|
67
|
+
expect.assertions(2);
|
68
|
+
});
|
69
|
+
});
|
70
|
+
});
|
71
71
|
//# sourceMappingURL=fileContainer.spec.js.map
|
package/dist/help/function.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.noop = void 0;
|
4
|
-
const noop = () => { };
|
5
|
-
exports.noop = noop;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.noop = void 0;
|
4
|
+
const noop = () => { };
|
5
|
+
exports.noop = noop;
|
6
6
|
//# sourceMappingURL=function.js.map
|
package/dist/help/generator.js
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.consumeGenerator = void 0;
|
4
|
-
const createWorkers = (generator, maxConcurrent, doWork) => {
|
5
|
-
return new Array(maxConcurrent)
|
6
|
-
.fill(generator())
|
7
|
-
.map((gen, workerIndex) => doWork(gen, workerIndex));
|
8
|
-
};
|
9
|
-
/**
|
10
|
-
* Consumes a generator or an async generator function concurrently
|
11
|
-
*
|
12
|
-
* @template T
|
13
|
-
* @param {() => PromiseGenerator<T>} generator The generator function to consume.
|
14
|
-
* @param {number} maxConcurrent The number of maximum concurrent workers.
|
15
|
-
* @param {(worker: number, promiseValue: Awaited<T>) => void} [callback] A callback function that runs after each iteration of the iterator. It takes in argument the promise resolved value as well as the worker (ID) assigned to fulfill that promise.
|
16
|
-
*/
|
17
|
-
const consumeGenerator = async (generator, maxConcurrent, callback) => {
|
18
|
-
const doWork = async (generator, workerIndex) => {
|
19
|
-
const next = await generator.next();
|
20
|
-
if (next.done) {
|
21
|
-
return;
|
22
|
-
}
|
23
|
-
const value = await next.value;
|
24
|
-
if (callback) {
|
25
|
-
callback(workerIndex, value);
|
26
|
-
}
|
27
|
-
return doWork(generator, workerIndex);
|
28
|
-
};
|
29
|
-
const workers = createWorkers(generator, maxConcurrent, doWork);
|
30
|
-
return Promise.all(workers);
|
31
|
-
};
|
32
|
-
exports.consumeGenerator = consumeGenerator;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.consumeGenerator = void 0;
|
4
|
+
const createWorkers = (generator, maxConcurrent, doWork) => {
|
5
|
+
return new Array(maxConcurrent)
|
6
|
+
.fill(generator())
|
7
|
+
.map((gen, workerIndex) => doWork(gen, workerIndex));
|
8
|
+
};
|
9
|
+
/**
|
10
|
+
* Consumes a generator or an async generator function concurrently
|
11
|
+
*
|
12
|
+
* @template T
|
13
|
+
* @param {() => PromiseGenerator<T>} generator The generator function to consume.
|
14
|
+
* @param {number} maxConcurrent The number of maximum concurrent workers.
|
15
|
+
* @param {(worker: number, promiseValue: Awaited<T>) => void} [callback] A callback function that runs after each iteration of the iterator. It takes in argument the promise resolved value as well as the worker (ID) assigned to fulfill that promise.
|
16
|
+
*/
|
17
|
+
const consumeGenerator = async (generator, maxConcurrent, callback) => {
|
18
|
+
const doWork = async (generator, workerIndex) => {
|
19
|
+
const next = await generator.next();
|
20
|
+
if (next.done) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
const value = await next.value;
|
24
|
+
if (callback) {
|
25
|
+
callback(workerIndex, value);
|
26
|
+
}
|
27
|
+
return doWork(generator, workerIndex);
|
28
|
+
};
|
29
|
+
const workers = createWorkers(generator, maxConcurrent, doWork);
|
30
|
+
return Promise.all(workers);
|
31
|
+
};
|
32
|
+
exports.consumeGenerator = consumeGenerator;
|
33
33
|
//# sourceMappingURL=generator.js.map
|
@@ -1,83 +1,83 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
3
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
4
|
-
var m = o[Symbol.asyncIterator], i;
|
5
|
-
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
6
|
-
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
7
|
-
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
8
|
-
};
|
9
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
10
|
-
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
11
|
-
var i, p;
|
12
|
-
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
13
|
-
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
14
|
-
};
|
15
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
16
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
17
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
18
|
-
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
19
|
-
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
20
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
21
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
22
|
-
function fulfill(value) { resume("next", value); }
|
23
|
-
function reject(value) { resume("throw", value); }
|
24
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
25
|
-
};
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
-
const generator_1 = require("./generator");
|
28
|
-
const process_1 = require("process");
|
29
|
-
describe('generator', () => {
|
30
|
-
const maxConcurrent = 2;
|
31
|
-
const buildPromise = (id) => () => new Promise((resolve) => {
|
32
|
-
(0, process_1.nextTick)(() => resolve(id));
|
33
|
-
});
|
34
|
-
const taskMatrix = [
|
35
|
-
[buildPromise(5), buildPromise(6)],
|
36
|
-
[buildPromise(1), buildPromise(2), buildPromise(3)],
|
37
|
-
[buildPromise(4)],
|
38
|
-
];
|
39
|
-
/**
|
40
|
-
* The promises should be consumed in this order:
|
41
|
-
* 5 6 1 2 3 4
|
42
|
-
*
|
43
|
-
* And distributed to the workers in this manner:
|
44
|
-
* Worker 1 : 5 1 3
|
45
|
-
* Worker 2 : 6 2 4
|
46
|
-
*/
|
47
|
-
const generator = function* () {
|
48
|
-
for (const taskList of taskMatrix) {
|
49
|
-
// Flattening first dimension of the task matrix
|
50
|
-
for (const task of taskList) {
|
51
|
-
// Flattening second dimension of the task matrix
|
52
|
-
yield task();
|
53
|
-
}
|
54
|
-
}
|
55
|
-
};
|
56
|
-
const asyncGenerator = function () {
|
57
|
-
return __asyncGenerator(this, arguments, function* () {
|
58
|
-
yield __await(yield* __asyncDelegator(__asyncValues(generator())));
|
59
|
-
});
|
60
|
-
};
|
61
|
-
const callback = jest.fn();
|
62
|
-
const callSequence = [
|
63
|
-
[0, 5],
|
64
|
-
[0, 1],
|
65
|
-
[0, 3],
|
66
|
-
[1, 6],
|
67
|
-
[1, 2],
|
68
|
-
[1, 4],
|
69
|
-
];
|
70
|
-
it('should consume a generator', async () => {
|
71
|
-
await (0, generator_1.consumeGenerator)(generator, maxConcurrent, callback);
|
72
|
-
callSequence.forEach((step) => {
|
73
|
-
expect(callback).toHaveBeenCalledWith(step[0], step[1]);
|
74
|
-
});
|
75
|
-
});
|
76
|
-
it('should consume an async generator', async () => {
|
77
|
-
await (0, generator_1.consumeGenerator)(asyncGenerator, maxConcurrent, callback);
|
78
|
-
callSequence.forEach((step) => {
|
79
|
-
expect(callback).toHaveBeenCalledWith(step[0], step[1]);
|
80
|
-
});
|
81
|
-
});
|
82
|
-
});
|
1
|
+
"use strict";
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
8
|
+
};
|
9
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
10
|
+
var __asyncDelegator = (this && this.__asyncDelegator) || function (o) {
|
11
|
+
var i, p;
|
12
|
+
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
13
|
+
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
14
|
+
};
|
15
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
16
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
17
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
18
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
19
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
20
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
21
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
22
|
+
function fulfill(value) { resume("next", value); }
|
23
|
+
function reject(value) { resume("throw", value); }
|
24
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
25
|
+
};
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
+
const generator_1 = require("./generator");
|
28
|
+
const process_1 = require("process");
|
29
|
+
describe('generator', () => {
|
30
|
+
const maxConcurrent = 2;
|
31
|
+
const buildPromise = (id) => () => new Promise((resolve) => {
|
32
|
+
(0, process_1.nextTick)(() => resolve(id));
|
33
|
+
});
|
34
|
+
const taskMatrix = [
|
35
|
+
[buildPromise(5), buildPromise(6)],
|
36
|
+
[buildPromise(1), buildPromise(2), buildPromise(3)],
|
37
|
+
[buildPromise(4)],
|
38
|
+
];
|
39
|
+
/**
|
40
|
+
* The promises should be consumed in this order:
|
41
|
+
* 5 6 1 2 3 4
|
42
|
+
*
|
43
|
+
* And distributed to the workers in this manner:
|
44
|
+
* Worker 1 : 5 1 3
|
45
|
+
* Worker 2 : 6 2 4
|
46
|
+
*/
|
47
|
+
const generator = function* () {
|
48
|
+
for (const taskList of taskMatrix) {
|
49
|
+
// Flattening first dimension of the task matrix
|
50
|
+
for (const task of taskList) {
|
51
|
+
// Flattening second dimension of the task matrix
|
52
|
+
yield task();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
};
|
56
|
+
const asyncGenerator = function () {
|
57
|
+
return __asyncGenerator(this, arguments, function* () {
|
58
|
+
yield __await(yield* __asyncDelegator(__asyncValues(generator())));
|
59
|
+
});
|
60
|
+
};
|
61
|
+
const callback = jest.fn();
|
62
|
+
const callSequence = [
|
63
|
+
[0, 5],
|
64
|
+
[0, 1],
|
65
|
+
[0, 3],
|
66
|
+
[1, 6],
|
67
|
+
[1, 2],
|
68
|
+
[1, 4],
|
69
|
+
];
|
70
|
+
it('should consume a generator', async () => {
|
71
|
+
await (0, generator_1.consumeGenerator)(generator, maxConcurrent, callback);
|
72
|
+
callSequence.forEach((step) => {
|
73
|
+
expect(callback).toHaveBeenCalledWith(step[0], step[1]);
|
74
|
+
});
|
75
|
+
});
|
76
|
+
it('should consume an async generator', async () => {
|
77
|
+
await (0, generator_1.consumeGenerator)(asyncGenerator, maxConcurrent, callback);
|
78
|
+
callSequence.forEach((step) => {
|
79
|
+
expect(callback).toHaveBeenCalledWith(step[0], step[1]);
|
80
|
+
});
|
81
|
+
});
|
82
|
+
});
|
83
83
|
//# sourceMappingURL=generator.spec.js.map
|
package/dist/help/urlUtils.js
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.StreamUrlBuilder = exports.PushUrlBuilder = void 0;
|
4
|
-
const environment_1 = require("../environment");
|
5
|
-
class BaseUrlBuilder {
|
6
|
-
constructor(organizationId, options) {
|
7
|
-
this.organizationId = organizationId;
|
8
|
-
this.options = options;
|
9
|
-
}
|
10
|
-
get platformURL() {
|
11
|
-
return `${(0, environment_1.platformUrl)(this.options)}/${this.organizationId}`;
|
12
|
-
}
|
13
|
-
get fileContainerUrl() {
|
14
|
-
return new URL(`${this.platformURL}/files`);
|
15
|
-
}
|
16
|
-
}
|
17
|
-
class PushUrlBuilder extends BaseUrlBuilder {
|
18
|
-
constructor(sourceId, organizationId, options) {
|
19
|
-
super(organizationId, options);
|
20
|
-
this.sourceId = sourceId;
|
21
|
-
}
|
22
|
-
get baseURL() {
|
23
|
-
return new URL(`${this.platformURL}/sources/${this.sourceId}`);
|
24
|
-
}
|
25
|
-
get baseAPIURLForUpdate() {
|
26
|
-
return new URL(`${this.baseURL}/documents/batch`);
|
27
|
-
}
|
28
|
-
}
|
29
|
-
exports.PushUrlBuilder = PushUrlBuilder;
|
30
|
-
class StreamUrlBuilder extends BaseUrlBuilder {
|
31
|
-
constructor(sourceId, organizationId, options) {
|
32
|
-
super(organizationId, options);
|
33
|
-
this.sourceId = sourceId;
|
34
|
-
}
|
35
|
-
get baseStreamURL() {
|
36
|
-
return new URL(`${this.platformURL}/sources/${this.sourceId}/stream`);
|
37
|
-
}
|
38
|
-
get baseAPIURLForUpdate() {
|
39
|
-
return new URL(`${this.baseStreamURL}/update`);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
exports.StreamUrlBuilder = StreamUrlBuilder;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.StreamUrlBuilder = exports.PushUrlBuilder = void 0;
|
4
|
+
const environment_1 = require("../environment");
|
5
|
+
class BaseUrlBuilder {
|
6
|
+
constructor(organizationId, options) {
|
7
|
+
this.organizationId = organizationId;
|
8
|
+
this.options = options;
|
9
|
+
}
|
10
|
+
get platformURL() {
|
11
|
+
return `${(0, environment_1.platformUrl)(this.options)}/${this.organizationId}`;
|
12
|
+
}
|
13
|
+
get fileContainerUrl() {
|
14
|
+
return new URL(`${this.platformURL}/files`);
|
15
|
+
}
|
16
|
+
}
|
17
|
+
class PushUrlBuilder extends BaseUrlBuilder {
|
18
|
+
constructor(sourceId, organizationId, options) {
|
19
|
+
super(organizationId, options);
|
20
|
+
this.sourceId = sourceId;
|
21
|
+
}
|
22
|
+
get baseURL() {
|
23
|
+
return new URL(`${this.platformURL}/sources/${this.sourceId}`);
|
24
|
+
}
|
25
|
+
get baseAPIURLForUpdate() {
|
26
|
+
return new URL(`${this.baseURL}/documents/batch`);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
exports.PushUrlBuilder = PushUrlBuilder;
|
30
|
+
class StreamUrlBuilder extends BaseUrlBuilder {
|
31
|
+
constructor(sourceId, organizationId, options) {
|
32
|
+
super(organizationId, options);
|
33
|
+
this.sourceId = sourceId;
|
34
|
+
}
|
35
|
+
get baseStreamURL() {
|
36
|
+
return new URL(`${this.platformURL}/sources/${this.sourceId}/stream`);
|
37
|
+
}
|
38
|
+
get baseAPIURLForUpdate() {
|
39
|
+
return new URL(`${this.baseStreamURL}/update`);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
exports.StreamUrlBuilder = StreamUrlBuilder;
|
43
43
|
//# sourceMappingURL=urlUtils.js.map
|
@@ -1,42 +1,42 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const platform_client_1 = require("@coveo/platform-client");
|
4
|
-
const environment_1 = require("../environment");
|
5
|
-
const urlUtils_1 = require("./urlUtils");
|
6
|
-
const platformOptions = {
|
7
|
-
region: platform_client_1.Region.US,
|
8
|
-
environment: environment_1.PlatformEnvironment.Prod,
|
9
|
-
};
|
10
|
-
describe('UrlBuilder', () => {
|
11
|
-
describe('PushUrlBuilder', () => {
|
12
|
-
let builder;
|
13
|
-
beforeEach(() => {
|
14
|
-
builder = new urlUtils_1.PushUrlBuilder('source-id', 'org-id', platformOptions);
|
15
|
-
});
|
16
|
-
it('should return the base url', () => {
|
17
|
-
expect(builder.baseURL.toString()).toMatchSnapshot();
|
18
|
-
});
|
19
|
-
it('should return the base url for update', () => {
|
20
|
-
expect(builder.baseAPIURLForUpdate.toString()).toMatchSnapshot();
|
21
|
-
});
|
22
|
-
it('should return the file container url', () => {
|
23
|
-
expect(builder.fileContainerUrl.toString()).toMatchSnapshot();
|
24
|
-
});
|
25
|
-
});
|
26
|
-
describe('StreamUrlBuilder', () => {
|
27
|
-
let builder;
|
28
|
-
beforeEach(() => {
|
29
|
-
builder = new urlUtils_1.StreamUrlBuilder('source-id', 'org-id', platformOptions);
|
30
|
-
});
|
31
|
-
it('should return the base url', () => {
|
32
|
-
expect(builder.baseStreamURL.toString()).toMatchSnapshot();
|
33
|
-
});
|
34
|
-
it('should return the base url for update', () => {
|
35
|
-
expect(builder.baseAPIURLForUpdate.toString()).toMatchSnapshot();
|
36
|
-
});
|
37
|
-
it('should return the file container url', () => {
|
38
|
-
expect(builder.fileContainerUrl.toString()).toMatchSnapshot();
|
39
|
-
});
|
40
|
-
});
|
41
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const platform_client_1 = require("@coveo/platform-client");
|
4
|
+
const environment_1 = require("../environment");
|
5
|
+
const urlUtils_1 = require("./urlUtils");
|
6
|
+
const platformOptions = {
|
7
|
+
region: platform_client_1.Region.US,
|
8
|
+
environment: environment_1.PlatformEnvironment.Prod,
|
9
|
+
};
|
10
|
+
describe('UrlBuilder', () => {
|
11
|
+
describe('PushUrlBuilder', () => {
|
12
|
+
let builder;
|
13
|
+
beforeEach(() => {
|
14
|
+
builder = new urlUtils_1.PushUrlBuilder('source-id', 'org-id', platformOptions);
|
15
|
+
});
|
16
|
+
it('should return the base url', () => {
|
17
|
+
expect(builder.baseURL.toString()).toMatchSnapshot();
|
18
|
+
});
|
19
|
+
it('should return the base url for update', () => {
|
20
|
+
expect(builder.baseAPIURLForUpdate.toString()).toMatchSnapshot();
|
21
|
+
});
|
22
|
+
it('should return the file container url', () => {
|
23
|
+
expect(builder.fileContainerUrl.toString()).toMatchSnapshot();
|
24
|
+
});
|
25
|
+
});
|
26
|
+
describe('StreamUrlBuilder', () => {
|
27
|
+
let builder;
|
28
|
+
beforeEach(() => {
|
29
|
+
builder = new urlUtils_1.StreamUrlBuilder('source-id', 'org-id', platformOptions);
|
30
|
+
});
|
31
|
+
it('should return the base url', () => {
|
32
|
+
expect(builder.baseStreamURL.toString()).toMatchSnapshot();
|
33
|
+
});
|
34
|
+
it('should return the base url for update', () => {
|
35
|
+
expect(builder.baseAPIURLForUpdate.toString()).toMatchSnapshot();
|
36
|
+
});
|
37
|
+
it('should return the file container url', () => {
|
38
|
+
expect(builder.fileContainerUrl.toString()).toMatchSnapshot();
|
39
|
+
});
|
40
|
+
});
|
41
|
+
});
|
42
42
|
//# sourceMappingURL=urlUtils.spec.js.map
|