dynamodb-ts-model
Version:
A DynamoDB model/client with full TypeScript typings
94 lines • 3.51 kB
JavaScript
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", { value: true });
const dynamodb_expressions_1 = require("dynamodb-expressions");
const DynamoClient_1 = require("./DynamoClient");
const types_1 = require("./types");
class DeviceModel extends DynamoClient_1.DynamoClient.model()
.withKey('id', 'meta')
.withIndex('foo', 'meta')
.withCreator(item => ({ createdAt: 'foo' }))
.withUpdater(item => Object.assign(item, { createdAt: '' }))
.class() {
}
function ensure(map, key, create) {
}
async function test() {
var _a, e_1, _b, _c;
const client = new DynamoClient_1.DynamoClient();
const d = new DeviceModel({ client, name: 'devices' });
const dayMap = new Map();
await d.update({
key: {
id: '42',
meta: '42'
},
attributes: {
domainId: dynamodb_expressions_1.UpdateAction.set(dynamodb_expressions_1.SetValue.add('meta', 2))
}
});
const x = await d.put({
//type: as<D1>(),
item: { id: 'foo', meta: '', domainId: '' }
//item: {id: 'foo', meta: '', foo:42,createdAt:''}
});
x === null || x === void 0 ? void 0 : x.item.createdAt;
const y = await d.put({
type: (0, types_1.as)(),
item: { id: 'foo', meta: '', domainId: '', createdAt: '' }
//item: {id: 'foo', meta: '', foo:42,createdAt:''}
});
y.item.domainId;
const lkast = await d.query({
//type: as<D2>(),
indexName: 'foo',
keyConditions: {}
});
const p = await d.query({
type: (0, types_1.as)(),
keyConditions: {
id: '42'
},
filterConditions: {
domainId: 'foo'
},
projection: ['id', 'foo']
});
const a = await d.update({
type: (0, types_1.as)(),
key: { id: '42', meta: '' },
attributes: {
domainId: ''
}
});
try {
for (var _d = true, _e = __asyncValues(d.scanIterator({ type: (0, types_1.as)(), projection: ['meta', 'createdAt', 'domainId'] })), _f; _f = await _e.next(), _a = _f.done, !_a;) {
_c = _f.value;
_d = false;
try {
const item = _c;
const { domainId, createdAt, meta } = item;
const time = new Date(createdAt).getTime();
const day = Math.floor(time / 1000 / 60 / 60 / 24);
const domainMap = dayMap.get(day) || new Map();
}
finally {
_d = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
}
//# sourceMappingURL=devices.js.map
;