@pylonsync/sdk 0.3.47 → 0.3.48

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/package.json +1 -1
  2. package/src/index.ts +27 -0
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.47",
6
+ "version": "0.3.48",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
package/src/index.ts CHANGED
@@ -114,6 +114,30 @@ export interface IndexDefinition {
114
114
  name: string;
115
115
  fields: string[];
116
116
  unique: boolean;
117
+ /**
118
+ * Optional SQL predicate. When set, the framework emits a *partial*
119
+ * index — `CREATE [UNIQUE] INDEX … WHERE <predicate>` — so the index
120
+ * (and any uniqueness constraint) only applies to rows matching the
121
+ * predicate.
122
+ *
123
+ * Use case: enforce "max 1 hobby-tier org per user" without breaking
124
+ * paid users who legitimately own many orgs:
125
+ *
126
+ * ```ts
127
+ * indexes: [{
128
+ * name: "uniq_hobby_owner",
129
+ * fields: ["createdBy"],
130
+ * unique: true,
131
+ * where: "plan = 'hobby'",
132
+ * }]
133
+ * ```
134
+ *
135
+ * The predicate is passed straight through to the database. Both
136
+ * SQLite and Postgres accept this syntax — write SQL the underlying
137
+ * engine understands. Pylon does NOT validate or escape this string,
138
+ * so DO NOT interpolate user input here.
139
+ */
140
+ where?: string;
117
141
  }
118
142
 
119
143
  export interface RelationDefinition {
@@ -294,6 +318,8 @@ export interface ManifestIndex {
294
318
  name: string;
295
319
  fields: string[];
296
320
  unique: boolean;
321
+ /** Optional partial-index predicate — see `IndexDefinition.where`. */
322
+ where?: string;
297
323
  }
298
324
 
299
325
  export interface ManifestRelation {
@@ -394,6 +420,7 @@ export function entitiesToManifest(
394
420
  name: idx.name,
395
421
  fields: idx.fields,
396
422
  unique: idx.unique,
423
+ ...(idx.where ? { where: idx.where } : {}),
397
424
  })),
398
425
  };
399
426
  if (e.relations && e.relations.length > 0) {