@teamscala/service-boot 0.23.456 → 0.23.457

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/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "name": "@teamscala/service-boot",
8
8
  "type": "module",
9
- "version": "0.23.456",
9
+ "version": "0.23.457",
10
10
  "sideEffects": false,
11
11
  "imports": {
12
12
  "#service-boot/*": "./src/*",
@@ -43,29 +43,68 @@ async function resolveStylesheetRaw(
43
43
  }
44
44
  return { path: p, base: dirname(p), content: await Bun.file(p).text() };
45
45
  }
46
- // Bare specifier: find node_modules/<id>/package.json by walking upward
47
- // from the importing file's dir then cwd, and read the DECLARED STYLE
48
- // entry (exports["."].style / style). Bun.resolve is not used here: it
49
- // hands back whatever the package's main is — for a normal JS package
50
- // that is a .js entry, not the declared stylesheet. A package with no
51
- // style entry is not a stylesheet import: that is a build-breaking
52
- // error naming the specifier, never an invented path whose ENOENT
53
- // surfaces as a misleading downstream CSS error.
46
+ // A BARE SPECIFIER IS A PACKAGE NAME PLUS AN OPTIONAL SUBPATH, and the two
47
+ // must be separated before anything is looked up. `@teamscala/ui-foundation`
48
+ // is a package; `@teamscala/ui-foundation/theme/styles.css` is that same
49
+ // package plus an explicit file inside it. Treating the whole string as a
50
+ // package name looks for node_modules/@teamscala/ui-foundation/theme/
51
+ // styles.css/package.json, which cannot exist — so EVERY subpath import
52
+ // fails and the styles bundle dies, taking the theme layer with it.
53
+ //
54
+ // A scoped name is the FIRST TWO segments (@scope/name); an unscoped name
55
+ // is the first. Everything after that is a path inside the package and is
56
+ // resolved directly — it names a file, so there is nothing to negotiate and
57
+ // no style entry to consult.
58
+ const segments = id.split("/");
59
+ const nameLength = id.startsWith("@") ? 2 : 1;
60
+ const packageName = segments.slice(0, nameLength).join("/");
61
+ const subpath = segments.slice(nameLength).join("/");
62
+
63
+ // Find node_modules/<packageName>/package.json by walking upward from the
64
+ // importing file's dir then cwd. Bun.resolve is not used: it hands back
65
+ // whatever the package's main is — for a normal JS package a .js entry,
66
+ // not the declared stylesheet — and an `exports` allow-list blocks the
67
+ // package.json subpath on exactly the CSS-only packages this must serve.
54
68
  const tried: string[] = [];
55
69
  for (const root of [base, cwd]) {
56
70
  let dir = root;
57
71
  for (;;) {
58
- const pkgPath = join(dir, "node_modules", id, "package.json");
72
+ const pkgPath = join(dir, "node_modules", packageName, "package.json");
59
73
  if (await Bun.file(pkgPath).exists()) {
74
+ const pkgDir = dirname(pkgPath);
60
75
  const pkg = await Bun.file(pkgPath).json();
61
- const entry: string | undefined =
62
- pkg.exports?.["."]?.style ?? pkg.style;
76
+ if (subpath) {
77
+ // THE EXPORTS MAP IS THE AUTHORITY ON WHERE A SUBPATH LIVES,
78
+ // and it commonly REMAPS. `@teamscala/ui-foundation` publishes
79
+ // "./theme/styles.css" -> "./src/theme/styles.css", so resolving
80
+ // the subpath literally against the package root looks for a
81
+ // file that has never existed there. Consult exports first and
82
+ // fall back to the literal path only for a package that
83
+ // declares none.
84
+ const exported = pkg.exports?.[`./${subpath}`];
85
+ const mapped: string | undefined =
86
+ typeof exported === "string"
87
+ ? exported
88
+ : (exported?.style ?? exported?.default);
89
+ const r = resolve(pkgDir, mapped ?? subpath);
90
+ if (!(await Bun.file(r).exists())) {
91
+ throw new Error(
92
+ `style import "${id}" resolves to ${r}, which does not exist` +
93
+ (mapped
94
+ ? ` (exports maps "./${subpath}" to "${mapped}")`
95
+ : ` (${packageName} declares no exports entry for "./${subpath}")`),
96
+ );
97
+ }
98
+ return { path: r, base: dirname(r), content: await Bun.file(r).text() };
99
+ }
100
+ // No subpath: the package itself must declare its stylesheet.
101
+ const entry: string | undefined = pkg.exports?.["."]?.style ?? pkg.style;
63
102
  if (!entry) {
64
103
  throw new Error(
65
104
  `style import "${id}" resolved to ${pkgPath} but the package declares no style entry (exports["."].style / style) — not a stylesheet package`,
66
105
  );
67
106
  }
68
- const r = resolve(dirname(pkgPath), entry);
107
+ const r = resolve(pkgDir, entry);
69
108
  return { path: r, base: dirname(r), content: await Bun.file(r).text() };
70
109
  }
71
110
  tried.push(pkgPath);
@@ -75,7 +114,7 @@ async function resolveStylesheetRaw(
75
114
  }
76
115
  }
77
116
  throw new Error(
78
- `style import "${id}" unresolved — no node_modules/${id}/package.json found walking up from ${base} or ${cwd} (${tried.length} location(s) tried)`,
117
+ `style import "${id}" unresolved — no node_modules/${packageName}/package.json found walking up from ${base} or ${cwd} (${tried.length} location(s) tried)`,
79
118
  );
80
119
  }
81
120
 
@@ -52,8 +52,7 @@ describe("interpolateMeta (resolver_input ref contract)", () => {
52
52
  });
53
53
 
54
54
  describe("resource-loader model capability", () => {
55
- test("an optional source still refuses a model absent from the generated client", async () => {
56
- const original = isServerClientRegistered() ? getServerClient() : null;
55
+ test("an optional source still refuses a model absent from the generated client", async () => { const original = isServerClientRegistered() ? getServerClient() : null;
57
56
  setServerClient({} as never);
58
57
  try {
59
58
  await expect(
@@ -104,3 +103,114 @@ describe("resource-loader model capability", () => {
104
103
  }
105
104
  });
106
105
  });
106
+
107
+ describe("required sources refuse unresolvable where refs", () => {
108
+ // The 2026-09-03 proposal outage class: interpolateTemplate DROPS a key
109
+ // whose ref resolves undefined, so a required source queries with a
110
+ // partial (or empty) filter — which matches an ARBITRARY row or none,
111
+ // serving a silent empty page instead of failing. Null is a real value
112
+ // (an unset column) and must keep flowing through.
113
+ const original = isServerClientRegistered() ? getServerClient() : null;
114
+ const capturingClient = (captured: { where: unknown }) => ({
115
+ builda_pages: {
116
+ findFirst: async (args: { where: unknown }) => {
117
+ captured.where = args.where;
118
+ return { id: "row" };
119
+ },
120
+ },
121
+ } as never);
122
+
123
+ test("a required source with an undefined ref throws naming it", async () => {
124
+ setServerClient(capturingClient({ where: null }));
125
+ try {
126
+ await expect(
127
+ resolveFromLoaderConfig(
128
+ {
129
+ sources: [
130
+ {
131
+ key: "page",
132
+ source: "orpc",
133
+ model: "builda_pages",
134
+ where: { id: ":proposal.page_id" },
135
+ optional: false,
136
+ },
137
+ ],
138
+ },
139
+ { id: "p1" },
140
+ ),
141
+ ).rejects.toThrow(/required source "page".*:proposal\.page_id.*undefined/);
142
+ } finally {
143
+ setServerClient(original as never);
144
+ }
145
+ });
146
+
147
+ test("an optional source with the same undefined ref still resolves null", async () => {
148
+ setServerClient({
149
+ builda_pages: { findFirst: async () => null },
150
+ } as never);
151
+ try {
152
+ await expect(
153
+ resolveFromLoaderConfig(
154
+ {
155
+ sources: [
156
+ {
157
+ key: "page",
158
+ source: "orpc",
159
+ model: "builda_pages",
160
+ where: { id: ":proposal.page_id" },
161
+ optional: true,
162
+ },
163
+ ],
164
+ },
165
+ { id: "p1" },
166
+ ),
167
+ ).resolves.toEqual({ page: null });
168
+ } finally {
169
+ setServerClient(original as never);
170
+ }
171
+ });
172
+
173
+ test("a resolved null flows through as a null filter on a required source", async () => {
174
+ const captured = { where: null as unknown };
175
+ // The first source resolves a row whose partner_id IS null — null is a
176
+ // real value flowing through interpolation, not an unresolved ref.
177
+ setServerClient({
178
+ builda_pages: {
179
+ findFirst: async (args: { where: unknown }) => {
180
+ captured.where = args.where;
181
+ return (args.where as { id: string }).id === "p1"
182
+ ? { id: "p1", partner_id: null }
183
+ : null;
184
+ },
185
+ },
186
+ } as never);
187
+ try {
188
+ await resolveFromLoaderConfig(
189
+ {
190
+ sources: [
191
+ {
192
+ key: "proposal",
193
+ source: "orpc",
194
+ model: "builda_pages",
195
+ where: { id: ":id" },
196
+ optional: false,
197
+ },
198
+ {
199
+ key: "partnerOrg",
200
+ source: "orpc",
201
+ model: "builda_pages",
202
+ where: { partner_id: ":proposal.partner_id" },
203
+ optional: false,
204
+ depends_on: ["proposal"],
205
+ },
206
+ ],
207
+ },
208
+ { id: "p1" },
209
+ );
210
+ } finally {
211
+ setServerClient(original as never);
212
+ }
213
+ // The partnerOrg source queried WITH { partner_id: null }, not refused.
214
+ expect(captured.where).toEqual({ partner_id: null });
215
+ });
216
+ });
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { loadRegistryConfig } from "@teamscala/db/registry/load-config";
15
+ import type { ResolverFnKey } from "@teamscala/db/registry/generated/resolver-fn";
15
16
  import { ResolverFnConfigSchema } from "@teamscala/db-validation/registry-schemas/resolver-fn";
16
17
  import { getServerClient } from "./page-server-orpc/server-client";
17
18
 
@@ -120,7 +121,7 @@ function toSelectMap(
120
121
  * hardcoded if(resolver_fn==='X') chain — adding a resolver is now a registry_edit row.
121
122
  */
122
123
  async function resolveByResolverFn(
123
- slug: string,
124
+ slug: ResolverFnKey,
124
125
  input: Record<string, unknown>,
125
126
  params: Record<string, unknown>,
126
127
  ): Promise<unknown> {
@@ -145,6 +146,40 @@ async function resolveByResolverFn(
145
146
  return fn({ input, client: await getServerClient(), params });
146
147
  }
147
148
 
149
+ /**
150
+ * Exact `:ref` strings inside a raw where/resolver_input whose value resolves
151
+ * to undefined — the keys interpolateTemplate DROPS. A dropped where key on a
152
+ * required source would query with a partial (or empty) filter, which matches
153
+ * an ARBITRARY row — worse than an error, so required sources refuse here
154
+ * instead (`a-component-may-not-report-a-state-it-has-not-verified`). Null is
155
+ * a real value (an unset column filtered as null) and never counts as broken.
156
+ */
157
+ function unresolvedTemplateRefs(
158
+ template: unknown,
159
+ params: Record<string, unknown>,
160
+ resolved: Record<string, unknown>,
161
+ ): string[] {
162
+ const broken: string[] = [];
163
+ const walk = (node: unknown): void => {
164
+ if (typeof node === "string") {
165
+ const exact = node.match(/^:([a-zA-Z0-9_.]+)$/);
166
+ if (exact && resolveParamRef(exact[1], params, resolved) === undefined) {
167
+ broken.push(exact[1]);
168
+ }
169
+ return;
170
+ }
171
+ if (Array.isArray(node)) {
172
+ for (const v of node) walk(v);
173
+ return;
174
+ }
175
+ if (node != null && typeof node === "object") {
176
+ for (const v of Object.values(node)) walk(v);
177
+ }
178
+ };
179
+ walk(template);
180
+ return broken;
181
+ }
182
+
148
183
  async function resolveSource(
149
184
  source: SourceConfig,
150
185
  params: Record<string, unknown>,
@@ -156,6 +191,14 @@ async function resolveSource(
156
191
  case "orpc":
157
192
  case "prisma": {
158
193
  if (!source.model) return null;
194
+ if (!source.optional && source.where) {
195
+ const broken = unresolvedTemplateRefs(source.where, params, resolved);
196
+ if (broken.length > 0) {
197
+ throw new Error(
198
+ `[resource_loader] required source "${source.key}": where ref(s) ${broken.map((ref) => `:${ref}`).join(", ")} resolved to undefined — refusing to query without them (a dropped filter silently matches an arbitrary row)`,
199
+ );
200
+ }
201
+ }
159
202
  const where = source.where
160
203
  ? (interpolateTemplate(source.where, params, resolved) as Record<
161
204
  string,
@@ -187,7 +230,11 @@ async function resolveSource(
187
230
  ) as Record<string, unknown>)
188
231
  : {};
189
232
 
190
- return resolveByResolverFn(source.resolver_fn ?? "", input, params);
233
+ return resolveByResolverFn(
234
+ source.resolver_fn as ResolverFnKey,
235
+ input,
236
+ params,
237
+ );
191
238
  }
192
239
  default:
193
240
  throw new Error(