zero-swift 0.5.7 → 0.6.1

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.
Files changed (2) hide show
  1. package/dist/bin.js +29 -3
  2. package/package.json +2 -2
package/dist/bin.js CHANGED
@@ -9,7 +9,7 @@ import { Cli, z } from "incur";
9
9
  // package.json
10
10
  var package_default = {
11
11
  name: "zero-swift",
12
- version: "0.5.7",
12
+ version: "0.6.1",
13
13
  description: "Generates the Swift row types and schema of a Zero app for the Zero Swift client.",
14
14
  license: "Apache-2.0",
15
15
  repository: {
@@ -124,6 +124,8 @@ var rowMembers = [
124
124
  "columns",
125
125
  "relationships",
126
126
  "columnValues",
127
+ // The aggregates a query asked for in `related`.
128
+ "aggregates",
127
129
  "hashValue",
128
130
  "CodingKeys",
129
131
  // The parameter of `init(entry:)`, which assigns the columns.
@@ -486,6 +488,10 @@ function generate(schema, customTypes, config, source) {
486
488
  r.one ? ` @Indirect ${pub}var ${r.property}: ${r.dest}?` : ` ${pub}var ${r.property}: [${r.dest}]?`
487
489
  );
488
490
  }
491
+ lines.push(
492
+ " // The aggregates a query asked for in `related`; nil when it asked for none.",
493
+ ` ${pub}var aggregates: RelationshipAggregates<${row}>?`
494
+ );
489
495
  }
490
496
  const params = [
491
497
  ...columns.map(
@@ -493,7 +499,8 @@ function generate(schema, customTypes, config, source) {
493
499
  ),
494
500
  ...relationships.map(
495
501
  (r) => `${r.property}: ${r.one ? `${r.dest}?` : `[${r.dest}]?`} = nil`
496
- )
502
+ ),
503
+ ...relationships.length ? [`aggregates: RelationshipAggregates<${row}>? = nil`] : []
497
504
  ];
498
505
  lines.push("");
499
506
  lines.push(` ${pub}init(`);
@@ -502,6 +509,9 @@ function generate(schema, customTypes, config, source) {
502
509
  for (const c of [...columns, ...relationships]) {
503
510
  lines.push(` self.${c.property} = ${c.property}`);
504
511
  }
512
+ if (relationships.length) {
513
+ lines.push(" self.aggregates = aggregates");
514
+ }
505
515
  lines.push(" }");
506
516
  lines.push("");
507
517
  lines.push(` ${pub}static let tableName = ${str(t)}`);
@@ -529,6 +539,9 @@ function generate(schema, customTypes, config, source) {
529
539
  for (const r of relationships) {
530
540
  lines.push(` ${r.property} = try entry.relationship(${str(r.name)})`);
531
541
  }
542
+ if (relationships.length) {
543
+ lines.push(" aggregates = RelationshipAggregates(entry: entry)");
544
+ }
532
545
  lines.push(" }");
533
546
  lines.push("");
534
547
  lines.push(` ${pub}var columnValues: Row {`);
@@ -538,7 +551,13 @@ function generate(schema, customTypes, config, source) {
538
551
  }
539
552
  lines.push(" ]");
540
553
  lines.push(" }");
541
- lines.push(...codingKeys([...columns, ...relationships]));
554
+ lines.push(
555
+ ...codingKeys([
556
+ ...columns,
557
+ ...relationships,
558
+ ...relationships.length ? [aggregatesKey(props)] : []
559
+ ])
560
+ );
542
561
  const keyColumns = table.primaryKey.map(
543
562
  (k) => columns.find((c) => c.name === k)
544
563
  );
@@ -650,6 +669,13 @@ function columnsDecl(pub, name, doc, columns) {
650
669
  lines.push(" }");
651
670
  return lines;
652
671
  }
672
+ function aggregatesKey(props) {
673
+ let name = "aggregates";
674
+ while (props.some((p) => p.name === name)) {
675
+ name += "_";
676
+ }
677
+ return { name, id: "aggregates", property: "aggregates" };
678
+ }
653
679
  function codingKeys(props) {
654
680
  if (props.every((p) => p.id === p.name)) {
655
681
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zero-swift",
3
- "version": "0.5.7",
3
+ "version": "0.6.1",
4
4
  "description": "Generates the Swift row types and schema of a Zero app for the Zero Swift client.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -24,9 +24,9 @@
24
24
  "esbuild": "0.28.2",
25
25
  "oxfmt": "^0.74.0",
26
26
  "vitest": "^5.0.5",
27
+ "@rocicorp/zero": "1.12.0",
27
28
  "zero-schema": "0.0.0",
28
29
  "zql": "0.0.0",
29
- "@rocicorp/zero": "1.12.0",
30
30
  "zero-types": "0.0.0"
31
31
  },
32
32
  "peerDependencies": {