@pylonsync/sdk 0.3.350 → 0.3.351
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 +4 -1
- package/package.json +1 -1
- package/src/index.ts +4 -1
- package/src/sdk.types.test.ts +69 -0
package/dist/index.d.ts
CHANGED
|
@@ -325,7 +325,10 @@ export declare function entity(name: string, fields: Record<string, FieldBuilder
|
|
|
325
325
|
indexes?: IndexDefinition[];
|
|
326
326
|
relations?: RelationDefinition[];
|
|
327
327
|
search?: SearchConfig;
|
|
328
|
-
|
|
328
|
+
/** `false` to keep out of the replica, or a {@link SyncScope} to bound
|
|
329
|
+
* which rows reach it. Mirrors {@link EntityDefinition.sync} — this is
|
|
330
|
+
* the type callers actually hit, so the two must not drift. */
|
|
331
|
+
sync?: boolean | SyncScope;
|
|
329
332
|
}): EntityDefinition;
|
|
330
333
|
export declare function relation(def: RelationDefinition): RelationDefinition;
|
|
331
334
|
export type AuthMode = "public" | "user";
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -415,7 +415,10 @@ export function entity(
|
|
|
415
415
|
indexes?: IndexDefinition[];
|
|
416
416
|
relations?: RelationDefinition[];
|
|
417
417
|
search?: SearchConfig;
|
|
418
|
-
|
|
418
|
+
/** `false` to keep out of the replica, or a {@link SyncScope} to bound
|
|
419
|
+
* which rows reach it. Mirrors {@link EntityDefinition.sync} — this is
|
|
420
|
+
* the type callers actually hit, so the two must not drift. */
|
|
421
|
+
sync?: boolean | SyncScope;
|
|
419
422
|
},
|
|
420
423
|
): EntityDefinition {
|
|
421
424
|
return {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { buildManifest, entity, field } from "./index";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The shape callers actually hit.
|
|
6
|
+
*
|
|
7
|
+
* `EntityDefinition.sync` and the `entity(name, fields, options)` options
|
|
8
|
+
* parameter declare the same field twice, and they drifted the moment
|
|
9
|
+
* `SyncScope` was added: the interface accepted a scope, the function did not,
|
|
10
|
+
* so `sync: { limit: 2000 }` was a type error in every real app while the
|
|
11
|
+
* feature looked shipped. These assert through `entity()` — the public door —
|
|
12
|
+
* so the two can't diverge again unnoticed.
|
|
13
|
+
*/
|
|
14
|
+
describe("entity() sync option", () => {
|
|
15
|
+
const fields = { orgId: field.string(), views: field.int() };
|
|
16
|
+
|
|
17
|
+
const manifestFor = (e: ReturnType<typeof entity>) =>
|
|
18
|
+
buildManifest({
|
|
19
|
+
name: "t",
|
|
20
|
+
version: "1",
|
|
21
|
+
entities: [e],
|
|
22
|
+
policies: [],
|
|
23
|
+
queries: [],
|
|
24
|
+
actions: [],
|
|
25
|
+
routes: [],
|
|
26
|
+
}) as unknown as {
|
|
27
|
+
entities: Array<{
|
|
28
|
+
name: string;
|
|
29
|
+
sync?: boolean;
|
|
30
|
+
sync_scope?: string;
|
|
31
|
+
sync_limit?: number;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
test("accepts a scope object, not just a boolean", () => {
|
|
36
|
+
const e = entity("Snap", fields, {
|
|
37
|
+
sync: { where: "data.orgId == auth.tenantId", limit: 2000 },
|
|
38
|
+
});
|
|
39
|
+
expect(e.sync).toEqual({
|
|
40
|
+
where: "data.orgId == auth.tenantId",
|
|
41
|
+
limit: 2000,
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("a scope reaches the manifest as flat sibling keys", () => {
|
|
46
|
+
// Flattened so `sync` stays a bool on the wire — an older binary reading a
|
|
47
|
+
// newer manifest replicates everything instead of failing to parse.
|
|
48
|
+
const snap = manifestFor(
|
|
49
|
+
entity("Snap", fields, {
|
|
50
|
+
sync: { where: "data.orgId == auth.tenantId", limit: 2000 },
|
|
51
|
+
}),
|
|
52
|
+
).entities[0];
|
|
53
|
+
expect(snap.sync).toBeUndefined(); // still the default: true
|
|
54
|
+
expect(snap.sync_scope).toBe("data.orgId == auth.tenantId");
|
|
55
|
+
expect(snap.sync_limit).toBe(2000);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("a limit with no predicate emits no scope expression", () => {
|
|
59
|
+
const snap = manifestFor(entity("Snap", fields, { sync: { limit: 500 } }))
|
|
60
|
+
.entities[0];
|
|
61
|
+
expect(snap.sync_scope).toBeUndefined();
|
|
62
|
+
expect(snap.sync_limit).toBe(500);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("sync: false still opts out entirely", () => {
|
|
66
|
+
expect(manifestFor(entity("Snap", fields, { sync: false })).entities[0].sync)
|
|
67
|
+
.toBe(false);
|
|
68
|
+
});
|
|
69
|
+
});
|