@porulle/adapter-pg-search 0.11.0 → 0.13.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,sBAAsB;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,sBAAsB,EAAE,CAAA;KAAE,CAAC,CAAC;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAqND,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa,CAwK9E"}
@@ -70,8 +70,15 @@ function attributeValues(document, name) {
70
70
  }
71
71
  function toDocument(row) {
72
72
  const attributes = parseAttributes(row.attributes);
73
+ const payload = row.payload && typeof row.payload === "object"
74
+ ? row.payload
75
+ : {};
76
+ const organizationId = typeof payload.organizationId === "string"
77
+ ? payload.organizationId
78
+ : undefined;
73
79
  return {
74
80
  id: String(row.id ?? ""),
81
+ ...(organizationId ? { organizationId } : {}),
75
82
  type: String(row.type ?? ""),
76
83
  slug: String(row.slug ?? ""),
77
84
  title: String(row.title ?? ""),
@@ -81,7 +88,7 @@ function toDocument(row) {
81
88
  brands: parseBrands(row.brands),
82
89
  text: String(row.text ?? ""),
83
90
  ...(Object.keys(attributes).length > 0 ? { attributes } : {}),
84
- ...(row.payload && typeof row.payload === "object" ? { payload: row.payload } : {}),
91
+ ...(Object.keys(payload).length > 0 ? { payload } : {}),
85
92
  };
86
93
  }
87
94
  function buildWhere(params, dictionary) {
@@ -95,6 +102,10 @@ function buildWhere(params, dictionary) {
95
102
  values.push(params.filters.type);
96
103
  clauses.push(`type = $${values.length}`);
97
104
  }
105
+ if (params.filters?.organizationId) {
106
+ values.push(params.filters.organizationId);
107
+ clauses.push(`payload ->> 'organizationId' = $${values.length}`);
108
+ }
98
109
  if (params.filters?.status) {
99
110
  values.push(params.filters.status);
100
111
  clauses.push(`status = $${values.length}`);
@@ -209,7 +220,10 @@ export function pgSearchAdapter(options) {
209
220
  document.brands,
210
221
  document.text,
211
222
  JSON.stringify(document.attributes ?? {}),
212
- JSON.stringify(document.payload ?? {}),
223
+ JSON.stringify({
224
+ ...(document.payload ?? {}),
225
+ ...(document.organizationId ? { organizationId: document.organizationId } : {}),
226
+ }),
213
227
  ]);
214
228
  }
215
229
  return Ok(undefined);
@@ -287,6 +301,10 @@ export function pgSearchAdapter(options) {
287
301
  values.push(params.type);
288
302
  conditions.push(`type = $${values.length}`);
289
303
  }
304
+ if (params.organizationId) {
305
+ values.push(params.organizationId);
306
+ conditions.push(`payload ->> 'organizationId' = $${values.length}`);
307
+ }
290
308
  values.push(limit);
291
309
  const rows = await options.query(`SELECT DISTINCT title
292
310
  FROM ${table}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@porulle/adapter-pg-search",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,15 +11,15 @@
11
11
  }
12
12
  },
13
13
  "dependencies": {
14
- "@porulle/core": "0.11.0"
14
+ "@porulle/core": "0.13.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/node": "^24.5.2",
18
18
  "eslint": "^9.39.1",
19
19
  "typescript": "5.9.2",
20
20
  "vitest": "^3.2.4",
21
- "@porulle/eslint-config": "0.1.0",
22
- "@porulle/typescript-config": "0.1.0"
21
+ "@porulle/typescript-config": "0.1.0",
22
+ "@porulle/eslint-config": "0.1.0"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"
package/src/index.ts CHANGED
@@ -94,8 +94,15 @@ function attributeValues(document: SearchDocument, name: string): string[] {
94
94
 
95
95
  function toDocument(row: PgSearchQueryResultRow): SearchDocument {
96
96
  const attributes = parseAttributes(row.attributes);
97
+ const payload = row.payload && typeof row.payload === "object"
98
+ ? row.payload as Record<string, unknown>
99
+ : {};
100
+ const organizationId = typeof payload.organizationId === "string"
101
+ ? payload.organizationId
102
+ : undefined;
97
103
  return {
98
104
  id: String(row.id ?? ""),
105
+ ...(organizationId ? { organizationId } : {}),
99
106
  type: String(row.type ?? ""),
100
107
  slug: String(row.slug ?? ""),
101
108
  title: String(row.title ?? ""),
@@ -105,7 +112,7 @@ function toDocument(row: PgSearchQueryResultRow): SearchDocument {
105
112
  brands: parseBrands(row.brands),
106
113
  text: String(row.text ?? ""),
107
114
  ...(Object.keys(attributes).length > 0 ? { attributes } : {}),
108
- ...(row.payload && typeof row.payload === "object" ? { payload: row.payload as Record<string, unknown> } : {}),
115
+ ...(Object.keys(payload).length > 0 ? { payload } : {}),
109
116
  };
110
117
  }
111
118
 
@@ -126,6 +133,11 @@ function buildWhere(
126
133
  clauses.push(`type = $${values.length}`);
127
134
  }
128
135
 
136
+ if (params.filters?.organizationId) {
137
+ values.push(params.filters.organizationId);
138
+ clauses.push(`payload ->> 'organizationId' = $${values.length}`);
139
+ }
140
+
129
141
  if (params.filters?.status) {
130
142
  values.push(params.filters.status);
131
143
  clauses.push(`status = $${values.length}`);
@@ -256,7 +268,10 @@ export function pgSearchAdapter(options: PgSearchAdapterOptions): SearchAdapter
256
268
  document.brands,
257
269
  document.text,
258
270
  JSON.stringify(document.attributes ?? {}),
259
- JSON.stringify(document.payload ?? {}),
271
+ JSON.stringify({
272
+ ...(document.payload ?? {}),
273
+ ...(document.organizationId ? { organizationId: document.organizationId } : {}),
274
+ }),
260
275
  ],
261
276
  );
262
277
  }
@@ -353,6 +368,11 @@ export function pgSearchAdapter(options: PgSearchAdapterOptions): SearchAdapter
353
368
  conditions.push(`type = $${values.length}`);
354
369
  }
355
370
 
371
+ if (params.organizationId) {
372
+ values.push(params.organizationId);
373
+ conditions.push(`payload ->> 'organizationId' = $${values.length}`);
374
+ }
375
+
356
376
  values.push(limit);
357
377
 
358
378
  const rows = await options.query(
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,sBAAsB;IACrC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,sBAAsB,EAAE,CAAA;KAAE,CAAC,CAAC;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAyMD,wBAAgB,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,aAAa,CAgK9E"}