@sprucelabs/mercury-chunking-emitter 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/{src/.spruce/features/permission.plugin.ts → build/.spruce/features/permission.plugin.d.ts} +1 -1
  2. package/build/.spruce/features/permission.plugin.js +5 -0
  3. package/build/.spruce/permissions/permissions.types.d.ts +7 -0
  4. package/build/.spruce/permissions/permissions.types.js +3 -0
  5. package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
  6. package/build/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +25 -0
  7. package/build/.spruce/schemas/fields/fieldClassMap.d.ts +2 -0
  8. package/build/.spruce/schemas/fields/fieldClassMap.js +4 -0
  9. package/{src/.spruce/schemas/fields/fields.types.ts → build/.spruce/schemas/fields/fields.types.d.ts} +1 -1
  10. package/build/.spruce/schemas/fields/fields.types.js +2 -0
  11. package/build/.spruce/schemas/schemas.types.d.ts +33 -0
  12. package/build/.spruce/schemas/schemas.types.js +4 -0
  13. package/{src/.spruce/schemas/spruce/v2020_07_22/choice.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/choice.schema.d.ts} +1 -1
  14. package/build/.spruce/schemas/spruce/v2020_07_22/choice.schema.js +5 -0
  15. package/{src/.spruce/schemas/spruce/v2020_07_22/link.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/link.schema.d.ts} +1 -1
  16. package/build/.spruce/schemas/spruce/v2020_07_22/link.schema.js +5 -0
  17. package/{src/.spruce/schemas/spruce/v2020_07_22/location.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/location.schema.d.ts} +1 -1
  18. package/build/.spruce/schemas/spruce/v2020_07_22/location.schema.js +5 -0
  19. package/{src/.spruce/schemas/spruce/v2020_07_22/message.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/message.schema.d.ts} +1 -1
  20. package/build/.spruce/schemas/spruce/v2020_07_22/message.schema.js +5 -0
  21. package/{src/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.d.ts} +1 -1
  22. package/build/.spruce/schemas/spruce/v2020_07_22/messageSource.schema.js +5 -0
  23. package/{src/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.d.ts} +1 -1
  24. package/build/.spruce/schemas/spruce/v2020_07_22/messageTarget.schema.js +5 -0
  25. package/{src/.spruce/schemas/spruce/v2020_07_22/organization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/organization.schema.d.ts} +1 -1
  26. package/build/.spruce/schemas/spruce/v2020_07_22/organization.schema.js +5 -0
  27. package/{src/.spruce/schemas/spruce/v2020_07_22/person.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/person.schema.d.ts} +1 -1
  28. package/build/.spruce/schemas/spruce/v2020_07_22/person.schema.js +5 -0
  29. package/{src/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.d.ts} +1 -1
  30. package/build/.spruce/schemas/spruce/v2020_07_22/personLocation.schema.js +5 -0
  31. package/{src/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.d.ts} +1 -1
  32. package/build/.spruce/schemas/spruce/v2020_07_22/personOrganization.schema.js +5 -0
  33. package/{src/.spruce/schemas/spruce/v2020_07_22/role.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/role.schema.d.ts} +1 -1
  34. package/build/.spruce/schemas/spruce/v2020_07_22/role.schema.js +5 -0
  35. package/{src/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.d.ts} +1 -1
  36. package/build/.spruce/schemas/spruce/v2020_07_22/sendMessage.schema.js +5 -0
  37. package/{src/.spruce/schemas/spruce/v2020_07_22/skill.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skill.schema.d.ts} +1 -1
  38. package/build/.spruce/schemas/spruce/v2020_07_22/skill.schema.js +5 -0
  39. package/{src/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.ts → build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.d.ts} +1 -1
  40. package/build/.spruce/schemas/spruce/v2020_07_22/skillCreator.schema.js +5 -0
  41. package/build/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
  42. package/build/chunkingEmitter/ChunkingEmitter.js +71 -0
  43. package/build/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
  44. package/build/chunkingEmitter/MockChunkingEmitter.js +54 -0
  45. package/build/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
  46. package/build/chunkingEmitter/chunkFieldDefinition.js +17 -0
  47. package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.d.ts +3 -0
  48. package/build/esm/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.js +23 -0
  49. package/build/esm/.spruce/schemas/schemas.types.d.ts +33 -0
  50. package/build/esm/.spruce/schemas/schemas.types.js +3 -0
  51. package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +30 -0
  52. package/build/esm/chunkingEmitter/ChunkingEmitter.js +81 -0
  53. package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +23 -0
  54. package/build/esm/chunkingEmitter/MockChunkingEmitter.js +62 -0
  55. package/build/esm/chunkingEmitter/chunkFieldDefinition.d.ts +2 -0
  56. package/build/esm/chunkingEmitter/chunkFieldDefinition.js +10 -0
  57. package/{src/index.ts → build/esm/index.d.ts} +3 -3
  58. package/build/esm/index.js +1 -0
  59. package/build/esm/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
  60. package/build/esm/schemas/v2023_10_21/chunkPaging.builder.js +15 -0
  61. package/build/index.d.ts +3 -0
  62. package/build/index.js +8 -0
  63. package/build/schemas/v2023_10_21/chunkPaging.builder.d.ts +15 -0
  64. package/build/schemas/v2023_10_21/chunkPaging.builder.js +17 -0
  65. package/package.json +6 -1
  66. package/.circleci/config.yml +0 -71
  67. package/.eslintignore +0 -3
  68. package/.eslintrc.js +0 -3
  69. package/.githooks/pre-push +0 -17
  70. package/.nvmrc +0 -1
  71. package/.vscode/launch.json +0 -58
  72. package/.vscode/settings.json +0 -70
  73. package/.vscode/tasks.json +0 -112
  74. package/CHANGELOG.md +0 -25
  75. package/release.config.js +0 -7
  76. package/src/.spruce/permissions/permissions.types.ts +0 -9
  77. package/src/.spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema.ts +0 -29
  78. package/src/.spruce/schemas/fields/fieldClassMap.ts +0 -6
  79. package/src/.spruce/schemas/schemas.types.ts +0 -52
  80. package/src/__tests__/behavioral/ChunkingEmitter.test.ts +0 -290
  81. package/src/__tests__/behavioral/TestingChunkingEmitter.test.ts +0 -174
  82. package/src/__tests__/support/AbstractChunkingEmitterTest.ts +0 -54
  83. package/src/chunkingEmitter/ChunkingEmitter.ts +0 -107
  84. package/src/chunkingEmitter/MockChunkingEmitter.ts +0 -101
  85. package/src/chunkingEmitter/chunkFieldDefinition.ts +0 -12
  86. package/src/schemas/v2023_10_21/chunkPaging.builder.ts +0 -16
  87. package/tsconfig.dist.json +0 -36
  88. package/tsconfig.json +0 -40
  89. /package/{src → build}/.spruce/settings.json +0 -0
@@ -1,107 +0,0 @@
1
- import { MercuryClient } from '@sprucelabs/mercury-client'
2
- import { EventName } from '@sprucelabs/mercury-types'
3
- import { assertOptions } from '@sprucelabs/schema'
4
- import { buildLog } from '@sprucelabs/spruce-skill-utils'
5
-
6
- export default class ChunkingEmitterImpl {
7
- private client: MercuryClient
8
- protected chunkSize: number
9
- private log = buildLog('ChunkingEmitter')
10
- public static Class?: new (options: ChunkingEmitterOptions) => ChunkingEmitter
11
- private totalErrors = 0
12
-
13
- protected constructor(options: ChunkingEmitterOptions) {
14
- const { client, chunkSize } = assertOptions(options, ['client'])
15
- this.client = client
16
- this.chunkSize = chunkSize ?? 10
17
- }
18
-
19
- public static async Emitter(options: ChunkingEmitterOptions) {
20
- assertOptions(options, ['client'])
21
- return new (this.Class ?? this)(options)
22
- }
23
-
24
- public async emit(options: ChunkingEmitterEmitOptions) {
25
- const { eventName, items, payloadKey, target } = assertOptions(options, [
26
- 'eventName',
27
- 'items',
28
- 'payloadKey',
29
- ])
30
-
31
- this.totalErrors = 0
32
- const chunks = this.splitItemsIntoChunks(items)
33
- let current = 0
34
-
35
- for (const chunk of chunks) {
36
- try {
37
- let targetAndPayload: Record<string, any> = {
38
- payload: {
39
- [payloadKey]: chunk,
40
- chunk: {
41
- current: current++,
42
- total: chunks.length,
43
- },
44
- },
45
- }
46
-
47
- if (target) {
48
- targetAndPayload.target = target
49
- }
50
-
51
- await this.client.emitAndFlattenResponses(
52
- eventName as EventName,
53
- targetAndPayload
54
- )
55
- } catch (err: any) {
56
- this.log.error('Failed to emit chunk', err)
57
- this.totalErrors++
58
- }
59
- }
60
- }
61
-
62
- public static reset() {
63
- this.Class = undefined
64
- }
65
-
66
- private splitItemsIntoChunks(items: Record<string, any>[]) {
67
- const chunks: Record<string, any>[][] = []
68
-
69
- let index = 0
70
-
71
- for (const item of items) {
72
- if (!chunks[index]) {
73
- chunks[index] = []
74
- }
75
-
76
- if (chunks[index].length === this.chunkSize) {
77
- index++
78
- chunks[index] = []
79
- }
80
-
81
- chunks[index].push(item)
82
- }
83
-
84
- return chunks
85
- }
86
-
87
- public getTotalErrors(): number {
88
- return this.totalErrors
89
- }
90
- }
91
-
92
- interface ChunkingEmitterOptions {
93
- client: MercuryClient
94
- chunkSize?: number
95
- }
96
-
97
- type ChunkingEmitterEmitOptions = {
98
- eventName: EventName
99
- items: Record<string, any>[]
100
- payloadKey: string
101
- target?: Record<string, any>
102
- }
103
-
104
- export interface ChunkingEmitter {
105
- emit(options: ChunkingEmitterEmitOptions): Promise<void>
106
- getTotalErrors(): number
107
- }
@@ -1,101 +0,0 @@
1
- import { MercuryTestClient } from '@sprucelabs/mercury-client'
2
- import { EventName } from '@sprucelabs/mercury-types'
3
- import { assert } from '@sprucelabs/test-utils'
4
- import { chunkFieldDefinition } from './chunkFieldDefinition'
5
- import { ChunkingEmitter } from './ChunkingEmitter'
6
-
7
- export default class MockChunkingEmitter implements ChunkingEmitter {
8
- private didEmit = false
9
- private emittedEventName?: EventName
10
- private emittedItems?: Record<string, unknown>[]
11
- private emittedPayloadKey?: string
12
- public static lastInstance?: MockChunkingEmitter
13
-
14
- public constructor() {
15
- MockChunkingEmitter.lastInstance = this
16
- }
17
-
18
- public static getLastInstance() {
19
- assert.isTruthy(
20
- this.lastInstance,
21
- 'You have not constructed a ChunkingEmitter! Try ChunkingEmitterImpl.Emitter({})'
22
- )
23
- return this.lastInstance
24
- }
25
-
26
- public static reset() {
27
- this.lastInstance = undefined
28
- }
29
-
30
- public async emit(options: {
31
- eventName: EventName
32
- items: Record<string, unknown>[]
33
- payloadKey: string
34
- }): Promise<void> {
35
- const { eventName, items, payloadKey } = options
36
- this.didEmit = true
37
- this.emittedEventName = eventName
38
- this.emittedItems = items
39
- this.emittedPayloadKey = payloadKey
40
- }
41
-
42
- public assertDidEmitPayloadKey(payloadKey: string) {
43
- this.assertDidEmit()
44
- assert.isEqual(
45
- this.emittedPayloadKey,
46
- payloadKey,
47
- `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${
48
- this.emittedPayloadKey || 'nothing'
49
- }`
50
- )
51
- }
52
-
53
- public getTotalErrors(): number {
54
- return 0
55
- }
56
-
57
- public assertEmittedItems(items: Record<string, any>[]) {
58
- this.assertDidEmit()
59
- assert.isEqualDeep(
60
- this.emittedItems,
61
- items,
62
- 'You did not chunkingEmitter.emit(...) the expected items!!'
63
- )
64
- }
65
-
66
- public assertDidEmit() {
67
- assert.isTrue(
68
- this.didEmit,
69
- `You did not ever call chunkingEmitter.emit(...). That is your next step!`
70
- )
71
- }
72
-
73
- public assertDidEmitEventNamed(fqen: EventName) {
74
- this.assertDidEmit()
75
- assert.isEqual(
76
- this.emittedEventName,
77
- fqen,
78
- `I expected chunkingEmitter to emit '${fqen}'! But you emitted ${
79
- this.emittedEventName || 'nothing'
80
- }`
81
- )
82
- }
83
-
84
- public assertEventHonorsChunkingSignature(fqen: EventName) {
85
- const emitter = MercuryTestClient.getInternalEmitter()
86
- const contract = emitter.getContract()
87
- const payload = contract.eventSignatures[fqen]?.emitPayloadSchema?.fields
88
- // @ts-ignore
89
- const chunkField = payload?.payload?.options?.schema?.fields?.chunk
90
- assert.isTruthy(
91
- chunkField,
92
- '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()'
93
- )
94
-
95
- assert.isEqualDeep(
96
- chunkField,
97
- chunkFieldDefinition(),
98
- 'Your chunk field is there but not properly formed. Use chunkFieldDefinition() to define it.'
99
- )
100
- }
101
- }
@@ -1,12 +0,0 @@
1
- import { FieldDefinitions } from '@sprucelabs/schema'
2
- import chunkPagingSchema from '#spruce/schemas/chunkingEmitter/v2023_10_21/chunkPaging.schema'
3
-
4
- export function chunkFieldDefinition() {
5
- return {
6
- type: 'schema',
7
- isRequired: true,
8
- options: {
9
- schema: chunkPagingSchema,
10
- },
11
- } as FieldDefinitions
12
- }
@@ -1,16 +0,0 @@
1
- import { buildSchema } from '@sprucelabs/schema'
2
-
3
- export default buildSchema({
4
- id: 'chunkPaging',
5
- name: 'Chunk Paging',
6
- fields: {
7
- total: {
8
- type: 'number',
9
- isRequired: true,
10
- },
11
- current: {
12
- type: 'number',
13
- isRequired: true,
14
- },
15
- },
16
- })
@@ -1,36 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "es2015",
4
- "target": "es6",
5
- "lib": [
6
- "es2015",
7
- "dom"
8
- ],
9
- "esModuleInterop": true,
10
- "moduleResolution": "node",
11
- "declaration": true,
12
- "noImplicitAny": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "noImplicitReturns": true,
15
- "strict": true,
16
- "noUnusedLocals": true,
17
- "resolveJsonModule": true,
18
- "sourceMap": false,
19
- "outDir": "./build",
20
- "baseUrl": "src",
21
- "experimentalDecorators": true,
22
- "skipLibCheck": true,
23
- "paths": {
24
- "#spruce/*": [".spruce/*"]
25
- }
26
- },
27
- "include": [
28
- "./*.ts",
29
- "./**/*.ts"
30
- ],
31
- "exclude": [
32
- "**/node_modules/*",
33
- "build/*",
34
- "esm/*"
35
- ]
36
- }
package/tsconfig.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "skipLibCheck": true,
4
- "module": "commonjs",
5
- "esModuleInterop": true,
6
- "target": "ES2017",
7
- "lib": [
8
- "DOM",
9
- "es2017",
10
- "ES2020"
11
- ],
12
- "declaration": true,
13
- "noImplicitAny": true,
14
- "allowJs": true,
15
- "forceConsistentCasingInFileNames": true,
16
- "noImplicitReturns": true,
17
- "strict": true,
18
- "noUnusedLocals": true,
19
- "resolveJsonModule": true,
20
- "moduleResolution": "node",
21
- "sourceMap": false,
22
- "outDir": "build",
23
- "baseUrl": "src",
24
- "experimentalDecorators": true,
25
- "paths": {
26
- "#spruce/*": [
27
- ".spruce/*"
28
- ]
29
- }
30
- },
31
- "include": [
32
- "./src/*.ts",
33
- "./src/**/*.ts",
34
- "./src/.spruce/**/*"
35
- ],
36
- "exclude": [
37
- "build",
38
- "esm"
39
- ]
40
- }
File without changes