diff --git a/package-lock.json b/package-lock.json index 592db7f..3c8e19c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dynamodb-onetable", - "version": "2.0.0", + "version": "2.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "dynamodb-onetable", - "version": "2.0.0", + "version": "2.0.1", "license": "MIT", "dependencies": { "@aws-sdk/client-dynamodb": "^3.5.0", diff --git a/package.json b/package.json index 3be7fef..dad4308 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dynamodb-onetable", - "version": "2.0.0", + "version": "2.0.1", "description": "DynamoDB access library for single-table designs", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", diff --git a/src/Table.d.ts b/src/Table.d.ts index e1b69e5..8948dae 100644 --- a/src/Table.d.ts +++ b/src/Table.d.ts @@ -67,7 +67,8 @@ export class Table { setLog(log: any): void; setSchema(schema?: OneSchema): Promise; transact(op: string, transaction: any, params?: OneParams): Promise; - uuid(): {}; + ulid(): string; + uuid(): string; deleteItem(properties: OneProperties, params?: OneParams): Promise; getItem(properties: OneProperties, params?: OneParams): Promise; diff --git a/src/ULID.js b/src/ULID.js index edddcb5..290590a 100644 --- a/src/ULID.js +++ b/src/ULID.js @@ -60,6 +60,6 @@ export default class ULID { bytes[i] = Letters.charAt(mod) now = (now - mod) / LettersLen } - return bytes.join('') + return bytes.reverse().join('') } } diff --git a/test/debug.ts b/test/debug.ts index 5911df2..17eecfe 100644 --- a/test/debug.ts +++ b/test/debug.ts @@ -48,9 +48,10 @@ test('Test', async() => { }, {log: false, hidden: true}) // dump("USER", user) - users = await User.find({sk: null}, {log: false, hidden: true}) + // users = await User.find({sk: null}, {log: false, hidden: true}) + + // users = await AdminUser.find({}, {index: 'gs1', log: false, hidden: true}) - // user = await User.get({entity: {id: user.entity.id}}) // dump("USERS", users) }) diff --git a/test/schemas/debugSchema.ts b/test/schemas/debugSchema.ts index 37bb497..01481ff 100644 --- a/test/schemas/debugSchema.ts +++ b/test/schemas/debugSchema.ts @@ -5,12 +5,16 @@ export default { version: '0.0.1', indexes: { primary: { hash: 'pk', sort: 'sk' }, - // gs1: { hash: 'gs1pk', sort: 'gs1sk', project: ['gs1pk', 'gs1sk', 'name']} + gs1: { hash: 'gs1pk', sort: 'gs1sk', project: 'all' }, }, models: { User: { pk: { type: String, value: '${_type}#' }, sk: { type: String, value: '${_type}#${domain}#${id}' }, + + gs1pk: { type: String, value: '${_type}#' }, + gs1sk: { type: String, value: '${_type}#${id}' }, + name: { type: String }, email: { type: String }, id: { type: String, uuid: "uuid" }, diff --git a/test/ulid.ts b/test/ulid.ts index 5a6b49d..3bbf88f 100644 --- a/test/ulid.ts +++ b/test/ulid.ts @@ -1,7 +1,7 @@ /* ulid.ts - Unit test for ULID */ -import {Match} from './utils/init' +import {Match, delay} from './utils/init' import ULID from '../src/ULID' // jest.setTimeout(7200 * 1000) @@ -49,3 +49,18 @@ test('ULID repeat', async() => { expect(id.length).toBe(26) } }) + +test('Sequence of timestamps', async() => { + const limit = 100 + let output = [] + for (let i = 0; i < limit; i++) { + let ulid = new ULID() + const id = ulid.toString() + await delay(1) + output.push(id) + } + let sorted = output.sort() + for (let i = 0; i < limit; i++) { + expect(output[i]).toBe(sorted[i]) + } +}) \ No newline at end of file