@semiont/make-meaning 0.4.17 → 0.4.18

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/dist/index.d.ts CHANGED
@@ -878,9 +878,17 @@ declare class ResourceContext {
878
878
  */
879
879
  static getResourceMetadata(resourceId: ResourceId, kb: KnowledgeBase): Promise<ResourceDescriptor$1 | null>;
880
880
  /**
881
- * List all resources by scanning view storage
881
+ * List resources, optionally filtered.
882
+ *
883
+ * When `search` is set, delegates to `kb.graph.searchResources`, which runs
884
+ * the name match in the graph engine instead of scanning every view in JS.
885
+ * The graph result is then narrowed by `archived` if requested.
886
+ *
887
+ * When `search` is unset, falls back to scanning all materialized views.
888
+ * (TODO: also push the listing path through the graph for large KBs.)
882
889
  */
883
890
  static listResources(filters: ListResourcesFilters | undefined, kb: KnowledgeBase): Promise<ResourceDescriptor$1[]>;
891
+ private static sortByDateDesc;
884
892
  /**
885
893
  * Add content previews to resources (for search results)
886
894
  * Retrieves and decodes the first 200 characters of each resource's primary representation
package/dist/index.js CHANGED
@@ -10917,7 +10917,7 @@ import { getEntityTypes } from "@semiont/ontology";
10917
10917
 
10918
10918
  // src/resource-context.ts
10919
10919
  import { getPrimaryRepresentation, decodeRepresentation } from "@semiont/api-client";
10920
- var ResourceContext = class {
10920
+ var ResourceContext = class _ResourceContext {
10921
10921
  /**
10922
10922
  * Get resource metadata from view storage
10923
10923
  */
@@ -10929,9 +10929,21 @@ var ResourceContext = class {
10929
10929
  return view.resource;
10930
10930
  }
10931
10931
  /**
10932
- * List all resources by scanning view storage
10932
+ * List resources, optionally filtered.
10933
+ *
10934
+ * When `search` is set, delegates to `kb.graph.searchResources`, which runs
10935
+ * the name match in the graph engine instead of scanning every view in JS.
10936
+ * The graph result is then narrowed by `archived` if requested.
10937
+ *
10938
+ * When `search` is unset, falls back to scanning all materialized views.
10939
+ * (TODO: also push the listing path through the graph for large KBs.)
10933
10940
  */
10934
10941
  static async listResources(filters, kb) {
10942
+ if (filters?.search) {
10943
+ const matches = await kb.graph.searchResources(filters.search);
10944
+ const filtered = filters.archived !== void 0 ? matches.filter((doc) => doc.archived === filters.archived) : matches;
10945
+ return _ResourceContext.sortByDateDesc(filtered);
10946
+ }
10935
10947
  const allViews = await kb.views.getAll();
10936
10948
  const resources = [];
10937
10949
  for (const view of allViews) {
@@ -10939,20 +10951,16 @@ var ResourceContext = class {
10939
10951
  if (filters?.archived !== void 0 && doc.archived !== filters.archived) {
10940
10952
  continue;
10941
10953
  }
10942
- if (filters?.search) {
10943
- const searchLower = filters.search.toLowerCase();
10944
- if (!doc.name.toLowerCase().includes(searchLower)) {
10945
- continue;
10946
- }
10947
- }
10948
10954
  resources.push(doc);
10949
10955
  }
10950
- resources.sort((a, b) => {
10956
+ return _ResourceContext.sortByDateDesc(resources);
10957
+ }
10958
+ static sortByDateDesc(resources) {
10959
+ return [...resources].sort((a, b) => {
10951
10960
  const aTime = a.dateCreated ? new Date(a.dateCreated).getTime() : 0;
10952
10961
  const bTime = b.dateCreated ? new Date(b.dateCreated).getTime() : 0;
10953
10962
  return bTime - aTime;
10954
10963
  });
10955
- return resources;
10956
10964
  }
10957
10965
  /**
10958
10966
  * Add content previews to resources (for search results)