@jaypie/dynamodb 0.2.0 → 0.3.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 +2 -2
- package/dist/cjs/entities.d.ts +6 -6
- package/dist/cjs/index.cjs +112 -106
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +3 -3
- package/dist/cjs/keyBuilders.d.ts +21 -21
- package/dist/cjs/mcp/admin/createTable.d.ts +1 -1
- package/dist/cjs/mcp/admin/dockerCompose.d.ts +1 -1
- package/dist/cjs/mcp/admin/status.d.ts +1 -1
- package/dist/cjs/mcp/index.cjs +143 -121
- package/dist/cjs/mcp/index.cjs.map +1 -1
- package/dist/cjs/queries.d.ts +15 -15
- package/dist/cjs/query.d.ts +7 -7
- package/dist/cjs/seedExport.d.ts +7 -7
- package/dist/cjs/types.d.ts +20 -20
- package/dist/esm/constants.d.ts +2 -2
- package/dist/esm/entities.d.ts +6 -6
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +91 -85
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/keyBuilders.d.ts +21 -21
- package/dist/esm/mcp/admin/createTable.d.ts +1 -1
- package/dist/esm/mcp/admin/dockerCompose.d.ts +1 -1
- package/dist/esm/mcp/admin/status.d.ts +1 -1
- package/dist/esm/mcp/index.js +133 -111
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/queries.d.ts +15 -15
- package/dist/esm/query.d.ts +7 -7
- package/dist/esm/seedExport.d.ts +7 -7
- package/dist/esm/types.d.ts +20 -20
- package/package.json +2 -2
package/dist/esm/entities.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type { StorableEntity } from "./types.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Get a single entity by primary key
|
|
4
4
|
*/
|
|
5
|
-
export declare const getEntity: import("@jaypie/
|
|
5
|
+
export declare const getEntity: import("@jaypie/fabric").Service<Record<string, unknown>, StorableEntity | null>;
|
|
6
6
|
/**
|
|
7
7
|
* Put (create or replace) an entity
|
|
8
8
|
* Auto-populates GSI index keys via indexEntity
|
|
9
9
|
*
|
|
10
|
-
* Note: This is a regular async function (not
|
|
10
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
11
11
|
* complex StorableEntity objects that can't be coerced by vocabulary's type system.
|
|
12
12
|
*/
|
|
13
13
|
export declare function putEntity({ entity, }: {
|
|
@@ -17,7 +17,7 @@ export declare function putEntity({ entity, }: {
|
|
|
17
17
|
* Update an existing entity
|
|
18
18
|
* Auto-populates GSI index keys and sets updatedAt
|
|
19
19
|
*
|
|
20
|
-
* Note: This is a regular async function (not
|
|
20
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
21
21
|
* complex StorableEntity objects that can't be coerced by vocabulary's type system.
|
|
22
22
|
*/
|
|
23
23
|
export declare function updateEntity({ entity, }: {
|
|
@@ -27,14 +27,14 @@ export declare function updateEntity({ entity, }: {
|
|
|
27
27
|
* Soft delete an entity by setting deletedAt timestamp
|
|
28
28
|
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
29
29
|
*/
|
|
30
|
-
export declare const deleteEntity: import("@jaypie/
|
|
30
|
+
export declare const deleteEntity: import("@jaypie/fabric").Service<Record<string, unknown>, boolean>;
|
|
31
31
|
/**
|
|
32
32
|
* Archive an entity by setting archivedAt timestamp
|
|
33
33
|
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
34
34
|
*/
|
|
35
|
-
export declare const archiveEntity: import("@jaypie/
|
|
35
|
+
export declare const archiveEntity: import("@jaypie/fabric").Service<Record<string, unknown>, boolean>;
|
|
36
36
|
/**
|
|
37
37
|
* Hard delete an entity (permanently removes from table)
|
|
38
38
|
* Use with caution - prefer deleteEntity for soft delete
|
|
39
39
|
*/
|
|
40
|
-
export declare const destroyEntity: import("@jaypie/
|
|
40
|
+
export declare const destroyEntity: import("@jaypie/fabric").Service<Record<string, unknown>, boolean>;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { getDocClient, getTableName, initClient, isInitialized, resetClient, } from "./client.js";
|
|
2
|
-
export { APEX, ARCHIVED_SUFFIX, DELETED_SUFFIX, INDEX_ALIAS, INDEX_CLASS,
|
|
2
|
+
export { APEX, ARCHIVED_SUFFIX, DELETED_SUFFIX, INDEX_ALIAS, INDEX_CLASS, INDEX_SCOPE, INDEX_TYPE, INDEX_XID, SEPARATOR, } from "./constants.js";
|
|
3
3
|
export { archiveEntity, deleteEntity, destroyEntity, getEntity, putEntity, updateEntity, } from "./entities.js";
|
|
4
|
-
export { buildCompositeKey, buildIndexAlias, buildIndexClass,
|
|
5
|
-
export { queryByAlias, queryByClass,
|
|
4
|
+
export { buildCompositeKey, buildIndexAlias, buildIndexClass, buildIndexScope, buildIndexType, buildIndexXid, calculateScope, DEFAULT_INDEXES, indexEntity, } from "./keyBuilders.js";
|
|
5
|
+
export { queryByAlias, queryByClass, queryByScope, queryByType, queryByXid, } from "./queries.js";
|
|
6
6
|
export { query } from "./query.js";
|
|
7
7
|
export type { QueryParams } from "./query.js";
|
|
8
8
|
export { exportEntities, exportEntitiesToJson, seedEntities, seedEntityIfNotExists, } from "./seedExport.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
2
2
|
import { DynamoDBDocumentClient, GetCommand, PutCommand, DeleteCommand, QueryCommand } from '@aws-sdk/lib-dynamodb';
|
|
3
3
|
import { ConfigurationError } from '@jaypie/errors';
|
|
4
|
-
import { getModelIndexes, populateIndexKeys, SEPARATOR, buildCompositeKey as buildCompositeKey$1, APEX,
|
|
5
|
-
export { APEX, ARCHIVED_SUFFIX, DEFAULT_INDEXES, DELETED_SUFFIX, SEPARATOR } from '@jaypie/
|
|
4
|
+
import { getModelIndexes, populateIndexKeys, SEPARATOR, buildCompositeKey as buildCompositeKey$1, APEX, calculateScope as calculateScope$1, fabricService, ARCHIVED_SUFFIX, DELETED_SUFFIX } from '@jaypie/fabric';
|
|
5
|
+
export { APEX, ARCHIVED_SUFFIX, DEFAULT_INDEXES, DELETED_SUFFIX, SEPARATOR } from '@jaypie/fabric';
|
|
6
6
|
|
|
7
7
|
// Environment variable names
|
|
8
8
|
const ENV_AWS_REGION = "AWS_REGION";
|
|
@@ -82,11 +82,11 @@ function resetClient() {
|
|
|
82
82
|
tableName = null;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// Re-export shared constants from
|
|
85
|
+
// Re-export shared constants from fabric
|
|
86
86
|
// GSI names (derived from DEFAULT_INDEXES)
|
|
87
87
|
const INDEX_ALIAS = "indexAlias";
|
|
88
88
|
const INDEX_CLASS = "indexClass";
|
|
89
|
-
const
|
|
89
|
+
const INDEX_SCOPE = "indexScope";
|
|
90
90
|
const INDEX_TYPE = "indexType";
|
|
91
91
|
const INDEX_XID = "indexXid";
|
|
92
92
|
|
|
@@ -94,53 +94,53 @@ const INDEX_XID = "indexXid";
|
|
|
94
94
|
// Key Builders
|
|
95
95
|
// =============================================================================
|
|
96
96
|
/**
|
|
97
|
-
* Build the
|
|
98
|
-
* @param
|
|
97
|
+
* Build the indexScope key for hierarchical queries
|
|
98
|
+
* @param scope - The scope (APEX or "{parent.model}#{parent.id}")
|
|
99
99
|
* @param model - The entity model name
|
|
100
|
-
* @returns Composite key: "{
|
|
100
|
+
* @returns Composite key: "{scope}#{model}"
|
|
101
101
|
*/
|
|
102
|
-
function
|
|
103
|
-
return `${
|
|
102
|
+
function buildIndexScope(scope, model) {
|
|
103
|
+
return `${scope}${SEPARATOR}${model}`;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Build the indexAlias key for human-friendly lookups
|
|
107
|
-
* @param
|
|
107
|
+
* @param scope - The scope
|
|
108
108
|
* @param model - The entity model name
|
|
109
109
|
* @param alias - The human-friendly alias
|
|
110
|
-
* @returns Composite key: "{
|
|
110
|
+
* @returns Composite key: "{scope}#{model}#{alias}"
|
|
111
111
|
*/
|
|
112
|
-
function buildIndexAlias(
|
|
113
|
-
return `${
|
|
112
|
+
function buildIndexAlias(scope, model, alias) {
|
|
113
|
+
return `${scope}${SEPARATOR}${model}${SEPARATOR}${alias}`;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
116
|
* Build the indexClass key for category filtering
|
|
117
|
-
* @param
|
|
117
|
+
* @param scope - The scope
|
|
118
118
|
* @param model - The entity model name
|
|
119
119
|
* @param recordClass - The category classification
|
|
120
|
-
* @returns Composite key: "{
|
|
120
|
+
* @returns Composite key: "{scope}#{model}#{class}"
|
|
121
121
|
*/
|
|
122
|
-
function buildIndexClass(
|
|
123
|
-
return `${
|
|
122
|
+
function buildIndexClass(scope, model, recordClass) {
|
|
123
|
+
return `${scope}${SEPARATOR}${model}${SEPARATOR}${recordClass}`;
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
126
|
* Build the indexType key for type filtering
|
|
127
|
-
* @param
|
|
127
|
+
* @param scope - The scope
|
|
128
128
|
* @param model - The entity model name
|
|
129
129
|
* @param type - The type classification
|
|
130
|
-
* @returns Composite key: "{
|
|
130
|
+
* @returns Composite key: "{scope}#{model}#{type}"
|
|
131
131
|
*/
|
|
132
|
-
function buildIndexType(
|
|
133
|
-
return `${
|
|
132
|
+
function buildIndexType(scope, model, type) {
|
|
133
|
+
return `${scope}${SEPARATOR}${model}${SEPARATOR}${type}`;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Build the indexXid key for external ID lookups
|
|
137
|
-
* @param
|
|
137
|
+
* @param scope - The scope
|
|
138
138
|
* @param model - The entity model name
|
|
139
139
|
* @param xid - The external ID
|
|
140
|
-
* @returns Composite key: "{
|
|
140
|
+
* @returns Composite key: "{scope}#{model}#{xid}"
|
|
141
141
|
*/
|
|
142
|
-
function buildIndexXid(
|
|
143
|
-
return `${
|
|
142
|
+
function buildIndexXid(scope, model, xid) {
|
|
143
|
+
return `${scope}${SEPARATOR}${model}${SEPARATOR}${xid}`;
|
|
144
144
|
}
|
|
145
145
|
// =============================================================================
|
|
146
146
|
// New Vocabulary-Based Functions
|
|
@@ -157,15 +157,15 @@ function buildCompositeKey(entity, fields, suffix) {
|
|
|
157
157
|
return buildCompositeKey$1(entity, fields, suffix);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
* Calculate the
|
|
160
|
+
* Calculate the scope from a parent reference
|
|
161
161
|
* @param parent - Optional parent entity reference
|
|
162
162
|
* @returns APEX ("@") if no parent, otherwise "{parent.model}#{parent.id}"
|
|
163
163
|
*/
|
|
164
|
-
function
|
|
164
|
+
function calculateScope(parent) {
|
|
165
165
|
if (!parent) {
|
|
166
166
|
return APEX;
|
|
167
167
|
}
|
|
168
|
-
return
|
|
168
|
+
return calculateScope$1(parent);
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Auto-populate GSI index keys on an entity
|
|
@@ -173,7 +173,7 @@ function calculateOu(parent) {
|
|
|
173
173
|
* Uses the model's registered indexes (from vocabulary registry) or
|
|
174
174
|
* DEFAULT_INDEXES if no custom indexes are registered.
|
|
175
175
|
*
|
|
176
|
-
* -
|
|
176
|
+
* - indexScope is always populated from scope + model
|
|
177
177
|
* - indexAlias is populated only when alias is present
|
|
178
178
|
* - indexClass is populated only when class is present
|
|
179
179
|
* - indexType is populated only when type is present
|
|
@@ -185,7 +185,7 @@ function calculateOu(parent) {
|
|
|
185
185
|
*/
|
|
186
186
|
function indexEntity(entity, suffix = "") {
|
|
187
187
|
const indexes = getModelIndexes(entity.model);
|
|
188
|
-
// Cast through unknown to bridge the type gap between StorableEntity and
|
|
188
|
+
// Cast through unknown to bridge the type gap between StorableEntity and IndexableModel
|
|
189
189
|
return populateIndexKeys(entity, indexes, suffix);
|
|
190
190
|
}
|
|
191
191
|
|
|
@@ -209,7 +209,7 @@ function calculateEntitySuffix(entity) {
|
|
|
209
209
|
/**
|
|
210
210
|
* Get a single entity by primary key
|
|
211
211
|
*/
|
|
212
|
-
const getEntity =
|
|
212
|
+
const getEntity = fabricService({
|
|
213
213
|
alias: "getEntity",
|
|
214
214
|
description: "Get a single entity by primary key",
|
|
215
215
|
input: {
|
|
@@ -231,7 +231,7 @@ const getEntity = serviceHandler({
|
|
|
231
231
|
* Put (create or replace) an entity
|
|
232
232
|
* Auto-populates GSI index keys via indexEntity
|
|
233
233
|
*
|
|
234
|
-
* Note: This is a regular async function (not
|
|
234
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
235
235
|
* complex StorableEntity objects that can't be coerced by vocabulary's type system.
|
|
236
236
|
*/
|
|
237
237
|
async function putEntity({ entity, }) {
|
|
@@ -250,7 +250,7 @@ async function putEntity({ entity, }) {
|
|
|
250
250
|
* Update an existing entity
|
|
251
251
|
* Auto-populates GSI index keys and sets updatedAt
|
|
252
252
|
*
|
|
253
|
-
* Note: This is a regular async function (not
|
|
253
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
254
254
|
* complex StorableEntity objects that can't be coerced by vocabulary's type system.
|
|
255
255
|
*/
|
|
256
256
|
async function updateEntity({ entity, }) {
|
|
@@ -272,7 +272,7 @@ async function updateEntity({ entity, }) {
|
|
|
272
272
|
* Soft delete an entity by setting deletedAt timestamp
|
|
273
273
|
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
274
274
|
*/
|
|
275
|
-
const deleteEntity =
|
|
275
|
+
const deleteEntity = fabricService({
|
|
276
276
|
alias: "deleteEntity",
|
|
277
277
|
description: "Soft delete an entity (sets deletedAt timestamp)",
|
|
278
278
|
input: {
|
|
@@ -309,7 +309,7 @@ const deleteEntity = serviceHandler({
|
|
|
309
309
|
* Archive an entity by setting archivedAt timestamp
|
|
310
310
|
* Re-indexes with appropriate suffix based on archived/deleted state
|
|
311
311
|
*/
|
|
312
|
-
const archiveEntity =
|
|
312
|
+
const archiveEntity = fabricService({
|
|
313
313
|
alias: "archiveEntity",
|
|
314
314
|
description: "Archive an entity (sets archivedAt timestamp)",
|
|
315
315
|
input: {
|
|
@@ -346,7 +346,7 @@ const archiveEntity = serviceHandler({
|
|
|
346
346
|
* Hard delete an entity (permanently removes from table)
|
|
347
347
|
* Use with caution - prefer deleteEntity for soft delete
|
|
348
348
|
*/
|
|
349
|
-
const destroyEntity =
|
|
349
|
+
const destroyEntity = fabricService({
|
|
350
350
|
alias: "destroyEntity",
|
|
351
351
|
description: "Hard delete an entity (permanently removes from table)",
|
|
352
352
|
input: {
|
|
@@ -409,16 +409,16 @@ async function executeQuery(indexName, keyValue, options = {}) {
|
|
|
409
409
|
};
|
|
410
410
|
}
|
|
411
411
|
/**
|
|
412
|
-
* Query entities by
|
|
413
|
-
* Uses
|
|
412
|
+
* Query entities by scope (parent hierarchy)
|
|
413
|
+
* Uses indexScope GSI
|
|
414
414
|
*
|
|
415
|
-
* Note: This is a regular async function (not
|
|
415
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
416
416
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
417
417
|
*/
|
|
418
|
-
async function
|
|
418
|
+
async function queryByScope({ archived = false, ascending = false, deleted = false, limit, model, scope, startKey, }) {
|
|
419
419
|
const suffix = calculateSuffix$1({ archived, deleted });
|
|
420
|
-
const keyValue =
|
|
421
|
-
return executeQuery(
|
|
420
|
+
const keyValue = buildIndexScope(scope, model) + suffix;
|
|
421
|
+
return executeQuery(INDEX_SCOPE, keyValue, {
|
|
422
422
|
ascending,
|
|
423
423
|
limit,
|
|
424
424
|
startKey,
|
|
@@ -428,7 +428,7 @@ async function queryByOu({ archived = false, ascending = false, deleted = false,
|
|
|
428
428
|
* Query a single entity by human-friendly alias
|
|
429
429
|
* Uses indexAlias GSI
|
|
430
430
|
*/
|
|
431
|
-
const queryByAlias =
|
|
431
|
+
const queryByAlias = fabricService({
|
|
432
432
|
alias: "queryByAlias",
|
|
433
433
|
description: "Query a single entity by human-friendly alias",
|
|
434
434
|
input: {
|
|
@@ -446,16 +446,19 @@ const queryByAlias = serviceHandler({
|
|
|
446
446
|
description: "Query deleted entities instead of active ones",
|
|
447
447
|
},
|
|
448
448
|
model: { type: String, description: "Entity model name" },
|
|
449
|
-
|
|
449
|
+
scope: { type: String, description: "Scope (@ for root)" },
|
|
450
450
|
},
|
|
451
|
-
service: async ({ alias, archived, deleted, model,
|
|
451
|
+
service: async ({ alias, archived, deleted, model, scope, }) => {
|
|
452
452
|
const aliasStr = alias;
|
|
453
453
|
const archivedBool = archived;
|
|
454
454
|
const deletedBool = deleted;
|
|
455
455
|
const modelStr = model;
|
|
456
|
-
const
|
|
457
|
-
const suffix = calculateSuffix$1({
|
|
458
|
-
|
|
456
|
+
const scopeStr = scope;
|
|
457
|
+
const suffix = calculateSuffix$1({
|
|
458
|
+
archived: archivedBool,
|
|
459
|
+
deleted: deletedBool,
|
|
460
|
+
});
|
|
461
|
+
const keyValue = buildIndexAlias(scopeStr, modelStr, aliasStr) + suffix;
|
|
459
462
|
const result = await executeQuery(INDEX_ALIAS, keyValue, {
|
|
460
463
|
limit: 1,
|
|
461
464
|
});
|
|
@@ -466,12 +469,12 @@ const queryByAlias = serviceHandler({
|
|
|
466
469
|
* Query entities by category classification
|
|
467
470
|
* Uses indexClass GSI
|
|
468
471
|
*
|
|
469
|
-
* Note: This is a regular async function (not
|
|
472
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
470
473
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
471
474
|
*/
|
|
472
|
-
async function queryByClass({ archived = false, ascending = false, deleted = false, limit, model,
|
|
475
|
+
async function queryByClass({ archived = false, ascending = false, deleted = false, limit, model, scope, recordClass, startKey, }) {
|
|
473
476
|
const suffix = calculateSuffix$1({ archived, deleted });
|
|
474
|
-
const keyValue = buildIndexClass(
|
|
477
|
+
const keyValue = buildIndexClass(scope, model, recordClass) + suffix;
|
|
475
478
|
return executeQuery(INDEX_CLASS, keyValue, {
|
|
476
479
|
ascending,
|
|
477
480
|
limit,
|
|
@@ -482,12 +485,12 @@ async function queryByClass({ archived = false, ascending = false, deleted = fal
|
|
|
482
485
|
* Query entities by type classification
|
|
483
486
|
* Uses indexType GSI
|
|
484
487
|
*
|
|
485
|
-
* Note: This is a regular async function (not
|
|
488
|
+
* Note: This is a regular async function (not fabricService) because it accepts
|
|
486
489
|
* complex startKey objects that can't be coerced by vocabulary's type system.
|
|
487
490
|
*/
|
|
488
|
-
async function queryByType({ archived = false, ascending = false, deleted = false, limit, model,
|
|
491
|
+
async function queryByType({ archived = false, ascending = false, deleted = false, limit, model, scope, startKey, type, }) {
|
|
489
492
|
const suffix = calculateSuffix$1({ archived, deleted });
|
|
490
|
-
const keyValue = buildIndexType(
|
|
493
|
+
const keyValue = buildIndexType(scope, model, type) + suffix;
|
|
491
494
|
return executeQuery(INDEX_TYPE, keyValue, {
|
|
492
495
|
ascending,
|
|
493
496
|
limit,
|
|
@@ -498,7 +501,7 @@ async function queryByType({ archived = false, ascending = false, deleted = fals
|
|
|
498
501
|
* Query a single entity by external ID
|
|
499
502
|
* Uses indexXid GSI
|
|
500
503
|
*/
|
|
501
|
-
const queryByXid =
|
|
504
|
+
const queryByXid = fabricService({
|
|
502
505
|
alias: "queryByXid",
|
|
503
506
|
description: "Query a single entity by external ID",
|
|
504
507
|
input: {
|
|
@@ -515,17 +518,20 @@ const queryByXid = serviceHandler({
|
|
|
515
518
|
description: "Query deleted entities instead of active ones",
|
|
516
519
|
},
|
|
517
520
|
model: { type: String, description: "Entity model name" },
|
|
518
|
-
|
|
521
|
+
scope: { type: String, description: "Scope (@ for root)" },
|
|
519
522
|
xid: { type: String, description: "External ID" },
|
|
520
523
|
},
|
|
521
|
-
service: async ({ archived, deleted, model,
|
|
524
|
+
service: async ({ archived, deleted, model, scope, xid, }) => {
|
|
522
525
|
const archivedBool = archived;
|
|
523
526
|
const deletedBool = deleted;
|
|
524
527
|
const modelStr = model;
|
|
525
|
-
const
|
|
528
|
+
const scopeStr = scope;
|
|
526
529
|
const xidStr = xid;
|
|
527
|
-
const suffix = calculateSuffix$1({
|
|
528
|
-
|
|
530
|
+
const suffix = calculateSuffix$1({
|
|
531
|
+
archived: archivedBool,
|
|
532
|
+
deleted: deletedBool,
|
|
533
|
+
});
|
|
534
|
+
const keyValue = buildIndexXid(scopeStr, modelStr, xidStr) + suffix;
|
|
529
535
|
const result = await executeQuery(INDEX_XID, keyValue, {
|
|
530
536
|
limit: 1,
|
|
531
537
|
});
|
|
@@ -565,8 +571,8 @@ function buildFilterObject(params) {
|
|
|
565
571
|
const result = {
|
|
566
572
|
model: params.model,
|
|
567
573
|
};
|
|
568
|
-
if (params.
|
|
569
|
-
result.
|
|
574
|
+
if (params.scope !== undefined) {
|
|
575
|
+
result.scope = params.scope;
|
|
570
576
|
}
|
|
571
577
|
if (params.filter) {
|
|
572
578
|
Object.assign(result, params.filter);
|
|
@@ -636,14 +642,14 @@ function selectBestIndex(indexes, filterFields) {
|
|
|
636
642
|
* specific query function (queryByOu, queryByAlias, etc.) to use.
|
|
637
643
|
*
|
|
638
644
|
* @example
|
|
639
|
-
* // Uses
|
|
640
|
-
* const allMessages = await query({ model: "message",
|
|
645
|
+
* // Uses indexScope (pk: ["scope", "model"])
|
|
646
|
+
* const allMessages = await query({ model: "message", scope: `chat#${chatId}` });
|
|
641
647
|
*
|
|
642
648
|
* @example
|
|
643
|
-
* // Uses indexAlias (pk: ["
|
|
649
|
+
* // Uses indexAlias (pk: ["scope", "model", "alias"])
|
|
644
650
|
* const byAlias = await query({
|
|
645
651
|
* model: "record",
|
|
646
|
-
*
|
|
652
|
+
* scope: "@",
|
|
647
653
|
* filter: { alias: "my-record" },
|
|
648
654
|
* });
|
|
649
655
|
*
|
|
@@ -702,18 +708,18 @@ function generateIndexName(pk) {
|
|
|
702
708
|
/**
|
|
703
709
|
* Seed a single entity if it doesn't already exist
|
|
704
710
|
*
|
|
705
|
-
* @param entity - Partial entity with at least alias, model, and
|
|
711
|
+
* @param entity - Partial entity with at least alias, model, and scope
|
|
706
712
|
* @returns true if entity was created, false if it already exists
|
|
707
713
|
*/
|
|
708
714
|
async function seedEntityIfNotExists(entity) {
|
|
709
|
-
if (!entity.alias || !entity.model || !entity.
|
|
710
|
-
throw new Error("Entity must have alias, model, and
|
|
715
|
+
if (!entity.alias || !entity.model || !entity.scope) {
|
|
716
|
+
throw new Error("Entity must have alias, model, and scope to check existence");
|
|
711
717
|
}
|
|
712
718
|
// Check if entity already exists
|
|
713
719
|
const existing = await queryByAlias({
|
|
714
720
|
alias: entity.alias,
|
|
715
721
|
model: entity.model,
|
|
716
|
-
|
|
722
|
+
scope: entity.scope,
|
|
717
723
|
});
|
|
718
724
|
if (existing) {
|
|
719
725
|
return false;
|
|
@@ -725,7 +731,7 @@ async function seedEntityIfNotExists(entity) {
|
|
|
725
731
|
id: entity.id ?? crypto.randomUUID(),
|
|
726
732
|
model: entity.model,
|
|
727
733
|
name: entity.name ?? entity.alias,
|
|
728
|
-
|
|
734
|
+
scope: entity.scope,
|
|
729
735
|
sequence: entity.sequence ?? Date.now(),
|
|
730
736
|
updatedAt: entity.updatedAt ?? now,
|
|
731
737
|
...entity,
|
|
@@ -755,15 +761,15 @@ async function seedEntities(entities, options = {}) {
|
|
|
755
761
|
for (const entity of entities) {
|
|
756
762
|
const alias = entity.alias ?? entity.name ?? "unknown";
|
|
757
763
|
try {
|
|
758
|
-
if (!entity.model || !entity.
|
|
759
|
-
throw new Error("Entity must have model and
|
|
764
|
+
if (!entity.model || !entity.scope) {
|
|
765
|
+
throw new Error("Entity must have model and scope");
|
|
760
766
|
}
|
|
761
767
|
// For entities with alias, check existence
|
|
762
768
|
if (entity.alias) {
|
|
763
769
|
const existing = await queryByAlias({
|
|
764
770
|
alias: entity.alias,
|
|
765
771
|
model: entity.model,
|
|
766
|
-
|
|
772
|
+
scope: entity.scope,
|
|
767
773
|
});
|
|
768
774
|
if (existing && !replace) {
|
|
769
775
|
result.skipped.push(alias);
|
|
@@ -785,7 +791,7 @@ async function seedEntities(entities, options = {}) {
|
|
|
785
791
|
id: entity.id ?? crypto.randomUUID(),
|
|
786
792
|
model: entity.model,
|
|
787
793
|
name: entity.name ?? entity.alias ?? "Unnamed",
|
|
788
|
-
|
|
794
|
+
scope: entity.scope,
|
|
789
795
|
sequence: entity.sequence ?? Date.now(),
|
|
790
796
|
updatedAt: entity.updatedAt ?? now,
|
|
791
797
|
...entity,
|
|
@@ -801,27 +807,27 @@ async function seedEntities(entities, options = {}) {
|
|
|
801
807
|
return result;
|
|
802
808
|
}
|
|
803
809
|
/**
|
|
804
|
-
* Export entities by model and
|
|
810
|
+
* Export entities by model and scope
|
|
805
811
|
*
|
|
806
|
-
* - Paginates through all matching entities via
|
|
812
|
+
* - Paginates through all matching entities via queryByScope
|
|
807
813
|
* - Returns entities sorted by sequence (ascending)
|
|
808
814
|
*
|
|
809
815
|
* @param model - The entity model name
|
|
810
|
-
* @param
|
|
816
|
+
* @param scope - The scope (APEX or "{parent.model}#{parent.id}")
|
|
811
817
|
* @param limit - Optional maximum number of entities to export
|
|
812
818
|
* @returns Export result with entities and count
|
|
813
819
|
*/
|
|
814
|
-
async function exportEntities(model,
|
|
820
|
+
async function exportEntities(model, scope, limit) {
|
|
815
821
|
const entities = [];
|
|
816
822
|
let startKey;
|
|
817
823
|
let remaining = limit;
|
|
818
824
|
do {
|
|
819
825
|
const batchLimit = remaining !== undefined ? Math.min(remaining, 100) : undefined;
|
|
820
|
-
const { items, lastEvaluatedKey } = await
|
|
826
|
+
const { items, lastEvaluatedKey } = await queryByScope({
|
|
821
827
|
ascending: true,
|
|
822
828
|
limit: batchLimit,
|
|
823
829
|
model,
|
|
824
|
-
|
|
830
|
+
scope,
|
|
825
831
|
startKey,
|
|
826
832
|
});
|
|
827
833
|
entities.push(...items);
|
|
@@ -839,14 +845,14 @@ async function exportEntities(model, ou, limit) {
|
|
|
839
845
|
* Export entities as a JSON string
|
|
840
846
|
*
|
|
841
847
|
* @param model - The entity model name
|
|
842
|
-
* @param
|
|
848
|
+
* @param scope - The scope (APEX or "{parent.model}#{parent.id}")
|
|
843
849
|
* @param pretty - Format JSON with indentation (default: true)
|
|
844
850
|
* @returns JSON string of exported entities
|
|
845
851
|
*/
|
|
846
|
-
async function exportEntitiesToJson(model,
|
|
847
|
-
const { entities } = await exportEntities(model,
|
|
852
|
+
async function exportEntitiesToJson(model, scope, pretty = true) {
|
|
853
|
+
const { entities } = await exportEntities(model, scope);
|
|
848
854
|
return pretty ? JSON.stringify(entities, null, 2) : JSON.stringify(entities);
|
|
849
855
|
}
|
|
850
856
|
|
|
851
|
-
export { INDEX_ALIAS, INDEX_CLASS,
|
|
857
|
+
export { INDEX_ALIAS, INDEX_CLASS, INDEX_SCOPE, INDEX_TYPE, INDEX_XID, archiveEntity, buildCompositeKey, buildIndexAlias, buildIndexClass, buildIndexScope, buildIndexType, buildIndexXid, calculateScope, deleteEntity, destroyEntity, exportEntities, exportEntitiesToJson, getDocClient, getEntity, getTableName, indexEntity, initClient, isInitialized, putEntity, query, queryByAlias, queryByClass, queryByScope, queryByType, queryByXid, resetClient, seedEntities, seedEntityIfNotExists, updateEntity };
|
|
852
858
|
//# sourceMappingURL=index.js.map
|