@lde/search-typesense 0.1.0 → 0.1.1
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/package.json +2 -2
- package/dist/frame.d.ts +0 -28
- package/dist/frame.d.ts.map +0 -1
- package/dist/frame.js +0 -42
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lde/search-typesense",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Generic Typesense engine adapter for RDF-backed search pipelines: collection lifecycle, bulk upsert and blue/green alias swap",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/ldelements/lde.git",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"typesense": "^3.0.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"testcontainers": "^12.0.
|
|
32
|
+
"testcontainers": "^12.0.3"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/dist/frame.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Quad } from '@rdfjs/types';
|
|
2
|
-
/**
|
|
3
|
-
* A flat Typesense document. `id` is required (Typesense uses it as the document
|
|
4
|
-
* key); every other field is engine-typed scalar data or an array thereof.
|
|
5
|
-
*/
|
|
6
|
-
export type TypesenseDocument = {
|
|
7
|
-
id: string;
|
|
8
|
-
} & Record<string, unknown>;
|
|
9
|
-
export type FrameFieldType = 'string' | 'string[]' | 'int' | 'float' | 'bool' | 'unixtime';
|
|
10
|
-
/**
|
|
11
|
-
* Maps one document field to a single RDF predicate on the framed subject.
|
|
12
|
-
* This is the generic, engine-agnostic half of projection — straight
|
|
13
|
-
* predicate-to-field mappings with datatype coercion. Domain-specific
|
|
14
|
-
* derivations (folding, grouping, cross-graph joins) are the consumer’s job.
|
|
15
|
-
*/
|
|
16
|
-
export interface FrameField {
|
|
17
|
-
readonly field: string;
|
|
18
|
-
readonly predicate: string;
|
|
19
|
-
readonly type: FrameFieldType;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Frame the quads describing one subject into a flat document, pulling each
|
|
23
|
-
* configured field’s value(s) from its predicate and coercing to the field’s
|
|
24
|
-
* type. Single-valued fields take the first object; `string[]` collects all.
|
|
25
|
-
* Predicates with no matching quad are omitted (left to Typesense optionality).
|
|
26
|
-
*/
|
|
27
|
-
export declare function frame(quads: Iterable<Quad>, subject: string, fields: readonly FrameField[]): TypesenseDocument;
|
|
28
|
-
//# sourceMappingURL=frame.d.ts.map
|
package/dist/frame.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../src/frame.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzE,MAAM,MAAM,cAAc,GACtB,QAAQ,GACR,UAAU,GACV,KAAK,GACL,OAAO,GACP,MAAM,GACN,UAAU,CAAC;AAEf;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CACnB,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EACrB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,SAAS,UAAU,EAAE,GAC5B,iBAAiB,CAoBnB"}
|
package/dist/frame.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Frame the quads describing one subject into a flat document, pulling each
|
|
3
|
-
* configured field’s value(s) from its predicate and coercing to the field’s
|
|
4
|
-
* type. Single-valued fields take the first object; `string[]` collects all.
|
|
5
|
-
* Predicates with no matching quad are omitted (left to Typesense optionality).
|
|
6
|
-
*/
|
|
7
|
-
export function frame(quads, subject, fields) {
|
|
8
|
-
const objectsByPredicate = new Map();
|
|
9
|
-
for (const quad of quads) {
|
|
10
|
-
if (quad.subject.value !== subject) {
|
|
11
|
-
continue;
|
|
12
|
-
}
|
|
13
|
-
const values = objectsByPredicate.get(quad.predicate.value) ?? [];
|
|
14
|
-
values.push(quad.object.value);
|
|
15
|
-
objectsByPredicate.set(quad.predicate.value, values);
|
|
16
|
-
}
|
|
17
|
-
const document = { id: subject };
|
|
18
|
-
for (const { field, predicate, type } of fields) {
|
|
19
|
-
const values = objectsByPredicate.get(predicate);
|
|
20
|
-
if (values === undefined || values.length === 0) {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
document[field] = coerce(values, type);
|
|
24
|
-
}
|
|
25
|
-
return document;
|
|
26
|
-
}
|
|
27
|
-
function coerce(values, type) {
|
|
28
|
-
switch (type) {
|
|
29
|
-
case 'string':
|
|
30
|
-
return values[0];
|
|
31
|
-
case 'string[]':
|
|
32
|
-
return values;
|
|
33
|
-
case 'int':
|
|
34
|
-
return Math.trunc(Number(values[0]));
|
|
35
|
-
case 'float':
|
|
36
|
-
return Number(values[0]);
|
|
37
|
-
case 'bool':
|
|
38
|
-
return values[0] === 'true' || values[0] === '1';
|
|
39
|
-
case 'unixtime':
|
|
40
|
-
return Math.trunc(new Date(values[0]).getTime() / 1000);
|
|
41
|
-
}
|
|
42
|
-
}
|