@genesislcap/mock-server 15.74.0 → 15.76.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
|
@@ -33,6 +33,8 @@ export declare class Connection {
|
|
|
33
33
|
permission: string[];
|
|
34
34
|
readonly subscriptions: Map<string, Subscription>;
|
|
35
35
|
cookieSessionAuthToken: string | undefined;
|
|
36
|
+
hostnameHeader: string | undefined;
|
|
37
|
+
remoteAddress: string | undefined;
|
|
36
38
|
readonly createdAt: number;
|
|
37
39
|
lastReceived: number;
|
|
38
40
|
lastSent: number;
|
|
@@ -17,6 +17,10 @@ export class Connection {
|
|
|
17
17
|
// The sessionAuthToken cookie the socket was opened with, under
|
|
18
18
|
// auth.cookieAuthentication; it authenticates every message (router.ts).
|
|
19
19
|
cookieSessionAuthToken;
|
|
20
|
+
// The upgrade request's HOSTNAME header and the client's address, which
|
|
21
|
+
// GSF's router gives a login as DETAILS.HOSTNAME (auth.ts routerHostname).
|
|
22
|
+
hostnameHeader;
|
|
23
|
+
remoteAddress;
|
|
20
24
|
// A verbose HEARTBEAT_PONG's CREATED_AT, LAST_RECEIVED and LAST_SENT, as
|
|
21
25
|
// genesis-router's ClientHandler keeps them (ClientHandler.kt:66-68,
|
|
22
26
|
// 100-113 @v8.15.29): 0 until a message other than a heartbeat goes either
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FieldDef, FieldTypeDef, Row } from '../types.ts';
|
|
2
|
+
export declare const isNestedType: (type: string) => type is "ARRAY" | "MAP" | "OBJECT" | "ANY";
|
|
3
|
+
export interface TypeShape {
|
|
4
|
+
type: string;
|
|
5
|
+
nullable?: boolean;
|
|
6
|
+
values?: string[];
|
|
7
|
+
maxSize?: number;
|
|
8
|
+
minLength?: number;
|
|
9
|
+
description?: string;
|
|
10
|
+
items?: FieldTypeDef;
|
|
11
|
+
unique?: boolean;
|
|
12
|
+
className?: string;
|
|
13
|
+
fields?: FieldDef[];
|
|
14
|
+
enumClass?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface NestedClass {
|
|
17
|
+
className: string;
|
|
18
|
+
fields: FieldDef[];
|
|
19
|
+
}
|
|
20
|
+
export declare function nestedClassOf(def: TypeShape): string;
|
|
21
|
+
export declare function nestedClasses(defs: TypeShape[], found?: Map<string, NestedClass>): Map<string, NestedClass>;
|
|
22
|
+
export declare function upperUnderscore(name: string): string;
|
|
23
|
+
export declare function metaType(def: TypeShape): Row;
|
|
24
|
+
export declare function metaDefinitions(classes: Map<string, NestedClass>, properties: (nested: NestedClass) => Row[]): Row;
|
|
25
|
+
export declare function nestedProperty(def: TypeShape): Row;
|
|
26
|
+
export declare function decodedValue(def: TypeShape, value: unknown): unknown;
|
|
27
|
+
export declare function jsonDefs(classes: Map<string, NestedClass>, resolve: (nested: NestedClass) => Array<TypeShape & {
|
|
28
|
+
name: string;
|
|
29
|
+
optional?: boolean;
|
|
30
|
+
}>): Row;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// DTO fields that hold more than one value: a Kotlin List or Set (ARRAY), a
|
|
2
|
+
// Map (MAP), a nested class (OBJECT) or Any (ANY), as GSF 8.15.29 describes
|
|
3
|
+
// and checks them (genesis-process metadata/pal: PALMetadataUtils.kt
|
|
4
|
+
// mapPropertyType, common/MetaFieldType.kt, jsonschema/JsonSchema.kt):
|
|
5
|
+
// - META: the type sits in the field's FIELD entry (MetaField's
|
|
6
|
+
// @JsonUnwrapped type), an ARRAY's items and a MAP's values as VALUE_TYPE,
|
|
7
|
+
// a nested class as a REFERENCE to its DEFINITIONS entry, keyed by its
|
|
8
|
+
// class name;
|
|
9
|
+
// - JSON schema: a DETAILS property through toJsonSchemaType, a nested
|
|
10
|
+
// class in $defs through mapJsonSchemaProperty, which orders keys
|
|
11
|
+
// differently, puts null first in a nullable's oneOf and puts an array's
|
|
12
|
+
// uniqueItems inside its items.
|
|
13
|
+
// A DESCRIPTION / description is the property's class: kotlin.collections.Set
|
|
14
|
+
// / List / Map, kotlin.Any, or the nested class's name.
|
|
15
|
+
import { eventMetaTypeOf, jsonTypeOf, jvmClassOf } from "./fieldTypes.js";
|
|
16
|
+
export const isNestedType = (type) => type === 'ARRAY' || type === 'MAP' || type === 'OBJECT' || type === 'ANY';
|
|
17
|
+
const ANY = { type: 'ANY' };
|
|
18
|
+
// The class a nested field's DESCRIPTION names.
|
|
19
|
+
export function nestedClassOf(def) {
|
|
20
|
+
if (def.type === 'ARRAY')
|
|
21
|
+
return def.unique ? 'kotlin.collections.Set' : 'kotlin.collections.List';
|
|
22
|
+
if (def.type === 'MAP')
|
|
23
|
+
return 'kotlin.collections.Map';
|
|
24
|
+
if (def.type === 'OBJECT')
|
|
25
|
+
return def.className ?? 'kotlin.Any';
|
|
26
|
+
return 'kotlin.Any';
|
|
27
|
+
}
|
|
28
|
+
// Every nested class the fields reach, the first time each is met, as GSF
|
|
29
|
+
// adds them to the definitions while it walks the class (depth first).
|
|
30
|
+
export function nestedClasses(defs, found = new Map()) {
|
|
31
|
+
for (const def of defs) {
|
|
32
|
+
if (def.type === 'OBJECT' && def.className && !found.has(def.className)) {
|
|
33
|
+
found.set(def.className, { className: def.className, fields: def.fields ?? [] });
|
|
34
|
+
nestedClasses(def.fields ?? [], found);
|
|
35
|
+
}
|
|
36
|
+
if (def.items)
|
|
37
|
+
nestedClasses([def.items], found);
|
|
38
|
+
}
|
|
39
|
+
return found;
|
|
40
|
+
}
|
|
41
|
+
const simpleName = (className) => className.slice(className.lastIndexOf('.') + 1);
|
|
42
|
+
// 'NotifyRoute' -> 'NOTIFY_ROUTE' (toUpperUnderscoreWithAcronyms).
|
|
43
|
+
export function upperUnderscore(name) {
|
|
44
|
+
return name
|
|
45
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
46
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2')
|
|
47
|
+
.toUpperCase();
|
|
48
|
+
}
|
|
49
|
+
// --- META ----------------------------------------------------------------------
|
|
50
|
+
// A type as META writes it unwrapped: NULLABLE, the type's own fields, TYPE
|
|
51
|
+
// and JSON_TYPE. Any is always nullable.
|
|
52
|
+
export function metaType(def) {
|
|
53
|
+
const NULLABLE = def.type === 'ANY' ? true : (def.nullable ?? false);
|
|
54
|
+
switch (def.type) {
|
|
55
|
+
case 'ARRAY':
|
|
56
|
+
return {
|
|
57
|
+
NULLABLE,
|
|
58
|
+
VALUE_TYPE: metaType(def.items ?? ANY),
|
|
59
|
+
UNIQUE: def.unique ?? false,
|
|
60
|
+
TYPE: 'ARRAY',
|
|
61
|
+
JSON_TYPE: 'array',
|
|
62
|
+
};
|
|
63
|
+
case 'MAP':
|
|
64
|
+
return {
|
|
65
|
+
NULLABLE,
|
|
66
|
+
KEY_TYPE: { NULLABLE: false, TYPE: 'STRING', JSON_TYPE: 'string' },
|
|
67
|
+
VALUE_TYPE: metaType(def.items ?? ANY),
|
|
68
|
+
TYPE: 'MAP',
|
|
69
|
+
JSON_TYPE: 'object',
|
|
70
|
+
};
|
|
71
|
+
case 'OBJECT':
|
|
72
|
+
if (!def.className)
|
|
73
|
+
return metaType(ANY);
|
|
74
|
+
return { NULLABLE, REFERENCE: def.className, TYPE: 'OBJECT', JSON_TYPE: 'object' };
|
|
75
|
+
// MetaFieldType.AnyType, an object with no constructor: Jackson writes its
|
|
76
|
+
// properties in declaration order, its null default included (as a
|
|
77
|
+
// recorded SYSTEM_ENTITY_FIELDS META shows).
|
|
78
|
+
case 'ANY':
|
|
79
|
+
return { TYPE: 'ANY', JSON_TYPE: jsonTypeOf('ANY'), NULLABLE, DEFAULT_VALUE: null };
|
|
80
|
+
case 'ENUM':
|
|
81
|
+
return {
|
|
82
|
+
NULLABLE,
|
|
83
|
+
...(def.values?.length ? { VALID_VALUES: def.values, DEFAULT_VALUE: def.values[0] } : {}),
|
|
84
|
+
ENUM_CLASS: def.enumClass ?? 'kotlin.Enum',
|
|
85
|
+
TYPE: 'ENUM',
|
|
86
|
+
JSON_TYPE: 'string',
|
|
87
|
+
};
|
|
88
|
+
default:
|
|
89
|
+
return { NULLABLE, TYPE: eventMetaTypeOf(def.type), JSON_TYPE: jsonTypeOf(def.type) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// DEFINITIONS: each nested class as {NAME, DESCRIPTION, PROPERTIES}, its
|
|
93
|
+
// properties written as the event's own FIELD entries are.
|
|
94
|
+
export function metaDefinitions(classes, properties) {
|
|
95
|
+
return Object.fromEntries([...classes.values()].map((nested) => [
|
|
96
|
+
nested.className,
|
|
97
|
+
{
|
|
98
|
+
NAME: upperUnderscore(simpleName(nested.className)),
|
|
99
|
+
DESCRIPTION: nested.className,
|
|
100
|
+
PROPERTIES: properties(nested),
|
|
101
|
+
},
|
|
102
|
+
]));
|
|
103
|
+
}
|
|
104
|
+
// --- JSON schema: DETAILS properties (toJsonSchemaType) -----------------------
|
|
105
|
+
const ref = (className) => ({ $ref: `#/$defs/${className}` });
|
|
106
|
+
const orNull = (schema, nullable) => nullable ? { oneOf: [schema, { type: 'null' }] } : schema;
|
|
107
|
+
// The bare type: an array's items or a map's values, with no annotations.
|
|
108
|
+
function itemSchema(def) {
|
|
109
|
+
switch (def.type) {
|
|
110
|
+
case 'ARRAY':
|
|
111
|
+
return orNull({ items: itemSchema(def.items ?? ANY), uniqueItems: def.unique ?? false, type: 'array' }, def.nullable);
|
|
112
|
+
case 'MAP':
|
|
113
|
+
return orNull({ additionalProperties: true, type: 'object' }, def.nullable);
|
|
114
|
+
case 'OBJECT':
|
|
115
|
+
return def.className ? orNull(ref(def.className), def.nullable) : itemSchema(ANY);
|
|
116
|
+
case 'ANY':
|
|
117
|
+
return anySchema({});
|
|
118
|
+
case 'ENUM':
|
|
119
|
+
return orNull({ ...(def.values?.length ? { enum: def.values } : {}), type: 'string' }, def.nullable);
|
|
120
|
+
case 'BIGDECIMAL':
|
|
121
|
+
return orNull({ pattern: '[0-9]+(\\.[0-9]+)?', type: 'string' }, def.nullable);
|
|
122
|
+
default:
|
|
123
|
+
return orNull({ type: jsonTypeOf(def.type) }, def.nullable);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Any: an object, string, number or boolean, and null.
|
|
127
|
+
function anySchema(annotations) {
|
|
128
|
+
return {
|
|
129
|
+
oneOf: [
|
|
130
|
+
{
|
|
131
|
+
oneOf: ['object', 'string', 'number', 'boolean'].map((type) => ({ ...annotations, type })),
|
|
132
|
+
},
|
|
133
|
+
{ type: 'null' },
|
|
134
|
+
],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
// A DETAILS property whose type is nested.
|
|
138
|
+
export function nestedProperty(def) {
|
|
139
|
+
const description = nestedClassOf(def);
|
|
140
|
+
switch (def.type) {
|
|
141
|
+
case 'ARRAY':
|
|
142
|
+
return orNull({
|
|
143
|
+
items: itemSchema(def.items ?? ANY),
|
|
144
|
+
uniqueItems: def.unique ?? false,
|
|
145
|
+
readOnly: false,
|
|
146
|
+
description,
|
|
147
|
+
type: 'array',
|
|
148
|
+
}, def.nullable);
|
|
149
|
+
case 'MAP':
|
|
150
|
+
return orNull({ additionalProperties: true, type: 'object' }, def.nullable);
|
|
151
|
+
case 'OBJECT':
|
|
152
|
+
return def.className ? orNull(ref(def.className), def.nullable) : nestedProperty(ANY);
|
|
153
|
+
default:
|
|
154
|
+
return anySchema({ readOnly: false, description });
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
// --- decoding ----------------------------------------------------------------------
|
|
158
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
159
|
+
// A nested value as Jackson decodes it into its class: the keys a nested
|
|
160
|
+
// class doesn't declare dropped (GSF's mapper doesn't fail on unknown
|
|
161
|
+
// properties, GenesisJacksonMapper.kt:260 @v8.15.29), in its lists and maps
|
|
162
|
+
// too. The value itself when nothing is dropped.
|
|
163
|
+
export function decodedValue(def, value) {
|
|
164
|
+
if (def.type === 'OBJECT' && def.className && isRecord(value)) {
|
|
165
|
+
const fields = new Map((def.fields ?? []).map((field) => [field.name, field]));
|
|
166
|
+
let changed = false;
|
|
167
|
+
const decoded = {};
|
|
168
|
+
for (const [key, item] of Object.entries(value)) {
|
|
169
|
+
const field = fields.get(key);
|
|
170
|
+
if (!field) {
|
|
171
|
+
changed = true;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
decoded[key] = decodedValue(field, item);
|
|
175
|
+
changed ||= decoded[key] !== item;
|
|
176
|
+
}
|
|
177
|
+
return changed ? decoded : value;
|
|
178
|
+
}
|
|
179
|
+
const items = def.items;
|
|
180
|
+
if (def.type === 'ARRAY' && items && Array.isArray(value)) {
|
|
181
|
+
const decoded = value.map((item) => decodedValue(items, item));
|
|
182
|
+
return decoded.some((item, index) => item !== value[index]) ? decoded : value;
|
|
183
|
+
}
|
|
184
|
+
if (def.type === 'MAP' && items && isRecord(value)) {
|
|
185
|
+
const decoded = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, decodedValue(items, item)]));
|
|
186
|
+
return Object.keys(value).some((key) => decoded[key] !== value[key]) ? decoded : value;
|
|
187
|
+
}
|
|
188
|
+
return value;
|
|
189
|
+
}
|
|
190
|
+
// --- JSON schema: $defs (mapJsonSchemaProperty) --------------------------------
|
|
191
|
+
function defsType(def, nullable) {
|
|
192
|
+
if (nullable)
|
|
193
|
+
return { oneOf: [{ type: 'null' }, defsType(def, false)] };
|
|
194
|
+
const type = def.type;
|
|
195
|
+
const schema = { type: jsonTypeOf(type) };
|
|
196
|
+
if (type === 'STRING') {
|
|
197
|
+
if (def.maxSize !== undefined)
|
|
198
|
+
schema.maxLength = def.maxSize;
|
|
199
|
+
if (def.minLength !== undefined)
|
|
200
|
+
schema.minLength = def.minLength;
|
|
201
|
+
}
|
|
202
|
+
if (type === 'OBJECT') {
|
|
203
|
+
if (def.className)
|
|
204
|
+
schema.$ref = `#/$defs/${def.className}`;
|
|
205
|
+
else
|
|
206
|
+
schema.additionalProperties = true;
|
|
207
|
+
}
|
|
208
|
+
if (type === 'MAP' && def.items && def.items.type !== 'ANY') {
|
|
209
|
+
schema.additionalProperties = defsType(def.items, typeNullable(def.items));
|
|
210
|
+
}
|
|
211
|
+
if (type === 'ENUM' && def.values?.length)
|
|
212
|
+
schema.enum = def.values;
|
|
213
|
+
if (type === 'ARRAY') {
|
|
214
|
+
const items = def.items ?? ANY;
|
|
215
|
+
schema.items = {
|
|
216
|
+
...defsType(items, typeNullable(items)),
|
|
217
|
+
...(def.unique ? { uniqueItems: true } : {}),
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return schema;
|
|
221
|
+
}
|
|
222
|
+
const typeNullable = (def) => (def.type === 'ANY' ? true : (def.nullable ?? false));
|
|
223
|
+
// $defs: each nested class as an object schema of its properties, closed to
|
|
224
|
+
// any other (no class here carries @AdditionalProperties), requiring the
|
|
225
|
+
// ones that aren't optional.
|
|
226
|
+
export function jsonDefs(classes, resolve) {
|
|
227
|
+
return Object.fromEntries([...classes.values()].map((nested) => {
|
|
228
|
+
const properties = resolve(nested);
|
|
229
|
+
const required = properties.filter((field) => !field.optional).map((field) => field.name);
|
|
230
|
+
return [
|
|
231
|
+
nested.className,
|
|
232
|
+
{
|
|
233
|
+
type: 'object',
|
|
234
|
+
description: nested.className,
|
|
235
|
+
properties: Object.fromEntries(properties.map((field) => [
|
|
236
|
+
field.name,
|
|
237
|
+
{
|
|
238
|
+
...defsType(field, typeNullable(field)),
|
|
239
|
+
description: isNestedType(field.type)
|
|
240
|
+
? nestedClassOf(field)
|
|
241
|
+
: (field.description ??
|
|
242
|
+
jvmClassOf(field.type, () => field.enumClass ?? 'kotlin.Enum')),
|
|
243
|
+
},
|
|
244
|
+
])),
|
|
245
|
+
additionalProperties: false,
|
|
246
|
+
...(required.length > 0 ? { required } : {}),
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
@@ -60,7 +60,7 @@ export type ErrorCodeName = keyof typeof ERROR_CODES;
|
|
|
60
60
|
export declare const ErrorCode: { readonly [Name in ErrorCodeName]: Name; };
|
|
61
61
|
export declare function statusCodeFor(code: string): string;
|
|
62
62
|
export declare function defaultTextFor(code: string): string | undefined;
|
|
63
|
-
export type GenesisErrorType = 'StandardError' | 'FieldError' | 'TableStandardError' | 'LoginError';
|
|
63
|
+
export type GenesisErrorType = 'StandardError' | 'FieldError' | 'TableStandardError' | 'LoginError' | 'PasswordValidationError';
|
|
64
64
|
export interface NackErrorInput {
|
|
65
65
|
'@type'?: GenesisErrorType;
|
|
66
66
|
CODE?: string;
|
|
@@ -90,12 +90,14 @@ export declare function toNackEntry(input: NackErrorInput): NackErrorEntry;
|
|
|
90
90
|
export declare function toLegacyNackEntry(input: NackErrorInput): NackErrorEntry;
|
|
91
91
|
export interface NackErrorOptions {
|
|
92
92
|
warnings?: NackErrorInput | NackErrorInput[];
|
|
93
|
+
messageType?: string;
|
|
93
94
|
}
|
|
94
95
|
export declare class NackError extends Error {
|
|
95
96
|
readonly errors: NackErrorEntry[];
|
|
96
97
|
readonly warnings: NackErrorEntry[];
|
|
97
98
|
readonly inputs: readonly NackErrorInput[];
|
|
98
99
|
readonly warningInputs: readonly NackErrorInput[];
|
|
100
|
+
readonly messageType: string | undefined;
|
|
99
101
|
constructor(errors: string | NackErrorInput | NackErrorInput[], options?: NackErrorOptions);
|
|
100
102
|
static field(field: string, text: string, path?: string | null, code?: string): NackError;
|
|
101
103
|
static standard(code: string, text?: string): NackError;
|
package/dist/protocol/errors.js
CHANGED
|
@@ -204,6 +204,7 @@ export class NackError extends Error {
|
|
|
204
204
|
warnings;
|
|
205
205
|
inputs;
|
|
206
206
|
warningInputs;
|
|
207
|
+
messageType;
|
|
207
208
|
constructor(errors, options = {}) {
|
|
208
209
|
const inputs = asList(errors);
|
|
209
210
|
const warningInputs = asList(options.warnings);
|
|
@@ -215,6 +216,7 @@ export class NackError extends Error {
|
|
|
215
216
|
this.warningInputs = warningInputs;
|
|
216
217
|
this.errors = entries;
|
|
217
218
|
this.warnings = warnings;
|
|
219
|
+
this.messageType = options.messageType;
|
|
218
220
|
}
|
|
219
221
|
// A FieldError: VALIDATION_ERROR (400) naming the field. PATH is the JSON
|
|
220
222
|
// path the error was found at — null (the default) for a handler's own
|
|
@@ -19,6 +19,11 @@ const JSON_TYPES = {
|
|
|
19
19
|
DATETIME: 'integer',
|
|
20
20
|
NANO_TIMESTAMP: 'integer',
|
|
21
21
|
RAW: 'string',
|
|
22
|
+
// A DTO's nested types (dtoTypes.ts): GSF's MetaFieldType jsonType.
|
|
23
|
+
ARRAY: 'array',
|
|
24
|
+
MAP: 'object',
|
|
25
|
+
OBJECT: 'object',
|
|
26
|
+
ANY: '{}',
|
|
22
27
|
};
|
|
23
28
|
// The JVM class of the generated DAO property, which the real server puts in
|
|
24
29
|
// DESCRIPTION / description. foundation-forms recognises a date field by
|
|
@@ -3,4 +3,5 @@ import { type AuthState } from '../handlers/auth.ts';
|
|
|
3
3
|
import { type CommitEventCtx } from '../handlers/commitEvent.ts';
|
|
4
4
|
import type { GenesisMessage, MockServerConfig } from '../types.ts';
|
|
5
5
|
import type { Connection } from './connection.ts';
|
|
6
|
+
export declare function replyNotLoggedOn(message: GenesisMessage, connection: Connection): void;
|
|
6
7
|
export declare function routeMessage(inbound: GenesisMessage, connection: Connection, config: MockServerConfig, store: Store, ctx: CommitEventCtx, auth?: AuthState): void;
|
package/dist/protocol/router.js
CHANGED
|
@@ -56,7 +56,7 @@ function ensureAuthenticated(message, connection, tokens) {
|
|
|
56
56
|
// Error reply for unauthenticated traffic, shaped per message family the same
|
|
57
57
|
// way each handler's own error paths are (REP_* for REQ_*, *_NACK for events,
|
|
58
58
|
// QUERY_UPDATE for DATA_LOGON, echoed MESSAGE_TYPE for META/JSON_SCHEMA).
|
|
59
|
-
function replyNotLoggedOn(message, connection) {
|
|
59
|
+
export function replyNotLoggedOn(message, connection) {
|
|
60
60
|
const type = message.MESSAGE_TYPE;
|
|
61
61
|
const ERROR = [{ CODE: ERROR_CODE.NOT_LOGGED_ON, TEXT: 'Not logged on' }];
|
|
62
62
|
if (isRequestReply(type)) {
|
|
@@ -111,9 +111,9 @@ export function routeMessage(inbound, connection, config, store, ctx, auth = cre
|
|
|
111
111
|
}
|
|
112
112
|
switch (message.MESSAGE_TYPE) {
|
|
113
113
|
case MESSAGE_TYPE.EVENT_LOGIN_AUTH:
|
|
114
|
-
return handleLogin(message, connection, config, auth);
|
|
114
|
+
return handleLogin(message, connection, config, auth, store, ctx.broadcastTableChange);
|
|
115
115
|
case MESSAGE_TYPE.EVENT_LOGOUT:
|
|
116
|
-
return handleLogout(message, connection, config, auth);
|
|
116
|
+
return handleLogout(message, connection, config, auth, store, ctx.broadcastTableChange);
|
|
117
117
|
case MESSAGE_TYPE.HEARTBEAT_PING:
|
|
118
118
|
return handleHeartbeat(message, connection, config, auth);
|
|
119
119
|
case MESSAGE_TYPE.DATA_LOGON:
|
|
@@ -6,6 +6,6 @@ export interface SchemaError {
|
|
|
6
6
|
property?: string;
|
|
7
7
|
message: string;
|
|
8
8
|
}
|
|
9
|
-
export declare function validateSchema(schema: Schema, value: unknown, location?: string): SchemaError[];
|
|
9
|
+
export declare function validateSchema(schema: Schema, value: unknown, location?: string, root?: Schema): SchemaError[];
|
|
10
10
|
export declare function schemaFieldErrors(errors: SchemaError[]): NackErrorInput[];
|
|
11
11
|
export {};
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
// GenesisJsonSchemaFactory (draft 2019-09, PathType.LEGACY,
|
|
7
7
|
// losslessNarrowing). This is the subset of that validator the engine's own
|
|
8
8
|
// event schemas need: type, const, enum, oneOf, properties, required,
|
|
9
|
-
// additionalProperties, minLength / maxLength, minimum / maximum and
|
|
9
|
+
// additionalProperties, minLength / maxLength, minimum / maximum, pattern, and
|
|
10
|
+
// for a DTO's lists, sets and nested classes items, uniqueItems and $ref (into
|
|
11
|
+
// the schema's own $defs).
|
|
10
12
|
// Texts, locations and their order follow networknt's output, checked by
|
|
11
13
|
// running the real validator on the recorded showcase schemas
|
|
12
14
|
// (test/schemaValidation.test.ts pins the cases).
|
|
@@ -45,11 +47,26 @@ function deepEqual(a, b) {
|
|
|
45
47
|
}
|
|
46
48
|
return false;
|
|
47
49
|
}
|
|
50
|
+
// A JSON value written with its object keys sorted: the same text for two
|
|
51
|
+
// values deepEqual calls equal, so a long array's repeats are found in one
|
|
52
|
+
// pass.
|
|
53
|
+
function canonical(value) {
|
|
54
|
+
if (Array.isArray(value))
|
|
55
|
+
return `[${value.map(canonical).join(',')}]`;
|
|
56
|
+
if (isObject(value)) {
|
|
57
|
+
const entries = Object.keys(value)
|
|
58
|
+
.sort()
|
|
59
|
+
.map((key) => `${JSON.stringify(key)}:${canonical(value[key])}`);
|
|
60
|
+
return `{${entries.join(',')}}`;
|
|
61
|
+
}
|
|
62
|
+
return JSON.stringify(value) ?? 'undefined';
|
|
63
|
+
}
|
|
48
64
|
// networknt evaluates these before a schema's other keywords, whatever their
|
|
49
65
|
// position; the rest go in key order.
|
|
50
66
|
const FIRST_KEYWORDS = ['type', 'properties'];
|
|
51
67
|
// String lengths count code points, as Java's codePointCount does.
|
|
52
68
|
const codePoints = (text) => [...text].length;
|
|
69
|
+
const DEFS = '#/$defs/';
|
|
53
70
|
const NOT_DEFINED = 'is not defined in the schema and the schema does not allow additional properties';
|
|
54
71
|
// One check per keyword, each a no-op on values it doesn't apply to (string
|
|
55
72
|
// keywords on non-strings, object keywords on non-objects, ...).
|
|
@@ -93,10 +110,10 @@ const KEYWORDS = {
|
|
|
93
110
|
fail(`does not match the regex pattern ${arg}`);
|
|
94
111
|
}
|
|
95
112
|
},
|
|
96
|
-
oneOf({ arg, value, location, errors, fail }) {
|
|
113
|
+
oneOf({ arg, root, value, location, errors, fail }) {
|
|
97
114
|
if (!Array.isArray(arg))
|
|
98
115
|
return;
|
|
99
|
-
const results = arg.map((branch) => validateSchema(branch, value, location));
|
|
116
|
+
const results = arg.map((branch) => validateSchema(branch, value, location, root));
|
|
100
117
|
const valid = results.flatMap((result, index) => (result.length === 0 ? [index] : []));
|
|
101
118
|
if (valid.length === 1)
|
|
102
119
|
return;
|
|
@@ -107,13 +124,13 @@ const KEYWORDS = {
|
|
|
107
124
|
fail('must be valid to one and only one schema, but 0 are valid');
|
|
108
125
|
errors.push(...results.flat());
|
|
109
126
|
},
|
|
110
|
-
properties({ arg, value, location, errors }) {
|
|
127
|
+
properties({ arg, root, value, location, errors }) {
|
|
111
128
|
if (!isObject(value) || !isObject(arg))
|
|
112
129
|
return;
|
|
113
130
|
for (const [name, propertySchema] of Object.entries(arg)) {
|
|
114
131
|
if (!Object.hasOwn(value, name))
|
|
115
132
|
continue;
|
|
116
|
-
errors.push(...validateSchema(propertySchema, value[name], `${location}.${name}
|
|
133
|
+
errors.push(...validateSchema(propertySchema, value[name], `${location}.${name}`, root));
|
|
117
134
|
}
|
|
118
135
|
},
|
|
119
136
|
required({ arg, value, fail }) {
|
|
@@ -124,7 +141,7 @@ const KEYWORDS = {
|
|
|
124
141
|
fail(`required property '${name}' not found`, name);
|
|
125
142
|
}
|
|
126
143
|
},
|
|
127
|
-
additionalProperties({ arg, schema, value, location, errors, fail }) {
|
|
144
|
+
additionalProperties({ arg, schema, root, value, location, errors, fail }) {
|
|
128
145
|
if (!isObject(value) || (arg !== false && !isObject(arg)))
|
|
129
146
|
return;
|
|
130
147
|
const known = isObject(schema.properties) ? schema.properties : {};
|
|
@@ -134,14 +151,41 @@ const KEYWORDS = {
|
|
|
134
151
|
if (arg === false)
|
|
135
152
|
fail(`property '${name}' ${NOT_DEFINED}`, name);
|
|
136
153
|
else
|
|
137
|
-
errors.push(...validateSchema(arg, value[name], `${location}.${name}
|
|
154
|
+
errors.push(...validateSchema(arg, value[name], `${location}.${name}`, root));
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
items({ arg, root, value, location, errors }) {
|
|
158
|
+
if (!Array.isArray(value) || !isObject(arg))
|
|
159
|
+
return;
|
|
160
|
+
value.forEach((item, index) => {
|
|
161
|
+
errors.push(...validateSchema(arg, item, `${location}[${index}]`, root));
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
uniqueItems({ arg, value, fail }) {
|
|
165
|
+
if (arg !== true || !Array.isArray(value))
|
|
166
|
+
return;
|
|
167
|
+
const seen = new Set();
|
|
168
|
+
for (const item of value) {
|
|
169
|
+
const key = canonical(item);
|
|
170
|
+
if (seen.has(key)) {
|
|
171
|
+
fail('must have only unique items in the array');
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
seen.add(key);
|
|
138
175
|
}
|
|
139
176
|
},
|
|
177
|
+
// Only the schema's own definitions: '#/$defs/<name>'.
|
|
178
|
+
$ref({ arg, root, value, location, errors }) {
|
|
179
|
+
const name = typeof arg === 'string' && arg.startsWith(DEFS) ? arg.slice(DEFS.length) : undefined;
|
|
180
|
+
const target = name !== undefined && isObject(root.$defs) ? root.$defs[name] : undefined;
|
|
181
|
+
if (isObject(target))
|
|
182
|
+
errors.push(...validateSchema(target, value, location, root));
|
|
183
|
+
},
|
|
140
184
|
// Anything else is an annotation (description, title, default, readOnly,
|
|
141
185
|
// genesisType, $schema, $defs, ...) and validates nothing; networknt
|
|
142
186
|
// doesn't enforce readOnly unless asked to.
|
|
143
187
|
};
|
|
144
|
-
export function validateSchema(schema, value, location = '$') {
|
|
188
|
+
export function validateSchema(schema, value, location = '$', root = schema) {
|
|
145
189
|
const errors = [];
|
|
146
190
|
if (!isObject(schema))
|
|
147
191
|
return errors;
|
|
@@ -156,6 +200,7 @@ export function validateSchema(schema, value, location = '$') {
|
|
|
156
200
|
KEYWORDS[keyword]({
|
|
157
201
|
arg: schema[keyword],
|
|
158
202
|
schema,
|
|
203
|
+
root,
|
|
159
204
|
value,
|
|
160
205
|
location,
|
|
161
206
|
errors,
|
package/dist/server.js
CHANGED
|
@@ -6,14 +6,17 @@ import { compareRecordIds } from "./db/ordering.js";
|
|
|
6
6
|
import { Store } from "./db/store.js";
|
|
7
7
|
import { entriesReading, planView, } from "./db/views.js";
|
|
8
8
|
import { createAuthState } from "./handlers/auth.js";
|
|
9
|
+
import { handleCommitEvent } from "./handlers/commitEvent.js";
|
|
9
10
|
import { crudEventHandler } from "./handlers/crudEvents.js";
|
|
10
11
|
import { pendingKey, viewRow, waitForPage } from "./handlers/dataLogon.js";
|
|
11
12
|
import { cookieAuthentication, createHttpRequestListener, parseCookies, SESSION_AUTH_TOKEN_COOKIE, } from "./handlers/http.js";
|
|
12
13
|
import { permittedQueryRow, requestingUser } from "./handlers/resourceAuth.js";
|
|
13
14
|
import { Connection } from "./protocol/connection.js";
|
|
14
15
|
import { isLegacyFidelity, liveModifyMode } from "./protocol/fidelity.js";
|
|
15
|
-
import { routeMessage } from "./protocol/router.js";
|
|
16
|
+
import { replyNotLoggedOn, routeMessage } from "./protocol/router.js";
|
|
16
17
|
import { dataserverRow, stampRow } from "./protocol/rowUpdate.js";
|
|
18
|
+
// WebSocket.OPEN: what a socket of the engine's own reports.
|
|
19
|
+
const WS_OPEN = 1;
|
|
17
20
|
// Whether two values are the same: the same primitive, or the same JSON.
|
|
18
21
|
function sameValue(a, b) {
|
|
19
22
|
return Object.is(a, b) || JSON.stringify(a) === JSON.stringify(b);
|
|
@@ -541,6 +544,27 @@ export function createMockServer(config) {
|
|
|
541
544
|
function extendEventHandler(eventName, augment) {
|
|
542
545
|
setEventHandler(eventName, augment(getEventHandler(eventName)));
|
|
543
546
|
}
|
|
547
|
+
// An event POSTed over HTTP (HttpRouteCtx.commitEvent): run through the
|
|
548
|
+
// socket's commit path on a connection of its own, whose one reply is the
|
|
549
|
+
// answer.
|
|
550
|
+
function commitEventOverHttp(message, userName) {
|
|
551
|
+
let reply = {};
|
|
552
|
+
const connection = new Connection({
|
|
553
|
+
readyState: WS_OPEN,
|
|
554
|
+
send: (data) => {
|
|
555
|
+
reply = JSON.parse(data);
|
|
556
|
+
},
|
|
557
|
+
});
|
|
558
|
+
connection.authenticated = userName !== undefined;
|
|
559
|
+
connection.userName = userName;
|
|
560
|
+
if (config.auth?.requireAuth && !connection.authenticated) {
|
|
561
|
+
replyNotLoggedOn(message, connection);
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
handleCommitEvent(message, connection, config, store, { broadcast, broadcastTableChange });
|
|
565
|
+
}
|
|
566
|
+
return reply;
|
|
567
|
+
}
|
|
544
568
|
let wss;
|
|
545
569
|
let httpServer;
|
|
546
570
|
function start(port) {
|
|
@@ -550,7 +574,12 @@ export function createMockServer(config) {
|
|
|
550
574
|
// node:http + the `ws` package rather than a runtime-specific API (e.g.
|
|
551
575
|
// Bun.serve) so this runs unmodified under both Node (>=22.6, via
|
|
552
576
|
// `node --experimental-strip-types`) and Bun.
|
|
553
|
-
httpServer = http.createServer(createHttpRequestListener(config, legacyHttpSessions, auth
|
|
577
|
+
httpServer = http.createServer(createHttpRequestListener(config, legacyHttpSessions, auth, {
|
|
578
|
+
store,
|
|
579
|
+
broadcast,
|
|
580
|
+
broadcastTableChange,
|
|
581
|
+
commitEvent: commitEventOverHttp,
|
|
582
|
+
}));
|
|
554
583
|
// A cookie-authenticated router answers an upgrade without a live
|
|
555
584
|
// sessionAuthToken cookie with HTTP 401 (PreHttpHandlerProvider.kt:61-95
|
|
556
585
|
// @v8.15.29). Read per upgrade, like every config field.
|
|
@@ -568,6 +597,9 @@ export function createMockServer(config) {
|
|
|
568
597
|
const connection = new Connection(ws);
|
|
569
598
|
if (cookieAuthentication(config))
|
|
570
599
|
connection.cookieSessionAuthToken = cookieToken(req);
|
|
600
|
+
const hostname = req.headers.hostname;
|
|
601
|
+
connection.hostnameHeader = typeof hostname === 'string' ? hostname : undefined;
|
|
602
|
+
connection.remoteAddress = req.socket.remoteAddress;
|
|
571
603
|
connections.add(connection);
|
|
572
604
|
ws.on('message', (data) => {
|
|
573
605
|
let message;
|