@sprucelabs/mercury-chunking-emitter 1.1.1 → 1.1.3
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/README.md +1 -0
- package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
- package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +25 -0
- package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
- package/build/.spruce/schemas/fields/fieldClassMap.js +4 -0
- package/{src/.spruce/schemas/fields/fields.types.ts → build/.spruce/schemas/fields/fields.types.d.ts} +1 -1
- package/build/.spruce/schemas/fields/fields.types.js +2 -0
- package/build/.spruce/schemas/schemas.types.d.ts +33 -0
- package/build/.spruce/schemas/schemas.types.js +4 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/choice.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/choice.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/link.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/link.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/location.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/location.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/message.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/message.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/organization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/organization.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/person.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/person.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/role.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/role.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/skill.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skill.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.js +5 -0
- package/{src/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.d.ts} +1 -1
- package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.js +5 -0
- package/build/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
- package/build/chunkingEmitter/ChunkingEmitter.js +71 -0
- package/build/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
- package/build/chunkingEmitter/MockChunkingEmitter.js +54 -0
- package/build/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
- package/build/chunkingEmitter/chunkFieldDefinition.js +17 -0
- package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
- package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +23 -0
- package/build/esm/.spruce/schemas/schemas.types.d.ts +33 -0
- package/build/esm/.spruce/schemas/schemas.types.js +3 -0
- package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
- package/build/esm/chunkingEmitter/ChunkingEmitter.js +81 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
- package/build/esm/chunkingEmitter/MockChunkingEmitter.js +62 -0
- package/build/esm/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
- package/build/esm/chunkingEmitter/chunkFieldDefinition.js +10 -0
- package/{src/index.ts → build/esm/index.d.ts} +3 -3
- package/build/esm/index.js +1 -0
- package/build/esm/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
- package/build/esm/schemas/v2023_10_21/chunkPaging.builder.js +15 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +8 -0
- package/build/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
- package/build/schemas/v2023_10_21/chunkPaging.builder.js +17 -0
- package/package.json +14 -6
- package/.circleci/config.yml +0 -71
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -3
- package/.githooks/pre-push +0 -17
- package/.nvmrc +0 -1
- package/.vscode/launch.json +0 -58
- package/.vscode/settings.json +0 -70
- package/.vscode/tasks.json +0 -112
- package/CHANGELOG.md +0 -25
- package/release.config.js +0 -7
- package/src/.spruce/features/permission.plugin.ts +0 -1
- package/src/.spruce/permissions/permissions.types.ts +0 -9
- package/src/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.ts +0 -29
- package/src/.spruce/schemas/fields/fieldClassMap.ts +0 -6
- package/src/.spruce/schemas/schemas.types.ts +0 -52
- package/src/__tests__/behavioral/ChunkingEmitter.test.ts +0 -290
- package/src/__tests__/behavioral/TestingChunkingEmitter.test.ts +0 -174
- package/src/__tests__/support/AbstractChunkingEmitterTest.ts +0 -54
- package/src/chunkingEmitter/ChunkingEmitter.ts +0 -107
- package/src/chunkingEmitter/MockChunkingEmitter.ts +0 -101
- package/src/chunkingEmitter/chunkFieldDefinition.ts +0 -12
- package/src/schemas/v2023_10_21/chunkPaging.builder.ts +0 -16
- package/tsconfig.dist.json +0 -36
- package/tsconfig.json +0 -40
- /package/{src → build}/.spruce/settings.json +0 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Spruce XP Documentation
|
|
|
19
19
|
<a href="https://developer.spruce.ai/#/"><img width="250" src="https://raw.githubusercontent.com/sprucelabsai/data-stores/master/docs/images/read-full-docs.png" /></a>
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
|
+
|
|
22
23
|
### Dependencies
|
|
23
24
|
|
|
24
25
|
[Arkit diagram here](docs/dependencies.md).
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const chunkPagingSchema = {
|
|
5
|
+
id: 'chunkPaging',
|
|
6
|
+
version: 'v2023_10_21',
|
|
7
|
+
namespace: 'ChunkingEmitter',
|
|
8
|
+
name: 'Chunk Paging',
|
|
9
|
+
fields: {
|
|
10
|
+
/** . */
|
|
11
|
+
'total': {
|
|
12
|
+
type: 'number',
|
|
13
|
+
isRequired: true,
|
|
14
|
+
options: undefined
|
|
15
|
+
},
|
|
16
|
+
/** . */
|
|
17
|
+
'current': {
|
|
18
|
+
type: 'number',
|
|
19
|
+
isRequired: true,
|
|
20
|
+
options: undefined
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
schema_1.SchemaRegistry.getInstance().trackSchema(chunkPagingSchema);
|
|
25
|
+
exports.default = chunkPagingSchema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema'
|
|
1
|
+
export { FieldDefinitions, FieldDefinitionMap, FieldValueTypeGeneratorMap, FieldMap } from '@sprucelabs/schema';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { SpruceSchemas } from '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types';
|
|
2
|
+
import { default as SchemaEntity } from '@sprucelabs/schema';
|
|
3
|
+
import * as SpruceSchema from '@sprucelabs/schema';
|
|
4
|
+
declare module '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types' {
|
|
5
|
+
namespace SpruceSchemas.ChunkingEmitter.v2023_10_21 {
|
|
6
|
+
interface ChunkPaging {
|
|
7
|
+
'total': number;
|
|
8
|
+
'current': number;
|
|
9
|
+
}
|
|
10
|
+
interface ChunkPagingSchema extends SpruceSchema.Schema {
|
|
11
|
+
id: 'chunkPaging';
|
|
12
|
+
version: 'v2023_10_21';
|
|
13
|
+
namespace: 'ChunkingEmitter';
|
|
14
|
+
name: 'Chunk Paging';
|
|
15
|
+
fields: {
|
|
16
|
+
/** . */
|
|
17
|
+
'total': {
|
|
18
|
+
type: 'number';
|
|
19
|
+
isRequired: true;
|
|
20
|
+
options: undefined;
|
|
21
|
+
};
|
|
22
|
+
/** . */
|
|
23
|
+
'current': {
|
|
24
|
+
type: 'number';
|
|
25
|
+
isRequired: true;
|
|
26
|
+
options: undefined;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface ChunkPagingEntity extends SchemaEntity<SpruceSchemas.ChunkingEmitter.v2023_10_21.ChunkPagingSchema> {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { choiceSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { choiceSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.choiceSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { linkSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { linkSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.linkSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { locationSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { locationSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.locationSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { messageSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { messageSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.messageSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { messageSourceSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { messageSourceSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.messageSourceSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { messageTargetSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { messageTargetSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.messageTargetSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { organizationSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { organizationSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.organizationSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { personSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { personSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.personSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { personLocationSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { personLocationSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.personLocationSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { personOrganizationSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { personOrganizationSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.personOrganizationSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { roleSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { roleSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.roleSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { sendMessageSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { sendMessageSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.sendMessageSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { skillSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { skillSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.skillSchema; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { skillCreatorSchema as default } from '@sprucelabs/spruce-core-schemas'
|
|
1
|
+
export { skillCreatorSchema as default } from '@sprucelabs/spruce-core-schemas';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = void 0;
|
|
4
|
+
var spruce_core_schemas_1 = require("@sprucelabs/spruce-core-schemas");
|
|
5
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return spruce_core_schemas_1.skillCreatorSchema; } });
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
2
|
+
import { EventName } from '@sprucelabs/mercury-types';
|
|
3
|
+
export default class ChunkingEmitterImpl {
|
|
4
|
+
private client;
|
|
5
|
+
protected chunkSize: number;
|
|
6
|
+
private log;
|
|
7
|
+
static Class?: new (options: ChunkingEmitterOptions) => ChunkingEmitter;
|
|
8
|
+
private totalErrors;
|
|
9
|
+
protected constructor(options: ChunkingEmitterOptions);
|
|
10
|
+
static Emitter(options: ChunkingEmitterOptions): Promise<ChunkingEmitter>;
|
|
11
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
12
|
+
static reset(): void;
|
|
13
|
+
private splitItemsIntoChunks;
|
|
14
|
+
getTotalErrors(): number;
|
|
15
|
+
}
|
|
16
|
+
interface ChunkingEmitterOptions {
|
|
17
|
+
client: MercuryClient;
|
|
18
|
+
chunkSize?: number;
|
|
19
|
+
}
|
|
20
|
+
type ChunkingEmitterEmitOptions = {
|
|
21
|
+
eventName: EventName;
|
|
22
|
+
items: Record<string, any>[];
|
|
23
|
+
payloadKey: string;
|
|
24
|
+
target?: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
export interface ChunkingEmitter {
|
|
27
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
28
|
+
getTotalErrors(): number;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@sprucelabs/schema");
|
|
4
|
+
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
|
|
5
|
+
class ChunkingEmitterImpl {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.log = (0, spruce_skill_utils_1.buildLog)('ChunkingEmitter');
|
|
8
|
+
this.totalErrors = 0;
|
|
9
|
+
const { client, chunkSize } = (0, schema_1.assertOptions)(options, ['client']);
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.chunkSize = chunkSize !== null && chunkSize !== void 0 ? chunkSize : 10;
|
|
12
|
+
}
|
|
13
|
+
static async Emitter(options) {
|
|
14
|
+
var _a;
|
|
15
|
+
(0, schema_1.assertOptions)(options, ['client']);
|
|
16
|
+
return new ((_a = this.Class) !== null && _a !== void 0 ? _a : this)(options);
|
|
17
|
+
}
|
|
18
|
+
async emit(options) {
|
|
19
|
+
const { eventName, items, payloadKey, target } = (0, schema_1.assertOptions)(options, [
|
|
20
|
+
'eventName',
|
|
21
|
+
'items',
|
|
22
|
+
'payloadKey',
|
|
23
|
+
]);
|
|
24
|
+
this.totalErrors = 0;
|
|
25
|
+
const chunks = this.splitItemsIntoChunks(items);
|
|
26
|
+
let current = 0;
|
|
27
|
+
for (const chunk of chunks) {
|
|
28
|
+
try {
|
|
29
|
+
let targetAndPayload = {
|
|
30
|
+
payload: {
|
|
31
|
+
[payloadKey]: chunk,
|
|
32
|
+
chunk: {
|
|
33
|
+
current: current++,
|
|
34
|
+
total: chunks.length,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
if (target) {
|
|
39
|
+
targetAndPayload.target = target;
|
|
40
|
+
}
|
|
41
|
+
await this.client.emitAndFlattenResponses(eventName, targetAndPayload);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
this.log.error('Failed to emit chunk', err);
|
|
45
|
+
this.totalErrors++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
static reset() {
|
|
50
|
+
this.Class = undefined;
|
|
51
|
+
}
|
|
52
|
+
splitItemsIntoChunks(items) {
|
|
53
|
+
const chunks = [];
|
|
54
|
+
let index = 0;
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
if (!chunks[index]) {
|
|
57
|
+
chunks[index] = [];
|
|
58
|
+
}
|
|
59
|
+
if (chunks[index].length === this.chunkSize) {
|
|
60
|
+
index++;
|
|
61
|
+
chunks[index] = [];
|
|
62
|
+
}
|
|
63
|
+
chunks[index].push(item);
|
|
64
|
+
}
|
|
65
|
+
return chunks;
|
|
66
|
+
}
|
|
67
|
+
getTotalErrors() {
|
|
68
|
+
return this.totalErrors;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = ChunkingEmitterImpl;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventName } from '@sprucelabs/mercury-types';
|
|
2
|
+
import { ChunkingEmitter } from './ChunkingEmitter';
|
|
3
|
+
export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
4
|
+
private didEmit;
|
|
5
|
+
private emittedEventName?;
|
|
6
|
+
private emittedItems?;
|
|
7
|
+
private emittedPayloadKey?;
|
|
8
|
+
static lastInstance?: MockChunkingEmitter;
|
|
9
|
+
constructor();
|
|
10
|
+
static getLastInstance(): MockChunkingEmitter;
|
|
11
|
+
static reset(): void;
|
|
12
|
+
emit(options: {
|
|
13
|
+
eventName: EventName;
|
|
14
|
+
items: Record<string, unknown>[];
|
|
15
|
+
payloadKey: string;
|
|
16
|
+
}): Promise<void>;
|
|
17
|
+
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
18
|
+
getTotalErrors(): number;
|
|
19
|
+
assertEmittedItems(items: Record<string, any>[]): void;
|
|
20
|
+
assertDidEmit(): void;
|
|
21
|
+
assertDidEmitEventNamed(fqen: EventName): void;
|
|
22
|
+
assertEventHonorsChunkingSignature(fqen: EventName): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const mercury_client_1 = require("@sprucelabs/mercury-client");
|
|
4
|
+
const test_utils_1 = require("@sprucelabs/test-utils");
|
|
5
|
+
const chunkFieldDefinition_1 = require("./chunkFieldDefinition");
|
|
6
|
+
class MockChunkingEmitter {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.didEmit = false;
|
|
9
|
+
MockChunkingEmitter.lastInstance = this;
|
|
10
|
+
}
|
|
11
|
+
static getLastInstance() {
|
|
12
|
+
test_utils_1.assert.isTruthy(this.lastInstance, 'You have not constructed a ChunkingEmitter! Try ChunkingEmitterImpl.Emitter({})');
|
|
13
|
+
return this.lastInstance;
|
|
14
|
+
}
|
|
15
|
+
static reset() {
|
|
16
|
+
this.lastInstance = undefined;
|
|
17
|
+
}
|
|
18
|
+
async emit(options) {
|
|
19
|
+
const { eventName, items, payloadKey } = options;
|
|
20
|
+
this.didEmit = true;
|
|
21
|
+
this.emittedEventName = eventName;
|
|
22
|
+
this.emittedItems = items;
|
|
23
|
+
this.emittedPayloadKey = payloadKey;
|
|
24
|
+
}
|
|
25
|
+
assertDidEmitPayloadKey(payloadKey) {
|
|
26
|
+
this.assertDidEmit();
|
|
27
|
+
test_utils_1.assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
28
|
+
}
|
|
29
|
+
getTotalErrors() {
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
assertEmittedItems(items) {
|
|
33
|
+
this.assertDidEmit();
|
|
34
|
+
test_utils_1.assert.isEqualDeep(this.emittedItems, items, 'You did not chunkingEmitter.emit(...) the expected items!!');
|
|
35
|
+
}
|
|
36
|
+
assertDidEmit() {
|
|
37
|
+
test_utils_1.assert.isTrue(this.didEmit, `You did not ever call chunkingEmitter.emit(...). That is your next step!`);
|
|
38
|
+
}
|
|
39
|
+
assertDidEmitEventNamed(fqen) {
|
|
40
|
+
this.assertDidEmit();
|
|
41
|
+
test_utils_1.assert.isEqual(this.emittedEventName, fqen, `I expected chunkingEmitter to emit '${fqen}'! But you emitted ${this.emittedEventName || 'nothing'}`);
|
|
42
|
+
}
|
|
43
|
+
assertEventHonorsChunkingSignature(fqen) {
|
|
44
|
+
var _a, _b, _c, _d, _e, _f;
|
|
45
|
+
const emitter = mercury_client_1.MercuryTestClient.getInternalEmitter();
|
|
46
|
+
const contract = emitter.getContract();
|
|
47
|
+
const payload = (_b = (_a = contract.eventSignatures[fqen]) === null || _a === void 0 ? void 0 : _a.emitPayloadSchema) === null || _b === void 0 ? void 0 : _b.fields;
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
const chunkField = (_f = (_e = (_d = (_c = payload === null || payload === void 0 ? void 0 : payload.payload) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.schema) === null || _e === void 0 ? void 0 : _e.fields) === null || _f === void 0 ? void 0 : _f.chunk;
|
|
50
|
+
test_utils_1.assert.isTruthy(chunkField, 'Your event does not conform to the chunking signature. Please add a chunk field to your event payload. Add a field to your payload called chunk: chunkFieldDefinition()');
|
|
51
|
+
test_utils_1.assert.isEqualDeep(chunkField, (0, chunkFieldDefinition_1.chunkFieldDefinition)(), 'Your chunk field is there but not properly formed. Use chunkFieldDefinition() to define it.');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.default = MockChunkingEmitter;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.chunkFieldDefinition = void 0;
|
|
7
|
+
const chunkPaging_schema_1 = __importDefault(require("./../.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema"));
|
|
8
|
+
function chunkFieldDefinition() {
|
|
9
|
+
return {
|
|
10
|
+
type: 'schema',
|
|
11
|
+
isRequired: true,
|
|
12
|
+
options: {
|
|
13
|
+
schema: chunkPaging_schema_1.default,
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.chunkFieldDefinition = chunkFieldDefinition;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SchemaRegistry } from '@sprucelabs/schema';
|
|
2
|
+
const chunkPagingSchema = {
|
|
3
|
+
id: 'chunkPaging',
|
|
4
|
+
version: 'v2023_10_21',
|
|
5
|
+
namespace: 'ChunkingEmitter',
|
|
6
|
+
name: 'Chunk Paging',
|
|
7
|
+
fields: {
|
|
8
|
+
/** . */
|
|
9
|
+
'total': {
|
|
10
|
+
type: 'number',
|
|
11
|
+
isRequired: true,
|
|
12
|
+
options: undefined
|
|
13
|
+
},
|
|
14
|
+
/** . */
|
|
15
|
+
'current': {
|
|
16
|
+
type: 'number',
|
|
17
|
+
isRequired: true,
|
|
18
|
+
options: undefined
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
SchemaRegistry.getInstance().trackSchema(chunkPagingSchema);
|
|
23
|
+
export default chunkPagingSchema;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export { SpruceSchemas } from '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types';
|
|
2
|
+
import { default as SchemaEntity } from '@sprucelabs/schema';
|
|
3
|
+
import * as SpruceSchema from '@sprucelabs/schema';
|
|
4
|
+
declare module '@sprucelabs/spruce-core-schemas/build/.spruce/schemas/core.schemas.types' {
|
|
5
|
+
namespace SpruceSchemas.ChunkingEmitter.v2023_10_21 {
|
|
6
|
+
interface ChunkPaging {
|
|
7
|
+
'total': number;
|
|
8
|
+
'current': number;
|
|
9
|
+
}
|
|
10
|
+
interface ChunkPagingSchema extends SpruceSchema.Schema {
|
|
11
|
+
id: 'chunkPaging';
|
|
12
|
+
version: 'v2023_10_21';
|
|
13
|
+
namespace: 'ChunkingEmitter';
|
|
14
|
+
name: 'Chunk Paging';
|
|
15
|
+
fields: {
|
|
16
|
+
/** . */
|
|
17
|
+
'total': {
|
|
18
|
+
type: 'number';
|
|
19
|
+
isRequired: true;
|
|
20
|
+
options: undefined;
|
|
21
|
+
};
|
|
22
|
+
/** . */
|
|
23
|
+
'current': {
|
|
24
|
+
type: 'number';
|
|
25
|
+
isRequired: true;
|
|
26
|
+
options: undefined;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
interface ChunkPagingEntity extends SchemaEntity<SpruceSchemas.ChunkingEmitter.v2023_10_21.ChunkPagingSchema> {
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MercuryClient } from '@sprucelabs/mercury-client';
|
|
2
|
+
import { EventName } from '@sprucelabs/mercury-types';
|
|
3
|
+
export default class ChunkingEmitterImpl {
|
|
4
|
+
private client;
|
|
5
|
+
protected chunkSize: number;
|
|
6
|
+
private log;
|
|
7
|
+
static Class?: new (options: ChunkingEmitterOptions) => ChunkingEmitter;
|
|
8
|
+
private totalErrors;
|
|
9
|
+
protected constructor(options: ChunkingEmitterOptions);
|
|
10
|
+
static Emitter(options: ChunkingEmitterOptions): Promise<ChunkingEmitter>;
|
|
11
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
12
|
+
static reset(): void;
|
|
13
|
+
private splitItemsIntoChunks;
|
|
14
|
+
getTotalErrors(): number;
|
|
15
|
+
}
|
|
16
|
+
interface ChunkingEmitterOptions {
|
|
17
|
+
client: MercuryClient;
|
|
18
|
+
chunkSize?: number;
|
|
19
|
+
}
|
|
20
|
+
type ChunkingEmitterEmitOptions = {
|
|
21
|
+
eventName: EventName;
|
|
22
|
+
items: Record<string, any>[];
|
|
23
|
+
payloadKey: string;
|
|
24
|
+
target?: Record<string, any>;
|
|
25
|
+
};
|
|
26
|
+
export interface ChunkingEmitter {
|
|
27
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
28
|
+
getTotalErrors(): number;
|
|
29
|
+
}
|
|
30
|
+
export {};
|