Skip to content

Commit c29dafe

Browse files
committed
types: improvements, stricter types and more checking
1 parent f2a5088 commit c29dafe

File tree

26 files changed

+160
-113
lines changed

26 files changed

+160
-113
lines changed

packages/core/test/model.spec.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ describe('model', () => {
6060
},
6161
}
6262
const resolved = resolveModels(modelTypes, defaults)
63-
expect(resolved[0].getKey({ id: 'foo' })).toBe(defaults.getKey?.({ id: 'foo' }))
64-
expect(resolved[0].meta).toEqual({
63+
expect(resolved[0]!.getKey({ id: 'foo' })).toBe(defaults.getKey?.({ id: 'foo' }))
64+
expect(resolved[0]!.meta).toEqual({
6565
path: '/test',
6666
test: 'meow',
6767
})
68-
expect(resolved[1].getKey({ id: 'foo' })).toBe((modelTypes[1] as Model).getKey?.({ id: 'foo' }))
69-
expect(resolved[1].meta).toEqual({
68+
expect(resolved[1]!.getKey({ id: 'foo' })).toBe((modelTypes[1] as Model).getKey?.({ id: 'foo' }))
69+
expect(resolved[1]!.meta).toEqual({
7070
test: 'meow',
7171
})
7272
})
@@ -119,8 +119,8 @@ describe('model', () => {
119119

120120
const resolved = resolveModels(modelTypes)
121121

122-
expect(resolved[0].getKey({ id: 'foo' })).toBe((modelTypes[0] as Model).getKey?.({ id: 'foo' }))
123-
expect(resolved[0].relations).toEqual({
122+
expect(resolved[0]!.getKey({ id: 'foo' })).toBe((modelTypes[0] as Model).getKey?.({ id: 'foo' }))
123+
expect(resolved[0]!.relations).toEqual({
124124
test: {
125125
to: {
126126
Test2: {
@@ -131,11 +131,11 @@ describe('model', () => {
131131
},
132132
},
133133
})
134-
expect(resolved[0].computed.calc).toBeTypeOf('function')
135-
expect(resolved[0].fields!.createdAt!.parse).toBeTypeOf('function')
136-
expect(resolved[0].formSchema.create['~standard'].vendor).toBe('rstore')
137-
expect(resolved[0].formSchema.update['~standard'].vendor).toBe('rstore')
138-
expect(resolved[0].meta).toEqual({
134+
expect(resolved[0]!.computed.calc).toBeTypeOf('function')
135+
expect(resolved[0]!.fields!.createdAt!.parse).toBeTypeOf('function')
136+
expect(resolved[0]!.formSchema.create['~standard']!.vendor).toBe('rstore')
137+
expect(resolved[0]!.formSchema.update['~standard']!.vendor).toBe('rstore')
138+
expect(resolved[0]!.meta).toEqual({
139139
test: 'meow',
140140
})
141141
})
@@ -164,13 +164,13 @@ describe('model', () => {
164164

165165
const resolved = resolveModels(modelTypes, defaults)
166166

167-
expect(resolved[0].getKey({ id: 0 })).toBe(defaults.getKey?.({ id: 0 }))
168-
expect(resolved[0].relations).toEqual({})
169-
expect(resolved[0].computed.calc).toBeTypeOf('function')
170-
expect(resolved[0].fields!.createdAt!.parse).toBeTypeOf('function')
171-
expect(resolved[0].formSchema.create['~standard'].vendor).toBe('rstore')
172-
expect(resolved[0].formSchema.update['~standard'].vendor).toBe('rstore')
173-
expect(resolved[0].meta).toEqual({
167+
expect(resolved[0]!.getKey({ id: 0 })).toBe(defaults.getKey?.({ id: 0 }))
168+
expect(resolved[0]!.relations).toEqual({})
169+
expect(resolved[0]!.computed.calc).toBeTypeOf('function')
170+
expect(resolved[0]!.fields!.createdAt!.parse).toBeTypeOf('function')
171+
expect(resolved[0]!.formSchema.create['~standard']!.vendor).toBe('rstore')
172+
expect(resolved[0]!.formSchema.update['~standard']!.vendor).toBe('rstore')
173+
expect(resolved[0]!.meta).toEqual({
174174
test: 'meow',
175175
})
176176
})

packages/core/test/plugin.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe('setupPlugin', () => {
116116
} as any)
117117

118118
expect(hookCallback).toHaveBeenCalledOnce()
119-
expect(hookCallback.mock.calls[0][0].model.name).toBe('Todo')
119+
expect(hookCallback.mock.calls[0]![0].model.name).toBe('Todo')
120120
})
121121

122122
it('should not filter hook with scopeId with ignoreScope', async () => {
@@ -154,8 +154,8 @@ describe('setupPlugin', () => {
154154
} as any)
155155

156156
expect(hookCallback).toHaveBeenCalledTimes(2)
157-
expect(hookCallback.mock.calls[0][0].model.name).toBe('Todo')
158-
expect(hookCallback.mock.calls[1][0].model.name).toBe('Message')
157+
expect(hookCallback.mock.calls[0]![0].model.name).toBe('Todo')
158+
expect(hookCallback.mock.calls[1]![0].model.name).toBe('Message')
159159
})
160160

161161
it('should not filter hook with model without scope', async () => {
@@ -189,8 +189,8 @@ describe('setupPlugin', () => {
189189
} as any)
190190

191191
expect(hookCallback).toHaveBeenCalledTimes(2)
192-
expect(hookCallback.mock.calls[0][0].model.name).toBe('Todo')
193-
expect(hookCallback.mock.calls[1][0].model.name).toBe('Message')
192+
expect(hookCallback.mock.calls[0]![0].model.name).toBe('Todo')
193+
expect(hookCallback.mock.calls[1]![0].model.name).toBe('Message')
194194
})
195195

196196
it('should not filter hook with plugin without scope', async () => {
@@ -225,8 +225,8 @@ describe('setupPlugin', () => {
225225
} as any)
226226

227227
expect(hookCallback).toHaveBeenCalledTimes(2)
228-
expect(hookCallback.mock.calls[0][0].model.name).toBe('Todo')
229-
expect(hookCallback.mock.calls[1][0].model.name).toBe('Message')
228+
expect(hookCallback.mock.calls[0]![0].model.name).toBe('Todo')
229+
expect(hookCallback.mock.calls[1]![0].model.name).toBe('Message')
230230
})
231231
})
232232

@@ -323,7 +323,7 @@ describe('setupPlugin', () => {
323323
expect(mockStore.$modelDefaults.computed).toEqual({
324324
test: expect.any(Function),
325325
})
326-
expect(mockStore.$modelDefaults.computed?.test({})).toBe('new')
326+
expect(mockStore.$modelDefaults.computed!.test!({})).toBe('new')
327327
})
328328
})
329329
})

packages/core/test/store.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('createStoreCore', () => {
1313
cache: {} as Cache,
1414
schema: [] as StoreSchema,
1515
modelDefaults: {} as ModelDefaults,
16-
plugins: [],
16+
plugins: []!,
1717
hooks: {
1818
callHookSync: vi.fn(),
1919
callHook: vi.fn(),
@@ -74,7 +74,7 @@ describe('createStoreCore', () => {
7474
const store = await createStoreCore(options)
7575
const item = { name: 'test' }
7676

77-
store.$processItemParsing(store.$models[0], item)
77+
store.$processItemParsing(store.$models[0]!, item)
7878

7979
expect(item.name).toBe('TEST')
8080
})
@@ -119,7 +119,7 @@ describe('createStoreCore', () => {
119119
},
120120
}
121121

122-
store.$processItemParsing(store.$models[0], message)
122+
store.$processItemParsing(store.$models[0]!, message)
123123

124124
expect(message.author.createdAt).toBeInstanceOf(Date)
125125
expect(message.author.createdAt.toISOString()).toBe('2023-01-01T00:00:00.000Z')
@@ -144,7 +144,7 @@ describe('createStoreCore', () => {
144144
const store = await createStoreCore(options)
145145
const item = { date: new Date('2023-01-01T00:00:00Z') }
146146

147-
store.$processItemSerialization(store.$models[0], item)
147+
store.$processItemSerialization(store.$models[0]!, item)
148148

149149
expect(item.date).toBe('2023-01-01T00:00:00.000Z')
150150
})
@@ -167,7 +167,7 @@ describe('createStoreCore', () => {
167167
const store = await createStoreCore(options)
168168
const item = { optionalField: null }
169169

170-
store.$processItemSerialization(store.$models[0], item)
170+
store.$processItemSerialization(store.$models[0]!, item)
171171

172172
expect(serializeMock).not.toHaveBeenCalled()
173173
})
@@ -193,7 +193,7 @@ describe('createStoreCore', () => {
193193
},
194194
}
195195

196-
store.$processItemSerialization(store.$models[0], item)
196+
store.$processItemSerialization(store.$models[0]!, item)
197197

198198
expect(item.metadata.createdAt).toBe('2023-01-01T00:00:00.000Z')
199199
})

packages/core/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"module": "ESNext",
55
"moduleResolution": "Node",
66
"strict": true,
7+
"noImplicitOverride": true,
8+
"noImplicitThis": true,
9+
"noUncheckedIndexedAccess": true,
710
"esModuleInterop": true,
11+
"forceConsistentCasingInFileNames": true,
812
"skipLibCheck": true
913
},
1014
"include": [

packages/nuxt-directus/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@types/node": "catalog:",
5050
"nuxt": "catalog:",
5151
"typescript": "catalog:",
52-
"vitest": "^3.0.9",
53-
"vue-tsc": "^2.2.8"
52+
"vitest": "catalog:",
53+
"vue-tsc": "catalog:"
5454
}
5555
}

packages/nuxt-drizzle/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"drizzle-orm": "^0.40.0",
5757
"nuxt": "catalog:",
5858
"typescript": "catalog:",
59-
"vitest": "^3.0.8",
60-
"vue-tsc": "^2.2.8"
59+
"vitest": "catalog:",
60+
"vue-tsc": "catalog:"
6161
}
6262
}

packages/nuxt-drizzle/src/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export default defineNuxtModule<ModuleOptions>({
283283
to: {
284284
[targetModel.name]: {
285285
on: {
286-
[getColumnKey(relation.referencedTable, targetRelation.config!.fields[0])]: getColumnKey(relation.sourceTable, targetRelation.config!.references[0]),
286+
[getColumnKey(relation.referencedTable, targetRelation.config!.fields[0]!)]: getColumnKey(relation.sourceTable, targetRelation.config!.references[0]!),
287287
},
288288
},
289289
},
@@ -341,7 +341,7 @@ export default defineNuxtModule<ModuleOptions>({
341341
to: {
342342
[targetModel.name]: {
343343
on: {
344-
[getColumnKey(relation.referencedTable, targetRelation.config!.fields[0])]: getColumnKey(relation.sourceTable, targetRelation.config!.references[0]),
344+
[getColumnKey(relation.referencedTable, targetRelation.config!.fields[0]!)]: getColumnKey(relation.sourceTable, targetRelation.config!.references[0]!),
345345
},
346346
},
347347
},

packages/nuxt-drizzle/src/runtime/plugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-expect-error virtual module
21
import { useRequestFetch } from '#app'
32
// @ts-expect-error virtual module
43
import { apiPath } from '#build/$rstore-drizzle-config.js'
@@ -135,10 +134,10 @@ export default definePlugin({
135134
items.sort((a: any, b: any) => {
136135
for (const param of orderBy) {
137136
const [key, order] = param.split('.')
138-
if (a[key] < b[key]) {
137+
if (a[key!] < b[key!]) {
139138
return order === 'asc' ? -1 : 1
140139
}
141-
if (a[key] > b[key]) {
140+
if (a[key!] > b[key!]) {
142141
return order === 'asc' ? 1 : -1
143142
}
144143
}

packages/nuxt-drizzle/src/runtime/server/api/[key]/index.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineEventHandler(async (event) => {
3131
}
3232

3333
const dbQuery = rstoreUseDrizzle().query as unknown as Record<string, RelationalQueryBuilder<any, any>>
34-
let result: any = await dbQuery[modelName].findFirst({
34+
let result: any = await dbQuery[modelName]!.findFirst({
3535
where: and(
3636
getDrizzleKeyWhere(key, primaryKeys, table),
3737
...where,

packages/nuxt-drizzle/src/runtime/server/api/index.get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ export default eventHandler(async (event) => {
8888
}
8989
const [columnName, order] = parts
9090
const operator = orderByOperators[order as 'asc' | 'desc']
91-
orderBy.push(operator((table as any)[columnName]))
91+
orderBy.push(operator((table as any)[columnName!]))
9292
}
9393
q.orderBy = orderBy
9494
}
9595

96-
let result = await dbQuery[modelName].findMany(q)
96+
let result = await dbQuery[modelName]!.findMany(q)
9797
result ??= []
9898

9999
await rstoreDrizzleHooks.callHook('index.get.after', {

0 commit comments

Comments
 (0)