1 |
|
2 | import { Document, DocumentObjectFromSchemaSettings } from "./Document";
|
3 | import { Model } from "./Model";
|
4 | import { DynamoDB } from "aws-sdk";
|
5 | import { ModelType, ObjectType } from "./General";
|
6 | export interface DynamoDBSetTypeResult {
|
7 | name: string;
|
8 | dynamicName?: (() => string);
|
9 | dynamodbType: string;
|
10 | isOfType: (value: ValueType, type?: "toDynamo" | "fromDynamo", settings?: Partial<DocumentObjectFromSchemaSettings>) => boolean;
|
11 | isSet: true;
|
12 | customType?: any;
|
13 | typeSettings?: AttributeDefinitionTypeSettings;
|
14 | toDynamo: (val: GeneralValueType[]) => SetValueType;
|
15 | fromDynamo: (val: SetValueType) => Set<ValueType>;
|
16 | }
|
17 | export interface DynamoDBTypeResult {
|
18 | name: string;
|
19 | dynamicName?: (() => string);
|
20 | dynamodbType: string | string[];
|
21 | isOfType: (value: ValueType) => {
|
22 | value: ValueType;
|
23 | type: string;
|
24 | };
|
25 | isSet: false;
|
26 | customType?: any;
|
27 | typeSettings?: AttributeDefinitionTypeSettings;
|
28 | nestedType: boolean;
|
29 | set?: DynamoDBSetTypeResult;
|
30 | }
|
31 | declare type SetValueType = {
|
32 | wrapperName: "Set";
|
33 | values: ValueType[];
|
34 | type: string;
|
35 | };
|
36 | declare type GeneralValueType = string | boolean | number | Buffer | Date;
|
37 | export declare type ValueType = GeneralValueType | {
|
38 | [key: string]: ValueType;
|
39 | } | ValueType[] | SetValueType;
|
40 | declare type AttributeType = string | StringConstructor | BooleanConstructor | NumberConstructor | typeof Buffer | DateConstructor | ObjectConstructor | ArrayConstructor;
|
41 | export interface TimestampObject {
|
42 | createdAt?: string | string[];
|
43 | updatedAt?: string | string[];
|
44 | }
|
45 | interface SchemaSettings {
|
46 | timestamps?: boolean | TimestampObject;
|
47 | saveUnknown?: boolean | string[];
|
48 | }
|
49 | interface IndexDefinition {
|
50 | name?: string;
|
51 | global?: boolean;
|
52 | rangeKey?: string;
|
53 | project?: boolean | string[];
|
54 | throughput?: "ON_DEMAND" | number | {
|
55 | read: number;
|
56 | write: number;
|
57 | };
|
58 | }
|
59 | interface AttributeDefinitionTypeSettings {
|
60 | storage?: "miliseconds" | "seconds";
|
61 | model?: ModelType<Document>;
|
62 | attributes?: string[];
|
63 | seperator?: string;
|
64 | }
|
65 | interface AttributeDefinition {
|
66 | type: AttributeType | {
|
67 | value: DateConstructor;
|
68 | settings?: AttributeDefinitionTypeSettings;
|
69 | } | {
|
70 | value: AttributeType;
|
71 | };
|
72 | schema?: AttributeType | AttributeType[] | AttributeDefinition | AttributeDefinition[] | SchemaDefinition | SchemaDefinition[];
|
73 | default?: ValueType | (() => ValueType);
|
74 | forceDefault?: boolean;
|
75 | validate?: ValueType | RegExp | ((value: ValueType) => boolean);
|
76 | required?: boolean;
|
77 | enum?: ValueType[];
|
78 | get?: ((value: ValueType) => ValueType);
|
79 | set?: ((value: ValueType) => ValueType);
|
80 | index?: boolean | IndexDefinition | IndexDefinition[];
|
81 | hashKey?: boolean;
|
82 | rangeKey?: boolean;
|
83 | }
|
84 | export interface SchemaDefinition {
|
85 | [attribute: string]: AttributeType | AttributeDefinition;
|
86 | }
|
87 | interface SchemaGetAttributeTypeSettings {
|
88 | unknownAttributeAllowed: boolean;
|
89 | }
|
90 | interface SchemaGetAttributeSettingValue {
|
91 | returnFunction: boolean;
|
92 | }
|
93 | export declare class Schema {
|
94 | settings: SchemaSettings;
|
95 | schemaObject: SchemaDefinition;
|
96 | attributes: (object?: ObjectType) => string[];
|
97 | getCreateTableAttributeParams(model: Model<Document>): Promise<Pick<DynamoDB.CreateTableInput, "AttributeDefinitions" | "KeySchema" | "GlobalSecondaryIndexes" | "LocalSecondaryIndexes">>;
|
98 | private getSingleAttributeType;
|
99 | getAttributeType(key: string, value?: ValueType, settings?: SchemaGetAttributeTypeSettings): string | string[];
|
100 | static attributeTypes: {
|
101 | findDynamoDBType: (type: any) => DynamoDBTypeResult | DynamoDBSetTypeResult;
|
102 | findTypeForValue: (...args: any[]) => DynamoDBTypeResult | DynamoDBSetTypeResult;
|
103 | };
|
104 | getHashKey: () => string;
|
105 | getRangeKey: () => string | void;
|
106 | defaultCheck(key: string, value: ValueType, settings: any): Promise<ValueType | void>;
|
107 | requiredCheck: (key: string, value: ValueType) => Promise<void>;
|
108 | getAttributeSettingValue(setting: string, key: string, settings?: SchemaGetAttributeSettingValue): any;
|
109 | getTypePaths(object: ObjectType, settings?: {
|
110 | type: "toDynamo" | "fromDynamo";
|
111 | previousKey?: string;
|
112 | includeAllProperties?: boolean;
|
113 | }): ObjectType;
|
114 | getIndexAttributes: () => Promise<{
|
115 | index: IndexDefinition;
|
116 | attribute: string;
|
117 | }[]>;
|
118 | getSettingValue: (setting: string) => any;
|
119 | getAttributeTypeDetails: (key: string, settings?: {
|
120 | standardKey?: boolean;
|
121 | typeIndexOptionMap?: {};
|
122 | }) => DynamoDBTypeResult | DynamoDBSetTypeResult | DynamoDBTypeResult[] | DynamoDBSetTypeResult[];
|
123 | getAttributeValue: (key: string, settings?: {
|
124 | standardKey?: boolean;
|
125 | typeIndexOptionMap?: {};
|
126 | }) => AttributeDefinition;
|
127 | getIndexes: (model: Model<Document>) => Promise<{
|
128 | GlobalSecondaryIndexes?: IndexItem[];
|
129 | LocalSecondaryIndexes?: IndexItem[];
|
130 | }>;
|
131 | getIndexRangeKeyAttributes: () => Promise<{
|
132 | attribute: string;
|
133 | }[]>;
|
134 | constructor(object: SchemaDefinition, settings?: SchemaSettings);
|
135 | }
|
136 | export interface IndexItem {
|
137 | IndexName: string;
|
138 | KeySchema: ({
|
139 | AttributeName: string;
|
140 | KeyType: "HASH" | "RANGE";
|
141 | })[];
|
142 | Projection: {
|
143 | ProjectionType: "KEYS_ONLY" | "INCLUDE" | "ALL";
|
144 | NonKeyAttributes?: string[];
|
145 | };
|
146 | ProvisionedThroughput?: {
|
147 | "ReadCapacityUnits": number;
|
148 | "WriteCapacityUnits": number;
|
149 | };
|
150 | }
|
151 | export {};
|