@genesislcap/mock-server 15.74.0 → 15.75.0
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 +296 -58
- package/dist/db/schema.d.ts +9 -1
- package/dist/db/schema.js +40 -11
- package/dist/db/store.d.ts +1 -0
- package/dist/db/store.js +4 -0
- package/dist/handlers/auth.d.ts +15 -6
- package/dist/handlers/auth.js +152 -33
- package/dist/handlers/commitEvent.js +43 -20
- package/dist/handlers/crudEvents.d.ts +3 -1
- package/dist/handlers/crudEvents.js +3 -2
- package/dist/handlers/eventValidation.js +6 -3
- package/dist/handlers/http.d.ts +2 -2
- package/dist/handlers/http.js +66 -43
- package/dist/handlers/jsonSchema.d.ts +1 -0
- package/dist/handlers/jsonSchema.js +72 -21
- package/dist/handlers/meta.d.ts +1 -1
- package/dist/handlers/meta.js +59 -10
- package/dist/handlers/requestReply.js +36 -9
- package/dist/index.d.ts +1 -1
- package/dist/presets/auth.d.ts +25 -0
- package/dist/presets/auth.js +855 -0
- package/dist/presets/cronExpression.d.ts +1 -0
- package/dist/presets/cronExpression.js +429 -0
- package/dist/presets/fileServer.d.ts +13 -0
- package/dist/presets/fileServer.js +399 -0
- package/dist/presets/gsf.d.ts +24 -0
- package/dist/presets/gsf.js +450 -0
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +1 -0
- package/dist/presets/javaTime.d.ts +7 -0
- package/dist/presets/javaTime.js +322 -0
- package/dist/presets/multipart.d.ts +14 -0
- package/dist/presets/multipart.js +91 -0
- package/dist/presets/notify.d.ts +27 -0
- package/dist/presets/notify.js +250 -0
- package/dist/presets/notifyDispatch.d.ts +28 -0
- package/dist/presets/notifyDispatch.js +570 -0
- package/dist/presets/notifyRules.d.ts +9 -0
- package/dist/presets/notifyRules.js +754 -0
- package/dist/presets/platform/backing.json +8058 -217
- package/dist/presets/platform/criteria-model.json +362 -0
- package/dist/presets/platform/time-zones.json +608 -0
- package/dist/presets/platform.d.ts +7 -0
- package/dist/presets/platform.js +145 -103
- package/dist/presets/products.d.ts +9 -7
- package/dist/presets/products.js +89 -21
- package/dist/presets/reconciliation.d.ts +18 -0
- package/dist/presets/reconciliation.js +721 -0
- package/dist/presets/reporting.d.ts +14 -0
- package/dist/presets/reporting.js +862 -0
- package/dist/protocol/connection.d.ts +2 -0
- package/dist/protocol/connection.js +4 -0
- package/dist/protocol/dtoTypes.d.ts +30 -0
- package/dist/protocol/dtoTypes.js +250 -0
- package/dist/protocol/errors.d.ts +3 -1
- package/dist/protocol/errors.js +2 -0
- package/dist/protocol/fieldTypes.js +5 -0
- package/dist/protocol/router.d.ts +1 -0
- package/dist/protocol/router.js +3 -3
- package/dist/protocol/schemaValidation.d.ts +1 -1
- package/dist/protocol/schemaValidation.js +53 -8
- package/dist/server.js +34 -2
- package/dist/types.d.ts +50 -2
- package/package.json +1 -1
- package/src/db/schema.ts +56 -13
- package/src/db/store.ts +5 -0
- package/src/handlers/auth.ts +211 -37
- package/src/handlers/commitEvent.ts +44 -19
- package/src/handlers/crudEvents.ts +9 -2
- package/src/handlers/eventValidation.ts +6 -3
- package/src/handlers/http.ts +83 -42
- package/src/handlers/jsonSchema.ts +86 -23
- package/src/handlers/meta.ts +77 -9
- package/src/handlers/requestReply.ts +42 -6
- package/src/index.ts +7 -0
- package/src/presets/auth.ts +961 -0
- package/src/presets/cronExpression.ts +445 -0
- package/src/presets/fileServer.ts +475 -0
- package/src/presets/gsf.ts +475 -0
- package/src/presets/index.ts +5 -0
- package/src/presets/javaTime.ts +354 -0
- package/src/presets/multipart.ts +110 -0
- package/src/presets/notify.ts +312 -0
- package/src/presets/notifyDispatch.ts +685 -0
- package/src/presets/notifyRules.ts +866 -0
- package/src/presets/platform/backing.json +8058 -217
- package/src/presets/platform/criteria-model.json +362 -0
- package/src/presets/platform/time-zones.json +608 -0
- package/src/presets/platform.ts +204 -115
- package/src/presets/products.ts +125 -19
- package/src/presets/reconciliation.ts +824 -0
- package/src/presets/reporting.ts +953 -0
- package/src/protocol/connection.ts +4 -0
- package/src/protocol/dtoTypes.ts +310 -0
- package/src/protocol/errors.ts +13 -1
- package/src/protocol/fieldTypes.ts +5 -0
- package/src/protocol/router.ts +3 -3
- package/src/protocol/schemaValidation.ts +61 -8
- package/src/server.ts +38 -2
- package/src/types.ts +147 -3
package/src/handlers/meta.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
dtoFields,
|
|
2
3
|
eventDefaultOf,
|
|
3
4
|
eventFields,
|
|
4
5
|
knownValues,
|
|
@@ -8,11 +9,19 @@ import {
|
|
|
8
9
|
requestReplySchema,
|
|
9
10
|
requestReplySourceSchema,
|
|
10
11
|
resolveEventTarget,
|
|
12
|
+
typedFields,
|
|
11
13
|
type EventTarget,
|
|
12
14
|
type ResolvedField,
|
|
13
15
|
} from '../db/schema.ts';
|
|
14
16
|
import type { Store } from '../db/store.ts';
|
|
15
17
|
import type { Connection } from '../protocol/connection.ts';
|
|
18
|
+
import {
|
|
19
|
+
isNestedType,
|
|
20
|
+
metaDefinitions,
|
|
21
|
+
metaType,
|
|
22
|
+
nestedClasses,
|
|
23
|
+
nestedClassOf,
|
|
24
|
+
} from '../protocol/dtoTypes.ts';
|
|
16
25
|
import { isLegacyFidelity } from '../protocol/fidelity.ts';
|
|
17
26
|
import {
|
|
18
27
|
enumClassOf,
|
|
@@ -32,6 +41,7 @@ import type {
|
|
|
32
41
|
QueryDef,
|
|
33
42
|
RequestReplyDef,
|
|
34
43
|
Row,
|
|
44
|
+
TypedRequestReply,
|
|
35
45
|
} from '../types.ts';
|
|
36
46
|
import { hiddenFields, requestingUser } from './resourceAuth.ts';
|
|
37
47
|
|
|
@@ -72,9 +82,13 @@ function dataserverMeta(
|
|
|
72
82
|
TYPE: 'DATASERVER',
|
|
73
83
|
NAME: name,
|
|
74
84
|
FIELD: fields.map(fieldMetadata),
|
|
75
|
-
|
|
76
|
-
?
|
|
77
|
-
:
|
|
85
|
+
...(query.legacyEngine
|
|
86
|
+
? {}
|
|
87
|
+
: {
|
|
88
|
+
INDEXES: query.indexes?.length
|
|
89
|
+
? query.indexes.map((index) => ({ NAME: index.name, FIELDS: index.fields.join(' ') }))
|
|
90
|
+
: DEFAULT_INDEXES,
|
|
91
|
+
}),
|
|
78
92
|
};
|
|
79
93
|
}
|
|
80
94
|
|
|
@@ -136,10 +150,23 @@ function requestServerMeta(
|
|
|
136
150
|
// default); DEFAULT appears only when the field has a default.
|
|
137
151
|
export function eventMetaField(
|
|
138
152
|
field: ResolvedField,
|
|
139
|
-
{ annotated, appName }: { annotated: boolean; appName?: string },
|
|
153
|
+
{ annotated: table, appName }: { annotated: boolean; appName?: string },
|
|
140
154
|
): Row {
|
|
141
155
|
const type = field.type;
|
|
142
|
-
|
|
156
|
+
// A table's DAO, or a DAO the DTO unwraps: its annotations.
|
|
157
|
+
const annotated = table || field.dao === true;
|
|
158
|
+
// A list, set, map, nested class or Any: no default, no annotations.
|
|
159
|
+
if (isNestedType(type)) {
|
|
160
|
+
return {
|
|
161
|
+
NAME: field.name,
|
|
162
|
+
DESCRIPTION: nestedClassOf(field),
|
|
163
|
+
...metaType(field),
|
|
164
|
+
OPTIONAL: field.optional ?? false,
|
|
165
|
+
READ_ONLY: false,
|
|
166
|
+
GENESIS_TYPE: null,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const enumClass = () => field.enumClass ?? enumClassOf(field.table, field.name, appName);
|
|
143
170
|
const values = knownValues(field);
|
|
144
171
|
const fieldDefault = eventDefaultOf(field);
|
|
145
172
|
const meta: Row = { NAME: field.name };
|
|
@@ -170,6 +197,39 @@ export function eventMetaField(
|
|
|
170
197
|
return meta;
|
|
171
198
|
}
|
|
172
199
|
|
|
200
|
+
// A typed request server's META (CustomReqRep's buildMetaData, GSF
|
|
201
|
+
// v8.15.29): the request class's fields in DETAILS.FIELD and the reply
|
|
202
|
+
// class's in DETAILS.REPLY, each described as an event DTO's field is, and
|
|
203
|
+
// the criteria keys ReqRepMeta has had since GSF 8.14 (ReqRepMeta.kt:41-43),
|
|
204
|
+
// sent null.
|
|
205
|
+
function typedRequestServerMeta(
|
|
206
|
+
name: string,
|
|
207
|
+
typed: TypedRequestReply,
|
|
208
|
+
appName: string | undefined,
|
|
209
|
+
): Row {
|
|
210
|
+
const describe = ({ className, fields }: TypedRequestReply['request']) => {
|
|
211
|
+
const resolved = typedFields(fields);
|
|
212
|
+
return {
|
|
213
|
+
DESCRIPTION: className,
|
|
214
|
+
FIELD: resolved.map((field) => eventMetaField(field, { annotated: false, appName })),
|
|
215
|
+
DEFINITIONS: metaDefinitions(nestedClasses(resolved), (nested) =>
|
|
216
|
+
dtoFields(nested.fields).map((field) =>
|
|
217
|
+
eventMetaField(field, { annotated: false, appName }),
|
|
218
|
+
),
|
|
219
|
+
),
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
NAME: name,
|
|
224
|
+
...describe(typed.request),
|
|
225
|
+
REPLY: { NAME: `REP_${name}`, ...describe(typed.reply) },
|
|
226
|
+
CRITERIA_ONLY_REQUEST: false,
|
|
227
|
+
SORTABLE_FIELDS: null,
|
|
228
|
+
CRITERIA_FIELDS: null,
|
|
229
|
+
TYPE: 'REQUEST_SERVER',
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
173
233
|
function eventMeta(
|
|
174
234
|
name: string,
|
|
175
235
|
target: EventTarget,
|
|
@@ -182,7 +242,11 @@ function eventMeta(
|
|
|
182
242
|
...(target.title ? { TITLE: target.title } : {}),
|
|
183
243
|
DESCRIPTION: target.className,
|
|
184
244
|
FIELD: fields.map((field) => eventMetaField(field, { annotated, appName })),
|
|
185
|
-
DEFINITIONS:
|
|
245
|
+
DEFINITIONS: metaDefinitions(nestedClasses(fields), (nested) =>
|
|
246
|
+
dtoFields(nested.fields, target.table).map((field) =>
|
|
247
|
+
eventMetaField(field, { annotated: false, appName }),
|
|
248
|
+
),
|
|
249
|
+
),
|
|
186
250
|
REPLY: eventReplyMeta(),
|
|
187
251
|
REQUIRES_APPROVAL: false,
|
|
188
252
|
SCHEDULABLE: false,
|
|
@@ -242,9 +306,13 @@ export function handleMetaRequest(
|
|
|
242
306
|
// Hidden fields disappear from the metadata too — a column the user can't
|
|
243
307
|
// see must not be offered to the grid at all.
|
|
244
308
|
const hidden = hiddenFields((query ?? requestReply)!.auth, requestingUser(connection));
|
|
245
|
-
details = query
|
|
246
|
-
|
|
247
|
-
|
|
309
|
+
if (query) details = dataserverMeta(resourceName, query, config, store, hidden);
|
|
310
|
+
else if (requestReply!.typed) {
|
|
311
|
+
const typed = requestReply!.typed;
|
|
312
|
+
details = typed.meta
|
|
313
|
+
? structuredClone(typed.meta)
|
|
314
|
+
: typedRequestServerMeta(resourceName, typed, config.appName);
|
|
315
|
+
} else details = requestServerMeta(resourceName, requestReply!, config, store, hidden);
|
|
248
316
|
}
|
|
249
317
|
connection.reply(message, { MESSAGE_TYPE: MESSAGE_TYPE.FEATURE_ACK, DETAILS: details });
|
|
250
318
|
}
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
projectRow,
|
|
36
36
|
requestReplyFieldNames,
|
|
37
37
|
requestReplySourceSchema,
|
|
38
|
+
typedFields,
|
|
38
39
|
type ResolvedField,
|
|
39
40
|
} from '../db/schema.ts';
|
|
40
41
|
import type { Store } from '../db/store.ts';
|
|
@@ -550,7 +551,9 @@ function plainReply(
|
|
|
550
551
|
const fieldNames = requestReplyFieldNames(requestReply, config, store);
|
|
551
552
|
// The rows come through the table's (or the view's root table's) primary
|
|
552
553
|
// key, as getBulk reads them (recorded: auth's RIGHT, in CODE order).
|
|
553
|
-
const ordered = [...store.getResourceRows(source.name)].sort(
|
|
554
|
+
const ordered = [...store.getResourceRows(source.name)].sort(
|
|
555
|
+
requestReply.order ?? rowComparator(byPrimaryKey(source)),
|
|
556
|
+
);
|
|
554
557
|
const candidates = requestReply.filter ? ordered.filter(requestReply.filter) : ordered;
|
|
555
558
|
|
|
556
559
|
const reply = requests.flatMap((request) => {
|
|
@@ -581,6 +584,7 @@ function resolverReply(
|
|
|
581
584
|
resourceName: string,
|
|
582
585
|
requestReply: RequestReplyDef,
|
|
583
586
|
message: GenesisMessage,
|
|
587
|
+
config: MockServerConfig,
|
|
584
588
|
store: Store,
|
|
585
589
|
user: RequestingUser,
|
|
586
590
|
): Row {
|
|
@@ -590,10 +594,41 @@ function resolverReply(
|
|
|
590
594
|
// returned.
|
|
591
595
|
const request: Row =
|
|
592
596
|
(typeof message.REQUEST === 'object' && message.REQUEST) || message.DETAILS?.REQUEST || {};
|
|
593
|
-
const
|
|
597
|
+
const resolved = requestReply.resolver!({ request, message, user, store, config });
|
|
598
|
+
const typed = requestReply.typed;
|
|
599
|
+
if (!typed) {
|
|
600
|
+
return {
|
|
601
|
+
MESSAGE_TYPE: `REP_${resourceName}`,
|
|
602
|
+
REPLY: applyResourceAuth(resolved, requestReply.auth, user),
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
// A typed server (AbstractCustomReqRep.kt:62-92, CustomReqRep.kt:34-38
|
|
606
|
+
// @v8.15.29): CRITERIA_MATCH compiled against the reply class, a criteria
|
|
607
|
+
// GSF can't compile failing the request (GENERIC_ERROR, with its text); the
|
|
608
|
+
// criteria over each whole row, then the resource's auth, then at most
|
|
609
|
+
// MAX_ROWS of them (Flow.take, which refuses a count below 1), with no
|
|
610
|
+
// paging.
|
|
611
|
+
const details: Row = message.DETAILS ?? {};
|
|
612
|
+
const maxRows =
|
|
613
|
+
readInteger(details.MAX_ROWS, 'lenient') ?? requestReply.rowLimit ?? DEFAULT_ROW_LIMIT;
|
|
614
|
+
if (maxRows < 1) throw new Error(`Requested element count ${maxRows} should be positive`);
|
|
615
|
+
const fields = typedFields(typed.reply.fields);
|
|
616
|
+
const replyClass: Source = {
|
|
617
|
+
name: typed.reply.className,
|
|
618
|
+
fields: new Map(fields.map((field) => [field.name, field])),
|
|
619
|
+
pkFields: [],
|
|
620
|
+
types: new Map(fields.map((field) => [field.name, field.type])),
|
|
621
|
+
};
|
|
622
|
+
const criteria = criteriaFilter(
|
|
623
|
+
readText(details.CRITERIA_MATCH),
|
|
624
|
+
replyClass,
|
|
625
|
+
(error) => new Error(error.message),
|
|
626
|
+
);
|
|
627
|
+
const rows = applyResourceAuth(applyCriteria(resolved, criteria), requestReply.auth, user);
|
|
594
628
|
return {
|
|
629
|
+
REPLY: rows.slice(0, maxRows),
|
|
595
630
|
MESSAGE_TYPE: `REP_${resourceName}`,
|
|
596
|
-
|
|
631
|
+
PARAMETRIC_TYPE: typed.reply.className,
|
|
597
632
|
};
|
|
598
633
|
}
|
|
599
634
|
|
|
@@ -645,7 +680,7 @@ export function handleRequestReply(
|
|
|
645
680
|
}
|
|
646
681
|
|
|
647
682
|
if (isLegacyFidelity(config)) {
|
|
648
|
-
legacyRequestReply(resourceName, requestReply, message, connection, store);
|
|
683
|
+
legacyRequestReply(resourceName, requestReply, message, connection, config, store);
|
|
649
684
|
return;
|
|
650
685
|
}
|
|
651
686
|
|
|
@@ -653,7 +688,7 @@ export function handleRequestReply(
|
|
|
653
688
|
let reply: Row;
|
|
654
689
|
try {
|
|
655
690
|
if (requestReply.resolver) {
|
|
656
|
-
reply = resolverReply(resourceName, requestReply, message, store, user);
|
|
691
|
+
reply = resolverReply(resourceName, requestReply, message, config, store, user);
|
|
657
692
|
} else if (requestReply.criteriaOnly) {
|
|
658
693
|
reply = criteriaOnlyReply(resourceName, requestReply, message, config, store, user);
|
|
659
694
|
} else {
|
|
@@ -685,6 +720,7 @@ function legacyRequestReply(
|
|
|
685
720
|
requestReply: RequestReplyDef,
|
|
686
721
|
message: GenesisMessage,
|
|
687
722
|
connection: Connection,
|
|
723
|
+
config: MockServerConfig,
|
|
688
724
|
store: Store,
|
|
689
725
|
): void {
|
|
690
726
|
const user = requestingUser(connection);
|
|
@@ -693,7 +729,7 @@ function legacyRequestReply(
|
|
|
693
729
|
try {
|
|
694
730
|
let rows: Row[];
|
|
695
731
|
if (requestReply.resolver) {
|
|
696
|
-
rows = requestReply.resolver({ request, message, user, store });
|
|
732
|
+
rows = requestReply.resolver({ request, message, user, store, config });
|
|
697
733
|
} else {
|
|
698
734
|
rows = store.getResourceRows(requestReply.source!);
|
|
699
735
|
if (Object.keys(request).length > 0) {
|
package/src/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type {
|
|
|
23
23
|
AntiJoinDef,
|
|
24
24
|
AuditDef,
|
|
25
25
|
AuthConfig,
|
|
26
|
+
AuthDirectory,
|
|
26
27
|
AuthUser,
|
|
27
28
|
BroadcastFn,
|
|
28
29
|
BroadcastTableChangeFn,
|
|
@@ -35,9 +36,11 @@ export type {
|
|
|
35
36
|
FidelityMode,
|
|
36
37
|
FieldDef,
|
|
37
38
|
FieldMetadata,
|
|
39
|
+
FieldTypeDef,
|
|
38
40
|
GeneratedFieldDef,
|
|
39
41
|
GenesisFieldType,
|
|
40
42
|
GenesisMessage,
|
|
43
|
+
HttpRouteCtx,
|
|
41
44
|
HttpRouteDef,
|
|
42
45
|
IndexDef,
|
|
43
46
|
JoinDef,
|
|
@@ -46,7 +49,10 @@ export type {
|
|
|
46
49
|
JoinType,
|
|
47
50
|
JoinValueLink,
|
|
48
51
|
LiveModifyMode,
|
|
52
|
+
LoginCtx,
|
|
53
|
+
LoginFailure,
|
|
49
54
|
MockServerConfig,
|
|
55
|
+
NestedFieldType,
|
|
50
56
|
OnMessageCtx,
|
|
51
57
|
OnMessageHook,
|
|
52
58
|
ProductDetails,
|
|
@@ -61,6 +67,7 @@ export type {
|
|
|
61
67
|
SocketLike,
|
|
62
68
|
SsoIdentityProvider,
|
|
63
69
|
TableDef,
|
|
70
|
+
TypedRequestReply,
|
|
64
71
|
ViewDef,
|
|
65
72
|
ViewRowSources,
|
|
66
73
|
} from './types.ts';
|