@weclapp/sdk 2.0.0-dev.58 → 2.0.0-dev.59
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/dist/cli.js +16 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1155,6 +1155,7 @@ const generateArray = (values) => {
|
|
|
1155
1155
|
|
|
1156
1156
|
// Only functions matching this regex are included in the generation.
|
|
1157
1157
|
const FILTER_REGEX = /^(some|count|create|remove|unique|update)$/;
|
|
1158
|
+
const SOME_FILTER_REGEX = /^(some)$/;
|
|
1158
1159
|
/**
|
|
1159
1160
|
* Generates for each function a map with the entity-name as key and service type as value.
|
|
1160
1161
|
* E.g. WServicesWith[Function] where [Function] may be something like "some" or "create".
|
|
@@ -1163,6 +1164,7 @@ const FILTER_REGEX = /^(some|count|create|remove|unique|update)$/;
|
|
|
1163
1164
|
*/
|
|
1164
1165
|
const generateGroupedServices = (services) => {
|
|
1165
1166
|
const entityDescriptors = new Map();
|
|
1167
|
+
const someQueryDescriptors = new Map();
|
|
1166
1168
|
for (const service of services) {
|
|
1167
1169
|
for (const fn of service.functions) {
|
|
1168
1170
|
if (!FILTER_REGEX.test(fn.name)) {
|
|
@@ -1176,17 +1178,28 @@ const generateGroupedServices = (services) => {
|
|
|
1176
1178
|
type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}`
|
|
1177
1179
|
}
|
|
1178
1180
|
]);
|
|
1181
|
+
if (SOME_FILTER_REGEX.test(fn.name)) {
|
|
1182
|
+
someQueryDescriptors.set(fn.name, [
|
|
1183
|
+
...(someQueryDescriptors.get(fn.name) ?? []),
|
|
1184
|
+
{
|
|
1185
|
+
name: service.name,
|
|
1186
|
+
required: true,
|
|
1187
|
+
type: `${pascalCase(service.name)}Service_${pascalCase(fn.name)}_Query`
|
|
1188
|
+
}
|
|
1189
|
+
]);
|
|
1190
|
+
}
|
|
1179
1191
|
}
|
|
1180
1192
|
}
|
|
1181
|
-
const
|
|
1193
|
+
const entityDescriptorEntries = [...entityDescriptors.entries()];
|
|
1194
|
+
const someQueryDescriptorEntries = [...someQueryDescriptors.entries()];
|
|
1182
1195
|
const typeGuards = [];
|
|
1183
|
-
for (const [name] of
|
|
1196
|
+
for (const [name] of entityDescriptorEntries) {
|
|
1184
1197
|
const constant = camelCase(`wServiceWith_${name}_Names`);
|
|
1185
1198
|
const service = pascalCase(`WServiceWith_${name}`);
|
|
1186
1199
|
const guard = `(service: string | undefined): service is ${service} =>\n${indent(`${constant}.includes(service as ${service});`)}`;
|
|
1187
1200
|
typeGuards.push(`export const is${service} = ${guard}`);
|
|
1188
1201
|
}
|
|
1189
|
-
return generateStatements(...
|
|
1202
|
+
return generateStatements(...entityDescriptorEntries.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}`), props)), ...entityDescriptorEntries.map(([name]) => generateType(pascalCase(`WServiceWith_${name}`), `keyof ${pascalCase(`WServicesWith_${name}`)}`)), ...someQueryDescriptorEntries.map(([name, props]) => generateInterface(pascalCase(`WServicesWith_${name}_Query`), props)), ...someQueryDescriptorEntries.map(([name]) => generateType(pascalCase(`WServiceWith_${name}_Query`), `keyof ${pascalCase(`WServicesWith_${name}_Query`)}`)), ...entityDescriptorEntries.map(([name, props]) => {
|
|
1190
1203
|
const constant = camelCase(`wServiceWith_${name}_Names`);
|
|
1191
1204
|
const type = pascalCase(`WServiceWith_${name}`);
|
|
1192
1205
|
const value = generateArray(props.map((v) => v.name));
|