@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,143 +1,143 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const platform_client_1 = require("@coveo/platform-client");
|
4
|
-
const typeUtils_1 = require("./typeUtils");
|
5
|
-
describe('typeUtils', () => {
|
6
|
-
const signedIntegerLimit = 0b1111111111111111111111111111111;
|
7
|
-
it.each([
|
8
|
-
// String
|
9
|
-
{ value: 'over 9000', type: platform_client_1.FieldTypes.STRING },
|
10
|
-
// LONG
|
11
|
-
{ value: 0, type: platform_client_1.FieldTypes.LONG },
|
12
|
-
{ value: -10, type: platform_client_1.FieldTypes.LONG },
|
13
|
-
{ value: signedIntegerLimit, type: platform_client_1.FieldTypes.LONG },
|
14
|
-
{ value: 10.0, type: platform_client_1.FieldTypes.LONG },
|
15
|
-
// LONG 64
|
16
|
-
{ value: signedIntegerLimit + 1, type: platform_client_1.FieldTypes.LONG_64 },
|
17
|
-
{ value: signedIntegerLimit * -1 - 2, type: platform_client_1.FieldTypes.LONG_64 },
|
18
|
-
// DOUBLE
|
19
|
-
{ value: 3.14, type: platform_client_1.FieldTypes.DOUBLE },
|
20
|
-
{ value: -1.23, type: platform_client_1.FieldTypes.DOUBLE },
|
21
|
-
{ value: 9.164e-17, type: platform_client_1.FieldTypes.DOUBLE },
|
22
|
-
{ value: -9.1642346778e-175, type: platform_client_1.FieldTypes.DOUBLE },
|
23
|
-
])('value $value should be of type $type', ({ value, type }) => {
|
24
|
-
expect((0, typeUtils_1.getGuessedTypeFromValue)(value)).toBe(type);
|
25
|
-
});
|
26
|
-
describe('when the transition is authorized', () => {
|
27
|
-
it.each([
|
28
|
-
{
|
29
|
-
from: platform_client_1.FieldTypes.LONG,
|
30
|
-
to: platform_client_1.FieldTypes.LONG,
|
31
|
-
expectation: platform_client_1.FieldTypes.LONG,
|
32
|
-
},
|
33
|
-
{
|
34
|
-
from: platform_client_1.FieldTypes.LONG,
|
35
|
-
to: platform_client_1.FieldTypes.LONG_64,
|
36
|
-
expectation: platform_client_1.FieldTypes.LONG_64,
|
37
|
-
},
|
38
|
-
{
|
39
|
-
from: platform_client_1.FieldTypes.LONG,
|
40
|
-
to: platform_client_1.FieldTypes.DOUBLE,
|
41
|
-
expectation: platform_client_1.FieldTypes.DOUBLE,
|
42
|
-
},
|
43
|
-
{
|
44
|
-
from: platform_client_1.FieldTypes.LONG_64,
|
45
|
-
to: platform_client_1.FieldTypes.DOUBLE,
|
46
|
-
expectation: platform_client_1.FieldTypes.DOUBLE,
|
47
|
-
},
|
48
|
-
{
|
49
|
-
from: platform_client_1.FieldTypes.DOUBLE,
|
50
|
-
to: platform_client_1.FieldTypes.DOUBLE,
|
51
|
-
expectation: platform_client_1.FieldTypes.DOUBLE,
|
52
|
-
},
|
53
|
-
{
|
54
|
-
from: platform_client_1.FieldTypes.LONG_64,
|
55
|
-
to: platform_client_1.FieldTypes.LONG,
|
56
|
-
expectation: platform_client_1.FieldTypes.LONG_64,
|
57
|
-
},
|
58
|
-
{
|
59
|
-
from: platform_client_1.FieldTypes.DOUBLE,
|
60
|
-
to: platform_client_1.FieldTypes.LONG_64,
|
61
|
-
expectation: platform_client_1.FieldTypes.DOUBLE,
|
62
|
-
},
|
63
|
-
])('From $from to $to should return $expectation', ({ from, to, expectation }) => {
|
64
|
-
expect((0, typeUtils_1.getMostEnglobingType)(from, to)).toBe(expectation);
|
65
|
-
});
|
66
|
-
});
|
67
|
-
describe('when the transition is not authorized', () => {
|
68
|
-
it.each([
|
69
|
-
{
|
70
|
-
from: platform_client_1.FieldTypes.LONG_64,
|
71
|
-
to: platform_client_1.FieldTypes.STRING,
|
72
|
-
},
|
73
|
-
{
|
74
|
-
from: platform_client_1.FieldTypes.STRING,
|
75
|
-
to: platform_client_1.FieldTypes.LONG,
|
76
|
-
},
|
77
|
-
])('From $from to $to should return $expectation', ({ from, to }) => {
|
78
|
-
expect((0, typeUtils_1.getMostEnglobingType)(from, to)).toBe(null);
|
79
|
-
});
|
80
|
-
});
|
81
|
-
describe('when the value is not a primitive', () => {
|
82
|
-
describe('when the object contains inconsistencies', () => {
|
83
|
-
it.each([
|
84
|
-
{
|
85
|
-
object: {
|
86
|
-
key1: 42,
|
87
|
-
key2: '123',
|
88
|
-
key3: 12.23,
|
89
|
-
},
|
90
|
-
mostEnglobingType: platform_client_1.FieldTypes.STRING,
|
91
|
-
},
|
92
|
-
{
|
93
|
-
object: [42, '123', 12.23],
|
94
|
-
mostEnglobingType: platform_client_1.FieldTypes.STRING,
|
95
|
-
},
|
96
|
-
{
|
97
|
-
object: {
|
98
|
-
key1: 12,
|
99
|
-
key2: 42.32,
|
100
|
-
},
|
101
|
-
mostEnglobingType: platform_client_1.FieldTypes.DOUBLE,
|
102
|
-
},
|
103
|
-
{
|
104
|
-
object: [12, 42.32],
|
105
|
-
mostEnglobingType: platform_client_1.FieldTypes.DOUBLE,
|
106
|
-
},
|
107
|
-
])('should fallback on the most englobing type', ({ object, mostEnglobingType }) => {
|
108
|
-
expect((0, typeUtils_1.getGuessedTypeFromValue)(object)).toEqual(mostEnglobingType);
|
109
|
-
});
|
110
|
-
});
|
111
|
-
describe('when the object does not contain inconsistencies', () => {
|
112
|
-
it.each([
|
113
|
-
{
|
114
|
-
object: {
|
115
|
-
key1: 12,
|
116
|
-
key2: 0,
|
117
|
-
},
|
118
|
-
objectType: platform_client_1.FieldTypes.LONG,
|
119
|
-
},
|
120
|
-
{
|
121
|
-
object: [12, 0],
|
122
|
-
objectType: platform_client_1.FieldTypes.LONG,
|
123
|
-
},
|
124
|
-
])('should fallback on the type of all the object values/elements', ({ object, objectType }) => {
|
125
|
-
expect((0, typeUtils_1.getGuessedTypeFromValue)(object)).toEqual(objectType);
|
126
|
-
});
|
127
|
-
});
|
128
|
-
describe('when the value is a multi-level object', () => {
|
129
|
-
it('should return a string type', () => {
|
130
|
-
const multiLevelObject = {
|
131
|
-
level: {
|
132
|
-
anotherLevel: {
|
133
|
-
anotherLevelDeep: 123,
|
134
|
-
},
|
135
|
-
},
|
136
|
-
};
|
137
|
-
const guessedType = (0, typeUtils_1.getGuessedTypeFromValue)(multiLevelObject);
|
138
|
-
expect(guessedType).toEqual(platform_client_1.FieldTypes.STRING);
|
139
|
-
});
|
140
|
-
});
|
141
|
-
});
|
142
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const platform_client_1 = require("@coveo/platform-client");
|
4
|
+
const typeUtils_1 = require("./typeUtils");
|
5
|
+
describe('typeUtils', () => {
|
6
|
+
const signedIntegerLimit = 0b1111111111111111111111111111111;
|
7
|
+
it.each([
|
8
|
+
// String
|
9
|
+
{ value: 'over 9000', type: platform_client_1.FieldTypes.STRING },
|
10
|
+
// LONG
|
11
|
+
{ value: 0, type: platform_client_1.FieldTypes.LONG },
|
12
|
+
{ value: -10, type: platform_client_1.FieldTypes.LONG },
|
13
|
+
{ value: signedIntegerLimit, type: platform_client_1.FieldTypes.LONG },
|
14
|
+
{ value: 10.0, type: platform_client_1.FieldTypes.LONG },
|
15
|
+
// LONG 64
|
16
|
+
{ value: signedIntegerLimit + 1, type: platform_client_1.FieldTypes.LONG_64 },
|
17
|
+
{ value: signedIntegerLimit * -1 - 2, type: platform_client_1.FieldTypes.LONG_64 },
|
18
|
+
// DOUBLE
|
19
|
+
{ value: 3.14, type: platform_client_1.FieldTypes.DOUBLE },
|
20
|
+
{ value: -1.23, type: platform_client_1.FieldTypes.DOUBLE },
|
21
|
+
{ value: 9.164e-17, type: platform_client_1.FieldTypes.DOUBLE },
|
22
|
+
{ value: -9.1642346778e-175, type: platform_client_1.FieldTypes.DOUBLE },
|
23
|
+
])('value $value should be of type $type', ({ value, type }) => {
|
24
|
+
expect((0, typeUtils_1.getGuessedTypeFromValue)(value)).toBe(type);
|
25
|
+
});
|
26
|
+
describe('when the transition is authorized', () => {
|
27
|
+
it.each([
|
28
|
+
{
|
29
|
+
from: platform_client_1.FieldTypes.LONG,
|
30
|
+
to: platform_client_1.FieldTypes.LONG,
|
31
|
+
expectation: platform_client_1.FieldTypes.LONG,
|
32
|
+
},
|
33
|
+
{
|
34
|
+
from: platform_client_1.FieldTypes.LONG,
|
35
|
+
to: platform_client_1.FieldTypes.LONG_64,
|
36
|
+
expectation: platform_client_1.FieldTypes.LONG_64,
|
37
|
+
},
|
38
|
+
{
|
39
|
+
from: platform_client_1.FieldTypes.LONG,
|
40
|
+
to: platform_client_1.FieldTypes.DOUBLE,
|
41
|
+
expectation: platform_client_1.FieldTypes.DOUBLE,
|
42
|
+
},
|
43
|
+
{
|
44
|
+
from: platform_client_1.FieldTypes.LONG_64,
|
45
|
+
to: platform_client_1.FieldTypes.DOUBLE,
|
46
|
+
expectation: platform_client_1.FieldTypes.DOUBLE,
|
47
|
+
},
|
48
|
+
{
|
49
|
+
from: platform_client_1.FieldTypes.DOUBLE,
|
50
|
+
to: platform_client_1.FieldTypes.DOUBLE,
|
51
|
+
expectation: platform_client_1.FieldTypes.DOUBLE,
|
52
|
+
},
|
53
|
+
{
|
54
|
+
from: platform_client_1.FieldTypes.LONG_64,
|
55
|
+
to: platform_client_1.FieldTypes.LONG,
|
56
|
+
expectation: platform_client_1.FieldTypes.LONG_64,
|
57
|
+
},
|
58
|
+
{
|
59
|
+
from: platform_client_1.FieldTypes.DOUBLE,
|
60
|
+
to: platform_client_1.FieldTypes.LONG_64,
|
61
|
+
expectation: platform_client_1.FieldTypes.DOUBLE,
|
62
|
+
},
|
63
|
+
])('From $from to $to should return $expectation', ({ from, to, expectation }) => {
|
64
|
+
expect((0, typeUtils_1.getMostEnglobingType)(from, to)).toBe(expectation);
|
65
|
+
});
|
66
|
+
});
|
67
|
+
describe('when the transition is not authorized', () => {
|
68
|
+
it.each([
|
69
|
+
{
|
70
|
+
from: platform_client_1.FieldTypes.LONG_64,
|
71
|
+
to: platform_client_1.FieldTypes.STRING,
|
72
|
+
},
|
73
|
+
{
|
74
|
+
from: platform_client_1.FieldTypes.STRING,
|
75
|
+
to: platform_client_1.FieldTypes.LONG,
|
76
|
+
},
|
77
|
+
])('From $from to $to should return $expectation', ({ from, to }) => {
|
78
|
+
expect((0, typeUtils_1.getMostEnglobingType)(from, to)).toBe(null);
|
79
|
+
});
|
80
|
+
});
|
81
|
+
describe('when the value is not a primitive', () => {
|
82
|
+
describe('when the object contains inconsistencies', () => {
|
83
|
+
it.each([
|
84
|
+
{
|
85
|
+
object: {
|
86
|
+
key1: 42,
|
87
|
+
key2: '123',
|
88
|
+
key3: 12.23,
|
89
|
+
},
|
90
|
+
mostEnglobingType: platform_client_1.FieldTypes.STRING,
|
91
|
+
},
|
92
|
+
{
|
93
|
+
object: [42, '123', 12.23],
|
94
|
+
mostEnglobingType: platform_client_1.FieldTypes.STRING,
|
95
|
+
},
|
96
|
+
{
|
97
|
+
object: {
|
98
|
+
key1: 12,
|
99
|
+
key2: 42.32,
|
100
|
+
},
|
101
|
+
mostEnglobingType: platform_client_1.FieldTypes.DOUBLE,
|
102
|
+
},
|
103
|
+
{
|
104
|
+
object: [12, 42.32],
|
105
|
+
mostEnglobingType: platform_client_1.FieldTypes.DOUBLE,
|
106
|
+
},
|
107
|
+
])('should fallback on the most englobing type', ({ object, mostEnglobingType }) => {
|
108
|
+
expect((0, typeUtils_1.getGuessedTypeFromValue)(object)).toEqual(mostEnglobingType);
|
109
|
+
});
|
110
|
+
});
|
111
|
+
describe('when the object does not contain inconsistencies', () => {
|
112
|
+
it.each([
|
113
|
+
{
|
114
|
+
object: {
|
115
|
+
key1: 12,
|
116
|
+
key2: 0,
|
117
|
+
},
|
118
|
+
objectType: platform_client_1.FieldTypes.LONG,
|
119
|
+
},
|
120
|
+
{
|
121
|
+
object: [12, 0],
|
122
|
+
objectType: platform_client_1.FieldTypes.LONG,
|
123
|
+
},
|
124
|
+
])('should fallback on the type of all the object values/elements', ({ object, objectType }) => {
|
125
|
+
expect((0, typeUtils_1.getGuessedTypeFromValue)(object)).toEqual(objectType);
|
126
|
+
});
|
127
|
+
});
|
128
|
+
describe('when the value is a multi-level object', () => {
|
129
|
+
it('should return a string type', () => {
|
130
|
+
const multiLevelObject = {
|
131
|
+
level: {
|
132
|
+
anotherLevel: {
|
133
|
+
anotherLevelDeep: 123,
|
134
|
+
},
|
135
|
+
},
|
136
|
+
};
|
137
|
+
const guessedType = (0, typeUtils_1.getGuessedTypeFromValue)(multiLevelObject);
|
138
|
+
expect(guessedType).toEqual(platform_client_1.FieldTypes.STRING);
|
139
|
+
});
|
140
|
+
});
|
141
|
+
});
|
142
|
+
});
|
143
143
|
//# sourceMappingURL=typeUtils.spec.js.map
|
package/dist/help/file.js
CHANGED
@@ -1,38 +1,38 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getAllJsonFilesFromEntries = exports.isJsonFile = void 0;
|
4
|
-
const fs_1 = require("fs");
|
5
|
-
const path_1 = require("path");
|
6
|
-
const isJsonFile = (documentPath) => {
|
7
|
-
return documentPath.toString().endsWith('.json');
|
8
|
-
};
|
9
|
-
exports.isJsonFile = isJsonFile;
|
10
|
-
const getAllJsonFilesFromEntries = (filesOrDirectories, fileNames = []) => {
|
11
|
-
const uniqueFileNames = [];
|
12
|
-
filesOrDirectories.flatMap((entry) => {
|
13
|
-
if ((0, fs_1.lstatSync)(entry).isDirectory()) {
|
14
|
-
recursiveDirectoryRead(entry, fileNames);
|
15
|
-
}
|
16
|
-
else {
|
17
|
-
fileNames.push(entry);
|
18
|
-
}
|
19
|
-
});
|
20
|
-
for (const file of fileNames) {
|
21
|
-
if (!uniqueFileNames.includes(file) && (0, exports.isJsonFile)(file)) {
|
22
|
-
uniqueFileNames.push(file);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
return uniqueFileNames;
|
26
|
-
};
|
27
|
-
exports.getAllJsonFilesFromEntries = getAllJsonFilesFromEntries;
|
28
|
-
const recursiveDirectoryRead = (folder, accumulator = []) => {
|
29
|
-
(0, fs_1.readdirSync)(folder, { withFileTypes: true }).map((dirent) => {
|
30
|
-
if (dirent.isDirectory()) {
|
31
|
-
recursiveDirectoryRead((0, path_1.join)(folder, dirent.name), accumulator);
|
32
|
-
}
|
33
|
-
else if (dirent.isFile()) {
|
34
|
-
accumulator.push((0, path_1.join)(folder, dirent.name));
|
35
|
-
}
|
36
|
-
});
|
37
|
-
};
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getAllJsonFilesFromEntries = exports.isJsonFile = void 0;
|
4
|
+
const fs_1 = require("fs");
|
5
|
+
const path_1 = require("path");
|
6
|
+
const isJsonFile = (documentPath) => {
|
7
|
+
return documentPath.toString().endsWith('.json');
|
8
|
+
};
|
9
|
+
exports.isJsonFile = isJsonFile;
|
10
|
+
const getAllJsonFilesFromEntries = (filesOrDirectories, fileNames = []) => {
|
11
|
+
const uniqueFileNames = [];
|
12
|
+
filesOrDirectories.flatMap((entry) => {
|
13
|
+
if ((0, fs_1.lstatSync)(entry).isDirectory()) {
|
14
|
+
recursiveDirectoryRead(entry, fileNames);
|
15
|
+
}
|
16
|
+
else {
|
17
|
+
fileNames.push(entry);
|
18
|
+
}
|
19
|
+
});
|
20
|
+
for (const file of fileNames) {
|
21
|
+
if (!uniqueFileNames.includes(file) && (0, exports.isJsonFile)(file)) {
|
22
|
+
uniqueFileNames.push(file);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return uniqueFileNames;
|
26
|
+
};
|
27
|
+
exports.getAllJsonFilesFromEntries = getAllJsonFilesFromEntries;
|
28
|
+
const recursiveDirectoryRead = (folder, accumulator = []) => {
|
29
|
+
(0, fs_1.readdirSync)(folder, { withFileTypes: true }).map((dirent) => {
|
30
|
+
if (dirent.isDirectory()) {
|
31
|
+
recursiveDirectoryRead((0, path_1.join)(folder, dirent.name), accumulator);
|
32
|
+
}
|
33
|
+
else if (dirent.isFile()) {
|
34
|
+
accumulator.push((0, path_1.join)(folder, dirent.name));
|
35
|
+
}
|
36
|
+
});
|
37
|
+
};
|
38
38
|
//# sourceMappingURL=file.js.map
|
package/dist/help/file.spec.js
CHANGED
@@ -1,68 +1,68 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const path_1 = require("path");
|
4
|
-
const process_1 = require("process");
|
5
|
-
const file_1 = require("./file");
|
6
|
-
describe('file', () => {
|
7
|
-
const fileList = [
|
8
|
-
'na/na/na/na/batman.json',
|
9
|
-
'not/a/json/file.txt',
|
10
|
-
'another/json/file.json',
|
11
|
-
];
|
12
|
-
const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
|
13
|
-
it('should filter out non JSON documents', () => {
|
14
|
-
const validFiles = fileList.filter(file_1.isJsonFile);
|
15
|
-
expect(validFiles).toEqual([
|
16
|
-
'na/na/na/na/batman.json',
|
17
|
-
'another/json/file.json',
|
18
|
-
]);
|
19
|
-
});
|
20
|
-
it('should return a list of JSON files', () => {
|
21
|
-
const folders = [(0, path_1.join)(pathToStub, 'mixdocuments')];
|
22
|
-
const files = [
|
23
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
24
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
25
|
-
];
|
26
|
-
const entries = [...files, ...folders];
|
27
|
-
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
28
|
-
expect(validJsonFiles).toEqual([
|
29
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
30
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
31
|
-
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
32
|
-
]);
|
33
|
-
});
|
34
|
-
it('should return an array of unique files', () => {
|
35
|
-
const folders = [(0, path_1.join)(pathToStub, 'mixdocuments')];
|
36
|
-
const files = [
|
37
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
38
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
39
|
-
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
40
|
-
];
|
41
|
-
const entries = [...files, ...folders];
|
42
|
-
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
43
|
-
expect(validJsonFiles).toEqual([
|
44
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
45
|
-
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
46
|
-
]);
|
47
|
-
});
|
48
|
-
it('should recursively read all JSON files in a directory', () => {
|
49
|
-
const folders = [
|
50
|
-
(0, path_1.join)(pathToStub, 'multiplelevelfolder'),
|
51
|
-
(0, path_1.join)(pathToStub, 'mixdocuments'),
|
52
|
-
];
|
53
|
-
const files = [
|
54
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
55
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
56
|
-
];
|
57
|
-
const entries = [...files, ...folders];
|
58
|
-
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
59
|
-
expect(validJsonFiles).toEqual([
|
60
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
61
|
-
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
62
|
-
(0, path_1.join)(pathToStub, 'multiplelevelfolder', 'parent.json'),
|
63
|
-
(0, path_1.join)(pathToStub, 'multiplelevelfolder', 'subfolder', 'child.json'),
|
64
|
-
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
65
|
-
]);
|
66
|
-
});
|
67
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const path_1 = require("path");
|
4
|
+
const process_1 = require("process");
|
5
|
+
const file_1 = require("./file");
|
6
|
+
describe('file', () => {
|
7
|
+
const fileList = [
|
8
|
+
'na/na/na/na/batman.json',
|
9
|
+
'not/a/json/file.txt',
|
10
|
+
'another/json/file.json',
|
11
|
+
];
|
12
|
+
const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
|
13
|
+
it('should filter out non JSON documents', () => {
|
14
|
+
const validFiles = fileList.filter(file_1.isJsonFile);
|
15
|
+
expect(validFiles).toEqual([
|
16
|
+
'na/na/na/na/batman.json',
|
17
|
+
'another/json/file.json',
|
18
|
+
]);
|
19
|
+
});
|
20
|
+
it('should return a list of JSON files', () => {
|
21
|
+
const folders = [(0, path_1.join)(pathToStub, 'mixdocuments')];
|
22
|
+
const files = [
|
23
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
24
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
25
|
+
];
|
26
|
+
const entries = [...files, ...folders];
|
27
|
+
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
28
|
+
expect(validJsonFiles).toEqual([
|
29
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
30
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
31
|
+
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
32
|
+
]);
|
33
|
+
});
|
34
|
+
it('should return an array of unique files', () => {
|
35
|
+
const folders = [(0, path_1.join)(pathToStub, 'mixdocuments')];
|
36
|
+
const files = [
|
37
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
38
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
39
|
+
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
40
|
+
];
|
41
|
+
const entries = [...files, ...folders];
|
42
|
+
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
43
|
+
expect(validJsonFiles).toEqual([
|
44
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
45
|
+
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
46
|
+
]);
|
47
|
+
});
|
48
|
+
it('should recursively read all JSON files in a directory', () => {
|
49
|
+
const folders = [
|
50
|
+
(0, path_1.join)(pathToStub, 'multiplelevelfolder'),
|
51
|
+
(0, path_1.join)(pathToStub, 'mixdocuments'),
|
52
|
+
];
|
53
|
+
const files = [
|
54
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
55
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
56
|
+
];
|
57
|
+
const entries = [...files, ...folders];
|
58
|
+
const validJsonFiles = (0, file_1.getAllJsonFilesFromEntries)(entries);
|
59
|
+
expect(validJsonFiles).toEqual([
|
60
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'batman.json'),
|
61
|
+
(0, path_1.join)(pathToStub, 'jsondocuments', 'fightclub.json'),
|
62
|
+
(0, path_1.join)(pathToStub, 'multiplelevelfolder', 'parent.json'),
|
63
|
+
(0, path_1.join)(pathToStub, 'multiplelevelfolder', 'subfolder', 'child.json'),
|
64
|
+
(0, path_1.join)(pathToStub, 'mixdocuments', 'valid.json'),
|
65
|
+
]);
|
66
|
+
});
|
67
|
+
});
|
68
68
|
//# sourceMappingURL=file.spec.js.map
|