dynamoose
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.5
@@ -125,3 +125,3 @@ "use strict"; | ||
return typePaths; | ||
}).map((obj) => Object.values(obj).map((obj) => { var _a; return ((_a = obj) === null || _a === void 0 ? void 0 : _a.matchCorrectness) || 0; })).map((array) => Math.min(...array)); | ||
}).map((obj) => Object.values(obj).map((obj) => (obj === null || obj === void 0 ? void 0 : obj.matchCorrectness) || 0)).map((array) => Math.min(...array)); | ||
return schemaCorrectnessScores; | ||
@@ -128,0 +128,0 @@ }, |
@@ -603,2 +603,6 @@ /// <reference types="node" /> | ||
getDefaultMapAttribute: (attribute: string) => string; | ||
getIndexAttributes: () => { | ||
index: IndexDefinition; | ||
attribute: string; | ||
}[]; | ||
} | ||
@@ -704,2 +708,17 @@ export declare class Schema extends InternalPropertiesClass<SchemaInternalProperties> { | ||
constructor(object: SchemaDefinition, settings?: SchemaSettings); | ||
/** | ||
* This property returns an array of strings with each string being the name of an attribute. Only attributes that are indexes are returned. | ||
* | ||
* ```js | ||
* const schema = new Schema({ | ||
* "id": String, | ||
* "name": { | ||
* "type": String, | ||
* "index": true | ||
* } | ||
* }); | ||
* console.log(schema.indexAttributes); // ["name"] | ||
* ``` | ||
*/ | ||
get indexAttributes(): string[]; | ||
attributes: (object?: ObjectType, settings?: SchemaAttributesMethodSettings) => string[]; | ||
@@ -743,6 +762,2 @@ getCreateTableAttributeParams(model: Model<Item>): Promise<Pick<DynamoDB.CreateTableInput, "AttributeDefinitions" | "KeySchema" | "GlobalSecondaryIndexes" | "LocalSecondaryIndexes">>; | ||
}): ObjectType; | ||
getIndexAttributes: () => Promise<{ | ||
index: IndexDefinition; | ||
attribute: string; | ||
}[]>; | ||
getSettingValue: (setting: string) => any; | ||
@@ -749,0 +764,0 @@ getAttributeTypeDetails: (key: string, settings?: { |
@@ -401,2 +401,21 @@ "use strict"; | ||
} | ||
}, | ||
"getIndexAttributes": () => { | ||
return this.attributes() | ||
.map((attribute) => ({ | ||
"index": this.getAttributeSettingValue("index", attribute), | ||
attribute | ||
})) | ||
.filter((obj) => Array.isArray(obj.index) ? obj.index.some((index) => Boolean(index)) : obj.index) | ||
.reduce((accumulator, currentValue) => { | ||
if (Array.isArray(currentValue.index)) { | ||
currentValue.index.forEach((currentIndex) => { | ||
accumulator.push(Object.assign(Object.assign({}, currentValue), { "index": currentIndex })); | ||
}); | ||
} | ||
else { | ||
accumulator.push(currentValue); | ||
} | ||
return accumulator; | ||
}, []); | ||
} | ||
@@ -508,2 +527,19 @@ }); | ||
} | ||
/** | ||
* This property returns an array of strings with each string being the name of an attribute. Only attributes that are indexes are returned. | ||
* | ||
* ```js | ||
* const schema = new Schema({ | ||
* "id": String, | ||
* "name": { | ||
* "type": String, | ||
* "index": true | ||
* } | ||
* }); | ||
* console.log(schema.indexAttributes); // ["name"] | ||
* ``` | ||
*/ | ||
get indexAttributes() { | ||
return this.getInternalProperties(internalProperties).getIndexAttributes().map((key) => key.attribute); | ||
} | ||
async getCreateTableAttributeParams(model) { | ||
@@ -536,3 +572,3 @@ const hashKey = this.hashKey; | ||
} | ||
utils_1.default.array_flatten(await Promise.all([this.getIndexAttributes(), this.getIndexRangeKeyAttributes()])).map((obj) => obj.attribute).forEach((index) => { | ||
utils_1.default.array_flatten(await Promise.all([this.getInternalProperties(internalProperties).getIndexAttributes(), this.getIndexRangeKeyAttributes()])).map((obj) => obj.attribute).forEach((index) => { | ||
if (AttributeDefinitionsNames.includes(index)) { | ||
@@ -611,4 +647,4 @@ return; | ||
const isValueUndefined = typeof value === "undefined" || value === null; | ||
if (settings.defaults && isValueUndefined || settings.forceDefault && await this.getAttributeSettingValue("forceDefault", key)) { | ||
const defaultValueRaw = await this.getAttributeSettingValue("default", key); | ||
if (settings.defaults && isValueUndefined || settings.forceDefault && this.getAttributeSettingValue("forceDefault", key)) { | ||
const defaultValueRaw = this.getAttributeSettingValue("default", key); | ||
let hasMultipleTypes; | ||
@@ -718,3 +754,3 @@ try { | ||
Schema.prototype.requiredCheck = async function (key, value) { | ||
const isRequired = await this.getAttributeSettingValue("required", key); | ||
const isRequired = this.getAttributeSettingValue("required", key); | ||
if ((typeof value === "undefined" || value === null) && (Array.isArray(isRequired) ? isRequired.some((val) => Boolean(val)) : isRequired)) { | ||
@@ -724,27 +760,8 @@ throw new Error_1.default.ValidationError(`${key} is a required property but has no value when trying to save item`); | ||
}; | ||
Schema.prototype.getIndexAttributes = async function () { | ||
return (await Promise.all(this.attributes() | ||
.map(async (attribute) => ({ | ||
"index": await this.getAttributeSettingValue("index", attribute), | ||
attribute | ||
})))) | ||
.filter((obj) => Array.isArray(obj.index) ? obj.index.some((index) => Boolean(index)) : obj.index) | ||
.reduce((accumulator, currentValue) => { | ||
if (Array.isArray(currentValue.index)) { | ||
currentValue.index.forEach((currentIndex) => { | ||
accumulator.push(Object.assign(Object.assign({}, currentValue), { "index": currentIndex })); | ||
}); | ||
} | ||
else { | ||
accumulator.push(currentValue); | ||
} | ||
return accumulator; | ||
}, []); | ||
}; | ||
Schema.prototype.getIndexRangeKeyAttributes = async function () { | ||
const indexes = await this.getIndexAttributes(); | ||
const indexes = await this.getInternalProperties(internalProperties).getIndexAttributes(); | ||
return indexes.map((index) => index.index.rangeKey).filter((a) => Boolean(a)).map((a) => ({ "attribute": a })); | ||
}; | ||
Schema.prototype.getIndexes = async function (model) { | ||
const indexes = (await this.getIndexAttributes()).reduce((accumulator, currentValue) => { | ||
const indexes = (await this.getInternalProperties(internalProperties).getIndexAttributes()).reduce((accumulator, currentValue) => { | ||
const indexValue = currentValue.index; | ||
@@ -751,0 +768,0 @@ const attributeValue = currentValue.attribute; |
@@ -49,3 +49,3 @@ import { CallbackType, DeepPartial, ObjectType } from "../General"; | ||
* | ||
* The `config` parameter is an object used to customize settings for the table. | ||
* The `options` parameter is an optional object used to customize settings for the table. | ||
* | ||
@@ -103,5 +103,5 @@ * | Name | Description | Type | Default | | ||
* @param models An array of [Model](/guide/Model.md) instances. | ||
* @param options An object used to customize settings for the table. | ||
* @param options An optional object used to customize settings for the table. | ||
*/ | ||
constructor(instance: Instance, name: string, models: Model[], options: TableOptionsOptional); | ||
constructor(instance: Instance, name: string, models: Model[], options?: TableOptionsOptional); | ||
/** | ||
@@ -108,0 +108,0 @@ * This property is a string that represents the table's hashKey. |
@@ -29,3 +29,3 @@ "use strict"; | ||
* | ||
* The `config` parameter is an object used to customize settings for the table. | ||
* The `options` parameter is an optional object used to customize settings for the table. | ||
* | ||
@@ -83,3 +83,3 @@ * | Name | Description | Type | Default | | ||
* @param models An array of [Model](/guide/Model.md) instances. | ||
* @param options An object used to customize settings for the table. | ||
* @param options An optional object used to customize settings for the table. | ||
*/ | ||
@@ -117,4 +117,8 @@ constructor(instance, name, models, options) { | ||
"pendingTaskPromise": () => { | ||
return this.getInternalProperties(internalProperties).ready ? Promise.resolve() : new Promise((resolve) => { | ||
this.getInternalProperties(internalProperties).pendingTasks.push(resolve); | ||
const internalPropertiesObject = this.getInternalProperties(internalProperties); | ||
if (internalPropertiesObject.setupFlowRunning === false && internalPropertiesObject.ready === false) { | ||
return Promise.reject(new Error_1.default.OtherError(`Table ${this.name} has not been initialized.`)); | ||
} | ||
return internalPropertiesObject.ready ? Promise.resolve() : new Promise((resolve) => { | ||
internalPropertiesObject.pendingTasks.push(resolve); | ||
}); | ||
@@ -368,7 +372,6 @@ }, | ||
create(settings, callback) { | ||
var _a; | ||
if (typeof settings === "function") { | ||
callback = settings; | ||
} | ||
const promise = ((_a = settings) === null || _a === void 0 ? void 0 : _a.return) === "request" ? (0, utilities_1.createTableRequest)(this) : (0, utilities_1.createTable)(this, true); | ||
const promise = (settings === null || settings === void 0 ? void 0 : settings.return) === "request" ? (0, utilities_1.createTableRequest)(this) : (0, utilities_1.createTable)(this, true); | ||
if (callback) { | ||
@@ -375,0 +378,0 @@ promise.then((response) => callback(null, response)).catch((error) => callback(error)); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const objectUtils = require("js-object-utilities"); | ||
function deep_copy(obj) { | ||
@@ -44,3 +45,3 @@ let copy; | ||
for (const attr in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, attr)) { | ||
if (Object.prototype.hasOwnProperty.call(obj, attr) && !objectUtils.isCircular(obj, attr)) { | ||
copy[attr] = deep_copy(obj[attr]); | ||
@@ -47,0 +48,0 @@ } |
{ | ||
"name": "dynamoose", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.5", | ||
"description": "Dynamoose is a modeling tool for Amazon's DynamoDB (inspired by Mongoose)", | ||
"homepage": "https://dynamoosejs.com", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"homepage": "https://dynamoosejs.com", | ||
"directories": { | ||
"doc": "docs" | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dynamoose/dynamoose.git" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^17.0.7", | ||
"@typescript-eslint/eslint-plugin": "^5.9.0", | ||
"@typescript-eslint/parser": "^5.9.0", | ||
"dynamoose-logger": "^3.0.0-alpha.1", | ||
"eslint": "^8.6.0", | ||
"eslint-plugin-no-only-tests": "^2.6.0", | ||
"jest": "^27.4.5", | ||
"rimraf": "^3.0.2", | ||
"source-map-support": "^0.5.21", | ||
"typescript": "^4.5.4" | ||
"author": { | ||
"name": "Charlie Fish", | ||
"email": "fishcharlie.code@gmail.com", | ||
"url": "https://charlie.fish" | ||
}, | ||
"scripts": { | ||
"prepare": "npm run build:clean && npm run build", | ||
"build": "tsc", | ||
@@ -33,64 +25,14 @@ "build:sourcemap": "tsc --sourceMap", | ||
"test": "npm run test:nocoverage -- --coverage --transformIgnorePatterns=''", | ||
"test:types": "tsc --project test/types/tsconfig.json", | ||
"lint": "eslint . --ext .ts,.js --max-warnings 0", | ||
"lint:fix": "npm run lint -- --fix", | ||
"site:install": "cd docs && npm install", | ||
"site:start": "cd docs && npm start", | ||
"site:build": "cd docs && npm run build", | ||
"site:swizzle": "cd docs && npm run swizzle" | ||
"test:types": "tsc --project test/types/tsconfig.json" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/dynamoose/dynamoose.git" | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "^3.49.0", | ||
"@aws-sdk/util-dynamodb": "^3.49.0", | ||
"dynamoose-utils": "^3.0.0-beta.5", | ||
"js-object-utilities": "^2.1.0" | ||
}, | ||
"author": { | ||
"name": "Charlie Fish", | ||
"email": "fishcharlie.code@gmail.com", | ||
"url": "https://charlie.fish" | ||
"devDependencies": { | ||
"dynamoose-logger": "^3.0.0-beta.5" | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Brandon Goode" | ||
} | ||
], | ||
"bugs": { | ||
"url": "https://github.com/dynamoose/dynamoose/issues" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "^3.45.0", | ||
"@aws-sdk/util-dynamodb": "^3.45.0", | ||
"dynamoose-utils": "^3.0.0-alpha.2", | ||
"js-object-utilities": "^2.0.0" | ||
}, | ||
"license": "Unlicense", | ||
"keywords": [ | ||
"dynamodb", | ||
"dynamo", | ||
"mongoose", | ||
"aws", | ||
"amazon", | ||
"document", | ||
"model", | ||
"schema", | ||
"database", | ||
"data", | ||
"datastore", | ||
"query", | ||
"scan", | ||
"nosql", | ||
"db", | ||
"nosql", | ||
"store", | ||
"document store", | ||
"table", | ||
"json", | ||
"object", | ||
"storage" | ||
], | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"funding": [ | ||
@@ -105,3 +47,4 @@ { | ||
} | ||
] | ||
], | ||
"gitHead": "cb548e4c2581483ceeef95c86cfc2d75475db527" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1328554
1
195
29454
1
1
0
1