@supacloud/compiler 0.27.1 → 0.27.3

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.
Files changed (3) hide show
  1. package/dist/cli.js +33 -11
  2. package/dist/index.js +33 -11
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -6135,9 +6135,7 @@ function parseController(input, ctx) {
6135
6135
  if (importPath)
6136
6136
  schemaImports[schemaExpr.text] = importPath;
6137
6137
  const declaration = resolveDeclaration(schemaExpr, ctx)[0];
6138
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(schemaExpr));
6139
- const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6140
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6138
+ const opaque = isOpaqueSchema(schemaExpr, declaration, ctx);
6141
6139
  (route.schemaKinds ??= {})[field] = opaque ? "opaque" : "declared";
6142
6140
  }
6143
6141
  }
@@ -6192,9 +6190,7 @@ function parseController(input, ctx) {
6192
6190
  if (importPath)
6193
6191
  schemaImports[schemaExpr.text] = importPath;
6194
6192
  const declaration = resolveDeclaration(schemaExpr, ctx)[0];
6195
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(schemaExpr));
6196
- const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6197
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6193
+ const opaque = isOpaqueSchema(schemaExpr, declaration, ctx);
6198
6194
  const previousKind = route.schemaKinds?.response;
6199
6195
  (route.schemaKinds ??= {}).response = opaque || previousKind === "opaque" ? "opaque" : "declared";
6200
6196
  }
@@ -6368,10 +6364,36 @@ function jobOptionError(ctx, code, message, node, errorCode, suggestion) {
6368
6364
  });
6369
6365
  }
6370
6366
  function jobSchemaKind(identifier, declaration, ctx) {
6371
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(identifier));
6372
- const initializer = ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6373
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6374
- return opaque ? "opaque" : "declared";
6367
+ return isOpaqueSchema(identifier, declaration, ctx) ? "opaque" : "declared";
6368
+ }
6369
+ function isOpaqueSchema(identifier, declaration, ctx) {
6370
+ function opaque(type, seen) {
6371
+ if (seen.has(type))
6372
+ return false;
6373
+ const nextSeen = new Set(seen).add(type);
6374
+ const kindProperty = type.getProperty("~kind");
6375
+ const kind = kindProperty && ctx.checker.getTypeOfSymbolAtLocation(kindProperty, identifier);
6376
+ if (kind?.isStringLiteral()) {
6377
+ if (kind.value === "Unknown" || kind.value === "Any")
6378
+ return true;
6379
+ if (kind.value === "Union" || kind.value === "Intersect") {
6380
+ const property = type.getProperty(kind.value === "Union" ? "anyOf" : "allOf");
6381
+ if (!property)
6382
+ return true;
6383
+ const members = ctx.checker.getIndexTypeOfType(ctx.checker.getTypeOfSymbolAtLocation(property, identifier), ts4.IndexKind.Number);
6384
+ if (!members)
6385
+ return true;
6386
+ const branches = members.isUnion() ? members.types : [members];
6387
+ return kind.value === "Union" ? branches.some((branch) => opaque(branch, nextSeen)) : branches.every((branch) => opaque(branch, nextSeen));
6388
+ }
6389
+ return false;
6390
+ }
6391
+ return /^T(?:Unknown|Any)\b/.test(ctx.checker.typeToString(type));
6392
+ }
6393
+ if (opaque(ctx.checker.getTypeAtLocation(identifier), new Set))
6394
+ return true;
6395
+ const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6396
+ return Boolean(initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text));
6375
6397
  }
6376
6398
  function checkedRpc(meta, ctx) {
6377
6399
  const expression = getProp(meta, "rpc");
@@ -16652,7 +16674,7 @@ function migrationDependencies() {
16652
16674
  return {
16653
16675
  "@supacloud/app": "0.18.0",
16654
16676
  "@supacloud/compiler": compilerVersion(),
16655
- "@supacloud/elysia": "0.20.0",
16677
+ "@supacloud/elysia": "0.20.1",
16656
16678
  elysia: "2.0.0-beta.19",
16657
16679
  typescript: "7.0.2"
16658
16680
  };
package/dist/index.js CHANGED
@@ -6130,9 +6130,7 @@ function parseController(input, ctx) {
6130
6130
  if (importPath)
6131
6131
  schemaImports[schemaExpr.text] = importPath;
6132
6132
  const declaration = resolveDeclaration(schemaExpr, ctx)[0];
6133
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(schemaExpr));
6134
- const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6135
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6133
+ const opaque = isOpaqueSchema(schemaExpr, declaration, ctx);
6136
6134
  (route.schemaKinds ??= {})[field] = opaque ? "opaque" : "declared";
6137
6135
  }
6138
6136
  }
@@ -6187,9 +6185,7 @@ function parseController(input, ctx) {
6187
6185
  if (importPath)
6188
6186
  schemaImports[schemaExpr.text] = importPath;
6189
6187
  const declaration = resolveDeclaration(schemaExpr, ctx)[0];
6190
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(schemaExpr));
6191
- const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6192
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6188
+ const opaque = isOpaqueSchema(schemaExpr, declaration, ctx);
6193
6189
  const previousKind = route.schemaKinds?.response;
6194
6190
  (route.schemaKinds ??= {}).response = opaque || previousKind === "opaque" ? "opaque" : "declared";
6195
6191
  }
@@ -6363,10 +6359,36 @@ function jobOptionError(ctx, code, message, node, errorCode, suggestion) {
6363
6359
  });
6364
6360
  }
6365
6361
  function jobSchemaKind(identifier, declaration, ctx) {
6366
- const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(identifier));
6367
- const initializer = ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6368
- const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
6369
- return opaque ? "opaque" : "declared";
6362
+ return isOpaqueSchema(identifier, declaration, ctx) ? "opaque" : "declared";
6363
+ }
6364
+ function isOpaqueSchema(identifier, declaration, ctx) {
6365
+ function opaque(type, seen) {
6366
+ if (seen.has(type))
6367
+ return false;
6368
+ const nextSeen = new Set(seen).add(type);
6369
+ const kindProperty = type.getProperty("~kind");
6370
+ const kind = kindProperty && ctx.checker.getTypeOfSymbolAtLocation(kindProperty, identifier);
6371
+ if (kind?.isStringLiteral()) {
6372
+ if (kind.value === "Unknown" || kind.value === "Any")
6373
+ return true;
6374
+ if (kind.value === "Union" || kind.value === "Intersect") {
6375
+ const property = type.getProperty(kind.value === "Union" ? "anyOf" : "allOf");
6376
+ if (!property)
6377
+ return true;
6378
+ const members = ctx.checker.getIndexTypeOfType(ctx.checker.getTypeOfSymbolAtLocation(property, identifier), ts4.IndexKind.Number);
6379
+ if (!members)
6380
+ return true;
6381
+ const branches = members.isUnion() ? members.types : [members];
6382
+ return kind.value === "Union" ? branches.some((branch) => opaque(branch, nextSeen)) : branches.every((branch) => opaque(branch, nextSeen));
6383
+ }
6384
+ return false;
6385
+ }
6386
+ return /^T(?:Unknown|Any)\b/.test(ctx.checker.typeToString(type));
6387
+ }
6388
+ if (opaque(ctx.checker.getTypeAtLocation(identifier), new Set))
6389
+ return true;
6390
+ const initializer = declaration && ts4.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
6391
+ return Boolean(initializer && ts4.isCallExpression(initializer) && ts4.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text));
6370
6392
  }
6371
6393
  function checkedRpc(meta, ctx) {
6372
6394
  const expression = getProp(meta, "rpc");
@@ -16452,7 +16474,7 @@ function migrationDependencies() {
16452
16474
  return {
16453
16475
  "@supacloud/app": "0.18.0",
16454
16476
  "@supacloud/compiler": compilerVersion(),
16455
- "@supacloud/elysia": "0.20.0",
16477
+ "@supacloud/elysia": "0.20.1",
16456
16478
  elysia: "2.0.0-beta.19",
16457
16479
  typescript: "7.0.2"
16458
16480
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/compiler",
3
- "version": "0.27.1",
3
+ "version": "0.27.3",
4
4
  "description": "Static compiler for @supacloud/app metadata: builds the application graph from AST, validates it, and generates reflection-free factory code",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",