@wszerad/items 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -547
- package/dist/index.d.mts +87 -0
- package/dist/index.mjs +193 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +4 -1
- package/.github/dependabot.yml +0 -15
- package/.github/workflows/publish.yml +0 -22
- package/.github/workflows/test.yml +0 -21
- package/.idea/copilot.data.migration.ask2agent.xml +0 -6
- package/.idea/items.iml +0 -0
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.oxlintrc.json +0 -13
- package/src/Items.ts +0 -215
- package/src/diff.ts +0 -44
- package/src/index.ts +0 -6
- package/src/selectId.ts +0 -7
- package/src/selector.ts +0 -20
- package/src/updater.ts +0 -6
- package/test/index.test.ts +0 -1095
- package/test-type-check.ts +0 -50
- package/tsconfig.json +0 -16
- package/tsdown.config.ts +0 -13
- package/vitest.config.ts +0 -9
package/test-type-check.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Items } from './src'
|
|
2
|
-
|
|
3
|
-
interface User {
|
|
4
|
-
id: number
|
|
5
|
-
name: string
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface Book {
|
|
9
|
-
isbn: string
|
|
10
|
-
title: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface Product {
|
|
14
|
-
sku: string
|
|
15
|
-
name: string
|
|
16
|
-
code: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
console.log('=== Type Inference Tests ===\n')
|
|
20
|
-
|
|
21
|
-
// Test 1: No selectId provided - I is inferred from User['id'] = number
|
|
22
|
-
console.log('Test 1: No selectId, infer from E["id"]')
|
|
23
|
-
const users = new Items<User>([{ id: 1, name: 'Alice' }])
|
|
24
|
-
const userId: number = users.getIds()[0]! // ✓ Type is correctly number
|
|
25
|
-
console.log(' User IDs type:', typeof userId, '✓')
|
|
26
|
-
|
|
27
|
-
// Test 2: With custom selectId - I is inferred from selectId return type (string)
|
|
28
|
-
console.log('\nTest 2: With selectId, infer from selectId return type')
|
|
29
|
-
const books = new Items<Book, string>([], { selectId: (book) => book.isbn })
|
|
30
|
-
const addedBooks = books.insert({ isbn: '978-0', title: 'TypeScript Guide' })
|
|
31
|
-
const bookId: string = addedBooks.getIds()[0]! // ✓ Type is correctly string
|
|
32
|
-
console.log(' Book IDs type:', typeof bookId, '✓')
|
|
33
|
-
|
|
34
|
-
// Test 3: selectId returning different type than default id property
|
|
35
|
-
console.log('\nTest 3: selectId with different return type')
|
|
36
|
-
const products = new Items<Product, number>([], { selectId: (p) => p.code })
|
|
37
|
-
const addedProducts = products.insert({ sku: 'ABC', name: 'Widget', code: 12345 })
|
|
38
|
-
const productId: number = addedProducts.getIds()[0]! // ✓ Type is correctly number
|
|
39
|
-
console.log(' Product IDs type:', typeof productId, '✓')
|
|
40
|
-
|
|
41
|
-
// Test 4: Full type inference from initial items
|
|
42
|
-
console.log('\nTest 4: Complete inference from initial items')
|
|
43
|
-
const autoInferred = new Items([{ id: 999, name: 'Test' }])
|
|
44
|
-
const autoId: number = autoInferred.getIds()[0]! // ✓ Both E and I are inferred
|
|
45
|
-
console.log(' Auto-inferred ID type:', typeof autoId, '✓')
|
|
46
|
-
|
|
47
|
-
console.log('\n✓ All type inference tests passed!')
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"lib": ["ES2022"],
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "Bundler",
|
|
7
|
-
"resolveJsonModule": true,
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"noEmit": true,
|
|
13
|
-
"types": ["node", "vitest/globals"]
|
|
14
|
-
},
|
|
15
|
-
"include": ["src", "test", "vitest.config.ts"]
|
|
16
|
-
}
|
package/tsdown.config.ts
DELETED