@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 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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=4.0.0"
6
6
  },
7
- "version": "0.0.5",
7
+ "version": "0.0.6",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "unknown"
@@ -66,7 +66,16 @@ type DatabaseTableOptions = {
66
66
  extensionFile?: (dialect: string) => string;
67
67
  };
68
68
  type TableExtensionOptions = {
69
- name: string;
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 (name === options.name) {
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frigear-nu/module-kit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Frigear Module Kit",