@malloydata/malloy 0.0.60-dev230718174455 → 0.0.60

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/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { Segment, isFilteredAliasedName, flattenQuery, expressionIsCalculation,
3
3
  export { HighlightType, MalloyTranslator, } from './lang';
4
4
  export type { LogMessage, TranslateResponse } from './lang';
5
5
  export { Malloy, Runtime, AtomicFieldType, ConnectionRuntime, SingleConnectionRuntime, EmptyURLReader, InMemoryURLReader, FixedConnectionMap, MalloyError, JoinRelationship, SourceRelationship, DateTimeframe, TimestampTimeframe, Result, QueryMaterializer, CSVWriter, JSONWriter, Parse, DataWriter, Explore, } from './malloy';
6
- export type { Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
6
+ export type { Model, PreparedQuery, PreparedResult, Field, AtomicField, ExploreField, QueryField, SortableField, DataArray, DataRecord, DataColumn, DataArrayOrRecord, ModelMaterializer, DocumentSymbol, DocumentHighlight, ResultJSON, PreparedResultMaterializer, SQLBlockMaterializer, ExploreMaterializer, WriteStream, SerializedExplore, } from './malloy';
7
7
  export type { RunSQLOptions } from './run_sql_options';
8
8
  export type { URLReader, InfoConnection, LookupConnection, Connection, QueryString, ModelString, QueryURL, ModelURL, PooledConnection, TestableConnection, PersistSQLResults, StreamingConnection, } from './runtime_types';
9
9
  export type { Loggable } from './malloy';
package/dist/malloy.d.ts CHANGED
@@ -503,11 +503,16 @@ export declare type SerializedExplore = {
503
503
  sourceExplore?: SerializedExplore;
504
504
  _parentExplore?: SerializedExplore;
505
505
  };
506
+ export declare type SortableField = {
507
+ field: Field;
508
+ dir: 'asc' | 'desc' | undefined;
509
+ };
506
510
  export declare class Explore extends Entity {
507
511
  protected readonly _structDef: StructDef;
508
512
  protected readonly _parentExplore?: Explore;
509
513
  private _fieldMap;
510
514
  private sourceExplore;
515
+ private _allFieldsWithOrder;
511
516
  constructor(structDef: StructDef, parentExplore?: Explore, source?: Explore);
512
517
  get source(): Explore | undefined;
513
518
  isIntrinsic(): boolean;
@@ -520,8 +525,9 @@ export declare class Explore extends Entity {
520
525
  getSingleExploreModel(): Model;
521
526
  private get fieldMap();
522
527
  get allFields(): Field[];
528
+ get allFieldsWithOrder(): SortableField[];
523
529
  get intrinsicFields(): Field[];
524
- get dimensions(): Field[];
530
+ get dimensions(): SortableField[];
525
531
  getFieldByName(fieldName: string): Field;
526
532
  getFieldByNameIfExists(fieldName: string): Field | undefined;
527
533
  get primaryKey(): string | undefined;
@@ -1125,36 +1131,42 @@ declare abstract class ScalarData<T> extends Data<T> {
1125
1131
  get field(): AtomicField;
1126
1132
  abstract get key(): string;
1127
1133
  isScalar(): this is ScalarData<T>;
1134
+ abstract compareTo(other: ScalarData<T>): number;
1128
1135
  }
1129
1136
  declare class DataString extends ScalarData<string> {
1130
1137
  protected _field: StringField;
1131
1138
  constructor(value: string, field: StringField);
1132
1139
  get field(): StringField;
1133
1140
  get key(): string;
1141
+ compareTo(other: ScalarData<string>): number;
1134
1142
  }
1135
1143
  declare class DataUnsupported extends ScalarData<unknown> {
1136
1144
  protected _field: UnsupportedField;
1137
1145
  constructor(value: unknown, field: UnsupportedField);
1138
1146
  get field(): UnsupportedField;
1139
1147
  get key(): string;
1148
+ compareTo(_other: ScalarData<unknown>): number;
1140
1149
  }
1141
1150
  declare class DataBoolean extends ScalarData<boolean> {
1142
1151
  protected _field: BooleanField;
1143
1152
  constructor(value: boolean, field: BooleanField);
1144
1153
  get field(): BooleanField;
1145
1154
  get key(): string;
1155
+ compareTo(other: ScalarData<boolean>): 0 | 1 | -1;
1146
1156
  }
1147
1157
  declare class DataJSON extends ScalarData<string> {
1148
1158
  protected _field: JSONField;
1149
1159
  constructor(value: string, field: JSONField);
1150
1160
  get field(): JSONField;
1151
1161
  get key(): string;
1162
+ compareTo(other: ScalarData<string>): 0 | 1 | -1;
1152
1163
  }
1153
1164
  declare class DataNumber extends ScalarData<number> {
1154
1165
  protected _field: NumberField;
1155
1166
  constructor(value: number, field: NumberField);
1156
1167
  get field(): NumberField;
1157
1168
  get key(): string;
1169
+ compareTo(other: ScalarData<number>): 0 | 1 | -1;
1158
1170
  }
1159
1171
  declare class DataTimestamp extends ScalarData<Date> {
1160
1172
  protected _field: TimestampField;
@@ -1162,6 +1174,7 @@ declare class DataTimestamp extends ScalarData<Date> {
1162
1174
  get value(): Date;
1163
1175
  get field(): TimestampField;
1164
1176
  get key(): string;
1177
+ compareTo(other: ScalarData<Date>): 0 | 1 | -1;
1165
1178
  }
1166
1179
  declare class DataDate extends ScalarData<Date> {
1167
1180
  protected _field: DateField;
@@ -1169,9 +1182,11 @@ declare class DataDate extends ScalarData<Date> {
1169
1182
  get value(): Date;
1170
1183
  get field(): DateField;
1171
1184
  get key(): string;
1185
+ compareTo(other: ScalarData<Date>): 0 | 1 | -1;
1172
1186
  }
1173
1187
  declare class DataBytes extends ScalarData<Buffer> {
1174
1188
  get key(): string;
1189
+ compareTo(other: ScalarData<Buffer>): 0 | 1 | -1;
1175
1190
  }
1176
1191
  declare class DataNull extends Data<null> {
1177
1192
  get value(): null;
package/dist/malloy.js CHANGED
@@ -980,11 +980,41 @@ class Explore extends Entity {
980
980
  get allFields() {
981
981
  return [...this.fieldMap.values()];
982
982
  }
983
+ get allFieldsWithOrder() {
984
+ var _a, _b;
985
+ if (!this._allFieldsWithOrder) {
986
+ const orderByFields = [
987
+ ...(((_b = (_a = this.structDef.resultMetadata) === null || _a === void 0 ? void 0 : _a.orderBy) === null || _b === void 0 ? void 0 : _b.map(f => {
988
+ if (typeof f.field === 'string') {
989
+ const a = {
990
+ field: this.fieldMap.get(f.field),
991
+ dir: f.dir,
992
+ };
993
+ return a;
994
+ }
995
+ throw new Error('Does not support mapping order by from number.');
996
+ })) || []),
997
+ ];
998
+ const orderByFieldSet = new Set(orderByFields.map(f => f.field.name));
999
+ this._allFieldsWithOrder = [
1000
+ ...orderByFields,
1001
+ ...this.allFields
1002
+ .filter(f => !orderByFieldSet.has(f.name))
1003
+ .map(field => {
1004
+ return {
1005
+ field,
1006
+ dir: 'asc',
1007
+ };
1008
+ }),
1009
+ ];
1010
+ }
1011
+ return this._allFieldsWithOrder;
1012
+ }
983
1013
  get intrinsicFields() {
984
1014
  return [...this.fieldMap.values()].filter(f => f.isIntrinsic());
985
1015
  }
986
1016
  get dimensions() {
987
- return [...this.fieldMap.values()].filter(f => f.isAtomicField() && f.sourceWasDimension());
1017
+ return [...this.allFieldsWithOrder].filter(f => f.field.isAtomicField() && f.field.sourceWasDimension());
988
1018
  }
989
1019
  getFieldByName(fieldName) {
990
1020
  const field = this.fieldMap.get(fieldName);
@@ -2248,6 +2278,11 @@ class DataString extends ScalarData {
2248
2278
  get key() {
2249
2279
  return this.value;
2250
2280
  }
2281
+ compareTo(other) {
2282
+ return this.value
2283
+ .toLocaleLowerCase()
2284
+ .localeCompare(other.value.toLocaleLowerCase());
2285
+ }
2251
2286
  }
2252
2287
  class DataUnsupported extends ScalarData {
2253
2288
  constructor(value, field) {
@@ -2260,6 +2295,9 @@ class DataUnsupported extends ScalarData {
2260
2295
  get key() {
2261
2296
  return '<unsupported>';
2262
2297
  }
2298
+ compareTo(_other) {
2299
+ return 0;
2300
+ }
2263
2301
  }
2264
2302
  class DataBoolean extends ScalarData {
2265
2303
  constructor(value, field) {
@@ -2272,6 +2310,15 @@ class DataBoolean extends ScalarData {
2272
2310
  get key() {
2273
2311
  return `${this.value}`;
2274
2312
  }
2313
+ compareTo(other) {
2314
+ if (this.value === other.value) {
2315
+ return 0;
2316
+ }
2317
+ if (this.value) {
2318
+ return 1;
2319
+ }
2320
+ return -1;
2321
+ }
2275
2322
  }
2276
2323
  class DataJSON extends ScalarData {
2277
2324
  constructor(value, field) {
@@ -2284,6 +2331,19 @@ class DataJSON extends ScalarData {
2284
2331
  get key() {
2285
2332
  return this.value;
2286
2333
  }
2334
+ compareTo(other) {
2335
+ const value = this.value.toString();
2336
+ const otherValue = other.toString();
2337
+ if (value === otherValue) {
2338
+ return 0;
2339
+ }
2340
+ else if (value > otherValue) {
2341
+ return 1;
2342
+ }
2343
+ else {
2344
+ return -1;
2345
+ }
2346
+ }
2287
2347
  }
2288
2348
  class DataNumber extends ScalarData {
2289
2349
  constructor(value, field) {
@@ -2296,6 +2356,16 @@ class DataNumber extends ScalarData {
2296
2356
  get key() {
2297
2357
  return `${this.value}`;
2298
2358
  }
2359
+ compareTo(other) {
2360
+ const difference = this.value - other.value;
2361
+ if (difference > 0) {
2362
+ return 1;
2363
+ }
2364
+ else if (difference === 0) {
2365
+ return 0;
2366
+ }
2367
+ return -1;
2368
+ }
2299
2369
  }
2300
2370
  function valueToDate(value) {
2301
2371
  // TODO properly map the data from BQ/Postgres types
@@ -2339,6 +2409,15 @@ class DataTimestamp extends ScalarData {
2339
2409
  get key() {
2340
2410
  return `${this.value.toLocaleString()}`;
2341
2411
  }
2412
+ compareTo(other) {
2413
+ if (this.value > other.value) {
2414
+ return 1;
2415
+ }
2416
+ else if (this.value < other.value) {
2417
+ return -1;
2418
+ }
2419
+ return 0;
2420
+ }
2342
2421
  }
2343
2422
  class DataDate extends ScalarData {
2344
2423
  constructor(value, field) {
@@ -2354,11 +2433,33 @@ class DataDate extends ScalarData {
2354
2433
  get key() {
2355
2434
  return `${this.value.toLocaleString()}`;
2356
2435
  }
2436
+ compareTo(other) {
2437
+ if (this.value > other.value) {
2438
+ return 1;
2439
+ }
2440
+ else if (this.value < other.value) {
2441
+ return -1;
2442
+ }
2443
+ return 0;
2444
+ }
2357
2445
  }
2358
2446
  class DataBytes extends ScalarData {
2359
2447
  get key() {
2360
2448
  return this.value.toString();
2361
2449
  }
2450
+ compareTo(other) {
2451
+ const value = this.value.toString();
2452
+ const otherValue = other.toString();
2453
+ if (value === otherValue) {
2454
+ return 0;
2455
+ }
2456
+ else if (value > otherValue) {
2457
+ return 1;
2458
+ }
2459
+ else {
2460
+ return -1;
2461
+ }
2462
+ }
2362
2463
  }
2363
2464
  class DataNull extends Data {
2364
2465
  get value() {
@@ -1711,7 +1711,12 @@ class QueryQuery extends QueryField {
1711
1711
  const sourceField = fi.turtleDef.name || fi.turtleDef.as;
1712
1712
  const sourceClasses = sourceField ? [sourceField] : [];
1713
1713
  const filterList = fi.firstSegment.filterList;
1714
- const limit = fi.turtleDef.pipeline[fi.turtleDef.pipeline.length - 1].limit;
1714
+ const lastSegment = fi.turtleDef.pipeline[fi.turtleDef.pipeline.length - 1];
1715
+ const limit = lastSegment.limit;
1716
+ let orderBy = undefined;
1717
+ if ((0, malloy_types_1.isQuerySegment)(lastSegment)) {
1718
+ orderBy = lastSegment.orderBy;
1719
+ }
1715
1720
  if (sourceField) {
1716
1721
  return {
1717
1722
  sourceField,
@@ -1719,6 +1724,7 @@ class QueryQuery extends QueryField {
1719
1724
  sourceClasses,
1720
1725
  fieldKind: 'struct',
1721
1726
  limit,
1727
+ orderBy,
1722
1728
  };
1723
1729
  }
1724
1730
  }
@@ -87,6 +87,7 @@ export interface ResultMetadataDef {
87
87
  }
88
88
  export interface ResultStructMetadataDef extends ResultMetadataDef {
89
89
  limit?: number;
90
+ orderBy?: OrderBy[];
90
91
  }
91
92
  export interface ResultMetadata {
92
93
  resultMetadata?: ResultMetadataDef;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/malloy",
3
- "version": "0.0.60-dev230718174455",
3
+ "version": "0.0.60",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",