@livon/schema 0.27.0-rc.1
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/PROMPT.md +21 -0
- package/README.md +13 -0
- package/SCHEMA.md +13 -0
- package/dist/SchemaValidationError.cjs +41 -0
- package/dist/SchemaValidationError.d.ts +20 -0
- package/dist/SchemaValidationError.js +7 -0
- package/dist/SchemaValidationError.spec.cjs +65 -0
- package/dist/SchemaValidationError.spec.d.ts +1 -0
- package/dist/SchemaValidationError.spec.js +59 -0
- package/dist/after.cjs +36 -0
- package/dist/after.d.ts +30 -0
- package/dist/after.js +2 -0
- package/dist/after.spec.cjs +54 -0
- package/dist/after.spec.d.ts +1 -0
- package/dist/after.spec.js +48 -0
- package/dist/and.cjs +36 -0
- package/dist/and.d.ts +26 -0
- package/dist/and.js +2 -0
- package/dist/and.spec.cjs +57 -0
- package/dist/and.spec.d.ts +1 -0
- package/dist/and.spec.js +51 -0
- package/dist/api.cjs +317 -0
- package/dist/api.d.ts +107 -0
- package/dist/api.js +277 -0
- package/dist/api.spec.cjs +512 -0
- package/dist/api.spec.d.ts +1 -0
- package/dist/api.spec.js +506 -0
- package/dist/array.cjs +74 -0
- package/dist/array.d.ts +25 -0
- package/dist/array.js +40 -0
- package/dist/array.spec.cjs +167 -0
- package/dist/array.spec.d.ts +1 -0
- package/dist/array.spec.js +161 -0
- package/dist/before.cjs +36 -0
- package/dist/before.d.ts +30 -0
- package/dist/before.js +2 -0
- package/dist/before.spec.cjs +54 -0
- package/dist/before.spec.d.ts +1 -0
- package/dist/before.spec.js +48 -0
- package/dist/binary.cjs +53 -0
- package/dist/binary.d.ts +24 -0
- package/dist/binary.js +19 -0
- package/dist/binary.spec.cjs +107 -0
- package/dist/binary.spec.d.ts +1 -0
- package/dist/binary.spec.js +101 -0
- package/dist/boolean.cjs +53 -0
- package/dist/boolean.d.ts +24 -0
- package/dist/boolean.js +19 -0
- package/dist/boolean.spec.cjs +96 -0
- package/dist/boolean.spec.d.ts +1 -0
- package/dist/boolean.spec.js +90 -0
- package/dist/context.cjs +125 -0
- package/dist/context.d.ts +101 -0
- package/dist/context.js +76 -0
- package/dist/context.spec.cjs +244 -0
- package/dist/context.spec.d.ts +1 -0
- package/dist/context.spec.js +238 -0
- package/dist/date.cjs +53 -0
- package/dist/date.d.ts +24 -0
- package/dist/date.js +19 -0
- package/dist/date.spec.cjs +97 -0
- package/dist/date.spec.d.ts +1 -0
- package/dist/date.spec.js +91 -0
- package/dist/doc.cjs +54 -0
- package/dist/doc.d.ts +25 -0
- package/dist/doc.js +17 -0
- package/dist/doc.spec.cjs +99 -0
- package/dist/doc.spec.d.ts +1 -0
- package/dist/doc.spec.js +93 -0
- package/dist/enumeration.cjs +74 -0
- package/dist/enumeration.d.ts +50 -0
- package/dist/enumeration.js +40 -0
- package/dist/enumeration.spec.cjs +110 -0
- package/dist/enumeration.spec.d.ts +1 -0
- package/dist/enumeration.spec.js +104 -0
- package/dist/hydrate.cjs +18 -0
- package/dist/hydrate.d.ts +1 -0
- package/dist/hydrate.js +0 -0
- package/dist/index.cjs +145 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +24 -0
- package/dist/index.spec.cjs +43 -0
- package/dist/index.spec.d.ts +1 -0
- package/dist/index.spec.js +37 -0
- package/dist/literal.cjs +55 -0
- package/dist/literal.d.ts +25 -0
- package/dist/literal.js +21 -0
- package/dist/literal.spec.cjs +93 -0
- package/dist/literal.spec.d.ts +1 -0
- package/dist/literal.spec.js +87 -0
- package/dist/number.cjs +89 -0
- package/dist/number.d.ts +84 -0
- package/dist/number.js +55 -0
- package/dist/number.spec.cjs +155 -0
- package/dist/number.spec.d.ts +1 -0
- package/dist/number.spec.js +149 -0
- package/dist/object.cjs +66 -0
- package/dist/object.d.ts +37 -0
- package/dist/object.js +32 -0
- package/dist/object.spec.cjs +171 -0
- package/dist/object.spec.d.ts +1 -0
- package/dist/object.spec.js +165 -0
- package/dist/operation.cjs +182 -0
- package/dist/operation.d.ts +197 -0
- package/dist/operation.js +133 -0
- package/dist/operation.spec.cjs +454 -0
- package/dist/operation.spec.d.ts +1 -0
- package/dist/operation.spec.js +448 -0
- package/dist/or.cjs +85 -0
- package/dist/or.d.ts +37 -0
- package/dist/or.js +51 -0
- package/dist/or.spec.cjs +204 -0
- package/dist/or.spec.d.ts +1 -0
- package/dist/or.spec.js +198 -0
- package/dist/schema.cjs +285 -0
- package/dist/schema.d.ts +132 -0
- package/dist/schema.js +233 -0
- package/dist/schema.spec.cjs +587 -0
- package/dist/schema.spec.d.ts +1 -0
- package/dist/schema.spec.js +581 -0
- package/dist/schemaFactory.cjs +125 -0
- package/dist/schemaFactory.d.ts +97 -0
- package/dist/schemaFactory.js +88 -0
- package/dist/schemaFactory.spec.cjs +197 -0
- package/dist/schemaFactory.spec.d.ts +1 -0
- package/dist/schemaFactory.spec.js +191 -0
- package/dist/schemaModule.cjs +280 -0
- package/dist/schemaModule.d.ts +97 -0
- package/dist/schemaModule.js +243 -0
- package/dist/schemaModule.spec.cjs +355 -0
- package/dist/schemaModule.spec.d.ts +1 -0
- package/dist/schemaModule.spec.js +349 -0
- package/dist/string.cjs +93 -0
- package/dist/string.d.ts +85 -0
- package/dist/string.js +59 -0
- package/dist/string.spec.cjs +158 -0
- package/dist/string.spec.d.ts +1 -0
- package/dist/string.spec.js +152 -0
- package/dist/testing/mocks/assertions.mock.cjs +48 -0
- package/dist/testing/mocks/assertions.mock.d.ts +5 -0
- package/dist/testing/mocks/assertions.mock.js +14 -0
- package/dist/testing/mocks/index.cjs +52 -0
- package/dist/testing/mocks/index.d.ts +4 -0
- package/dist/testing/mocks/index.js +3 -0
- package/dist/testing/mocks/schema.mock.cjs +120 -0
- package/dist/testing/mocks/schema.mock.d.ts +37 -0
- package/dist/testing/mocks/schema.mock.js +74 -0
- package/dist/tuple.cjs +58 -0
- package/dist/tuple.d.ts +33 -0
- package/dist/tuple.js +24 -0
- package/dist/tuple.spec.cjs +162 -0
- package/dist/tuple.spec.d.ts +1 -0
- package/dist/tuple.spec.js +156 -0
- package/dist/typeGuards.cjs +60 -0
- package/dist/typeGuards.d.ts +93 -0
- package/dist/typeGuards.js +8 -0
- package/dist/typeGuards.spec.cjs +101 -0
- package/dist/typeGuards.spec.d.ts +1 -0
- package/dist/typeGuards.spec.js +95 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.ts +289 -0
- package/dist/types.js +0 -0
- package/dist/union.cjs +74 -0
- package/dist/union.d.ts +33 -0
- package/dist/union.js +40 -0
- package/dist/union.spec.cjs +159 -0
- package/dist/union.spec.d.ts +1 -0
- package/dist/union.spec.js +153 -0
- package/package.json +47 -0
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_exports__ = {};
|
|
3
|
+
const external_vitest_namespaceObject = require("vitest");
|
|
4
|
+
const external_context_cjs_namespaceObject = require("./context.cjs");
|
|
5
|
+
const external_operation_cjs_namespaceObject = require("./operation.cjs");
|
|
6
|
+
const external_string_cjs_namespaceObject = require("./string.cjs");
|
|
7
|
+
const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
|
|
8
|
+
(0, external_vitest_namespaceObject.describe)('operation utilities', ()=>{
|
|
9
|
+
let context;
|
|
10
|
+
(0, external_vitest_namespaceObject.beforeAll)(()=>{
|
|
11
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)();
|
|
12
|
+
});
|
|
13
|
+
(0, external_vitest_namespaceObject.beforeEach)(()=>{
|
|
14
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)();
|
|
15
|
+
});
|
|
16
|
+
(0, external_vitest_namespaceObject.afterEach)(()=>{
|
|
17
|
+
external_vitest_namespaceObject.vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
(0, external_vitest_namespaceObject.afterAll)(()=>{
|
|
20
|
+
external_vitest_namespaceObject.vi.restoreAllMocks();
|
|
21
|
+
});
|
|
22
|
+
(0, external_vitest_namespaceObject.describe)('operation()', ()=>{
|
|
23
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
24
|
+
(0, external_vitest_namespaceObject.it)('should return operation payload when output schema is provided', ()=>{
|
|
25
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
26
|
+
name: 'Input',
|
|
27
|
+
type: 'input',
|
|
28
|
+
outputValue: {
|
|
29
|
+
id: 'u-1'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
33
|
+
name: 'Output',
|
|
34
|
+
type: 'output',
|
|
35
|
+
outputValue: {
|
|
36
|
+
ok: true
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
40
|
+
ok: true
|
|
41
|
+
}));
|
|
42
|
+
const result = (0, external_operation_cjs_namespaceObject.operation)({
|
|
43
|
+
input: inputSchema,
|
|
44
|
+
output: outputSchema,
|
|
45
|
+
exec,
|
|
46
|
+
doc: {
|
|
47
|
+
summary: 'operation doc'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
(0, external_vitest_namespaceObject.expect)(result.type).toBe('operation');
|
|
51
|
+
(0, external_vitest_namespaceObject.expect)(result.input).toBe(inputSchema);
|
|
52
|
+
(0, external_vitest_namespaceObject.expect)(result.output).toBe(outputSchema);
|
|
53
|
+
(0, external_vitest_namespaceObject.expect)(result.exec).toBe(exec);
|
|
54
|
+
(0, external_vitest_namespaceObject.expect)(result.doc).toEqual({
|
|
55
|
+
summary: 'operation doc'
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
60
|
+
(0, external_vitest_namespaceObject.it)('should keep output undefined when output schema is omitted', ()=>{
|
|
61
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
62
|
+
outputValue: 'input'
|
|
63
|
+
});
|
|
64
|
+
const result = (0, external_operation_cjs_namespaceObject.operation)({
|
|
65
|
+
input: inputSchema,
|
|
66
|
+
exec: (input)=>input.length
|
|
67
|
+
});
|
|
68
|
+
(0, external_vitest_namespaceObject.expect)(result.output).toBeUndefined();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, external_vitest_namespaceObject.describe)('fieldOperation()', ()=>{
|
|
73
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
74
|
+
(0, external_vitest_namespaceObject.it)('should normalize shape dependsOn and shape input when shape values are provided', ()=>{
|
|
75
|
+
const result = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
76
|
+
dependsOn: {
|
|
77
|
+
id: (0, external_string_cjs_namespaceObject.string)()
|
|
78
|
+
},
|
|
79
|
+
input: {
|
|
80
|
+
name: (0, external_string_cjs_namespaceObject.string)()
|
|
81
|
+
},
|
|
82
|
+
exec: ()=>'ok'
|
|
83
|
+
});
|
|
84
|
+
(0, external_vitest_namespaceObject.expect)(result.type).toBe('field');
|
|
85
|
+
(0, external_vitest_namespaceObject.expect)(result.dependsOn.name).toBe('dependsOn');
|
|
86
|
+
(0, external_vitest_namespaceObject.expect)(result.input?.name).toBe('input');
|
|
87
|
+
});
|
|
88
|
+
(0, external_vitest_namespaceObject.it)('should keep provided schema dependsOn without wrapping when schema is provided', ()=>{
|
|
89
|
+
const dependsOn = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
90
|
+
name: 'DependsOnSchema',
|
|
91
|
+
type: 'dependsOn',
|
|
92
|
+
outputValue: {
|
|
93
|
+
id: 'u-1'
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
const result = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
97
|
+
dependsOn,
|
|
98
|
+
exec: ()=>'ok'
|
|
99
|
+
});
|
|
100
|
+
(0, external_vitest_namespaceObject.expect)(result.dependsOn).toBe(dependsOn);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
104
|
+
(0, external_vitest_namespaceObject.it)('should keep output undefined when output is omitted', ()=>{
|
|
105
|
+
const dependsOn = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
106
|
+
outputValue: {
|
|
107
|
+
id: 'u-1'
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const result = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
111
|
+
dependsOn,
|
|
112
|
+
exec: ()=>'ok'
|
|
113
|
+
});
|
|
114
|
+
(0, external_vitest_namespaceObject.expect)(result.output).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
(0, external_vitest_namespaceObject.describe)('withOperationName()', ()=>{
|
|
119
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
120
|
+
(0, external_vitest_namespaceObject.it)('should set operation name when wrapper is used', ()=>{
|
|
121
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
122
|
+
input: (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
123
|
+
outputValue: 'value'
|
|
124
|
+
}),
|
|
125
|
+
exec: ()=>'ok'
|
|
126
|
+
});
|
|
127
|
+
const named = (0, external_operation_cjs_namespaceObject.withOperationName)({
|
|
128
|
+
name: 'createUser',
|
|
129
|
+
operation: op
|
|
130
|
+
});
|
|
131
|
+
(0, external_vitest_namespaceObject.expect)(named.name).toBe('createUser');
|
|
132
|
+
(0, external_vitest_namespaceObject.expect)(named.type).toBe('operation');
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
136
|
+
(0, external_vitest_namespaceObject.it)('should preserve original operation members when name is injected', ()=>{
|
|
137
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>'ok');
|
|
138
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
139
|
+
input: (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
140
|
+
outputValue: 'value'
|
|
141
|
+
}),
|
|
142
|
+
exec
|
|
143
|
+
});
|
|
144
|
+
const named = (0, external_operation_cjs_namespaceObject.withOperationName)({
|
|
145
|
+
name: 'createUser',
|
|
146
|
+
operation: op
|
|
147
|
+
});
|
|
148
|
+
(0, external_vitest_namespaceObject.expect)(named.exec).toBe(exec);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
(0, external_vitest_namespaceObject.describe)('withFieldOperationName()', ()=>{
|
|
153
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
154
|
+
(0, external_vitest_namespaceObject.it)('should set field operation name when wrapper is used', ()=>{
|
|
155
|
+
const op = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
156
|
+
dependsOn: (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
157
|
+
outputValue: {
|
|
158
|
+
id: 'u-1'
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
exec: ()=>'ok'
|
|
162
|
+
});
|
|
163
|
+
const named = (0, external_operation_cjs_namespaceObject.withFieldOperationName)({
|
|
164
|
+
name: 'user.displayName',
|
|
165
|
+
operation: op
|
|
166
|
+
});
|
|
167
|
+
(0, external_vitest_namespaceObject.expect)(named.name).toBe('user.displayName');
|
|
168
|
+
(0, external_vitest_namespaceObject.expect)(named.type).toBe('field');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
172
|
+
(0, external_vitest_namespaceObject.it)('should preserve original field operation members when name is injected', ()=>{
|
|
173
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>'ok');
|
|
174
|
+
const dependsOn = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
175
|
+
outputValue: {
|
|
176
|
+
id: 'u-1'
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const op = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
180
|
+
dependsOn,
|
|
181
|
+
exec
|
|
182
|
+
});
|
|
183
|
+
const named = (0, external_operation_cjs_namespaceObject.withFieldOperationName)({
|
|
184
|
+
name: 'user.displayName',
|
|
185
|
+
operation: op
|
|
186
|
+
});
|
|
187
|
+
(0, external_vitest_namespaceObject.expect)(named.dependsOn).toBe(dependsOn);
|
|
188
|
+
(0, external_vitest_namespaceObject.expect)(named.exec).toBe(exec);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
(0, external_vitest_namespaceObject.describe)('runOperation()', ()=>{
|
|
193
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
194
|
+
(0, external_vitest_namespaceObject.it)('should parse input and output and publish to all rooms when publish hook returns payload', async ()=>{
|
|
195
|
+
const parsedInput = {
|
|
196
|
+
id: 'u-1'
|
|
197
|
+
};
|
|
198
|
+
const parsedOutput = {
|
|
199
|
+
id: 'result'
|
|
200
|
+
};
|
|
201
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
202
|
+
outputValue: parsedInput
|
|
203
|
+
});
|
|
204
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
205
|
+
outputValue: parsedOutput
|
|
206
|
+
});
|
|
207
|
+
const publisher = external_vitest_namespaceObject.vi.fn(async ()=>void 0);
|
|
208
|
+
const publishHook = external_vitest_namespaceObject.vi.fn(()=>({
|
|
209
|
+
event: 'created'
|
|
210
|
+
}));
|
|
211
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>parsedOutput);
|
|
212
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)({
|
|
213
|
+
request: {
|
|
214
|
+
publisher
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
218
|
+
input: inputSchema,
|
|
219
|
+
output: outputSchema,
|
|
220
|
+
publish: {
|
|
221
|
+
userCreated: publishHook
|
|
222
|
+
},
|
|
223
|
+
rooms: ()=>[
|
|
224
|
+
'room-a',
|
|
225
|
+
'room-b'
|
|
226
|
+
],
|
|
227
|
+
ack: {
|
|
228
|
+
required: true,
|
|
229
|
+
mode: 'handled'
|
|
230
|
+
},
|
|
231
|
+
exec
|
|
232
|
+
});
|
|
233
|
+
const result = await (0, external_operation_cjs_namespaceObject.runOperation)(op, {
|
|
234
|
+
rawInput: true
|
|
235
|
+
}, context);
|
|
236
|
+
(0, external_vitest_namespaceObject.expect)(exec).toHaveBeenCalledWith(parsedInput, context);
|
|
237
|
+
(0, external_vitest_namespaceObject.expect)(outputSchema.parse).toHaveBeenCalledWith(parsedOutput, context);
|
|
238
|
+
(0, external_vitest_namespaceObject.expect)(publishHook).toHaveBeenCalledWith(parsedOutput, context);
|
|
239
|
+
(0, external_vitest_namespaceObject.expect)(publisher).toHaveBeenCalledTimes(2);
|
|
240
|
+
(0, external_vitest_namespaceObject.expect)(publisher).toHaveBeenNthCalledWith(1, {
|
|
241
|
+
topic: 'userCreated',
|
|
242
|
+
payload: {
|
|
243
|
+
event: 'created'
|
|
244
|
+
},
|
|
245
|
+
input: parsedInput,
|
|
246
|
+
ack: {
|
|
247
|
+
required: true,
|
|
248
|
+
mode: 'handled'
|
|
249
|
+
},
|
|
250
|
+
meta: {
|
|
251
|
+
room: 'room-a'
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
(0, external_vitest_namespaceObject.expect)(publisher).toHaveBeenNthCalledWith(2, {
|
|
255
|
+
topic: 'userCreated',
|
|
256
|
+
payload: {
|
|
257
|
+
event: 'created'
|
|
258
|
+
},
|
|
259
|
+
input: parsedInput,
|
|
260
|
+
ack: {
|
|
261
|
+
required: true,
|
|
262
|
+
mode: 'handled'
|
|
263
|
+
},
|
|
264
|
+
meta: {
|
|
265
|
+
room: 'room-b'
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
(0, external_vitest_namespaceObject.expect)(result).toEqual(parsedOutput);
|
|
269
|
+
});
|
|
270
|
+
(0, external_vitest_namespaceObject.it)('should skip publish when request publisher is missing', async ()=>{
|
|
271
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
272
|
+
outputValue: 'parsed-input'
|
|
273
|
+
});
|
|
274
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
275
|
+
outputValue: 'parsed-output'
|
|
276
|
+
});
|
|
277
|
+
const publishHook = external_vitest_namespaceObject.vi.fn(()=>'payload');
|
|
278
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>'result');
|
|
279
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)();
|
|
280
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
281
|
+
input: inputSchema,
|
|
282
|
+
output: outputSchema,
|
|
283
|
+
publish: {
|
|
284
|
+
topic: publishHook
|
|
285
|
+
},
|
|
286
|
+
exec
|
|
287
|
+
});
|
|
288
|
+
const result = await (0, external_operation_cjs_namespaceObject.runOperation)(op, 'raw-input', context);
|
|
289
|
+
(0, external_vitest_namespaceObject.expect)(result).toBe('parsed-output');
|
|
290
|
+
(0, external_vitest_namespaceObject.expect)(publishHook).not.toHaveBeenCalled();
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
294
|
+
(0, external_vitest_namespaceObject.it)('should report publish hook errors when publish hook throws', async ()=>{
|
|
295
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
296
|
+
outputValue: 'parsed-input'
|
|
297
|
+
});
|
|
298
|
+
const publisher = external_vitest_namespaceObject.vi.fn(async ()=>void 0);
|
|
299
|
+
const publishHookError = new Error('hook failed');
|
|
300
|
+
const publishHook = external_vitest_namespaceObject.vi.fn(()=>{
|
|
301
|
+
throw publishHookError;
|
|
302
|
+
});
|
|
303
|
+
const onPublishError = external_vitest_namespaceObject.vi.fn();
|
|
304
|
+
const logger = {
|
|
305
|
+
error: external_vitest_namespaceObject.vi.fn()
|
|
306
|
+
};
|
|
307
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)({
|
|
308
|
+
request: {
|
|
309
|
+
publisher,
|
|
310
|
+
onPublishError,
|
|
311
|
+
logger
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
315
|
+
input: inputSchema,
|
|
316
|
+
exec: async ()=>'output',
|
|
317
|
+
publish: {
|
|
318
|
+
topic: publishHook
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
await (0, external_operation_cjs_namespaceObject.runOperation)(op, 'raw-input', context);
|
|
322
|
+
(0, external_vitest_namespaceObject.expect)(onPublishError).toHaveBeenCalledWith(publishHookError, {
|
|
323
|
+
topic: 'topic',
|
|
324
|
+
phase: 'publish-hook'
|
|
325
|
+
});
|
|
326
|
+
(0, external_vitest_namespaceObject.expect)(logger.error).toHaveBeenCalled();
|
|
327
|
+
});
|
|
328
|
+
(0, external_vitest_namespaceObject.it)('should report publisher errors when publisher throws', async ()=>{
|
|
329
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
330
|
+
outputValue: 'parsed-input'
|
|
331
|
+
});
|
|
332
|
+
const publisherError = new Error('publisher failed');
|
|
333
|
+
const publisher = external_vitest_namespaceObject.vi.fn(async ()=>{
|
|
334
|
+
throw publisherError;
|
|
335
|
+
});
|
|
336
|
+
const onPublishError = external_vitest_namespaceObject.vi.fn();
|
|
337
|
+
const logger = {
|
|
338
|
+
error: external_vitest_namespaceObject.vi.fn()
|
|
339
|
+
};
|
|
340
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)({
|
|
341
|
+
request: {
|
|
342
|
+
publisher,
|
|
343
|
+
onPublishError,
|
|
344
|
+
logger
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
const op = (0, external_operation_cjs_namespaceObject.operation)({
|
|
348
|
+
input: inputSchema,
|
|
349
|
+
exec: async ()=>'output',
|
|
350
|
+
publish: {
|
|
351
|
+
topic: ()=>({
|
|
352
|
+
ok: true
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
await (0, external_operation_cjs_namespaceObject.runOperation)(op, 'raw-input', context);
|
|
357
|
+
(0, external_vitest_namespaceObject.expect)(onPublishError).toHaveBeenCalledWith(publisherError, {
|
|
358
|
+
topic: 'topic',
|
|
359
|
+
phase: 'publisher'
|
|
360
|
+
});
|
|
361
|
+
(0, external_vitest_namespaceObject.expect)(logger.error).toHaveBeenCalled();
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
(0, external_vitest_namespaceObject.describe)('runFieldOperation()', ()=>{
|
|
366
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
367
|
+
(0, external_vitest_namespaceObject.it)('should parse dependsOn and input and output when input and output schemas are provided', async ()=>{
|
|
368
|
+
const parsedDependsOn = {
|
|
369
|
+
id: 'u-1'
|
|
370
|
+
};
|
|
371
|
+
const parsedInput = {
|
|
372
|
+
field: 'name'
|
|
373
|
+
};
|
|
374
|
+
const parsedOutput = {
|
|
375
|
+
value: 'Alice'
|
|
376
|
+
};
|
|
377
|
+
const dependsOnSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
378
|
+
outputValue: parsedDependsOn
|
|
379
|
+
});
|
|
380
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
381
|
+
outputValue: parsedInput
|
|
382
|
+
});
|
|
383
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
384
|
+
outputValue: parsedOutput
|
|
385
|
+
});
|
|
386
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
387
|
+
raw: true
|
|
388
|
+
}));
|
|
389
|
+
const op = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
390
|
+
dependsOn: dependsOnSchema,
|
|
391
|
+
input: inputSchema,
|
|
392
|
+
output: outputSchema,
|
|
393
|
+
exec
|
|
394
|
+
});
|
|
395
|
+
const result = await (0, external_operation_cjs_namespaceObject.runFieldOperation)(op, {
|
|
396
|
+
rawDependsOn: true
|
|
397
|
+
}, {
|
|
398
|
+
rawInput: true
|
|
399
|
+
}, context);
|
|
400
|
+
(0, external_vitest_namespaceObject.expect)(dependsOnSchema.parse).toHaveBeenCalledWith({
|
|
401
|
+
rawDependsOn: true
|
|
402
|
+
}, context);
|
|
403
|
+
(0, external_vitest_namespaceObject.expect)(inputSchema.parse).toHaveBeenCalledWith({
|
|
404
|
+
rawInput: true
|
|
405
|
+
}, context);
|
|
406
|
+
(0, external_vitest_namespaceObject.expect)(exec).toHaveBeenCalledWith(parsedDependsOn, parsedInput, context);
|
|
407
|
+
(0, external_vitest_namespaceObject.expect)(outputSchema.parse).toHaveBeenCalledWith({
|
|
408
|
+
raw: true
|
|
409
|
+
}, context);
|
|
410
|
+
(0, external_vitest_namespaceObject.expect)(result).toEqual(parsedOutput);
|
|
411
|
+
});
|
|
412
|
+
(0, external_vitest_namespaceObject.it)('should treat second parameter as context when input schema is missing', async ()=>{
|
|
413
|
+
const parsedDependsOn = {
|
|
414
|
+
id: 'u-1'
|
|
415
|
+
};
|
|
416
|
+
const dependsOnSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
417
|
+
outputValue: parsedDependsOn
|
|
418
|
+
});
|
|
419
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>'resolved');
|
|
420
|
+
const op = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
421
|
+
dependsOn: dependsOnSchema,
|
|
422
|
+
exec
|
|
423
|
+
});
|
|
424
|
+
const result = await (0, external_operation_cjs_namespaceObject.runFieldOperation)(op, {
|
|
425
|
+
rawDependsOn: true
|
|
426
|
+
}, context);
|
|
427
|
+
(0, external_vitest_namespaceObject.expect)(exec).toHaveBeenCalledWith(parsedDependsOn, context);
|
|
428
|
+
(0, external_vitest_namespaceObject.expect)(result).toBe('resolved');
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
432
|
+
(0, external_vitest_namespaceObject.it)('should create request context when context has no request before execution', async ()=>{
|
|
433
|
+
const dependsOnSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
434
|
+
outputValue: {
|
|
435
|
+
id: 'u-1'
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
context = (0, external_context_cjs_namespaceObject.createSchemaContext)();
|
|
439
|
+
const op = (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
440
|
+
dependsOn: dependsOnSchema,
|
|
441
|
+
exec: async ()=>'ok'
|
|
442
|
+
});
|
|
443
|
+
await (0, external_operation_cjs_namespaceObject.runFieldOperation)(op, {
|
|
444
|
+
rawDependsOn: true
|
|
445
|
+
}, context);
|
|
446
|
+
(0, external_vitest_namespaceObject.expect)(context.getRequestContext()).toBeDefined();
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
452
|
+
Object.defineProperty(exports, '__esModule', {
|
|
453
|
+
value: true
|
|
454
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|