@atscript/db-memory 0.1.135 → 0.1.136

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.cjs CHANGED
@@ -348,7 +348,8 @@ function projectRow(row, projection, opts) {
348
348
  * - null and missing form ONE group; a calendar-bucket key is the
349
349
  * `@uniqu/core` kernel label (the SQLite UDF runs the same kernel);
350
350
  * - `sum` / `avg` over no numeric value are `null`; `min` / `max` order with
351
- * the `$sort` comparator; any other `$fn` is `INVALID_QUERY`;
351
+ * the `$sort` comparator; `countDistinct` counts distinct non-null values
352
+ * by group identity (below); any other `$fn` is `INVALID_QUERY`;
352
353
  * - group identity is type-tagged: `1` and `"1"` never share a group (a
353
354
  * number and a bigint of one value do), `Date`s group by instant, JSON
354
355
  * values by a key-order-independent serialization;
@@ -504,6 +505,19 @@ function accumulatorFactory(expr) {
504
505
  };
505
506
  };
506
507
  }
508
+ case "countDistinct": return () => {
509
+ const plain = /* @__PURE__ */ new Set();
510
+ const tokens = /* @__PURE__ */ new Set();
511
+ return {
512
+ add: (row) => {
513
+ const v = read(row);
514
+ if (v == null) return;
515
+ if (typeof v === "string" || typeof v === "boolean") plain.add(v);
516
+ else tokens.add(identityToken(v));
517
+ },
518
+ result: () => plain.size + tokens.size
519
+ };
520
+ };
507
521
  case "min":
508
522
  case "max": {
509
523
  const sign = expr.$fn === "min" ? -1 : 1;
@@ -1093,6 +1107,10 @@ var MemoryAdapter = class extends _atscript_db.BaseDbAdapter {
1093
1107
  calendarBucketUnits() {
1094
1108
  return _atscript_db.ALL_BUCKET_UNITS;
1095
1109
  }
1110
+ /** Every aggregate function, `countDistinct` included. */
1111
+ aggregateFns() {
1112
+ return _atscript_db.ALL_AGGREGATE_FNS;
1113
+ }
1096
1114
  async updateMany(filter, data, ops) {
1097
1115
  this._assertWritable();
1098
1116
  const matched = this._selectForWrite(filter, void 0, true);
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TFieldOps } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TFieldOps } from "@atscript/db";
2
2
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
3
 
4
4
  //#region src/lib/memory-adapter.d.ts
@@ -367,6 +367,8 @@ declare class MemoryAdapter extends BaseDbAdapter {
367
367
  * there is no zone this adapter cannot resolve).
368
368
  */
369
369
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
370
+ /** Every aggregate function, `countDistinct` included. */
371
+ aggregateFns(): ReadonlySet<AggregateFn>;
370
372
  updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
371
373
  replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
372
374
  deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TFieldOps } from "@atscript/db";
1
+ import { AggregateFn, BaseDbAdapter, BucketUnit, DbQuery, DbSpace, FilterExpr, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TFieldOps } from "@atscript/db";
2
2
  import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
3
3
 
4
4
  //#region src/lib/memory-adapter.d.ts
@@ -367,6 +367,8 @@ declare class MemoryAdapter extends BaseDbAdapter {
367
367
  * there is no zone this adapter cannot resolve).
368
368
  */
369
369
  calendarBucketUnits(): ReadonlySet<BucketUnit>;
370
+ /** Every aggregate function, `countDistinct` included. */
371
+ aggregateFns(): ReadonlySet<AggregateFn>;
370
372
  updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
371
373
  replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
372
374
  deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ALL_BUCKET_UNITS, BaseDbAdapter, DbError, DbSpace, walkFilter } from "@atscript/db";
1
+ import { ALL_AGGREGATE_FNS, ALL_BUCKET_UNITS, BaseDbAdapter, DbError, DbSpace, walkFilter } from "@atscript/db";
2
2
  import { assertAggregateFn, resolveAlias } from "@atscript/db/agg";
3
3
  import { bucketer } from "@uniqu/core";
4
4
  //#region src/lib/memory-filter.ts
@@ -347,7 +347,8 @@ function projectRow(row, projection, opts) {
347
347
  * - null and missing form ONE group; a calendar-bucket key is the
348
348
  * `@uniqu/core` kernel label (the SQLite UDF runs the same kernel);
349
349
  * - `sum` / `avg` over no numeric value are `null`; `min` / `max` order with
350
- * the `$sort` comparator; any other `$fn` is `INVALID_QUERY`;
350
+ * the `$sort` comparator; `countDistinct` counts distinct non-null values
351
+ * by group identity (below); any other `$fn` is `INVALID_QUERY`;
351
352
  * - group identity is type-tagged: `1` and `"1"` never share a group (a
352
353
  * number and a bigint of one value do), `Date`s group by instant, JSON
353
354
  * values by a key-order-independent serialization;
@@ -503,6 +504,19 @@ function accumulatorFactory(expr) {
503
504
  };
504
505
  };
505
506
  }
507
+ case "countDistinct": return () => {
508
+ const plain = /* @__PURE__ */ new Set();
509
+ const tokens = /* @__PURE__ */ new Set();
510
+ return {
511
+ add: (row) => {
512
+ const v = read(row);
513
+ if (v == null) return;
514
+ if (typeof v === "string" || typeof v === "boolean") plain.add(v);
515
+ else tokens.add(identityToken(v));
516
+ },
517
+ result: () => plain.size + tokens.size
518
+ };
519
+ };
506
520
  case "min":
507
521
  case "max": {
508
522
  const sign = expr.$fn === "min" ? -1 : 1;
@@ -1092,6 +1106,10 @@ var MemoryAdapter = class extends BaseDbAdapter {
1092
1106
  calendarBucketUnits() {
1093
1107
  return ALL_BUCKET_UNITS;
1094
1108
  }
1109
+ /** Every aggregate function, `countDistinct` included. */
1110
+ aggregateFns() {
1111
+ return ALL_AGGREGATE_FNS;
1112
+ }
1095
1113
  async updateMany(filter, data, ops) {
1096
1114
  this._assertWritable();
1097
1115
  const matched = this._selectForWrite(filter, void 0, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/db-memory",
3
- "version": "0.1.135",
3
+ "version": "0.1.136",
4
4
  "description": "In-memory adapter for atscript-db.",
5
5
  "keywords": [
6
6
  "atscript",
@@ -45,7 +45,7 @@
45
45
  "@atscript/core": "^0.1.92",
46
46
  "@atscript/typescript": "^0.1.92",
47
47
  "@uniqu/core": "^0.1.11",
48
- "@atscript/db": "^0.1.135"
48
+ "@atscript/db": "^0.1.136"
49
49
  },
50
50
  "scripts": {
51
51
  "postinstall": "asc -f dts",