@proseql/core 0.1.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.
- package/LICENSE +21 -0
- package/dist/errors/crud-errors.d.ts +98 -0
- package/dist/errors/crud-errors.d.ts.map +1 -0
- package/dist/errors/crud-errors.js +23 -0
- package/dist/errors/crud-errors.js.map +1 -0
- package/dist/errors/index.d.ts +16 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +12 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/migration-errors.d.ts +22 -0
- package/dist/errors/migration-errors.d.ts.map +1 -0
- package/dist/errors/migration-errors.js +14 -0
- package/dist/errors/migration-errors.js.map +1 -0
- package/dist/errors/plugin-errors.d.ts +15 -0
- package/dist/errors/plugin-errors.d.ts.map +1 -0
- package/dist/errors/plugin-errors.js +11 -0
- package/dist/errors/plugin-errors.js.map +1 -0
- package/dist/errors/query-errors.d.ts +31 -0
- package/dist/errors/query-errors.d.ts.map +1 -0
- package/dist/errors/query-errors.js +11 -0
- package/dist/errors/query-errors.js.map +1 -0
- package/dist/errors/storage-errors.d.ts +30 -0
- package/dist/errors/storage-errors.d.ts.map +1 -0
- package/dist/errors/storage-errors.js +11 -0
- package/dist/errors/storage-errors.js.map +1 -0
- package/dist/factories/crud-factory-with-relationships.d.ts +28 -0
- package/dist/factories/crud-factory-with-relationships.d.ts.map +1 -0
- package/dist/factories/crud-factory-with-relationships.js +8 -0
- package/dist/factories/crud-factory-with-relationships.js.map +1 -0
- package/dist/factories/crud-factory.d.ts +25 -0
- package/dist/factories/crud-factory.d.ts.map +1 -0
- package/dist/factories/crud-factory.js +8 -0
- package/dist/factories/crud-factory.js.map +1 -0
- package/dist/factories/database-effect.d.ts +241 -0
- package/dist/factories/database-effect.d.ts.map +1 -0
- package/dist/factories/database-effect.js +859 -0
- package/dist/factories/database-effect.js.map +1 -0
- package/dist/hooks/hook-runner.d.ts +60 -0
- package/dist/hooks/hook-runner.d.ts.map +1 -0
- package/dist/hooks/hook-runner.js +107 -0
- package/dist/hooks/hook-runner.js.map +1 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/indexes/index-lookup.d.ts +33 -0
- package/dist/indexes/index-lookup.d.ts.map +1 -0
- package/dist/indexes/index-lookup.js +180 -0
- package/dist/indexes/index-lookup.js.map +1 -0
- package/dist/indexes/index-manager.d.ts +118 -0
- package/dist/indexes/index-manager.d.ts.map +1 -0
- package/dist/indexes/index-manager.js +345 -0
- package/dist/indexes/index-manager.js.map +1 -0
- package/dist/indexes/search-index.d.ts +179 -0
- package/dist/indexes/search-index.d.ts.map +1 -0
- package/dist/indexes/search-index.js +405 -0
- package/dist/indexes/search-index.js.map +1 -0
- package/dist/migrations/migration-runner.d.ts +70 -0
- package/dist/migrations/migration-runner.d.ts.map +1 -0
- package/dist/migrations/migration-runner.js +271 -0
- package/dist/migrations/migration-runner.js.map +1 -0
- package/dist/migrations/migration-types.d.ts +63 -0
- package/dist/migrations/migration-types.d.ts.map +1 -0
- package/dist/migrations/migration-types.js +5 -0
- package/dist/migrations/migration-types.js.map +1 -0
- package/dist/operations/crud/create-with-relationships.d.ts +44 -0
- package/dist/operations/crud/create-with-relationships.d.ts.map +1 -0
- package/dist/operations/crud/create-with-relationships.js +483 -0
- package/dist/operations/crud/create-with-relationships.js.map +1 -0
- package/dist/operations/crud/create.d.ts +48 -0
- package/dist/operations/crud/create.d.ts.map +1 -0
- package/dist/operations/crud/create.js +333 -0
- package/dist/operations/crud/create.js.map +1 -0
- package/dist/operations/crud/delete-with-relationships.d.ts +63 -0
- package/dist/operations/crud/delete-with-relationships.d.ts.map +1 -0
- package/dist/operations/crud/delete-with-relationships.js +395 -0
- package/dist/operations/crud/delete-with-relationships.js.map +1 -0
- package/dist/operations/crud/delete.d.ts +58 -0
- package/dist/operations/crud/delete.d.ts.map +1 -0
- package/dist/operations/crud/delete.js +267 -0
- package/dist/operations/crud/delete.js.map +1 -0
- package/dist/operations/crud/unique-check.d.ts +114 -0
- package/dist/operations/crud/unique-check.d.ts.map +1 -0
- package/dist/operations/crud/unique-check.js +383 -0
- package/dist/operations/crud/unique-check.js.map +1 -0
- package/dist/operations/crud/update-with-relationships.d.ts +45 -0
- package/dist/operations/crud/update-with-relationships.d.ts.map +1 -0
- package/dist/operations/crud/update-with-relationships.js +516 -0
- package/dist/operations/crud/update-with-relationships.js.map +1 -0
- package/dist/operations/crud/update.d.ts +91 -0
- package/dist/operations/crud/update.d.ts.map +1 -0
- package/dist/operations/crud/update.js +505 -0
- package/dist/operations/crud/update.js.map +1 -0
- package/dist/operations/crud/upsert.d.ts +52 -0
- package/dist/operations/crud/upsert.d.ts.map +1 -0
- package/dist/operations/crud/upsert.js +386 -0
- package/dist/operations/crud/upsert.js.map +1 -0
- package/dist/operations/query/aggregate.d.ts +30 -0
- package/dist/operations/query/aggregate.d.ts.map +1 -0
- package/dist/operations/query/aggregate.js +227 -0
- package/dist/operations/query/aggregate.js.map +1 -0
- package/dist/operations/query/cursor-stream.d.ts +18 -0
- package/dist/operations/query/cursor-stream.d.ts.map +1 -0
- package/dist/operations/query/cursor-stream.js +199 -0
- package/dist/operations/query/cursor-stream.js.map +1 -0
- package/dist/operations/query/filter-stream.d.ts +12 -0
- package/dist/operations/query/filter-stream.d.ts.map +1 -0
- package/dist/operations/query/filter-stream.js +167 -0
- package/dist/operations/query/filter-stream.js.map +1 -0
- package/dist/operations/query/filter.d.ts +13 -0
- package/dist/operations/query/filter.d.ts.map +1 -0
- package/dist/operations/query/filter.js +267 -0
- package/dist/operations/query/filter.js.map +1 -0
- package/dist/operations/query/paginate-stream.d.ts +11 -0
- package/dist/operations/query/paginate-stream.d.ts.map +1 -0
- package/dist/operations/query/paginate-stream.js +22 -0
- package/dist/operations/query/paginate-stream.js.map +1 -0
- package/dist/operations/query/query-helpers.d.ts +14 -0
- package/dist/operations/query/query-helpers.d.ts.map +1 -0
- package/dist/operations/query/query-helpers.js +22 -0
- package/dist/operations/query/query-helpers.js.map +1 -0
- package/dist/operations/query/resolve-computed.d.ts +142 -0
- package/dist/operations/query/resolve-computed.d.ts.map +1 -0
- package/dist/operations/query/resolve-computed.js +197 -0
- package/dist/operations/query/resolve-computed.js.map +1 -0
- package/dist/operations/query/search.d.ts +110 -0
- package/dist/operations/query/search.d.ts.map +1 -0
- package/dist/operations/query/search.js +188 -0
- package/dist/operations/query/search.js.map +1 -0
- package/dist/operations/query/select-stream.d.ts +27 -0
- package/dist/operations/query/select-stream.d.ts.map +1 -0
- package/dist/operations/query/select-stream.js +88 -0
- package/dist/operations/query/select-stream.js.map +1 -0
- package/dist/operations/query/select.d.ts +54 -0
- package/dist/operations/query/select.d.ts.map +1 -0
- package/dist/operations/query/select.js +159 -0
- package/dist/operations/query/select.js.map +1 -0
- package/dist/operations/query/sort-stream.d.ts +46 -0
- package/dist/operations/query/sort-stream.d.ts.map +1 -0
- package/dist/operations/query/sort-stream.js +158 -0
- package/dist/operations/query/sort-stream.js.map +1 -0
- package/dist/operations/query/sort.d.ts +9 -0
- package/dist/operations/query/sort.d.ts.map +1 -0
- package/dist/operations/query/sort.js +58 -0
- package/dist/operations/query/sort.js.map +1 -0
- package/dist/operations/relationships/populate-stream.d.ts +29 -0
- package/dist/operations/relationships/populate-stream.d.ts.map +1 -0
- package/dist/operations/relationships/populate-stream.js +159 -0
- package/dist/operations/relationships/populate-stream.js.map +1 -0
- package/dist/operations/relationships/populate.d.ts +15 -0
- package/dist/operations/relationships/populate.d.ts.map +1 -0
- package/dist/operations/relationships/populate.js +228 -0
- package/dist/operations/relationships/populate.js.map +1 -0
- package/dist/plugins/plugin-hooks.d.ts +25 -0
- package/dist/plugins/plugin-hooks.d.ts.map +1 -0
- package/dist/plugins/plugin-hooks.js +64 -0
- package/dist/plugins/plugin-hooks.js.map +1 -0
- package/dist/plugins/plugin-registry.d.ts +26 -0
- package/dist/plugins/plugin-registry.d.ts.map +1 -0
- package/dist/plugins/plugin-registry.js +150 -0
- package/dist/plugins/plugin-registry.js.map +1 -0
- package/dist/plugins/plugin-types.d.ts +95 -0
- package/dist/plugins/plugin-types.d.ts.map +1 -0
- package/dist/plugins/plugin-types.js +6 -0
- package/dist/plugins/plugin-types.js.map +1 -0
- package/dist/plugins/plugin-validation.d.ts +49 -0
- package/dist/plugins/plugin-validation.d.ts.map +1 -0
- package/dist/plugins/plugin-validation.js +295 -0
- package/dist/plugins/plugin-validation.js.map +1 -0
- package/dist/reactive/change-event.d.ts +44 -0
- package/dist/reactive/change-event.d.ts.map +1 -0
- package/dist/reactive/change-event.js +49 -0
- package/dist/reactive/change-event.js.map +1 -0
- package/dist/reactive/change-pubsub.d.ts +32 -0
- package/dist/reactive/change-pubsub.d.ts.map +1 -0
- package/dist/reactive/change-pubsub.js +31 -0
- package/dist/reactive/change-pubsub.js.map +1 -0
- package/dist/reactive/evaluate-query.d.ts +62 -0
- package/dist/reactive/evaluate-query.d.ts.map +1 -0
- package/dist/reactive/evaluate-query.js +57 -0
- package/dist/reactive/evaluate-query.js.map +1 -0
- package/dist/reactive/watch-by-id.d.ts +53 -0
- package/dist/reactive/watch-by-id.d.ts.map +1 -0
- package/dist/reactive/watch-by-id.js +55 -0
- package/dist/reactive/watch-by-id.js.map +1 -0
- package/dist/reactive/watch.d.ts +78 -0
- package/dist/reactive/watch.d.ts.map +1 -0
- package/dist/reactive/watch.js +133 -0
- package/dist/reactive/watch.js.map +1 -0
- package/dist/serializers/codecs/hjson.d.ts +33 -0
- package/dist/serializers/codecs/hjson.d.ts.map +1 -0
- package/dist/serializers/codecs/hjson.js +40 -0
- package/dist/serializers/codecs/hjson.js.map +1 -0
- package/dist/serializers/codecs/json.d.ts +22 -0
- package/dist/serializers/codecs/json.d.ts.map +1 -0
- package/dist/serializers/codecs/json.js +28 -0
- package/dist/serializers/codecs/json.js.map +1 -0
- package/dist/serializers/codecs/json5.d.ts +26 -0
- package/dist/serializers/codecs/json5.d.ts.map +1 -0
- package/dist/serializers/codecs/json5.js +33 -0
- package/dist/serializers/codecs/json5.js.map +1 -0
- package/dist/serializers/codecs/jsonc.d.ts +29 -0
- package/dist/serializers/codecs/jsonc.d.ts.map +1 -0
- package/dist/serializers/codecs/jsonc.js +38 -0
- package/dist/serializers/codecs/jsonc.js.map +1 -0
- package/dist/serializers/codecs/jsonl.d.ts +17 -0
- package/dist/serializers/codecs/jsonl.d.ts.map +1 -0
- package/dist/serializers/codecs/jsonl.js +31 -0
- package/dist/serializers/codecs/jsonl.js.map +1 -0
- package/dist/serializers/codecs/prose.d.ts +419 -0
- package/dist/serializers/codecs/prose.d.ts.map +1 -0
- package/dist/serializers/codecs/prose.js +1060 -0
- package/dist/serializers/codecs/prose.js.map +1 -0
- package/dist/serializers/codecs/toml.d.ts +23 -0
- package/dist/serializers/codecs/toml.d.ts.map +1 -0
- package/dist/serializers/codecs/toml.js +66 -0
- package/dist/serializers/codecs/toml.js.map +1 -0
- package/dist/serializers/codecs/toon.d.ts +20 -0
- package/dist/serializers/codecs/toon.d.ts.map +1 -0
- package/dist/serializers/codecs/toon.js +33 -0
- package/dist/serializers/codecs/toon.js.map +1 -0
- package/dist/serializers/codecs/yaml.d.ts +24 -0
- package/dist/serializers/codecs/yaml.d.ts.map +1 -0
- package/dist/serializers/codecs/yaml.js +31 -0
- package/dist/serializers/codecs/yaml.js.map +1 -0
- package/dist/serializers/format-codec.d.ts +53 -0
- package/dist/serializers/format-codec.d.ts.map +1 -0
- package/dist/serializers/format-codec.js +148 -0
- package/dist/serializers/format-codec.js.map +1 -0
- package/dist/serializers/presets.d.ts +48 -0
- package/dist/serializers/presets.d.ts.map +1 -0
- package/dist/serializers/presets.js +72 -0
- package/dist/serializers/presets.js.map +1 -0
- package/dist/serializers/serializer-service.d.ts +11 -0
- package/dist/serializers/serializer-service.d.ts.map +1 -0
- package/dist/serializers/serializer-service.js +4 -0
- package/dist/serializers/serializer-service.js.map +1 -0
- package/dist/state/collection-state.d.ts +19 -0
- package/dist/state/collection-state.d.ts.map +1 -0
- package/dist/state/collection-state.js +15 -0
- package/dist/state/collection-state.js.map +1 -0
- package/dist/state/state-operations.d.ts +38 -0
- package/dist/state/state-operations.d.ts.map +1 -0
- package/dist/state/state-operations.js +65 -0
- package/dist/state/state-operations.js.map +1 -0
- package/dist/storage/in-memory-adapter-layer.d.ts +16 -0
- package/dist/storage/in-memory-adapter-layer.d.ts.map +1 -0
- package/dist/storage/in-memory-adapter-layer.js +81 -0
- package/dist/storage/in-memory-adapter-layer.js.map +1 -0
- package/dist/storage/persistence-effect.d.ts +244 -0
- package/dist/storage/persistence-effect.d.ts.map +1 -0
- package/dist/storage/persistence-effect.js +551 -0
- package/dist/storage/persistence-effect.js.map +1 -0
- package/dist/storage/storage-service.d.ts +22 -0
- package/dist/storage/storage-service.d.ts.map +1 -0
- package/dist/storage/storage-service.js +4 -0
- package/dist/storage/storage-service.js.map +1 -0
- package/dist/storage/transforms.d.ts +183 -0
- package/dist/storage/transforms.d.ts.map +1 -0
- package/dist/storage/transforms.js +263 -0
- package/dist/storage/transforms.js.map +1 -0
- package/dist/transactions/transaction.d.ts +87 -0
- package/dist/transactions/transaction.d.ts.map +1 -0
- package/dist/transactions/transaction.js +240 -0
- package/dist/transactions/transaction.js.map +1 -0
- package/dist/types/aggregate-types.d.ts +73 -0
- package/dist/types/aggregate-types.d.ts.map +1 -0
- package/dist/types/aggregate-types.js +14 -0
- package/dist/types/aggregate-types.js.map +1 -0
- package/dist/types/computed-types.d.ts +71 -0
- package/dist/types/computed-types.d.ts.map +1 -0
- package/dist/types/computed-types.js +8 -0
- package/dist/types/computed-types.js.map +1 -0
- package/dist/types/crud-relationship-types.d.ts +180 -0
- package/dist/types/crud-relationship-types.d.ts.map +1 -0
- package/dist/types/crud-relationship-types.js +17 -0
- package/dist/types/crud-relationship-types.js.map +1 -0
- package/dist/types/crud-types.d.ts +343 -0
- package/dist/types/crud-types.d.ts.map +1 -0
- package/dist/types/crud-types.js +43 -0
- package/dist/types/crud-types.js.map +1 -0
- package/dist/types/cursor-types.d.ts +52 -0
- package/dist/types/cursor-types.d.ts.map +1 -0
- package/dist/types/cursor-types.js +2 -0
- package/dist/types/cursor-types.js.map +1 -0
- package/dist/types/database-config-types.d.ts +196 -0
- package/dist/types/database-config-types.d.ts.map +1 -0
- package/dist/types/database-config-types.js +11 -0
- package/dist/types/database-config-types.js.map +1 -0
- package/dist/types/hook-types.d.ts +158 -0
- package/dist/types/hook-types.d.ts.map +1 -0
- package/dist/types/hook-types.js +6 -0
- package/dist/types/hook-types.js.map +1 -0
- package/dist/types/index-types.d.ts +42 -0
- package/dist/types/index-types.d.ts.map +1 -0
- package/dist/types/index-types.js +8 -0
- package/dist/types/index-types.js.map +1 -0
- package/dist/types/operators.d.ts +5 -0
- package/dist/types/operators.d.ts.map +1 -0
- package/dist/types/operators.js +297 -0
- package/dist/types/operators.js.map +1 -0
- package/dist/types/query-overloads.d.ts +54 -0
- package/dist/types/query-overloads.d.ts.map +1 -0
- package/dist/types/query-overloads.js +3 -0
- package/dist/types/query-overloads.js.map +1 -0
- package/dist/types/reactive-types.d.ts +75 -0
- package/dist/types/reactive-types.d.ts.map +1 -0
- package/dist/types/reactive-types.js +7 -0
- package/dist/types/reactive-types.js.map +1 -0
- package/dist/types/schema-types.d.ts +56 -0
- package/dist/types/schema-types.d.ts.map +1 -0
- package/dist/types/schema-types.js +8 -0
- package/dist/types/schema-types.js.map +1 -0
- package/dist/types/search-types.d.ts +82 -0
- package/dist/types/search-types.d.ts.map +1 -0
- package/dist/types/search-types.js +110 -0
- package/dist/types/search-types.js.map +1 -0
- package/dist/types/types.d.ts +286 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +2 -0
- package/dist/types/types.js.map +1 -0
- package/dist/utils/id-generator.d.ts +97 -0
- package/dist/utils/id-generator.d.ts.map +1 -0
- package/dist/utils/id-generator.js +247 -0
- package/dist/utils/id-generator.js.map +1 -0
- package/dist/utils/nested-path.d.ts +56 -0
- package/dist/utils/nested-path.d.ts.map +1 -0
- package/dist/utils/nested-path.js +119 -0
- package/dist/utils/nested-path.js.map +1 -0
- package/dist/utils/path.d.ts +16 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +24 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/validators/foreign-key.d.ts +49 -0
- package/dist/validators/foreign-key.d.ts.map +1 -0
- package/dist/validators/foreign-key.js +153 -0
- package/dist/validators/foreign-key.js.map +1 -0
- package/dist/validators/schema-validator.d.ts +19 -0
- package/dist/validators/schema-validator.d.ts.map +1 -0
- package/dist/validators/schema-validator.js +34 -0
- package/dist/validators/schema-validator.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UnknownRecord } from "../../types/types";
|
|
2
|
+
/**
|
|
3
|
+
* Type helper to handle object-based field selections with nested support
|
|
4
|
+
*/
|
|
5
|
+
type SelectedTypeFromObject<T, Selection extends Record<string, unknown>> = {
|
|
6
|
+
[K in keyof Selection & keyof T]: Selection[K] extends true ? T[K] : Selection[K] extends Record<string, unknown> ? T[K] extends Record<string, unknown> ? SelectedTypeFromObject<T[K], Selection[K]> : never : never;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Apply object-based field selection to a single object
|
|
10
|
+
* @param data - The object to select fields from
|
|
11
|
+
* @param selection - Object with true values for fields to select
|
|
12
|
+
* @returns Object with only the selected fields
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyObjectSelection<T extends UnknownRecord, const Selection extends Record<string, unknown>>(data: T, selection: Selection): SelectedTypeFromObject<T, Selection>;
|
|
15
|
+
/**
|
|
16
|
+
* Apply field selection to an array of objects
|
|
17
|
+
* @param data - Array of objects to select fields from
|
|
18
|
+
* @param selection - Object with true values for fields to select
|
|
19
|
+
* @returns Array of objects with only the selected fields
|
|
20
|
+
*/
|
|
21
|
+
export declare function applySelectionToArray<T extends UnknownRecord, const Selection extends Record<string, unknown>>(data: T[], selection: Selection): Array<SelectedTypeFromObject<T, Selection>>;
|
|
22
|
+
/**
|
|
23
|
+
* Apply field selection with null/undefined handling
|
|
24
|
+
* @param data - The object to select fields from (can be null/undefined)
|
|
25
|
+
* @param selection - Object with true values for fields to select
|
|
26
|
+
* @returns Object with selected fields or null/undefined
|
|
27
|
+
*/
|
|
28
|
+
export declare function applySelectionSafe<T extends UnknownRecord, const Selection extends Record<string, unknown>>(data: T | null | undefined, selection: Selection): SelectedTypeFromObject<T, Selection> | null | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Check if a field should be selected based on selection criteria
|
|
31
|
+
* @param field - The field name to check
|
|
32
|
+
* @param selection - Object with true values or undefined for all fields
|
|
33
|
+
* @returns Whether the field should be included
|
|
34
|
+
*/
|
|
35
|
+
export declare function shouldSelectField<T extends UnknownRecord>(field: keyof T, selection: Record<string, unknown> | undefined): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Type guard to check if a value has selected fields
|
|
38
|
+
*/
|
|
39
|
+
export declare function hasSelectedFields<T extends UnknownRecord, const Selection extends Record<string, unknown>>(value: unknown, selection: Selection): value is SelectedTypeFromObject<T, Selection>;
|
|
40
|
+
/**
|
|
41
|
+
* Merge object-based field selections from multiple sources
|
|
42
|
+
* Useful for combining field selections from different query parts
|
|
43
|
+
*/
|
|
44
|
+
export declare function mergeObjectFieldSelections<_T extends UnknownRecord>(...selections: Array<Record<string, unknown> | undefined>): Record<string, unknown> | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Create a field selector function for use in pipelines
|
|
47
|
+
*/
|
|
48
|
+
export declare function createFieldSelector<T extends UnknownRecord, const Selection extends Record<string, unknown>>(selection: Selection): (data: T) => SelectedTypeFromObject<T, Selection>;
|
|
49
|
+
/**
|
|
50
|
+
* Create a field selector for arrays
|
|
51
|
+
*/
|
|
52
|
+
export declare function createArrayFieldSelector<T extends UnknownRecord, const Selection extends Record<string, unknown>>(selection: Selection): (data: T[]) => Array<SelectedTypeFromObject<T, Selection>>;
|
|
53
|
+
export {};
|
|
54
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../../src/operations/query/select.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAiBvD;;GAEG;AACH,KAAK,sBAAsB,CAAC,CAAC,EAAE,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAC1E,CAAC,IAAI,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,IAAI,GACxD,CAAC,CAAC,CAAC,CAAC,GACJ,SAAS,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC3C,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,GAC1C,KAAK,GACN,KAAK;CACT,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,CAAC,SAAS,aAAa,EACvB,KAAK,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9C,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,sBAAsB,CAAC,CAAC,EAAE,SAAS,CAAC,CAgCrE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,CAAC,SAAS,aAAa,EACvB,KAAK,CAAC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE/C,IAAI,EAAE,CAAC,EAAE,EACT,SAAS,EAAE,SAAS,GAClB,KAAK,CAAC,sBAAsB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAM7C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC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AAM,CAAC,EAAE,KAAG,KAAK,CAAC,sBAAsB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAG/D"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Type guard for checking if value is a record
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
// Type guard for checking if value is a UnknownRecord
|
|
6
|
+
function isUnknownRecord(value) {
|
|
7
|
+
return isRecord(value);
|
|
8
|
+
}
|
|
9
|
+
// Type guard for checking if value is a selection config
|
|
10
|
+
function isSelectionConfig(value) {
|
|
11
|
+
return isRecord(value);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Apply object-based field selection to a single object
|
|
15
|
+
* @param data - The object to select fields from
|
|
16
|
+
* @param selection - Object with true values for fields to select
|
|
17
|
+
* @returns Object with only the selected fields
|
|
18
|
+
*/
|
|
19
|
+
export function applyObjectSelection(data, selection) {
|
|
20
|
+
// Handle edge cases
|
|
21
|
+
if (!isUnknownRecord(data)) {
|
|
22
|
+
// Return empty object for invalid data
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
// If no selection specified, return empty object
|
|
26
|
+
if (!selection || Object.keys(selection).length === 0) {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
// Create new object with only selected fields
|
|
30
|
+
const result = {};
|
|
31
|
+
for (const [key, value] of Object.entries(selection)) {
|
|
32
|
+
if (value === true && key in data) {
|
|
33
|
+
result[key] = data[key];
|
|
34
|
+
}
|
|
35
|
+
else if (isSelectionConfig(value) && key in data) {
|
|
36
|
+
// Handle nested selection for populated fields
|
|
37
|
+
const nestedData = data[key];
|
|
38
|
+
if (Array.isArray(nestedData)) {
|
|
39
|
+
result[key] = nestedData
|
|
40
|
+
.filter(isUnknownRecord)
|
|
41
|
+
.map((item) => applyObjectSelection(item, value));
|
|
42
|
+
}
|
|
43
|
+
else if (isUnknownRecord(nestedData)) {
|
|
44
|
+
result[key] = applyObjectSelection(nestedData, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Apply field selection to an array of objects
|
|
52
|
+
* @param data - Array of objects to select fields from
|
|
53
|
+
* @param selection - Object with true values for fields to select
|
|
54
|
+
* @returns Array of objects with only the selected fields
|
|
55
|
+
*/
|
|
56
|
+
export function applySelectionToArray(data, selection) {
|
|
57
|
+
if (!Array.isArray(data)) {
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
return data.map((item) => applyObjectSelection(item, selection));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Apply field selection with null/undefined handling
|
|
64
|
+
* @param data - The object to select fields from (can be null/undefined)
|
|
65
|
+
* @param selection - Object with true values for fields to select
|
|
66
|
+
* @returns Object with selected fields or null/undefined
|
|
67
|
+
*/
|
|
68
|
+
export function applySelectionSafe(data, selection) {
|
|
69
|
+
if (data === null)
|
|
70
|
+
return null;
|
|
71
|
+
if (data === undefined)
|
|
72
|
+
return undefined;
|
|
73
|
+
return applyObjectSelection(data, selection);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if a field should be selected based on selection criteria
|
|
77
|
+
* @param field - The field name to check
|
|
78
|
+
* @param selection - Object with true values or undefined for all fields
|
|
79
|
+
* @returns Whether the field should be included
|
|
80
|
+
*/
|
|
81
|
+
export function shouldSelectField(field, selection) {
|
|
82
|
+
// If no selection specified, include all fields
|
|
83
|
+
if (!selection) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
// Handle object-based selection
|
|
87
|
+
const fieldStr = String(field);
|
|
88
|
+
return fieldStr in selection && selection[fieldStr] === true;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Type guard to check if a value has selected fields
|
|
92
|
+
*/
|
|
93
|
+
export function hasSelectedFields(value, selection) {
|
|
94
|
+
if (!value || typeof value !== "object") {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
if (!isUnknownRecord(value)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
const obj = value;
|
|
101
|
+
// Handle object-based selection
|
|
102
|
+
return Object.entries(selection).every(([key, val]) => {
|
|
103
|
+
if (val === true) {
|
|
104
|
+
return key in obj;
|
|
105
|
+
}
|
|
106
|
+
return true; // Skip non-true values
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Merge object-based field selections from multiple sources
|
|
111
|
+
* Useful for combining field selections from different query parts
|
|
112
|
+
*/
|
|
113
|
+
export function mergeObjectFieldSelections(...selections) {
|
|
114
|
+
// Filter out undefined selections
|
|
115
|
+
const validSelections = selections.filter((sel) => sel !== undefined);
|
|
116
|
+
// If no valid selections, return undefined (select all)
|
|
117
|
+
if (validSelections.length === 0) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
// Merge all selections with deep merge for nested objects
|
|
121
|
+
const merged = {};
|
|
122
|
+
for (const selection of validSelections) {
|
|
123
|
+
for (const [key, value] of Object.entries(selection)) {
|
|
124
|
+
if (value === true) {
|
|
125
|
+
merged[key] = true;
|
|
126
|
+
}
|
|
127
|
+
else if (typeof value === "object" && value !== null) {
|
|
128
|
+
// Deep merge nested selections
|
|
129
|
+
const existing = merged[key];
|
|
130
|
+
if (typeof existing === "object" &&
|
|
131
|
+
existing !== null &&
|
|
132
|
+
!Array.isArray(existing)) {
|
|
133
|
+
merged[key] = { ...existing, ...value };
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
merged[key] = { ...value };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return merged;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Create a field selector function for use in pipelines
|
|
145
|
+
*/
|
|
146
|
+
export function createFieldSelector(selection) {
|
|
147
|
+
return (data) => {
|
|
148
|
+
return applyObjectSelection(data, selection);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a field selector for arrays
|
|
153
|
+
*/
|
|
154
|
+
export function createArrayFieldSelector(selection) {
|
|
155
|
+
return (data) => {
|
|
156
|
+
return applySelectionToArray(data, selection);
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../../src/operations/query/select.ts"],"names":[],"mappings":"AAEA,+CAA+C;AAC/C,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,sDAAsD;AACtD,SAAS,eAAe,CAAC,KAAc;IACtC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAED,yDAAyD;AACzD,SAAS,iBAAiB,CAAC,KAAc;IACxC,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC;AAeD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAGlC,IAAO,EAAE,SAAoB;IAC9B,oBAAoB;IACpB,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,uCAAuC;QACvC,OAAO,EAA0C,CAAC;IACnD,CAAC;IAED,iDAAiD;IACjD,IAAI,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvD,OAAO,EAA0C,CAAC;IACnD,CAAC;IAED,8CAA8C;IAC9C,MAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE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46 @@
|
|
|
1
|
+
import { Stream } from "effect";
|
|
2
|
+
import { SEARCH_SCORE_KEY, type SearchConfig } from "../../types/search-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A sort configuration mapping field names to sort direction.
|
|
5
|
+
*/
|
|
6
|
+
type SortConfig = Partial<Record<string, "asc" | "desc">>;
|
|
7
|
+
/**
|
|
8
|
+
* Extract SearchConfig from a where clause if present at top level.
|
|
9
|
+
* Returns undefined if no top-level $search is found.
|
|
10
|
+
*/
|
|
11
|
+
export declare function extractSearchConfig(where: Record<string, unknown> | undefined): SearchConfig | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Compute and attach search relevance scores as metadata to each item in the stream.
|
|
14
|
+
* This is called after filtering to pre-compute scores for the sort stage.
|
|
15
|
+
*
|
|
16
|
+
* Attaches the score as `_searchScore` on each item. Items that don't match
|
|
17
|
+
* the search (already filtered out) won't be processed.
|
|
18
|
+
*
|
|
19
|
+
* @param searchConfig - The search configuration containing query and optional fields
|
|
20
|
+
* @returns A stream combinator that attaches _searchScore metadata to each item
|
|
21
|
+
*/
|
|
22
|
+
export declare const attachSearchScores: <T extends Record<string, unknown>>(searchConfig: SearchConfig | undefined) => <E, R>(stream: Stream.Stream<T, E, R>) => Stream.Stream<T & {
|
|
23
|
+
readonly [SEARCH_SCORE_KEY]?: number;
|
|
24
|
+
}, E, R>;
|
|
25
|
+
/**
|
|
26
|
+
* Apply relevance-based sorting for search results.
|
|
27
|
+
* Sorts items by their search relevance score in descending order.
|
|
28
|
+
*
|
|
29
|
+
* This function expects items to have a pre-computed `_searchScore` attached
|
|
30
|
+
* by `attachSearchScores`. If the score is not present, it falls back to
|
|
31
|
+
* computing the score on-the-fly.
|
|
32
|
+
*
|
|
33
|
+
* @param searchConfig - The search configuration containing query and optional fields
|
|
34
|
+
* @returns A stream combinator that sorts by relevance score
|
|
35
|
+
*/
|
|
36
|
+
export declare const applyRelevanceSort: <T extends Record<string, unknown>>(searchConfig: SearchConfig) => <E, R>(stream: Stream.Stream<T, E, R>) => Stream.Stream<T, E, R>;
|
|
37
|
+
/**
|
|
38
|
+
* Apply a sort configuration as a Stream combinator.
|
|
39
|
+
* Collects the stream, sorts in memory, and re-emits as a new stream.
|
|
40
|
+
*
|
|
41
|
+
* Supports multi-field sorting with asc/desc order, nested field paths (dot notation),
|
|
42
|
+
* and handles undefined/null values (sorted to the end regardless of direction).
|
|
43
|
+
*/
|
|
44
|
+
export declare const applySort: <T extends Record<string, unknown>>(sort: SortConfig | undefined) => <E, R>(stream: Stream.Stream<T, E, R>) => Stream.Stream<T, E, R>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=sort-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-stream.d.ts","sourceRoot":"","sources":["../../../src/operations/query/sort-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACN,gBAAgB,EAChB,KAAK,YAAY,EACjB,MAAM,6BAA6B,CAAC;AAIrC;;GAEG;AACH,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;AAE1D;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GACxC,YAAY,GAAG,SAAS,CAQ1B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,YAAY,GAAG,SAAS,MACzE,CAAC,EAAE,CAAC,EACJ,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,EAAE,CAAC,CAiClE,CAAC;AAmCH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,GAC7B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,YAAY,MAC7D,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAoC5D,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,UAAU,GAAG,SAAS,MAC/D,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAG,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAiC5D,CAAC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Chunk, Effect, Stream } from "effect";
|
|
2
|
+
import { SEARCH_SCORE_KEY, } from "../../types/search-types.js";
|
|
3
|
+
import { getNestedValue } from "../../utils/nested-path.js";
|
|
4
|
+
import { computeSearchScore, tokenize } from "./search.js";
|
|
5
|
+
/**
|
|
6
|
+
* Extract SearchConfig from a where clause if present at top level.
|
|
7
|
+
* Returns undefined if no top-level $search is found.
|
|
8
|
+
*/
|
|
9
|
+
export function extractSearchConfig(where) {
|
|
10
|
+
if (!where)
|
|
11
|
+
return undefined;
|
|
12
|
+
const searchValue = where.$search;
|
|
13
|
+
if (searchValue === null || typeof searchValue !== "object")
|
|
14
|
+
return undefined;
|
|
15
|
+
const config = searchValue;
|
|
16
|
+
// Validate that it has the required 'query' property
|
|
17
|
+
if (typeof config.query !== "string")
|
|
18
|
+
return undefined;
|
|
19
|
+
return config;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compute and attach search relevance scores as metadata to each item in the stream.
|
|
23
|
+
* This is called after filtering to pre-compute scores for the sort stage.
|
|
24
|
+
*
|
|
25
|
+
* Attaches the score as `_searchScore` on each item. Items that don't match
|
|
26
|
+
* the search (already filtered out) won't be processed.
|
|
27
|
+
*
|
|
28
|
+
* @param searchConfig - The search configuration containing query and optional fields
|
|
29
|
+
* @returns A stream combinator that attaches _searchScore metadata to each item
|
|
30
|
+
*/
|
|
31
|
+
export const attachSearchScores = (searchConfig) => (stream) => {
|
|
32
|
+
// No search config: pass through unchanged (no scores to attach)
|
|
33
|
+
if (!searchConfig)
|
|
34
|
+
return stream;
|
|
35
|
+
const queryTokens = tokenize(searchConfig.query);
|
|
36
|
+
// Empty query: no scoring needed
|
|
37
|
+
if (queryTokens.length === 0)
|
|
38
|
+
return stream;
|
|
39
|
+
return Stream.map(stream, (item) => {
|
|
40
|
+
// Determine target fields: explicit or all string fields
|
|
41
|
+
let targetFields;
|
|
42
|
+
if (searchConfig.fields && searchConfig.fields.length > 0) {
|
|
43
|
+
targetFields = searchConfig.fields;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
targetFields = Object.keys(item).filter((k) => typeof item[k] === "string");
|
|
47
|
+
}
|
|
48
|
+
const score = computeSearchScore(item, queryTokens, targetFields);
|
|
49
|
+
return { ...item, [SEARCH_SCORE_KEY]: score };
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Compare two values for sorting, returning a negative, zero, or positive number.
|
|
54
|
+
* Handles undefined/null (always sort to end), strings, numbers, booleans, Dates, and fallback toString.
|
|
55
|
+
*/
|
|
56
|
+
function compareValues(aValue, bValue) {
|
|
57
|
+
// Handle undefined/null values - they always sort to the end
|
|
58
|
+
if (aValue === undefined || aValue === null) {
|
|
59
|
+
if (bValue === undefined || bValue === null) {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
if (bValue === undefined || bValue === null) {
|
|
65
|
+
return -1;
|
|
66
|
+
}
|
|
67
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
68
|
+
return aValue.localeCompare(bValue);
|
|
69
|
+
}
|
|
70
|
+
if (typeof aValue === "number" && typeof bValue === "number") {
|
|
71
|
+
return aValue - bValue;
|
|
72
|
+
}
|
|
73
|
+
if (typeof aValue === "boolean" && typeof bValue === "boolean") {
|
|
74
|
+
return (aValue ? 1 : 0) - (bValue ? 1 : 0);
|
|
75
|
+
}
|
|
76
|
+
if (aValue instanceof Date && bValue instanceof Date) {
|
|
77
|
+
return aValue.getTime() - bValue.getTime();
|
|
78
|
+
}
|
|
79
|
+
// Fallback: convert to string
|
|
80
|
+
return String(aValue).localeCompare(String(bValue));
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Apply relevance-based sorting for search results.
|
|
84
|
+
* Sorts items by their search relevance score in descending order.
|
|
85
|
+
*
|
|
86
|
+
* This function expects items to have a pre-computed `_searchScore` attached
|
|
87
|
+
* by `attachSearchScores`. If the score is not present, it falls back to
|
|
88
|
+
* computing the score on-the-fly.
|
|
89
|
+
*
|
|
90
|
+
* @param searchConfig - The search configuration containing query and optional fields
|
|
91
|
+
* @returns A stream combinator that sorts by relevance score
|
|
92
|
+
*/
|
|
93
|
+
export const applyRelevanceSort = (searchConfig) => (stream) => {
|
|
94
|
+
const queryTokens = tokenize(searchConfig.query);
|
|
95
|
+
// Empty query: no relevance to sort by
|
|
96
|
+
if (queryTokens.length === 0)
|
|
97
|
+
return stream;
|
|
98
|
+
return Stream.unwrap(Effect.map(Stream.runCollect(stream), (chunk) => {
|
|
99
|
+
const arr = Chunk.toArray(chunk);
|
|
100
|
+
// Sort by pre-computed score, or compute on-the-fly if not present
|
|
101
|
+
const scored = arr.map((item) => {
|
|
102
|
+
// Use pre-computed score if available
|
|
103
|
+
const preComputedScore = item[SEARCH_SCORE_KEY];
|
|
104
|
+
if (typeof preComputedScore === "number") {
|
|
105
|
+
return { item, score: preComputedScore };
|
|
106
|
+
}
|
|
107
|
+
// Fallback: compute score on-the-fly (for backward compatibility)
|
|
108
|
+
let targetFields;
|
|
109
|
+
if (searchConfig.fields && searchConfig.fields.length > 0) {
|
|
110
|
+
targetFields = searchConfig.fields;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
targetFields = Object.keys(item).filter((k) => typeof item[k] === "string");
|
|
114
|
+
}
|
|
115
|
+
const score = computeSearchScore(item, queryTokens, targetFields);
|
|
116
|
+
return { item, score };
|
|
117
|
+
});
|
|
118
|
+
// Sort by score descending (higher scores first)
|
|
119
|
+
scored.sort((a, b) => b.score - a.score);
|
|
120
|
+
return Stream.fromIterable(scored.map(({ item }) => item));
|
|
121
|
+
}));
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Apply a sort configuration as a Stream combinator.
|
|
125
|
+
* Collects the stream, sorts in memory, and re-emits as a new stream.
|
|
126
|
+
*
|
|
127
|
+
* Supports multi-field sorting with asc/desc order, nested field paths (dot notation),
|
|
128
|
+
* and handles undefined/null values (sorted to the end regardless of direction).
|
|
129
|
+
*/
|
|
130
|
+
export const applySort = (sort) => (stream) => {
|
|
131
|
+
if (!sort || Object.keys(sort).length === 0)
|
|
132
|
+
return stream;
|
|
133
|
+
const sortFields = Object.entries(sort);
|
|
134
|
+
return Stream.unwrap(Effect.map(Stream.runCollect(stream), (chunk) => {
|
|
135
|
+
const arr = Chunk.toArray(chunk);
|
|
136
|
+
arr.sort((a, b) => {
|
|
137
|
+
for (const [field, order] of sortFields) {
|
|
138
|
+
const aValue = getNestedValue(a, field);
|
|
139
|
+
const bValue = getNestedValue(b, field);
|
|
140
|
+
// Undefined/null always sort to the end, regardless of direction
|
|
141
|
+
const aIsNullish = aValue === undefined || aValue === null;
|
|
142
|
+
const bIsNullish = bValue === undefined || bValue === null;
|
|
143
|
+
if (aIsNullish || bIsNullish) {
|
|
144
|
+
if (aIsNullish && bIsNullish)
|
|
145
|
+
continue;
|
|
146
|
+
return aIsNullish ? 1 : -1;
|
|
147
|
+
}
|
|
148
|
+
const comparison = compareValues(aValue, bValue);
|
|
149
|
+
if (comparison !== 0) {
|
|
150
|
+
return order === "desc" ? -comparison : comparison;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
});
|
|
155
|
+
return Stream.fromIterable(arr);
|
|
156
|
+
}));
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=sort-stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-stream.js","sourceRoot":"","sources":["../../../src/operations/query/sort-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EACN,gBAAgB,GAEhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO3D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAClC,KAA0C;IAE1C,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC;IAClC,IAAI,WAAW,KAAK,IAAI,IAAI,OAAO,WAAW,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9E,MAAM,MAAM,GAAG,WAA2B,CAAC;IAC3C,qDAAqD;IACrD,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACvD,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC9B,CAAoC,YAAsC,EAAE,EAAE,CAC9E,CACC,MAA8B,EACsC,EAAE;IACtE,iEAAiE;IACjE,IAAI,CAAC,YAAY;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C;QACV,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC,CAAC,CACF,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SortOrder } from "../../types/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sort an array of data based on sort configuration
|
|
4
|
+
* @param data The data to sort
|
|
5
|
+
* @param sortConfig The sort configuration (field -> order mapping)
|
|
6
|
+
* @returns The sorted data
|
|
7
|
+
*/
|
|
8
|
+
export declare function sortData<T extends Record<string, unknown>>(data: T[], sortConfig?: Partial<Record<string, SortOrder>>): T[];
|
|
9
|
+
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../src/operations/query/sort.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,IAAI,EAAE,CAAC,EAAE,EACT,UAAU,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,GAC7C,CAAC,EAAE,CAsDL"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getNestedValue } from "../../utils/nested-path";
|
|
2
|
+
/**
|
|
3
|
+
* Sort an array of data based on sort configuration
|
|
4
|
+
* @param data The data to sort
|
|
5
|
+
* @param sortConfig The sort configuration (field -> order mapping)
|
|
6
|
+
* @returns The sorted data
|
|
7
|
+
*/
|
|
8
|
+
export function sortData(data, sortConfig) {
|
|
9
|
+
if (!sortConfig || Object.keys(sortConfig).length === 0) {
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
// Create a copy to avoid mutating the original array
|
|
13
|
+
const sorted = [...data];
|
|
14
|
+
// Get sort fields in order
|
|
15
|
+
const sortFields = Object.entries(sortConfig);
|
|
16
|
+
sorted.sort((a, b) => {
|
|
17
|
+
for (const [field, order] of sortFields) {
|
|
18
|
+
const aValue = getNestedValue(a, field);
|
|
19
|
+
const bValue = getNestedValue(b, field);
|
|
20
|
+
// Handle undefined/null values - they always sort to the end
|
|
21
|
+
if (aValue === undefined || aValue === null) {
|
|
22
|
+
if (bValue === undefined || bValue === null) {
|
|
23
|
+
continue; // Both undefined/null, check next field
|
|
24
|
+
}
|
|
25
|
+
return 1; // a is undefined/null, b is not - a goes after b
|
|
26
|
+
}
|
|
27
|
+
if (bValue === undefined || bValue === null) {
|
|
28
|
+
return -1; // b is undefined/null, a is not - a goes before b
|
|
29
|
+
}
|
|
30
|
+
// Compare values
|
|
31
|
+
let comparison = 0;
|
|
32
|
+
if (typeof aValue === "string" && typeof bValue === "string") {
|
|
33
|
+
comparison = aValue.localeCompare(bValue);
|
|
34
|
+
}
|
|
35
|
+
else if (typeof aValue === "number" && typeof bValue === "number") {
|
|
36
|
+
comparison = aValue - bValue;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof aValue === "boolean" && typeof bValue === "boolean") {
|
|
39
|
+
// false < true in ascending order
|
|
40
|
+
comparison = (aValue ? 1 : 0) - (bValue ? 1 : 0);
|
|
41
|
+
}
|
|
42
|
+
else if (aValue instanceof Date && bValue instanceof Date) {
|
|
43
|
+
comparison = aValue.getTime() - bValue.getTime();
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
// For other types, convert to string for comparison
|
|
47
|
+
comparison = String(aValue).localeCompare(String(bValue));
|
|
48
|
+
}
|
|
49
|
+
// Apply sort order
|
|
50
|
+
if (comparison !== 0) {
|
|
51
|
+
return order === "desc" ? -comparison : comparison;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return 0; // All fields are equal
|
|
55
|
+
});
|
|
56
|
+
return sorted;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=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fig } from "../../types/database-config-types.js";
|
|
4
|
+
/**
|
|
5
|
+
* PopulateValue can be:
|
|
6
|
+
* - `true` to populate a relationship with all fields
|
|
7
|
+
* - An object with nested populate config for recursive population
|
|
8
|
+
*/
|
|
9
|
+
type PopulateValue = boolean | Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Apply relationship population as a Stream combinator.
|
|
12
|
+
*
|
|
13
|
+
* For each item in the stream, resolves relationships by reading related
|
|
14
|
+
* entities from collection Refs. Supports nested population recursively
|
|
15
|
+
* up to a depth of 5.
|
|
16
|
+
*
|
|
17
|
+
* - `ref` relationships: look up a single entity in the target collection
|
|
18
|
+
* using the foreign key field (default: `<relationName>Id`)
|
|
19
|
+
* - `inverse` relationships: find all entities in the target collection
|
|
20
|
+
* whose foreign key points back to this item's `id`
|
|
21
|
+
*
|
|
22
|
+
* @param populateConfig - Which relationships to populate (e.g. `{ company: true }`)
|
|
23
|
+
* @param stateRefs - Map of collection name → Ref<ReadonlyMap<string, entity>>
|
|
24
|
+
* @param dbConfig - Full database config with relationship definitions
|
|
25
|
+
* @param collectionName - Name of the source collection being queried
|
|
26
|
+
*/
|
|
27
|
+
export declare const applyPopulate: <T extends Record<string, unknown>>(populateConfig: Record<string, PopulateValue> | undefined, stateRefs: Record<string, Ref.Ref<ReadonlyMap<string, Record<string, unknown>>>>, dbConfig: Record<string, CollectionConfig>, collectionName: string) => <E, R>(stream: Stream.Stream<T, E, R>) => Stream.Stream<T, E | DanglingReferenceError, R>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=populate-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"populate-stream.d.ts","sourceRoot":"","sources":["../../../src/operations/relationships/populate-stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,GAAG,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAO7E;;;;GAIG;AACH,KAAK,aAAa,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAuMvD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,GACxB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,gBAAgB,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,EACzD,WAAW,MAAM,CAChB,MAAM,EACN,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CACrD,EACD,UAAU,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAC1C,gBAAgB,MAAM,MAEtB,CAAC,EAAE,CAAC,EACJ,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAC5B,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,sBAAsB,EAAE,CAAC,CAyBhD,CAAC"}
|