@jaypie/dynamodb 0.4.4 → 0.5.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.
@@ -34,6 +34,12 @@ export interface BaseQueryOptions {
34
34
  deleted?: boolean;
35
35
  /** Maximum number of items to return */
36
36
  limit?: number;
37
+ /**
38
+ * Optional scope narrower. Passing a scope restricts the query via
39
+ * `begins_with` on the GSI sort key (scope + updatedAt). Omitting it
40
+ * lists every entity of the model across scopes.
41
+ */
42
+ scope?: string;
37
43
  /** Pagination cursor from previous query */
38
44
  startKey?: Record<string, unknown>;
39
45
  }
@@ -43,23 +49,15 @@ export interface BaseQueryOptions {
43
49
  export interface QueryByScopeParams extends BaseQueryOptions {
44
50
  /** The entity model name */
45
51
  model: string;
46
- /** The scope (APEX or "{parent.model}#{parent.id}") */
47
- scope: string;
48
52
  }
49
53
  /**
50
54
  * Parameters for queryByAlias
51
55
  */
52
- export interface QueryByAliasParams {
56
+ export interface QueryByAliasParams extends BaseQueryOptions {
53
57
  /** The human-friendly alias */
54
58
  alias: string;
55
- /** Query archived entities instead of active ones */
56
- archived?: boolean;
57
- /** Query deleted entities instead of active ones */
58
- deleted?: boolean;
59
59
  /** The entity model name */
60
60
  model: string;
61
- /** The scope */
62
- scope: string;
63
61
  }
64
62
  /**
65
63
  * Parameters for queryByCategory
@@ -69,8 +67,6 @@ export interface QueryByCategoryParams extends BaseQueryOptions {
69
67
  category: string;
70
68
  /** The entity model name */
71
69
  model: string;
72
- /** The scope */
73
- scope: string;
74
70
  }
75
71
  /**
76
72
  * Parameters for queryByType
@@ -78,23 +74,15 @@ export interface QueryByCategoryParams extends BaseQueryOptions {
78
74
  export interface QueryByTypeParams extends BaseQueryOptions {
79
75
  /** The entity model name */
80
76
  model: string;
81
- /** The scope */
82
- scope: string;
83
77
  /** The type classification */
84
78
  type: string;
85
79
  }
86
80
  /**
87
81
  * Parameters for queryByXid
88
82
  */
89
- export interface QueryByXidParams {
90
- /** Query archived entities instead of active ones */
91
- archived?: boolean;
92
- /** Query deleted entities instead of active ones */
93
- deleted?: boolean;
83
+ export interface QueryByXidParams extends BaseQueryOptions {
94
84
  /** The entity model name */
95
85
  model: string;
96
- /** The scope */
97
- scope: string;
98
86
  /** The external ID */
99
87
  xid: string;
100
88
  }
@@ -108,37 +96,34 @@ export interface QueryResult<T = StorableEntity> {
108
96
  lastEvaluatedKey?: Record<string, unknown>;
109
97
  }
110
98
  /**
111
- * Entity with required fields for DynamoDB storage.
99
+ * Entity stored in DynamoDB.
100
+ *
101
+ * Primary key is `id` only (no sort key). `model` and `scope` are regular
102
+ * attributes; GSI attribute values (e.g., `indexModel`, `indexModelAlias`,
103
+ * `indexModelSk`) are auto-populated by `indexEntity` on every write.
112
104
  *
113
- * Extends FabricModel from @jaypie/fabric with:
114
- * - Required storage fields (id, model, name, scope, sequence)
115
- * - String timestamps (DynamoDB uses ISO 8601 strings, not Date objects)
116
- * - GSI index keys (auto-populated by indexEntity)
105
+ * `createdAt` and `updatedAt` are both ISO 8601 strings. `updatedAt` is
106
+ * managed by `indexEntity` on every write; callers never set it manually.
117
107
  */
118
108
  export interface StorableEntity extends Omit<FabricModel, "archivedAt" | "createdAt" | "deletedAt" | "updatedAt"> {
119
- /** Partition key (e.g., "record", "message") */
120
- model: string;
121
- /** Sort key (UUID) */
109
+ /** Primary key (UUID) */
122
110
  id: string;
111
+ /** Entity model name (e.g., "record", "message") */
112
+ model: string;
123
113
  /** Human-readable name */
124
- name: string;
114
+ name?: string;
125
115
  /** Scope: APEX ("@") or "{parent.model}#{parent.id}" */
126
116
  scope: string;
127
- /** Timestamp for chronological ordering (Date.now()) */
128
- sequence: number;
129
- indexAlias?: string;
130
- indexCategory?: string;
131
- indexScope?: string;
132
- indexType?: string;
133
- indexXid?: string;
134
- createdAt: string;
135
- updatedAt: string;
136
- /** Archive timestamp (for inactive but preserved records) */
117
+ /** Creation timestamp (ISO 8601). Backfilled by indexEntity if missing. */
118
+ createdAt?: string;
119
+ /** Last-write timestamp (ISO 8601). Managed by indexEntity on every write. */
120
+ updatedAt?: string;
121
+ /** Archive timestamp — presence drives #archived suffix on GSI pk */
137
122
  archivedAt?: string;
138
- /** Soft-delete timestamp */
123
+ /** Soft-delete timestamp — presence drives #deleted suffix on GSI pk */
139
124
  deletedAt?: string;
140
125
  /** Application-specific state flags */
141
126
  state?: Record<string, unknown>;
142
- /** Allow additional properties for downstream entity extensions */
127
+ /** Allow additional properties (including dynamically named GSI attrs) */
143
128
  [key: string]: unknown;
144
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/dynamodb",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/finlaysonstudio/jaypie.git"