@jaypie/fabric 0.2.3 → 0.2.4
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/README.md +9 -8
- package/dist/cjs/index/index.d.ts +1 -1
- package/dist/cjs/index/registry.d.ts +4 -1
- package/dist/cjs/index/types.d.ts +9 -1
- package/dist/cjs/index.cjs +43 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/esm/index/index.d.ts +1 -1
- package/dist/esm/index/registry.d.ts +4 -1
- package/dist/esm/index/types.d.ts +9 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +43 -3
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -591,9 +591,9 @@ const message: FabricMessage = {
|
|
|
591
591
|
When persisting models to DynamoDB, use index utilities to build GSI keys:
|
|
592
592
|
|
|
593
593
|
```typescript
|
|
594
|
-
import { APEX, calculateScope, populateIndexKeys, registerModel } from "@jaypie/fabric";
|
|
594
|
+
import { APEX, calculateScope, DEFAULT_INDEXES, populateIndexKeys, registerModel } from "@jaypie/fabric";
|
|
595
595
|
|
|
596
|
-
// Register model indexes
|
|
596
|
+
// Register custom model indexes (recommended)
|
|
597
597
|
registerModel({
|
|
598
598
|
model: "record",
|
|
599
599
|
indexes: [
|
|
@@ -619,16 +619,16 @@ const message = {
|
|
|
619
619
|
// ...other fields
|
|
620
620
|
};
|
|
621
621
|
|
|
622
|
-
// Auto-populate GSI keys
|
|
623
|
-
const
|
|
624
|
-
{ name: "indexScope", pk: ["scope", "model"], sk: ["sequence"] },
|
|
625
|
-
{ name: "indexAlias", pk: ["scope", "model", "alias"], sk: ["sequence"], sparse: true },
|
|
626
|
-
];
|
|
627
|
-
const indexed = populateIndexKeys(record, indexes);
|
|
622
|
+
// Auto-populate GSI keys
|
|
623
|
+
const indexed = populateIndexKeys(record, DEFAULT_INDEXES);
|
|
628
624
|
// indexed.indexScope = "@#record"
|
|
629
625
|
// indexed.indexAlias = "@#record#2026-12-12"
|
|
630
626
|
```
|
|
631
627
|
|
|
628
|
+
> **Deprecated:** `DEFAULT_INDEXES` is restored in 0.2.4 to unblock consumers
|
|
629
|
+
> and is scheduled for removal in 0.3.0. Register model indexes explicitly with
|
|
630
|
+
> `registerModel()` instead.
|
|
631
|
+
|
|
632
632
|
## API
|
|
633
633
|
|
|
634
634
|
### Main Export (`@jaypie/fabric`)
|
|
@@ -655,6 +655,7 @@ const indexed = populateIndexKeys(record, indexes);
|
|
|
655
655
|
| `populateIndexKeys` | Populate GSI keys on an entity |
|
|
656
656
|
| `buildCompositeKey` | Build composite key from fields |
|
|
657
657
|
| `calculateScope` | Calculate scope |
|
|
658
|
+
| `DEFAULT_INDEXES` | Default GSI definitions (deprecated, removal targeted for 0.3.0) |
|
|
658
659
|
| `APEX` | Root-level marker (`"@"`) |
|
|
659
660
|
| `SEPARATOR` | Composite key separator (`"#"`) |
|
|
660
661
|
| `ARCHIVED_SUFFIX` | Suffix for archived entities |
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Exports all index-related types, functions, and constants.
|
|
5
5
|
*/
|
|
6
|
-
export { ARCHIVED_SUFFIX, DEFAULT_SORT_KEY, DELETED_SUFFIX, type IndexDefinition, type IndexField, type ModelSchema, } from "./types.js";
|
|
6
|
+
export { ARCHIVED_SUFFIX, DEFAULT_INDEXES, DEFAULT_SORT_KEY, DELETED_SUFFIX, type IndexDefinition, type IndexField, type ModelSchema, } from "./types.js";
|
|
7
7
|
export { buildCompositeKey, calculateIndexSuffix, calculateScope, generateIndexName, type IndexableModel, populateIndexKeys, tryBuildCompositeKey, } from "./keyBuilder.js";
|
|
8
8
|
export { clearRegistry, getAllRegisteredIndexes, getModelIndexes, getModelSchema, getRegisteredModels, isModelRegistered, registerModel, } from "./registry.js";
|
|
@@ -22,7 +22,10 @@ export declare function getModelSchema(model: string): ModelSchema | undefined;
|
|
|
22
22
|
* Get index definitions for a model
|
|
23
23
|
*
|
|
24
24
|
* Returns the model's custom indexes if registered,
|
|
25
|
-
* otherwise returns
|
|
25
|
+
* otherwise returns DEFAULT_INDEXES.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated The fallback to DEFAULT_INDEXES will be removed in 0.3.0.
|
|
28
|
+
* Register model indexes explicitly with `registerModel()`.
|
|
26
29
|
*
|
|
27
30
|
* @param model - Model name to get indexes for
|
|
28
31
|
* @returns Array of index definitions
|
|
@@ -32,9 +32,17 @@ export interface IndexDefinition {
|
|
|
32
32
|
export interface ModelSchema {
|
|
33
33
|
/** The model name (e.g., "record", "message", "chat") */
|
|
34
34
|
model: string;
|
|
35
|
-
/** Custom indexes for this model (
|
|
35
|
+
/** Custom indexes for this model (uses DEFAULT_INDEXES if not specified) */
|
|
36
36
|
indexes?: IndexDefinition[];
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Default indexes for the DynamoDB GSI pattern.
|
|
40
|
+
* These are used when a model does not specify custom indexes.
|
|
41
|
+
*
|
|
42
|
+
* @deprecated Restored in 0.2.4 to unblock consumers. Will be removed in
|
|
43
|
+
* 0.3.0 — register model indexes explicitly with `registerModel()` instead.
|
|
44
|
+
*/
|
|
45
|
+
export declare const DEFAULT_INDEXES: IndexDefinition[];
|
|
38
46
|
/**
|
|
39
47
|
* Default sort key fields when sk is not specified
|
|
40
48
|
*/
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -776,6 +776,43 @@ function computeResolvedName(model) {
|
|
|
776
776
|
* GSIs and auto-detect which index to use for queries.
|
|
777
777
|
*/
|
|
778
778
|
// =============================================================================
|
|
779
|
+
// Default Indexes
|
|
780
|
+
// =============================================================================
|
|
781
|
+
/**
|
|
782
|
+
* Default indexes for the DynamoDB GSI pattern.
|
|
783
|
+
* These are used when a model does not specify custom indexes.
|
|
784
|
+
*
|
|
785
|
+
* @deprecated Restored in 0.2.4 to unblock consumers. Will be removed in
|
|
786
|
+
* 0.3.0 — register model indexes explicitly with `registerModel()` instead.
|
|
787
|
+
*/
|
|
788
|
+
const DEFAULT_INDEXES = [
|
|
789
|
+
{ name: "indexScope", pk: ["scope", "model"], sk: ["sequence"] },
|
|
790
|
+
{
|
|
791
|
+
name: "indexAlias",
|
|
792
|
+
pk: ["scope", "model", "alias"],
|
|
793
|
+
sk: ["sequence"],
|
|
794
|
+
sparse: true,
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
name: "indexCategory",
|
|
798
|
+
pk: ["scope", "model", "category"],
|
|
799
|
+
sk: ["sequence"],
|
|
800
|
+
sparse: true,
|
|
801
|
+
},
|
|
802
|
+
{
|
|
803
|
+
name: "indexType",
|
|
804
|
+
pk: ["scope", "model", "type"],
|
|
805
|
+
sk: ["sequence"],
|
|
806
|
+
sparse: true,
|
|
807
|
+
},
|
|
808
|
+
{
|
|
809
|
+
name: "indexXid",
|
|
810
|
+
pk: ["scope", "model", "xid"],
|
|
811
|
+
sk: ["sequence"],
|
|
812
|
+
sparse: true,
|
|
813
|
+
},
|
|
814
|
+
];
|
|
815
|
+
// =============================================================================
|
|
779
816
|
// Constants
|
|
780
817
|
// =============================================================================
|
|
781
818
|
/**
|
|
@@ -951,14 +988,17 @@ function getModelSchema(model) {
|
|
|
951
988
|
* Get index definitions for a model
|
|
952
989
|
*
|
|
953
990
|
* Returns the model's custom indexes if registered,
|
|
954
|
-
* otherwise returns
|
|
991
|
+
* otherwise returns DEFAULT_INDEXES.
|
|
992
|
+
*
|
|
993
|
+
* @deprecated The fallback to DEFAULT_INDEXES will be removed in 0.3.0.
|
|
994
|
+
* Register model indexes explicitly with `registerModel()`.
|
|
955
995
|
*
|
|
956
996
|
* @param model - Model name to get indexes for
|
|
957
997
|
* @returns Array of index definitions
|
|
958
998
|
*/
|
|
959
999
|
function getModelIndexes(model) {
|
|
960
1000
|
const schema = MODEL_REGISTRY.get(model);
|
|
961
|
-
return schema?.indexes ??
|
|
1001
|
+
return schema?.indexes ?? DEFAULT_INDEXES;
|
|
962
1002
|
}
|
|
963
1003
|
/**
|
|
964
1004
|
* Get all registered models
|
|
@@ -1754,6 +1794,7 @@ exports.ARCHIVED_SUFFIX = ARCHIVED_SUFFIX;
|
|
|
1754
1794
|
exports.BOOLEAN_TYPE = BOOLEAN_TYPE;
|
|
1755
1795
|
exports.DATETIME_TYPE = DATETIME_TYPE;
|
|
1756
1796
|
exports.DATE_TYPE = DATE_TYPE;
|
|
1797
|
+
exports.DEFAULT_INDEXES = DEFAULT_INDEXES;
|
|
1757
1798
|
exports.DEFAULT_SORT_KEY = DEFAULT_SORT_KEY;
|
|
1758
1799
|
exports.DELETED_SUFFIX = DELETED_SUFFIX;
|
|
1759
1800
|
exports.DOLLARS_TYPE = DOLLARS_TYPE;
|