@juo/blocks 1.1.0-alpha.4 → 1.1.0-alpha.5

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/core.js CHANGED
@@ -1349,10 +1349,138 @@ function createSubscriptionService(adapter) {
1349
1349
  };
1350
1350
  }
1351
1351
  const CustomerServiceContext = createContext("services/customer");
1352
- function createCustomerService() {
1352
+ function createCustomerService(adapter) {
1353
1353
  const current = d(null);
1354
- const service = { current };
1355
- return service;
1354
+ return {
1355
+ current,
1356
+ async getCurrent() {
1357
+ const result = await adapter.getCurrent();
1358
+ if (result._tag === "Success") current.value = result.data;
1359
+ return result;
1360
+ },
1361
+ getAll: () => adapter.getAll(),
1362
+ getById: (id) => adapter.getById(id),
1363
+ create: (data) => adapter.create(data),
1364
+ update: (id, data) => adapter.update(id, data),
1365
+ remove: (id) => adapter.remove(id)
1366
+ };
1367
+ }
1368
+ function createMockCustomerAdapter() {
1369
+ let customers = [
1370
+ {
1371
+ id: "customer-1",
1372
+ name: "Customer 1",
1373
+ metadata: { mealCount: 3 }
1374
+ },
1375
+ {
1376
+ id: "customer-2",
1377
+ name: "Customer 2",
1378
+ metadata: { mealCount: 4 }
1379
+ }
1380
+ ];
1381
+ return {
1382
+ async getCurrent() {
1383
+ return { _tag: "Success", data: customers[0] ?? null };
1384
+ },
1385
+ async getAll() {
1386
+ return { _tag: "Success", data: [...customers] };
1387
+ },
1388
+ async getById(id) {
1389
+ return {
1390
+ _tag: "Success",
1391
+ data: customers.find((c2) => c2.id === id) ?? null
1392
+ };
1393
+ },
1394
+ async create(data) {
1395
+ const customer = { id: `customer-${Date.now()}`, ...data };
1396
+ customers = [...customers, customer];
1397
+ return { _tag: "Success", data: customer };
1398
+ },
1399
+ async update(id, data) {
1400
+ const existing = customers.find((c2) => c2.id === id);
1401
+ if (!existing) return { _tag: "Failure", error: "Customer not found" };
1402
+ const updated = { ...existing, ...data };
1403
+ customers = customers.map((c2) => c2.id === id ? updated : c2);
1404
+ return { _tag: "Success", data: updated };
1405
+ },
1406
+ async remove(id) {
1407
+ customers = customers.filter((c2) => c2.id !== id);
1408
+ return { _tag: "Success", data: void 0 };
1409
+ }
1410
+ };
1411
+ }
1412
+ function createApiCustomerAdapter(fetcher) {
1413
+ return {
1414
+ async getCurrent() {
1415
+ try {
1416
+ const res = await fetcher("/customer/v1/customer");
1417
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1418
+ const data = await res.json();
1419
+ return { _tag: "Success", data };
1420
+ } catch (e2) {
1421
+ return { _tag: "Failure", error: e2 };
1422
+ }
1423
+ },
1424
+ async getAll() {
1425
+ try {
1426
+ const res = await fetcher("/customer/v1/customers");
1427
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1428
+ const data = await res.json();
1429
+ return { _tag: "Success", data };
1430
+ } catch (e2) {
1431
+ return { _tag: "Failure", error: e2 };
1432
+ }
1433
+ },
1434
+ async getById(id) {
1435
+ try {
1436
+ const res = await fetcher(`/customer/v1/customers/${id}`);
1437
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1438
+ const data = await res.json();
1439
+ return { _tag: "Success", data };
1440
+ } catch (e2) {
1441
+ return { _tag: "Failure", error: e2 };
1442
+ }
1443
+ },
1444
+ async create(data) {
1445
+ try {
1446
+ const res = await fetcher("/customer/v1/customers", {
1447
+ method: "POST",
1448
+ headers: { "Content-Type": "application/json" },
1449
+ body: JSON.stringify(data)
1450
+ });
1451
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1452
+ const created = await res.json();
1453
+ return { _tag: "Success", data: created };
1454
+ } catch (e2) {
1455
+ return { _tag: "Failure", error: e2 };
1456
+ }
1457
+ },
1458
+ async update(id, data) {
1459
+ try {
1460
+ const res = await fetcher(`/customer/v1/customers/${id}`, {
1461
+ method: "PATCH",
1462
+ headers: { "Content-Type": "application/json" },
1463
+ body: JSON.stringify(data)
1464
+ });
1465
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1466
+ const updated = await res.json();
1467
+ return { _tag: "Success", data: updated };
1468
+ } catch (e2) {
1469
+ return { _tag: "Failure", error: e2 };
1470
+ }
1471
+ },
1472
+ async remove(id) {
1473
+ try {
1474
+ const res = await fetcher(`/customer/v1/customers/${id}`, {
1475
+ method: "DELETE"
1476
+ });
1477
+ if (!res.ok) return { _tag: "Failure", error: await res.text() };
1478
+ return { _tag: "Success", data: void 0 };
1479
+ } catch (e2) {
1480
+ return { _tag: "Failure", error: e2 };
1481
+ }
1482
+ }
1483
+ };
1356
1484
  }
1357
1485
  function createMockOrderAdapter() {
1358
1486
  let orders = [
@@ -1993,6 +2121,7 @@ export {
1993
2121
  T2 as TranslationContext,
1994
2122
  W as WorkflowServiceContext,
1995
2123
  w as computed,
2124
+ createApiCustomerAdapter,
1996
2125
  createApiOrderAdapter,
1997
2126
  createApiSchedulesAdapter,
1998
2127
  createApiSubscriptionAdapter,
@@ -2002,6 +2131,7 @@ export {
2002
2131
  f as createCeRenderer,
2003
2132
  createContext,
2004
2133
  createCustomerService,
2134
+ createMockCustomerAdapter,
2005
2135
  createMockOrderAdapter,
2006
2136
  createMockProductAdapter,
2007
2137
  createMockSchedulesAdapter,
@@ -1,4 +1,4 @@
1
- import { ContextType } from '../../context';
2
- import { CustomerServiceContext } from './types';
3
- export declare function createCustomerService(): ContextType<typeof CustomerServiceContext>;
1
+ import { CustomerAdapter } from './adapter';
2
+ import { CustomerService } from './types';
3
+ export declare function createCustomerService(adapter: CustomerAdapter): CustomerService;
4
4
  //# sourceMappingURL=customerService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"customerService.d.ts","sourceRoot":"","sources":["../../../src/services/customer/customerService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGjD,wBAAgB,qBAAqB,IAAI,WAAW,CAAC,OAAO,sBAAsB,CAAC,CAMlF"}
1
+ {"version":3,"file":"customerService.d.ts","sourceRoot":"","sources":["../../../src/services/customer/customerService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAY,eAAe,EAAE,MAAM,SAAS,CAAC;AAEzD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,CAkB/E"}
@@ -1,3 +1,4 @@
1
1
  export { CustomerServiceContext, type CustomerService, type Customer, } from './types';
2
2
  export { createCustomerService, } from './customerService';
3
+ export { type CustomerAdapter, createMockCustomerAdapter, createApiCustomerAdapter, } from './adapter';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/customer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,eAAe,EACpB,KAAK,QAAQ,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,GACtB,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/customer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,KAAK,eAAe,EACpB,KAAK,QAAQ,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,KAAK,eAAe,EACpB,yBAAyB,EACzB,wBAAwB,GACzB,MAAM,WAAW,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { Signal } from '@preact/signals-core';
2
+ import { Result } from '../../utils';
2
3
  export type Customer = {
3
4
  id: string;
4
5
  name: string;
@@ -8,6 +9,12 @@ export type Customer = {
8
9
  export type PostableCustomer = Omit<Customer, "id">;
9
10
  export type CustomerService = {
10
11
  current: Signal<Customer | null>;
12
+ getCurrent(): Promise<Result<Customer | null>>;
13
+ getAll(): Promise<Result<Customer[]>>;
14
+ getById(id: string): Promise<Result<Customer | null>>;
15
+ create(data: PostableCustomer): Promise<Result<Customer>>;
16
+ update(id: string, data: Partial<PostableCustomer>): Promise<Result<Customer>>;
17
+ remove(id: string): Promise<Result>;
11
18
  };
12
19
  export declare const CustomerServiceContext: {
13
20
  __context__: CustomerService;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/customer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAEpD,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,EAAE,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;CAAsD,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/services/customer/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;AAEpD,MAAM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