monorise 2.0.0-dev.1 → 2.0.0-dev.2

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.
@@ -1,4 +1,4 @@
1
- import { Entity as Entity$2, EntitySchemaMap, createEntityConfig, WhereConditions, ApiKeyPolicies, ApiKeyRoutePermission, CompiledApiKeyPolicy } from '../base/index';
1
+ import { Entity as Entity$2, EntitySchemaMap, createEntityConfig, SearchSettings, ResolvedSearchConfig, WhereConditions, ApiKeyPolicies, ApiKeyRoutePermission, CompiledApiKeyPolicy } from '../base/index';
2
2
  import * as hono from 'hono';
3
3
  import { Hono, MiddlewareHandler } from 'hono';
4
4
  import * as _aws_sdk_client_dynamodb from '@aws-sdk/client-dynamodb';
@@ -14,7 +14,7 @@ import { FirehoseClient } from '@aws-sdk/client-firehose';
14
14
  import { LambdaClient } from '@aws-sdk/client-lambda';
15
15
  import { S3Client } from '@aws-sdk/client-s3';
16
16
  import * as hono_aws_lambda from 'hono/aws-lambda';
17
- import { SQSEvent, SQSBatchItemFailure, DynamoDBBatchItemFailure, APIGatewayProxyWebsocketEventV2, APIGatewayProxyResultV2, DynamoDBStreamEvent } from 'aws-lambda';
17
+ import { SQSEvent, SQSBatchItemFailure, DynamoDBBatchItemFailure, Context, APIGatewayProxyWebsocketEventV2, APIGatewayProxyResultV2, DynamoDBStreamEvent } from 'aws-lambda';
18
18
  import { _Record } from '@aws-sdk/client-dynamodb-streams';
19
19
 
20
20
  type EventDetail = {
@@ -291,6 +291,65 @@ declare class MutualRepository extends Repository {
291
291
  }): Promise<void>;
292
292
  }
293
293
 
294
+ /**
295
+ * Word index for entities configured with `search`. Each word an entity is
296
+ * indexed by is a copy of the entity at PK `SEARCH#<type>`, SK
297
+ * `<word>#<entityId>`, with R1PK set to the entity so the replication
298
+ * processor keeps its data current and removes it with the entity.
299
+ */
300
+ declare class SearchRepository {
301
+ private readonly EntityConfig;
302
+ private readonly TABLE_NAME;
303
+ private readonly dynamodbClient;
304
+ private readonly entityRepository;
305
+ private readonly searchDefaults?;
306
+ private readyTypes;
307
+ constructor(EntityConfig: Record<Entity$2, ReturnType<typeof createEntityConfig>>, TABLE_NAME: string, dynamodbClient: DynamoDB, entityRepository: EntityRepository, searchDefaults?: SearchSettings | undefined);
308
+ /** The resolved `search` config, or undefined if the type isn't indexed. */
309
+ searchConfig(entityType: Entity$2): ResolvedSearchConfig | undefined;
310
+ indexedEntityTypes(): Entity$2[];
311
+ private rowKeys;
312
+ private searchRow;
313
+ /** Puts a row for each word in `add` and deletes the rows in `remove`. */
314
+ writeRows<T extends Entity$2>(entity: Entity$1<T>, add: string[], remove: string[]): Promise<void>;
315
+ /** The words an entity currently has rows for, read from the GSI. */
316
+ existingWords(entityType: Entity$2, entityId: string): Promise<string[]>;
317
+ getIndexState(entityType: Entity$2): Promise<{
318
+ state?: string;
319
+ configHash?: string;
320
+ } | undefined>;
321
+ markIndexBuilding(entityType: Entity$2, configHash: string): Promise<void>;
322
+ /**
323
+ * Marks the index ready, unless a newer reindex has taken over since: its
324
+ * config hash replaces this one when it starts.
325
+ */
326
+ markIndexReady(entityType: Entity$2, configHash: string): Promise<boolean>;
327
+ /** Whether the index was fully built for the current config. */
328
+ isIndexReady(entityType: Entity$2, config: ResolvedSearchConfig): Promise<boolean>;
329
+ /** Deletes the marker, so the next reindex rebuilds the type in full. */
330
+ clearIndexState(entityType: Entity$2): Promise<void>;
331
+ /**
332
+ * Brings one entity's rows in line with its current data and config. It
333
+ * runs alongside the stream, which may write a newer version of the same
334
+ * rows, so each write only goes through over an older copy.
335
+ */
336
+ reindexEntity(entityType: Entity$2, entityId: string, config: ResolvedSearchConfig): Promise<void>;
337
+ private lookUp;
338
+ /**
339
+ * Every entity matching `query`, newest first. Reads the rows of the
340
+ * query's longest word, or scans every entity while the index is still
341
+ * being built for the current config. Both give the same matches.
342
+ *
343
+ * There's no `totalCount`: counting every entity of the type would take
344
+ * the scan the index avoids. `filteredCount` is the number of matches.
345
+ */
346
+ searchEntities<T extends Entity$2>(entityType: T, query: string): Promise<{
347
+ items: Entity$1<T>[];
348
+ totalCount?: undefined;
349
+ filteredCount: number;
350
+ }>;
351
+ }
352
+
294
353
  declare class TaggedEntity<T extends Entity$2> extends Entity$1<T> {
295
354
  tagName: string;
296
355
  group?: string;
@@ -4625,7 +4684,8 @@ declare class GetEntityController {
4625
4684
 
4626
4685
  declare class ListEntitiesController {
4627
4686
  private entityRepository;
4628
- constructor(entityRepository: EntityRepository);
4687
+ private searchRepository;
4688
+ constructor(entityRepository: EntityRepository, searchRepository: SearchRepository);
4629
4689
  controller: hono.MiddlewareHandler<any, string, {}, Response & hono.TypedResponse<{
4630
4690
  data: {
4631
4691
  [x: string]: hono_utils_types.JSONValue;
@@ -4968,6 +5028,7 @@ declare class DependencyContainer {
4968
5028
  EmailAuthEnabledEntities: Entity$2[];
4969
5029
  /** Policies from the file `apiKeys` points to in monorise.config.ts. */
4970
5030
  ApiKeyPolicies?: ApiKeyPolicies;
5031
+ SearchDefaults?: SearchSettings;
4971
5032
  tableName?: string;
4972
5033
  };
4973
5034
  private _instanceCache;
@@ -4979,6 +5040,7 @@ declare class DependencyContainer {
4979
5040
  EmailAuthEnabledEntities: Entity$2[];
4980
5041
  /** Policies from the file `apiKeys` points to in monorise.config.ts. */
4981
5042
  ApiKeyPolicies?: ApiKeyPolicies;
5043
+ SearchDefaults?: SearchSettings;
4982
5044
  tableName?: string;
4983
5045
  });
4984
5046
  createCachedInstance<T extends new (...args: any[]) => any>(ClassRef: T, ...args: ConstructorParameters<T>): InstanceType<T>;
@@ -4988,6 +5050,7 @@ declare class DependencyContainer {
4988
5050
  get dbUtils(): DbUtils;
4989
5051
  get eventUtils(): EventUtils;
4990
5052
  get entityRepository(): EntityRepository;
5053
+ get searchRepository(): SearchRepository;
4991
5054
  get mutualRepository(): MutualRepository;
4992
5055
  get entityServiceLifeCycle(): EntityServiceLifeCycle;
4993
5056
  get entityService(): EntityService;
@@ -5077,11 +5140,11 @@ declare const analyticsQueryHandler: () => <L extends hono_aws_lambda.LambdaEven
5077
5140
  multiValueHeaders?: undefined;
5078
5141
  })>;
5079
5142
 
5080
- declare const handler$9: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5143
+ declare const handler$a: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5081
5144
  batchItemFailures: SQSBatchItemFailure[];
5082
5145
  }>;
5083
5146
 
5084
- declare const handler$8: (config: Record<Entity$2, ReturnType<typeof createEntityConfig>>) => (event: {
5147
+ declare const handler$9: (config: Record<Entity$2, ReturnType<typeof createEntityConfig>>) => (event: {
5085
5148
  Records: _Record[];
5086
5149
  }) => Promise<{
5087
5150
  batchItemFailures: DynamoDBBatchItemFailure[];
@@ -5109,7 +5172,7 @@ declare function startBackfill(reconcile?: boolean): Promise<{
5109
5172
  exportTime: string | undefined;
5110
5173
  started: boolean;
5111
5174
  }>;
5112
- declare const handler$7: (config: Config) => (event: S3ExportEvent | BackfillLaunchEvent) => Promise<{
5175
+ declare const handler$8: (config: Config) => (event: S3ExportEvent | BackfillLaunchEvent) => Promise<{
5113
5176
  exportArn: string | undefined;
5114
5177
  exportTime: string | undefined;
5115
5178
  started: boolean;
@@ -5140,26 +5203,50 @@ type Dataset = {
5140
5203
  type Manifest = {
5141
5204
  datasets: Dataset[];
5142
5205
  };
5143
- declare const handler$6: (configuredManifest?: Manifest) => () => Promise<void>;
5206
+ declare const handler$7: (configuredManifest?: Manifest) => () => Promise<void>;
5144
5207
 
5145
- declare const handler$5: () => Promise<void>;
5208
+ declare const handler$6: () => Promise<void>;
5146
5209
 
5147
- declare const handler$4: () => Promise<void>;
5210
+ declare const handler$5: () => Promise<void>;
5148
5211
 
5149
- declare const handler$3: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5212
+ declare const handler$4: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5150
5213
  batchItemFailures: SQSBatchItemFailure[];
5151
5214
  }>;
5152
5215
 
5153
- declare const handler$2: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5216
+ declare const handler$3: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5154
5217
  batchItemFailures: SQSBatchItemFailure[];
5155
5218
  }>;
5156
5219
 
5157
- declare const handler$1: (container: DependencyContainer) => (event: {
5220
+ declare const handler$2: (container: DependencyContainer) => (event: {
5158
5221
  Records: _Record[];
5159
5222
  }) => Promise<{
5160
5223
  batchItemFailures: DynamoDBBatchItemFailure[];
5161
5224
  }>;
5162
5225
 
5226
+ type SearchReindexEvent = {
5227
+ action: 'start';
5228
+ force?: boolean;
5229
+ } | {
5230
+ action: 'reindex';
5231
+ entityType: Entity$2;
5232
+ configHash: string;
5233
+ lastKey?: string;
5234
+ failures?: number;
5235
+ };
5236
+ /**
5237
+ * Builds the search index for entities that existed before their `search`
5238
+ * config did, or before it changed. Search scans every entity until a type
5239
+ * is marked ready. Runs as one invocation per entity type, each handing the
5240
+ * rest of its type to a new invocation when it runs low on time. Rows are
5241
+ * only listed here: each entity is read again before its rows are written.
5242
+ *
5243
+ * A page that fails is retried by a new invocation from the same page. Once
5244
+ * it has failed MAX_FAILURES times in a row the invocation throws, so the
5245
+ * function's error alarm fires; the type keeps scanning until a forced start
5246
+ * or a config change rebuilds it.
5247
+ */
5248
+ declare const handler$1: (container: DependencyContainer, invoke?: (event: SearchReindexEvent) => Promise<void>, pause?: (ms: number) => Promise<unknown>) => (event: SearchReindexEvent, context?: Pick<Context, "getRemainingTimeInMillis">) => Promise<void>;
5249
+
5163
5250
  declare const handler: (container: DependencyContainer) => (ev: SQSEvent) => Promise<{
5164
5251
  batchItemFailures: SQSBatchItemFailure[];
5165
5252
  }>;
@@ -5252,12 +5339,13 @@ declare module 'hono' {
5252
5339
  declare class CoreFactory {
5253
5340
  private config;
5254
5341
  setupCommonRoutes: ReturnType<typeof setupCommonRoutes>;
5255
- mutualProcessor: ReturnType<typeof handler$3>;
5256
- replicationProcessor: ReturnType<typeof handler$1>;
5257
- createEntityProcessor: ReturnType<typeof handler$9>;
5258
- analyticsProcessor: ReturnType<typeof handler$8>;
5259
- analyticsBackfillProcessor: ReturnType<typeof handler$7>;
5260
- prejoinProcessor: ReturnType<typeof handler$2>;
5342
+ mutualProcessor: ReturnType<typeof handler$4>;
5343
+ replicationProcessor: ReturnType<typeof handler$2>;
5344
+ searchReindexProcessor: ReturnType<typeof handler$1>;
5345
+ createEntityProcessor: ReturnType<typeof handler$a>;
5346
+ analyticsProcessor: ReturnType<typeof handler$9>;
5347
+ analyticsBackfillProcessor: ReturnType<typeof handler$8>;
5348
+ prejoinProcessor: ReturnType<typeof handler$3>;
5261
5349
  tagProcessor: ReturnType<typeof handler>;
5262
5350
  appHandler: ReturnType<typeof appHandler>;
5263
5351
  wsConnect: ReturnType<typeof connect>;
@@ -5270,7 +5358,8 @@ declare class CoreFactory {
5270
5358
  AllowedEntityTypes: Entity$2[];
5271
5359
  EmailAuthEnabledEntities: Entity$2[];
5272
5360
  ApiKeyPolicies?: ApiKeyPolicies;
5361
+ SearchDefaults?: SearchSettings;
5273
5362
  });
5274
5363
  }
5275
5364
 
5276
- export { type ApiKeyPrincipal, DependencyContainer, Entity$1 as Entity, type EntityAction, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, StandardError, StandardErrorCode, TagRepository, TransactionService, WebSocketRepository, handler$7 as analyticsBackfillProcessor, handler$6 as analyticsMaterializationProcessor, handler$5 as analyticsModelProcessor, handler$8 as analyticsProcessor, analyticsQueryHandler, handler$4 as analyticsViewProcessor, appHandler, handler$9 as createEntityProcessor, CoreFactory as default, handler$3 as mutualProcessor, handler$2 as prejoinProcessor, handler$1 as replicationProcessor, requires, setupCommonRoutes, startBackfill as startAnalyticsBackfill, handler as tagProcessor, transactional, broadcast as wsBroadcast, connect as wsConnect, $default as wsDefault, disconnect as wsDisconnect };
5365
+ export { type ApiKeyPrincipal, DependencyContainer, Entity$1 as Entity, type EntityAction, EntityRepository, EntityService, Mutual, MutualRepository, MutualService, PROJECTION_EXPRESSION, SearchRepository, StandardError, StandardErrorCode, TagRepository, TransactionService, WebSocketRepository, handler$8 as analyticsBackfillProcessor, handler$7 as analyticsMaterializationProcessor, handler$6 as analyticsModelProcessor, handler$9 as analyticsProcessor, analyticsQueryHandler, handler$5 as analyticsViewProcessor, appHandler, handler$a as createEntityProcessor, CoreFactory as default, handler$4 as mutualProcessor, handler$3 as prejoinProcessor, handler$2 as replicationProcessor, requires, handler$1 as searchReindexProcessor, setupCommonRoutes, startBackfill as startAnalyticsBackfill, handler as tagProcessor, transactional, broadcast as wsBroadcast, connect as wsConnect, $default as wsDefault, disconnect as wsDisconnect };