@jaypie/dynamodb 0.1.3 → 0.2.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/dist/cjs/constants.d.ts +1 -4
- package/dist/cjs/entities.d.ts +8 -8
- package/dist/cjs/index.cjs +235 -53
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +4 -2
- package/dist/cjs/keyBuilders.d.ts +17 -2
- package/dist/cjs/mcp/index.cjs +119 -93
- package/dist/cjs/mcp/index.cjs.map +1 -1
- package/dist/cjs/queries.d.ts +6 -6
- package/dist/cjs/query.d.ts +58 -0
- package/dist/cjs/seedExport.d.ts +5 -5
- package/dist/cjs/types.d.ts +9 -11
- package/dist/esm/constants.d.ts +1 -4
- package/dist/esm/entities.d.ts +8 -8
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +204 -39
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/keyBuilders.d.ts +17 -2
- package/dist/esm/mcp/index.js +109 -83
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/queries.d.ts +6 -6
- package/dist/esm/query.d.ts +58 -0
- package/dist/esm/seedExport.d.ts +5 -5
- package/dist/esm/types.d.ts +9 -11
- package/package.json +2 -2
package/dist/esm/queries.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseQueryOptions,
|
|
1
|
+
import type { BaseQueryOptions, StorableEntity, QueryResult } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Query parameters for queryByOu
|
|
4
4
|
*/
|
|
@@ -13,12 +13,12 @@ interface QueryByOuParams extends BaseQueryOptions {
|
|
|
13
13
|
* Note: This is a regular async function (not serviceHandler) because it accepts
|
|
14
14
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
15
15
|
*/
|
|
16
|
-
export declare function queryByOu({ archived, ascending, deleted, limit, model, ou, startKey, }: QueryByOuParams): Promise<QueryResult<
|
|
16
|
+
export declare function queryByOu({ archived, ascending, deleted, limit, model, ou, startKey, }: QueryByOuParams): Promise<QueryResult<StorableEntity>>;
|
|
17
17
|
/**
|
|
18
18
|
* Query a single entity by human-friendly alias
|
|
19
19
|
* Uses indexAlias GSI
|
|
20
20
|
*/
|
|
21
|
-
export declare const queryByAlias: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>,
|
|
21
|
+
export declare const queryByAlias: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>, StorableEntity | null>;
|
|
22
22
|
/**
|
|
23
23
|
* Query parameters for queryByClass
|
|
24
24
|
*/
|
|
@@ -34,7 +34,7 @@ interface QueryByClassParams extends BaseQueryOptions {
|
|
|
34
34
|
* Note: This is a regular async function (not serviceHandler) because it accepts
|
|
35
35
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
36
36
|
*/
|
|
37
|
-
export declare function queryByClass({ archived, ascending, deleted, limit, model, ou, recordClass, startKey, }: QueryByClassParams): Promise<QueryResult<
|
|
37
|
+
export declare function queryByClass({ archived, ascending, deleted, limit, model, ou, recordClass, startKey, }: QueryByClassParams): Promise<QueryResult<StorableEntity>>;
|
|
38
38
|
/**
|
|
39
39
|
* Query parameters for queryByType
|
|
40
40
|
*/
|
|
@@ -50,10 +50,10 @@ interface QueryByTypeParams extends BaseQueryOptions {
|
|
|
50
50
|
* Note: This is a regular async function (not serviceHandler) because it accepts
|
|
51
51
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
52
52
|
*/
|
|
53
|
-
export declare function queryByType({ archived, ascending, deleted, limit, model, ou, startKey, type, }: QueryByTypeParams): Promise<QueryResult<
|
|
53
|
+
export declare function queryByType({ archived, ascending, deleted, limit, model, ou, startKey, type, }: QueryByTypeParams): Promise<QueryResult<StorableEntity>>;
|
|
54
54
|
/**
|
|
55
55
|
* Query a single entity by external ID
|
|
56
56
|
* Uses indexXid GSI
|
|
57
57
|
*/
|
|
58
|
-
export declare const queryByXid: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>,
|
|
58
|
+
export declare const queryByXid: import("@jaypie/vocabulary").ServiceHandlerFunction<Record<string, unknown>, StorableEntity | null>;
|
|
59
59
|
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Query Function with Auto-Detect Index Selection
|
|
3
|
+
*
|
|
4
|
+
* The query() function automatically selects the best index based on
|
|
5
|
+
* the filter fields provided. This simplifies query construction by
|
|
6
|
+
* removing the need to know which specific GSI to use.
|
|
7
|
+
*/
|
|
8
|
+
import { DEFAULT_INDEXES, getModelIndexes } from "@jaypie/vocabulary";
|
|
9
|
+
import type { QueryResult, StorableEntity } from "./types.js";
|
|
10
|
+
/**
|
|
11
|
+
* Query parameters for the unified query function
|
|
12
|
+
*/
|
|
13
|
+
export interface QueryParams<T = StorableEntity> {
|
|
14
|
+
/** Whether to query archived entities instead of active ones */
|
|
15
|
+
archived?: boolean;
|
|
16
|
+
/** Whether to sort ascending (oldest first). Default: false */
|
|
17
|
+
ascending?: boolean;
|
|
18
|
+
/** Whether to query deleted entities instead of active ones */
|
|
19
|
+
deleted?: boolean;
|
|
20
|
+
/** Filter object with field values to match. Used for index auto-detection. */
|
|
21
|
+
filter?: Partial<T>;
|
|
22
|
+
/** Maximum number of items to return */
|
|
23
|
+
limit?: number;
|
|
24
|
+
/** Model name (required) */
|
|
25
|
+
model: string;
|
|
26
|
+
/** Organizational unit (APEX or "{parent.model}#{parent.id}") */
|
|
27
|
+
ou?: string;
|
|
28
|
+
/** Pagination cursor from previous query */
|
|
29
|
+
startKey?: Record<string, unknown>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Query entities with automatic index selection
|
|
33
|
+
*
|
|
34
|
+
* The query function automatically selects the best GSI based on
|
|
35
|
+
* the filter fields provided. This removes the need to know which
|
|
36
|
+
* specific query function (queryByOu, queryByAlias, etc.) to use.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Uses indexOu (pk: ["ou", "model"])
|
|
40
|
+
* const allMessages = await query({ model: "message", ou: `chat#${chatId}` });
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* // Uses indexAlias (pk: ["ou", "model", "alias"])
|
|
44
|
+
* const byAlias = await query({
|
|
45
|
+
* model: "record",
|
|
46
|
+
* ou: "@",
|
|
47
|
+
* filter: { alias: "my-record" },
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Uses a custom registered index if model has one
|
|
52
|
+
* const byChat = await query({
|
|
53
|
+
* model: "message",
|
|
54
|
+
* filter: { chatId: "abc-123" },
|
|
55
|
+
* });
|
|
56
|
+
*/
|
|
57
|
+
export declare function query<T extends StorableEntity = StorableEntity>(params: QueryParams<T>): Promise<QueryResult<T>>;
|
|
58
|
+
export { DEFAULT_INDEXES, getModelIndexes };
|
package/dist/esm/seedExport.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { StorableEntity } from "./types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Result of a seed operation
|
|
4
4
|
*/
|
|
@@ -25,7 +25,7 @@ export interface SeedOptions {
|
|
|
25
25
|
/**
|
|
26
26
|
* Result of an export operation
|
|
27
27
|
*/
|
|
28
|
-
export interface ExportResult<T extends
|
|
28
|
+
export interface ExportResult<T extends StorableEntity = StorableEntity> {
|
|
29
29
|
/** Number of entities exported */
|
|
30
30
|
count: number;
|
|
31
31
|
/** Exported entities */
|
|
@@ -37,7 +37,7 @@ export interface ExportResult<T extends FabricEntity = FabricEntity> {
|
|
|
37
37
|
* @param entity - Partial entity with at least alias, model, and ou
|
|
38
38
|
* @returns true if entity was created, false if it already exists
|
|
39
39
|
*/
|
|
40
|
-
export declare function seedEntityIfNotExists<T extends Partial<
|
|
40
|
+
export declare function seedEntityIfNotExists<T extends Partial<StorableEntity>>(entity: T): Promise<boolean>;
|
|
41
41
|
/**
|
|
42
42
|
* Seed multiple entities (idempotent)
|
|
43
43
|
*
|
|
@@ -50,7 +50,7 @@ export declare function seedEntityIfNotExists<T extends Partial<FabricEntity>>(e
|
|
|
50
50
|
* @param options - Seed options
|
|
51
51
|
* @returns Result with created, skipped, and errors arrays
|
|
52
52
|
*/
|
|
53
|
-
export declare function seedEntities<T extends Partial<
|
|
53
|
+
export declare function seedEntities<T extends Partial<StorableEntity>>(entities: T[], options?: SeedOptions): Promise<SeedResult>;
|
|
54
54
|
/**
|
|
55
55
|
* Export entities by model and organizational unit
|
|
56
56
|
*
|
|
@@ -62,7 +62,7 @@ export declare function seedEntities<T extends Partial<FabricEntity>>(entities:
|
|
|
62
62
|
* @param limit - Optional maximum number of entities to export
|
|
63
63
|
* @returns Export result with entities and count
|
|
64
64
|
*/
|
|
65
|
-
export declare function exportEntities<T extends
|
|
65
|
+
export declare function exportEntities<T extends StorableEntity>(model: string, ou: string, limit?: number): Promise<ExportResult<T>>;
|
|
66
66
|
/**
|
|
67
67
|
* Export entities as a JSON string
|
|
68
68
|
*
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BaseEntity } from "@jaypie/vocabulary";
|
|
1
2
|
/**
|
|
2
3
|
* DynamoDB client configuration
|
|
3
4
|
*/
|
|
@@ -100,16 +101,21 @@ export interface QueryByXidParams {
|
|
|
100
101
|
/**
|
|
101
102
|
* Result of a query operation
|
|
102
103
|
*/
|
|
103
|
-
export interface QueryResult<T =
|
|
104
|
+
export interface QueryResult<T = StorableEntity> {
|
|
104
105
|
/** Array of matching entities */
|
|
105
106
|
items: T[];
|
|
106
107
|
/** Pagination cursor for next page (undefined if no more results) */
|
|
107
108
|
lastEvaluatedKey?: Record<string, unknown>;
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
|
-
*
|
|
111
|
+
* Entity with required fields for DynamoDB storage.
|
|
112
|
+
*
|
|
113
|
+
* Extends BaseEntity from @jaypie/vocabulary with:
|
|
114
|
+
* - Required storage fields (id, model, name, ou, sequence)
|
|
115
|
+
* - String timestamps (DynamoDB uses ISO 8601 strings, not Date objects)
|
|
116
|
+
* - GSI index keys (auto-populated by indexEntity)
|
|
111
117
|
*/
|
|
112
|
-
export interface
|
|
118
|
+
export interface StorableEntity extends Omit<BaseEntity, "archivedAt" | "createdAt" | "deletedAt" | "updatedAt"> {
|
|
113
119
|
/** Partition key (e.g., "record", "message") */
|
|
114
120
|
model: string;
|
|
115
121
|
/** Sort key (UUID) */
|
|
@@ -125,14 +131,6 @@ export interface FabricEntity {
|
|
|
125
131
|
indexOu?: string;
|
|
126
132
|
indexType?: string;
|
|
127
133
|
indexXid?: string;
|
|
128
|
-
/** Human-friendly slug/alias */
|
|
129
|
-
alias?: string;
|
|
130
|
-
/** Category classification */
|
|
131
|
-
class?: string;
|
|
132
|
-
/** Type classification */
|
|
133
|
-
type?: string;
|
|
134
|
-
/** External ID for integration with external systems */
|
|
135
|
-
xid?: string;
|
|
136
134
|
createdAt: string;
|
|
137
135
|
updatedAt: string;
|
|
138
136
|
/** Archive timestamp (for inactive but preserved records) */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/dynamodb",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/finlaysonstudio/jaypie.git"
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@aws-sdk/client-dynamodb": "^3.726.1",
|
|
43
43
|
"@aws-sdk/lib-dynamodb": "^3.726.1",
|
|
44
|
-
"@jaypie/vocabulary": "^0.
|
|
44
|
+
"@jaypie/vocabulary": "^0.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@rollup/plugin-typescript": "^12.1.2",
|