@tallyui/core 0.2.0 → 2.0.0
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/LICENSE +21 -0
- package/dist/index.d.ts +540 -8
- package/dist/index.js +294 -4
- package/dist/rxdb/index.d.ts +41 -0
- package/dist/rxdb/index.js +26 -0
- package/package.json +27 -3
- package/src/commands.ts +32 -0
- package/src/context/connector-context.tsx +49 -4
- package/src/index.ts +41 -0
- package/src/money.ts +142 -0
- package/src/replication/combine.ts +73 -0
- package/src/replication/reconcile-feed.ts +79 -0
- package/src/rxdb/index.ts +4 -0
- package/src/rxdb/read-fresh.ts +36 -0
- package/src/rxdb/watch-fresh.ts +19 -0
- package/src/sign-in.ts +21 -0
- package/src/stock-overlay.ts +35 -0
- package/src/store-settings.ts +29 -0
- package/src/types/commands.ts +107 -0
- package/src/types/connector.ts +70 -0
- package/src/types/index.ts +16 -1
- package/src/types/money.ts +33 -0
- package/src/types/reconcile.ts +43 -0
- package/src/types/replication.ts +6 -0
- package/src/types/stock.ts +18 -0
- package/src/types/store-settings.ts +23 -0
- package/src/types/traits/product.ts +55 -6
- package/src/utils/compare-ids.ts +16 -0
- package/src/variants.ts +14 -0
- package/src/__tests__/connector-context.test.tsx +0 -100
- package/src/types/replication.test-d.ts +0 -20
package/src/types/index.ts
CHANGED
|
@@ -11,6 +11,21 @@ export type {
|
|
|
11
11
|
|
|
12
12
|
export type { ReplicationAdapter } from './replication';
|
|
13
13
|
|
|
14
|
-
export type {
|
|
14
|
+
export type { FingerprintReconcileAdapter, IdReconcileAdapter, StockReconcileAdapter } from './reconcile';
|
|
15
|
+
|
|
16
|
+
export type { StoreSettings, StoreSettingsChoice } from './store-settings';
|
|
17
|
+
|
|
18
|
+
export type { ProductTraits, TraitContext, VariantSummary } from './traits/product';
|
|
19
|
+
|
|
20
|
+
export type { Money, ProductPrice, ResolvedPrice } from './money';
|
|
21
|
+
|
|
22
|
+
export type { StockLevel, StockStatus } from './stock';
|
|
15
23
|
|
|
16
24
|
export type { CustomerTraits } from './traits/customer';
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
CommandType, CommandEnvelope, CommandStatus, CommandServerRefs,
|
|
28
|
+
CommandWarning, CommandError, CommandResult, OrderCreateLine,
|
|
29
|
+
PaymentMethodKind, OrderCreatePayment, OrderCreatePayload,
|
|
30
|
+
CommandBatchRequest, CommandBatchResponse,
|
|
31
|
+
} from './commands';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A monetary amount in integer minor units (cents for EUR/USD, yen for JPY)
|
|
3
|
+
* with its ISO 4217 currency code. Integers keep arithmetic exact, and the
|
|
4
|
+
* code travels with the amount so nothing assumes a store-wide currency.
|
|
5
|
+
*/
|
|
6
|
+
export interface Money {
|
|
7
|
+
/** Integer amount in the currency's minor unit, e.g. 1250 for €12.50. */
|
|
8
|
+
amount: number;
|
|
9
|
+
/** Upper-case ISO 4217 code, e.g. 'EUR'. 'XXX' when the backend gives none. */
|
|
10
|
+
currency: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* One entry in a product's price list.
|
|
15
|
+
*
|
|
16
|
+
* `base` is the everyday price. `sale` is a temporary reduction that replaces
|
|
17
|
+
* the base price in the same currency while it applies. Backends express
|
|
18
|
+
* sales differently (WooCommerce sale_price, Medusa sale price lists, Shopify
|
|
19
|
+
* compare_at_price) and each connector maps its own form into these entries,
|
|
20
|
+
* so components never need regular/sale/on-sale flags.
|
|
21
|
+
*/
|
|
22
|
+
export interface ProductPrice extends Money {
|
|
23
|
+
kind: 'base' | 'sale';
|
|
24
|
+
/** Set when the backend says so for this price; it wins over the store-level `pricesIncludeTax`. Undefined: use the store-level setting. */
|
|
25
|
+
taxInclusive?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The price to charge, and the price it replaces when a sale applies; each keeps its source's `taxInclusive` when set. */
|
|
29
|
+
export interface ResolvedPrice {
|
|
30
|
+
current: Money & { taxInclusive?: boolean };
|
|
31
|
+
/** Set only when a sale price applies: the base price it replaces. */
|
|
32
|
+
was?: Money & { taxInclusive?: boolean };
|
|
33
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SyncContext } from './connector';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Re-reads stock from the backend, because replication misses stock changes
|
|
5
|
+
* that bump no product timestamp (ADR-060). The runner stores `fetchPages`
|
|
6
|
+
* output in the non-replicated `stock_levels` collection; readers merge it
|
|
7
|
+
* into a read-only view of each product with `overlay`. Nothing is written
|
|
8
|
+
* into the replicated products.
|
|
9
|
+
*/
|
|
10
|
+
export interface StockReconcileAdapter<Doc = any> {
|
|
11
|
+
/** Current stock, one backend request per page, keyed as the connector chooses (variant, inventory item). */
|
|
12
|
+
fetchPages(context: SyncContext): AsyncIterable<Map<string, unknown>>;
|
|
13
|
+
/**
|
|
14
|
+
* Pure: the fields of `doc` that `stock` changes, or undefined when nothing
|
|
15
|
+
* differs. Keys absent from `stock` are left alone. The result is merged
|
|
16
|
+
* into a read-only view of the document and never written.
|
|
17
|
+
*/
|
|
18
|
+
overlay(doc: Doc, stock: Map<string, unknown>): Partial<Doc> | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Catches a deleted product or a deleted variant that replication misses (ADR-060). Nothing is written locally: `enqueue` hands disagreeing documents to a `createReconcileFeed` pull adapter instead. */
|
|
22
|
+
export interface IdReconcileAdapter<Doc = any> {
|
|
23
|
+
/** Every live product with its live variant ids, one backend request per page. */
|
|
24
|
+
fetchPages(context: SyncContext): AsyncIterable<Array<{ id: string; variantIds: string[] }>>;
|
|
25
|
+
/** The variant ids a local product document lists. */
|
|
26
|
+
variantIds(doc: Doc): string[];
|
|
27
|
+
/** Hand local documents that disagree with the backend to the collection's pull (see createReconcileFeed). */
|
|
28
|
+
enqueue(entries: Array<{ id: string; local: Doc }>): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Re-delivers products whose remote fingerprint differs from the local one (ADR-060). */
|
|
32
|
+
export interface FingerprintReconcileAdapter<Doc = any> {
|
|
33
|
+
/** Remote fingerprints by product id, one backend request per page. Products the backend doesn't report are left alone. */
|
|
34
|
+
fetchPages(context: SyncContext): AsyncIterable<Map<string, string>>;
|
|
35
|
+
/** The same fingerprint computed from a local product document. */
|
|
36
|
+
fingerprint(doc: Doc): string;
|
|
37
|
+
/**
|
|
38
|
+
* Hands products to the collection's pull (the reconcile feed). `refreshOnly`
|
|
39
|
+
* marks an entry so a missing product is skipped, never tombstoned: only the
|
|
40
|
+
* id reconcile, with its mass-delete brake, may delete.
|
|
41
|
+
*/
|
|
42
|
+
enqueue(entries: Array<{ id: string; local: Doc; refreshOnly?: boolean }>): void;
|
|
43
|
+
}
|
package/src/types/replication.ts
CHANGED
|
@@ -26,6 +26,12 @@ export interface ReplicationAdapter<RxDocType, CheckpointType = any> {
|
|
|
26
26
|
checkpoint: CheckpointType;
|
|
27
27
|
}>;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Fresh install only: the checkpoint this feed starts from instead of a full first pass,
|
|
31
|
+
* read before any feed runs (combinePullAdapters). Absent: a full first pass, as today.
|
|
32
|
+
*/
|
|
33
|
+
seedCheckpoint?: (context: SyncContext) => Promise<CheckpointType>;
|
|
34
|
+
|
|
29
35
|
/**
|
|
30
36
|
* Optional real-time event stream.
|
|
31
37
|
* Emit { documents, checkpoint } for live updates,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Backend-neutral stock state.
|
|
3
|
+
*
|
|
4
|
+
* - `in_stock`: sellable now. `quantity` is set when the backend tracks it.
|
|
5
|
+
* - `out_of_stock`: tracked and none left; not sellable.
|
|
6
|
+
* - `backorder`: none left but the backend accepts orders anyway.
|
|
7
|
+
* - `unknown`: the backend did not say.
|
|
8
|
+
*
|
|
9
|
+
* `quantity` is undefined when stock is not tracked, which is different from
|
|
10
|
+
* a tracked quantity of 0.
|
|
11
|
+
*/
|
|
12
|
+
export type StockStatus = 'in_stock' | 'out_of_stock' | 'backorder' | 'unknown';
|
|
13
|
+
|
|
14
|
+
export interface StockLevel {
|
|
15
|
+
status: StockStatus;
|
|
16
|
+
/** Units on hand, when tracked. May be negative on backorder. */
|
|
17
|
+
quantity?: number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** What the POS needs from the store's own settings (TV4). Read once after sign-in; the app feeds all three consumers from it. */
|
|
2
|
+
export interface StoreSettings {
|
|
3
|
+
/** ISO 4217, upper case (the currency prices are sold in). */
|
|
4
|
+
currency: string;
|
|
5
|
+
/** Whether the store's catalogue prices include tax. It feeds both the connector's traits and the POS TaxProvider, so the two cannot disagree. */
|
|
6
|
+
pricesIncludeTax: boolean;
|
|
7
|
+
/** Tax rates for the store's location as integer parts per million (25% = 250000), keyed by the backend's tax class; `default` applies to a product with no class. Always integers: a connector rounds a backend's decimal rate once, at its edge. Structurally the same as @tallyui/pos's TaxRateMap. */
|
|
8
|
+
taxRatesPpm: { default: number; [taxClass: string]: number };
|
|
9
|
+
/** Connector-specific and opaque to the app: what the connector needs to price documents. The app passes it back to the connector unchanged, and never logs it. */
|
|
10
|
+
pricingContext?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Picks among several regions, countries or sales channels when the store has more than one.
|
|
15
|
+
* The app persists the choice per store, in its own settings, so it is asked once. A stored
|
|
16
|
+
* choice that no longer resolves (for example, the region was deleted) raises `choice_required`
|
|
17
|
+
* again instead of failing. Backends without the concept ignore a field.
|
|
18
|
+
*/
|
|
19
|
+
export interface StoreSettingsChoice {
|
|
20
|
+
region?: string;
|
|
21
|
+
country?: string;
|
|
22
|
+
channel?: string;
|
|
23
|
+
}
|
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
import type { ProductPrice } from '../money';
|
|
2
|
+
import type { StockLevel } from '../stock';
|
|
3
|
+
|
|
4
|
+
/** One purchasable variant of a product, in backend-neutral terms. */
|
|
5
|
+
export interface VariantSummary {
|
|
6
|
+
/** Backend variant id; the id sent in order lines. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Variant label, e.g. 'S / White'; undefined when the backend has none. */
|
|
9
|
+
title?: string;
|
|
10
|
+
sku?: string;
|
|
11
|
+
/** First non-empty of the backend's barcode fields. */
|
|
12
|
+
barcode?: string;
|
|
13
|
+
prices: ProductPrice[];
|
|
14
|
+
stock: StockLevel;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Store-level facts a connector may need to interpret a raw document, for
|
|
19
|
+
* backends whose documents omit them (WooCommerce product prices carry no
|
|
20
|
+
* currency).
|
|
21
|
+
*/
|
|
22
|
+
export interface TraitContext {
|
|
23
|
+
/** The store's ISO 4217 currency code. */
|
|
24
|
+
currency?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
1
27
|
/**
|
|
2
28
|
* Product traits — the stable interface that UI components program against.
|
|
3
29
|
*
|
|
@@ -7,6 +33,10 @@
|
|
|
7
33
|
* Vendure, Shopify, etc.
|
|
8
34
|
*
|
|
9
35
|
* The generic `Doc` type is the connector's raw RxDB document type.
|
|
36
|
+
*
|
|
37
|
+
* Price and stock are read through the backend-neutral `getPrices` and
|
|
38
|
+
* `getStock`. The older string-price and WooCommerce-style stock accessors
|
|
39
|
+
* remain for existing consumers and are deprecated.
|
|
10
40
|
*/
|
|
11
41
|
export interface ProductTraits<Doc = any> {
|
|
12
42
|
/** Product display name */
|
|
@@ -15,16 +45,29 @@ export interface ProductTraits<Doc = any> {
|
|
|
15
45
|
/** SKU / stock keeping unit */
|
|
16
46
|
getSku: (doc: Doc) => string | undefined;
|
|
17
47
|
|
|
18
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* The product's price list: base prices, plus sale prices while a sale
|
|
50
|
+
* applies, per currency. Pass the list to `resolvePrice` for the price to
|
|
51
|
+
* charge. For variable products this describes the default variant.
|
|
52
|
+
*/
|
|
53
|
+
getPrices: (doc: Doc, context?: TraitContext) => ProductPrice[];
|
|
54
|
+
|
|
55
|
+
/** Stock state of the whole product across its variants; `quantity` is the total on hand when every variant is tracked, else undefined. */
|
|
56
|
+
getStock: (doc: Doc) => StockLevel;
|
|
57
|
+
|
|
58
|
+
/** All purchasable variants, in id order (connectors store variants sorted by id). Optional: connectors without variant support omit it. */
|
|
59
|
+
getVariants?: (doc: Doc, context?: TraitContext) => VariantSummary[];
|
|
60
|
+
|
|
61
|
+
/** @deprecated Use `getPrices` with `resolvePrice`. */
|
|
19
62
|
getPrice: (doc: Doc) => string | undefined;
|
|
20
63
|
|
|
21
|
-
/** Regular (non-sale) price */
|
|
64
|
+
/** Regular (non-sale) price. @deprecated Use `getPrices` with `resolvePrice`. */
|
|
22
65
|
getRegularPrice: (doc: Doc) => string | undefined;
|
|
23
66
|
|
|
24
|
-
/** Sale price, if on sale */
|
|
67
|
+
/** Sale price, if on sale. @deprecated Use `getPrices` with `resolvePrice`. */
|
|
25
68
|
getSalePrice: (doc: Doc) => string | undefined;
|
|
26
69
|
|
|
27
|
-
/** Whether the product is currently on sale */
|
|
70
|
+
/** Whether the product is currently on sale. @deprecated Use `getPrices` with `resolvePrice`. */
|
|
28
71
|
isOnSale: (doc: Doc) => boolean;
|
|
29
72
|
|
|
30
73
|
/** Primary image URL */
|
|
@@ -36,15 +79,21 @@ export interface ProductTraits<Doc = any> {
|
|
|
36
79
|
/** Short description / excerpt */
|
|
37
80
|
getDescription: (doc: Doc) => string | undefined;
|
|
38
81
|
|
|
39
|
-
/** Stock status */
|
|
82
|
+
/** Stock status. @deprecated Use `getStock`. */
|
|
40
83
|
getStockStatus: (doc: Doc) => 'instock' | 'outofstock' | 'onbackorder' | 'unknown';
|
|
41
84
|
|
|
42
|
-
/** Stock quantity (null if not tracked) */
|
|
85
|
+
/** Stock quantity (null if not tracked). @deprecated Use `getStock`. */
|
|
43
86
|
getStockQuantity: (doc: Doc) => number | null;
|
|
44
87
|
|
|
45
88
|
/** Whether this product has variants/variations */
|
|
46
89
|
hasVariants: (doc: Doc) => boolean;
|
|
47
90
|
|
|
91
|
+
/** Whether the product may be sold at the register now: published/active, not a draft, archived or disabled. */
|
|
92
|
+
isSellable: (doc: Doc) => boolean;
|
|
93
|
+
|
|
94
|
+
/** Number of purchasable variants; 1 for a simple product. */
|
|
95
|
+
getVariantCount: (doc: Doc) => number;
|
|
96
|
+
|
|
48
97
|
/** Product type (simple, variable, etc. — connector-specific but useful for UI hints) */
|
|
49
98
|
getType: (doc: Doc) => string;
|
|
50
99
|
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const INTEGER_STRING = /^\d+$/;
|
|
2
|
+
|
|
3
|
+
/** Orders backend ids: numerically when both are integer strings (Vendure '9' < '10', compared with BigInt so long ids stay exact), with ties in numeric value (e.g. '01' vs '1') broken by plain string order; an integer id always sorts before a non-integer one; otherwise (neither is an integer string) by plain string order (not `localeCompare`, which is locale-dependent). This is a total order, so sorting is consistent regardless of input order. */
|
|
4
|
+
export function compareIds(a: string | number, b: string | number): number {
|
|
5
|
+
const sa = String(a);
|
|
6
|
+
const sb = String(b);
|
|
7
|
+
const aNum = INTEGER_STRING.test(sa);
|
|
8
|
+
const bNum = INTEGER_STRING.test(sb);
|
|
9
|
+
if (aNum && bNum) {
|
|
10
|
+
const diff = BigInt(sa) - BigInt(sb);
|
|
11
|
+
if (diff !== 0n) return diff < 0n ? -1 : 1;
|
|
12
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
13
|
+
}
|
|
14
|
+
if (aNum !== bNum) return aNum ? -1 : 1;
|
|
15
|
+
return sa < sb ? -1 : sa > sb ? 1 : 0;
|
|
16
|
+
}
|
package/src/variants.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { VariantSummary } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The variant whose barcode or SKU equals `code`, compared after trimming
|
|
5
|
+
* both sides and ignoring case. A barcode match wins over a SKU match. When
|
|
6
|
+
* several variants match the same way, the first one wins. Returns undefined
|
|
7
|
+
* for an empty code or no match.
|
|
8
|
+
*/
|
|
9
|
+
export function findVariantByCode(variants: VariantSummary[], code: string): VariantSummary | undefined {
|
|
10
|
+
const normalized = code.trim().toLowerCase();
|
|
11
|
+
if (!normalized) return undefined;
|
|
12
|
+
return variants.find((variant) => variant.barcode?.trim().toLowerCase() === normalized)
|
|
13
|
+
?? variants.find((variant) => variant.sku?.trim().toLowerCase() === normalized);
|
|
14
|
+
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { renderHook } from '@testing-library/react';
|
|
3
|
-
import type { ReactNode } from 'react';
|
|
4
|
-
import { ConnectorProvider, useConnector, useProductTraits } from '../context/connector-context';
|
|
5
|
-
import type { TallyConnector } from '../types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Minimal connector stub that satisfies the TallyConnector interface
|
|
9
|
-
* just enough for context tests.
|
|
10
|
-
*/
|
|
11
|
-
const stubConnector: TallyConnector = {
|
|
12
|
-
id: 'test',
|
|
13
|
-
name: 'Test Connector',
|
|
14
|
-
description: 'Stub for testing',
|
|
15
|
-
auth: {
|
|
16
|
-
type: 'none',
|
|
17
|
-
fields: [],
|
|
18
|
-
getHeaders: () => ({}),
|
|
19
|
-
},
|
|
20
|
-
schemas: {
|
|
21
|
-
products: {
|
|
22
|
-
version: 0,
|
|
23
|
-
primaryKey: 'id',
|
|
24
|
-
type: 'object',
|
|
25
|
-
properties: { id: { type: 'string', maxLength: 100 } },
|
|
26
|
-
required: ['id'],
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
traits: {
|
|
30
|
-
product: {
|
|
31
|
-
getId: (doc) => doc.id,
|
|
32
|
-
getName: (doc) => doc.name,
|
|
33
|
-
getSku: () => undefined,
|
|
34
|
-
getPrice: () => undefined,
|
|
35
|
-
getRegularPrice: () => undefined,
|
|
36
|
-
getSalePrice: () => undefined,
|
|
37
|
-
isOnSale: () => false,
|
|
38
|
-
getImageUrl: () => undefined,
|
|
39
|
-
getImageUrls: () => [],
|
|
40
|
-
getDescription: () => undefined,
|
|
41
|
-
getStockStatus: () => 'unknown',
|
|
42
|
-
getStockQuantity: () => null,
|
|
43
|
-
hasVariants: () => false,
|
|
44
|
-
getType: () => 'simple',
|
|
45
|
-
getBarcode: () => undefined,
|
|
46
|
-
getCategoryNames: () => [],
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
sync: {
|
|
50
|
-
products: {
|
|
51
|
-
fetchAllIds: async () => [],
|
|
52
|
-
fetchByIds: async () => [],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
function wrapper({ children }: { children: ReactNode }) {
|
|
58
|
-
return <ConnectorProvider connector={stubConnector}>{children}</ConnectorProvider>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
describe('ConnectorProvider + useConnector', () => {
|
|
62
|
-
it('provides the connector through context', () => {
|
|
63
|
-
const { result } = renderHook(() => useConnector(), { wrapper });
|
|
64
|
-
|
|
65
|
-
expect(result.current).toBe(stubConnector);
|
|
66
|
-
expect(result.current.id).toBe('test');
|
|
67
|
-
expect(result.current.name).toBe('Test Connector');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('throws when useConnector is called outside a provider', () => {
|
|
71
|
-
expect(() => {
|
|
72
|
-
renderHook(() => useConnector());
|
|
73
|
-
}).toThrow('useConnector() must be used within a <ConnectorProvider>');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('useProductTraits', () => {
|
|
78
|
-
it('returns the product traits from the active connector', () => {
|
|
79
|
-
const { result } = renderHook(() => useProductTraits(), { wrapper });
|
|
80
|
-
|
|
81
|
-
expect(result.current).toBe(stubConnector.traits.product);
|
|
82
|
-
expect(typeof result.current.getName).toBe('function');
|
|
83
|
-
expect(typeof result.current.getPrice).toBe('function');
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('traits work against a mock document', () => {
|
|
87
|
-
const { result } = renderHook(() => useProductTraits(), { wrapper });
|
|
88
|
-
const traits = result.current;
|
|
89
|
-
|
|
90
|
-
const doc = { id: '1', name: 'Widget' };
|
|
91
|
-
expect(traits.getName(doc)).toBe('Widget');
|
|
92
|
-
expect(traits.getId(doc)).toBe('1');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('throws when called outside a provider', () => {
|
|
96
|
-
expect(() => {
|
|
97
|
-
renderHook(() => useProductTraits());
|
|
98
|
-
}).toThrow('useConnector() must be used within a <ConnectorProvider>');
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { describe, expectTypeOf, it } from 'vitest';
|
|
2
|
-
import type { ReplicationAdapter, SyncContext } from '@tallyui/core';
|
|
3
|
-
|
|
4
|
-
describe('ReplicationAdapter types', () => {
|
|
5
|
-
it('accepts a typed adapter with custom checkpoint', () => {
|
|
6
|
-
type Product = { id: string; name: string; _deleted: boolean };
|
|
7
|
-
type Checkpoint = { id: string; modified: string };
|
|
8
|
-
|
|
9
|
-
const adapter: ReplicationAdapter<Product, Checkpoint> = {} as any;
|
|
10
|
-
|
|
11
|
-
expectTypeOf(adapter.pull.handler).toBeFunction();
|
|
12
|
-
expectTypeOf(adapter.push).toEqualTypeOf<ReplicationAdapter<Product, Checkpoint>['push']>();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('requires _deleted on document type', () => {
|
|
16
|
-
type Doc = { id: string; _deleted: boolean };
|
|
17
|
-
type Adapter = ReplicationAdapter<Doc>;
|
|
18
|
-
expectTypeOf<Adapter['pull']['handler']>().toBeFunction();
|
|
19
|
-
});
|
|
20
|
-
});
|