@snowtop/ent 0.1.22 → 0.1.24
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/core/base.d.ts +1 -0
- package/core/query_impl.d.ts +1 -0
- package/core/query_impl.js +3 -2
- package/package.json +1 -1
- package/parse_schema/parse.js +138 -7
- package/schema/struct_field.js +2 -1
package/core/base.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export interface SelectBaseDataOptions extends DataOptions {
|
|
|
70
70
|
fields: string[];
|
|
71
71
|
fieldsAlias?: string;
|
|
72
72
|
disableFieldsAlias?: boolean;
|
|
73
|
+
disableDefaultOrderByAlias?: boolean;
|
|
73
74
|
}
|
|
74
75
|
export interface SelectDataOptions extends SelectBaseDataOptions {
|
|
75
76
|
key: string;
|
package/core/query_impl.d.ts
CHANGED
package/core/query_impl.js
CHANGED
|
@@ -13,7 +13,8 @@ function getOrderByPhrase(orderby, alias) {
|
|
|
13
13
|
nullsPlacement = " NULLS LAST";
|
|
14
14
|
break;
|
|
15
15
|
}
|
|
16
|
-
const
|
|
16
|
+
const orderByAlias = v.alias ?? alias;
|
|
17
|
+
const col = orderByAlias ? `${orderByAlias}.${v.column}` : v.column;
|
|
17
18
|
return `${col} ${v.direction}${nullsPlacement}`;
|
|
18
19
|
})
|
|
19
20
|
.join(", ");
|
|
@@ -71,7 +72,7 @@ function buildQuery(options) {
|
|
|
71
72
|
parts.push(`GROUP BY ${options.groupby}`);
|
|
72
73
|
}
|
|
73
74
|
if (options.orderby) {
|
|
74
|
-
parts.push(`ORDER BY ${getOrderByPhrase(options.orderby, fieldsAlias)}`);
|
|
75
|
+
parts.push(`ORDER BY ${getOrderByPhrase(options.orderby, options.disableDefaultOrderByAlias ? undefined : fieldsAlias)}`);
|
|
75
76
|
}
|
|
76
77
|
if (options.limit) {
|
|
77
78
|
parts.push(`LIMIT ${options.limit}`);
|
package/package.json
CHANGED
package/parse_schema/parse.js
CHANGED
|
@@ -180,22 +180,126 @@ async function processPattern(patterns, pattern, processedSchema) {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
if (patterns
|
|
183
|
+
if (!patterns.hasPattern(name)) {
|
|
184
184
|
// intentionally processing separately and not passing pattern.name
|
|
185
185
|
const edges = processEdges(pattern.edges || []);
|
|
186
|
-
|
|
186
|
+
const processed = {
|
|
187
187
|
name: pattern.name,
|
|
188
188
|
assocEdges: edges,
|
|
189
189
|
fields: fields,
|
|
190
190
|
disableMixin: pattern.disableMixin,
|
|
191
191
|
};
|
|
192
|
+
patterns.addPattern(pattern, processed);
|
|
192
193
|
}
|
|
193
194
|
else {
|
|
194
|
-
// TODO ideally we want to make sure that different patterns don't have the same name
|
|
195
195
|
// can't do a deepEqual check because function calls and therefore different instances in fields
|
|
196
|
+
// so compare as best we can
|
|
197
|
+
const cmp = comparePatterns(pattern, patterns);
|
|
198
|
+
if (typeof cmp !== "boolean") {
|
|
199
|
+
if (cmp.field) {
|
|
200
|
+
throw new Error(`pattern '${pattern.name}' in schema ${processedSchema.schemaPath} has different field ${cmp.field.name} from another pattern with the same name`);
|
|
201
|
+
}
|
|
202
|
+
else if (cmp.edge) {
|
|
203
|
+
throw new Error(`pattern '${pattern.name}' in schema ${processedSchema.schemaPath} has different field ${cmp.edge.name} from another pattern with the same name`);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
throw new Error(`pattern '${pattern.name}' in schema ${processedSchema.schemaPath} has different ${cmp.difference} from another pattern with the same name`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
196
209
|
}
|
|
197
210
|
return ret;
|
|
198
211
|
}
|
|
212
|
+
function comparePatterns(pattern, patterns) {
|
|
213
|
+
const processedPattern = patterns.getProcessedPattern(pattern.name);
|
|
214
|
+
if (pattern.name !== processedPattern.name) {
|
|
215
|
+
return {
|
|
216
|
+
difference: "name",
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
if (pattern.disableMixin !== processedPattern.disableMixin) {
|
|
220
|
+
return {
|
|
221
|
+
difference: "disableMixin",
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
const processedFields = patterns.getPatternFields(pattern.name);
|
|
225
|
+
for (const k in pattern.fields) {
|
|
226
|
+
if (!processedFields[k]) {
|
|
227
|
+
return {
|
|
228
|
+
difference: "field",
|
|
229
|
+
field: {
|
|
230
|
+
name: k,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (!compareField(pattern.fields[k], processedFields[k])) {
|
|
235
|
+
return {
|
|
236
|
+
difference: "field",
|
|
237
|
+
field: {
|
|
238
|
+
name: k,
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
for (const k in processedFields) {
|
|
244
|
+
if (!pattern.fields[k]) {
|
|
245
|
+
return {
|
|
246
|
+
difference: "field",
|
|
247
|
+
field: {
|
|
248
|
+
name: k,
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if ((pattern.edges?.length ?? 0) !== (processedPattern.assocEdges.length ?? 0)) {
|
|
254
|
+
return {
|
|
255
|
+
difference: "edges",
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (!pattern.edges?.length) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
for (let i = 0; i < pattern.edges?.length; i++) {
|
|
262
|
+
if (!compareEdge(pattern.edges[i], processedPattern.assocEdges[i])) {
|
|
263
|
+
return {
|
|
264
|
+
difference: "edge",
|
|
265
|
+
edge: {
|
|
266
|
+
name: pattern.edges[i].name,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
function compareObject(o1, o2) {
|
|
274
|
+
for (const k in o1) {
|
|
275
|
+
const v = o1[k];
|
|
276
|
+
if (typeof v === "function" ||
|
|
277
|
+
typeof v === "symbol" ||
|
|
278
|
+
(typeof v === "object" && v !== null)) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
if (v !== o2[k]) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
function compareField(field, procesedField) {
|
|
288
|
+
for (const k in field) {
|
|
289
|
+
if (!compareObject(field[k], procesedField[k])) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
function compareEdge(edge, processedEdge) {
|
|
296
|
+
for (const k in edge) {
|
|
297
|
+
if (!compareObject(edge[k], processedEdge[k])) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
199
303
|
var NullableResult;
|
|
200
304
|
(function (NullableResult) {
|
|
201
305
|
NullableResult["CONTENTS"] = "contents";
|
|
@@ -238,9 +342,36 @@ function processAction(action) {
|
|
|
238
342
|
}
|
|
239
343
|
return ret;
|
|
240
344
|
}
|
|
345
|
+
class ProcessPatterns {
|
|
346
|
+
constructor() {
|
|
347
|
+
this.patternsDict = {};
|
|
348
|
+
this.originalPatterns = {};
|
|
349
|
+
}
|
|
350
|
+
addPattern(pattern, processed) {
|
|
351
|
+
this.originalPatterns[pattern.name] = pattern;
|
|
352
|
+
this.patternsDict[pattern.name] = processed;
|
|
353
|
+
}
|
|
354
|
+
getProcessedPattern(name) {
|
|
355
|
+
const pattern = this.patternsDict[name];
|
|
356
|
+
if (!pattern) {
|
|
357
|
+
throw new Error(`no pattern ${name}`);
|
|
358
|
+
}
|
|
359
|
+
return pattern;
|
|
360
|
+
}
|
|
361
|
+
getPatternFields(name) {
|
|
362
|
+
const pattern = this.originalPatterns[name];
|
|
363
|
+
if (!pattern) {
|
|
364
|
+
throw new Error(`no pattern ${name}`);
|
|
365
|
+
}
|
|
366
|
+
return pattern.fields;
|
|
367
|
+
}
|
|
368
|
+
hasPattern(name) {
|
|
369
|
+
return !!this.patternsDict[name];
|
|
370
|
+
}
|
|
371
|
+
}
|
|
241
372
|
async function parseSchema(potentialSchemas, globalSchema) {
|
|
242
|
-
|
|
243
|
-
|
|
373
|
+
const schemas = {};
|
|
374
|
+
const processPatterns = new ProcessPatterns();
|
|
244
375
|
let parsedGlobalSchema;
|
|
245
376
|
if (globalSchema) {
|
|
246
377
|
parsedGlobalSchema = await parseGlobalSchema(globalSchema);
|
|
@@ -285,7 +416,7 @@ async function parseSchema(potentialSchemas, globalSchema) {
|
|
|
285
416
|
let patternNames = [];
|
|
286
417
|
if (schema.patterns) {
|
|
287
418
|
for (const pattern of schema.patterns) {
|
|
288
|
-
const ret = await processPattern(
|
|
419
|
+
const ret = await processPattern(processPatterns, pattern, processedSchema);
|
|
289
420
|
patternNames.push(pattern.name);
|
|
290
421
|
if (ret.transformsSelect) {
|
|
291
422
|
if (processedSchema.transformsSelect) {
|
|
@@ -320,7 +451,7 @@ async function parseSchema(potentialSchemas, globalSchema) {
|
|
|
320
451
|
const biome = translatePrettier();
|
|
321
452
|
return {
|
|
322
453
|
schemas,
|
|
323
|
-
patterns,
|
|
454
|
+
patterns: processPatterns.patternsDict,
|
|
324
455
|
globalSchema: parsedGlobalSchema,
|
|
325
456
|
config: {
|
|
326
457
|
rome: biome,
|
package/schema/struct_field.js
CHANGED