@unisian/start 0.7.0 → 0.8.1

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/dist/serve.d.mts CHANGED
@@ -1,32 +1,25 @@
1
1
  import { reportBrowserError } from "./report-browser-error.mjs";
2
2
  import * as Schema from "effect/Schema";
3
3
  import { AnyContract, Capability, InputOf } from "@unisian/capability";
4
- import { RequestLogTags, RequestReference } from "@unisian/effect-observability";
5
- import { ShopifyAdmin, ShopifyLayerConfig } from "@unisian/shopify-admin";
6
- import { AuthenticatedShop, CurrentShop, ShopifyApp } from "@unisian/shopify-auth";
4
+ import { RequestLogTags, RequestReference, RunTags } from "@unisian/effect-observability";
7
5
  import * as Layer from "effect/Layer";
8
- import { ShopDomain } from "@unisian/shopify-sessions";
9
- import { HttpClient } from "effect/http";
10
6
  //#region src/serve.d.ts
11
7
  export interface ServeContext {
12
- readonly shopify: AuthenticatedShop;
13
8
  readonly log: RequestLogTags;
14
9
  }
15
- export interface ServeConfig<Services, ServicesError> extends ShopifyLayerConfig {
16
- readonly services?: Layer.Layer<Services, ServicesError> | undefined;
10
+ export interface Caller<Identity, IdentityError> {
11
+ readonly tags: RunTags;
12
+ readonly layer: Layer.Layer<Identity, IdentityError>;
17
13
  }
18
- export type Provided<Services> = CurrentShop | ShopifyAdmin | ShopifyApp | HttpClient.HttpClient | RequestReference | Services;
19
14
  export interface ServerFnCall<ContractType extends AnyContract, Context> {
20
15
  readonly data: InputOf<ContractType>["Type"];
21
- readonly context: Context;
16
+ readonly context: Context & ServeContext;
22
17
  readonly serverFnMeta: {
23
18
  readonly name: string;
24
19
  };
25
20
  }
26
- export declare const serveWith: <Context, Services, ServicesError>(callerOf: (context: Context) => {
27
- readonly shop: ShopDomain;
28
- readonly log: RequestLogTags;
29
- }, layerFor: (context: Context) => Layer.Layer<Services, ServicesError>) => <ContractType extends AnyContract, Requirements extends Services | CurrentShop | RequestReference>(capability: Capability<ContractType, Requirements>) => ({ data, context, serverFnMeta }: ServerFnCall<ContractType, Context>) => Promise<Schema.Json>;
30
- export declare const makeServe: <Services = never, ServicesError = never>(config: () => ServeConfig<Services, ServicesError>) => <ContractType extends AnyContract, Requirements extends (HttpClient.HttpClient | ShopifyAdmin | ShopifyApp | Exclude<Services, CurrentShop | RequestReference>) | CurrentShop | RequestReference>(capability: Capability<ContractType, Requirements>) => ({ data, context, serverFnMeta }: ServerFnCall<ContractType, ServeContext>) => Promise<Schema.Json>;
21
+ export declare const serveWith: <Context, Identity, IdentityError, Services, ServicesError>(callerOf: (context: Context) => Caller<Identity, IdentityError>, layerFor: (context: Context) => Layer.Layer<Services, ServicesError>) => <ContractType extends AnyContract, Requirements extends Identity | Services | RequestReference>(capability: Capability<ContractType, Requirements>) => ({ data, context, serverFnMeta }: ServerFnCall<ContractType, Context>) => Promise<Schema.Json>;
22
+ export declare function makeServe<Services = never, ServicesError = never>(services: () => Layer.Layer<Services, ServicesError>): ReturnType<typeof serveWith<ServeContext, never, never, Services, ServicesError>>;
23
+ export declare function makeServe<Context, Identity, IdentityError, Services = never, ServicesError = never>(services: () => Layer.Layer<Services, ServicesError>, caller: (context: Context) => Caller<Identity, IdentityError>): ReturnType<typeof serveWith<Context, Identity, IdentityError, Services, ServicesError>>;
31
24
  //#endregion
32
25
  export { reportBrowserError };
package/dist/serve.mjs CHANGED
@@ -3,8 +3,6 @@ import { serverFnNameFor } from "./function-id.mjs";
3
3
  import { reportBrowserError } from "./report-browser-error.mjs";
4
4
  import * as Schema from "effect/Schema";
5
5
  import { RequestReference, logFailure, runPromiseExit } from "@unisian/effect-observability";
6
- import { ShopifyAdmin, shopifyLayer } from "@unisian/shopify-admin";
7
- import { CurrentShop } from "@unisian/shopify-auth";
8
6
  import * as Effect from "effect/Effect";
9
7
  import * as Layer from "effect/Layer";
10
8
  //#region src/serve.ts
@@ -15,21 +13,22 @@ const serveWith = (callerOf, layerFor) => (capability) => {
15
13
  const serverFnName = serverFnNameFor(contract.name);
16
14
  return async ({ data, context, serverFnMeta }) => {
17
15
  if (serverFnMeta.name !== serverFnName) throw new Error(`${serverFnMeta.name} serves ${contract.name}; name it ${serverFnName} so its URL names the contract`);
18
- const { shop, log } = callerOf(context);
19
- const layer = Layer.mergeAll(layerFor(context), Layer.succeed(CurrentShop, { shop }), Layer.succeed(RequestReference, { reference: log.reference })).pipe(Layer.orDie);
16
+ const { log } = context;
17
+ const caller = callerOf(context);
18
+ const layer = Layer.mergeAll(layerFor(context), caller.layer, Layer.succeed(RequestReference, { reference: log.reference })).pipe(Layer.orDie);
20
19
  const exit = await capability.handler(data).pipe(Effect.flatMap((output) => Effect.orDie(encodeOutput(output))), Effect.provide(layer), Effect.tapCause((cause) => logFailure("server function", cause)), runPromiseExit(contract.name, {
21
- ...log,
22
- shop
20
+ ...caller.tags,
21
+ ...log
23
22
  }));
24
23
  return wire.encode(exit, log.reference);
25
24
  };
26
25
  };
27
- const makeServe = (config) => serveWith((context) => ({
28
- log: context.log,
29
- shop: context.shopify.shop
30
- }), (context) => {
31
- const { services, ...shopify } = config();
32
- return Layer.mergeAll(ShopifyAdmin.layer(context.shopify).pipe(Layer.provideMerge(shopifyLayer(shopify))), services ?? Layer.empty);
33
- });
26
+ const anonymous = {
27
+ layer: Layer.empty,
28
+ tags: {}
29
+ };
30
+ function makeServe(services, caller) {
31
+ return serveWith(caller ?? (() => anonymous), services);
32
+ }
34
33
  //#endregion
35
34
  export { makeServe, reportBrowserError, serveWith };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@unisian/start",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/baoagency/unisian-next.git",
7
+ "url": "git+https://github.com/baoagency/app-template.git",
8
8
  "directory": "packages/start"
9
9
  },
10
10
  "files": [
@@ -32,11 +32,8 @@
32
32
  "effect": "4.0.6",
33
33
  "react": "19.3.0",
34
34
  "vite": "npm:@voidzero-dev/vite-plus-core@1.1.0",
35
- "@unisian/capability": "0.7.0",
36
- "@unisian/shopify-auth": "0.7.0",
37
- "@unisian/shopify-sessions": "0.7.0",
38
- "@unisian/effect-observability": "0.7.0",
39
- "@unisian/shopify-admin": "0.7.0"
35
+ "@unisian/capability": "0.8.1",
36
+ "@unisian/effect-observability": "0.8.1"
40
37
  },
41
38
  "peerDependencies": {
42
39
  "@tanstack/react-query": "^5.104.1",
@@ -45,11 +42,8 @@
45
42
  "@tanstack/react-start": "^1.168.60",
46
43
  "effect": "^4.0.2",
47
44
  "react": "^19.3.0",
48
- "@unisian/capability": "0.7.0",
49
- "@unisian/effect-observability": "0.7.0",
50
- "@unisian/shopify-admin": "0.7.0",
51
- "@unisian/shopify-sessions": "0.7.0",
52
- "@unisian/shopify-auth": "0.7.0"
45
+ "@unisian/effect-observability": "0.8.1",
46
+ "@unisian/capability": "0.8.1"
53
47
  },
54
48
  "scripts": {}
55
49
  }