@frigear-nu/module-kit 0.0.5 → 0.0.6
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 +32 -0
- package/dist/module.json +1 -1
- package/dist/runtime/utils/server.d.ts +10 -1
- package/dist/runtime/utils/server.js +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,6 +116,38 @@ call with the merged columns and deduplicated imports. The base `schema` file mu
|
|
|
116
116
|
`sqliteTable('users', { ... })`) matching `name`, since it determines which factory (`sqliteTable`/`pgTable`/etc.) and
|
|
117
117
|
SQL table name to use for the merged result.
|
|
118
118
|
|
|
119
|
+
`name` also accepts an array, so a single `file` can export extension columns for several tables in one go, the same
|
|
120
|
+
way `registerDatabaseTable` does:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
extendDatabaseTable(nuxt, {
|
|
124
|
+
name: ['users', 'userPasskeys'],
|
|
125
|
+
resolver: createResolver(import.meta.url),
|
|
126
|
+
file: dialect => `./runtime/db/extra.${dialect}`,
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
// runtime/db/extra.sqlite.ts
|
|
132
|
+
export const users = sqliteTable('users', {
|
|
133
|
+
locale: text().default('da'),
|
|
134
|
+
})
|
|
135
|
+
export const userPasskeys = sqliteTable('user_passkeys', {
|
|
136
|
+
label: text(),
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`name` can also be omitted entirely, in which case `file` is registered against every table that generates a schema -
|
|
141
|
+
whichever table(s) it actually has a matching export for pick up its columns, exactly as the shared Nuxt-layer
|
|
142
|
+
`server/db/extend.<dialect>.ts` files already do; tables with no matching export in `file` are left untouched:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
extendDatabaseTable(nuxt, {
|
|
146
|
+
resolver: createResolver(import.meta.url),
|
|
147
|
+
file: dialect => `./runtime/db/extra.${dialect}`,
|
|
148
|
+
})
|
|
149
|
+
```
|
|
150
|
+
|
|
119
151
|
#### Using a `factory`
|
|
120
152
|
|
|
121
153
|
Pass `factory` to `registerDatabaseTable` when you need shared defaults (e.g. timestamps) applied consistently across
|
package/dist/module.json
CHANGED
|
@@ -66,7 +66,16 @@ type DatabaseTableOptions = {
|
|
|
66
66
|
extensionFile?: (dialect: string) => string;
|
|
67
67
|
};
|
|
68
68
|
type TableExtensionOptions = {
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* The name of the table to extend (e.g. `users`). Pass an array of names (e.g. `['users', 'userPasskeys']`) when
|
|
71
|
+
* `file` exports columns for several tables at once - it's resolved and parsed once per matching table, same as
|
|
72
|
+
* if `extendDatabaseTable` had been called separately for each name with the same `file`.
|
|
73
|
+
*
|
|
74
|
+
* When omitted, `file` is registered against every table - whichever table(s) it actually has a matching export
|
|
75
|
+
* for (parsed the same way as the shared Nuxt-layer `server/db/extend.<dialect>.ts` files) pick up its columns;
|
|
76
|
+
* tables it has no matching export for are unaffected.
|
|
77
|
+
*/
|
|
78
|
+
name?: string | string[];
|
|
70
79
|
resolver: ReturnType<typeof createResolver>;
|
|
71
80
|
file: (dialect: string) => string;
|
|
72
81
|
};
|
|
@@ -13,8 +13,9 @@ export const onDatabaseSchemaExtend = async (nuxt, extender) => {
|
|
|
13
13
|
return nuxt.hook("hub:db:schema:extend", extender);
|
|
14
14
|
};
|
|
15
15
|
export const extendDatabaseTable = (nuxt, options) => {
|
|
16
|
+
const names = options.name === void 0 ? void 0 : Array.isArray(options.name) ? options.name : [options.name];
|
|
16
17
|
nuxt.hook("module-kit:db:table:extend", async ({ name, dialect, paths }) => {
|
|
17
|
-
if (
|
|
18
|
+
if (names === void 0 || names.includes(name)) {
|
|
18
19
|
const file = await options.resolver.resolvePath(options.file(dialect));
|
|
19
20
|
if (existsSync(file)) paths.push(file);
|
|
20
21
|
}
|