@cogenta/commerce 0.2.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.
Files changed (98) hide show
  1. package/LICENSE +373 -0
  2. package/dist/admin/permissions.d.ts +57 -0
  3. package/dist/admin/permissions.d.ts.map +1 -0
  4. package/dist/admin/permissions.js +87 -0
  5. package/dist/admin/permissions.js.map +1 -0
  6. package/dist/admin/router.d.ts +53 -0
  7. package/dist/admin/router.d.ts.map +1 -0
  8. package/dist/admin/router.js +476 -0
  9. package/dist/admin/router.js.map +1 -0
  10. package/dist/cart/store.d.ts +91 -0
  11. package/dist/cart/store.d.ts.map +1 -0
  12. package/dist/cart/store.js +342 -0
  13. package/dist/cart/store.js.map +1 -0
  14. package/dist/cart/totals.d.ts +73 -0
  15. package/dist/cart/totals.d.ts.map +1 -0
  16. package/dist/cart/totals.js +65 -0
  17. package/dist/cart/totals.js.map +1 -0
  18. package/dist/catalog/store.d.ts +53 -0
  19. package/dist/catalog/store.d.ts.map +1 -0
  20. package/dist/catalog/store.js +358 -0
  21. package/dist/catalog/store.js.map +1 -0
  22. package/dist/catalog/types.d.ts +95 -0
  23. package/dist/catalog/types.d.ts.map +1 -0
  24. package/dist/catalog/types.js +5 -0
  25. package/dist/catalog/types.js.map +1 -0
  26. package/dist/coupon/store.d.ts +103 -0
  27. package/dist/coupon/store.d.ts.map +1 -0
  28. package/dist/coupon/store.js +181 -0
  29. package/dist/coupon/store.js.map +1 -0
  30. package/dist/customer/store.d.ts +41 -0
  31. package/dist/customer/store.d.ts.map +1 -0
  32. package/dist/customer/store.js +103 -0
  33. package/dist/customer/store.js.map +1 -0
  34. package/dist/index.d.ts +42 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +23 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/invoice/pdf.d.ts +67 -0
  39. package/dist/invoice/pdf.d.ts.map +1 -0
  40. package/dist/invoice/pdf.js +449 -0
  41. package/dist/invoice/pdf.js.map +1 -0
  42. package/dist/invoice/store.d.ts +96 -0
  43. package/dist/invoice/store.d.ts.map +1 -0
  44. package/dist/invoice/store.js +221 -0
  45. package/dist/invoice/store.js.map +1 -0
  46. package/dist/money.d.ts +55 -0
  47. package/dist/money.d.ts.map +1 -0
  48. package/dist/money.js +146 -0
  49. package/dist/money.js.map +1 -0
  50. package/dist/order/store.d.ts +75 -0
  51. package/dist/order/store.d.ts.map +1 -0
  52. package/dist/order/store.js +301 -0
  53. package/dist/order/store.js.map +1 -0
  54. package/dist/order/types.d.ts +67 -0
  55. package/dist/order/types.d.ts.map +1 -0
  56. package/dist/order/types.js +71 -0
  57. package/dist/order/types.js.map +1 -0
  58. package/dist/payment/manual.d.ts +27 -0
  59. package/dist/payment/manual.d.ts.map +1 -0
  60. package/dist/payment/manual.js +105 -0
  61. package/dist/payment/manual.js.map +1 -0
  62. package/dist/payment/registry.d.ts +23 -0
  63. package/dist/payment/registry.d.ts.map +1 -0
  64. package/dist/payment/registry.js +30 -0
  65. package/dist/payment/registry.js.map +1 -0
  66. package/dist/payment/store.d.ts +38 -0
  67. package/dist/payment/store.d.ts.map +1 -0
  68. package/dist/payment/store.js +253 -0
  69. package/dist/payment/store.js.map +1 -0
  70. package/dist/payment/stripe.d.ts +10 -0
  71. package/dist/payment/stripe.d.ts.map +1 -0
  72. package/dist/payment/stripe.js +419 -0
  73. package/dist/payment/stripe.js.map +1 -0
  74. package/dist/payment/types.d.ts +124 -0
  75. package/dist/payment/types.d.ts.map +1 -0
  76. package/dist/payment/types.js +18 -0
  77. package/dist/payment/types.js.map +1 -0
  78. package/dist/rows.d.ts +26 -0
  79. package/dist/rows.d.ts.map +1 -0
  80. package/dist/rows.js +87 -0
  81. package/dist/rows.js.map +1 -0
  82. package/dist/shipping/store.d.ts +88 -0
  83. package/dist/shipping/store.d.ts.map +1 -0
  84. package/dist/shipping/store.js +165 -0
  85. package/dist/shipping/store.js.map +1 -0
  86. package/dist/subscription/store.d.ts +106 -0
  87. package/dist/subscription/store.d.ts.map +1 -0
  88. package/dist/subscription/store.js +310 -0
  89. package/dist/subscription/store.js.map +1 -0
  90. package/dist/tables.d.ts +41 -0
  91. package/dist/tables.d.ts.map +1 -0
  92. package/dist/tables.js +383 -0
  93. package/dist/tables.js.map +1 -0
  94. package/dist/tax/store.d.ts +68 -0
  95. package/dist/tax/store.d.ts.map +1 -0
  96. package/dist/tax/store.js +126 -0
  97. package/dist/tax/store.js.map +1 -0
  98. package/package.json +42 -0
@@ -0,0 +1,310 @@
1
+ import { CogentaError, identifier, newId, sql, } from '@cogenta/core';
2
+ import { assertCurrency, assertMinor } from '../money.js';
3
+ import { referenceFrom } from '../order/store.js';
4
+ import { toInt, toNullableText, toText } from '../rows.js';
5
+ import { TABLES } from '../tables.js';
6
+ export const SUBSCRIPTION_STATUSES = ['active', 'paused', 'cancelled'];
7
+ export const INTERVAL_UNITS = ['day', 'week', 'month', 'year'];
8
+ function decode(row) {
9
+ return {
10
+ id: toText(row.id, 'subscription.id'),
11
+ customerId: toText(row.customer_id, 'subscription.customer_id'),
12
+ variantId: toText(row.variant_id, 'subscription.variant_id'),
13
+ quantity: toInt(row.quantity, 'subscription.quantity'),
14
+ status: toText(row.status, 'subscription.status'),
15
+ intervalUnit: toText(row.interval_unit, 'subscription.interval_unit'),
16
+ intervalCount: toInt(row.interval_count, 'subscription.interval_count'),
17
+ priceMinor: toInt(row.price_minor, 'subscription.price_minor'),
18
+ currency: toText(row.currency, 'subscription.currency'),
19
+ paymentDriver: toText(row.payment_driver, 'subscription.payment_driver'),
20
+ currentPeriodStart: toText(row.current_period_start, 'subscription.current_period_start'),
21
+ currentPeriodEnd: toText(row.current_period_end, 'subscription.current_period_end'),
22
+ nextBillingAt: toText(row.next_billing_at, 'subscription.next_billing_at'),
23
+ shippingCountry: toNullableText(row.shipping_country),
24
+ shippingRegion: toNullableText(row.shipping_region),
25
+ createdAt: toText(row.created_at, 'subscription.created_at'),
26
+ updatedAt: toText(row.updated_at, 'subscription.updated_at'),
27
+ cancelledAt: toNullableText(row.cancelled_at),
28
+ };
29
+ }
30
+ /**
31
+ * The end of a billing period.
32
+ *
33
+ * Month and year arithmetic is where recurring billing goes wrong, so the rule
34
+ * is stated rather than inherited from `Date`: adding a month to 31 January
35
+ * gives **28 February** (or the 29th in a leap year), not 3 March. JavaScript's
36
+ * `setMonth` overflows into the next month, which would silently move a
37
+ * subscriber's billing day forward every short month until it drifted off the
38
+ * end of the calendar.
39
+ */
40
+ export function advancePeriod(from, unit, count) {
41
+ const start = new Date(from);
42
+ if (Number.isNaN(start.getTime())) {
43
+ throw new CogentaError({
44
+ code: 'COMMERCE_SUBSCRIPTION_INVALID',
45
+ message: `"${from}" is not a date a billing period can start on.`,
46
+ hint: 'Use an ISO 8601 timestamp.',
47
+ });
48
+ }
49
+ if (unit === 'day' || unit === 'week') {
50
+ const days = count * (unit === 'week' ? 7 : 1);
51
+ return new Date(start.getTime() + days * 24 * 60 * 60 * 1000).toISOString();
52
+ }
53
+ const months = unit === 'year' ? count * 12 : count;
54
+ const year = start.getUTCFullYear();
55
+ const month = start.getUTCMonth() + months;
56
+ const day = start.getUTCDate();
57
+ const targetYear = year + Math.floor(month / 12);
58
+ const targetMonth = ((month % 12) + 12) % 12;
59
+ // Day 0 of the following month is the last day of this one.
60
+ const lastDay = new Date(Date.UTC(targetYear, targetMonth + 1, 0)).getUTCDate();
61
+ return new Date(Date.UTC(targetYear, targetMonth, Math.min(day, lastDay), start.getUTCHours(), start.getUTCMinutes(), start.getUTCSeconds(), start.getUTCMilliseconds())).toISOString();
62
+ }
63
+ export function createSubscriptionStore(db, dependencies, now = Date.now) {
64
+ const d = db.dialect;
65
+ const subscriptions = identifier(TABLES.subscriptions, d);
66
+ const cycles = identifier(TABLES.subscriptionCycles, d);
67
+ const orders = identifier(TABLES.orders, d);
68
+ const orderLines = identifier(TABLES.orderLines, d);
69
+ const stamp = () => new Date(now()).toISOString();
70
+ async function read(id, executor = db) {
71
+ const result = await executor.query(sql `select * from ${subscriptions} where id = ${id}`);
72
+ const row = result.rows[0];
73
+ return row === undefined ? null : decode(row);
74
+ }
75
+ async function load(id) {
76
+ const found = await read(id);
77
+ if (found === null) {
78
+ throw new CogentaError({
79
+ code: 'COMMERCE_SUBSCRIPTION_NOT_FOUND',
80
+ message: 'This subscription does not exist.',
81
+ hint: 'It may have been cancelled and removed.',
82
+ });
83
+ }
84
+ return found;
85
+ }
86
+ /**
87
+ * Bills one period, in one transaction.
88
+ *
89
+ * `period_key` is unique, and it is claimed **first**. That is what makes
90
+ * running the biller twice in a minute — a retried cron, two workers, an
91
+ * impatient operator — charge once: the second attempt collides on the
92
+ * unique key and unwinds before any stock is taken or any order is written.
93
+ */
94
+ async function billOne(subscription) {
95
+ const periodStart = subscription.nextBillingAt;
96
+ const periodEnd = advancePeriod(periodStart, subscription.intervalUnit, subscription.intervalCount);
97
+ const periodKey = `${subscription.id}:${periodStart}`;
98
+ const variant = await dependencies.catalog.readVariant(subscription.variantId);
99
+ if (variant === null) {
100
+ return { skipped: 'The subscribed product no longer exists.' };
101
+ }
102
+ const customer = await dependencies.customers.read(subscription.customerId);
103
+ if (customer === null) {
104
+ return { skipped: 'The subscriber no longer exists.' };
105
+ }
106
+ const orderId = newId(now);
107
+ const at = stamp();
108
+ try {
109
+ return await db.transaction(async (tx) => {
110
+ await tx.query(sql `
111
+ insert into ${cycles} (id, subscription_id, period_start, period_end, period_key, order_id, status, created_at)
112
+ values (${newId(now)}, ${subscription.id}, ${periodStart}, ${periodEnd}, ${periodKey},
113
+ ${orderId}, ${'billed'}, ${at})`);
114
+ const taken = await dependencies.catalog.takeStock([{ variantId: subscription.variantId, quantity: subscription.quantity }], tx);
115
+ if (taken.kind === 'short') {
116
+ throw new CycleRefused('The subscribed product is out of stock.');
117
+ }
118
+ const lineTotal = subscription.priceMinor * subscription.quantity;
119
+ // A renewal is not a basket, so it does not go through the cart. It
120
+ // is priced at the agreed rate, which is the whole point of a
121
+ // subscription — and it produces a real order, so it appears in the
122
+ // same lists, history and invoicing as everything else.
123
+ await tx.query(sql `
124
+ insert into ${orders} (id, reference, customer_id, email, status, currency,
125
+ subtotal_minor, discount_minor, shipping_minor, tax_minor, total_minor,
126
+ coupon_code, shipping_country, shipping_region,
127
+ shipping_method_id, shipping_method_label,
128
+ placed_at, updated_at, subscription_id)
129
+ values (${orderId}, ${referenceFrom(orderId)}, ${customer.id}, ${customer.email},
130
+ ${'pending'}, ${subscription.currency},
131
+ ${lineTotal}, ${0}, ${0}, ${0}, ${lineTotal},
132
+ ${null}, ${subscription.shippingCountry}, ${subscription.shippingRegion},
133
+ ${null}, ${null}, ${at}, ${at}, ${subscription.id})`);
134
+ await tx.query(sql `
135
+ insert into ${orderLines} (id, order_id, variant_id, sku, title, quantity,
136
+ unit_price_minor, subtotal_minor, discount_minor,
137
+ tax_minor, tax_rate_bp, total_minor, position)
138
+ values (${newId(now)}, ${orderId}, ${variant.id}, ${variant.sku}, ${variant.title},
139
+ ${subscription.quantity}, ${subscription.priceMinor}, ${lineTotal},
140
+ ${0}, ${0}, ${0}, ${lineTotal}, ${0})`);
141
+ await tx.query(sql `
142
+ update ${subscriptions}
143
+ set current_period_start = ${periodStart},
144
+ current_period_end = ${periodEnd},
145
+ next_billing_at = ${periodEnd},
146
+ updated_at = ${at}
147
+ where id = ${subscription.id}`);
148
+ return { orderId };
149
+ }, { immediate: true });
150
+ }
151
+ catch (error) {
152
+ if (error instanceof CycleRefused) {
153
+ // The period is still marked as attempted, so the next run does not
154
+ // retry it forever — and the billing date still moves, because a
155
+ // subscriber whose delivery was skipped is not owed two next month.
156
+ await db.query(sql `
157
+ insert into ${cycles} (id, subscription_id, period_start, period_end, period_key, order_id, status, created_at)
158
+ values (${newId(now)}, ${subscription.id}, ${periodStart}, ${periodEnd}, ${`${periodKey}:skipped`},
159
+ ${null}, ${'skipped_out_of_stock'}, ${at})`);
160
+ await db.query(sql `
161
+ update ${subscriptions}
162
+ set current_period_start = ${periodStart}, current_period_end = ${periodEnd},
163
+ next_billing_at = ${periodEnd}, updated_at = ${at}
164
+ where id = ${subscription.id}`);
165
+ return { skipped: error.reason };
166
+ }
167
+ // Everything else is either a unique-key collision on `period_key` —
168
+ // somebody else billed this period between the query and here, which is
169
+ // the correct outcome and not an error — or a genuine failure.
170
+ //
171
+ // Told apart by asking, rather than assumed. A blanket "already billed"
172
+ // would turn a broken database into a silent no-op, and a biller that
173
+ // reports success while charging nobody is the worst possible failure
174
+ // mode for this file.
175
+ const claimed = await db.query(sql `select id from ${cycles} where period_key = ${periodKey}`);
176
+ if (claimed.rows.length > 0)
177
+ return { skipped: 'This period was already billed.' };
178
+ throw error;
179
+ }
180
+ }
181
+ return {
182
+ create: async (input) => {
183
+ const variant = await dependencies.catalog.readVariant(input.variantId);
184
+ if (variant === null) {
185
+ throw new CogentaError({
186
+ code: 'COMMERCE_VARIANT_NOT_FOUND',
187
+ message: 'This product variant does not exist.',
188
+ hint: 'A subscription needs something to deliver.',
189
+ });
190
+ }
191
+ const count = input.intervalCount ?? 1;
192
+ if (!Number.isInteger(count) || count < 1 || count > 36) {
193
+ throw new CogentaError({
194
+ code: 'COMMERCE_SUBSCRIPTION_INVALID',
195
+ message: `A billing interval must be between 1 and 36, got ${String(count)}.`,
196
+ hint: 'Every three months is intervalUnit "month", intervalCount 3.',
197
+ });
198
+ }
199
+ const id = newId(now);
200
+ const at = stamp();
201
+ const start = input.startAt ?? at;
202
+ const end = advancePeriod(start, input.intervalUnit, count);
203
+ await db.query(sql `
204
+ insert into ${subscriptions} (id, customer_id, variant_id, quantity, status,
205
+ interval_unit, interval_count, price_minor, currency,
206
+ payment_driver, current_period_start, current_period_end,
207
+ next_billing_at, shipping_country, shipping_region,
208
+ created_at, updated_at, cancelled_at)
209
+ values (${id}, ${input.customerId}, ${input.variantId}, ${input.quantity ?? 1}, ${'active'},
210
+ ${input.intervalUnit}, ${count},
211
+ ${assertMinor(input.priceMinor ?? variant.priceMinor, 'A subscription price')},
212
+ ${assertCurrency(input.currency ?? variant.currency)},
213
+ ${input.paymentDriver ?? 'manual'}, ${start}, ${end}, ${start},
214
+ ${input.shippingCountry ?? null}, ${input.shippingRegion ?? null},
215
+ ${at}, ${at}, ${null})`);
216
+ return load(id);
217
+ },
218
+ read,
219
+ list: async (options) => {
220
+ let statement = sql `select * from ${subscriptions}`;
221
+ if (options?.customerId !== undefined && options.status !== undefined) {
222
+ statement = sql `${statement} where customer_id = ${options.customerId} and status = ${options.status}`;
223
+ }
224
+ else if (options?.customerId !== undefined) {
225
+ statement = sql `${statement} where customer_id = ${options.customerId}`;
226
+ }
227
+ else if (options?.status !== undefined) {
228
+ statement = sql `${statement} where status = ${options.status}`;
229
+ }
230
+ const result = await db.query(sql `${statement} order by created_at desc, id desc`);
231
+ return result.rows.map(decode);
232
+ },
233
+ pause: async (id) => {
234
+ await load(id);
235
+ await db.query(sql `update ${subscriptions} set status = ${'paused'}, updated_at = ${stamp()} where id = ${id} and status = ${'active'}`);
236
+ return load(id);
237
+ },
238
+ resume: async (id) => {
239
+ const subscription = await load(id);
240
+ if (subscription.status === 'cancelled') {
241
+ throw new CogentaError({
242
+ code: 'COMMERCE_SUBSCRIPTION_INVALID',
243
+ message: 'A cancelled subscription cannot be resumed.',
244
+ hint: 'Create a new subscription instead — the old one is a closed record.',
245
+ });
246
+ }
247
+ // Billing resumes from now, not from where it was paused. Charging a
248
+ // subscriber for the months they were paused is exactly what pausing was
249
+ // supposed to prevent.
250
+ const at = stamp();
251
+ await db.query(sql `
252
+ update ${subscriptions} set status = ${'active'}, next_billing_at = ${at}, updated_at = ${at}
253
+ where id = ${id}`);
254
+ return load(id);
255
+ },
256
+ cancel: async (id) => {
257
+ await load(id);
258
+ const at = stamp();
259
+ await db.query(sql `
260
+ update ${subscriptions} set status = ${'cancelled'}, cancelled_at = ${at}, updated_at = ${at}
261
+ where id = ${id} and cancelled_at is null`);
262
+ return load(id);
263
+ },
264
+ cycles: async (id) => {
265
+ const result = await db.query(sql `select * from ${cycles} where subscription_id = ${id} order by period_start asc, id asc`);
266
+ return result.rows.map((row) => ({
267
+ id: toText(row.id, 'cycle.id'),
268
+ subscriptionId: toText(row.subscription_id, 'cycle.subscription_id'),
269
+ periodStart: toText(row.period_start, 'cycle.period_start'),
270
+ periodEnd: toText(row.period_end, 'cycle.period_end'),
271
+ orderId: toNullableText(row.order_id),
272
+ status: toText(row.status, 'cycle.status'),
273
+ createdAt: toText(row.created_at, 'cycle.created_at'),
274
+ }));
275
+ },
276
+ runBilling: async (options) => {
277
+ const due = await db.query(sql `
278
+ select * from ${subscriptions}
279
+ where status = ${'active'} and next_billing_at <= ${stamp()}
280
+ order by next_billing_at asc`);
281
+ const billed = [];
282
+ const skipped = [];
283
+ for (const row of due.rows.slice(0, options?.limit ?? 200)) {
284
+ const subscription = decode(row);
285
+ const outcome = await billOne(subscription);
286
+ if ('orderId' in outcome) {
287
+ billed.push({ subscriptionId: subscription.id, orderId: outcome.orderId });
288
+ // The renewal starts a payment through the same store as any other
289
+ // order, so a subscription with no gateway configured produces bank
290
+ // transfer instructions rather than failing (R2).
291
+ await dependencies.payments.start(outcome.orderId);
292
+ }
293
+ else {
294
+ skipped.push({ subscriptionId: subscription.id, reason: outcome.skipped });
295
+ }
296
+ }
297
+ return { billed, skipped };
298
+ },
299
+ };
300
+ }
301
+ /** Internal. Unwinds a billing transaction with a reason. */
302
+ class CycleRefused extends Error {
303
+ reason;
304
+ constructor(reason) {
305
+ super(reason);
306
+ this.name = 'CycleRefused';
307
+ this.reason = reason;
308
+ }
309
+ }
310
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/subscription/store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAEZ,UAAU,EACV,KAAK,EAEL,GAAG,GACJ,MAAM,eAAe,CAAA;AAGtB,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAmB,aAAa,EAAE,MA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ACF"}
@@ -0,0 +1,41 @@
1
+ import { type DatabaseHandle } from '@cogenta/core';
2
+ /**
3
+ * Every table contract E owns.
4
+ *
5
+ * Prefixed `cogenta_commerce_` rather than `cogenta_`: a site's content tables
6
+ * are named after the collections **it** declares, so a shop that also declares
7
+ * a `product` collection for the storefront page must not collide with the
8
+ * commercial record of the same product. The two are deliberately different
9
+ * objects (ADR draft 0023) and they must be able to coexist in one database.
10
+ */
11
+ export declare const TABLES: {
12
+ readonly products: 'cogenta_commerce_products';
13
+ readonly variants: 'cogenta_commerce_variants';
14
+ readonly customers: 'cogenta_commerce_customers';
15
+ readonly carts: 'cogenta_commerce_carts';
16
+ readonly cartLines: 'cogenta_commerce_cart_lines';
17
+ readonly orders: 'cogenta_commerce_orders';
18
+ readonly orderLines: 'cogenta_commerce_order_lines';
19
+ readonly orderEvents: 'cogenta_commerce_order_events';
20
+ readonly payments: 'cogenta_commerce_payments';
21
+ readonly refunds: 'cogenta_commerce_refunds';
22
+ readonly taxRules: 'cogenta_commerce_tax_rules';
23
+ readonly shippingMethods: 'cogenta_commerce_shipping_methods';
24
+ readonly coupons: 'cogenta_commerce_coupons';
25
+ readonly couponRedemptions: 'cogenta_commerce_coupon_redemptions';
26
+ readonly invoices: 'cogenta_commerce_invoices';
27
+ readonly invoiceSequences: 'cogenta_commerce_invoice_sequences';
28
+ readonly subscriptions: 'cogenta_commerce_subscriptions';
29
+ readonly subscriptionCycles: 'cogenta_commerce_subscription_cycles';
30
+ };
31
+ /**
32
+ * Creates everything this package owns, idempotently.
33
+ *
34
+ * Same shape as `ensureAuthTables`: `create table if not exists`, run once at
35
+ * startup, so a fresh install and an upgrade take the same path. Commerce is
36
+ * **not** part of contract A's migration engine on purpose — a site that never
37
+ * sells anything never creates these tables, which is the whole point of
38
+ * putting commerce in its own contract rather than raising `schema` to 3.0.
39
+ */
40
+ export declare function ensureCommerceTables(db: DatabaseHandle): Promise<void>;
41
+ //# sourceMappingURL=tables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tables.d.ts","sourceRoot":"","sources":["../src/tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAKpB,MAAM,eAAe,CAAA;AAEtB;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM;aACjB,QAAQ,EAAE,2BAA2B;aACrC,QAAQ,EAAE,2BAA2B;aACrC,SAAS,EAAE,4BAA4B;aACvC,KAAK,EAAE,wBAAwB;aAC/B,SAAS,EAAE,6BAA6B;aACxC,MAAM,EAAE,yBAAyB;aACjC,UAAU,EAAE,8BAA8B;aAC1C,WAAW,EAAE,+BAA+B;aAC5C,QAAQ,EAAE,2BAA2B;aACrC,OAAO,EAAE,0BAA0B;aACnC,QAAQ,EAAE,4BAA4B;aACtC,eAAe,EAAE,mCAAmC;aACpD,OAAO,EAAE,0BAA0B;aACnC,iBAAiB,EAAE,qCAAqC;aACxD,QAAQ,EAAE,2BAA2B;aACrC,gBAAgB,EAAE,oCAAoC;aACtD,aAAa,EAAE,gCAAgC;aAC/C,kBAAkB,EAAE,sCAAsC;CAClD,CAAA;AAuBV;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAoT5E"}