UNPKG

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