zitejs 0.9.16 → 0.9.19

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.
@@ -220,7 +220,13 @@ function createAliasPlugin(opts) {
220
220
  /^zitejs\/backend\/base$/,
221
221
  ];
222
222
  for (const filter of sdkSources) {
223
- build.onResolve({ filter }, () => {
223
+ build.onResolve({ filter }, (args) => {
224
+ // When .zite/backend.ts imports from zitejs/backend/base, mark it
225
+ // external to break the cycle — the wrapper re-declares everything
226
+ // it needs so the import is only used at typecheck time.
227
+ if (args.importer && args.importer.endsWith('.zite/backend.ts')) {
228
+ return { path: 'zitejs/backend', external: true };
229
+ }
224
230
  if (opts.sdkPath)
225
231
  return { path: path.resolve(opts.sdkPath) };
226
232
  if (opts.baseDir) {
@@ -37,13 +37,11 @@ function resolveBaseId() {
37
37
  }
38
38
  async function runSync() {
39
39
  if (!TOKEN) {
40
- console.error('Error: ZITE_DB_TOKEN is required.');
41
- process.exit(1);
40
+ throw new Error('ZITE_DB_TOKEN is required.');
42
41
  }
43
42
  const baseId = resolveBaseId();
44
43
  if (!baseId) {
45
- console.error('Error: Could not determine base ID.');
46
- process.exit(1);
44
+ throw new Error('Could not determine base ID.');
47
45
  }
48
46
  console.log(`Syncing database ${baseId}...`);
49
47
  const base = await fetchBaseMetadata(baseId);
@@ -220,11 +220,17 @@ function generateBackendWrapperTs() {
220
220
  '// Auto-generated type-narrowing wrapper. Do not edit manually.',
221
221
  '// Re-exports createEndpoint with context.user typed to the app User.',
222
222
  '',
223
- "import { ZiteError } from 'zitejs/backend/base';",
224
223
  "import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext } from 'zitejs/backend/base';",
225
224
  "import type { User } from './user';",
226
225
  '',
227
- 'export { ZiteError };',
226
+ 'export class ZiteError extends Error {',
227
+ ' statusCode: number;',
228
+ ' constructor(message: string, options?: { statusCode?: number }) {',
229
+ ' super(message);',
230
+ " this.name = 'ZiteError';",
231
+ ' this.statusCode = options?.statusCode ?? 500;',
232
+ ' }',
233
+ '}',
228
234
  '',
229
235
  'export interface ZiteRequestContext extends Omit<_ZiteRequestContext, "user"> {',
230
236
  ' user: User;',
@@ -184,7 +184,13 @@ function createAliasPlugin(opts) {
184
184
  /^zitejs\/backend\/base$/,
185
185
  ];
186
186
  for (const filter of sdkSources) {
187
- build.onResolve({ filter }, () => {
187
+ build.onResolve({ filter }, (args) => {
188
+ // When .zite/backend.ts imports from zitejs/backend/base, mark it
189
+ // external to break the cycle — the wrapper re-declares everything
190
+ // it needs so the import is only used at typecheck time.
191
+ if (args.importer && args.importer.endsWith('.zite/backend.ts')) {
192
+ return { path: 'zitejs/backend', external: true };
193
+ }
188
194
  if (opts.sdkPath)
189
195
  return { path: path.resolve(opts.sdkPath) };
190
196
  if (opts.baseDir) {
@@ -33,13 +33,11 @@ function resolveBaseId() {
33
33
  }
34
34
  export async function runSync() {
35
35
  if (!TOKEN) {
36
- console.error('Error: ZITE_DB_TOKEN is required.');
37
- process.exit(1);
36
+ throw new Error('ZITE_DB_TOKEN is required.');
38
37
  }
39
38
  const baseId = resolveBaseId();
40
39
  if (!baseId) {
41
- console.error('Error: Could not determine base ID.');
42
- process.exit(1);
40
+ throw new Error('Could not determine base ID.');
43
41
  }
44
42
  console.log(`Syncing database ${baseId}...`);
45
43
  const base = await fetchBaseMetadata(baseId);
@@ -209,11 +209,17 @@ export function generateBackendWrapperTs() {
209
209
  '// Auto-generated type-narrowing wrapper. Do not edit manually.',
210
210
  '// Re-exports createEndpoint with context.user typed to the app User.',
211
211
  '',
212
- "import { ZiteError } from 'zitejs/backend/base';",
213
212
  "import type { ZiteRequestContext as _ZiteRequestContext, ZiteScheduledContext as _ZiteScheduledContext } from 'zitejs/backend/base';",
214
213
  "import type { User } from './user';",
215
214
  '',
216
- 'export { ZiteError };',
215
+ 'export class ZiteError extends Error {',
216
+ ' statusCode: number;',
217
+ ' constructor(message: string, options?: { statusCode?: number }) {',
218
+ ' super(message);',
219
+ " this.name = 'ZiteError';",
220
+ ' this.statusCode = options?.statusCode ?? 500;',
221
+ ' }',
222
+ '}',
217
223
  '',
218
224
  'export interface ZiteRequestContext extends Omit<_ZiteRequestContext, "user"> {',
219
225
  ' user: User;',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zitejs",
3
- "version": "0.9.16",
3
+ "version": "0.9.19",
4
4
  "description": "The Zite framework — build apps on Zite Database",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/runtime/index.js",