5htp 0.5.9-6 → 0.5.9-7

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.
@@ -344,8 +344,17 @@ function Plugin(babel, { app, side, debug }: TOptions) {
344
344
  p.key.type === 'Identifier'
345
345
  &&
346
346
  p.value.type === 'CallExpression'
347
+ &&
348
+ // TODO: reliable way to know if it's a service
349
+ !(
350
+ p.value.callee.type === 'MemberExpression'
351
+ &&
352
+ p.value.callee.object.type === 'Identifier'
353
+ &&
354
+ p.value.callee.object.name === 'api'
355
+ )
347
356
  ) {
348
-
357
+
349
358
  // Pass request context as 2nd argument
350
359
  p.value.arguments = p.value.arguments.length === 0
351
360
  ? [ t.objectExpression([]), t.identifier('context') ]
package/compiler/index.ts CHANGED
@@ -294,9 +294,45 @@ declare module '@models/types' {
294
294
  declare module '@request' {
295
295
 
296
296
  }
297
+
298
+ declare namespace preact.JSX {
299
+ interface HTMLAttributes {
300
+ src?: string;
301
+ }
302
+ }
297
303
  `
298
304
  );
299
305
 
306
+ fs.outputFileSync(
307
+ path.join( app.paths.client.generated, 'context.ts'),
308
+ `// TODO: move it into core (but how to make sure usecontext returns ${appClassIdentifier}'s context ?)
309
+ import React from 'react';
310
+
311
+ import type ${appClassIdentifier}Server from '@/server/.generated/app';
312
+ import type { TRouterContext as TServerRouterRequestContext } from '@server/services/router/response';
313
+ import type { TRouterContext as TClientRouterRequestContext } from '@client/services/router/response';
314
+ import type ${appClassIdentifier}Client from '.';
315
+
316
+ // TO Fix: TClientRouterRequestContext is unable to get the right type of ${appClassIdentifier}Client["router"]
317
+ // (it gets ClientApplication instead of ${appClassIdentifier}Client)
318
+ type ClientRequestContext = TClientRouterRequestContext<${appClassIdentifier}Client["Router"], ${appClassIdentifier}Client>;
319
+ type ServerRequestContext = TServerRouterRequestContext<${appClassIdentifier}Server["Router"]>
320
+ type UniversalServices = ClientRequestContext | ServerRequestContext
321
+
322
+ // Non-universla services are flagged as potentially undefined
323
+ export type ClientContext = (
324
+ UniversalServices
325
+ &
326
+ Partial<Omit<ClientRequestContext, keyof UniversalServices>>
327
+ &
328
+ {
329
+ Router: ${appClassIdentifier}Client["Router"],
330
+ }
331
+ )
332
+
333
+ export const ReactClientContext = React.createContext<ClientContext>({} as ClientContext);
334
+ export default (): ClientContext => React.useContext<ClientContext>(ReactClientContext);`);
335
+
300
336
  fs.outputFileSync(
301
337
  path.join( app.paths.server.generated, 'app.ts'),
302
338
  `import { Application } from '@server/app/index';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "5htp",
3
3
  "description": "Convenient TypeScript framework designed for Performance and Productivity.",
4
- "version": "0.5.9-6",
4
+ "version": "0.5.9-7",
5
5
  "author": "Gaetan Le Gac (https://github.com/gaetanlegac)",
6
6
  "repository": "git://github.com/gaetanlegac/5htp.git",
7
7
  "license": "MIT",