@goatlab/typesense 0.0.2 → 0.0.4
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/README.md +405 -0
- package/dist/TypesenseApi.d.ts +114 -70
- package/dist/TypesenseApi.js +101 -55
- package/dist/TypesenseApi.js.map +1 -1
- package/dist/actions/aliases/createOrUpdateAlias.js +7 -2
- package/dist/actions/aliases/createOrUpdateAlias.js.map +1 -1
- package/dist/actions/aliases/deleteAlias.js +3 -1
- package/dist/actions/aliases/deleteAlias.js.map +1 -1
- package/dist/actions/aliases/getAlias.js +3 -1
- package/dist/actions/aliases/getAlias.js.map +1 -1
- package/dist/actions/collections/getOrCreateCollection.js +1 -1
- package/dist/actions/collections/getOrCreateCollection.js.map +1 -1
- package/dist/actions/documents/exportDocuments.js.map +1 -1
- package/dist/actions/documents/insertDocument.d.ts +1 -1
- package/dist/actions/documents/insertDocument.js +1 -2
- package/dist/actions/documents/insertDocument.js.map +1 -1
- package/dist/actions/documents/updateDocument.d.ts +2 -2
- package/dist/actions/documents/updateDocument.js.map +1 -1
- package/dist/actions/documents/upsertDocument.d.ts +1 -1
- package/dist/actions/documents/upsertDocument.js.map +1 -1
- package/dist/actions/presets/deletePreset.js +4 -1
- package/dist/actions/presets/deletePreset.js.map +1 -1
- package/dist/actions/presets/getPreset.js +4 -1
- package/dist/actions/presets/getPreset.js.map +1 -1
- package/dist/actions/presets/listPresets.js +13 -1
- package/dist/actions/presets/listPresets.js.map +1 -1
- package/dist/actions/presets/upsertPreset.js +6 -2
- package/dist/actions/presets/upsertPreset.js.map +1 -1
- package/dist/components/resilience-policy.d.ts +4 -0
- package/dist/components/resilience-policy.js +21 -0
- package/dist/components/resilience-policy.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/tests/type-inference-example.d.ts +1 -0
- package/dist/tests/type-inference-example.js +91 -0
- package/dist/tests/type-inference-example.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/dist/typesense.model.d.ts +1 -0
- package/dist/typesense.model.js.map +1 -1
- package/dist/utils/schema-to-types.d.ts +46 -0
- package/dist/utils/schema-to-types.js +10 -0
- package/dist/utils/schema-to-types.js.map +1 -0
- package/dist/utils/schema-typed-api.d.ts +33 -0
- package/dist/utils/schema-typed-api.js +42 -0
- package/dist/utils/schema-typed-api.js.map +1 -0
- package/dist/utils/tenant.d.ts +9 -0
- package/dist/utils/tenant.js +12 -0
- package/dist/utils/tenant.js.map +1 -1
- package/package.json +9 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TypesenseFilterBuilder = exports.ExportFormatter = exports.CollectionSchemaManager = exports.ResiliencePolicy = exports.TypesenseHttpClient = exports.TypesenseApi = void 0;
|
|
3
|
+
exports.createSchemaTypedApi = exports.defineCollection = exports.TypesenseFilterBuilder = exports.ExportFormatter = exports.CollectionSchemaManager = exports.ResiliencePolicy = exports.TypesenseHttpClient = exports.TypesenseApi = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
// Main exports
|
|
6
6
|
var TypesenseApi_1 = require("./TypesenseApi");
|
|
@@ -20,4 +20,9 @@ var typesense_filter_builder_1 = require("./components/typesense.filter-builder"
|
|
|
20
20
|
Object.defineProperty(exports, "TypesenseFilterBuilder", { enumerable: true, get: function () { return typesense_filter_builder_1.TypesenseFilterBuilder; } });
|
|
21
21
|
// Re-export all action functions
|
|
22
22
|
tslib_1.__exportStar(require("./TypesenseApi"), exports);
|
|
23
|
+
// Schema utilities
|
|
24
|
+
var schema_to_types_1 = require("./utils/schema-to-types");
|
|
25
|
+
Object.defineProperty(exports, "defineCollection", { enumerable: true, get: function () { return schema_to_types_1.defineCollection; } });
|
|
26
|
+
var schema_typed_api_1 = require("./utils/schema-typed-api");
|
|
27
|
+
Object.defineProperty(exports, "createSchemaTypedApi", { enumerable: true, get: function () { return schema_typed_api_1.createSchemaTypedApi; } });
|
|
23
28
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,eAAe;AACf,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,kDAAuB;AACvB,4DAAiC;AAEjC,oBAAoB;AACpB,wDAA8D;AAArD,kHAAA,mBAAmB,OAAA;AAC5B,oEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AACzB,8DAAqE;AAA5D,yHAAA,uBAAuB,OAAA;AAChC,kEAA+D;AAAtD,mHAAA,eAAe,OAAA;AACxB,kFAA8E;AAArE,kIAAA,sBAAsB,OAAA;AAE/B,iCAAiC;AACjC,yDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,eAAe;AACf,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,kDAAuB;AACvB,4DAAiC;AAEjC,oBAAoB;AACpB,wDAA8D;AAArD,kHAAA,mBAAmB,OAAA;AAC5B,oEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AACzB,8DAAqE;AAA5D,yHAAA,uBAAuB,OAAA;AAChC,kEAA+D;AAAtD,mHAAA,eAAe,OAAA;AACxB,kFAA8E;AAArE,kIAAA,sBAAsB,OAAA;AAE/B,iCAAiC;AACjC,yDAA8B;AAI9B,mBAAmB;AACnB,2DAIgC;AAH9B,mHAAA,gBAAgB,OAAA;AAKlB,6DAEiC;AAD/B,wHAAA,oBAAoB,OAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Example demonstrating TypeScript type inference for Typesense
|
|
3
|
+
// npx vitest run ./src/tests/type-inference-example.ts
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
const vitest_1 = require("vitest");
|
|
6
|
+
const index_1 = require("../index");
|
|
7
|
+
(0, vitest_1.describe)('Type Inference Example', () => {
|
|
8
|
+
(0, vitest_1.it)('should demonstrate proper type inference', () => {
|
|
9
|
+
// Define a strongly-typed collection
|
|
10
|
+
const ProductCollection = (0, index_1.defineCollection)({
|
|
11
|
+
name: 'products',
|
|
12
|
+
fields: [
|
|
13
|
+
{ name: 'id', type: 'string' },
|
|
14
|
+
{ name: 'title', type: 'string' },
|
|
15
|
+
{ name: 'description', type: 'string', optional: true },
|
|
16
|
+
{ name: 'price', type: 'float' },
|
|
17
|
+
{ name: 'inStock', type: 'bool' },
|
|
18
|
+
{ name: 'tags', type: 'string[]', optional: true }
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
// These should compile without errors
|
|
22
|
+
const validDoc1 = {
|
|
23
|
+
title: 'Laptop',
|
|
24
|
+
price: 999.99,
|
|
25
|
+
inStock: true
|
|
26
|
+
};
|
|
27
|
+
const validDoc2 = {
|
|
28
|
+
title: 'Gaming Laptop',
|
|
29
|
+
description: 'High-performance laptop',
|
|
30
|
+
price: 1999.99,
|
|
31
|
+
inStock: true,
|
|
32
|
+
tags: ['gaming', 'performance']
|
|
33
|
+
};
|
|
34
|
+
// Create typed API
|
|
35
|
+
const api = (0, index_1.createSchemaTypedApi)(ProductCollection)({
|
|
36
|
+
prefixUrl: 'http://localhost:8108',
|
|
37
|
+
token: 'xyz'
|
|
38
|
+
});
|
|
39
|
+
// Verify API structure
|
|
40
|
+
(0, vitest_1.expect)(api).toBeDefined();
|
|
41
|
+
(0, vitest_1.expect)(api.documents).toBeDefined();
|
|
42
|
+
(0, vitest_1.expect)(typeof api.documents.insert).toBe('function');
|
|
43
|
+
// The following would be compile errors if uncommented:
|
|
44
|
+
// ❌ Missing required field
|
|
45
|
+
// const invalidDoc1: ProductDoc = {
|
|
46
|
+
// price: 99.99,
|
|
47
|
+
// inStock: true
|
|
48
|
+
// }
|
|
49
|
+
// ❌ Wrong type for price
|
|
50
|
+
// const invalidDoc2: ProductDoc = {
|
|
51
|
+
// title: 'Product',
|
|
52
|
+
// price: '99.99', // should be number
|
|
53
|
+
// inStock: true
|
|
54
|
+
// }
|
|
55
|
+
// ❌ Wrong type for optional field
|
|
56
|
+
// const invalidDoc3: ProductDoc = {
|
|
57
|
+
// title: 'Product',
|
|
58
|
+
// price: 99.99,
|
|
59
|
+
// inStock: true,
|
|
60
|
+
// tags: 'single-tag' // should be string[]
|
|
61
|
+
// }
|
|
62
|
+
});
|
|
63
|
+
(0, vitest_1.it)('should handle complex field types', () => {
|
|
64
|
+
const EventCollection = (0, index_1.defineCollection)({
|
|
65
|
+
name: 'events',
|
|
66
|
+
fields: [
|
|
67
|
+
{ name: 'id', type: 'string' },
|
|
68
|
+
{ name: 'name', type: 'string' },
|
|
69
|
+
{ name: 'timestamp', type: 'int64' },
|
|
70
|
+
{ name: 'location', type: 'geopoint' },
|
|
71
|
+
{ name: 'attendees', type: 'int32[]', optional: true },
|
|
72
|
+
{ name: 'metadata', type: 'object', optional: true }
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
const validEvent = {
|
|
76
|
+
name: 'Tech Conference',
|
|
77
|
+
timestamp: Date.now(),
|
|
78
|
+
location: [37.7749, -122.4194]
|
|
79
|
+
};
|
|
80
|
+
const validEventWithOptionals = {
|
|
81
|
+
name: 'Meetup',
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
location: [40.7128, -74.0060],
|
|
84
|
+
attendees: [10, 20, 30],
|
|
85
|
+
metadata: { organizer: 'John', venue: 'Tech Hub' }
|
|
86
|
+
};
|
|
87
|
+
(0, vitest_1.expect)(validEvent).toBeDefined();
|
|
88
|
+
(0, vitest_1.expect)(validEventWithOptionals).toBeDefined();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=type-inference-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-inference-example.js","sourceRoot":"","sources":["../../src/tests/type-inference-example.ts"],"names":[],"mappings":";AAAA,gEAAgE;AAChE,uDAAuD;;AAEvD,mCAA6C;AAC7C,oCAAyF;AAEzF,IAAA,iBAAQ,EAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,IAAA,WAAE,EAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,qCAAqC;QACrC,MAAM,iBAAiB,GAAG,IAAA,wBAAgB,EAAC;YACzC,IAAI,EAAE,UAAU;YAChB,MAAM,EAAE;gBACN,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAiB,EAAE;gBACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAiB,EAAE;gBAC1C,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,QAAiB,EAAE,QAAQ,EAAE,IAAI,EAAE;gBAChE,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAgB,EAAE;gBACzC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAe,EAAE;gBAC1C,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAmB,EAAE,QAAQ,EAAE,IAAI,EAAE;aACnD;SACF,CAAC,CAAA;QAKX,sCAAsC;QACtC,MAAM,SAAS,GAAe;YAC5B,KAAK,EAAE,QAAQ;YACf,KAAK,EAAE,MAAM;YACb,OAAO,EAAE,IAAI;SACd,CAAA;QAED,MAAM,SAAS,GAAe;YAC5B,KAAK,EAAE,eAAe;YACtB,WAAW,EAAE,yBAAyB;YACtC,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,IAAI;YACb,IAAI,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC;SAChC,CAAA;QAED,mBAAmB;QACnB,MAAM,GAAG,GAAG,IAAA,4BAAoB,EAAC,iBAAiB,CAAC,CAAC;YAClD,SAAS,EAAE,uBAAuB;YAClC,KAAK,EAAE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I,CAAC,GAAG,EAAE;YACrB,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,QAAQ,CAAC;SAC/B,CAAA;QAED,MAAM,uBAAuB,GAAa;YACxC,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,QAAQ,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC;YAC7B,SAAS,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;YACvB,QAAQ,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE;SACnD,CAAA;QAED,IAAA,eAAM,EAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAA;QAChC,IAAA,eAAM,EAAC,uBAAuB,CAAC,CAAC,WAAW,EAAE,CAAA;IAC/C,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TypesenseHttpClient } from './components/http-client';
|
|
2
2
|
import type { ResiliencePolicy } from './components/resilience-policy';
|
|
3
3
|
import type { CollectionSchemaManager } from './components/schema-manager';
|
|
4
|
-
export interface TypesenseContext {
|
|
4
|
+
export interface TypesenseContext<TDoc = unknown> {
|
|
5
5
|
httpClient: TypesenseHttpClient;
|
|
6
6
|
resilience: ResiliencePolicy;
|
|
7
7
|
schemaManager: CollectionSchemaManager;
|
|
@@ -11,6 +11,7 @@ export interface TypesenseContext {
|
|
|
11
11
|
autoCreateCollection?: boolean;
|
|
12
12
|
suppressLogs?: boolean;
|
|
13
13
|
fqcn: (baseCollectionName?: string) => string;
|
|
14
|
+
docType?: TDoc;
|
|
14
15
|
}
|
|
15
16
|
export type Rest<Ctx, A> = Omit<A, keyof Ctx>;
|
|
16
17
|
export type Callable<F extends (a: any) => any, Ctx> = Rest<Ctx, Parameters<F>[0]> extends Record<string, never> ? () => ReturnType<F> : (arg: Rest<Ctx, Parameters<F>[0]>) => ReturnType<F>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typesense.model.js","sourceRoot":"","sources":["../src/typesense.model.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"typesense.model.js","sourceRoot":"","sources":["../src/typesense.model.ts"],"names":[],"mappings":";;;AA8UA,8CAEC;AAKD,kDAEC;AAKD,kDAmBC;AA7WD;;GAEG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvB,MAAM,CAAQ;IACd,UAAU,CAAQ;IAClB,QAAQ,CAAM;IACd,kBAAkB,CAAS;IAC3B,cAAc,CAAO;IACrB,UAAU,CAAS;IACnB,cAAc,CAAS;IAEvC,YACE,OAAe,EACf,MAAc,EACd,QAAc,EACd,OAAgC;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAExB,iEAAiE;QACjE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,SAAS,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;YAClD,MAAM,OAAO,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAA,CAAC,8BAA8B;YAC7E,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;YACzC,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAA;YAE1C,IAAI,SAAS;gBAAE,IAAI,CAAC,kBAAkB,GAAG,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;YAChE,IAAI,OAAO;gBAAE,IAAI,CAAC,cAAc,GAAG,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;YAClE,IAAI,UAAU;gBAAE,IAAI,CAAC,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AAK,CAAC,QAAQ,EAAE,CAAC;YAChF,MAAM,CAAC,IAAI,CAAC,qDAAqD,CAAC,CAAA;QACpE,CAAC;IACH,CAAC;IAED,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC1B,MAAM;KACP,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAa,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,oDAAoD,CAAC,CAAA;QAC3D,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AALD,oDAKC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { TypesenseCollection, TypesenseCollectionField } from '../typesense.model';
|
|
2
|
+
/**
|
|
3
|
+
* Helper type to preserve literal types
|
|
4
|
+
*/
|
|
5
|
+
type Literal<T> = T extends string ? T : never;
|
|
6
|
+
/**
|
|
7
|
+
* Maps field type to TypeScript type
|
|
8
|
+
*/
|
|
9
|
+
type FieldTypeToTS<T extends TypesenseCollectionField['type']> = T extends 'string' ? string : T extends 'string[]' ? string[] : T extends 'int32' | 'int64' ? number : T extends 'int32[]' | 'int64[]' ? number[] : T extends 'float' ? number : T extends 'float[]' ? number[] : T extends 'bool' ? boolean : T extends 'bool[]' ? boolean[] : T extends 'geopoint' ? [number, number] : T extends 'geopoint[]' ? [number, number][] : T extends 'auto' ? string | string[] : T extends 'object' ? Record<string, any> : T extends 'object[]' ? Record<string, any>[] : any;
|
|
10
|
+
/**
|
|
11
|
+
* Extract required fields (fields without optional: true)
|
|
12
|
+
*/
|
|
13
|
+
type RequiredFields<C extends TypesenseCollection> = Exclude<C['fields'][number], {
|
|
14
|
+
optional: true;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Extract optional fields
|
|
18
|
+
*/
|
|
19
|
+
type OptionalFields<C extends TypesenseCollection> = Extract<C['fields'][number], {
|
|
20
|
+
optional: true;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* Map required fields to object type
|
|
24
|
+
*/
|
|
25
|
+
type RequiredFieldsType<C extends TypesenseCollection> = {
|
|
26
|
+
[F in RequiredFields<C> as Literal<F['name']> extends 'id' ? never : Literal<F['name']>]: FieldTypeToTS<F['type']>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Map optional fields to object type
|
|
30
|
+
*/
|
|
31
|
+
type OptionalFieldsType<C extends TypesenseCollection> = {
|
|
32
|
+
[F in OptionalFields<C> as Literal<F['name']> extends 'id' ? never : Literal<F['name']>]?: FieldTypeToTS<F['type']>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Infers the document type from a collection (excluding id for TypesenseApi compatibility)
|
|
36
|
+
*/
|
|
37
|
+
export type InferDocumentType<C extends TypesenseCollection> = RequiredFieldsType<C> & OptionalFieldsType<C>;
|
|
38
|
+
/**
|
|
39
|
+
* Infers the TypeScript type from a collection definition
|
|
40
|
+
*/
|
|
41
|
+
export type InferFromCollection<C extends TypesenseCollection> = InferDocumentType<C>;
|
|
42
|
+
/**
|
|
43
|
+
* Helper to create a typed collection definition
|
|
44
|
+
*/
|
|
45
|
+
export declare function defineCollection<const C extends TypesenseCollection>(collection: C): C;
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCollection = defineCollection;
|
|
4
|
+
/**
|
|
5
|
+
* Helper to create a typed collection definition
|
|
6
|
+
*/
|
|
7
|
+
function defineCollection(collection) {
|
|
8
|
+
return collection;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=schema-to-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-to-types.js","sourceRoot":"","sources":["../../src/utils/schema-to-types.ts"],"names":[],"mappings":";;AAqEA,4CAEC;AALD;;GAEG;AACH,SAAgB,gBAAgB,CAAsC,UAAa;IACjF,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TypesenseCollection } from '../typesense.model';
|
|
2
|
+
import { TypesenseApi, type TypesenseApiOptions } from '../TypesenseApi';
|
|
3
|
+
import { type InferFromCollection } from './schema-to-types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a strongly-typed API instance from a collection definition
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const ProductCollection = defineCollection({
|
|
10
|
+
* name: 'products',
|
|
11
|
+
* fields: [
|
|
12
|
+
* { name: 'id', type: 'string' },
|
|
13
|
+
* { name: 'name', type: 'string' },
|
|
14
|
+
* { name: 'price', type: 'float' },
|
|
15
|
+
* { name: 'inStock', type: 'bool' }
|
|
16
|
+
* ]
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* const api = createSchemaTypedApi(ProductCollection)({
|
|
20
|
+
* prefixUrl: 'http://localhost:8108',
|
|
21
|
+
* token: 'xyz'
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* // Fully typed operations
|
|
25
|
+
* await api.documents.insert({
|
|
26
|
+
* id: '1',
|
|
27
|
+
* name: 'Widget',
|
|
28
|
+
* price: 99.99,
|
|
29
|
+
* inStock: true
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createSchemaTypedApi<const C extends TypesenseCollection>(collection: C): (options: Omit<TypesenseApiOptions, "collectionName">) => TypesenseApi<InferFromCollection<C>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchemaTypedApi = createSchemaTypedApi;
|
|
4
|
+
const TypesenseApi_1 = require("../TypesenseApi");
|
|
5
|
+
/**
|
|
6
|
+
* Creates a strongly-typed API instance from a collection definition
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const ProductCollection = defineCollection({
|
|
11
|
+
* name: 'products',
|
|
12
|
+
* fields: [
|
|
13
|
+
* { name: 'id', type: 'string' },
|
|
14
|
+
* { name: 'name', type: 'string' },
|
|
15
|
+
* { name: 'price', type: 'float' },
|
|
16
|
+
* { name: 'inStock', type: 'bool' }
|
|
17
|
+
* ]
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* const api = createSchemaTypedApi(ProductCollection)({
|
|
21
|
+
* prefixUrl: 'http://localhost:8108',
|
|
22
|
+
* token: 'xyz'
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* // Fully typed operations
|
|
26
|
+
* await api.documents.insert({
|
|
27
|
+
* id: '1',
|
|
28
|
+
* name: 'Widget',
|
|
29
|
+
* price: 99.99,
|
|
30
|
+
* inStock: true
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
function createSchemaTypedApi(collection) {
|
|
35
|
+
return (options) => {
|
|
36
|
+
return new TypesenseApi_1.TypesenseApi({
|
|
37
|
+
...options,
|
|
38
|
+
collectionName: collection.name
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=schema-typed-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-typed-api.js","sourceRoot":"","sources":["../../src/utils/schema-typed-api.ts"],"names":[],"mappings":";;AAiCA,oDAWC;AA3CD,kDAAwE;AAGxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,SAAgB,oBAAoB,CAClC,UAAa;IAIb,OAAO,CAAC,OAAoD,EAAyB,EAAE;QACrF,OAAO,IAAI,2BAAY,CAAU;YAC/B,GAAG,OAAO;YACV,cAAc,EAAE,UAAU,CAAC,IAAI;SACT,CAAC,CAAA;IAC3B,CAAC,CAAA;AACH,CAAC"}
|
package/dist/utils/tenant.d.ts
CHANGED
|
@@ -46,3 +46,12 @@ export declare function isTenantCollection(collectionName: string): boolean;
|
|
|
46
46
|
* @returns Collections belonging to the specified tenant
|
|
47
47
|
*/
|
|
48
48
|
export declare function filterCollectionsByTenant(collections: string[], tenantId: string): string[];
|
|
49
|
+
/**
|
|
50
|
+
* Creates a tenant-qualified resource name for aliases, synonyms, presets, etc.
|
|
51
|
+
* This ensures tenant isolation for all Typesense resources, not just collections
|
|
52
|
+
*
|
|
53
|
+
* @param tenantId - Optional tenant ID (if not provided, returns the resource name as-is)
|
|
54
|
+
* @param resourceName - Base resource name
|
|
55
|
+
* @returns Tenant-qualified resource name or original name
|
|
56
|
+
*/
|
|
57
|
+
export declare function createTenantQualifiedName(tenantId: string | undefined, resourceName: string): string;
|
package/dist/utils/tenant.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.createFQCN = createFQCN;
|
|
|
8
8
|
exports.parseFQCN = parseFQCN;
|
|
9
9
|
exports.isTenantCollection = isTenantCollection;
|
|
10
10
|
exports.filterCollectionsByTenant = filterCollectionsByTenant;
|
|
11
|
+
exports.createTenantQualifiedName = createTenantQualifiedName;
|
|
11
12
|
/**
|
|
12
13
|
* Validates and sanitizes a tenant ID for use in collection names
|
|
13
14
|
* - Enforces allowed characters: a-zA-Z0-9_-
|
|
@@ -86,4 +87,15 @@ function filterCollectionsByTenant(collections, tenantId) {
|
|
|
86
87
|
const prefix = `${tenantId}__`;
|
|
87
88
|
return collections.filter(name => name.startsWith(prefix));
|
|
88
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a tenant-qualified resource name for aliases, synonyms, presets, etc.
|
|
92
|
+
* This ensures tenant isolation for all Typesense resources, not just collections
|
|
93
|
+
*
|
|
94
|
+
* @param tenantId - Optional tenant ID (if not provided, returns the resource name as-is)
|
|
95
|
+
* @param resourceName - Base resource name
|
|
96
|
+
* @returns Tenant-qualified resource name or original name
|
|
97
|
+
*/
|
|
98
|
+
function createTenantQualifiedName(tenantId, resourceName) {
|
|
99
|
+
return tenantId ? `${tenantId}__${resourceName}` : resourceName;
|
|
100
|
+
}
|
|
89
101
|
//# sourceMappingURL=tenant.js.map
|
package/dist/utils/tenant.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenant.js","sourceRoot":"","sources":["../../src/utils/tenant.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAYH,4CA2BC;AAUD,gCAEC;AAQD,8BAWC;AAQD,gDAEC;AASD,8DAGC;
|
|
1
|
+
{"version":3,"file":"tenant.js","sourceRoot":"","sources":["../../src/utils/tenant.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAYH,4CA2BC;AAUD,gCAEC;AAQD,8BAWC;AAQD,gDAEC;AASD,8DAGC;AAUD,8DAEC;AAtGD;;;;;;;;;GASG;AACH,SAAgB,gBAAgB,CAAC,QAAgB;IAC/C,IAAI,CAAC,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;IAED,kBAAkB;IAClB,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;IAE/B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IAED,2BAA2B;IAC3B,MAAM,cAAc,GAAG,mBAAmB,CAAA;IAC1C,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAA;IACH,CAAC;IAED,mBAAmB;IACnB,IAAI,OAAO,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAC3D,CAAC;IAED,uBAAuB;IACvB,OAAO,OAAO,CAAC,WAAW,EAAE,CAAA;AAC9B,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,QAAgB,EAAE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
"
|
|
5
|
+
"description": "Modern TypeScript wrapper for Typesense search engine API",
|
|
6
|
+
"author": "ignacio.cabrera@goatlab.io",
|
|
7
|
+
"version": "0.0.4",
|
|
7
8
|
"private": false,
|
|
8
9
|
"publishConfig": {
|
|
9
10
|
"access": "public"
|
|
10
11
|
},
|
|
11
12
|
"types": "./dist/index.d.ts",
|
|
12
13
|
"dependencies": {
|
|
14
|
+
"zod": "^4.0.5",
|
|
13
15
|
"@goatlab/js-utils": "0.8.42",
|
|
14
16
|
"@goatlab/tsconfig": "0.0.15"
|
|
15
17
|
},
|
|
16
|
-
"description": "Metabase API wrapper for TypeScript and Node.js",
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@testcontainers/mysql": "^11.0.3",
|
|
19
20
|
"@types/node": "^18.15.9",
|
|
@@ -38,10 +39,13 @@
|
|
|
38
39
|
],
|
|
39
40
|
"homepage": "https://docs.goatlab.io",
|
|
40
41
|
"keywords": [
|
|
41
|
-
"
|
|
42
|
+
"typesense",
|
|
43
|
+
"search",
|
|
42
44
|
"api",
|
|
43
45
|
"wrapper",
|
|
44
|
-
"typescript"
|
|
46
|
+
"typescript",
|
|
47
|
+
"search-engine",
|
|
48
|
+
"full-text-search"
|
|
45
49
|
],
|
|
46
50
|
"scripts": {
|
|
47
51
|
"build": "tsc",
|