@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
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { eventDefaultOf, eventFields, inferEventTable, knownValues, isDeleteEventName, querySchema, requestFieldsOf, requestReplyReplySchema, requestReplySourceSchema, resolveEventTarget, resolveSourceSchema, withTypeOverrides, } from "../db/schema.js";
|
|
1
|
+
import { dtoFields, eventDefaultOf, eventFields, inferEventTable, knownValues, isDeleteEventName, querySchema, requestFieldsOf, requestReplyReplySchema, requestReplySourceSchema, resolveEventTarget, resolveSourceSchema, typedFields, withTypeOverrides, } from "../db/schema.js";
|
|
2
|
+
import { isNestedType, jsonDefs, nestedClasses, nestedProperty } from "../protocol/dtoTypes.js";
|
|
2
3
|
import { isLegacyFidelity } from "../protocol/fidelity.js";
|
|
3
4
|
import { BIGDECIMAL_PATTERN, enumClassOf, jsonTypeOf, jvmClassOf, rangeOf, titleCase, } from "../protocol/fieldTypes.js";
|
|
4
5
|
import { dataLogonReplySchema, dataLogonSchema, eventInboundProperties, eventReplySchema, GENESIS_META_SCHEMA, REQUEST_DETAILS_SCHEMA, } from "../protocol/gsfSchemas.js";
|
|
@@ -27,10 +28,13 @@ export { inferEventTable };
|
|
|
27
28
|
// One DETAILS property of an event's INBOUND schema. Nullable fields are
|
|
28
29
|
// oneOf [schema, null]; BigDecimal is a string with a pattern and no
|
|
29
30
|
// genesisType; dates are integers (epoch millis) described as DateTime. Only
|
|
30
|
-
// a table event's DAO class
|
|
31
|
-
// (see meta.ts eventMetaField).
|
|
32
|
-
function eventProperty(field,
|
|
31
|
+
// a table event's DAO class, and a DAO a DTO unwraps, have titles, lengths,
|
|
32
|
+
// ranges and genesisTypes (see meta.ts eventMetaField).
|
|
33
|
+
function eventProperty(field, table, appName) {
|
|
33
34
|
const type = field.type;
|
|
35
|
+
if (isNestedType(type))
|
|
36
|
+
return nestedProperty(field);
|
|
37
|
+
const annotated = table || field.dao === true;
|
|
34
38
|
const property = {};
|
|
35
39
|
if (annotated && type === 'STRING') {
|
|
36
40
|
if (field.minLength !== undefined)
|
|
@@ -47,7 +51,8 @@ function eventProperty(field, annotated, appName) {
|
|
|
47
51
|
if (type === 'ENUM' && knownValues(field))
|
|
48
52
|
property.enum = knownValues(field);
|
|
49
53
|
property.description =
|
|
50
|
-
field.description ??
|
|
54
|
+
field.description ??
|
|
55
|
+
jvmClassOf(type, () => field.enumClass ?? enumClassOf(field.table, field.name, appName));
|
|
51
56
|
const fieldDefault = eventDefaultOf(field);
|
|
52
57
|
if (fieldDefault !== undefined)
|
|
53
58
|
property.default = fieldDefault;
|
|
@@ -64,6 +69,27 @@ function eventProperty(field, annotated, appName) {
|
|
|
64
69
|
function isRequired(field) {
|
|
65
70
|
return !field.optional;
|
|
66
71
|
}
|
|
72
|
+
// The nested classes an INBOUND schema's $refs name, as GSF writes them for
|
|
73
|
+
// its validator and its JSON_SCHEMA reply alike
|
|
74
|
+
// (SingleObjectDefinition.toJsonSchema, JsonSchema.kt:474-486 @v8.15.29):
|
|
75
|
+
// each property as DETAILS' are, the required ones listed (an empty list
|
|
76
|
+
// too), and no additionalProperties, so a nested item may carry keys its
|
|
77
|
+
// class doesn't have, which the decoder drops. A reply's $defs are written
|
|
78
|
+
// the other way (dtoTypes.ts jsonDefs).
|
|
79
|
+
function inboundDefs(fields, table, appName) {
|
|
80
|
+
return Object.fromEntries([...nestedClasses(fields).values()].map((nested) => {
|
|
81
|
+
const properties = dtoFields(nested.fields, table);
|
|
82
|
+
return [
|
|
83
|
+
nested.className,
|
|
84
|
+
{
|
|
85
|
+
properties: Object.fromEntries(properties.map((field) => [field.name, eventProperty(field, false, appName)])),
|
|
86
|
+
required: properties.filter(isRequired).map((field) => field.name),
|
|
87
|
+
description: nested.className,
|
|
88
|
+
type: 'object',
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
67
93
|
// An event's INBOUND schema: the message, with DETAILS as the event's class.
|
|
68
94
|
// It is also what an inbound event is validated against
|
|
69
95
|
// (handlers/eventValidation.ts), as on the real server.
|
|
@@ -81,7 +107,7 @@ export function eventInboundSchema(eventName, target, fields, appName) {
|
|
|
81
107
|
additionalProperties: true,
|
|
82
108
|
description: target.className,
|
|
83
109
|
...(target.title ? { title: target.title } : {}),
|
|
84
|
-
$defs:
|
|
110
|
+
$defs: inboundDefs(fields, target.table, appName),
|
|
85
111
|
$schema: GENESIS_META_SCHEMA,
|
|
86
112
|
type: 'object',
|
|
87
113
|
};
|
|
@@ -100,8 +126,11 @@ function typeSchema(field) {
|
|
|
100
126
|
};
|
|
101
127
|
}
|
|
102
128
|
// A row property in a reply schema: nullable as oneOf [null, schema], with
|
|
103
|
-
// an empty description and the Genesis type (BigDecimal included)
|
|
129
|
+
// an empty description and the Genesis type (BigDecimal included); a typed
|
|
130
|
+
// server's list, map or nested class as a DTO's is.
|
|
104
131
|
function rowProperty(field, nullable) {
|
|
132
|
+
if (isNestedType(field.type))
|
|
133
|
+
return nestedProperty({ ...field, nullable });
|
|
105
134
|
return nullable
|
|
106
135
|
? { oneOf: [{ type: 'null' }, typeSchema(field)], description: '', genesisType: field.type }
|
|
107
136
|
: { ...typeSchema(field), description: '', genesisType: field.type };
|
|
@@ -116,25 +145,37 @@ function dataserverSchema(queryName, query, config, store) {
|
|
|
116
145
|
};
|
|
117
146
|
}
|
|
118
147
|
function requestServerSchema(name, requestReply, config, store) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
// A typed server's request and reply classes (not recorded: in the
|
|
149
|
+
// envelope a GPAL request server's schema has), else the request block and
|
|
150
|
+
// the source's fields.
|
|
151
|
+
const typed = requestReply.typed;
|
|
152
|
+
const entityFields = typed ? [] : requestReplySourceSchema(requestReply, config, store).fields;
|
|
153
|
+
const requestFields = typed
|
|
154
|
+
? typedFields(typed.request.fields)
|
|
155
|
+
: requestFieldsOf(requestReply, store).map((fieldName) => entityFields.find((candidate) => candidate.name === fieldName) ??
|
|
156
|
+
{ name: fieldName, type: 'STRING' });
|
|
157
|
+
const requestProperties = Object.fromEntries(requestFields.map((field) => [
|
|
158
|
+
field.name,
|
|
159
|
+
isNestedType(field.type)
|
|
160
|
+
? nestedProperty(field)
|
|
161
|
+
: {
|
|
126
162
|
readOnly: false,
|
|
127
|
-
...(type === 'ENUM' &&
|
|
163
|
+
...(field.type === 'ENUM' && knownValues(field) ? { enum: knownValues(field) } : {}),
|
|
128
164
|
description: '',
|
|
129
|
-
genesisType: type,
|
|
130
|
-
type: jsonTypeOf(type),
|
|
165
|
+
genesisType: field.type,
|
|
166
|
+
type: jsonTypeOf(field.type),
|
|
131
167
|
},
|
|
132
|
-
|
|
133
|
-
}));
|
|
168
|
+
]));
|
|
134
169
|
const request = { properties: requestProperties, additionalProperties: false, type: 'object' };
|
|
135
170
|
// The reply block, else the source's fields then RECORD_ID and TIMESTAMP,
|
|
136
171
|
// as REPLY_FIELD (see requestReplyReplySchema).
|
|
137
|
-
const fields =
|
|
172
|
+
const fields = typed
|
|
173
|
+
? typedFields(typed.reply.fields)
|
|
174
|
+
: requestReplyReplySchema(requestReply, config, store).fields;
|
|
175
|
+
// The nested classes a typed server's reply $refs name.
|
|
176
|
+
const replyDefs = typed
|
|
177
|
+
? jsonDefs(nestedClasses(fields), (nested) => dtoFields(nested.fields))
|
|
178
|
+
: {};
|
|
138
179
|
return {
|
|
139
180
|
INBOUND: {
|
|
140
181
|
properties: {
|
|
@@ -147,7 +188,7 @@ function requestServerSchema(name, requestReply, config, store) {
|
|
|
147
188
|
required: ['MESSAGE_TYPE', 'SOURCE_REF', 'USER_NAME', 'REQUEST'],
|
|
148
189
|
additionalProperties: false,
|
|
149
190
|
description: `GPAL Request definition for ${name}`,
|
|
150
|
-
$defs: {},
|
|
191
|
+
$defs: typed ? inboundDefs(requestFields) : {},
|
|
151
192
|
type: 'object',
|
|
152
193
|
},
|
|
153
194
|
OUTBOUND: {
|
|
@@ -169,9 +210,19 @@ function requestServerSchema(name, requestReply, config, store) {
|
|
|
169
210
|
},
|
|
170
211
|
required: ['MESSAGE_TYPE', 'SOURCE_REF'],
|
|
171
212
|
additionalProperties: false,
|
|
213
|
+
...(Object.keys(replyDefs).length > 0 ? { $defs: replyDefs } : {}),
|
|
172
214
|
},
|
|
173
215
|
};
|
|
174
216
|
}
|
|
217
|
+
// A request server's reply row properties, as its OUTBOUND schema's
|
|
218
|
+
// REPLY.items gives them, or undefined when the config has no such server.
|
|
219
|
+
export function requestServerReplyProperties(name, config, store) {
|
|
220
|
+
const requestReply = config.requestReplies?.[name];
|
|
221
|
+
if (!requestReply)
|
|
222
|
+
return undefined;
|
|
223
|
+
return requestServerSchema(name, requestReply, config, store).OUTBOUND.properties.REPLY.items
|
|
224
|
+
.properties;
|
|
225
|
+
}
|
|
175
226
|
// The FEATURE resolves, in order, as: an entry in config.eventSchemas, a
|
|
176
227
|
// dataserver query, a request server (by resource name, without REQ_), an
|
|
177
228
|
// EVENT_<TABLE>_<VERB> event, and finally a bare table name — the last is
|
package/dist/handlers/meta.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ResolvedField } from '../db/schema.ts';
|
|
|
2
2
|
import type { Store } from '../db/store.ts';
|
|
3
3
|
import type { Connection } from '../protocol/connection.ts';
|
|
4
4
|
import type { GenesisMessage, MockServerConfig, Row } from '../types.ts';
|
|
5
|
-
export declare function eventMetaField(field: ResolvedField, { annotated, appName }: {
|
|
5
|
+
export declare function eventMetaField(field: ResolvedField, { annotated: table, appName }: {
|
|
6
6
|
annotated: boolean;
|
|
7
7
|
appName?: string;
|
|
8
8
|
}): Row;
|
package/dist/handlers/meta.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { eventDefaultOf, eventFields, knownValues, querySchema, requestFieldsOf, requestReplyReplySchema, requestReplySchema, requestReplySourceSchema, resolveEventTarget, } from "../db/schema.js";
|
|
1
|
+
import { dtoFields, eventDefaultOf, eventFields, knownValues, querySchema, requestFieldsOf, requestReplyReplySchema, requestReplySchema, requestReplySourceSchema, resolveEventTarget, typedFields, } from "../db/schema.js";
|
|
2
|
+
import { isNestedType, metaDefinitions, metaType, nestedClasses, nestedClassOf, } from "../protocol/dtoTypes.js";
|
|
2
3
|
import { isLegacyFidelity } from "../protocol/fidelity.js";
|
|
3
4
|
import { enumClassOf, eventMetaTypeOf, jsonTypeOf, jvmClassOf, rangeOf, titleCase, } from "../protocol/fieldTypes.js";
|
|
4
5
|
import { eventReplyMeta } from "../protocol/gsfSchemas.js";
|
|
@@ -29,9 +30,13 @@ function dataserverMeta(name, query, config, store, hidden) {
|
|
|
29
30
|
TYPE: 'DATASERVER',
|
|
30
31
|
NAME: name,
|
|
31
32
|
FIELD: fields.map(fieldMetadata),
|
|
32
|
-
|
|
33
|
-
?
|
|
34
|
-
:
|
|
33
|
+
...(query.legacyEngine
|
|
34
|
+
? {}
|
|
35
|
+
: {
|
|
36
|
+
INDEXES: query.indexes?.length
|
|
37
|
+
? query.indexes.map((index) => ({ NAME: index.name, FIELDS: index.fields.join(' ') }))
|
|
38
|
+
: DEFAULT_INDEXES,
|
|
39
|
+
}),
|
|
35
40
|
};
|
|
36
41
|
}
|
|
37
42
|
// The two request-server shapes of ReqRepMetaData.kt: criteria-only
|
|
@@ -80,9 +85,22 @@ function requestServerMeta(name, requestReply, config, store, hidden) {
|
|
|
80
85
|
// none of them (GENESIS_TYPE null). An ENUM always names its values, its
|
|
81
86
|
// class and a DEFAULT_VALUE (the class's first value when the field has no
|
|
82
87
|
// default); DEFAULT appears only when the field has a default.
|
|
83
|
-
export function eventMetaField(field, { annotated, appName }) {
|
|
88
|
+
export function eventMetaField(field, { annotated: table, appName }) {
|
|
84
89
|
const type = field.type;
|
|
85
|
-
|
|
90
|
+
// A table's DAO, or a DAO the DTO unwraps: its annotations.
|
|
91
|
+
const annotated = table || field.dao === true;
|
|
92
|
+
// A list, set, map, nested class or Any: no default, no annotations.
|
|
93
|
+
if (isNestedType(type)) {
|
|
94
|
+
return {
|
|
95
|
+
NAME: field.name,
|
|
96
|
+
DESCRIPTION: nestedClassOf(field),
|
|
97
|
+
...metaType(field),
|
|
98
|
+
OPTIONAL: field.optional ?? false,
|
|
99
|
+
READ_ONLY: false,
|
|
100
|
+
GENESIS_TYPE: null,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const enumClass = () => field.enumClass ?? enumClassOf(field.table, field.name, appName);
|
|
86
104
|
const values = knownValues(field);
|
|
87
105
|
const fieldDefault = eventDefaultOf(field);
|
|
88
106
|
const meta = { NAME: field.name };
|
|
@@ -120,6 +138,30 @@ export function eventMetaField(field, { annotated, appName }) {
|
|
|
120
138
|
meta.GENESIS_TYPE = annotated ? type : null;
|
|
121
139
|
return meta;
|
|
122
140
|
}
|
|
141
|
+
// A typed request server's META (CustomReqRep's buildMetaData, GSF
|
|
142
|
+
// v8.15.29): the request class's fields in DETAILS.FIELD and the reply
|
|
143
|
+
// class's in DETAILS.REPLY, each described as an event DTO's field is, and
|
|
144
|
+
// the criteria keys ReqRepMeta has had since GSF 8.14 (ReqRepMeta.kt:41-43),
|
|
145
|
+
// sent null.
|
|
146
|
+
function typedRequestServerMeta(name, typed, appName) {
|
|
147
|
+
const describe = ({ className, fields }) => {
|
|
148
|
+
const resolved = typedFields(fields);
|
|
149
|
+
return {
|
|
150
|
+
DESCRIPTION: className,
|
|
151
|
+
FIELD: resolved.map((field) => eventMetaField(field, { annotated: false, appName })),
|
|
152
|
+
DEFINITIONS: metaDefinitions(nestedClasses(resolved), (nested) => dtoFields(nested.fields).map((field) => eventMetaField(field, { annotated: false, appName }))),
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
NAME: name,
|
|
157
|
+
...describe(typed.request),
|
|
158
|
+
REPLY: { NAME: `REP_${name}`, ...describe(typed.reply) },
|
|
159
|
+
CRITERIA_ONLY_REQUEST: false,
|
|
160
|
+
SORTABLE_FIELDS: null,
|
|
161
|
+
CRITERIA_FIELDS: null,
|
|
162
|
+
TYPE: 'REQUEST_SERVER',
|
|
163
|
+
};
|
|
164
|
+
}
|
|
123
165
|
function eventMeta(name, target, fields, appName) {
|
|
124
166
|
const annotated = target.kind === 'table';
|
|
125
167
|
return {
|
|
@@ -127,7 +169,7 @@ function eventMeta(name, target, fields, appName) {
|
|
|
127
169
|
...(target.title ? { TITLE: target.title } : {}),
|
|
128
170
|
DESCRIPTION: target.className,
|
|
129
171
|
FIELD: fields.map((field) => eventMetaField(field, { annotated, appName })),
|
|
130
|
-
DEFINITIONS: {},
|
|
172
|
+
DEFINITIONS: metaDefinitions(nestedClasses(fields), (nested) => dtoFields(nested.fields, target.table).map((field) => eventMetaField(field, { annotated: false, appName }))),
|
|
131
173
|
REPLY: eventReplyMeta(),
|
|
132
174
|
REQUIRES_APPROVAL: false,
|
|
133
175
|
SCHEDULABLE: false,
|
|
@@ -175,9 +217,16 @@ export function handleMetaRequest(message, connection, config, store) {
|
|
|
175
217
|
// Hidden fields disappear from the metadata too — a column the user can't
|
|
176
218
|
// see must not be offered to the grid at all.
|
|
177
219
|
const hidden = hiddenFields((query ?? requestReply).auth, requestingUser(connection));
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
220
|
+
if (query)
|
|
221
|
+
details = dataserverMeta(resourceName, query, config, store, hidden);
|
|
222
|
+
else if (requestReply.typed) {
|
|
223
|
+
const typed = requestReply.typed;
|
|
224
|
+
details = typed.meta
|
|
225
|
+
? structuredClone(typed.meta)
|
|
226
|
+
: typedRequestServerMeta(resourceName, typed, config.appName);
|
|
227
|
+
}
|
|
228
|
+
else
|
|
229
|
+
details = requestServerMeta(resourceName, requestReply, config, store, hidden);
|
|
181
230
|
}
|
|
182
231
|
connection.reply(message, { MESSAGE_TYPE: MESSAGE_TYPE.FEATURE_ACK, DETAILS: details });
|
|
183
232
|
}
|
|
@@ -19,7 +19,7 @@ import { strictCriteriaRefusal } from "../db/criteriaDialect.js";
|
|
|
19
19
|
import { checkGroovySyntax } from "../db/groovySyntax.js";
|
|
20
20
|
import { withoutRecordFields } from "../db/identity.js";
|
|
21
21
|
import { compareValues, parseOrderBy, rowComparator } from "../db/ordering.js";
|
|
22
|
-
import { pkFieldsOf, primaryKeyIndexName, projectRow, requestReplyFieldNames, requestReplySourceSchema, } from "../db/schema.js";
|
|
22
|
+
import { pkFieldsOf, primaryKeyIndexName, projectRow, requestReplyFieldNames, requestReplySourceSchema, typedFields, } from "../db/schema.js";
|
|
23
23
|
import { bigDecimalFields, decimalText, encodeRow } from "../db/values.js";
|
|
24
24
|
import { ErrorCode, NackError, nackPayload } from "../protocol/errors.js";
|
|
25
25
|
import { isLegacyFidelity } from "../protocol/fidelity.js";
|
|
@@ -451,7 +451,7 @@ function plainReply(resourceName, requestReply, message, config, store, user) {
|
|
|
451
451
|
const fieldNames = requestReplyFieldNames(requestReply, config, store);
|
|
452
452
|
// The rows come through the table's (or the view's root table's) primary
|
|
453
453
|
// key, as getBulk reads them (recorded: auth's RIGHT, in CODE order).
|
|
454
|
-
const ordered = [...store.getResourceRows(source.name)].sort(rowComparator(byPrimaryKey(source)));
|
|
454
|
+
const ordered = [...store.getResourceRows(source.name)].sort(requestReply.order ?? rowComparator(byPrimaryKey(source)));
|
|
455
455
|
const candidates = requestReply.filter ? ordered.filter(requestReply.filter) : ordered;
|
|
456
456
|
const reply = requests.flatMap((request) => {
|
|
457
457
|
const matches = requestPredicate(request, source);
|
|
@@ -477,16 +477,43 @@ function plainReply(resourceName, requestReply, message, config, store, user) {
|
|
|
477
477
|
};
|
|
478
478
|
}
|
|
479
479
|
// --- resolvers (custom request servers) -------------------------------------
|
|
480
|
-
function resolverReply(resourceName, requestReply, message, store, user) {
|
|
480
|
+
function resolverReply(resourceName, requestReply, message, config, store, user) {
|
|
481
481
|
// The resolver owns REQUEST interpretation entirely — no generic
|
|
482
482
|
// REQUEST/CRITERIA filtering is applied on top, since a computed reply's
|
|
483
483
|
// rows needn't echo the request's fields at all. Its rows go out exactly as
|
|
484
484
|
// returned.
|
|
485
485
|
const request = (typeof message.REQUEST === 'object' && message.REQUEST) || message.DETAILS?.REQUEST || {};
|
|
486
|
-
const
|
|
486
|
+
const resolved = requestReply.resolver({ request, message, user, store, config });
|
|
487
|
+
const typed = requestReply.typed;
|
|
488
|
+
if (!typed) {
|
|
489
|
+
return {
|
|
490
|
+
MESSAGE_TYPE: `REP_${resourceName}`,
|
|
491
|
+
REPLY: applyResourceAuth(resolved, requestReply.auth, user),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
// A typed server (AbstractCustomReqRep.kt:62-92, CustomReqRep.kt:34-38
|
|
495
|
+
// @v8.15.29): CRITERIA_MATCH compiled against the reply class, a criteria
|
|
496
|
+
// GSF can't compile failing the request (GENERIC_ERROR, with its text); the
|
|
497
|
+
// criteria over each whole row, then the resource's auth, then at most
|
|
498
|
+
// MAX_ROWS of them (Flow.take, which refuses a count below 1), with no
|
|
499
|
+
// paging.
|
|
500
|
+
const details = message.DETAILS ?? {};
|
|
501
|
+
const maxRows = readInteger(details.MAX_ROWS, 'lenient') ?? requestReply.rowLimit ?? DEFAULT_ROW_LIMIT;
|
|
502
|
+
if (maxRows < 1)
|
|
503
|
+
throw new Error(`Requested element count ${maxRows} should be positive`);
|
|
504
|
+
const fields = typedFields(typed.reply.fields);
|
|
505
|
+
const replyClass = {
|
|
506
|
+
name: typed.reply.className,
|
|
507
|
+
fields: new Map(fields.map((field) => [field.name, field])),
|
|
508
|
+
pkFields: [],
|
|
509
|
+
types: new Map(fields.map((field) => [field.name, field.type])),
|
|
510
|
+
};
|
|
511
|
+
const criteria = criteriaFilter(readText(details.CRITERIA_MATCH), replyClass, (error) => new Error(error.message));
|
|
512
|
+
const rows = applyResourceAuth(applyCriteria(resolved, criteria), requestReply.auth, user);
|
|
487
513
|
return {
|
|
514
|
+
REPLY: rows.slice(0, maxRows),
|
|
488
515
|
MESSAGE_TYPE: `REP_${resourceName}`,
|
|
489
|
-
|
|
516
|
+
PARAMETRIC_TYPE: typed.reply.className,
|
|
490
517
|
};
|
|
491
518
|
}
|
|
492
519
|
// A failed request is a MSG_NACK. A NackError keeps its items. Anything else
|
|
@@ -524,14 +551,14 @@ export function handleRequestReply(message, connection, config, store) {
|
|
|
524
551
|
return;
|
|
525
552
|
}
|
|
526
553
|
if (isLegacyFidelity(config)) {
|
|
527
|
-
legacyRequestReply(resourceName, requestReply, message, connection, store);
|
|
554
|
+
legacyRequestReply(resourceName, requestReply, message, connection, config, store);
|
|
528
555
|
return;
|
|
529
556
|
}
|
|
530
557
|
const user = requestingUser(connection);
|
|
531
558
|
let reply;
|
|
532
559
|
try {
|
|
533
560
|
if (requestReply.resolver) {
|
|
534
|
-
reply = resolverReply(resourceName, requestReply, message, store, user);
|
|
561
|
+
reply = resolverReply(resourceName, requestReply, message, config, store, user);
|
|
535
562
|
}
|
|
536
563
|
else if (requestReply.criteriaOnly) {
|
|
537
564
|
reply = criteriaOnlyReply(resourceName, requestReply, message, config, store, user);
|
|
@@ -560,13 +587,13 @@ function matchesLegacyRequestFields(row, request) {
|
|
|
560
587
|
return row[field] === value;
|
|
561
588
|
});
|
|
562
589
|
}
|
|
563
|
-
function legacyRequestReply(resourceName, requestReply, message, connection, store) {
|
|
590
|
+
function legacyRequestReply(resourceName, requestReply, message, connection, config, store) {
|
|
564
591
|
const user = requestingUser(connection);
|
|
565
592
|
const request = (typeof message.REQUEST === 'object' && message.REQUEST) || message.DETAILS?.REQUEST || {};
|
|
566
593
|
try {
|
|
567
594
|
let rows;
|
|
568
595
|
if (requestReply.resolver) {
|
|
569
|
-
rows = requestReply.resolver({ request, message, user, store });
|
|
596
|
+
rows = requestReply.resolver({ request, message, user, store, config });
|
|
570
597
|
}
|
|
571
598
|
else {
|
|
572
599
|
rows = store.getResourceRows(requestReply.source);
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { RECORD_FIELDS, RECORD_ID, TIMESTAMP } from './db/identity.ts';
|
|
|
5
5
|
export { ErrorCode, NackError, statusCodeFor, type ErrorCodeName, type GenesisErrorType, type NackErrorEntry, type NackErrorInput, type NackErrorOptions, } from './protocol/errors.ts';
|
|
6
6
|
export { compileCriteria, type CriteriaOptions, filterByCriteria, type Predicate, } from './db/criteria.ts';
|
|
7
7
|
export { criteriaRefusal } from './db/criteriaRefusal.ts';
|
|
8
|
-
export type { AntiJoinDef, AuditDef, AuthConfig, AuthUser, BroadcastFn, BroadcastTableChangeFn, CookieAuthenticationOptions, CrudEventVerb, EventHandler, EventHandlerCtx, EventHandlerResult, EventSchemaOverride, FidelityMode, FieldDef, FieldMetadata, GeneratedFieldDef, GenesisFieldType, GenesisMessage, HttpRouteDef, IndexDef, JoinDef, JoinFieldLink, JoinLink, JoinType, JoinValueLink, LiveModifyMode, MockServerConfig, OnMessageCtx, OnMessageHook, ProductDetails, QueryDef, RequestingUser, RequestReplyDef, RequestReplyResolverCtx, ResourceAuthDef, ResourceItem, Row, SequenceFormat, SocketLike, SsoIdentityProvider, TableDef, ViewDef, ViewRowSources, } from './types.ts';
|
|
8
|
+
export type { AntiJoinDef, AuditDef, AuthConfig, AuthDirectory, AuthUser, BroadcastFn, BroadcastTableChangeFn, CookieAuthenticationOptions, CrudEventVerb, EventHandler, EventHandlerCtx, EventHandlerResult, EventSchemaOverride, FidelityMode, FieldDef, FieldMetadata, FieldTypeDef, GeneratedFieldDef, GenesisFieldType, GenesisMessage, HttpRouteCtx, HttpRouteDef, IndexDef, JoinDef, JoinFieldLink, JoinLink, JoinType, JoinValueLink, LiveModifyMode, LoginCtx, LoginFailure, MockServerConfig, NestedFieldType, OnMessageCtx, OnMessageHook, ProductDetails, QueryDef, RequestingUser, RequestReplyDef, RequestReplyResolverCtx, ResourceAuthDef, ResourceItem, Row, SequenceFormat, SocketLike, SsoIdentityProvider, TableDef, TypedRequestReply, ViewDef, ViewRowSources, } from './types.ts';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Store } from '../db/store.ts';
|
|
2
|
+
import type { AuthDirectory, EventHandler, EventHandlerCtx, EventSchemaOverride, HttpRouteDef, RequestReplyDef, ViewDef } from '../types.ts';
|
|
3
|
+
export declare const hasRight: (store: Store, user: string, code: string) => boolean;
|
|
4
|
+
type FixedRights = ReadonlyMap<string, readonly string[]>;
|
|
5
|
+
export interface AuthBackingOptions {
|
|
6
|
+
userOf(ctx: EventHandlerCtx): string;
|
|
7
|
+
passwords: Map<string, string>;
|
|
8
|
+
fixedRights?: FixedRights;
|
|
9
|
+
}
|
|
10
|
+
export declare const changePasswordRoute: HttpRouteDef;
|
|
11
|
+
/**
|
|
12
|
+
* auth's events, request servers and views, for the platform preset to merge.
|
|
13
|
+
*/
|
|
14
|
+
export declare function authBacking({ userOf, passwords, fixedRights }: AuthBackingOptions): {
|
|
15
|
+
eventHandlers: {
|
|
16
|
+
[x: string]: EventHandler;
|
|
17
|
+
};
|
|
18
|
+
eventSchemas: Record<string, EventSchemaOverride>;
|
|
19
|
+
requestReplies: Record<string, RequestReplyDef>;
|
|
20
|
+
views: {
|
|
21
|
+
USER_PROFILE_NAMES: ViewDef;
|
|
22
|
+
};
|
|
23
|
+
directory: AuthDirectory;
|
|
24
|
+
};
|
|
25
|
+
export {};
|