@pylonsync/sdk 0.19.1 → 0.21.0

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,18 @@ export interface EntityDefinition {
334
334
  * can read" and "nothing".
335
335
  */
336
336
  sync?: boolean | SyncScope;
337
+ /**
338
+ * Record every insert, update, and delete in the audit log: actor,
339
+ * tenant, row id, and the names of changed fields (not their values).
340
+ * Read it with `ctx.audit.list({ entity })` or `GET /api/admin/audit`.
341
+ */
342
+ audit?: boolean;
343
+ /**
344
+ * Delete rows once they pass a retention period. A system job runs
345
+ * hourly; each deletion goes through the entity pipeline and is recorded
346
+ * in the audit log as `retention.delete`. See {@link RetentionRule}.
347
+ */
348
+ retention?: RetentionRule;
337
349
  /**
338
350
  * Per-row CRDT (Loro) documents. Default `true`: every write merges through
339
351
  * a document, and offline edits from several devices converge. Set `false`
@@ -376,6 +388,24 @@ export interface SyncScope {
376
388
  */
377
389
  limit?: number;
378
390
  }
391
+ /**
392
+ * Retention rule for an entity.
393
+ *
394
+ * - `{ field: "createdAt", after: "365d" }` deletes a row once `createdAt`
395
+ * is older than 365 days. Durations: `s`, `m`, `h`, `d`, `w`, `y`.
396
+ * - `{ field: "deleteAfter" }` (no `after`) deletes a row once
397
+ * `deleteAfter` is in the past. Use it for a retention period per tenant:
398
+ * set `deleteAfter` on each row at insert.
399
+ *
400
+ * `field` is a `datetime` field, or an `int`/`float` field holding unix
401
+ * milliseconds. Rows whose `hold` field (a `bool`) is true are kept, for
402
+ * example under a legal hold.
403
+ */
404
+ export interface RetentionRule {
405
+ field: string;
406
+ after?: string;
407
+ hold?: string;
408
+ }
379
409
  export declare function entity(name: string, fields: Record<string, FieldBuilder>, options?: {
380
410
  indexes?: IndexDefinition[];
381
411
  relations?: RelationDefinition[];
@@ -387,6 +417,12 @@ export declare function entity(name: string, fields: Record<string, FieldBuilder
387
417
  /** `false` for server-written rows that need no CRDT document. Mirrors
388
418
  * {@link EntityDefinition.crdt}. */
389
419
  crdt?: boolean;
420
+ /** Record every write in the audit log. Mirrors
421
+ * {@link EntityDefinition.audit}. */
422
+ audit?: boolean;
423
+ /** Delete rows past a retention period. Mirrors
424
+ * {@link EntityDefinition.retention}. */
425
+ retention?: RetentionRule;
390
426
  }): EntityDefinition;
391
427
  export declare function relation(def: RelationDefinition): RelationDefinition;
392
428
  export { defineRoute } from "./route";
@@ -571,6 +607,10 @@ export interface ManifestEntity {
571
607
  sync_limit?: number;
572
608
  /** CRDT mode; omitted when true (the runtime default). */
573
609
  crdt?: boolean;
610
+ /** Audit every write; omitted when false. */
611
+ audit?: boolean;
612
+ /** Retention rule; omitted when unset. */
613
+ retention?: RetentionRule;
574
614
  }
575
615
  export interface ManifestRoute {
576
616
  path: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.19.1",
6
+ "version": "0.21.0",
7
7
  "type": "module",
8
8
  "main": "./src/index.ts",
9
9
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -431,6 +431,18 @@ export interface EntityDefinition {
431
431
  * can read" and "nothing".
432
432
  */
433
433
  sync?: boolean | SyncScope;
434
+ /**
435
+ * Record every insert, update, and delete in the audit log: actor,
436
+ * tenant, row id, and the names of changed fields (not their values).
437
+ * Read it with `ctx.audit.list({ entity })` or `GET /api/admin/audit`.
438
+ */
439
+ audit?: boolean;
440
+ /**
441
+ * Delete rows once they pass a retention period. A system job runs
442
+ * hourly; each deletion goes through the entity pipeline and is recorded
443
+ * in the audit log as `retention.delete`. See {@link RetentionRule}.
444
+ */
445
+ retention?: RetentionRule;
434
446
  /**
435
447
  * Per-row CRDT (Loro) documents. Default `true`: every write merges through
436
448
  * a document, and offline edits from several devices converge. Set `false`
@@ -475,6 +487,25 @@ export interface SyncScope {
475
487
  limit?: number;
476
488
  }
477
489
 
490
+ /**
491
+ * Retention rule for an entity.
492
+ *
493
+ * - `{ field: "createdAt", after: "365d" }` deletes a row once `createdAt`
494
+ * is older than 365 days. Durations: `s`, `m`, `h`, `d`, `w`, `y`.
495
+ * - `{ field: "deleteAfter" }` (no `after`) deletes a row once
496
+ * `deleteAfter` is in the past. Use it for a retention period per tenant:
497
+ * set `deleteAfter` on each row at insert.
498
+ *
499
+ * `field` is a `datetime` field, or an `int`/`float` field holding unix
500
+ * milliseconds. Rows whose `hold` field (a `bool`) is true are kept, for
501
+ * example under a legal hold.
502
+ */
503
+ export interface RetentionRule {
504
+ field: string;
505
+ after?: string;
506
+ hold?: string;
507
+ }
508
+
478
509
  export function entity(
479
510
  name: string,
480
511
  fields: Record<string, FieldBuilder>,
@@ -489,6 +520,12 @@ export function entity(
489
520
  /** `false` for server-written rows that need no CRDT document. Mirrors
490
521
  * {@link EntityDefinition.crdt}. */
491
522
  crdt?: boolean;
523
+ /** Record every write in the audit log. Mirrors
524
+ * {@link EntityDefinition.audit}. */
525
+ audit?: boolean;
526
+ /** Delete rows past a retention period. Mirrors
527
+ * {@link EntityDefinition.retention}. */
528
+ retention?: RetentionRule;
492
529
  },
493
530
  ): EntityDefinition {
494
531
  return {
@@ -499,6 +536,8 @@ export function entity(
499
536
  search: options?.search,
500
537
  sync: options?.sync,
501
538
  crdt: options?.crdt,
539
+ audit: options?.audit,
540
+ retention: options?.retention,
502
541
  };
503
542
  }
504
543
 
@@ -743,6 +782,10 @@ export interface ManifestEntity {
743
782
  sync_limit?: number;
744
783
  /** CRDT mode; omitted when true (the runtime default). */
745
784
  crdt?: boolean;
785
+ /** Audit every write; omitted when false. */
786
+ audit?: boolean;
787
+ /** Retention rule; omitted when unset. */
788
+ retention?: RetentionRule;
746
789
  }
747
790
 
748
791
  export interface ManifestRoute {
@@ -1274,6 +1317,16 @@ export function entitiesToManifest(
1274
1317
  if (e.crdt === false) {
1275
1318
  result.crdt = false;
1276
1319
  }
1320
+ if (e.audit === true) {
1321
+ result.audit = true;
1322
+ }
1323
+ if (e.retention) {
1324
+ result.retention = {
1325
+ field: e.retention.field,
1326
+ ...(e.retention.after ? { after: e.retention.after } : {}),
1327
+ ...(e.retention.hold ? { hold: e.retention.hold } : {}),
1328
+ };
1329
+ }
1277
1330
  return result;
1278
1331
  });
1279
1332
  }