@pylonsync/sdk 0.11.4 → 0.11.5

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
@@ -334,6 +334,15 @@ export interface EntityDefinition {
334
334
  * can read" and "nothing".
335
335
  */
336
336
  sync?: boolean | SyncScope;
337
+ /**
338
+ * Per-row CRDT (Loro) documents. Default `true`: every write merges through
339
+ * a document, and offline edits from several devices converge. Set `false`
340
+ * for rows only the server writes and that nobody edits concurrently:
341
+ * rollups, counters, metering windows, audit logs. Those pay a document read
342
+ * and write on every change for nothing, and a row rewritten every few
343
+ * minutes carries a snapshot that grows with each write.
344
+ */
345
+ crdt?: boolean;
337
346
  }
338
347
  /**
339
348
  * Bounded replication for an entity that should stay live but shouldn't ship
@@ -375,6 +384,9 @@ export declare function entity(name: string, fields: Record<string, FieldBuilder
375
384
  * which rows reach it. Mirrors {@link EntityDefinition.sync} — this is
376
385
  * the type callers actually hit, so the two must not drift. */
377
386
  sync?: boolean | SyncScope;
387
+ /** `false` for server-written rows that need no CRDT document. Mirrors
388
+ * {@link EntityDefinition.crdt}. */
389
+ crdt?: boolean;
378
390
  }): EntityDefinition;
379
391
  export declare function relation(def: RelationDefinition): RelationDefinition;
380
392
  export { defineRoute } from "./route";
@@ -557,6 +569,8 @@ export interface ManifestEntity {
557
569
  */
558
570
  sync_scope?: string;
559
571
  sync_limit?: number;
572
+ /** CRDT mode; omitted when true (the runtime default). */
573
+ crdt?: boolean;
560
574
  }
561
575
  export interface ManifestRoute {
562
576
  path: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.11.4",
6
+ "version": "0.11.5",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./dist/index.d.ts",
@@ -0,0 +1,18 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { entitiesToManifest, entity, field } from "./index";
3
+
4
+ describe("entity crdt option", () => {
5
+ test("crdt: false reaches the manifest", () => {
6
+ const [m] = entitiesToManifest([entity("Rollup", { n: field.int() }, { crdt: false })]);
7
+ expect(m.crdt).toBe(false);
8
+ });
9
+
10
+ test("the default is omitted, so the runtime default (true) applies", () => {
11
+ const [a, b] = entitiesToManifest([
12
+ entity("Note", { title: field.string() }),
13
+ entity("Doc", { title: field.string() }, { crdt: true }),
14
+ ]);
15
+ expect("crdt" in a).toBe(false);
16
+ expect("crdt" in b).toBe(false);
17
+ });
18
+ });
package/src/index.ts CHANGED
@@ -431,6 +431,15 @@ export interface EntityDefinition {
431
431
  * can read" and "nothing".
432
432
  */
433
433
  sync?: boolean | SyncScope;
434
+ /**
435
+ * Per-row CRDT (Loro) documents. Default `true`: every write merges through
436
+ * a document, and offline edits from several devices converge. Set `false`
437
+ * for rows only the server writes and that nobody edits concurrently:
438
+ * rollups, counters, metering windows, audit logs. Those pay a document read
439
+ * and write on every change for nothing, and a row rewritten every few
440
+ * minutes carries a snapshot that grows with each write.
441
+ */
442
+ crdt?: boolean;
434
443
  }
435
444
 
436
445
  /**
@@ -477,6 +486,9 @@ export function entity(
477
486
  * which rows reach it. Mirrors {@link EntityDefinition.sync} — this is
478
487
  * the type callers actually hit, so the two must not drift. */
479
488
  sync?: boolean | SyncScope;
489
+ /** `false` for server-written rows that need no CRDT document. Mirrors
490
+ * {@link EntityDefinition.crdt}. */
491
+ crdt?: boolean;
480
492
  },
481
493
  ): EntityDefinition {
482
494
  return {
@@ -486,6 +498,7 @@ export function entity(
486
498
  relations: options?.relations,
487
499
  search: options?.search,
488
500
  sync: options?.sync,
501
+ crdt: options?.crdt,
489
502
  };
490
503
  }
491
504
 
@@ -728,6 +741,8 @@ export interface ManifestEntity {
728
741
  */
729
742
  sync_scope?: string;
730
743
  sync_limit?: number;
744
+ /** CRDT mode; omitted when true (the runtime default). */
745
+ crdt?: boolean;
731
746
  }
732
747
 
733
748
  export interface ManifestRoute {
@@ -1052,6 +1067,10 @@ export function entitiesToManifest(
1052
1067
  if (scope.where !== undefined) result.sync_scope = scope.where;
1053
1068
  if (scope.limit !== undefined) result.sync_limit = scope.limit;
1054
1069
  }
1070
+ // Emit only when opted OUT — the runtime defaults crdt to true.
1071
+ if (e.crdt === false) {
1072
+ result.crdt = false;
1073
+ }
1055
1074
  return result;
1056
1075
  });
1057
1076
  }